readfoamfiles.rb

Path: readfoamfiles.rb
Last Update: Thu Jun 26 23:42:52 +0200 2008

Methods

Public Instance methods

@path= "/home/bjorn/OpenFOAM/OpenFOAM-1.4.1/tutorials/twoPhaseEulerFoam/bed2/" @path= "/home/bjorn/OpenFOAM/OpenFOAM-1.4.1/tutorials/twoPhaseEulerFoam/bubbleColumn/" @path = "/home/bjorn/OpenFOAM/OpenFOAM-1.4.1/tutorials/rhoSonicFoam/shockTube/" @path = "/home/bjorn/OpenFOAM/OpenFOAM-1.4.1/tutorials/nonNewtonianIcoFoam/offsetCylinder/" @path += "constant/polyMesh/" @path = "/home/bjorn/default/constant/polyMesh/" @path="/home/bjorn/OpenFOAM/OpenFOAM-1.4.1/tutorials/simpleFoam/pitzDailyExptInlet/constant/polyMesh/" @path = "/home/bjorn/cube/constant/polyMesh/"

[Source]

# File readfoamfiles.rb, line 33
def readpolymesh(path)
@path = path
@path += "/constant/polyMesh/"
# read points
# read file
file = File.new(@path+"points", "r")
points = file.read
file.close
# check point num
test = points.scan(/\d*[\s]?\([\s]?\(/)
test2 = test[0]
test2.gsub!(/[\(|\)]/,"")
puts "points size should be #{test2.to_i}"
# extract data
points2 = points.scan(/\(([\w|\W|\s]{0,})\)/)
points3 = points2[0][0].split(/\)\s\(/)
$points4 = Array.new
points3.each do |tmp|
   tmp.gsub!(/[\(|\)|\n]/,"")
   tmp2 = tmp.split(/\s/)
   $points4.push( [ tmp2[0].to_f, tmp2[1].to_f, tmp2[2].to_f ] )
   #puts "string/float x: #{tmp2[0]}/#{tmp2[0].to_f}, #{tmp2[1]}/#{tmp2[1].to_f}, #{tmp2[2]}/#{tmp2[2].to_f}"
   #puts "(#{tmp2[0]} #{tmp2[1]} #{tmp2[2]})"
end
# test size
if test2.to_i == $points4.size 
   puts "points input size correct (#{$points4.size})"
else
   puts "something wrong with points input (#{$points4.size})"
end


# read faces
# read file
file = File.new(@path+"faces", "r")
faces = file.read
file.close
# check point num
test = faces.scan(/\d*[\s]?\([\s]?\d+?\(/)
test2 = test[0].split(/\n/)[0]
test2.gsub!(/[\(|\)]/,"")
puts "faces size should be #{test2}"
# extract data
faces2 = faces.scan(/\(([\w|\W|\s]{0,})\)/)
faces3 = faces2[0][0].split(/\d+\(/)
faces3.shift
$faces4 = Array.new
faces3.each do |tmp|
   tmp.gsub!(/[\(|\)|\n]/,"")
   tmp2 = tmp.split(/\s/)
   $faces4.push( [ tmp2[0].to_i, tmp2[1].to_i, tmp2[2].to_i, tmp2[3].to_i ] )
   #puts "string/integer x: #{tmp2[0]}/#{tmp2[0].to_i}, #{tmp2[1]}/#{tmp2[1].to_i}, #{tmp2[2]}/#{tmp2[2].to_i}, #{tmp2[3]}/#{tmp2[3].to_i}"
   #puts "4(#{tmp2[0].to_i} #{tmp2[1].to_i} #{tmp2[2].to_i} #{tmp2[3].to_i})"
end
# test size
if test2.to_i == $faces4.size 
   puts "faces input size correct (#{$faces4.size})"
else
   puts "something wrong with faces input (#{$faces4.size})"
end
####################################################################################################
# read boundary
# read file
file = File.new(@path+"boundary", "r")
boundary = file.read
file.close
# check point num
test = boundary.scan(/\d*[\s]?\([\w]*/)
test2 = test[0].split(/\s/)[0]
test2.gsub!(/[\(|\)]/,"")
puts "boundary size should be #{test2}"
# extract data
#boundary2 = boundary.scan(/\(([\w|\W|\s]{0,})\)/)
boundary2 = boundary.scan(/\s+\(([\w|\W|\s]{0,})\)/)
boundary3 = boundary2[0][0].split(/\}/)
#puts "boundary3 size #{boundary3.size}"
boundary3.pop
$boundary4 = Array.new
boundary3.each do |tmp|
   # format of boundary4 array [ [ "name", type, "type", physicalType, "physicalType", nFaces, n, startFace, "startFace" ] [...] ]
   info = tmp.split("{")
   name = info[0].gsub!(/[\(|\)|\n]/,"")
   rest = info[1].split( ";" )
   @infolist = Array.new
   @infolist.push(name)
   rest.each do |tmp2|
      tmp3 = tmp2.split("\s")
      if tmp3.size > 0
        tmp3.each do |tmp4|
           @infolist.push(tmp4)
        end
      end
   end
   $boundary4.push( @infolist ) 
end
# test size
if test2.to_i == $boundary4.size 
   puts "boundary input size correct (#{$boundary4.size})"
else
   puts "something wrong with boundary input (#{$boundary4.size})"
end
 
####################################################################################################

if false
# print result
$points4.each do |tmp|
   tmp.each do |tmp2|
      print "#{tmp2} "
   end
   print "\n"
end
# print result
$faces4.each do |tmp|
   tmp.each do |tmp2|
      print "#{tmp2} "
   end
   print "\n"
end
end
if false
$boundary4.each do |bndry|
   bndry.each do |item|
      print "#{item} "
   end
   print "\n"
end
end
   $boundary4.each do |bndry|
      test = LiteFace3.new(bndry)
      test.show
      $globalobjects.push(test)
   end
end

[Validate]