SamUL: return value for PTOptimize() ?

  • solarjoe
  • Topic Author
More
07 Jan 2013 14:27 #1121 by solarjoe
SamUL: return value for PTOptimize() ? was created by solarjoe
Hello,

I am using SamUL for parameter studies on power tower systems.

According to the documentation there is no return value for the
PTOptimize().

What happens if there is an error during the optimization?

Will SAM continue using the variables from
the prevoius run that are still present in the text boxes?
Or will it stop showing the error in the console window?

Kind regards,
Joe

Please Log in or Create an account to join the conversation.

  • solarjoe
  • Topic Author
More
08 Jan 2013 16:25 #1122 by solarjoe
Replied by solarjoe on topic SamUL: return value for PTOptimize() ?
Hello,

I just gave it a try and found out that PtOptimize returns a string.
(According to the docs it returns nothing...)

test = PtOptimize()
outln(test)

results in

Set Tower Height: 235.56 m
,Set Receiver Height: 18.93 m
,Set Receiver Diameter: 14.5 m
,Updated Heliostat Field (Span=360).

Well, one could use a little string processing to get a usable
exit code from this, BUT the string does not change if the
optimizer fails...strange.
Can someone please give it a try and see if this is reproduceable?

Kind regards,
Joe


Please Log in or Create an account to join the conversation.

  • Paul Gilman
More
08 Jan 2013 17:13 #1123 by Paul Gilman
Replied by Paul Gilman on topic SamUL: return value for PTOptimize() ?
Dear Joe,

The ptoptimize() function does not return an error code or message to indicate whether or not it ran successfully. In your script, the value of test is false regardless of whether ptoptimize() runs or fails.

The following script sample confirms that:

BEGIN SAMPLE SCRIPT

setactivecase("test")

'run
SetInput("csp.pt.opt.max_tower_height", 100)
results = ptoptimize()
outln(results)

'fail
SetInput("csp.pt.opt.max_tower_height", 1000)
results = ptoptimize()
outln(results)

END SAMPLE SCRIPT

The output is:

BEGIN OUTPUT

false
false

END OUTPUT

We are looking into this to see if there is a way for the function to return useful information. (In case you are interested, ptoptimize() runs the PTGEN code, which is written in FORTRAN, while the rest of SAM is written in C++. To have ptoptimize() return error messages, we have to capture the FORTRAN error messages and present them in C++.)

Here's a crude workaround to see if ptoptimize() runs or fails: Because the SetInput() function actually changes the values you see on the SAM input pages, you can run your script, and then go to the Heliostat Field page, click Start Wizard and confirm that the values from your script are in the input fields, and then run the wizard to see if it fails.

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

  • solarjoe
  • Topic Author
More
09 Jan 2013 07:29 #1124 by solarjoe
Replied by solarjoe on topic SamUL: return value for PTOptimize() ?
Hello Paul,

thanks for your quick response.

Well, it would be good to have a reliable exit code.
We would like to run some parameter studies and
found out that SAM does not quit if the
optimization fails if SamUL is used.

It just continues using the values from the previous run.

I gave it a try again, and PtOptimize() really returns a string
in my script. (SAM 2012.11.30)

Your example returns

---
Set Tower Height: 235.56 m
,Set Receiver Height: 18.93 m
,Set Receiver Diameter: 14.5 m
,Updated Heliostat Field (Span=360).

Set Tower Height: 235.56 m
,Set Receiver Height: 18.93 m
,Set Receiver Diameter: 14.5 m
,Updated Heliostat Field (Span=360).
---

which is the same thing that I ran into before:
no matter if the optimization runs or fails ( I checked manually)
the same string is returned.

One thing that might be an acceptable workaround is to set

- Tower Height
- Receiver Height
- Receiver Diameter
- Heliostat Field

to dummy values before the optimitation and check if they were
changed.

I will give that a try...

Kind regards,
Joe

Please Log in or Create an account to join the conversation.

  • solarjoe
  • Topic Author
More
09 Jan 2013 10:14 #1125 by solarjoe
Replied by solarjoe on topic SamUL: return value for PTOptimize() ?
Hello again,

just one more comment:

If a previous optimization was successful and a current one fails
SAM might use the result files from the previous one.
They are located in

%APPDATA%\SAMEXE\SAMEXE-yourusername-INST1-2012.11.30\simdata\ptwizard

and are called
"SAM_Tower_DELSOL.inc"
"toSAM.dat"

If a new optimization is started the ptwizard directory is not wiped
these files are still present. So if an optimization fails
SAM will still find the result files and take them.

A fix in SAM would be to completely wipe the ptwizard directory before
each run.

In SamUL this can be achieved using DeleteTempFiles().

Kind regards,
Joe

Please Log in or Create an account to join the conversation.

  • Paul Gilman
More
10 Jan 2013 00:15 #1126 by Paul Gilman
Replied by Paul Gilman on topic SamUL: return value for PTOptimize() ?
Hi Joe,

We've made some changes to the
ptoptimize()
function to make it more useful. These changes will be part of the update we plan to release next week (around January 17th).

In the new version,
ptoptimize()
returns
true
when it runs successfully, and
false
when it fails. A new function,
ptgetoutput()
shows the PTGEN output to help with troubleshooting.

Here is sample code you can use to test the function when the new version is available:



setactivecase("tower")

outln("trying with SM = 2.4...")

SetInput("csp.pt.rec.solar_multiple",2.4) 'Set the solar multiple
ok = ptoptimize()
outln("ptgen result? " + ok )
text = ptgetoutput()
outln("output=\n" + text)

outln("")

outln("trying with SM = 8...")

SetInput("csp.pt.rec.solar_multiple",8) 'Set the solar multiple
ok = ptoptimize()
outln("ptgen result? " + ok )
text = ptgetoutput()
outln("output=\n" + text)


And the resulting output:



trying with SM = 2.4...
ptgen result? true
output=
PTGEN VERSION 27SEP12
Optimizing plant dimensions...
Optimization successful!
PTGEN SUCCESS
Set Tower Height: 203.33 m
Set Receiver Height: 20.41 m
Set Receiver Diameter: 17.67 m
Updated Heliostat Field (Span=360).

trying with SM = 8...
ptgen result? false
output=
PTGEN VERSION 27SEP12
Optimizing plant dimensions...

OPTIMIZATION ERROR!

DELSOL3 failed to produce an optimized plant design with the given parameters.
The maximum possible power level for any receiver with a 250.0 [m] tower
height is 1111.80 [MWth]. The max possible power level for a receiver with
diameter 23.00 [m] and with height 36.80 [m] is 1048.95 [MWth]. The minimum
power of interest is 2233.00 [MWth].

Based on this information, the following recommendations apply:

>>> It is likely that both the maximum tower height and the maximum
        receiver dimensions are insufficient for this power level.
>>> Increase the maximum tower height and the maximum receiver
        diameter and height.
>>> If these recommendations are unsuccessful, the maximum heliostat
        field diameter may be too low, or the maximum flux on the receiver
        may be too low.
Failed to invoke


I hope that helps. Happy SamULing!

Best regards,
Paul.

Please Log in or Create an account to join the conversation.

Moderators: Paul Gilman
Powered by Kunena Forum