Maker Pro
Maker Pro

Ported pvwatts results

C

Curbie

Jan 1, 1970
0
I'm porting NREL's pvwatts.c (version 1) to Visual Basic for
Applications (VBA) so I can use Typical Meteorological Year version 3
(TMY3) data for 1020 reporting stations. Summaries of TMY3 data along
with the ported pvwatts code are intended for use in an Excel
spread-sheet, hence the VBA port.

I choose pvwatts so I verify my code against a known standard before
using the ported functions for my spread-sheet's needs. The ported
code's monthly results seems to match NREL's results given compiler
float point differences, but the ported code's daily results are off?

My questions are:
1) Has anyone done this port before, is this the best results I
can expect given compiler float point differences?
2) Does this look like a porting bug or just float point
differences?

Any help would be appreciated.

Thanks,

Curbie

My Results <<<<<<<<<<<<<<<<<<<<<<<<<<
Station Identification
WBRS#: 26451
City: Anchorage
State: Alaska
Latitude(deg): 61.16667
Longitude(deg): -150.0167
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4
Array Type: Fixed Tilt
Array Tilt(deg): 61.16667
Array Azimuth(deg): 180
Energy Cost(cents/kWh): 0.124

Energy Production

Month Rad. AC kWh
(kwh) (kwh) cost
1 0.83 095 11.78
2 2.16 245 30.38
3 3.74 469 58.16
4 4.31 506 62.74
5 4.82 569 70.56
6 4.68 511 63.36
7 4.45 496 61.50
8 3.75 418 51.83
9 3.25 362 44.89
10 1.88 218 27.03
11 1.39 163 20.21
12 0.61 066 08.18
----------------------------
Yearly 2.99 4111 509.76

1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 1 1 0 0 0 0 0
7 0 0 0 0 1 1 1 1 0 0 0 0
8 0 0 1 1 1 1 1 1 0 0 0 0
9 0 1 8 3 8 9 5 2 1 1 1 0
10 1 5 23 15 22 23 16 13 10 4 4 1
11 6 22 40 31 36 35 28 22 21 14 19 2
12 11 34 47 47 49 45 41 35 35 22 27 12
13 20 42 60 56 61 50 49 46 42 28 31 16
14 19 42 57 62 62 56 53 47 46 32 26 15
15 16 38 60 60 65 52 54 47 48 29 22 9
16 7 28 48 54 55 50 50 46 41 27 10 2
17 1 12 28 48 47 47 43 37 34 17 1 0
18 0 1 11 33 35 33 35 29 21 7 0 0
19 0 0 1 16 20 21 23 15 10 1 0 0
20 0 0 0 3 5 8 8 3 1 0 0 0
21 0 0 0 1 1 2 1 1 1 0 0 0
22 0 0 0 0 1 1 1 1 0 0 0 0
23 0 0 0 0 0 1 1 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0


NREL Results <<<<<<<<<<<<<<<<<<<<<<<<<<
Station Identification
WBAN#: 26451
City: ANCHORAGE
State: AK
Latitude(deg): N 61.17
Longitude(deg): W150.02
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4.0
Array Type: Fixed Tilt
Array Tilt(deg): 61.1
Array Azimuth(deg): 180.0

Energy Cost(cents/kWh): 12.4

Energy Production
1 0.83 95 11.78
2 2.16 244 30.26
3 3.77 469 58.16
4 4.35 506 62.74
5 4.88 569 70.56
6 4.74 511 63.36
7 4.51 495 61.38
8 3.78 417 51.71
9 3.28 361 44.76
10 1.88 216 26.78
11 1.39 163 20.21
12 0.61 66 8.18
Year 3.02 4112 509.89


1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 1 0 0 0 0 0 0
9 0 0 7 2 7 8 4 1 0 0 0 0
10 0 4 23 15 22 22 16 12 9 3 4 0
11 6 21 40 31 35 34 28 22 21 14 19 2
12 11 33 46 47 48 45 40 35 34 21 26 11
13 19 41 60 56 60 49 49 46 41 27 31 15
14 19 42 57 61 62 56 52 46 45 31 25 15
15 15 37 59 59 64 51 53 46 47 29 21 9
16 6 27 48 54 55 50 50 45 40 26 9 1
17 1 11 27 47 47 47 42 37 33 17 0 0
18 0 1 10 33 35 33 34 29 20 6 0 0
19 0 0 0 15 19 20 22 14 9 0 0 0
20 0 0 0 2 5 8 8 3 0 0 0 0
21 0 0 0 0 0 1 1 0 0 0 0 0
22 0 0 0 0 0 0 0 0 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0
 
M

Martin Riddle

Jan 1, 1970
0
Could be either, usually FP errors are small and can be largely ignored
for the application.
A Double is a IEEE 64 bit number, are you porting from a 32bit float?
Run some calculations by hand, You may be more accurate in your port
than the original pvwatts.

Cheers
 
C

Curbie

Jan 1, 1970
0
Could be either
That's my trouble, I'm scratching my head.
usually FP errors are small and can be largely ignored
for the application.
Ok, good.
A Double is a IEEE 64 bit number Correct?

are you porting from a 32bit float?
Yes, just a few cases of doubles, mostly floats, but a pile of them.
c float = VBA Single
c double = VBA Double
Run some calculations by hand
I've run both c and VBA debuggers side-by-side and single-stepped
through 24 hours of data over the last week and found both porting
bugs (me) and compiler differences which I corrected with functions,
still not getting exactly matching results, real close, but not exact.
You may be more accurate in your port than the original pvwatts.
All I want is to be AS accurate to verify the port, they know what
there're doing with solar energy, I know some programming but solar
energy math, not so much.

Martin, thanks for your time and help, but I'm still in the mud on
this, maybe others can help clear this up a little?

Curbie
 
C

Curbie

Jan 1, 1970
0
What if you avoid the Single and just use Double for the float.
The results are the same (see below).
Another thing to try is to compile pvwatts in c and run that exe. It
will tell you if there is a compiler FP issue.
The pvwatts results are from a local compiled pvwatts.exe, I’m not
sure what compiler issue you’re referring to? The compiler
differences I was referring to has to due with how different compile
internally seeds, rounds, and utilizes FP co-processor results.
You do know that the hardware FP is 80 bits wide.
No I didn’t, is been a long time since I played with hardware.
There are some differences between MS and other compilers.
That’s the focus of question, it seems to me that I either have a
porting bug, which I can fix (if I can find it) or the variations are
due to compiler differences, which I can’t fix. Which one is the
question?
Good Luck
Thanks for your time and help.
Back at cha.

Curbie

Singles<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Station Identification
WBRS#: 26451
City: Anchorage
State: Alaska
Latitude(deg): 61.16667
Longitude(deg): -150.0167
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4
Array Type: Fixed Tilt
Array Tilt(deg): 61.16667
Array Azimuth(deg): 180
Energy Cost(cents/kWh): 0.124

Energy Production

Month Rad. AC kWh
(kwh) (kwh) cost
1 0.83 095 11.78
2 2.16 245 30.38
3 3.74 469 58.16
4 4.31 506 62.74
5 4.82 569 70.56
6 4.68 511 63.36
7 4.45 496 61.50
8 3.75 418 51.83
9 3.25 362 44.89
10 1.88 218 27.03
11 1.39 163 20.21
12 0.61 066 08.18
----------------------------
Yearly 2.99 4111 509.76

1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 1 1 0 0 0 0 0
7 0 0 0 0 1 1 1 1 0 0 0 0
8 0 0 1 1 1 1 1 1 0 0 0 0
9 0 1 8 3 8 9 5 2 1 1 1 0
10 1 5 23 15 22 23 16 13 10 4 4 1
11 6 22 40 31 36 35 28 22 21 14 19 2
12 11 34 47 47 49 45 41 35 35 22 27 12
13 20 42 60 56 61 50 49 46 42 28 31 16
14 19 42 57 62 62 56 53 47 46 32 26 15
15 16 38 60 60 65 52 54 47 48 29 22 9
16 7 28 48 54 55 50 50 46 41 27 10 2
17 1 12 28 48 47 47 43 37 34 17 1 0
18 0 1 11 33 35 33 35 29 21 7 0 0
19 0 0 1 16 20 21 23 15 10 1 0 0
20 0 0 0 3 5 8 8 3 1 0 0 0
21 0 0 0 1 1 2 1 1 1 0 0 0
22 0 0 0 0 1 1 1 1 0 0 0 0
23 0 0 0 0 0 1 1 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0

Doubles<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Station Identification
WBRS#: 26451
City: Anchorage
State: Alaska
Latitude(deg): 61.1666679382324
Longitude(deg): -150.016662597656
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4
Array Type: Fixed Tilt
Array Tilt(deg): 61.16667
Array Azimuth(deg): 180
Energy Cost(cents/kWh): 0.124

Energy Production

Month Rad. AC kWh
(kwh) (kwh) cost
1 0.83 095 11.78
2 2.16 245 30.38
3 3.74 469 58.16
4 4.31 506 62.74
5 4.82 569 70.56
6 4.68 511 63.36
7 4.45 496 61.50
8 3.75 418 51.83
9 3.25 362 44.89
10 1.88 218 27.03
11 1.39 163 20.21
12 0.61 066 08.18
----------------------------
Yearly 2.99 4111 509.76

1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 1 1 0 0 0 0 0
7 0 0 0 0 1 1 1 1 0 0 0 0
8 0 0 1 1 1 1 1 1 0 0 0 0
9 0 1 8 3 8 9 5 2 1 1 1 0
10 1 5 23 15 22 23 16 13 10 4 4 1
11 6 22 40 31 36 35 28 22 21 14 19 2
12 11 34 47 47 49 45 41 35 35 22 27 12
13 20 42 60 56 61 50 49 46 42 28 31 16
14 19 42 57 62 62 56 53 47 46 32 26 15
15 16 38 60 60 65 52 54 47 48 29 22 9
16 7 28 48 54 55 50 50 46 41 27 10 2
17 1 12 28 48 47 47 43 37 34 17 1 0
18 0 1 11 33 35 33 35 29 21 7 0 0
19 0 0 1 16 20 21 23 15 10 1 0 0
20 0 0 0 3 5 8 8 3 1 0 0 0
21 0 0 0 1 1 2 1 1 1 0 0 0
22 0 0 0 0 1 1 1 1 0 0 0 0
23 0 0 0 0 0 1 1 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0
 
C

Curbie

Jan 1, 1970
0
Martin,

Finally after two more days of debugging, I’m pretty clear on my
questions.

This is the best results I can expect and the differences remaining
are due to compiler float point implementations.

I’m a little troubled that the differences in available radiation
(Rad. kWh) between my port and the NREL standard seem to grow the more
available radiation there is, but I’m pretty certain now that this is
due to compiler float point implementations and there is nothing I can
do about it.

After all this test was on Anchorage Alaska I’ll may end up revisiting
the debugging depending on the differences for sunny places like
Miami, but for now I’m going to optimize the port for VBA and test
changes against this. As soon as I’m through optimizing and cleaning,
I’ll test other locations.

I’m more comfortable that my available radiation results are slightly
less than instead of slightly more than NREL’s, I’d rather be on safe
side.

Thanks again for your time and help, sometimes a little encouragement
goes a long way.

Have fun.

Curbie

(Me)***********************************************************
Station Identification
WBRS#: 26451
City: Anchorage
State: Alaska
Latitude(deg): 61.16667
Longitude(deg): -150.0167
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4
Array Type: Fixed Tilt
Array Tilt(deg): 61.16667
Array Azimuth(deg): 180
Energy Cost(cents/kWh): 0.124

Energy Production

Month Rad. AC kWh
(kwh) (kwh) cost
1 0.83 095 11.78
2 2.16 245 30.38
3 3.74 469 58.16
4 4.31 506 62.74
5 4.82 569 70.56
6 4.68 511 63.36
7 4.45 496 61.50
8 3.74 417 51.71
9 3.25 362 44.89
10 1.87 217 26.91
11 1.39 163 20.21
12 0.61 066 08.18
----------------------------
Yearly 2.99 4110 509.64

1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 1 0 0 0 0 0 0
9 0 0 7 2 7 8 4 1 0 0 0 0
10 0 4 23 15 21 22 16 12 9 3 4 0
11 6 21 40 31 35 34 28 22 21 14 19 2
12 11 33 46 47 48 45 40 35 34 21 26 11
13 19 41 60 56 60 49 49 46 41 27 31 15
14 19 42 57 61 61 56 52 46 45 31 25 15
15 15 37 59 59 64 51 53 46 47 29 21 9
16 6 27 48 54 55 50 50 45 40 26 9 1
17 1 11 28 47 47 47 42 37 33 17 0 0
18 0 1 10 33 35 33 34 29 20 6 0 0
19 0 0 0 15 19 20 22 14 9 0 0 0
20 0 0 0 2 5 8 8 3 0 0 0 0
21 0 0 0 0 0 1 1 0 0 0 0 0
22 0 0 0 0 0 0 0 0 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0

(NREL)*********************************************************
Station Identification
WBAN#: 26451
City: ANCHORAGE
State: AK
Latitude(deg): N 61.17
Longitude(deg): W150.02
Elevation(m): 35

PV System Specifications
AC Rating(kW): 4.0
Array Type: Fixed Tilt
Array Tilt(deg): 61.2
Array Azimuth(deg): 180.0

Energy Cost(cents/kWh): 12.4

Energy Production
1 0.83 95 11.78
2 2.16 244 30.26
3 3.77 469 58.16
4 4.35 506 62.74
5 4.88 568 70.43
6 4.74 510 63.24
7 4.50 495 61.38
8 3.77 417 51.71
9 3.28 361 44.76
10 1.88 216 26.78
11 1.39 163 20.21
12 0.61 66 8.18
Year 3.02 4110 509.64


1 0 0 0 0 0 0 0 0 0 0 0 0
2 0 0 0 0 0 0 0 0 0 0 0 0
3 0 0 0 0 0 0 0 0 0 0 0 0
4 0 0 0 0 0 0 0 0 0 0 0 0
5 0 0 0 0 0 0 0 0 0 0 0 0
6 0 0 0 0 0 0 0 0 0 0 0 0
7 0 0 0 0 0 0 0 0 0 0 0 0
8 0 0 0 0 0 1 0 0 0 0 0 0
9 0 0 7 2 7 8 4 1 0 0 0 0
10 0 4 23 15 22 22 16 12 9 3 4 0
11 6 21 40 31 35 34 28 22 21 14 19 2
12 11 33 46 47 48 45 40 35 34 21 26 11
13 19 41 60 56 60 49 49 46 41 27 31 15
14 19 42 57 61 62 56 52 46 45 31 25 15
15 15 37 59 59 64 51 53 46 47 29 21 9
16 6 27 48 54 55 50 50 45 40 26 9 1
17 1 11 27 47 47 47 42 37 33 17 0 0
18 0 1 10 33 35 33 34 29 20 6 0 0
19 0 0 0 15 19 20 22 14 9 0 0 0
20 0 0 0 2 5 8 8 3 0 0 0 0
21 0 0 0 0 0 1 1 0 0 0 0 0
22 0 0 0 0 0 0 0 0 0 0 0 0
23 0 0 0 0 0 0 0 0 0 0 0 0
24 0 0 0 0 0 0 0 0 0 0 0 0
 
C

Curbie

Jan 1, 1970
0
Bob,

Bio-fuel in the morning, PV in the evening, you get around.
Things to look for: Go thru the source and look for any parenthesized
expression that doesnt have a decimal point in it.... this expression
would get evaluated as an int, even if the result was promoted to
double later.
I ran into that twice during single-step debugging, but couldn't
categorize the issue well enough to make changes by just reading the
code. After two days (my 3rd. go round) of debugging, I'm pretty sure
the remaining small differences are just compiler FP implementation
differences iterated of bunch of times.

I ran C and VBA debuggers side-by-side and single-stepped through
thousands of steps, I'm not saying it's perfect as is sits, but for
now it's time to clean-up and optimize against the results I have.
After that, I'll run tests on different latitude/longitude extremes
(four counters and center of the country along with Hawaii),
daylight-saving-time areas, looking for some larger differences which
should be easier follow and debug.

Did you know that you can use either sodium hydroxide or potassium
hydroxide for the transesterification, potassium hydroxide can be
home-made from wood ash?

Have fun.

Curbie
 
C

Curbie

Jan 1, 1970
0
Bob,

Better yet...

Pvwatts version 1 directory index is here"
http://rredc.nrel.gov/solar/codes_algs/PVWATTS/version1/US/code/versions/
pvwatts.c

Be sure to grab these guys too, you'll need them:
electric.dat
pvsystem.dat
pvweb.dat
station.num


Typical Meteorological Year (TMY2) data, download from the National
Renewable Energy Laboratory (NREL) web-site here:
http://rredc.nrel.gov/solar/old_data/nsrdb/tmy2/

If you want to play with TMY3, not directly compatible with pvwatts,
but 1020 stations instead of 239 makes it worth the effort (IMO).
Typical Meteorological Year (TMY3) data, download from the National
Renewable Energy Laboratory (NREL) web-site here:
http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/tmy3/

There is also a pvwatts 2 out there somewhere.

Have fun.

Curbie
 
C

Curbie

Jan 1, 1970
0
Thanks for the link.
No problem, all that stuff is supposed to be for the benefit of every
one, after all U.S. taxpayers paid for it.
I looked at the pvwatts.c file for a while. One
thing that seemed sloppy was they defined DTOR (degrees to radians)
in 3 or 4 different functions, and I think one place it was float and
another it was double. Same with pi. The place where its declared as a
float its initialized with 7 or 8 digits which is plenty for a float,
but once again, they have it defined as a double in another function,
BUT ITS STILL INITALIZED the same way!. I'd also make 273.15 a const
and give it a name and a few other picky little OCD style preferences.
I agree with your queasiness about some of the programming, one thing
I've learned from all the ports I've done over the years is to port
exactly bug and all, once I get matching results and ONLY when (and
if) I've learned enough about the program do I implement fixes.

I get the impression that whoever wrote pvwatts was more of a
scientist capable of and more worried the complex math, than a
programmer worried about clean coding. But I just don't know why
pvwatts was written the way it was, and the math is complex enough
where it going to take a lot reading before attempt to implement a
fix.

Solpos.c was well written, commented, and documented (packet with
references) and was a dream to port, pvwatts was a nightmare to port.

Are you a lunix guy?
If so what distribution do you recommend for home users (GUI)?

I'm thinking about setting up lunix on one of my machines for the
Internet, and dropping my Windows machines back to Win 2000 pro which
I have on CD.

Thanks for the light.

Curbie
 
Top