def read(self): beamReader = FluentCase(self.beamCaseFile) beamReader.read() print 'beam mesh read in. Done!' print '------------------------------------------------------------' self.solidMeshes = beamReader.getMeshList() self.geomFields = models.GeomFields('geom') self.solidMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.solidMeshes) self.solidMetricsCalculator.init() fluidReader = FluentCase(self.fluidCaseFile) fluidReader.read() print 'fluid mesh read in. Done!' print '------------------------------------------------------------' self.fluidMeshes = fluidReader.getMeshList() self.fluidMeshesNew = self.fluidMeshes self.fluidMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.fluidMeshes) self.fluidMetricsCalculator.init() self.solidBoundaryMeshes = [ m.extrude(1, self.beam_thickness, True) for m in self.solidMeshes ] self.solidBoundaryMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.solidBoundaryMeshes) self.solidBoundaryMetricsCalculator.init()
def __init__(self, beamMesh, backgroundMesh, beamThickness, initialGap): ## Read in 2d Solid Mesh self.beam_thickness = beamThickness self.Gap = initialGap beamReader = FluentCase(beamMesh) beamReader.read() print "read solid mesh" self.solidMeshes = beamReader.getMeshList() self.geomFields = models.GeomFields('geom') self.solidMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.solidMeshes) self.solidMetricsCalculator.init() ## Define plate and deformation model self.plateFields = models.PlateFields('plate') self.pmodel = models.PlateModelA(self.geomFields, self.plateFields, self.solidMeshes) self.dmodel = models.PlateDeformationModelA(self.geomFields, self.plateFields, self.solidMeshes) bcMap = self.pmodel.getBCMap() ## Apply a default Boundary Condition #for i, bc in bcMap.iteritems(): #bc.bcType = 'SpecifiedTraction' ## Read in 3d Background Mesh fluidReader = FluentCase(backgroundMesh) fluidReader.read() self.fluidMeshes = fluidReader.getMeshList() self.fluidMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.fluidMeshes) self.fluidMetricsCalculator.init() ## Define electric model self.elecFields = models.ElectricFields('elec') self.emodel = models.ElectricModelA(self.geomFields, self.elecFields, self.fluidMeshes) bcMap = self.emodel.getBCMap() ## Apply Default boundary conditions for i, bc in bcMap.iteritems(): bc.bcType = "Symmetry" self.solidBoundaryMeshes = [ m.extrude(1, beamThickness, True) for m in self.solidMeshes ] self.solidBoundaryMetricsCalculator = models.MeshMetricsCalculatorA( self.geomFields, self.solidBoundaryMeshes) self.solidBoundaryMetricsCalculator.init()
part_mesh_fluid.isDebug(0) part_mesh_fluid.partition() part_mesh_fluid.mesh() fluidMeshes = part_mesh_fluid.meshList() if not MPI.COMM_WORLD.Get_rank(): print "partition is done for Fluid Mesh" if options.time: solver_start = zeros(1, dtype='d') solver_end = zeros(1, dtype='d') solver_time = zeros(1, dtype='d') solver_maxtime = zeros(1, dtype='d') solver_mintime = zeros(1, dtype='d') solver_start[0] = MPI.Wtime() geomFields = models.GeomFields('geom') fluidMetricsCalculator = models.MeshMetricsCalculatorA(geomFields, fluidMeshes) fluidMetricsCalculator.init() solidBoundaryMeshes = [m.extractBoundaryMesh() for m in solidMeshes] solidBoundaryMetricsCalculator = models.MeshMetricsCalculatorA( geomFields, solidBoundaryMeshes) solidBoundaryMetricsCalculator.init() flowFields = models.FlowFields('flow') fmodel = models.FlowModelA(geomFields, flowFields, fluidMeshes) fluidWalls = [3, 4] fluidInlet = [5] fluidOutlet = [6]
def RunSim(xmax,ymax,zmax,imax,jmax,kmax,old_values,laser_file): #pdb.set_trace() mesh = generateBoxMesh(xmax, ymax, zmax, imax, jmax, kmax) meshes = (mesh,) geomFields = models.GeomFields('geom') metricsCalculator = models.MeshMetricsCalculatorA(geomFields,meshes) metricsCalculator.init() thermalFields = models.ThermalFields('temperature') tmodel = models.ThermalModelA(geomFields,thermalFields,meshes) bcmap = tmodel.getBCMap() vcmap = tmodel.getVCMap() global time global numTimeSteps global curr_cycle global v_laser global laser_pos global laser_pos_next global int_time vcZone = vcmap[mesh.getID()] # Set boundary conditions and material properties vcZone['thermalConductivity'] = thermalConductivity vcZone['density'] = density # vcZone['specificHeat'] = 1546 xmin_id = 1 xmax_id = 2 ymin_id = 3 ymax_id = 4 zmin_id = 5 zmax_id = 6 bc_xmin = bcmap[xmin_id] bc_xmax = bcmap[xmax_id] bc_ymin = bcmap[ymin_id] bc_ymax = bcmap[ymax_id] bc_zmin = bcmap[zmin_id] bc_zmax = bcmap[zmax_id] bc_zmax.bcType = 'Mixed' bc_zmax.setVar('farFieldTemperature',initTemp) bc_zmax.setVar('surfaceEmissivity',-1.0) bc_zmax.setVar('convectiveCoefficient',-30) bc_zmin.bcType = 'Convective' bc_zmin.setVar('farFieldTemperature',initTemp) bc_zmin.setVar('convectiveCoefficient',-1332) # bc_zmin.setVar('specifiedHeatFlux',0) bc_ymin.bcType = 'SpecifiedTemperature' bc_ymin.setVar('specifiedTemperature',298.0) bc_ymax.bcType = 'SpecifiedTemperature' bc_ymax.setVar('specifiedTemperature',298.0) bc_xmin.bcType = 'SpecifiedTemperature' bc_xmin.setVar('specifiedTemperature',298.0) bc_xmax.bcType = 'SpecifiedTemperature' bc_xmax.setVar('specifiedTemperature',298.0) # Set solver options toptions = tmodel.getOptions() toptions.transient = True toptions.enthalpyModel = True toptions.polynomialCp = True toptions['latentHeat'] = latentHeat toptions['solidTemp'] = solidTemp toptions['liquidTemp'] = liquidTemp toptions.cpFile = specificHeatFile toptions.setVar('initialTemperature', initTemp) pc = fvmbaseExt.AMG() pc.verbosity = 0 defSolver = fvmbaseExt.BCGStab() defSolver.preconditioner = pc defSolver.relativeTolerance = 1.e-10 defSolver.absoluteTolerance = 1.e-10 defSolver.nMaxIteractions = 1000 defSolver.verbosity = 0 toptions.linearSolver = defSolver tmodel.init() cells = mesh.getCells() ncells = cells.getSelfCount() old_ncells, old_temp, old_tempN1, old_enth, old_enthN1, old_enthInv, old_dHdT, old_meltFrac = old_values temp = thermalFields.temperature tempN1 = thermalFields.temperatureN1 enth = thermalFields.enthalpy enthN1 = thermalFields.enthalpyN1 enthInv = thermalFields.enthalpyInverse dHdT = thermalFields.dHdT meltFrac = thermalFields.meltFrac temp = temp[cells].asNumPyArray() tempN1 = tempN1[cells].asNumPyArray() enth = enth[cells].asNumPyArray() enthN1 = enthN1[cells].asNumPyArray() enthInv = enthInv[cells].asNumPyArray() dHdT = dHdT[cells].asNumPyArray() meltFrac = meltFrac[cells].asNumPyArray() ##recover data from previous mesh if it exists if(old_ncells != 0): for c in range(old_ncells): temp[c] = old_temp[c] tempN1[c] = old_tempN1[c] enth[c] = old_enth[c] enthN1[c] = old_enthN1[c] enthInv[c] = old_enthInv[c] dHdT[c] = old_dHdT[c] meltFrac[c] = old_meltFrac[c] nodes=mesh.getCellNodes() NodeCoord=mesh.getNodeCoordinates().asNumPyArray() CellCoord=geomFields.coordinate[cells].asNumPyArray() laser_width = 3*laser_diam/4/2.146 laser_path = open(laser_file,'r') if (curr_cycle == -1): curr_cycle = 1 line = laser_path.readline() words = line.split() if(time != float(words[0])): raise NameError('Time does not match start time in laser_file') laser_pos.x = float(words[1]) laser_pos.y = float(words[2]) laser_power = float(words[3]) line = laser_path.readline() words = line.split() int_time = float(words[0])-time v_laser = [(float(words[1])-laser_pos.x)/int_time,(float(words[2])-laser_pos.y)/int_time] laser_power_next = float(words[3]) else: line = laser_path.readline() words = line.split() laser_power = float(words[3]) if (float(words[0]) > time): raise NameError('Current time not within laser_file for restart') else: while(True): line = laser_path.readline() words = line.split() if (float(words[0]) > time): int_time = float(words[0])-time v_laser = [(float(words[1])-laser_pos.x)/int_time,(float(words[2])-laser_pos.y)/int_time] laser_power_next = float(words[3]) break else: laser_power = float(words[3]) f = open('laser_position','a') f.write(str(time) + ' ' + str(numTimeSteps) + ' ' + str(laser_pos.x) + ' ' + str(laser_pos.y) + '\n') MeltFracField = thermalFields.meltFrac meltFracArray = MeltFracField[cells].asNumPyArray() for c in range(ncells): lim = getNodeCoords(c,CellCoord,NodeCoord,nodes) if(lim[0] >= 0.01) and (lim[1] <= 0.09) and (lim[2] >= 0.01) and (lim[3] <= 0.09) and (lim[5] <= 0.0001): meltFracArray[c] = 1.0 else: meltFracArray[c] = 0.0 while(True): #find the timestep. if (int_time <= maxTimeStep): timeStep = int_time else: timeStep = maxTimeStep laser_pos_next.x = laser_pos.x+v_laser[0]*timeStep laser_pos_next.y = laser_pos.y+v_laser[1]*timeStep int_time = int_time - timeStep toptions.setVar('timeStep',timeStep) print "Current Time: " + str(time) print "Time Step: " + str(timeStep) laser_rect = getLaserRect(laser_pos,laser_pos_next,v_laser,laser_width) SourceField = thermalFields.source sourceArray = SourceField[cells].asNumPyArray() CondField = thermalFields.conductivity condArray = CondField[cells].asNumPyArray() TempField = thermalFields.temperature tempArray = TempField[cells].asNumPyArray() MeltFracField = thermalFields.meltFrac meltFracArray = MeltFracField[cells].asNumPyArray() for c in range(ncells): #set source term lim = getNodeCoords(c,CellCoord,NodeCoord,nodes) if ((lim[5]-zlen) < -1/beta*math.log(0.01*beta/(1-R))): source = 0 elif (cellLaserOverlap(lim,laser_pos,laser_pos_next,laser_width, laser_rect)): ts = getTimes(lim,laser_pos,laser_width,v_laser,timeStep) if (len(ts) == 2): source = GaussLegendreQuadrature(laserSource,xs,Ws,ts[0],ts[1],lim,laser_pos,laser_power,v_laser)/timeStep elif (len(ts) == 0): source = 0.0 else: raise NameError('Bad number of solutions to laser overlap cell ' + str(c)) else: source = 0 sourceArray[c] = source ##Set conductivity based on previous temperature solidCond = condFunction(tempArray[c]) condArray[c] = condMeltFunction(solidCond,meltFracArray[c]) tmodel.advance(maxIterPerTimeStep) ##Picard iterate out any temperature dependent conductivity picardIters = 1 urf = 0.9 while(picardIters < 200): for c in range(ncells): solidCond = condFunction(tempArray[c]) if((meltFracArray[c] >= 1.0) or (tempArray[c] >= liquidTemp)): condArray[c] = (1.0-urf)*condArray[c] + urf*solidCond else: condArray[c] = (1.0-urf)*condArray[c] + urf*condMeltFunction(solidCond, max(meltFracArray[c],(tempArray[c]-solidTemp)/ (liquidTemp-solidTemp))) picardIters = picardIters + 1 prev_temp = np.copy(tempArray) tmodel.advance(maxIterPerTimeStep) err_norm = np.linalg.norm(prev_temp-tempArray)/np.linalg.norm(tempArray) print err_norm if (err_norm < 1e-4*urf): break if (picardIters == 20): print 'Picard Iterations did not converge after 20 iterations. Decreasing urf to 0.8' urf = 0.8 if (picardIters == 60): print 'Picard Iterations did not converge after 60 iterations. Decreasing urf to 0.7' urf = 0.7 if (picardIters == 120): print 'Picard Iterations did not converge after 120 iterations. Decreasing urf to 0.6' urf = 0.6 else: raise NameError('Picard iterations did not converge after 200 iterations') ##Update time tmodel.updateTime() time = time + timeStep # Update laser position laser_pos.x = laser_pos_next.x laser_pos.y = laser_pos_next.y f.write(str(time) + ' ' + str(numTimeSteps) + ' ' + str(laser_pos.x) + ' ' + str(laser_pos.y) + '\n') # Output data for current timestep if((numTimeSteps % outFreq) == 0): filename = outfilebase + '_' + str(numTimeSteps) + '.vtk' writer = exporters.VTKWriterA(geomFields,meshes,filename, "TestTemperature",False,0) writer.init() writer.writeScalarField(thermalFields.temperature, "Temperature") writer.writeScalarField(thermalFields.meltFrac, "MeltFraction") #writer.writeScalarField(thermalFields.conductivity, "Conductivity") writer.finish() write_restart_file((ncells, temp, tempN1, enth, enthN1, enthInv, dHdT, meltFrac)) numTimeSteps = numTimeSteps + 1 if(int_time == 0.0): laser_power = laser_power_next line = laser_path.readline() if (line == ''): break else: words = line.split() if (len(words) == 0): break else: int_time = float(words[0])-time v_laser = [(float(words[1])-laser_pos.x)/int_time,(float(words[2])-laser_pos.y)/int_time] laser_power_next = float(words[3]) f.close() return_temp = np.copy(temp) return_tempN1 = np.copy(tempN1) return_enth = np.copy(enth) return_enthN1 = np.copy(enthN1) return_enthInv = np.copy(enthInv) return_dHdT = np.copy(dHdT) return_meltFrac = np.copy(meltFrac) return (ncells, return_temp, return_tempN1, return_enth, return_enthN1, return_enthInv, return_dHdT, return_meltFrac)