FAQ¶
Can I change the directory where .edp scripts are executed ?¶
By default, the interpreted script is saved in a temporary directory which is removed once
the FreeFemRunner is destroyed. However,
it can also be saved in a custom directory by using the parameter run_dir from the constructor
of FreeFemRunner:
# Save PyFreeFEM script files in the directory .run/
runner = FreeFemRunner(code,run_dir="run")
An exception is raised if the specified directory does not exist.
Warning
Specifying a running directory is useful to check and possibly to
modify the .edp filed generated by PyFreeFEM.
However, be warned that temporary directories are preferable to avoid
conflicting accesses to stored data: conflicts can occur
if several instances of a FreeFemRunner sharing
the same running directory are executed (e.g. when running multiple
processes of the same
python script).
Can I use macro files ?¶
Macro files can be specified with the parameter macro_files
of the FreeFemRunner constructor:
runner = FreeFemRunner(code,macro_files=["utils.edp","macros.edp"])
These files will be automatically copied to the PyFreeFEM running directory when calling
execute(). Macro files also support PyFreeFEM preprocessing
instructions.
Alternatively, macro files can be saved in the pyfreefem/edp directory and can be imported
using the IMPORT preprocessing instruction:
IMPORT "macros.edp"
Can I run scripts with FreeFem++-mpi or ff-mpirun?¶
It is possible to run a script in parallel with the command ff-mpirun instead of FreeFem++ and
with a desired number of cpus by
using the arguments ncpu or with_mpi of the method ~pyfreefem.freefemrunner.execute:
# Run in parallel on 4 cpus with ff-mpirun -np 4
runner.execute(ncpu=4);
# Run on 1 cpu with ff-mpirun -np 1
runner.execute(ncpu=1,with_mpi=1);
In that case, a magic variable WITH_MPI is automatically
assigned and set to 1, which can be used to execute instructions
depending on whether ff-mpirun is used, e.g.:
IF WITH_MPI
/* Instructions to include if the code is run with ff-mpirun */
ELSE
/* Instructions to include if the code is run with FreeFem++ */
int mpirank = 0;
int mpisize = 1;
ENDIF
Can I enable FreeFEM graphics ?¶
FreeFEM graphics are disabled by default. They can be activated by
assigning plot=True when calling the method execute():
from pyfreefem import FreeFemRunner
code="""
mesh=square(10,10);
plot(Th);
"""
FreeFemRunner(code).execute()
Executing the script.py will display the following figure:
Can I change the default FreeFem++ command ?¶
On some configurations, it is useful to change the FreeFem command. This
can be achieved by updating the method ~FreeFemRunner.cmd.
For instance, if one wants to prefix the FreeFem++ command when
graphics are activated (option -wg), then one can modify
~FreeFemRunner.cmd as follows:
from pyfreefem import FreeFemRunner
# Small hack for running FreeFem -wg command with vglrun
def cmd(self, *args, **kwargs):
cmd = self.old_cmd(*args,**kwargs)
if self.plot or kwargs.get('plot', False):
cmd = "vglrun "+cmd
return cmd
FreeFemRunner.old_cmd = FreeFemRunner.cmd
FreeFemRunner.cmd = cmd
Now, FreeFemRunner.execute(plot=True) will call
vglrun FreeFem++ -wg.
See also the example pyfreefem/examples/ex13_change_cmd.py.