Starting from version 3.11 of Arcane, it is possible to define dataset functions in C#. There are two types of functions:
Example Example of using C# functions for the dataset shows how to use user functions in C#.
To define dataset functions in C#, the user must define a class containing a set of public methods whose signature matches that of a dataset function. In this case, Arcane generates a dataset function whose name is that of the corresponding method.
Valid signatures are those corresponding to methods that take an argument of type double or Int32 and return a type of double or Int32.
For example, with the following code, there will be 2 user functions
Advanced functions must be called directly by C++ code. The IStandardFunction interface allows retrieving a pointer to these methods. There are 4 possible prototypes:
For a simple dataset option, it is possible to retrieve the IStandardFunction instance via the CaseOptionSimple::standardFunction() method.
For example, if the dataset option node-velocity must have a function with the signature f(Real,Real3) -> Real3, we can retrieve the instance and use it as follows:
The functor instance is not modified during the calculation. It is therefore possible to keep it between iterations.
The arcane_dotnet_compile command, available in the bin directory of the Arcane installation, allows compiling a C# file into an assembly (.dll) which will be placed in the current directory. The name of the assembly is the name of the compiled file without the .cs extension. The compiled file is platform-independent, so it only needs to be compiled once.
You must then reference this assembly in the .arc file within the <functions> element at the root of the dataset:
When running the calculation, you must specify the argument -A,UsingDotNet=1 so that the .Net environment is used and the Functions.dll assembly is loaded. If the assembly name is relative (for example, on Linux it does not start with /), the assembly must be located in the current execution directory.
Once the assembly is loaded, Arcane will create an instance of the class specified in the <class-name> element. It is therefore possible to have a constructor in this class, and it will be used. The class may be located in a namespace. In this case, you must specify the full name in <class-name>, such as MyNamespace.MyClass.