Menu

#223 ParsedParameterFile for unit definition error: 'str' object has no attribute 'dims'

confirmed
None
high
major
Always
none
ubuntu 18
python3.7
pyfoam 0.6.10
general
2018-11-11
2018-11-06
No

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,

Related

PyFoam: #223

Discussion

  • Bernhard Gschaider

    • status: new --> confirmed
     
  • Bernhard Gschaider

    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

     
  • Bernhard Gschaider

    The problem was a comparsion operation that assumed that the other side was a dimension as well

     
    • Rodrigo Leite Prates

      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:

      The problem was a comparsion operation that assumed that the other side
      was a dimension as well

      Attachments:


      Status: confirmed
      Group: Next Release (example)
      Created: Tue Nov 06, 2018 03:26 PM UTC by Rodrigo Leite Prates
      Last Updated: Thu Nov 08, 2018 10:01 PM UTC
      Owner: Bernhard Gschaider

      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,

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/openfoam-extend/ticketspyfoam/223/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       

      Related

      PyFoam: #223

  • Bernhard Gschaider

    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

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.