parameters: (fileName)
return_statement: return mesh
docstring: Import mesh from Hydrus3D. File Version 3.
  
      TODO:
      ----
      * 3D
  
      Parameters
      ----------
      fileName : str
          Filename of Hydrus output file.
docstring_summary: Import mesh from Hydrus3D. File Version 3.
docstring_tokens: Import mesh from Hydrus3D . File Version 3 .
function: def readHydrusMeshV3(fileName):
      """Import mesh from Hydrus3D. File Version 3.
  
      TODO:
      ----
      * 3D
  
      Parameters
      ----------
      fileName : str
          Filename of Hydrus output file.
  
      """
      with open(fileName) as fid:
          lines = fid.readlines()
          mesh = None
          nNodes = 0
          nBound = 0
          nCells = 0
          for i, line in enumerate(lines):
              if 'Mesh Dim' in line:
                  dim = int(line.split('\r\n')[0].split(':')[1])
                  if dim != 2:
                      pg.error('3D mesh not yet implemented.')
  
                  mesh = pg.Mesh(dim=dim)
  
              if 'DIMENSIONS' in line:
                  nNodes, nEle1, nEle2, nEle3 = lines[i+8].split(
                      '\r\n')[0].split()
                  if mesh.dim() == 1:
                      nNodes = int(nNodes)
                      nCells = int(nEle1)
                  elif mesh.dim() == 2:
                      nNodes = int(nNodes)
                      nBound = int(nEle1)
                      nCells = int(nEle2)
                  else:
                      nNodes = int(nNodes)
                      nBound = int(nEle2)
                      nCells = int(nEle3)
  
                  # print(nNodes, nBound, nCells)
  
              if 'NODAL' in line:
                  for l in lines[i+7:i+7+nNodes]:
                      vals = l.split('\r\n')[0].split()
                      if mesh.dim() == 1:
                          mesh.createNode([float(vals[1]), 0.0])
                      elif mesh.dim() == 2:
                          mesh.createNode([float(vals[1]), float(vals[2])])
                      elif mesh.dim() == 3:
                          mesh.createNode([float(vals[1]), float(vals[2]),
                                           float(vals[3])])
                  i = i + 7 + nNodes
  
              if '1D-ELEMENTS' in line:
                  for l in lines[i + 8:]:
                      vals = l.split('\r\n')[0].split()
                      if mesh.dim() == 2:
                          try:
                              mesh.createBoundary([int(vals[2])-1,
                                                   int(vals[3])-1],
                                                  marker=int(vals[1]))
                          except BaseException as e:
                              if mesh.boundaryCount() != nBound:
                                  print(e)
                                  pg.error('Something is wrong in the file.'
                                           '{:d} 1D-Elements are announced but'
                                           'only {:d} found'.format(
                                              nBound, mesh.boundaryCount()))
                                  i = i + 8 + mesh.boundaryCount()
                              break
                      else:
                          pg.error('Something wrong with mesh dimension')
  
              if '2D-ELEMENTS' in line:
                  for l in lines[i + 10:]:
                      vals = l.split('\r\n')[0].split()
                      if mesh.dim() == 2:
                          try:
                              nn = [int(vals[2])-1, int(vals[3])-1,
                                    int(vals[4])-1]
                              # nn = [int(v)-1 for v in vals[2:5]]
                              if int(vals[5]) > 0:
                                  nn.append(int(vals[5])-1)
  
                              mesh.createCell(nn, marker=int(vals[1]))
                          except BaseException as e:
                              if mesh.cellCount() != nCells:
                                  print(e)
                                  pg.error('Something is wrong in the file. '
                                           '{0} 2D-Elements announced but only '
                                           '{1} found'.format(nCells,
                                                              mesh.cellCount()))
  
                                  i = i + 10 + mesh.cellCount()
                                  break
                      else:
                          pg.error('3D mesh not yet implemented.')
  
      return mesh
function_tokens: def readHydrusMeshV3 ( fileName ) : with open ( fileName ) as fid : lines = fid . readlines ( ) mesh = None nNodes = 0 nBound = 0 nCells = 0 for i , line in enumerate ( lines ) : if 'Mesh Dim' in line : dim = int ( line . split ( '\r\n' ) [ 0 ] . split ( ':' ) [ 1 ] ) if dim != 2 : pg . error ( '3D mesh not yet implemented.' ) mesh = pg . Mesh ( dim = dim ) if 'DIMENSIONS' in line : nNodes , nEle1 , nEle2 , nEle3 = lines [ i + 8 ] . split ( '\r\n' ) [ 0 ] . split ( ) if mesh . dim ( ) == 1 : nNodes = int ( nNodes ) nCells = int ( nEle1 ) elif mesh . dim ( ) == 2 : nNodes = int ( nNodes ) nBound = int ( nEle1 ) nCells = int ( nEle2 ) else : nNodes = int ( nNodes ) nBound = int ( nEle2 ) nCells = int ( nEle3 ) # print(nNodes, nBound, nCells) if 'NODAL' in line : for l in lines [ i + 7 : i + 7 + nNodes ] : vals = l . split ( '\r\n' ) [ 0 ] . split ( ) if mesh . dim ( ) == 1 : mesh . createNode ( [ float ( vals [ 1 ] ) , 0.0 ] ) elif mesh . dim ( ) == 2 : mesh . createNode ( [ float ( vals [ 1 ] ) , float ( vals [ 2 ] ) ] ) elif mesh . dim ( ) == 3 : mesh . createNode ( [ float ( vals [ 1 ] ) , float ( vals [ 2 ] ) , float ( vals [ 3 ] ) ] ) i = i + 7 + nNodes if '1D-ELEMENTS' in line : for l in lines [ i + 8 : ] : vals = l . split ( '\r\n' ) [ 0 ] . split ( ) if mesh . dim ( ) == 2 : try : mesh . createBoundary ( [ int ( vals [ 2 ] ) - 1 , int ( vals [ 3 ] ) - 1 ] , marker = int ( vals [ 1 ] ) ) except BaseException as e : if mesh . boundaryCount ( ) != nBound : print ( e ) pg . error ( 'Something is wrong in the file.' '{:d} 1D-Elements are announced but' 'only {:d} found' . format ( nBound , mesh . boundaryCount ( ) ) ) i = i + 8 + mesh . boundaryCount ( ) break else : pg . error ( 'Something wrong with mesh dimension' ) if '2D-ELEMENTS' in line : for l in lines [ i + 10 : ] : vals = l . split ( '\r\n' ) [ 0 ] . split ( ) if mesh . dim ( ) == 2 : try : nn = [ int ( vals [ 2 ] ) - 1 , int ( vals [ 3 ] ) - 1 , int ( vals [ 4 ] ) - 1 ] # nn = [int(v)-1 for v in vals[2:5]] if int ( vals [ 5 ] ) > 0 : nn . append ( int ( vals [ 5 ] ) - 1 ) mesh . createCell ( nn , marker = int ( vals [ 1 ] ) ) except BaseException as e : if mesh . cellCount ( ) != nCells : print ( e ) pg . error ( 'Something is wrong in the file. ' '{0} 2D-Elements announced but only ' '{1} found' . format ( nCells , mesh . cellCount ( ) ) ) i = i + 10 + mesh . cellCount ( ) break else : pg . error ( '3D mesh not yet implemented.' ) return mesh