Showing results for 
Search instead for 
Do you mean 

How to use the code opening feature in LMS Imagine.Lab Amesim

by Siemens Theorist Siemens Theorist on ‎03-17-2017 12:05 PM - edited

Purpose

Modeling complex phenomenon such as heat transfer or pressure drop sometimes requires using specific correlations representing companies’ know-how in the domain.

The code opening feature allows you replacing LMS Imagine.Lab Amesim standard correlations for heat transfer and pressure drop with your own ones (empirical or from literature) and share them with third parties while ensuring IP protection.

This feature is currently available for some generic heat transfer/pressure drop components and a generic tool was designed to help the user: the dynamic library compiler tool.

Dynamic library compiler tool

The dynamic library compiler tool guides you through the different steps of the external function creation:

  1. Get a source code template,
  2. Edit the code,
  3. Compile the external function,
  4. Get your model ready to use it.

pict_01.png

 

Launching the tool

When available, an “external user-defined function” option appears for heat exchange or pressure drop definition.

pict_02.png

 

Selecting this option leads to a dedicated parameter group display.

pict_03.png

  

This editable parameter group is composed of:

  • a link to launch the dynamic library compiler tool,
  • the user-function path.

 

Source code loading and saving

The "New" button allows loading and saving the source code skeleton.

 

pict_04.png

  

A preview of the code is displayed in the tool (read-only).

 

Source code opening

The "Open" button allows browsing and opening a previously modified external function file.

 

pict_05.png

 

Source code edition

The “Edit” button allows opening the source code into the preferred '.c' file editor for modification.

 

pict_06.png

 

 

Find bellow an example reproducing the standard heat transfer correlation for circular pipe:

 

pict_07.png

 

 

Note that the reserved zone for private code allows you focusing on the correlation definition. Inputs/outputs management is already handled by the skeleton.

A large number of available LMS Amesim documented public utilities can be directly used. Math expressions are recognized too.

 

Compilation process

Once modified, the external function has to be compiled to be well interpreted by the component at run time.

The compilation follows three steps:

 

pict_08.png

 

  • Compiler selection

Select an available compiler on your current installation.

Tips: Prefer using the same compiler as the one set for the sketch compilation.

 

  • Compilation launch

Use the "Compile" button to launch the complete compilation process.

 

  • Compilation status

The compilation process appends the log window with every available information.

Tips: Those displayed information are important for compilation failure understanding and code correction.

 

Apply the created external function

Once created, the dynamic library embedding the external function is to be applied to the component.

Using the "Apply and close" button allows applying the file path to the dynamic library related text parameter.

 

pict_09.png

 

 

pict_10.png

Conclusion

As illustrated in this article, to create an external user-defined function in LMS Amesim, these steps must be followed:

  • Select the “external user-defined function” option
  • Launch the tool
  • Get a “New” template
  • “Edit” the source code
  • Launch the compilation process
  • Apply the created file path to component parameters

This external function definition allows validating the implemented correlation at once and then sharing it. This file can be used into several components on a same sketch.

Comments
by Enthusiast
on ‎06-15-2017 12:50 AM

Hi, FMT_THM 

I had a problem while i use the AMESet to make a component , I want to use the function "tpf_thermo_2" to get the "h, fluid specific enthalpy in the fluid ",but i don't konw what's meaning of "com,comunication index of capacitive element",is it means the "com index at port~"?

in the function "tpf_thermo_2" the "com" is "int ".but in the component the "com index at port~" is "double"?

thanks!

function1.pngcom index at port 1.pngcom index at port is double.pngfunction need int.png

by Siemens Theorist Siemens Theorist
3 weeks ago

Hi wangxiaobo,

 

LMS Ameset only enables to declare doubles as port input/output.
This TPF communication index allows to identify every capacity with a unique identifier and accessing properly its properties.

 

To use those indexes as "int" inputs, we usually cast those variables:
   int comIdx1 = (int)(*com1);

Then use it:

   tpf_thermo_2_(&comIdx1, ...);

 

PS: sorry for the late answer, no alert/notification was active on this article. I will keep an open eye on it plus force notifications on this article.

 

Regards,

FMT_THM