| Module | CommonTasks |
| In: |
methods.rb
|
# File methods.rb, line 881 def celldef(vertex) cell = Array.new cellnum = 0 rowlength = vertex[0].size collength = vertex.size truefalse = [true,false] (0..vertex.size-2).each do |row| truefalse = truefalse.reverse tmptruefalse = truefalse (0..vertex[0].size-2).each do |col| cell[cellnum] = [col+row*rowlength, col+row*rowlength+1, col+(1+row)*rowlength+1, col+(1+row)*rowlength, tmptruefalse[0]] cellnum += 1 tmptruefalse = tmptruefalse.reverse end end return cell end
# File methods.rb, line 868 def celldefold(vertex) cell = Array.new cellnum = 0 rowlength = vertex[0].size collength = vertex.size (0..vertex.size-2).each do |row| (0..vertex[0].size-2).each do |col| cell[cellnum] = [row+row*collength, row+row*collength+1, row+(1+row)*collength+1, row+(1+row)*collength] cellnum += 1 end end return cell end
# File methods.rb, line 74 def checkslave(input, depth) if ($compactmeshref[input[0]][0] == nil && $compactmeshref[input[0]][1] == nil && $compactmeshref[input[0]][2] == nil && $compactmeshref[input[0]][3] == nil && $compactmeshref[input[0]][4] == nil) || input[2] == nil || depth > 50 return input else # find out where to look # maybe I have to check something else if input[1] == "meshx" depth += 1 checkslave($compactmeshref[input[0]][1], depth) elsif input[1] == "meshy" depth += 1 checkslave($compactmeshref[input[0]][2], depth) elsif input[1] == "meshz" depth += 1 checkslave($compactmeshref[input[0]][3], depth) elsif input[1] == "meshnum" depth += 1 checkslave($compactmeshref[input[0]][4], depth) end end end
start compact meshref
# File methods.rb, line 38 def compactmeshrefrow(meshrefrow) refrow = meshrefrow # find row dependents, meshx, meshy and meshnum, store in arrays slaverow, slavex, slavey, slavez, slavenum = Array.new, Array.new, Array.new, Array.new, Array.new if refrow.size > 0 (2..refrow.size - 1).step(3) do |idx| if refrow[idx] == nil && refrow[idx-1] != nil slaverow.push([ refrow[idx-2], refrow[idx-1] ]) # a zero because I use Array.sort later on end if refrow[idx] == "meshx" slavex.push([ refrow[idx-2], refrow[idx-1], refrow[idx] ]) end if refrow[idx] == "meshy" slavey.push([ refrow[idx-2], refrow[idx-1], refrow[idx] ]) end if refrow[idx] == "meshz" slavez.push([ refrow[idx-2], refrow[idx-1], refrow[idx] ]) end if refrow[idx] == "meshnum" slavenum.push([ refrow[idx-2], refrow[idx-1], refrow[idx] ]) end end begin sortrow = slaverow.sort[0] sortrow = [ sortrow[0], sortrow[1], nil] if sortrow != nil sortx = slavex.sort[0] sorty = slavey.sort[0] sortz = slavez.sort[0] sortnum = slavenum.sort[0] rescue return nil, nil, nil, nil, nil end return sortrow, sortx, sorty, sortz, sortnum end return nil, nil, nil, nil, nil end
create cell definition
# File methods.rb, line 744 def createCellDef(meshx, meshy) celldef = Array.new cellnum = 0 truefalse = [true,false] (0..meshy-2).each do |ydir| truefalse = truefalse.reverse tmptruefalse = truefalse (0..meshx-2).each do |xdir| celldef[cellnum] = [xdir+ydir*meshx, xdir+ydir*meshx+1, xdir+(1+ydir)*meshx+1, xdir+(1+ydir)*meshx, tmptruefalse[0]] cellnum += 1 tmptruefalse = tmptruefalse.reverse end end if false # true/false print "celldef: " celldef.each do |tmp| tmp.each do |def1| print def1 print ", " end print "\n" end end # if true/false return celldef end
for given celldef array you get l[0|1|2|3]def
# File methods.rb, line 771 def findAllLdef(celldef) if celldef.size == 0 return 0 end @celldef = celldef def findnextl0(currentcell) ressize = @res0.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell @res0.push(@celldef[cellno1][1]) @cell0.push(cellno1) break end end if ressize == @res0.size @flag = false end end def findnextl1(currentcell) ressize = @res1.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell @res1.push(@celldef[cellno1][2]) @cell1.push(cellno1) break end end if ressize == @res1.size @flag = false end end def findnextl2(currentcell) ressize = @res2.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell @res2.push(@celldef[cellno1][3]) @cell2.push(cellno1) break end end if ressize == @res2.size @flag = false end end def findnextl3(currentcell) ressize = @res3.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][3] == @celldef[currentcell][0] && cellno1 != currentcell @res3.push(@celldef[cellno1][0]) @cell3.push(cellno1) break end end if ressize == @res3.size @flag = false end end @res0 = Array.new @res0.push( celldef[0][0] ) @res0.push( celldef[0][1] ) @cell0 = Array.new @cell0.push(0) @flag = true while @flag findnextl0(@cell0.last) end @res1 = Array.new @res1.push( celldef[@cell0.last][1] ) @res1.push( celldef[@cell0.last][2] ) @cell1 = Array.new @cell1.push(@cell0.last) @flag = true while @flag findnextl1(@cell1.last) end @res2 = Array.new @res2.push( celldef[@cell1.last][2] ) @res2.push( celldef[@cell1.last][3] ) @cell2 = Array.new @cell2.push(@cell1.last) @flag = true while @flag findnextl2(@cell2.last) end @res3 = Array.new @res3.push( celldef[@cell2.last][3] ) @res3.push( celldef[@cell2.last][0] ) @cell3 = Array.new @cell3.push(@cell2.last) @flag = true while @flag findnextl3(@cell3.last) end #puts "l0.size #{@res0.size}, l1.size #{@res1.size}, l2.size #{@res2.size}, l3.size #{@res3.size}" return @res0, @res1, @res2, @res3 end
# File methods.rb, line 139 def findconnections(table) @connections = Array.new (0..$MAX_ROW-1).each do |row| if table.getItemText(row,0) != "" @connections[row] = Array.new (($MAX_ATTRIB_SIZE*2 + 1)..$MAX_COL-1).each do |col| text = table.getItemText(row, col) if text != "" && text[0,4] != "csys" refrow, refname = reffind(row, col, table) if refrow != nil @connections[row] += [ row, table.getItemText(row, 0), text ] @connections[row] += [ refrow, table.getItemText(refrow, 0), refname ] end end end end end return @connections end
# File methods.rb, line 776 def findnextl0(currentcell) ressize = @res0.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][0] == @celldef[currentcell][1] && cellno1 != currentcell @res0.push(@celldef[cellno1][1]) @cell0.push(cellno1) break end end if ressize == @res0.size @flag = false end end
# File methods.rb, line 789 def findnextl1(currentcell) ressize = @res1.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][1] == @celldef[currentcell][2] && cellno1 != currentcell @res1.push(@celldef[cellno1][2]) @cell1.push(cellno1) break end end if ressize == @res1.size @flag = false end end
# File methods.rb, line 802 def findnextl2(currentcell) ressize = @res2.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][2] == @celldef[currentcell][3] && cellno1 != currentcell @res2.push(@celldef[cellno1][3]) @cell2.push(cellno1) break end end if ressize == @res2.size @flag = false end end
# File methods.rb, line 815 def findnextl3(currentcell) ressize = @res3.size (0..@celldef.size-1).each do |cellno1| if @celldef[cellno1][3] == @celldef[currentcell][0] && cellno1 != currentcell @res3.push(@celldef[cellno1][0]) @cell3.push(cellno1) break end end if ressize == @res3.size @flag = false end end
extract the csys from the selbuffer and return csys ans ref
# File methods.rb, line 432 def getcsys(selection) ref = Array.new csys = $defaultcsys selection.each do |sel| if sel.class == Csys csys = sel else ref.push(sel) end end return csys, ref end
# File methods.rb, line 444 def getfaces(selection) faces = Array.new selection.each do |sel| if sel.class == InfoFace || sel.class == LiteFace faces.push(sel) end end if faces.size > 0 return faces else return nil end end
find 2l faces for mesh assigning connections in format [ currentrow, "l0", "*" , row, "p0", "*" ]
# File methods.rb, line 273 def getmeshref(connections) @meshref = Array.new (0..connections.size - 1).each do |tmp| @meshref[tmp] = Array.new end connections.each do |cons| if cons[1] == nil # do nothing elsif cons[1][0,1] == "f" # InfoFace2l if cons.size == 12 if cons[3] < cons[9] test1, row1 = whichmeshref( cons[3], cons[5], true, connections ) test2, row2 = whichmeshref( cons[9], cons[11], false, connections ) @meshref[ cons[9] ].push( row1, test1 , test2 ) else test1, row1 = whichmeshref( cons[9], cons[11], true, connections ) test2, row2 = whichmeshref( cons[3], cons[5], false, connections ) @meshref[ cons[3] ].push( row1, test1 , test2 ) end # InfoFace4l elsif cons.size == 24 if cons[3] < cons[15] test1, row1 = whichmeshref( cons[3], cons[5], true, connections) test2, row2 = whichmeshref( cons[15], cons[17], false, connections) @meshref[ cons[15] ].push( row1, test1 , test2 ) else test1, row1 = whichmeshref( cons[15], cons[17], true, connections ) test2, row2 = whichmeshref( cons[3], cons[5], false, connections ) @meshref[ cons[3] ].push( row1, test1 , test2 ) end if cons[9] < cons[21] test1, row1 = whichmeshref( cons[9], cons[11], true, connections ) test2, row2 = whichmeshref( cons[21], cons[23], false, connections ) @meshref[ cons[21] ].push( row1, test1 , test2 ) else test1, row1 = whichmeshref( cons[21], cons[23], true, connections ) test2, row2 = whichmeshref( cons[9], cons[11], false, connections ) @meshref[ cons[9] ].push( row1, test1 , test2 ) end end elsif cons[1][0,1] == "c" # a cube end end return @meshref end
# File methods.rb, line 738 def havePoint(points,pointnum) rowlen = points[0].size return points[(pointnum/rowlen).to_i][pointnum-(pointnum/rowlen).to_i*rowlen] end
# File methods.rb, line 564 def invPositionInCsys(csys, pos) # cart2cylindrical # 3 possible coordinate systems # "normal" -> cartesian x,y,z # "cyl" -> cylindrical r, fi, z (fi in degrees) # "spherical" -> spherical r, fi, theta (fi, theta in degrees) # Just thinking! # cylindrical/spherical csys with ref to cartesian coordinate system is placed in cartesian coordinates # csys with ref to cylindrical/spherical coordinate system is placed in cylindrical/spherical coordinates? # puts "inpos was #{pos[0]}, #{pos[1]}, #{pos[2]}" #p = [csys.xpos, csys.ypos, csys.zpos] p = [0.0,0.0,0.0] vp = [-csys.xpos+pos[0], -csys.ypos + pos[1], -csys.zpos + pos[2] ] # transform x-axis # rotateX(p,ang,v) vp = rotateZ(p, -csys.zrot, vp).to_a vp = rotateY(p, -csys.yrot, vp).to_a vp = rotateX(p, -csys.xrot, vp).to_a # puts "invpos before case was #{vp[0]}, #{vp[1]}, #{vp[2]}" case csys.csystype when 0 # pos is ready to be used #puts "thats normal" when 1 # pos has to be converted to r,fi,z-coordinates #puts "it's cylindrical" #vp[0].to_f==0 ? ang1=0:ang1 = toDeg(Math::atan(vp[1]/vp[0])) #length0 = vectLength([vp[0],vp[1],0]) #ang1 = solidAtan(vp[0],vp[1]) #vp[0] = length0 #vp[1] = ang1 vp = cart2cyl(vp[0], vp[1], vp[2]) when 2 # pos has to be converted to r,fi,theta-coordinates #puts "a spherical csys" ?? vp = cart2spherical(vp[0], vp[1], vp[2]) end # puts "invpos was #{vp[0]}, #{vp[1]}, #{vp[2]}" return vp end
# File methods.rb, line 626 def invPositionInCsysAlot(csys, xvec, yvec, zvec) maxlen = [ xvec.size, yvec.size, zvec.size ].min - 1 xres, yres, zres = Array.new, Array.new, Array.new puts maxlen (0..maxlen).each do |tmp| xres[tmp], yres[tmp], zres[tmp] = invPositionInCsys( csys, [xvec[tmp], yvec[tmp], zvec[tmp] ] ) end return xres, yres, zres end
# File methods.rb, line 635 def invPositionInCsysold(csys, pos) # 3 possible coordinate systems # "normal" -> cartesian x,y,z # "cyl" -> cylindrical r, fi, z (fi in degrees) # "spherical" -> spherical r, fi, theta (fi, theta in degrees) # Just thinking! # cylindrical/spherical csys with ref to cartesian coordinate system is placed in cartesian coordinates # csys with ref to cylindrical/spherical coordinate system is placed in cylindrical/spherical coordinates? # puts "inpos was #{pos[0]}, #{pos[1]}, #{pos[2]}" #p = [csys.xpos, csys.ypos, csys.zpos] p = [0.0,0.0,0.0] vp = [-csys.xpos+pos[0], -csys.ypos + pos[1], -csys.zpos + pos[2] ] # transform x-axis # rotateX(p,ang,v) vp = rotateZ(p, -csys.zrot, vp).to_a vp = rotateY(p, -csys.yrot, vp).to_a vp = rotateX(p, -csys.xrot, vp).to_a # puts "invpos before case was #{vp[0]}, #{vp[1]}, #{vp[2]}" case csys.csystype when 0 # pos is ready to be used #puts "thats normal" when 1 # pos has to be converted to r,fi,z-coordinates #puts "it's cylindrical" length0 = vectLength([vp[0],vp[1],0]) #vp[0].to_f==0 ? ang1=0:ang1 = toDeg(Math::atan(vp[1]/vp[0])) ang1 = solidAtan(vp[0],vp[1]) vp[0] = length0 vp[1] = ang1 when 2 # pos has to be converted to r,fi,theta-coordinates #puts "a spherical csys" length0 = vectLength([ vp[0],vp[1],vp[2] ]) ang1 = solidAtan(vp[0],vp[1]) ang2 = solidAtan(vp[0],vp[2]) vp[0] = length0 vp[1] = ang1 vp[2] = ang2 vp[1].abs == 180.0 ? vp[1] = 0.0:nil #vp[2].abs == 180.0 ? vp[2] = 0.0:nil #(vp[1].abs == 180.0 || vp[2].abs == 180.0) ? vp[2] = 0.0:nil (vp[1].abs == 90.0 || vp[1].abs == 270.0) ? vp[2] = 0.0:nil (vp[2].abs == 90.0 || vp[2].abs == 270.0) ? vp[1] = 0.0:nil #vp[2] == 270.0 ? vp[2] = 90.0:vp[2] = vp[2] end # puts "invpos was #{vp[0]}, #{vp[1]}, #{vp[2]}" return vp end
# File methods.rb, line 95 def makefinalref ###REMOVE PRINTOUT#################################################################################### puts "start " $compactmeshref.each do |tmp| print "compactmeshref: " tmp.each do |tmp2| if tmp2 != nil tmp2.each do |tmp3| print "#{tmp3} " end end end print "\n" end ###REMOVE PRINTOUT#################################################################################### (0..$compactmeshref.size-1).each do |row| (0..4).each do |idx| if $compactmeshref[row][idx] != nil rootnum = checkslave( $compactmeshref[row][idx],0 ) begin $compactmeshref[row][idx] = [ rootnum[0], rootnum[1], $compactmeshref[row][idx][2] ] rescue end end end end end
figure out which object type from table
# File methods.rb, line 159 def objtype(inputarray, row) cons = inputarray[row] if cons[1] == nil return nil elsif cons[1][0,1] == "l" if ( cons[4][0,1] == "p" && cons[5] == "*" ) || cons[5][0,1] == "p" return "InfoLine" end elsif cons[1][0,1] == "f" if ( cons[4][0,1] == "p" && cons[5] == "*" ) || cons[5][0,1] == "p" return "InfoFace1p" elsif (( cons[4][0,1] == "l" && cons[5] == "*" ) || cons[5][0,1] == "l" ) && cons.size == 6 return "InfoFace1l" elsif (( cons[4][0,1] == "l" && cons[5] == "*" ) || cons[5][0,1] == "l" ) && cons.size == 12 return "InfoFace2l" elsif (( cons[4][0,1] == "l" && cons[5] == "*" ) || cons[5][0,1] == "l" ) && cons.size == 24 return "InfoFace4l" end elsif cons[1][0,1] == "c" if ( cons[4][0,1] == "p" && cons[5] == "*" ) || cons[5][0,1] == "p" return "InfoCube1p" elsif (( cons[4][0,1] == "f" && cons[5] == "*" ) || cons[5][0,1] == "f") && cons.size == 6 return "InfoCube1f" end end return nil end
returns the openfoam bc numbering
# File methods.rb, line 899 def openfoambcno(selbuffer,objects) if selbuffer == InfoFace || selbuffer == LiteFace selbuffer = [ selbuffer ] end @cubes = Array.new objects.objects.each do |tmp| if tmp.class.to_s[0,8] == "InfoCube" @cubes.push(tmp) end end @result = Array.new selbuffer.each do |selected| if selected.class == InfoFace || selected.class == LiteFace @cubes.each_with_index do |cube1, cubeno| cube1.if.each_with_index do |internalface, intno| if internalface.parent == selected tmpres = cubeno*6 + iftobc(intno) @result.push( tmpres ) end end end end end return @result end
if you know the position in reference coordinate system, you get the position in global cartesian coordinate system with positionInCsys method. If you know the position in global cartesian coordinate system and want the position in reference coordinate system use the invPositionInCsys method.
# File methods.rb, line 516 def positionInCsys(csys, pos) # 3 possible coordinate systems # "normal" -> cartesian x,y,z # "cyl" -> cylindrical r, fi, z (fi in degrees) # "spherical" -> spherical r, fi, theta (fi, theta in degrees) # Just thinking! # cylindrical/spherical csys with ref to cartesian coordinate system is placed in cartesian coordinates # csys with ref to cylindrical/spherical coordinate system is placed in cylindrical/spherical coordinates? if csys.count == 0 return pos end case csys.csystype when 0 # pos is ready to be used #puts "thats normal" # page 251 BETA when 1 # pos has to be converted to x,y,z-coordinates #puts "it's cylindrical" # tmppos = [pos[0], 0, pos[2]] # pos = rotateZ([0,0,0], -toRad(pos[1]), tmppos).to_a pos = cyl2cart(pos[0], pos[1], pos[2]) # puts "pos #{pos[0]}, #{pos[1]}, #{pos[2]}" # page 252 BETA when 2 # pos has to be converted to x,y,z-coordinates #puts "a spherical csys" # tmppos = [pos[0], 0.0, 0.0] # tmppos = rotateZ([0,0,0], -toRad(pos[1]), tmppos).to_a # pos = rotateY([0,0,0], toRad(pos[2]), tmppos).to_a pos = spherical2cart(pos[0], pos[1], pos[2]) # puts "pos #{pos[0]}, #{pos[1]}, #{pos[2]}" end p = [csys.xpos, csys.ypos, csys.zpos] # better than a crash. begin vp = [csys.xpos+pos[0], csys.ypos + pos[1], csys.zpos + pos[2] ] rescue vp = [0.0, 0.0, 0.0] end # transform x-axis # rotateX(p,ang,v) vp = rotateX(p, csys.xrot, vp).to_a vp = rotateY(p, csys.yrot, vp).to_a vp = rotateZ(p, csys.zrot, vp).to_a return vp end
# File methods.rb, line 618 def positionInCsysAlot(csys, xvec, yvec, zvec) maxlen = [ xvec.size, yvec.size, zvec.size ].min - 1 xres, yres, zres = Array.new, Array.new, Array.new (0..maxlen).each do |tmp| xres[tmp], yres[tmp], zres[tmp] = positionInCsys( csys, [xvec[tmp], yvec[tmp], zvec[tmp] ] ) end return xres, yres, zres end
# File methods.rb, line 457 def radiusadjust(x, y, z, radius, xaxis, yaxis, zaxis, refattr) l = vertexDistance([x.first, y.first, z.first], [x.last, y.last, z.last]).to_f radius = 0.51 * l if radius < (l/2.01) dist = Math::sqrt(radius**2 - l**2/4) movvec = crossSpecial([x.first, y.first, z.first], [x.last, y.last, z.last], [xaxis, yaxis, zaxis]) xreturn = Array.new yreturn = Array.new zreturn = Array.new if refattr == 0 direction = 1.0 else direction = -1.0 end meshint = (x.size-1).to_f (0..x.size-1).each do |num| xreturn[num] = x[num] + (Math::sqrt(radius**2-(l/2 - l*num/meshint)**2) - dist)*movvec[0]*direction yreturn[num] = y[num] + (Math::sqrt(radius**2-(l/2 - l*num/meshint)**2) - dist)*movvec[1]*direction zreturn[num] = z[num] + (Math::sqrt(radius**2-(l/2 - l*num/meshint)**2) - dist)*movvec[2]*direction end return xreturn, yreturn, zreturn end
# File methods.rb, line 478 def radiusadjustold(xvec, yvec, zvec, radius, xaxis, yaxis, zaxis,meshnum, refattr) # h=sqrt(R^2-(L/2-d)^2) l=vectLength([xvec[0]-xvec.to_a.last,yvec[0]-yvec.to_a.last,zvec[0]-zvec.to_a.last]) if radius < l / 2.01 radius = 0.51 * l end dist = Math::sqrt(radius**2 - l.to_f**2/4 ) arr = Array.new (0..(meshnum-1)).each do |i| arr[i] = Math::sqrt(radius**2 - (l.to_f/2 - l.to_f*i/(meshnum-1))**2 ) -dist end movdist = Vector.elements( arr ) movvec = Vector.elements( crossSpecial([xvec[0],yvec[0],zvec[0]], [xvec.to_a.last, yvec.to_a.last, zvec.to_a.last], [xaxis, yaxis, zaxis]) ) if refattr == 0 xvec += movdist*movvec[0] yvec += movdist*movvec[1] zvec += movdist*movvec[2] else xvec -= movdist*movvec[0] yvec -= movdist*movvec[1] zvec -= movdist*movvec[2] end return xvec, yvec, zvec end
new mesh num function start
# File methods.rb, line 129 def reffind(row, col, table ) while row > 0 row -= 1 text = @table.getItemText(row,col) if text != "" return row, text end end return nil, nil end
setmesh can access parent.class, parent.reftype, @info[2] to decide how to adjust parent object to get the right mesh count obj = face line, num = mesh points, noFromRow = mesh number from row
# File methods.rb, line 327 def setmesh(obj,num, noFromRow) # test if it's a line # have to find faces connected to line if obj.class == InfoLine oldnum = obj.meshnum obj.meshnum = num obj.meshNoFromRow = noFromRow if obj.meshNoFromRow == nil #if oldnum != num #$updatelater.push(obj) #obj.select obj.update #end elsif obj.class == DefLine if obj.info[0].class == InfoFace case obj.info[0].reftype when "1p" #oldnum = obj.info[0].meshx if obj.info[2] == "l0" || obj.info[2] == "l2" #oldnum = obj.info[0].meshy if obj.info[2] == "l1" || obj.info[2] == "l3" #obj.info[0].meshx = num if obj.info[2] == "l0" || obj.info[2] == "l2" #obj.info[0].meshy = num if obj.info[2] == "l1" || obj.info[2] == "l3" oldnum = obj.info[0].meshx if obj.info[1] == obj.info[0].firstline || obj.info[1] == obj.info[0].thirdline oldnum = obj.info[0].meshy if obj.info[1] == obj.info[0].secondline || obj.info[1] == obj.info[0].fourthline obj.info[0].meshx = num if obj.info[1] == obj.info[0].firstline || obj.info[1] == obj.info[0].thirdline obj.info[0].meshy = num if obj.info[1] == obj.info[0].secondline || obj.info[1] == obj.info[0].fourthline #if oldnum != num $updatelater.push(obj.info[0]) #obj.info[0].select # obj.info[0].update #end when "1l" #if obj.info[2] == "l1" || obj.info[2] == "l3" if obj.info[1] == obj.info[0].secondline || obj.info[1] == obj.info[0].fourthline oldnum = obj.info[0].meshnum obj.info[0].meshnum = num if oldnum != num && obj.info[0].row < row $updatelater.push(obj.info[0]) #obj.info[0].select # obj.info[0].update end else setmesh(obj.info[0].l0, num, noFromRow) end when "2l" #if obj.info[2] == "l0" || obj.info[2] == "l2" if obj.info[1] == obj.info[0].firstline || obj.info[1] == obj.info[0].thirdline if obj.info[0].l0.info[0].row < obj.info[0].l2.info[0].row if obj.info[0].l0.class == InfoLine oldnum = obj.info[0].l0.meshnum obj.info[0].l0.meshnum = num if oldnum != num $updatelater.push(obj.info[0]) #obj.info[0].update end elsif obj.info[0].l0.class = DefLine setmesh(obj.info[0].l0, num, noFromRow) end else if obj.info[0].l2.class == InfoLine oldnum = obj.info[0].l2.meshnum obj.info[0].l2.meshnum = num if oldnum != num #obj.info[0].update $updatelater.push(obj.info[0]) end elsif obj.info[0].l2.class = DefLine setmesh(obj.info[0].l2, num, noFromRow) end end # l1 andl l3 else oldnum = obj.info[0].meshnum obj.info[0].meshnum = num if oldnum != num #obj.info[0].update $updatelater.push(obj.info[0]) end end when "4l" $updatelater.push(obj.info[0]) end elsif obj.info[0].class == InfoCube1p #i: l0, l2, l10, l8 #j: l1, l3, l9, l11 #k: l4, l5, l6, l7 oldnum = obj.info[0].meshx if obj.info[2] == "l0" || obj.info[2] == "l2" || obj.info[2] == "l10" || obj.info[2] == "l8" oldnum = obj.info[0].meshy if obj.info[2] == "l1" || obj.info[2] == "l3" || obj.info[2] == "l9" || obj.info[2] == "l11" oldnum = obj.info[0].meshz if obj.info[2] == "l4" || obj.info[2] == "l5" || obj.info[2] == "l6" || obj.info[2] == "l7" obj.info[0].meshx = num if obj.info[2] == "l0" || obj.info[2] == "l2" || obj.info[2] == "l10" || obj.info[2] == "l8" obj.info[0].meshy = num if obj.info[2] == "l1" || obj.info[2] == "l3" || obj.info[2] == "l9" || obj.info[2] == "l11" obj.info[0].meshz = num if obj.info[2] == "l4" || obj.info[2] == "l5" || obj.info[2] == "l6" || obj.info[2] == "l7" if oldnum != num && noFromRow < obj.info[0].row #obj.info[0].update $updatelater.push(obj.info[0]) end elsif obj.info[0].class == InfoCube1f oldnum = obj.info[0].meshnum if obj.info[2] == "l4" || obj.info[2] == "l5" || obj.info[2] == "l6" || obj.info[2] == "l7" obj.info[0].meshnum = num if obj.info[2] == "l4" || obj.info[2] == "l5" || obj.info[2] == "l6" || obj.info[2] == "l7" if oldnum != num && noFromRow < obj.info[0].row #obj.info[0].update $updatelater.push(obj.info[0]) end end end end
a atan that works all the time… returns angle in degrees atan(v1/v2) or atan(x-coord,y-coord) could be further generalized
# File methods.rb, line 702 def solidAtan(v1,v2) calculationerror=1e-12 if v1.to_f.abs <= calculationerror && v2.to_f.abs <= calculationerror return 0.0 elsif v1.to_f > calculationerror && v2.to_f.abs <= calculationerror return 0.0 elsif v1.to_f < calculationerror && v2.to_f.abs <= calculationerror return 180.0 elsif v1.to_f.abs <= calculationerror && v2.to_f > calculationerror return 90.0 elsif v1.to_f.abs <= calculationerror && v2.to_f < calculationerror return 270.0 elsif v1.to_f > calculationerror && v2.to_f > calculationerror return toDeg(Math::atan(v2/v1)) elsif v1.to_f < calculationerror && v2.to_f > calculationerror return toDeg(Math::atan(-v1/v2))+90.0 elsif v1.to_f < calculationerror && v2.to_f < calculationerror return toDeg(Math::atan(v2/v1))+180.0 elsif v1.to_f > calculationerror && v2.to_f < calculationerror return toDeg(Math::atan(-v1/v2))+270.0 else ang1 = 0.0 end if ang1 >= 360.0 ang1 -= 360.0 end return ang1 end
for theta calculation atan(x,z)
# File methods.rb, line 685 def solidAtan2(v1,v2) ang1 = 0.0 v2.to_f == 0.0 && v1.to_f == 0.0 ? ang1 = 0.0:nil v2.to_f == 0.0 && v1.to_f > 0.0 ? ang1 = 0.0:nil v2.to_f > 0.0 && v1.to_f == 0.0 ? ang1 = 270.0:nil v2.to_f == 0.0 && v1.to_f < 0.0 ? ang1 = 180.0:nil v2.to_f < 0.0 && v1.to_f == 0.0 ? ang1 = 90.0:nil v2.to_f > 0.0 && v1.to_f > 0.0 ? ang1 = toDeg(Math::atan(v2/v1))+270:nil v2.to_f > 0.0 && v1.to_f < 0.0 ? ang1 = toDeg(Math::atan(-v1/v2))+180:nil v2.to_f < 0.0 && v1.to_f < 0.0 ? ang1 = toDeg(Math::atan(v2/v1))+90:nil v2.to_f < 0.0 && v1.to_f > 0.0 ? ang1 = toDeg(Math::atan(-v1/v2)):nil return ang1 end
see if two lines are conneced
# File methods.rb, line 26 def test2lconn(line1, line2) if line1.firstpoint == line2.firstpoint || line1.firstpoint == line2.lastpoint || line1.lastpoint == line2.firstpoint || line1.lastpoint == line2.lastpoint #puts "it's a 2lconn" return true else #puts "it's NOT a 2lconn" return false end end
# File methods.rb, line 730 def truefalse(xind,yind) if xind % 2 == 0 && yind % 2 == 0 || xind % 2 != 0 && yind % 2 != 0 return true else return false end end
do something like whichmeshref( row, "l7") (would be something like "meshnum", "meshy"..)
# File methods.rb, line 187 def whichmeshref( row, name , recurse, connections) test = objtype(connections, row) case test when "InfoLine" return "meshnum", row when "InfoFace1p" if name == "l0" || name == "l2" return "meshx", row elsif name == "l1" || name == "l3" return "meshy", row else return "InfoFace1p" , row end when "InfoFace1l" if name == "l1" || name == "l3" return "meshnum", row elsif recurse # find which reference l0 and l2 has whichmeshref( connections[row][3], connections[row][5], true, connections ) else return nil end when "InfoFace2l" if name == "l1" || name == "l3" return "meshnum", row elsif name == "l0" || name == "l2" # find which reference l0 has # 5 f3 l0 3 f1 l2 5 f3 l2 4 f2 l2 if recurse if connections[row][3] < connections[row][9] whichmeshref( connections[row][3], connections[row][5], true, connections ) else whichmeshref( connections[row][9], connections[row][11], true, connections ) end else return nil end else return "InfoFace2l", row end when "InfoFace4l" if recurse if name == "l0" || name == "l2" ##if name == "l1" || name == "l3" # 3 l0 9 l1 15 l2 20 l3 # 6 f4 l0 3 f1 l1 6 f4 l1 5 f3 l3 6 f4 l2 4 f2 l3 6 f4 l3 2 f0 l3 if connections[row][3] < connections[row][15] whichmeshref( connections[row][3],connections[row][5], true, connections ) else whichmeshref( connections[row][15],connections[row][17], true, connections ) end elsif name == "l1" || name == "l3" ##elsif name == "l0" || name == "l2" if connections[row][9] < connections[row][21] whichmeshref( connections[row][9],connections[row][11], true, connections ) else whichmeshref( connections[row][21],connections[row][23], true, connections ) end else return "InfoFace4l", row end else return nil end when "InfoCube1p" if name == "l0" || name == "l2" || name == "10" || name == "l8" return "meshx", row elsif name == "l1" || name == "l3" || name == "l9" || name == "l11" return "meshy", row elsif name == "l4" || name == "l5" || name == "l6" || name == "l7" return "meshz", row else # recurse here return "InfoCube1p", row end when "InfoCube1f" if name == "l4" || name == "l5" || name == "l6" || name == "l7" return "meshnum", row else # recurse here return "InfoCube1f", row end end end