Hi,
When a try to parse a dict file with unit definition " nu [0 2 -1 0 0 0 0] 1e-05; ", like transportProperties, I have the following error:
transportProperties = ParsedParameterFile("transportProperties")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/RunDictionary/ParsedParameterFile.py", line 85, in init
self.readFile()
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/RunDictionary/FileBasis.py", line 102, in readFile
self.content=self.parse(txt)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/RunDictionary/ParsedParameterFile.py", line 104, in parse
doMacroExpansion=self.doMacros)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/RunDictionary/ParsedParameterFile.py", line 311, in init
self.header,self.data=self.parse(content)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/Basics/PlyParser.py", line 60, in parse
return yacc.parse(content,debug=debug)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/ThirdParty/ply/yacc.py", line 331, in parse
return self.parseopt_notrack(input, lexer, debug, tracking, tokenfunc)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/ThirdParty/ply/yacc.py", line 1118, in parseopt_notrack
p.callable(pslice)
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/RunDictionary/ParsedParameterFile.py", line 1180, in p_dictitem
if len(p[1])==2 and p[1][0]=="uniform":
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/Basics/DataStructures.py", line 32, in eq
return self.cmp(other)==0
File "/home/rodrigo/miniconda3/lib/python3.7/site-packages/PyFoam/Basics/DataStructures.py", line 184, in cmp
if other.dims is None:
AttributeError: 'str' object has no attribute 'dims'</module></stdin>
To bypass this error I comment the above part of code from DataStructures.py:
def __cmp__(self,other): if other==None: return 1 if self.dims is None: if other.dims is not None: return -1 else: return cmp(self.dimString,other.dimString) #else: # if other.dims is None: # return 1 #else: # return cmp(self.dims,other.dims)
transportProperties.content
{'transportModel': 'Newtonian', 'nu': ['[ 0 2 -1 0 0 0 0 ]', 1e-05]}
Is there another way to fix that?
Regards,
This seems to be a problem with the new format (in the good old days dimensioned scalar had a name as well: "nu nu [0 2 -1 0 0 0 0] 1e-05;". For some reason THAT is parsed)
Didn't see this because v1806 says "nu 1e-05;"
I've added a unit-test (that fails) and will try to fix this ASAP
The problem was a comparsion operation that assumed that the other side was a dimension as well
Hi Bernhard,
Thanks for the feedback.
I updated DataStructures.py with the changes in
fixDimensionComparison.patch but now the return of
transportProperties = WriteParameterFile('transportProperties')
transportProperties.content
is {}.
When a print, this just show:
print(transportProperties)
// -- C++ --
// File generated by PyFoam - sorry for the ugliness
FoamFile
{
class dictionary;
format ascii;
object transportProperties;
version 2.0;
}
I will continue investigating the code.
Regards,
Em qui, 8 de nov de 2018 às 20:56, Bernhard Gschaider bgschaid@users.sourceforge.net escreveu:
Related
PyFoam: #223
Look at the documentation string of WriteParameterFile: it says that this is only used to write. In other words it doesn't read. This class is only for generating a dictionary from scratch
Writing a ParsedParameterFile can be done using the methods class FileBasisBackup