Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
Example No. 3

With Example 3 and subsequent examples, we no longer use a singleton. So we will see a simple example of using the service normally.

Note that this example does the same thing as the previous examples.

.axl File – <options> Section

To start, let's look at the options of the .axl file:

SimpleTableOutputExample3.axl

<options>
<service-instance name="st-output" type="Arcane::ISimpleTableOutput">
<description>ST Output</description>
</service-instance>
</options>

In the .axl, we just declare the use of a service implementing the Arcane::ISimpleTableOutput interface.

.arc File – Module Option Section

Here is the corresponding .arc:

SimpleTableOutputExample3.arc

<simple-table-output-example3>
<st-output name="SimpleCsvOutput">
<tableDir>example3</tableDir>
<tableName>Results_Example3</tableName>
</st-output>
</simple-table-output-example3>

Here, compared to the previous example, we fill in the options in the service section. We request the use of the SimpleCsvOutput service with the two options it requires.

Initial Entry Point

Let's look at the start-init entry point:

SimpleTableOutputExample3Module.cc

void SimpleTableOutputExample3Module::
initModule()
{
srand(1234);
// On initialise le tableau grâce à un des initialisateurs.
// Le nom du tableau sera le nom choisi dans le .arc.
options()->stOutput()->init();
// On print le tableau dans son état actuel (vide, avec un titre).
options()->stOutput()->print();
}

Compared to the previous example, we do not need to retrieve a pointer to a singleton; here it is a service used normally.

Still compared to the previous example, the service manages the default values.

Note
For now, it is impossible to request the non-writing of output files directly in the .arc service section. If you do not put values in the tableDir and tableName options, writing will still occur. This must be handled by the module for the time being.

Loop Entry Point

Let's look at the compute-loop entry point:

SimpleTableOutputExample3Module.cc

void SimpleTableOutputExample3Module::
loopModule()
{
// On crée une colonne nommé "Iteration X" (avec X = itération actuelle).
options()->stOutput()->addColumn("Iteration " + String::fromNumber(m_global_iteration()));
// On génère deux valeurs (c'est pour l'exemple, sinon oui, ça sert à rien).
Integer nb_fissions = rand()%99;
Integer nb_collisions = rand()%99;
// On ajoute deux valeurs à deux lignes (par défaut,
// si les lignes n'existe pas encore, elles sont créées).
options()->stOutput()->addElementInRow("Nb de Fissions", nb_fissions);
options()->stOutput()->addElementInRow("Nb de Collisions", nb_collisions);
// On print le tableau dans son état actuel.
options()->stOutput()->print();
// On effectue trois itérations.
if (m_global_iteration() == 3)
subDomain()->timeLoopMng()->stopComputeLoop(true);
}

Aside from replacing the singleton pointer with the use of module options, there are no differences from the two previous examples.

Exit Entry Point

Finally, let's look at the exit entry point:

SimpleTableOutputExample3Module.cc

void SimpleTableOutputExample3Module::
endModule()
{
// On print le tableau dans son état actuel.
options()->stOutput()->print();
// On enregistre le résultat dans le dossier choisi
// par l'utilisateur dans le .arc.
options()->stOutput()->writeFile();
}

Here, we simply write the output file (and print the table). If one wishes to control whether or not the file is written via the .arc, this is where it can be done by conditioning the call to writeFile() with an if().