Module preprocessor

ENABLE_LINE_BREAKS = True

Enable or disable the parsing of double backslash \\.

MAGIC_CHARACTER = '$'

Prefix character for magic variables (by default $).

class Preprocessor(script, config={}, included={}, debug=0)

A class that parses FreeFEM .edp scripts with enhanced PyFreeFEM meta-language instructions (see PyFreeFEM meta-language).

The pyfreefem.preprocessor.Preprocessor class is used by pyfreefem.FreeFemRunner for parsing FreeFEM .edp scripts with enhanced preprocessing instructions and converting it into a proper, executable .edp code. The usage is similar to pyfreefem.FreeFemRunner:

python
from pyfreefem import Preprocessor
# Parse a single file
preproc=Preprocessor('solveState.edp')

# Parse a list of files (to be assembled consecutively)
preproc=Preprocessor(['params.edp','solveState.edp'])

# Parse a single file with an updated configuration
 preproc=Preprocessor('solveState.edp',{'ITER':'0010'})

 # Parse raw code
code = """DEFAULT (n,30)
mesh Th=square($n,$n);
preproc=Preprocessor(code)"""

# Then parse these files with `Preprocessor.parse':
parsedCode=preproc.parse();
parsedCode=preproc.parse({'n':'0001'});# Parse with a different configuration

A configuration dictionary config containing the updated (or predefined) values of magic variables is assembled while parsing the .edp file.

Parameters:
  • script – single file name, list of file names or raw .edp script

  • config – (optional) a dictionary of magic variables with default values

  • included – (optional) a list of file names that must not be included. Usually empty, used for implementation purposes.

  • debug – A tuning parameter for flexible verbose output, allowing to check the behavior of the parsing.

config

Dictionary of magic variables. This dictionary is updated after calling pyfreefem.preprocessor.Preprocessor.parse().

parse(config={})

Parse the .edp script provided to the pyfreefem.preprocessor.Preprocessor instance.

Parameters:

config

a configuration for the magic variable that takes precedence over the default config value provided to the pyfreefem.preprocessor.Preprocessor constructor.

python
preproc = Preprocessor('file.edp')
parsedCode=preproc.parse({'hmin':'0.002'})

Once the pyfreefem.preprocessor.Preprocessor.parse() has been called, the parameter pyfreefem.preprocessor.Preprocessor.config is updated.

replace(string, config=None)

Replace a string containing magic variables with their values provided by the config parameter.

Parameters:
  • string – string to replace

  • config – (default: None). The magic variables are replaced according to the values given by config If not specified, config is set to be the attribute pyfreefem.preprocessor.Preprocessor.config.

set(assign)

Update the config dictionary

Parameters:

assign (dict) – New values for the dictionary pyfreefem.preprocessor.Preprocessor.config.