Friday, October 25, 2013

Passing Assumed Shape Arrays between Fortran and C++

Abstract

Fortran 90 introduced assumed shape arrays (colloquially referred to as "Fortran 90 Arrays"), a big step forward.  Fortran 2003 introduced interoperability with C/C++, another step forward.  Unfortunately, there is no well-known way to pass assumed shape arrays between Fortran and C++.  This is a serious problem: assumed shape arrays are widely used in modern Fortran code, and not being able to interoperate easily with C/C++ in those cases can make the C interop features nearly useless.

Here, we present a standards-compliant way to allocate assumed shape arrays in Fortran and pass them to code written in C++.  This method is fully compliant with the Fortran 2003 and C++98/11 language standards.

Prerequisites

We begin by using a C++ library that provides functionality equivalent to Fortran's assumed shape arrays.  We used Blitz++; however, others have suggested Armadillo and Eigen.  Although we have not investigated, we believe the techniques outlined here would work for these other packages as well.

These techniques will also require a Fortran 2003 compiler that supports the ISO standard Fortran/C interop.

Description

With appropriate information on memory layout, Blitz++ is able to create array structures that reference already-allocated areas of memory.  The required information is stored in the Fortran "dope vector."  Unfortunately, dope vectors are implement-dependent, and cannot be read directly.

We proceed by reconstructing the Fortran dope vector using a series of standard Fortran 2003 calls.  Consider the following structure, which can store information on a 2-dimensional dope vector:
type, bind(c) :: arr_spec_2    type(c_ptr) :: base    type(c_ptr) :: deltas(2    integer(c_int) :: lbounds(2)    integer(c_int) :: ubounds(2)end type
We then fill it in.  Here is how that can be done for 2-D assumed shape arrays of type real*8:
    function c_loc_double(x)
        use, intrinsic :: iso_c_binding
        real*8, target :: x
        type(c_ptr) :: c_loc_double
        c_loc_double = c_loc(x)
    end function
    ! ================ Type (real*8, double), Rank 2
    subroutine get_spec_double_2(arr, low1,low2, spec)
    implicit none
    real*8, dimension(:,:), target :: arr
    integer :: low1,low2
    type(arr_spec_2) :: spec
        spec%base = c_loc_double( arr(lbound(arr,1),lbound(arr,2)) )
     
        ! ------- Dimension 1
        spec%lbounds(1) = low1
        spec%ubounds(1) = low1 + ubound(arr,1) - 1
        if (spec%lbounds(1) < spec%ubounds(1)) then
            spec%deltas(1) = c_loc_double(arr(lbound(arr,1)+1,lbound(arr,2)))
        else
            spec%deltas(1) = spec%base
        end if
        ! ------- Dimension 2
        spec%lbounds(2) = low2
        spec%ubounds(2) = low2 + ubound(arr,2) - 1
        if (spec%lbounds(2) < spec%ubounds(2)) then
            spec%deltas(2) = c_loc_double(arr(lbound(arr,1),lbound(arr,2)+1))
        else
            spec%deltas(2) = spec%base
        end if
    end subroutine
A few things to note:

  1. The function c_loc_double(x) is required because c_loc() does not seem to work directly on elements of arrays (at least not in GNU's gfortran).
  2. The deltas() array contains the address of the second element in each dimension.  True skip offsets for each dimension can be computed by spec%deltas(i) - spec%base.  This is not done because Fortran does not have pointer arithmetic.

Fortran 2003 does not preserve the lower bound of an array when you pass it.  Therefore, the lower bounds of each dimension have to be passed into the subroutine get_spec_double_2().  In order to make life more convenient, this can be hidden under the hood with the following macro (if one is using Fortran with the C pre-processor):
#define GET_SPEC_DOUBLE_2(arr, spec) \    get_spec_double_2(arr, lbound(arr,1),lbound(arr,2), spec)

With the dope vector stored in a type(arr_spec_2) object, that information may now be passed to a C++ subroutine via a matching C++ structure --- and then reconstituted into a Blitz++ array.  We can use C++ templates to make a version that will work for all types and ranks:
/** Used to accept Fortran 90 arrays and re-constitute them as blitz++ arrays.
@see f90blitz_f.py */
template<class ArrT, int rank>
struct F90Array {
    ArrT *base;
    ArrT *deltas[rank];
    int lbounds[rank];
    int ubounds[rank];
    /** Extract F90Array info from existing blitz::Array.  Used to
    write C++ test code for Fortrn APIs. */
    F90Array(blitz::Array<ArrT,rank> &arr) {
        this->base = arr.data();
        blitz::TinyVector<int, rank> idx(0);
        for (int i=0; i<rank; ++i) {
            this->deltas[i] = this->base + arr.stride(i);
            this->lbounds[i] = arr.lbound(i);
            this->ubounds[i] = arr.ubound(i);
        }
    }

    blitz::Array<ArrT,rank> to_blitz()
    {
        blitz::TinyVector<int, rank> shape, stride;
        blitz::GeneralArrayStorage<rank> stor;
        for (int i=0; i<rank; ++i) {
            shape[i] = ubounds[i] - lbounds[i] + 1;
            stride[i] = deltas[i] - base;
            stor.base()[i] = lbounds[i];
            // Ordering is not needed because we're using stride
            // stor.ordering()[i] = i;      // Fortran ordering, blitz++ manual p31
        }
        return blitz::Array<ArrT,rank>(base, shape, stride,
            blitz::neverDeleteData, stor);
    }
};

Example

The code may now be used as follows:


interface    subroutine c_function(arr_spec) bind(c)        type(arr_spec_2) :: arr_spec    end subroutine c_functionend interface
real*8, dimension(:,:) :: arrtype(arr_spec_2) :: arr_spec
    call GET_SPEC_DOUBLE_2(arr, arr_spec)    call c_function(arr_spec)
-------------------------------extern "C" void c_function(F90Array<double, 2> &arr_spec){    auto arr(arr_spec.to_blitz());    printf("Here is a value: %f\n", arr(17,34));}

Generalization

The above code works only for rank-2 arrays of real*8.  The same principles can be applied to extract and use dope vectors for any size and kind of array; but because Fortran lacks templates, writing out the required code would be tedious.  For this reason, we provide a Python script, f90blitz_f.py to generate the required Fortran code.  This script really needs only be run once.  Its usage is:
python f90blitz_f.py <output.f90> <output.h>
The variables fctypes and ranks must be modified inside the script, to control which data types and ranks of arrays get generated.  This can be customized as needed for any particular program.

The required code is only two files: a templated C++ header file, and a Python script to generate the required Fortran files.  That code may be downloaded here:


https://drive.google.com/file/d/0B1tFrRmi_97eRGlmWU1CaVJ4NkE/edit?usp=sharing
https://drive.google.com/file/d/0B1tFrRmi_97eWUdZV3pvZlpyNGs/edit?usp=sharing






Tuesday, August 27, 2013

Can Fracking Save Us from Climate Catastrophe?

It has been noted that US carbon emissions have gone down more than that of any other industrialized nation in the past few years.  This has been used as evidence to support the American laissez-faire approach to the entire issue.


The decrease is due mainly to fracking and the shale gas boom.  There is so much cheap natural gas out there that utilities are switching power generation from coal to gas.  It's a win for utilities, win for consumers, and win for the environment!  If only it were that simple.  For one thing, any change in the relative price of coal vs. natural gas can reverse the "progress" on emissions:


But there is a more serious problem.  Let's suppose for now that fracking releases so much gas that the world stops burning coal, switching to gas instead.  Heck, let's suppose that we stop burning oil as well, and convert all our fossil fuel use to gas!  And let's imagine that this conversion will reduce the world's carbon footprint by 50%.  Where does that get us?

Well... if the world was hurtling toward a cliff at 100mph, now we're speeding toward that very same cliff at 50mph.  It means that all the climate-related problems we will be facing will take twice as long to materialize.  That would certainly be good news.

But it would not really solve the problem.  Humanity is currently releasing huge amounts of CO2 into the atmosphere.  When similar amounts of CO2 were released "suddenly" in the past, bad things happened... 10 degrees (F) of warming, mass extinctions, long-term changes in the course of the history of life.  Look, for example, at the end-Permian and end-Triassic extinctions.  The extinction issues will likely persist long after all the CO2 we've released into the atmosphere gets mopped up into the rocks due to the long-term carbon cycle.  

The problem here is that both of the above extinction events were the result of "sudden" releases of CO2.  How sudden?  Paleontologists think about a million years.  Which is 10,000 times slower than we're releasing CO2 right now.  It doesn't matter if we release that much CO2 over 100 years or 200 years, the end result will be the same.  All that would have to change is Jim Hansen would have to change the title of his book from "Storms of my Grandchildren" to "Storms of my Great-Great-Grandchildren."

So let's quit the charade of how natural gas and fracking will save us.  It will only ever get us halfway there.  Instead, let's focus on REAL solutions to the climate problem, which require zero-carbon technologies.  The best that natural gas will ever buy us is a little bit of time.

[By the same token, one could consider one of my favorite technologies, the electric bicycle.  Suppose we stop driving cars and drive electric bikes instead.  These use dramatically less fuel than automobiles, about 10% that of a Nissan Leaf.  Heck, let's suppose we cut ALL our fossil fuel use by 90%.  Would we still need to worry about climate change?  Unfortunately, yes.  Now the catastrophe that would have taken 100 years will take 1000 years to unfold.  Maybe that's OK for some people, although the mass extinctions would still happen similarly in either case.]

Saturday, July 27, 2013

Is Solar Net Metering REALLY a Threat to Utilities?

Intereting article in the NY Times Blog:

http://www.nytimes.com/2013/07/27/business/energy-environment/utilities-confront-fresh-threat-do-it-yourself-power.html?pagewanted=all&_r=0

For years, power companies have watched warily as solar panels have sprouted across the nation’s rooftops. Now, in almost panicked tones, they are fighting hard to slow the spread...        

The real problem seems to be that solar customers pay nothing under net metering, even though they use the grid.  A few thoughts:

1. Develop a rate for reverse electric flow, as well as forward.  Then solar customers will get charged for their use of the grid, whether it was forward or reverse.  Meanwhile, solar customers should be paid the prevailing wholesale rate for the electricity they provide AT THE TIME THEY PROVIDE IT.  That is, they should get the high daytime wholesale rate if they provide electricity during a hot summer day with all the A/C going.  This seems to be the most economically straightforward way to price things.

2. Stop subsidizing solar, and put in place a sensible carbon tax (aka Jim Hansen).  With such a tax in place, suddenly solar won't need any subsidies.

3. If utilities don't like distributed generation, regulators can suggest a willingness to change policy --- but ONLY IF the utilities meet certain benchmark targets for renewable content in the electricity they provide.

Thursday, November 22, 2012

Mike Bloomberg's Thanksgiving Gift

Last week, I received a great Thanksgiving Gift from Mike Bloomberg.  I work in Morningside Heights, and take my bike to Midtown sometimes.  It's always been dicey: Central Park is OK without cars, but can be downright dangerous when bikes and pedestrians are all crowded into just one of the three lanes (I know from unfortunate experience).  I generally tried to use it only during no-car hours for this reason.

Well, last week I noticed something different upon entering the park: the lanes have been reconfigured! Now, there is one lane for pedestrians, one for bikes and one for cars (and carriages).  Now it FINALLY safe to use this route through the City, even during rush hour.  Horray!

http://www.examiner.com/article/dot-paints-wider-central-park-lanes-for-bikes-and-runners

But what about horse carriages?  Should they go in the bike or the car lane?  I have no idea.  But I do know that horses are big, and I give them a wide berth.

Hubway Bike Share: First Impressions



I took a trip to Boston this past October.  It was a quick in-and-out for business: arrive late in the evening at South Station, sleep over, and then leave the next day from South Station immediately after the meeting.

In the past, I would take the T to get around town: I can't tell you how many times I've found myself waiting for the Red Line late at night at South Station.  But this time... this time, I figured I would try out Hubway, Boston's new bike share program.  Instead of my Charlie Card, I took my bike helmet.

Upon arrival at South Station, I had no problem finding the bikes.  And after a few minutes of studying the instructions, I figured out how to use it and paid $5 on my credit card for a 24-hour membership.  The price was incredibly reasonable, as this would serve all my transportation needs for the next day: three trips in all.

The first thing I did was add lights to the bike.  They have built-in dynamo-powered lights.  But the lightweight LED headlight I strapped on to the handlebars was much brighter.  Same thing for the LED light I'd attached to my backpack.  In my book, you can never have too many lights on your bike.

And then off I went.  I headed across Downtown Crossing, then cut across the Boston Commons to the Arthur Fiedler Memorial Bridge.  From there, it was an easy level stretch along the Charles River: always a pleasant way to get in and out of downtown.  I rarely feel unsafe biking alone at night because --- someone would have to stop me before they do anything.

By this time, it became clear to me: these bikes are NOT built for speed.  They are indestructible and not particularly heavy.  But their 3-speed gearing is rather low, and I was simply not able to go more than maybe 12 mph.  Since I'm used to getting around at about twice that speed, this was hard for me to get used to.  Patience is a virtue.... anyway, it still beat waiting for the T and walking.

I popped back over Storrow Drive in the middle of BU and found a nicely renovated bike lane on Commonwealth Ave.  Great job!

Hubway allows you only 30 minutes of ride before they add a surcharge.  But you can ride as long as you like if you "check in."  So that's what I did on BU Campus.  I found another bike rack, turned my bike in, and then tried to get a second bike.  For that, I had to insert my credit card again.  Not to charge, just verify.

Uh oh... the machine couldn't read my card, and I might find myself walking the rest of the way.  NOT COOL.  Luckily, it finally did manage to read the card, and off I went again.  I found that the BU Bridge was now safe on bike, something it never was in the past (thank you, nice job), and then left the bike at Micro Center.  It was an amazing feeling to just roll up, stick the thing in the rack, and then just... walk away.  No muss, no fuss.

All in all, my entire trip from South Station to Cambridgeport took less than 30 minutes.  That is comparable to the T.  This particular location is a 10-minute walk from the T, which made the bike so much more convenient.  Unfortunately, I still had to walk a couple of blocks from Micro Center.

The next day went smoothly.  I picked up a bike at Micro Center (the same bike as last night, in fact) and had no problem riding to Harvard Square.  Again... these are slow bikes, and that didn't feel as good as my own bike riding in traffic on Putnam Ave.  But I got to Harvard Square all right and had no problem finding an empty rack slot.  No muss, no fuss.

Given the slow speed of these bikes, I was a little apprehensive of riding all the way back to South Station. They're not as fun as my own bikes.  In the end, I ended up talking with my colleagues for so long, I had to get a ride to South Station. And I must say, the way you can just drive down the Pike and then right up into the parking garage on top of the bus station is pretty cool.  Before I knew it, I found myself on a Greyhound heading back to Port Authority.

So what do I think?  Overall, a great system, but the bikes are slow.  Patience is a virtue.  It was a great value for $5, even though I got only 2 trips out of it, not 3.  Do I plan on using it the next time I go to Boston?  Certainly!

What does this mean for New York?  New York is bigger than Boston, but I'm afraid the bikes won't be any faster.  Members will need to become well versed in the bike-swap procedure in order to get many interesting places in New York --- certainly any inter-borough travel will require that technique.

The biggest possible problem for the  casual user would be broken credit card readers and getting stuck mid-trip because of them.  This could be fixed if they allow you to enter a code to re-rent once you've turned in a bike, rather than having to insert your physical credit card.  Or if they make an app and use RFID phones.  Or... there are a million ways to solve this problem.  But it does need to be solved.

Thursday, November 1, 2012

Which Newfangled Vehicles will Save You Money?

The past few years have been an exciting time in the automobile industry. For many decades, "innovation" meant changing the tail fins or adding bluetooth to the radio. But now, in the face of rising gasoline prices and global warming, the industry is finally responding with some truly innovative new products and drivetrains. We've seen exotic cars like the Tesla Roadster, all-electric vehicles that change the way we think about range and fueling, and increasingly a lot of just plain improved gasoline, diesel and hybrid vehicles.

A lot has been written about the carbon footprint of these new options. And there will always be early adopters willing to spend anything on the latest low-carbon vehicle. Most of the rest of us are interested in lowering our carbon footprint, but we also need to save money. More importantly, advanced-technology fuel-saving vehicles will really take off when they offer consumers overall savings. But with a bewildering array of alt-fuel vehicles coming out every day, it becomes increasingly hard to tell which car will actually do that for us.

The problem is that so many of the assumptions we've taken for granted have been uprooted. A car that saves money for one driver might not for another. Hybrid technology saves gas in city driving but not highway. Diesel vehicles get impressive fuel economy, but diesel fuel also costs more. Electric vehicles bring a whole new dimension to the cost issue, and plug-in hybrids make things even more complex. And many of these new cars get better fuel economy in the city than highway, uprooting decades of thinking about fuel economy.

To help bring clarity to this conundrum, I put together a spreadsheet (below). At the top, you fill in your prices for gasoline, diesel fuel, electricty and your particular city/driving mix. Then you make a series of columns for each car you're considering. I've filled in some columns for cars I might want to conside buying (ideally, small wagons). In general, you enter yellow cells and white cells are computed for you. Then, a "total" cost of ownership is provided at the bottom. Note that this does not include factors such as insurance and repairs. And it assumes you will keep the care for 100,000 miles and then sell at whatever the resale value is at the end.

(To play with yourself: click on the diagonal arrow to open the spreadsheet in a new menu. Then choose "Download" under the "File" menu.)
So what does this spreadsheet tell us?

Electric Vehicles

A quick glance tells us we might save money with the Nissan Leaf. This all-electric vehicle is cheaper than plug-in hybrids like the Chevy Volt because it has no gasoline engine. And electric vehicles certainly cost the least per mile to drive. If someone else pays to charge your vehicle at work or at the mall, they cost even less (put in $0.00 on your electric cost to see how much less.)

But before running out and buying a Leaf, beware that the resale value of the Leaf of $10,000 may be optimistic. Priuses with 100,000 miles can sell for $10,000. But we just don't know how things will hold up with all-electric vehicles. Battery packs will be more expensive than those for the Prius, and that could affect their price. So could brand perception of Nissan vs. Toyota. Here's an in-depth analysis of how Leaf battery issues might go over time.

On the other hand, other than the battery, the Leaf has very little on it that can wear out. It could last until the body rusts through --- which is a long time with today's high-quality paint jobs. And even if you spend $9K after a decade to replace the batteries, that's still a lot less than a new car.

Other things to note: The Leaf's price includes a $7.5K tax credit which will not survive forever, and it is only appropriate as a second car due to range and charging issues common to all electric vehicles.

Conclusion: An electric vehicle such as the Leaf could be a cost-effective second car for the early adopter willing to take a little bit of a risk. If thins turn out well with maintenance, battery and depreciation, it could be an amazing value. If not, it could be near worthless after a decade.

Hybrid Vehicles

For the one-car family or someone not ready to take the risk of an all-electric vehicle, hybrids make more sense and are also quite economical. Hybrid technology is now over a decade old, and we have extensive data on how well it holds up. The answer is, remarkably well. In fact, the Toyota Prius has the lowest depreciation of any vehicle. I continue to be amazed that you can drive one of them for 100,000 miles and then sell it for $10K --- twice the new sales price of my 1980 Honda Civic.
Assuming resale values hold, the Toyota Prius V looks like a sold winner on price. It saves enough fuel, and holds its resale value well enough, to justify the initially higher sales price compared to a traditional gasoline car such as the Toyota Matrix or Ford Focus.  And plus, it's COOL, it has lots of extras on the inside.

The Ford C-max, a close competitor to the Prius V, offers another intruiging possibility. Its overall cost is rather similar, but it gets even better fuel economy. The real question is whether or not it will hold its resale value as well as the Prius. I assumed it would hold its value better than most cars, but not as well as a Prius; but that is a guess. Lowered resale value is also an issue with the Prius: resale values could drop as hybrid vehicles become more common.

Conclusion: The eco-conscious buyer with low financial risk tolerance need look no further than the Prius. It will cost you more money up-front, but you will make it back at today's gas prices. Other hybrid vehicles will likely offer a similar value proposition.

The Losers

Finally, for the vehicle choices NOT on the efficient frontier:

  • Diesel: Diesel engines are great for trucks, and they offer impressive low-RPM grunt. But they are heavier than gasoline engines and cost more to build. And the higher price of diesel fuel makes them almost as expensive to run as traditional gasoline engines.


  • Traditional Gasoline: Rising gasoline prices and falling cost of hybrid technology mean that traditional gasoline engines are no longer cost effective.

    So go ahead, buy that Prius you've been eying. You can afford it (once your current car dies).

    Sunday, October 21, 2012

    Does Public Transportation Save Energy?

    Ever since the gas crises 1970's it's become environmental dogma that getting people to park their automobile and hop on a bus or a train will save energy.  In the 1970's, when American automobiles achieved 15mpg if they're lucky, that was certainly the case.  But a lot has changed since the 1970's.  How should the environmentally conscious traveler and urban planner think about transportation and energy use today?

    The answer is complicated, but also surprising.  Let's consider local travel (commuting) and long distance travel separately.  Most of our transportation energy is consumed in local travel, so that is what we will consider in this article.  Long distance will have to wait.

    Local Travel

    Let's look at the typical energy use of some public transit systems, and then compare them to our favorite automobile in the driveway.  Let's look at the DOE Transportation Energy Data Book Chapter 2. Not surprisingly, public transit systems vary in their energy use: light rail systems use between 2,000 (San Diego, CA) and 30,000 (Kenosha, WI) BTU per passenger-mile.  Similarly, heavy rail systems vary from 1,800 (New York City) to over 10,000 (Cleveland, OH) BTU per passenger-mile.

    How do we evaluate whether or not these systems save energy?  It depends on your perspective.  Let's suppose you're environmentally conscious and you drive a Prius.  Your rated 51mpg in the city translates to just 2,254 BTU per mile.  So even if you drive alone, you will be more fuel-efficient than all heavy rail (subway) systems except those in New York City, Atlanta GA and Oakland CA --- which are apparently only marginally more efficient than a single-driver Prius.  You will be more fuel-efficient than all light-rail systems except those in Stockon CA, Los Angeles CA, San Carlos CA, and Alexandria VA.  And you will be more fuel-efficient than all commuter-rail systems in America.

    Now consider that US fuel economy standards are set to steadily rise, to 54.5 mpg (2110 BTU/passenger-mile) by the year 2025.  That means that by 2025, today's Prius will be below average in fuel economy, and everyone can expect to drive a car that's more fuel-efficient than all but a few transit systems.

    Hmm... transit systems don't save energy?  How has it come to this, after we were told for decades that we should ride the bus to save energy?  Basically, busses and trains were always designed with fuel efficiency in mind, whereas that was not on the agenda for automobiles until recently.  Automobiles have been improving steadily, whereas there is not so much room for improvement on transit vehicles --- especially not electric ones.  Moreover, transit vehicles suffer from many inherent inefficiencies due to the nature of shared service: extra weight per passenger to make vehicles large enough to walk around in, frequent stops, and low seat utilization.

    The last one is worth considering: a hypothetical morning rush-hour bus/train that starts in the suburbs picks people up along the way, and dumps a full load downtown will only have a 25% seat utilization.  That's 50% on the way in and 0% on the way back out.  So even if it's standing-room-only by the time you get off downtown, the average seat utilization of the system as a whole can still be relatively low.  On the other hand, automobiles have only a 25% seat utilization if you don't car-pool, which is not so different from what one could expect from a transit system.

    So busses and trains aren't so much better as we were led to believe.  What should we do about this in our decision-making?  It depends on who you are and what decision you are making.
    1. If you're trying to get to work in the morning rush hour in a city with a crowded transit system, you will save the most energy by car-pooling.  Even if you only have a 30mpg Corolla, two of you in the car will still save energy over any transit system.  And by driving, you relieve the transit system of having to run more busses or trains.
    2. If you can't car-pool, just buy a Prius.  You'll still do better than almost any transit system.
    3. If you do a reverse commute, the things look very different: now you will save energy by taking transit --- and lots of it.  You are taking advantage of "free" seats that won't be filled anyway, making your effective energy use zero.

    Carbon Footprint

    Since I'm a climate scientist, I don't really care how much energy you use, as long as you didn't generate CO2 in the process.  What I DO care about is your carbon footprint.  So let's look at the comparative carbon footprint of these different modes.

    From the carbon footprint point of view, automobiles aren't looking so hot anymore, nor are busses.  Why?  Because the only way we know how to power them is with carbon-intensive petroleum.  The New York City Subway, which runs on electricity, 30% of it nuclear-generated, now looks like a clear carbon winner over anything you can drive.  

    Unless you drive an electric car, of course.  And aren't electric cars great: new cars such as the Chevy Volt and Nissan Leaf get anywhere between 100mpg and 200mpg equivalent, depending on who you ask and how your electricity is being generated.  Now, the efficiency winner tips back away from the transit systems.  Electric cars have the same carbon advantages over petroleum as do electric trains.  If nothing else, switching to an electric fleet will allow us to move away from petroleum for transportation, toward other cheaper primary fuels: for example, coal, solar, nuclear, wind, natural gas, hydro --- pretty much anything in the days of $100/barrel oil.

    Smart Growth and Transportation Planners

    What does this all this mean for city planners?  Rather than trying to build busses to the exurbs, it seems the best way to save energy on transportation is to decrease demand for it.  And we know how to do that: build denser, more compact cities where the places people live and the places they shop and work are closer together.  The term "Smart Growth" embodies this philosophy.

    And it works.  Whereas transit usage is uniformly low almost everywhere, Total Vehicle Miles travelled per day varies greatly among American cities.  Not surprisingly, New Yorkers travel less than anyone else on average (9 miles/day): travel by any means is slow and difficult, and there is so much so close anyway.  And suburban New Yorkers, who drive through densely-packed suburbs, drive less than almost anyone else (17 miles/day).  Even Los Angelenos, famous for their car culture, don't drive that much: 23 miles/day.  In contrast, Houstonians drive an average of 38 miles/day.  Think about it: driving a Prius in Houston will have a greater carbon footprint than a Corolla in LA.  And if you live in New York City, you might as well drive a mini-van or SUV.

    So where does transit come in?  The problem is, compact cities quickly become congested, and there's no place to park all those Priuses anyway.  Transit enables cities to grow at higher densities than would otherwise be possible using just automobiles.  Transit does not save energy directly.  But it is a key tool we have that allows us to save energy by building compact cities.  Even in "transit-oriented developments" being built today, the overwhelming majority of people drive.  But they drive less, and that is the key.

    What does this mean for the transportation planner?  In building new cities, we should plan for transit via bus lanes, rights-of-way, etc.  But there's no need to actually build and operate the transit lines until congestion creates demand.  That is 180 degrees different from the more common approach today, in which we do anything we can to entice people out of their cars.  The problem is, once we've built a non-compact city, it doesn't matter what form of transportation we use to get around it, we will be stuck with high energy use.

    There are other good reasons to build transit systems as well: they require lower capital costs for the vehicles, use less infrastructure per capita, use less land in the city centers, and provide universal mobility.  But they only really work well in relatively dense, compact areas.

    The Ultimate Carbon-Friendly Transportation

    If riding the bus doesn't win eco-points over driving your Prius, what's the serious eco-warrior to do to get to work?  The answer is the bicycle.  But not just any kind of bike.  Read on...

    It's well-known that bicycles require less energy to move forward than any other vehicle known to mankind.  They are so efficient because they are extremely light-weight, they have low rolling resistance, and they don't go fast enough for that efficiency to be killed by their bad aerodynamics (25 mph and up).  So bikes are really efficient to push around, and twice as efficient as walking.

    The big problem with bikes is their inefficient power plant: you.  Because you eat food grown through our commercial agriculture system, which is incredibly inefficient.  For example, 40 calories of fossil fuel energy are expended for every calorie of beef protein produced at your table, ready for you to eat.  Other foods seem to be better: grains require only maybe 10 calories of oil per calorie of food.

    So when we take our agriculture system into account and look at biking vs. our trusty Prius, how do things  stack up in the end?  If you're a couch potato and need the exercise anyway, then the bike is a clear winner.

    But suppose you're already fit, now you'll have to eat more when you bike.  If you eat bananas to power your bike, you'll apparently come in at 65g CO2 per mile.  That compares with 220g CO2 per mile for a Prius.  Definitely a lot more efficient.  But if you and your three buddies want to get somewhere, you'll do less harm to the planet driving your Prius.  And if you're a carnivore and love your cheeseburgers... well, you might as well just drive, the cheeseburger-powered bicycle apparently does 260g CO2 per mile.

    If biking doesn't save much energy after all, what's the eco-conscious bike lover to do?  The answer is this new invention that came out of China over the last decade: the electric bike.  At first, it seems like "cheating:" surely a motorized vehicle will have a higher carbon footprint than a manual bicycle.  But our electric grid is (thankfully) far more efficient than our agriculture, giving electric bikes a significantly lower carbon footprint in the end.

    All-in-all, my electric bike uses about 10% the power of a Nissan Leaf --- which translates into somewhere between 1,000 and 2,000 mpg electric equivalent.  The vehicle has a top speed of 20mph, goes for 30 miles on a charge, and requires so little power to recharge it's not worth metering: someone once e-biked across Canada using only $10 of electricity.

    So there it is.  The electric bicycle is the most energy-efficient, lowest carbon-footprint way to get around that's known to mankind.  Eco-warriors, take note.  Even if you charge up your bike on the dirtiest coal-fired power you can find, your carbon footprint on an electric bike is still almost too small to measure.  Even better, e-bikes are blast to ride, and they get you across the Hudson River for free!

    Summary

    What are the take-away points for this, if you personally want to lower your carbon footprint?  It's pretty simple:
    1. Arrange your live so you don't have to travel as far.  See if you can live close to where you work, etc.
    2. Ride the bus if it saves you time, money or aggravation.
    3. Plan on spending $25K for your next car, which should be a hybrid and get at least 45-50 mpg, even in the city.  This is less than the average $30K spent on new automobiles in America today.
    4. Go get an electric bike, and ride it wherever you find it to be practical.  You will make the money back very quickly in lowered costs of gasoline, wear-and-tear, tolls, etc.
    5. Get involved in your local government to adopt a complete streets policy --- on that provides safe bicycle facilities in your town.
    This article is Copyright (c) 2012 by Bob Fischer.  Unauthorized use and/or duplication of this material without express and written permission from this article is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Bob Fischer and The Jersey Biker with appropriate and specific direction to the original content.