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
.edpscripts with enhanced PyFreeFEM meta-language instructions (see PyFreeFEM meta-language).The
pyfreefem.preprocessor.Preprocessorclass is used bypyfreefem.FreeFemRunnerfor parsing FreeFEM.edpscripts with enhanced preprocessing instructions and converting it into a proper, executable.edpcode. The usage is similar topyfreefem.FreeFemRunner:pythonfrom 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 configurationA configuration dictionary
configcontaining the updated (or predefined) values of magic variables is assembled while parsing the.edpfile.- Parameters:
script – single file name, list of file names or raw
.edpscriptconfig – (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
.edpscript provided to thepyfreefem.preprocessor.Preprocessorinstance.- Parameters:
config –
a configuration for the magic variable that takes precedence over the default
configvalue provided to thepyfreefem.preprocessor.Preprocessorconstructor.pythonpreproc = Preprocessor('file.edp') parsedCode=preproc.parse({'hmin':'0.002'})
Once the
pyfreefem.preprocessor.Preprocessor.parse()has been called, the parameterpyfreefem.preprocessor.Preprocessor.configis updated.
-
replace(string, config=None)¶ -
Replace a string containing magic variables with their values provided by the
configparameter.- 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.