Module MeshExport
In: meshexport.rb

Methods

Public Instance methods

[Source]

# File meshexport.rb, line 152
   def bctoif(bcno)
      return iftobc(bcno)
   end

[Source]

# File meshexport.rb, line 169
   def boundarystring(name, boundarytype, physicaltype, startface, nfaces )
      # type: wall, patch
      # physicalType: wallFunctions, inlet
      return "#{name}
{
    type            #{boundarytype}\;
    physicalType    #{physicaltype}\;
    startFace       #{startface}\;
    nFaces          #{nfaces}\;
}\n"

   end

gives the internal face number(s) based on the i,j,k-value

[Source]

# File meshexport.rb, line 110
   def ifnofromijk(i,j,k,imax,jmax,kmax)
      result = Array.new
      if i == 0
         result.push(4)
      end
      if i == imax
         result.push(2)
      end
      if j == 0
         result.push(1)
      end
      if j == jmax
         result.push(3)
      end
      if k == 0
         result.push(0)
      end
      if k == kmax
         result.push(5)
      end
      if result.size > 0
         return result
      else
         return nil
      end
   end

[Source]

# File meshexport.rb, line 136
   def iftobc(ifno)
      case ifno.to_s
         when "0"
            return 4
         when "1"
            return 2
         when "2"
            return 1
         when "3"
            return 3
         when "4"
            return 0
         when "5"
            return 5
      end
   end

hash to find point number in points array

[Source]

# File meshexport.rb, line 534
         def numforijk(i,j,k)
            #return @pointhash["#{i}-#{j}-#{k}"]
            #puts "skt numforijk i #{i}, j #{j}, k #{k} point #{@pointhasharr[@cubenomethod]["#{i}-#{j}-#{k}"]}"
            return @pointhasharr[@cubenomethod]["#{i}-#{j}-#{k}"]
         end
 end cube loop

points += "(0 0 0)\n"

 face creation

 face4 (i,j,k) = 0:(i,j,k), 1:(i+1, j, k), 2:(i+1, j+1,k), 3:(i, j+1, k)   i,j 0..[i,j]max-1
 face0 (i,j,k) = 0:(i,j,k), 3:(i,j+1,k)  7:(i,j+1,k+1)  4:(i,j,k+1)        j,k 0..[j,k]max-1
 face2 (i,j,k) = 0:(i,j,k), 4:(i,j,k+1), 5:(i+1,j,k+1), 1:(i+1,j,k)
 find faces by searching pointpos array, maybe create a hash?

[Source]

# File meshexport.rb, line 526
         def numforijk2(i,j,k)
            @pointpos.each do |tmp|
               if tmp[1] == i && tmp[2] == j && tmp[3] == k
                  return tmp[0]
               end
            end
         end

export to openfoam format

[Source]

# File meshexport.rb, line 182
   def openfoamexport2(internalfacearray,filename)
      @relocatetracker = 0      # track how many relocated points there are
      puts "

   OpenFOAM Mesh Export Begins:


"
      cubeifarr = internalfacearray
      # determine wich faces are connected
      @connections = Array.new
      (0..cubeifarr.size-1).each do |master|
         (1..cubeifarr.size-1).each do |slave|
            if master < slave
               # check which faces are connected
               (0..5).each do |ifmaster|
                  (0..5).each do |ifslave|
                     if cubeifarr[master].if[ifmaster].parent == cubeifarr[slave].if[ifslave].parent
                        @connections.push([master, ifmaster, slave , ifslave ])
                     end
                  end
               end
            end
         end
      end
      @masters = Array.new
      @slaves = Array.new
      @mastersif = Array.new
      @slavesif = Array.new
      @masterhash = Hash.new
      @slavehash = Hash.new
      @ownerhash = Array.new
      @uppertriangular = Array.new
      # not used right now
      (0..cubeifarr.size-1).each do |ownertmp|
         # could be a hash pointing to an array @upperAndOwner -> [ owner, uppertriangular ]
         @ownerhash[ownertmp] = Hash.new
         @uppertriangular[ownertmp] = Hash.new
      end
      # fill arrays with master-slave relation(s)
      @connections.each do |tmp|
         @masters.push(tmp[0])                                                 # master
         @mastersif.push(tmp[1])                                               # master internal face
         @masterhash["#{tmp[0]}-#{tmp[1]}"] = "#{tmp[2]}-#{tmp[3]}"            # key: "master-ifmaster", entry: "slave-ifslave"
         @slaves.push(tmp[2])                                                  # slave
         @slavesif.push(tmp[3])                                                        # slave internal face
         @slavehash["#{tmp[2]}-#{tmp[3]}"] = "#{tmp[0]}-#{tmp[1]}"             # key: "slave-ifslave", entry: "master-ifmaster"
      end

      # mesh all cubes
      @numpoints = 0
      #@points = ""
      @points = Array.new 
      @numfaces = 0
      #@facearray = Array.new
      @faceinfo = Array.new
      @faceshape = nil
      @cellnum = 0
      @pointhasharr = Array.new
      # each face has point with internal point numbers. When they are conncted the
      # internal point number is a link to numpoint. Therefore an array with numpoint information for each 
      # internal face point is created and stored in @cubepointinfo which will be an array of arrays.
      # @cubepointinfo = [ [ [face0points],[face1points],... ] , [cube1], [cube2], ... ]
      # access a point with @cubepointinfno[cubeno][faceno]["internal point number"] ( = numpoint)
      @cubepointinfo = Array.new
      # loop through all cubes
      #cubeifarr.each do |intcube|
      #
      #
      #
      # start loop through cubes
      #
      #
      time1 = Benchmark.measure {
      (0..cubeifarr.size-1).each do |cubeno| # start loop through cubes
         @cubenomethod = cubeno                                 # cubeno accessible for entire method
         @pointhasharr[cubeno] = Hash.new                               # Hash created to store numpoints with "idir"-"jdir"-"kdir" keys
         @pointhasharr[cubeno]["startpoint"] = @numpoints               # -1??? startpoint for current cube
         @pointhasharr[cubeno]["pointbefore"] = @numpoints - 1  # -1??? already made points ,  will get value -1 for first cube?? see what works later on
         cubeif = cubeifarr[cubeno].if
         if cubeno > 0
            # TODO use pointhasharr "startpoint" instead
            @cellnum += cubeifarr[cubeno-1].cellcount
         end
         # test for negative volume and set volreverse accordingly
         itmp, jtmp = 0, 0
         p0test = [ cubeif[0].parent.x[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.y[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.z[0][cubeif[0].getpointno(itmp,jtmp)] ]
         itmp, jtmp = 1, 0
         p1test = [ cubeif[0].parent.x[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.y[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.z[0][cubeif[0].getpointno(itmp,jtmp)] ]
         itmp, jtmp = 0, 1
         p2test = [ cubeif[0].parent.x[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.y[0][cubeif[0].getpointno(itmp,jtmp)],
                    cubeif[0].parent.z[0][cubeif[0].getpointno(itmp,jtmp)] ]
         itmp, ktmp = 0, 1
         p3test = [ cubeif[1].parent.x[0][cubeif[1].getpointno(itmp,ktmp)],
                    cubeif[1].parent.y[0][cubeif[1].getpointno(itmp,ktmp)],
                    cubeif[1].parent.z[0][cubeif[1].getpointno(itmp,ktmp)] ]
         test1 = crossProduct([ p1test[0]-p0test[0], p1test[1]-p0test[1], p1test[2]-p0test[2] ], 
                      [ p2test[0]-p0test[0], p2test[1]-p0test[1], p2test[2]-p0test[2] ] ) 
         test2 = [ p3test[0]-p0test[0], p3test[1]-p0test[1], p3test[2]-p0test[2] ]  
         angle1 = angleBetween(test1, test2)
         if angle1 < 90
            @volreverse = false
         else
            @volreverse = true
         end
         #
         #
         #
         #
         #@numpoints = (cubeif[0].imax+1)*(cubeif[0].jmax+1)*(cubeif[1].jmax+1)
         # NOTUSED? numcells = cubeif[0].imax*cubeif[0].jmax*cubeif[1].jmax
         imaxtmp = cubeif[0].imax
         jmaxtmp = cubeif[0].jmax
         kmaxtmp = cubeif[1].jmax
         #
         # point creation
         #
         #
         # supress already made points...
         #@pointpos = Array.new
         # Maybe slave points has to get filtered out here already.
         # When a point is a slavepoint the hash should return the master point number and @numpoint should not be updated.
         #@pointhash = Hash.new
         @cubepointinfo[cubeno] = Array.new             # create an array to store face points
         (0..5).each do |tmp|
            @cubepointinfo[cubeno][tmp] = Array.new     # create an array for each face
         end
         # already created @pointhasharr[cubeno] = Hash.new
         # before create mesh do diffs for new mesh method
         @cubemesh = Mesh::CubeMesh.new(cubeifarr[cubeno])
         # create mesh 
         (0..kmaxtmp).each do |kdir|
            (0..jmaxtmp).each do |jdir|
               (0..imaxtmp).each do |idir|
                  @relocate = false
                  # points between if[0] and if[5]
                  # @pointpos.push([@numpoints, idir, jdir, kdir])
                  # find internal face number
                  # internal face on first defined master 
                  if @slaves.member?cubeno 
                     if kdir == 0 || jdir == 0 || idir == 0 || kdir == kmaxtmp || jdir == jmaxtmp || idir == imaxtmp
                        # if ifno1 != nil
                        # if @slavehash["#{cubeno}-#{ifno1}"] != nil
                        ifno1 = ifnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        testflag, cubeno3, ifno3 = testhash2(cubeno, ifno1, @slavehash)
                        if testflag
                           # loop through all ifno3
                           ifno2 = ifno3.first 
                           cubeno1 = cubeno3.first
                           (0..ifno3.size-1).each do |masternum| 
                              ifpointnumber = Array.new
                              case ifno3[masternum].to_s
                                 when "0"
                                    firstdir, seconddir = idir, jdir
                                 when "1"
                                    firstdir, seconddir = idir, kdir
                                 when "2"
                                    firstdir, seconddir = jdir, kdir
                                 when "3"
                                    firstdir, seconddir = idir, kdir
                                 when "4"
                                    firstdir, seconddir = jdir, kdir
                                 when "5"
                                    firstdir, seconddir = idir, jdir
                              end
                              ifpointnumber.push( cubeif[0].getpointno(idir, jdir) )
                              ifpointnumber.push( cubeif[1].getpointno(idir, kdir) )
                              ifpointnumber.push( cubeif[2].getpointno(jdir, kdir) )
                              ifpointnumber.push( cubeif[3].getpointno(idir, kdir) )
                              ifpointnumber.push( cubeif[4].getpointno(jdir, kdir) )
                              ifpointnumber.push( cubeif[5].getpointno(idir, jdir) )
                              #ifpointnumber.push( cubeif[ifno2].getpointno(firstdir, seconddir) )
                              begin
                                 # we can have five masterif:s
                                 # get the master for the slaveif
                                 mastercube, masterif = @slavehash["#{cubeno3[masternum]}-#{ifno3[masternum]}"].split("-")
                                 # don't use cubeif, has to be master cubeif????
                                 # firstdir, seconddir????
                                 if @cubepointinfo[mastercube.to_i][masterif.to_i][cubeif[ifno3[masternum]].getpointno(firstdir, seconddir)] == nil
                                    #puts "imax #{cubeif[ifno3[masternum]].imax}, jmax #{cubeif[ifno3[masternum]].jmax}, idir #{idir}, jdir #{jdir}, kdir #{kdir}" 
                                 else
                                    @relocate = true
                                    # here we are in trouble
                                    @relocatenumpoints = @cubepointinfo[mastercube.to_i][masterif.to_i][cubeif[ifno3[masternum]].getpointno(firstdir, seconddir)]
                                    @relocatemaster = mastercube.to_i
                                    @relocateif = masterif.to_i
                                 end
                              raise
                              rescue
                                 #puts "skt no master for slave: cube #{cubeno1}, internal face #{ifno2}"
                              end
                              # from the calculated internal face point number we get master numpoints
                              # here we will have the shared face
                              if @relocate == true
                                 @pointhasharr[cubeno]["#{idir}-#{jdir}-#{kdir}"] = @relocatenumpoints
                              end
                           end
                        end # testflag
                     end
                  end
                  # another already made cube has its numpoints in @pointhasharr[cubeno]
                  # the pointnum start is stored in "startpoint" => number_of_points_already_made
                  #
                  # if it's a duplicate point it has to be relocated to an already made point
                  # this pointhash has to be an array of pointhashes. One hash for each cube.
                  #@pointhash["#{idir}-#{jdir}-#{kdir}"] = @numpoints
                  csys1 = cubeif[0].parent.csys
                  if csys1.csystype == 0 || true                     # remove true when rest of code can take it...
                     csys = 0
                  else
                     csys = csys1.count
                  end
                  p0x = cubeif[0].parent.x[csys][cubeif[0].getpointno(idir,jdir)]       # possible error with i, j dir
                  p0y = cubeif[0].parent.y[csys][cubeif[0].getpointno(idir,jdir)]
                  p0z = cubeif[0].parent.z[csys][cubeif[0].getpointno(idir,jdir)]
                  if p0x == nil
                     p0x = 0
                     p0y = 0
                     p0z = 0
                  end
                  idir1 = idir
                  jdir1 = jdir
                  p1x = cubeif[5].parent.x[csys][cubeif[5].getpointno(idir1,jdir1)]
                  p1y = cubeif[5].parent.y[csys][cubeif[5].getpointno(idir1,jdir1)]
                  p1z = cubeif[5].parent.z[csys][cubeif[5].getpointno(idir1,jdir1)]
                  if p1x == nil
                     p1x = 0
                     p1y = 0
                     p1z = 0
                  end
                  xpoint1 = p0x + (p1x-p0x)*kdir/kmaxtmp
                  ypoint1 = p0y + (p1y-p0y)*kdir/kmaxtmp
                  zpoint1 = p0z + (p1z-p0z)*kdir/kmaxtmp
                  if csys1.csystype == 0 || true                     # remove true when rest of code can take it...or maybe use the new mesh method
                     xpoint, ypoint, zpoint = xpoint1, ypoint1, zpoint1
                  else
                     xpoint, ypoint, zpoint = positionInCsys(csys1, [ xpoint1, ypoint1, zpoint1 ] )
                  end
                  # cubepointinfo creation
                  # create for internal face 4
                  if idir == 0
                     # this pno will be found when slave cube face is created and then numpoints will be found.
                     pno = cubeif[4].getpointno(jdir,kdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][4][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][4][pno] = @numpoints
                        end
                     end
                  end
                  # create if 2
                  if idir == imaxtmp
                     pno = cubeif[2].getpointno(jdir,kdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][2][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][2][pno] = @numpoints
                        end
                     end
                  end
                  # create if 1
                  if jdir == 0
                     pno = cubeif[1].getpointno(idir,kdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][1][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][1][pno] = @numpoints
                        end
                     end
                  end
                  # create if 3
                  if jdir == jmaxtmp
                     pno = cubeif[3].getpointno(idir,kdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][3][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][3][pno] = @numpoints
                        end
                     end
                  end
                  # create if 0
                  if kdir == 0
                     pno = cubeif[0].getpointno(idir,jdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][0][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][0][pno] = @numpoints
                        end
                     end
                  end
                  # create if 5
                  if kdir == kmaxtmp
                     pno = cubeif[5].getpointno(idir,jdir)
                     if pno < 0 || pno == nil
                     else
                        if @relocate
                           @cubepointinfo[cubeno][5][pno] = @relocatenumpoints
                        else
                           @cubepointinfo[cubeno][5][pno] = @numpoints
                        end
                     end
                  end
   
                  if !@relocate
                     @pointhasharr[cubeno]["#{idir}-#{jdir}-#{kdir}"] = @numpoints
                     #@points[@numpoints] = "(#{xpoint} #{ypoint} #{zpoint})\n" 
                     @points[@numpoints] = "(#{@cubemesh.xpos[idir][jdir][kdir]} #{@cubemesh.ypos[idir][jdir][kdir]} #{@cubemesh.zpos[idir][jdir][kdir]})\n" 
                     @numpoints += 1
                  else
                     @relocatetracker += 1
                  end
               end
            end
         end
         
   
         #
         # end cube loop
         #
         #
         #
         #points += "(0 0 0)\n"
         #
         # face creation
         #
         # face4 (i,j,k) = 0:(i,j,k), 1:(i+1, j, k), 2:(i+1, j+1,k), 3:(i, j+1, k)   i,j 0..[i,j]max-1
         # face0 (i,j,k) = 0:(i,j,k), 3:(i,j+1,k)  7:(i,j+1,k+1)  4:(i,j,k+1)        j,k 0..[j,k]max-1
         # face2 (i,j,k) = 0:(i,j,k), 4:(i,j,k+1), 5:(i+1,j,k+1), 1:(i+1,j,k)
         # find faces by searching pointpos array, maybe create a hash?
         def numforijk2(i,j,k)
            @pointpos.each do |tmp|
               if tmp[1] == i && tmp[2] == j && tmp[3] == k
                  return tmp[0]
               end
            end
         end
         # hash to find point number in points array
         def numforijk(i,j,k)
            #return @pointhash["#{i}-#{j}-#{k}"]
            #puts "skt numforijk i #{i}, j #{j}, k #{k} point #{@pointhasharr[@cubenomethod]["#{i}-#{j}-#{k}"]}"
            return @pointhasharr[@cubenomethod]["#{i}-#{j}-#{k}"]
         end
         faces = ""
         # neighbour and owner is going to be calculated
         # first do internal faces
         (0..kmaxtmp-1).each do |kdir|
            (0..jmaxtmp-1).each do |jdir|
               (0..imaxtmp-1).each do |idir|
                  facenumber = -1
                  # face0/1
                  if idir != imaxtmp - 1
                     #idir == 0 ? icell = 0: icell = idir - 1
                     icell = idir
                     jcell = jdir
                     kcell = kdir
                     # neighbour cell block must be taken into account
                     neighbour = cellnofromijk(icell+1, jcell, kcell, imaxtmp, jmaxtmp, kmaxtmp)
                     owner = cellnofromijk(icell, jcell, kcell, imaxtmp, jmaxtmp, kmaxtmp)
                     neighbour += @cellnum
                     owner += @cellnum
                     if @volreverse
                        @faceshape = [[1,0,0], [1,0,1], [1,1,1], [1,1,0]]
                     else
                        @faceshape = [[1,0,0], [1,1,0], [1,1,1], [1,0,1]]
                     end # volreverse
                     @faceinfo.push([facenumber, neighbour, owner, 
                     numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                     numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                     numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                     numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                     cubeno,nil ])
                  end
                  # face2/3
                  if jdir != jmaxtmp - 1
                     icell = idir
                     jcell = jdir
                     #jdir == 0 ? jcell = 0: jcell = jdir - 1
                     kcell = kdir
                     neighbour = cellnofromijk(icell, jcell+1, kcell, imaxtmp, jmaxtmp, kmaxtmp)
                     owner = cellnofromijk(icell, jcell, kcell, imaxtmp, jmaxtmp, kmaxtmp)
                     neighbour += @cellnum
                     owner += @cellnum
                     if @volreverse
                        @faceshape = [[0,1,0], [1,1,0], [1,1,1], [0,1,1]]
                     else
                        @faceshape = [[0,1,0], [0,1,1], [1,1,1], [1,1,0]]
                     end # volreverse
                     @faceinfo.push([facenumber, neighbour, owner, 
                     numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                     numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                     numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                     numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                     cubeno,nil])
                  end
                  # face4/5
                  if kdir != kmaxtmp - 1
                     icell = idir
                     jcell = jdir
                     #kdir == 0 ? kcell = 0: kcell = kdir - 1
                     kcell = kdir
                     neighbour = cellnofromijk(icell, jcell, kcell+1, imaxtmp, jmaxtmp, kmaxtmp)
                     owner = cellnofromijk(icell, jcell, kcell, imaxtmp, jmaxtmp, kmaxtmp)
                     neighbour += @cellnum
                     owner += @cellnum
                     if @volreverse
                        @faceshape = [[0,0,1], [0,1,1], [1,1,1], [1,0,1]]
                     else
                        @faceshape = [[0,0,1], [1,0,1], [1,1,1], [0,1,1]]
                     end  # volreverse
                     @faceinfo.push([facenumber, neighbour, owner, 
                     numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                     numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                     numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                     numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                     cubeno, nil ])
                  end
               end
            end
         end


   
   
         # face0/1, internal face 4/2
         @uppertriagularno = 0
         [0, imaxtmp].each do |idir|
            (0..kmaxtmp-1).each do |kdir|
               (0..jmaxtmp-1).each do |jdir|
                  @createface = false
                  @createowner = false
                  @slaveface = false
                  reverse = false               # not necessary
                  # first test: if it's a master 
                  #
                  # face0 internal face 4
                  #
                  if idir == 0
                     if !(@masterhash["#{cubeno}-#{4}"] != nil)        # true if it's not a master
                        if @slavehash["#{cubeno}-#{4}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = false
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{4}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = true
                           facenumber = 0 + cubeno*6
                           iffaceno = 4
                           neighbour = -1
                           owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{4}"] != nil)
                        @createowner = true
                        reverse = true
                        owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  #
                  # face1 internal face 2
                  #
                  if idir == imaxtmp
                     if !(@masterhash["#{cubeno}-#{2}"] != nil)
                        if @slavehash["#{cubeno}-#{2}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = true
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir-1, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{2}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = false
                           facenumber = 1 + cubeno*6
                           iffaceno = 2
                           neighbour = -1
                           owner = cellnofromijk(idir-1, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{2}"] != nil)
                        @createowner = true
                        reverse = false
                        owner = cellnofromijk(idir-1, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  if @createface || @createowner
                     if !reverse
                        if @volreverse 
                           @faceshape = [[0,0,0], [0,0,1], [0,1,1], [0,1,0]]
                        else
                           @faceshape = [[0,0,0], [0,1,0], [0,1,1], [0,0,1]]
                        end # volreverse
                     else
                        if @volreverse
                           @faceshape = [[0,0,0], [0,1,0], [0,1,1], [0,0,1]]
                        else
                           @faceshape = [[0,0,0], [0,0,1], [0,1,1], [0,1,0]]
                        end # volreverse
                     end
                     if @createowner
                        # sort points
                        p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                        p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                        p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                        p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                        sortp = [ p0, p1, p2, p3 ].sort
                        @ownerhash[cubeno]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"] = owner
                     else
                        if @slaveface
                           # sort points
                           p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                           p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                           p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                           p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                           sortp = [ p0, p1, p2, p3 ].sort
                           # now fix upper triangular ordering with owner and uppertriangular info
                           owner = @ownerhash[tmpmaster.to_i]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"]
                           #uppertri = @uppertriangular[tmpmaster.to_i]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"]
                        end
                        @faceinfo.push([facenumber, neighbour, owner, 
                        numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                        numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                        numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                        numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                        cubeno, iffaceno ])
                        @numfaces += 1
                     end
                  else
                     # create a hash with owner info accessable with face point definition
                     # "p0-p1-p2-p3" -> owner
                  end
               end
            end
         end
      
         # face2/3, internal face 1/3
         @uppertriangularno = 0
         [0, jmaxtmp].each do |jdir|
            (0..kmaxtmp-1).each do |kdir|
               (0..imaxtmp-1).each do |idir|
                  @createface = false
                  @createowner = false
                  @slaveface = false
                  reverse = false               # not necessary
                  # first test: if it's a master 
                  #
                  # face2 internal face 1
                  #
                  if jdir == 0
                     if !(@masterhash["#{cubeno}-#{1}"] != nil)        # true if it's not a master
                        if @slavehash["#{cubeno}-#{1}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = false
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{1}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = true
                           facenumber = 2 + cubeno*6
                           iffaceno = 1
                           neighbour = -1
                           owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{1}"] != nil)
                        @createowner = true
                        reverse = true
                        owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  #
                  # face3 internal face 3
                  #
                  if jdir == jmaxtmp
                     if !(@masterhash["#{cubeno}-#{3}"] != nil)
                        if @slavehash["#{cubeno}-#{3}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = true
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir, jdir-1, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{3}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = false
                           facenumber = 3 + cubeno*6
                           iffaceno = 3
                           neighbour = -1
                           owner = cellnofromijk(idir, jdir-1, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{3}"] != nil)
                        @createowner = true
                        reverse = false
                        owner = cellnofromijk(idir, jdir-1, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  if @createface || @createowner
                     if !reverse
                        if @volreverse
                           @faceshape = [[0,0,0], [1,0,0], [1,0,1], [0,0,1]]
                        else
                           @faceshape = [[0,0,0], [0,0,1], [1,0,1], [1,0,0]]
                        end # volreverse
                     else
                        if @volreverse
                           @faceshape = [[0,0,0], [0,0,1], [1,0,1], [1,0,0]]
                        else
                           @faceshape = [[0,0,0], [1,0,0], [1,0,1], [0,0,1]]
                        end # volreverse
                     end
                     if @createowner
                        # sort points
                        p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                        p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                        p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                        p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                        sortp = [ p0, p1, p2, p3 ].sort
                        @ownerhash[cubeno]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"] = owner
                        #@uppertriangular[cubeno]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"] = @uppertriangularno 
                     else
                        if @slaveface
                           # sort points
                           p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                           p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                           p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                           p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                           sortp = [ p0, p1, p2, p3 ].sort
                           owner = @ownerhash[tmpmaster.to_i]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"]
                           # owner += @cellnum
                        end
                        @faceinfo.push([facenumber, neighbour, owner, 
                        numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                        numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                        numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                        numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                        cubeno, iffaceno ])
                        @numfaces += 1
                     end
                  else
                  end
               end
            end
         end
   
         # face4/5, internal face 0/5
         @uppertriangularno = 0
         [0, kmaxtmp].each do |kdir|
            (0..jmaxtmp-1).each do |jdir|
               (0..imaxtmp-1).each do |idir|
                  @createface = false
                  @createowner = false
                  @slaveface = false
                  reverse = false               # not necessary
                  # first test: if it's a master 
                  #
                  # face4 internal face 0
                  #
                  if kdir == 0
                     if !(@masterhash["#{cubeno}-#{0}"] != nil)        # true if it's not a master
                        if @slavehash["#{cubeno}-#{0}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = false
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{0}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = true
                           facenumber = 4 + cubeno*6
                           iffaceno = 0
                           neighbour = -1
                           owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{0}"] != nil)
                        @createowner = true
                        reverse = true
                        owner = cellnofromijk(idir, jdir, kdir, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  #
                  # face1 internal face 2
                  #
                  if kdir == kmaxtmp
                     if !(@masterhash["#{cubeno}-#{5}"] != nil)
                        if @slavehash["#{cubeno}-#{5}"] != nil        # true if it's a slave
                           @createface = true
                           @slaveface = true
                           reverse = true
                           facenumber = -1
                           iffaceno = -1
                           neighbour = cellnofromijk(idir, jdir, kdir-1, imaxtmp, jmaxtmp, kmaxtmp)
                           neighbour += @cellnum
                           tmpmaster, tmpif = @slavehash["#{cubeno}-#{5}"].split("-")
                        else
                           # do a boundary
                           @createface = true
                           reverse = false
                           facenumber = 5 + cubeno*6
                           iffaceno = 5
                           neighbour = -1
                           owner = cellnofromijk(idir, jdir, kdir-1, imaxtmp, jmaxtmp, kmaxtmp)
                           owner += @cellnum
                        end
                     elsif (@masterhash["#{cubeno}-#{5}"] != nil)
                        @createowner = true
                        reverse = false
                        owner = cellnofromijk(idir, jdir, kdir-1, imaxtmp, jmaxtmp, kmaxtmp)
                        owner += @cellnum
                     end
                  end
                  if @createface || @createowner
                     if !reverse
                        if @volreverse
                           @faceshape = [[0,0,0], [0,1,0], [1,1,0], [1,0,0]]
                        else
                           @faceshape = [[0,0,0], [1,0,0], [1,1,0], [0,1,0]]
                        end # volreverse
                     else
                        if @volreverse
                           @faceshape = [[0,0,0], [1,0,0], [1,1,0], [0,1,0]]
                        else
                           @faceshape = [[0,0,0], [0,1,0], [1,1,0], [1,0,0]]
                        end # volreverse
                     end
                     if @createowner
                        # sort points
                        p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                        p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                        p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                        p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                        sortp = [ p0, p1, p2, p3 ].sort
                        @ownerhash[cubeno]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"] = owner
                        #@uppertriangular[cubeno]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"] = @uppertriangularno 
                     else
                        if @slaveface
                           # sort points
                           p0 = numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2])
                           p1 = numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2])
                           p2 = numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2])
                           p3 = numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2])
                           sortp = [ p0, p1, p2, p3 ].sort
                           owner = @ownerhash[tmpmaster.to_i]["#{sortp[0]}-#{sortp[1]}-#{sortp[2]}-#{sortp[3]}"]
                        end
                        @faceinfo.push([facenumber, neighbour, owner, 
                        numforijk(idir+@faceshape[0][0],jdir+@faceshape[0][1],kdir+@faceshape[0][2]),
                        numforijk(idir+@faceshape[1][0],jdir+@faceshape[1][1],kdir+@faceshape[1][2]),
                        numforijk(idir+@faceshape[2][0],jdir+@faceshape[2][1],kdir+@faceshape[2][2]),
                        numforijk(idir+@faceshape[3][0],jdir+@faceshape[3][1],kdir+@faceshape[3][2]),
                        cubeno, iffaceno ])
                        @numfaces += 1
                     end
                  else
                  end
               end
            end
         end
      end

      @facearray = Array.new
      @faceinfo.each do |tmp|
         @facearray.push([tmp[0], tmp[1], tmp[2], "4(#{tmp[3]} #{tmp[4]} #{tmp[5]} #{tmp[6]})\n"] )
      end
      @internalarray = Array.new
      @boundaryarray = Array.new
      @facearray.each do |tmp|
         if tmp[1] == -1
            @boundaryarray.push(tmp)
         else
            @internalarray.push(tmp)
         end
      end
      @tmparray = Array.new
      @sortedfacearray = @internalarray + @boundaryarray
      }
      puts "time for mesh1: #{time1.total}, number of points #{@numpoints}" 
      time2 = Benchmark.measure {

      neighbourstring = ""
      ownerstring = ""
      facesstring = ""
      # Takes a lot of time
??
      neighbourstring2 = Array.new
      ownerstring2 = Array.new
      facesstring2 = Array.new
      (0..@sortedfacearray.size - 1).each do |idx|
         neighbourstring2[idx] = "#{@sortedfacearray[idx][1]}\n"
         ownerstring2[idx] = "#{@sortedfacearray[idx][2]}\n"
         facesstring2[idx] = "#{@sortedfacearray[idx][3]}"
      end
      neighbourstring = neighbourstring2.to_s
      ownerstring = ownerstring2.to_s
      facesstring = facesstring2.to_s
      pointshead = "FoamFile
{
    version 2.0;
    format ascii;

    root \"\";
    case \"\";
    instance \"\";
    local \"\";

    class vectorField;
    object points;
}\n"
      # NOPUTS puts "numpoints #{@numpoints}"
      pointshead += "#{@numpoints}\n(\n"
      neighbourhead = "FoamFile
{
    version 2.0;
    format ascii;

    root \"\";
    case \"\";
    instance \"\";
    local \"\";

    class labelList;
    object neighbour;
}\n"
      ownerhead = "FoamFile
{
    version 2.0;
    format ascii;

    root \"\";
    case \"\";
    instance \"\";
    local \"\";

    class labelList;
    object owner;
}\n"
      faceshead = "FoamFile
{
    version 2.0;
    format ascii;

    root \"\";
    case \"\";
    instance \"\";
    local \"\";

    class faceList;
    object faces;
}\n"
      boundaryhead = "FoamFile
{
    version 2.0;
    format ascii;

    root \"\";
    case \"\";
    instance \"\";
    local \"\";

    class polyBoundaryMesh;
    object boundary;
}\n"
   
      # warn hardcoded values
      epsilonfile = foamEpsilonHeader($globalworkdir, $globalcasename, "43")
      kfile = foamKHeader($globalworkdir, $globalcasename, "1.5")
      nutildafile = foamNuTildaHeader($globalworkdir, $globalcasename, "0")
      pfile = foamPHeader($globalworkdir, $globalcasename, "0")
      rfile = foamRHeader($globalworkdir, $globalcasename, "(0 0 0 0 0 0 0 0 0)")
      ufile = foamUHeader($globalworkdir, $globalcasename, "(0 0 0)")
      pointsfile = pointshead + @points.to_s
      pointsfile += ")\n"
      boundaryfile = boundaryhead + "(\n"
      boundaryarray = Array.new
      startarray = Array.new
      (0..@sortedfacearray.size-1).each do |idx|
         if @sortedfacearray[idx][0] != -1
            if boundaryarray[ @sortedfacearray[idx][0] ] == nil
               boundaryarray[ @sortedfacearray[idx][0] ] = 0 
               startarray[ @sortedfacearray[idx][0] ] = idx
            end
            boundaryarray[ @sortedfacearray[idx][0] ] += 1 
         end
      end
      inlets = [ 17 ]
      outlets = [ 29 ]
      inlets = [ 5 ]
      outlets = [ 10 ]
      inlets = $globalinlet
      outlets = $globaloutlet


      (0..boundaryarray.size - 1).each do |idx|
         if inlets.member?idx
            xvel, yvel, zvel, turbk, turbeps = $globalinletdata[idx]
            boundaryfile += boundarystring("INLET#{idx}","patch", "inlet", startarray[idx], boundaryarray[idx])
            epsilonfile += foamString("INLET#{idx}", "fixedValue", "#{turbeps}")
            kfile += foamString("INLET#{idx}", "fixedValue", "#{turbk}")
            nutildafile += foamString("INLET#{idx}", "fixedValue", "0")
            pfile += foamString("INLET#{idx}", "zeroGradient", nil)
            rfile += foamString("INLET#{idx}", "fixedValue", "(0 0 0 0 0 0 0 0 0)")
            ufile += foamString("INLET#{idx}", "fixedValue", "(#{xvel} #{yvel} #{zvel})")
         elsif outlets.member?idx
            pressure = $globaloutletdata[idx]
            boundaryfile += boundarystring("OUTLET#{idx}","patch", "PressureOutlet", startarray[idx], boundaryarray[idx])
            epsilonfile += foamString("OUTLET#{idx}", "zeroGradient", nil)
            kfile += foamString("OUTLET#{idx}", "zeroGradient", nil)
            nutildafile += foamString("OUTLET#{idx}", "zeroGradient", nil)
            pfile += foamString("OUTLET#{idx}", "fixedValue", "#{pressure}")
            rfile += foamString("OUTLET#{idx}", "zeroGradient", nil)
            ufile += foamString("OUTLET#{idx}", "zeroGradient", nil)
         else
            boundaryfile += wallstring(idx, startarray[idx], boundaryarray[idx])
            epsilonfile += foamString("WALL#{idx}", "zeroGradient", nil)
            kfile += foamString("WALL#{idx}", "zeroGradient", nil)
            nutildafile += foamString("WALL#{idx}", "zeroGradient", nil)
            pfile += foamString("WALL#{idx}", "zeroGradient", nil)
            rfile += foamString("WALL#{idx}", "zeroGradient", nil)
            ufile += foamString("WALL#{idx}", "fixedValue", "(0 0 0)")
         end
      end
      boundaryfile += ")\n"
      epsilonfile += foamFooter
      kfile += foamFooter
      nutildafile += foamFooter
      pfile += foamFooter
      rfile += foamFooter
      ufile += foamFooter
      @numfaces = @sortedfacearray.size 
      facesfile = faceshead + "#{@numfaces}\n(\n" + facesstring
      facesfile += ")\n"
      ownerfile = ownerhead + "#{@numfaces}\n(\n" + ownerstring
      ownerfile += ")\n"
      neighbourfile = neighbourhead + "#{@numfaces}\n(\n" + neighbourstring
      neighbourfile += ")\n"
      #faces += "4(10 11 23 22)\n"
      #
      # cell creation
      #
      #cells = "#{numcells}\n(\n"
      # I only have to use [i,j,k]maxtmp for the cell definitions.
      #(0..imaxtmp-1).each do |idir|
      #   (0..jstart).each do |faceno|
      #      # face 0 is faceno and faceno + (jmaxtmp-1)*(kmaxtmp-1)
      #   end
      #end
      #cells += "6(1 2 3 4 5 6)\n"
      #cells += ")\n"
      #cells = openfoamcelldef(imaxtmp+1, jmaxtmp+1, kmaxtmp+1)
      #
      # write to file
      #
      begin
         FileUtils::cd($globalworkdir)
      rescue
         FXMessageBox.warning(self, MBOX_OK, "Warning","Work Dir \"#{$globalworkdir}\" doesn't exist")
      end
      #FileUtils::rm_rf($globalcasename)
      begin
         FileUtils::mkdir($globalcasename)
      rescue
      end
      begin
         FileUtils::mkdir("#{$globalcasename}/constant")
      rescue
      end
      begin
         FileUtils::mkdir("#{$globalcasename}/constant/polyMesh")
      rescue
      end
      a = File.open("#{$globalcasename}/constant/polyMesh/points", "w")
      a.write(pointsfile)
      a.close
      #File.open("#{globalcasename}2/constant/polyMesh/points", "w").close
      a = File.open("#{$globalcasename}/constant/polyMesh/faces", "w")
      a.write(facesfile)
      a.close
      a = File.open("#{$globalcasename}/constant/polyMesh/owner", "w")
      a.write(ownerfile)
      a.close
      a = File.open("#{$globalcasename}/constant/polyMesh/neighbour", "w")
      a.write(neighbourfile)
      a.close
      a = File.open("#{$globalcasename}/constant/polyMesh/boundary", "w")
      a.write(boundaryfile)
      a.close

      a = File.open("#{$globalcasename}/0/epsilon", "w")
      a.write(epsilonfile)
      a.close
      a = File.open("#{$globalcasename}/0/k", "w")
      a.write(kfile)
      a.close
      a = File.open("#{$globalcasename}/0/nuTilda", "w")
      a.write(nutildafile)
      a.close
      a = File.open("#{$globalcasename}/0/p", "w")
      a.write(pfile)
      a.close
      a = File.open("#{$globalcasename}/0/R", "w")
      a.write(rfile)
      a.close
      a = File.open("#{$globalcasename}/0/U", "w")
      a.write(ufile)
      a.close
      }
      puts "time for mesh1: #{time1.total}, mesh2: #{time2.total}, number of points #{@numpoints}" 

   end

[Source]

# File meshexport.rb, line 78
   def testhash(no1, no2, hash1)
      @no1b = no1
      @no2b = no2
      @hash1b = hash1
      if @no1b.class == Array && @no2b.class == Array
         @no1b.each do |tmp1|
            @no2b.each do |tmp2|
               if @hash1b["#{tmp1}-#{tmp2}"] != nil
                  return true, tmp1, tmp2
               end
            end
         end
      elsif @no1b.class == Array
         @no1b.each do |tmp1|
            if @hash1b["#{tmp1}-#{@no2b}"] != nil
               return true, tmp1, @no2b
            end
         end
      elsif @no2b.class == Array 
         @no2b.each do |tmp2|
            if @hash1b["#{@no1b}-#{tmp2}"] != nil
               return true, @no1b, tmp2
            end
         end
      else
         if @hash1b["#{@no1b}-#{@no2b}"] != nil
            return true, @no1b, @no2b
         end
      end
      return false, nil, nil
   end

any nils in the hash? does also work if a point is on an edge (close to more than one internal face)

[Source]

# File meshexport.rb, line 27
   def testhash2(no1, no2, hash1)
      @no1b = no1
      @no2b = no2
      @hash1b = hash1
      @result = Array.new
      if @no1b.class == Array && @no2b.class == Array
         @no1b.each do |tmp1|
            @no2b.each do |tmp2|
               if @hash1b["#{tmp1}-#{tmp2}"] != nil
                  tmpmaster, tmpif = @hash1b["#{tmp1}-#{tmp2}"].split("-")
                  @result.push( [tmpmaster.to_i, tmp1, tmp2] )
               end
            end
         end
      elsif @no1b.class == Array
         @no1b.each do |tmp1|
            if @hash1b["#{tmp1}-#{@no2b}"] != nil
                tmpmaster, tmpif = @hash1b["#{tmp1}-#{@no2b}"].split("-")
                @result.push( [tmpmaster.to_i, tmp1, @no2b] )
            end
         end
      elsif @no2b.class == Array 
         @no2b.each do |tmp2|
            if @hash1b["#{@no1b}-#{tmp2}"] != nil
               tmpmaster, tmpif = @hash1b["#{@no1b}-#{tmp2}"].split("-")
               @result.push( [tmpmaster.to_i, @no1b, tmp2] )
            end
         end
      else
         if @hash1b["#{@no1b}-#{@no2b}"] != nil
            tmpmaster, tmpif = @hash1b["#{@no1b}-#{@no2b}"].split("-")
            @result.push( [tmpmaster.to_i, @no1b, @no2b] )
         end
      end
      # is this sorting necessary?? Did not solve a thing it seems.
      sortresult = @result.sort
      #sortresult = @result.reverse
      #sortresult = @result
      if sortresult.size > 0
         @res1 = Array.new
         @res2 = Array.new
         @result.each do |tmp|
            @res1.push(tmp[1])
            @res2.push(tmp[2])
         end
         #return true, sortresult[0][1], sortresult[0][2]
         return true, @res1, @res2 
      else
         return false, nil, nil
      end
   end

[Source]

# File meshexport.rb, line 155
   def wallstring(boundarynumber, startface, nfaces )

      if startface != nil
         return "WALL#{boundarynumber}
{
    type            wall\;
    physicalType    wallFunctions\;
    startFace       #{startface}\;
    nFaces          #{nfaces}\;
}\n"
      else
         return ""
      end
   end

[Validate]