Python external function examples: Line stress external result

This topic is intended to be read in conjunction with the main external function documentation, and the example source code.

This ZIP file contains all of the Python external function examples, with each example contained in the appropriately named sub-folder.

This example uses the track calculation feature of the OrcaFlex bend stiffness variable data source to provide a custom line stress result. The track calculation feature allows an external function access to line node instantaneous calculation data without incurring the performance expense of having to calculate bend stiffness within the external function. The external function is specified as a tracking function in the bending stiffness data source on the variable data form.

This example comprises OrcaFlex file LineStressExternalResult.dat, Python script LineStressExternalResult.py and fatigue file ExternallyCalculatedStress.ftg. The OrcaFlex fatigue file is used in the fatigue analysis section below.

The custom stress result calculated by this example allows the user to specify tension and curvature stress factors as well as the component angle. To do this the function needs to log the curvature values and wall tension for each half segment. The curvature values are available from the info.InstantaneousCalculationData object provided by OrcaFlex to the TrackCalculation method. In this example the line has fifty segments of one line type which results in one hundred instances of the external function being created. There is one instance for each half segment.

Our single custom result is registered when the method RegisterResults is called, specifying the result name, External Stress, and the result units to appear on the OrcaFlex results selection form. Registration also supplies a numerical ID which OrcaFlex uses to refer to this result. Although this method will be called once for each instance, OrcaFlex only permits unique result IDs and ignores subsequent registrations. Following the call to RegisterResults, each instance's Initialise method is called. During Initialise a working data object (an instance of NodeHalfSegmentData) is created. We can't set the arc length in the Initialise method as this data is not provided until the call to TrackCalculation.

The TrackCalculation method is called once per log interval, before the call to LogResult. This method is passed the instantaneous data for the half segment in the info.InstantaneousCalculationData property. From this we can set the arc length and curvature values in our working data. In the following call to LogResult we query the model to obtain the wall tension at the half segment arc length. This data is logged with OrcaFlex by setting the info.LogData property and using the Python json module to convert the array of tension and curvature to a string.

When requesting this result from OrcaFlex, the user can specify stress factors for tension and curvature, and an angular position. These parameters are passed to the DeriveResult method in the info.ObjectExtra.ExternalResultText property. The parameter text needs to be in JSON format for this example. A tension and stress factor of 1.1 and 1.2 respectively with a theta of 45.0 degrees would be represented in the external result text as:

{"w": 1.1, "c": 1.2, "t": 45.0}

The DeriveResult method retrieves the saved log data for the current sample period from the info.LogData property and converts this back into Python values using the json module. Next the external result text is also parsed using json. Finally the stress result is calculated and returned to OrcaFlex by setting the info.Value property.

Using external stress for fatigue analysis

An externally calculated result variable can be consumed by the OrcaFlex fatigue module. This allows you to define a bespoke stress result in your Python code and let OrcaFlex calculate and collate fatigue damage.

An example of this can be found in the fatigue file ExternallyCalculatedStress.ftg. In order to carry out the fatigue analysis you need to create a load case simulation file. This is based on LineStressExternalResult.dat and so you will need to generate a dynamic OrcaFlex simulation file based on that data file.

Once you have generated the simulation file, open the .ftg file in the OrcaFlex fatigue module. Note that the damage calculation data is set to externally calculated stress. This is the setting that determines that an external results variable will be used.

Now switch to the Components page. This is very similar to the input data for stress factor fatigue. Indeed, the form of our external result was chosen so that we can compare against the built-in stress factor fatigue option.

The stress result data item is External Stress, i.e. the name of our external result variable. The component name data item is used to specify the external result text. In our example file this is:

{"w": 10, "c": 250e3, "t": %theta%}

The first and second values are the wall tension and curvature stress factors respectively. The final value is theta. Note that we use the special symbol %theta% rather than specifying a fixed value. The reason being that we extract multiple stress results, at different circumferential points, at each arc length along the line. When OrcaFlex calls the external function it replaces %theta% with the true theta value, in degrees, and then calls DeriveResult.

You can now calculate the fatigue for this input data and view results just as you would for any other OrcaFlex damage calculation.

Now switch the Damage Calculation to Stress factors. Note that the data has been setup to match that which we used for externally calculated stress. The tension stress factor is 10 and the curvature stress factor is 250e3. You can calculate fatigue now and confirm that the results are the same as we obtained using externally calculated stress.

One final point to make is that fatigue analysis is one of the most demanding calculations that OrcaFlex performs. Using externally calculated stress can lead to rather slow performance of the fatigue calculation. This is one scenario where the performance benefits of a native external function (see the C++ External Function Examples ) could out-weigh the convenience of Python.