Articles on this page:



How do I set the Peakedness parameter for JONSWAP waves via the Project API?

Bladed versions affected:
4.8 onwards

Last updated:
25 November 2024

Problem

Most of the wave parameters can be set in the API using code such as that in the Python example below (the C# version is analogous):

# set waves to irregular
prj.Environment.Sea.TimeVaryingWaves.ModelType = 2
# set spectral model type to JONSWAP
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.WaveType = 0
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Height = Hs
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Period = Tp
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Peakedness = Gamma # doesn't work!
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.RandomSeed = RandomSeed 
prj.Environment.Sea.TimeVaryingWaves.Direction = Mdir
print (prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Height)
print (prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Period)
# print (prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Peakedness) this throws an error

However, the Peakedness parameter is not handled correctly and will throw an error if you try to read it. You can set it without an error in Python, but the value won't be recognised by Bladed.

Solution

This is a known bug which will be fixed in due course. The answer is to use a different part of the API data model (the "Legacy" model).

Replace this line:
prj.Environment.Sea.TimeVaryingWaves.IrregularWaves.Peakedness = Gamma

with this one:
prj.LegacyModel.OldWAVES.fGamma = Gamma

Keywords

Peakedness; Gamma; JONSWAP; Irregular; Waves; API


Back to top

Python version compatibility for Project and Batch APIs

Bladed versions affected:
All current 4.x versions

Last updated:
1 September 2022

Problem

An error occurs at the following script line, when trying to access the Project API or Batch API using Python:

clr.AddReference('GH.Bladed.Api.Facades')

The error message that appears may be similar to:

FileNotFoundException: Unable to find assembly 'GH.Bladed.Api.Facades' in Python.Runtime.CLRModule.AddReference(String name)

Solution

When using the Project API or Batch API with Python, it is important to note that only 32-bit versions of Python can be used – 64-bit versions of Python cannot be used. If the script is run using a 64-bit version of Python the error above may be shown. Note that the error message is misleading - the 'GH.Bladed.Api.Facades' file may have been found, but it cannot be loaded (i.e. due to the 32/64-bit incompatibility).

Furthermore, use of the APIs requires the Python.NET package, which is officially compatible up to Python 3.8.

Therefore, it is recommended that the highest version of Python that is used with the Bladed APIs is the 32-bit version of 3.8.

Keywords

Project; Batch; API; Python; 32-bit; 64-bit


Back to top

Exception occurs calling DotNetArrayToNumpy() function in Python Results API v1

Bladed versions affected:
All current 4.x versions

Last updated:
20 March 2023

Problem

An exception is thrown at the following line within the DotNetArrayToNumpy() function in the Python implementation of Results API v1 (in the ResultsApiUtils.py file):

src_ptr = dotNetArray.PointerToFirstElement.ToInt32()

The exception is:

AttributeError: 'IDisposableReadOnlyList[Double]' object has no attribute 'PointerToFirstElement'

Solution

This exception occurs if version 3.0.1 (or later) of the pythonnet package is being used.

Please downgrade the version of the pythonnet package to version 2.5.2.

Keywords

Python; Results API v1; pythonnet


Back to top

Tip to locate the required Project API parameter

Problem

It may be not easy to find the required API in the BladedAPIReference.chm file. How to quickly find the required Project API parameter?

Solution

There is a tip to use project XML file to locate the parameter. It can be found on the Bladed API user manual Appendix D.1. The user manual is under the Bladed installation folder. For example, C:\DNV\Bladed 4.x\Documentation\Bladed API by default. Here is an example package, in which the current definitions are modified via APIs.

The detailed steps:

  1. In the Bladed GUI screen, load a basis project. Save this project file with name a.prj.

  2. In the Bladed GUI screen, find the input parameter of interest and set its value to a value that is different from the basis project. Save it with name b.prj. In the example package, the current definition is changed.
    "Tip to locate the required Project API parameter" article figure 1

  3. In the Project API, set the PreserveTempSubdirectoryContainingXmlProjectOnGetProject setting to true.

  4. In the Project API, call GetProject twice, once to load a.prj and again to load b.prj. This will result in two XML files being stored on the file system. See the example script file.

  5. To locate the XML files, check the API log output.

    "Tip to locate the required Project API parameter" article figure 2

  6. Compare the two XML files. According to the XML file structure, the required API for the current can be located. For example here, the near surface velocity is: prj.Environment.Sea.Currents.NearSurfaceVelocity

    "Tip to locate the required Project API parameter" article figure 3

Keywords

Project API


Back to top

How to add encrypted project files into Batch using the Project API

Bladed versions affected:
4.9 onwards

Last updated:
18 August 2023

Problem

Using the Project API to add an encrypted project into Batch fails.

Solution

First, turn on this option in the beginning of the API script:
Bladed.ProjectApi.Settings.SuppressEncryptionException = True

Then, the API falsely expects a PASSWORD keyword in the .prj file. It expects to see this after the NOTES keyword.

Example 1: if there is no "Project Info" data defined in the encrypted project, take the demo_a model as an example (see the following figure). Open the .prj file in a text format, and manually add the keyword PASSWORD. Please note there is a "tab" after the keyword PASSWORD. Save the .prj file. Then load it with Bladed API as usual.

"How to add encrypted project files into Batch using the Project API" article figure 1

Example 2: if there is "Project Info" data defined in the encrypted project, take the FloatingDemo model as an example (see the following figure). In the .prj file, the keyword PASSWORD is added after the line NOTES.

But the "Project Info" data has been removed. Users can add the "Project Info" back through the API. Please see the example code here.

"How to add encrypted project files into Batch using the Project API" article figure 2

Keywords

Project API; Encryption


Back to top

Convert output files from Bladed simulations to readable text files

Problem

How to turn a loads variable into an ASCII file?

Solution

Here is an example Python script with a possible example of turning a loads variable into an ASCII file. It requires the dnv-bladed-results Python package webpage which contains all needed instructions to install the package, and it includes examples.

#import ResultsAPi and Group processor
from dnv_bladed_results import ResultsApi, Group

#get the target run outputs
run = ResultsApi.get_run("C:\\DNV\\Bladed 4.16\\DemoModels\\IEA_15MW", "powprod")

#get all output groups (as seen in the results viewer)
all_groups = run.get_groups()

#find out what groups and variable names exist (same as in the results viewer):
group: Group 
for group in all_groups:
        print("Group:")
        print(group.get_name())
        print("Variables in group:")
        var_names = group.get_variable_names()
        print(var_names)
        print("-------")

print("######################################")

#get a time series variable (2D) , example Blade 1 loads Fx on the principal axes)
blade_1_fx = run.get_variable_2d("Blade 1 Fx (Principal axes)")
dependentVarUnit=blade_1_fx.get_siunit()
dependentVarName=blade_1_fx.get_name()
print(dependentVarName)
blade_1_fx_values = blade_1_fx.get_data_for_all_independent_variable_values()
print(blade_1_fx.get_data_for_all_independent_variable_values())

#Print all time stamps on the console
primaryIndVar = blade_1_fx.get_independent_variable(0)
primaryIndVarName = primaryIndVar.get_name()   # Returns 'Time'
primaryIndVarUnit = primaryIndVar.get_siunit()   # Returns 's'
print(primaryIndVarName)
print(primaryIndVarUnit)
time_stamps =blade_1_fx.get_independent_variable(0).get_values_as_number()
print(time_stamps)
#print all span locations on the console
secondaryIndVar = blade_1_fx.get_independent_variable(1)
secondaryIndVarName = secondaryIndVar.get_name()   # Returns 'Distance along blade'
secondaryIndVarUnit = secondaryIndVar.get_siunit()   # Returns 'm'
print(blade_1_fx.get_independent_variable(1).get_name())
span_locations = blade_1_fx.get_independent_variable(1).get_values_as_number()
print(span_locations)

#Print to a file a specific blade station time series:
with open('example_timeseries.csv', 'w') as file:
    file.write(str(" "))
    for index, span in enumerate(span_locations):
        file.write(";"+"Station "+str(index))

    file.write("\n"+secondaryIndVarName+" ["+secondaryIndVarUnit+"]")
    for span in span_locations:
        file.write(";"+str(span))
    
    file.write(str("\n"+primaryIndVarName +" ["+primaryIndVarUnit+"]"))
    for span in span_locations:
        file.write(";"+dependentVarName+" ["+dependentVarUnit+"]")

    for time_index,time in enumerate(time_stamps):
        file.write("\n"+str(time))
        for span_index, span in enumerate(span_locations):
            #write load value:
            file.write(";"+str(blade_1_fx_values[span_index][time_index]))

Keywords

Results API v2


Back to top