3. Executer of the order#
The term « executor » is not very pretty but it represents the base class that allows to execute all orders by factorizing common tasks. In old versions, we talked about a « supervisor » who added a layer intermediary between the command file and the command itself. Today, a command is a Python function.
The file code_aster/codeCommands/modi_mail.py
is ready to use:
from.. Supervis import ExecuteCommand
class transformMesh (executeCommand):
"" "Command that changes a :class:`~code_aster.Objects.Mesh`. ""
command_name = "MODI_MAIL"
def create_result (self, keywords):
"" "Initialize the result.
Arguments:
keywords (dict): Keywords arguments of user's keywords.
"""
Self. _result = keywords [" MAILLAGE "]
def add_dependencies (self, keywords):
"" "Register input*dataStructure* objects as dependencies.
Arguments:
keywords (dict): User's keywords.
"""
def post_exec (self, keywords):
"" "Execute the command.
Arguments:
keywords (dict): User's keywords.
"""
Self. _result.build ()
MODI_MAIL = transformMesh.run
3.1. Description#
MODI_MAIL is the Python function of the command. It is the function performed in the
command file.
We can see that this is the run
method of the*transformMesh* class which
<docdev-executecommand>inherits the base class is `ExecuteCommand `_.
This mechanism makes it possible to pool the tasks common to all orders: general check, time measurement, syntax check, syntax display, creation of the result, execution itself, final treatments.
In this file, we only specify what is necessary.
command_name
also allows you to automatically associate the order catalog.
create_result
initializes the object produced by the command.
In our case, the command always changes the object provided under MAILLAGE.
Most of the time, a new object is created either empty or based on the keywords.
The content of this object will be completed by the Fortran operator.
add_dependencies
is overloaded here and does not add any dependencies to the product object.
The method by default adds a dependency to each data structure provided.
by the keywords.
Care must be taken not to add superfluous dependencies to avoid cluttering the memory.
of useless objects.
Adding dependencies this way should go away when all objects carry
by nature (in their C++ class) pointers to parent objects.
post_exec
allows you to call instructions after the Fortran part has been executed,
often to complete the content of the C++ object to allow access from Python.
For this MODI_MAIL function to be accessible from the command file as
all others, it should be added in code_aster/codeCommands/__init__.py
.
So when the user makes:
from code_aster.commands import*
MODI_MAIL is available.