The "macroExpansion" option in the "ParsedParameterFile" class, assumes that the path to the "#include" files are relative to the location of the dictionary. .... There are a couple of issues in this case....:
[a]. It is not always the case that a relative path is used when specifying the location of the file.... it could also be an absolute path, in which case, the line 511 in ParsedParameterFile.py would not provide a usable path.
[b]. The path may contain environment variables which get substituted correctly by OpenFOAM but are not expanded by PyFoam
[c]. Environment variables such as "$FOAM_CASE" which are only valid when actually running the case need to substituted by the right paths by PyFoam utilities. [Sample: #include "$FOAM_CASE/../inletFlowRate.dat" ]
---- additional_information ----
Location of the failure: PyFoam/RunDictionary/ParsedParameterFile.py
Line number: 510 - 521
-------------- Quote - Begin ----------------
510 if self.doMacros:
511 fName=path.join(self.directory(),p[2][1:-1])
512 read=True
513 if p[1]=="includeIfPresent" and not path.exists(fName):
514 read=False
515 if read and not path.exists(fName):
516 raise PyFoamParserError("The included file "+fName+" does not exist")
517 if read:
518 data=ParsedParameterFile(fName,noHeader=True)
519 into=self.dictStack[-1]
520 for k in data:
521 into[k]=data[k]
-------------- Quote - End ------------------
Possible solutions:
1. The python function "os.path.expandvars" could be used to substitute the contents of standard environment variables into the path.
2. Parse the "#include" directive to detect if the specified path is a relative or absolute path and always convert to an absolute path (?)
3. No robust solution idea yet for special environment variables such as "$FOAM_CASE"
Will have a look at it.
The thing with FOAM_CASE can be solved by inserting it into os.environ. Then the substitution of the variables should work.
The detection of absolute paths can be done with os.path.isabs
hi,
I have a related issue:
When I try to include a file that is located in a parent directory as relative path with
#include "../common/defaultParameters_mesh"
pyFoam does not recognise this, but simply adds it to the absolute path of the case (~/OpenFoam/cyberspeck-8/tool/test):
Error in /opt/OpenFOAM/ThirdParty-8/PyFoam/bin/pyFoamPrepareCase.py : Error in PyFoamParser: 'The included file ~/OpenFoam/cyberspeck-8/tool/test/../common/defaultParameters_mesh does not exist'
Is there a better way to include a openFoam dict file?
Regards,
david