def initializeModels(self): print "--Solving Models--" self.maxdeformation = [] self.numIterations = 20 self.globalTime = 0 self.globalCount = 0 self.timeStep = 3600 self.saveFrequency = 2 self.saveVTKstate = True initialTransient = False self.probeIndex = 3240 pc = fvmbaseExt.AMG() pc.verbosity = 0 defSolver = fvmbaseExt.DirectSolver() defSolver.preconditioner = pc defSolver.relativeTolerance = 1e-6 defSolver.absoluteTolerance = 1.e-15 defSolver.nMaxIterations = 50000 defSolver.verbosity = 1 poptions = self.pmodel.getOptions() poptions.deformationLinearSolver = defSolver poptions.deformationTolerance = 1.0e-6 poptions.setVar("deformationURF", 1.0) poptions.printNormalizedResiduals = True poptions.timeDiscretizationOrder = 2 poptions.transient = True poptions.scf = 5. / 6. poptions.setVar('timeStep', self.timeStep) poptions.setVar('residualStressXX', self.residualStress[0]) poptions.setVar('residualStressYY', self.residualStress[1]) poptions.setVar('residualStressZZ', self.residualStress[2]) ### elec solver ### epc = fvmbaseExt.AMG() epc.verbosity = 0 elecSolver = fvmbaseExt.BCGStab() elecSolver.preconditioner = epc elecSolver.relativeTolerance = 1e-6 elecSolver.nMaxIterations = 1000 elecSolver.maxCoarseLevels = 30 elecSolver.verbosity = 0 eoptions = self.emodel.getOptions() eoptions.electrostaticsLinearSolver = elecSolver eoptions.electrostaticsTolerance = 0.5e-5 eoptions.electrostatics_enable = 1 eoptions.chargetransport_enable = 0 eoptions.tunneling = 0 eoptions.ibm_enable = 1 eoptions.transient_enable = False eoptions.printNormalizedResiduals = True ### initialize models and run ### self.pmodel.init() self.emodel.init() self.dmodel.init()
def solvers(self, timeStep=1e-8): if self.enablePlateModel == True: pc = fvmbaseExt.AMG() pc.verbosity = 0 defSolver = fvmbaseExt.DirectSolver() defSolver.preconditioner = pc defSolver.relativeTolerance = 1e-10 defSolver.absoluteTolerance = 1.e-20 defSolver.nMaxIterations = 50000 defSolver.verbosity = 0 poptions = self.pmodel.getOptions() poptions.deformationLinearSolver = defSolver poptions.deformationTolerance = 1.0e-3 poptions.setVar("deformationURF", 1.0) poptions.printNormalizedResiduals = True poptions.timeDiscretizationOrder = 1 poptions.transient = False poptions.scf = 5. / 6. poptions.setVar('timeStep', timeStep) poptions.variableTimeStep = True poptions.residualStress = False poptions.creep = False if self.enableElecModel == True: epc = fvmbaseExt.AMG() epc.verbosity = 0 elecSolver = fvmbaseExt.BCGStab() elecSolver.preconditioner = epc elecSolver.relativeTolerance = 1e-4 elecSolver.absoluteTolerance = 1e-20 elecSolver.nMaxIterations = 1000 elecSolver.maxCoarseLevels = 20 elecSolver.verbosity = 0 eoptions = self.emodel.getOptions() eoptions.electrostaticsLinearSolver = elecSolver eoptions.electrostaticsTolerance = 1e-3 eoptions.electrostatics_enable = 1 eoptions.chargetransport_enable = 0 eoptions.tunneling = 0 eoptions.ibm_enable = 1 eoptions.transient_enable = False eoptions.printNormalizedResiduals = True if self.enableFlowModel == True: foptions = self.fmodel.getOptions() foptions.momentumTolerance = 1e-3 foptions.continuityTolerance = 1e-3 foptions.setVar("momentumURF", 0.7) foptions.setVar("pressureURF", 0.3) foptions.transient = False foptions.setVar("timeStep", timeStep) foptions.printNormalizedResiduals = True print 'solvers are established'
bc['specifiedXVelocity'] = 1 bc['specifiedYVelocity'] = 0 bc['specifiedZVelocity'] = 0 for id in fluidOutlet: if id in bcMap: bc = bcMap[id] bc.bcType = 'PressureBoundary' vcMap = fmodel.getVCMap() for i, vc in vcMap.iteritems(): vc['viscosity'] = 1 vc['density'] = 1 #fluidReader.importFlowBCs(fmodel,fluidMeshes) #flow solvers momPC = fvmbaseExt.AMG() momPC.maxCoarseLevels = 0 momPC.verbosity = 0 momSolver = fvmbaseExt.AMG() momSolver.smootherType = fvmbaseExt.AMG.JACOBI #momSolver.preconditioner = momPC momSolver.relativeTolerance = 1e-1 momSolver.absoluteTolerance = 1e-50 momSolver.nMaxIterations = 100 momSolver.maxCoarseLevels = 0 momSolver.verbosity = 0 contPC = fvmbaseExt.AMG() contPC.maxCoarseLevels = 0 contPC.verbosity = 0 contSolver = fvmbaseExt.AMG()
bc.bcType = "Symmetry" vcMap = emodel.getVCMap() for i, vc in vcMap.iteritems(): vc.vcType = "dielectric" vc['dielectric_constant'] = dielectric_constant ### flow model and boundary condition ### flowFields = models.FlowFields('flow') fmodel = models.FlowModelA(geomFields, flowFields, fluidMeshes) fluidReader.importFlowBCs(fmodel, fluidMeshes) ### ================================= solvers ===================================### ### elec solver ### epc = fvmbaseExt.AMG() epc.verbosity = 0 elecSolver = fvmbaseExt.BCGStab() elecSolver.preconditioner = epc elecSolver.relativeTolerance = 1e-3 elecSolver.nMaxIterations = 1000 elecSolver.maxCoarseLevels = 20 elecSolver.verbosity = 0 eoptions = emodel.getOptions() eoptions.electrostaticsLinearSolver = elecSolver eoptions.electrostaticsTolerance = 0.5e-5 eoptions.electrostatics_enable = 1 eoptions.chargetransport_enable = 0 eoptions.tunneling = 0 eoptions.ibm_enable = 1
bcLeft.setVar('specifiedMassFraction', 0.0) bcRight.setVar('specifiedMassFraction', 1.0) # Neumann on Bottom,Top bcBottom1.bcType = 'SpecifiedMassFlux' bcBottom1.setVar('specifiedMassFlux', 0.0) bcTop1.bcType = 'SpecifiedMassFlux' bcTop1.setVar('specifiedMassFlux', 0.0) bcBottom2.bcType = 'SpecifiedMassFlux' bcBottom2.setVar('specifiedMassFlux', 0.0) bcTop2.bcType = 'SpecifiedMassFlux' bcTop2.setVar('specifiedMassFlux', 0.0) soptions = smodel.getOptions() solver = fvmbaseExt.AMG() solver.relativeTolerance = 1e-14 #solver tolerance solver.absoluteTolerance = 1e-16 #solver tolerance solver.nMaxIterations = 100 solver.maxCoarseLevels = 30 solver.verbosity = 0 soptions.linearSolver = solver # model tolerances are only needed for non-linear or unstructured problems #soptions.relativeTolerance=1e-16 #soptions.absoluteTolerance=1e-16 #smodel.printBCs() smodel.init() smodel.advance(1)
bcMapTherm[7].bcType = 'Symmetry' for i in [5, 6, 7, 8, 9, 10]: bc = bcMap[i] bc.bcType = 'Symmetry' bcMapTherm.bcType = 'Symmetry' #bc.bcType = 'NoSlipWall' fmodel.printBCs() tmodel.printBCs() vcmap = tmodel.getVCMap() vcZone = vcmap[meshes[0].getID()] vcZone['thermalConductivity'] = 1.0E-10 vcZone['density'] = 1000.0 vcZone['specificHeat'] = 1.0 momSolver = fvmbaseExt.AMG() momSolver.relativeTolerance = 1e-1 momSolver.nMaxIterations = 20 momSolver.maxCoarseLevels = 20 momSolver.verbosity = 0 contSolver = fvmbaseExt.AMG() #pc = fvmbaseExt.AMG() #pc.verbosity=0 #contSolver = fvmbaseExt.BCGStab() #contSolver.preconditioner = pc contSolver.relativeTolerance = 1e-1 contSolver.nMaxIterations = 20 contSolver.verbosity = 0 contSolver.maxCoarseLevels = 20
bc_xmin.setVar('specifiedTemperature',300.0) bc_xmax.bcType = 'SpecifiedTemperature' bc_xmax.setVar('specifiedTemperature',400.0) # Set solver options toptions = tmodel.getOptions() toptions.transient = False toptions.enthalpyModel = False toptions.polynomialCp = False #toptions['latentHeat'] = latentHeat #toptions['solidTemp'] = solidTemp #toptions['liquidTemp'] = liquidTemp #toptions.cpFile = specificHeatFile toptions.setVar('initialTemperature', 298.0) 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() tmodel.advance(100) writer = exporters.VTKWriterA(geomFields,meshes,"adaptive_test.vtk", "TestTemperature",False,0) writer.init() writer.writeScalarField(thermalFields.temperature, "Temperature")
def solveModels(self, appliedVoltage): print "--Solving Models--" maxdeformation = [] numIterations = 200 globalTime = 0 globalCount = 0 timeStep = 2e-7 saveFrequency = 2 initialTransient = False probeIndex = 3240 pc = fvmbaseExt.AMG() pc.verbosity = 0 defSolver = fvmbaseExt.BCGStab() defSolver.preconditioner = pc defSolver.relativeTolerance = 1e-6 defSolver.absoluteTolerance = 1.e-15 defSolver.nMaxIterations = 50000 defSolver.verbosity = 1 poptions = self.pmodel.getOptions() poptions.deformationLinearSolver = defSolver poptions.deformationTolerance = 1.0e-3 poptions.setVar("deformationURF", 1.0) poptions.printNormalizedResiduals = True poptions.timeDiscretizationOrder = 2 poptions.transient = False poptions.scf = 5. / 6. poptions.setVar('timeStep', timeStep) ### elec solver ### epc = fvmbaseExt.AMG() epc.verbosity = 0 elecSolver = fvmbaseExt.BCGStab() elecSolver.preconditioner = epc elecSolver.relativeTolerance = 1e-3 elecSolver.nMaxIterations = 1000 elecSolver.maxCoarseLevels = 20 elecSolver.verbosity = 0 eoptions = self.emodel.getOptions() eoptions.electrostaticsLinearSolver = elecSolver eoptions.electrostaticsTolerance = 0.5e-5 eoptions.electrostatics_enable = 1 eoptions.chargetransport_enable = 0 eoptions.tunneling = 0 eoptions.ibm_enable = 1 eoptions.transient_enable = False eoptions.printNormalizedResiduals = True ### initialize models and run ### self.pmodel.init() self.emodel.init() self.dmodel.init() ibManager = fvmbaseExt.IBManager(self.geomFields, self.solidBoundaryMeshes[0], self.fluidMeshes) for Voltage in appliedVoltage: for mesh in self.solidBoundaryMeshes: faces = mesh.getFaces() areaMag = self.geomFields.areaMag[faces] faceCount = faces.getCount() pot = areaMag.newSizedClone(faceCount) pota = pot.asNumPyArray() pota[:] = appliedVoltage self.elecFields.potential[faces] = pot sbMeshFaces = self.solidBoundaryMeshes[0].getFaces() ibManager.fluidNeighborsPerIBFace = 4 ibManager.solidNeighborsPerIBFace = 4 ibManager.fluidNeighborsPerSolidFace = 6 t1 = time.time() #--------------Timestep Loop --------------------------# for n in range(0, numIterations): # checkMarking(globalCount) # --------------- update IBM -------------------------# print "*** update IBM at globalCount %i ***" % globalCount ibManager.update() self.fluidMetricsCalculator.computeIBInterpolationMatrices( sbMeshFaces) self.fluidMetricsCalculator.computeSolidInterpolationMatrices( sbMeshFaces) #------------solve electrostatics--------# print "*** solving electric model at globalCount %i ***" % globalCount for i in range(0, 20): self.emodel.computeIBFacePotential(sbMeshFaces) self.emodel.advance(1) self.emodel.computeSolidSurfaceForcePerUnitArea( sbMeshFaces) #saveVTK(n) #------------update force on beam ----------# print "*** update force at globalCount %i ***" % globalCount sbElecForce = self.elecFields.force[sbMeshFaces].asNumPyArray() solidMesh = self.solidMeshes[0] solidCells = solidMesh.getCells() nCells = solidCells.getCount() nSelfCells = solidCells.getSelfCount() nSBFaces = sbMeshFaces.getCount() if (nSBFaces != 2 * nSelfCells + (nCells - nSelfCells)): print "the extruded solid boundary mesh has wrong face numbers!" force = self.plateFields.force[solidCells].asNumPyArray() thickness = self.plateFields.thickness[ solidCells].asNumPyArray() force[:] = 0. ### Need to correct~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ thickness[:] = self.beam_thickness # force on interior cells for c in range(0, nSelfCells): botFaceIndex = c topFaceIndex = c + nSelfCells force[c] = sbElecForce[botFaceIndex][2] + sbElecForce[ topFaceIndex][2] # force on boundary cells for c in range(nSelfCells, nCells): force[c] = sbElecForce[nSelfCells + c][2] #pdb.set_trace() #------------solve structure-------------# print "*** solving structure model at globalCount %i ***" % globalCount self.pmodel.advance(1) self.dmodel.calculateNodeDisplacement() self.dmodel.deformPlate() self.solidMetricsCalculator.recalculate_deform() #------------update solid boundary mesh---------------# #solidBoundaryMeshes = [m.extrude(1, beam_thickness, True) for m in solidMeshes] sbNodes = self.solidBoundaryMeshes[0].getNodes() nSBNodes = sbNodes.getCount() nodes = self.solidMeshes[0].getNodes() if nSBNodes != nodes.getCount() * 2: print "the extruded solid mesh has wrong node number!" nodeCoord = self.geomFields.coordinate[nodes].asNumPyArray() bNodeCoord = self.geomFields.coordinate[sbNodes].asNumPyArray() bMeshCoord = self.solidBoundaryMeshes[0].getNodeCoordinates( ).asNumPyArray() self.deformation = self.geomFields.nodeDisplacement[ nodes].asNumPyArray() #pdb.set_trace() for sbn in range(0, nSBNodes / 2): bNodeCoord[sbn][ 2] = -self.beam_thickness / 2 + nodeCoord[sbn][2] bMeshCoord[sbn][ 2] = -self.beam_thickness / 2 + nodeCoord[sbn][2] for sbn in range(nSBNodes / 2, nSBNodes): bNodeCoord[sbn][2] = self.beam_thickness / 2 + nodeCoord[ sbn - nSBNodes / 2][2] bMeshCoord[sbn][2] = self.beam_thickness / 2 + nodeCoord[ sbn - nSBNodes / 2][2] #pdb.set_trace() #solidBoundaryMetricsCalculator = models.MeshMetricsCalculatorA(geomFields,solidBoundaryMeshes) #solidBoundaryMetricsCalculator.init() self.solidBoundaryMetricsCalculator.recalculate_deform() cell = self.solidMeshes[0].getCells() deform = self.plateFields.deformation[cell].asNumPyArray() def_min = deform.min(axis=0) def_min_z = def_min[2] maxdeformation.append(def_min_z) if (n != 0): if ((maxdeformation[n] - maxdeformation[n - 1]) / maxdeformation[n] < 1e-3): print "Convergence reached" break # -----------------update time --------------------------# globalTime += timeStep globalCount += 1 #self.pmodel.updateTime() #saveVTK(n) #writeTrace( if (n % saveFrequency == 0): writer = exporters.VTKWriterA( self.geomFields, self.fluidMeshes, "elecfield-" + str(n) + ".vtk", "fix-fix beam", False, 0) writer.init() writer.writeScalarField(self.elecFields.potential, "potential") writer.writeVectorField(self.elecFields.electric_field, "potentialgradient") writer.finish() writer1 = exporters.VTKWriterA( self.geomFields, self.solidMeshes, "structural-" + str(n) + ".vtk", "Disk", False, 0) writer1.init() writer1.writeVectorField(self.plateFields.deformation, "Deformation") writer1.finish() t2 = time.time() print '\nsolution time = %f' % (t2 - t1) return maxdeformation[n]
if bcID in bcElecMap: bc = emodel.getBCMap()[bcID] # bc.bcType = 'SpecifiedPotential' # bc.setVar('specifiedPotential',350) bc.bcType = 'SpecifiedPotentialFlux' bc.setVar('specifiedPotentialFlux', 0) #bc.bcType = 'SpecifiedCharge' #bc.setVar('specifiedCharge',350) vcMap = smodel.getVCMap() for i, vc in vcMap.iteritems(): vc['density'] = rho vc['eta'] = E / (2. * (1 + nu)) vc['eta1'] = nu * E / ((1 + nu) * (1 - 1.0 * nu)) pc = fvmbaseExt.AMG() pc.verbosity = 0 defSolver = fvmbaseExt.DirectSolver() defSolver.preconditioner = pc defSolver.relativeTolerance = 1e-5 defSolver.absoluteTolerance = 1.e-30 defSolver.nMaxIterations = 60 defSolver.verbosity = 1 elecSolver = fvmbaseExt.AMG() elecSolver.relativeTolerance = 1e-3 elecSolver.nMaxIterations = 100 elecSolver.maxCoarseLevels = 20 elecSolver.verbosity = 1 soptions = smodel.getOptions()
bc6.setVar('specifiedTemperature', 0) # set viscosity and density, this is done per mesh since each mesh has its own VC object vcMap = tmodel.getVCMap() for vc in vcMap.values(): # vc.setVar('density',1.0) vc.setVar('thermalConductivity', 1.0) ######################### conn = meshes[0].getCellCells() semi_bandwidth = 6 #spike_storage = fvmbaseExt.SpikeStorage(conn, semi_bandwidth) #pc = fvmbaseExt.SpikeSolver(spike_storage) #pc = fvmbaseExt.JacobiSolver() #pc = fvmbaseExt.ILU0Solver() pc = fvmbaseExt.AMG() #pc.setMergeLEvelSize(40000) #pc.verbosity=3 tSolver = fvmbaseExt.BCGStab() #tSolver = fvmbaseExt.JacobiSolver() tSolver.preconditioner = pc tSolver.relativeTolerance = 1e-4 tSolver.nMaxIterations = 200000 tSolver.verbosity = 3 ##################### tSolver = fvmbaseExt.AMG() #tSolver.smootherType = fvmbaseExt.AMG.JACOBI tSolver.relativeTolerance = 1e-9 tSolver.nMaxIterations = 200000
bc3.bcType = 'NoSlipWall' bc3.setVar('specifiedXVelocity', 1) ## set viscosity and density, this is done per mesh since each mesh has its own VC object vcMap = fmodel.getVCMap() for vc in vcMap.values(): vc.setVar('density', 1.0) vc.setVar('viscosity', 0.1) ######################### conn = meshes[0].getCellCells() semi_bandwidth_mom = 3 #spike_storage_mom = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_mom) #pcMom = fvmbaseExt.SpikeSolver(spike_storage_mom) #pcMom = fvmbaseExt.JacobiSolver() #pcMom = fvmbaseExt.ILU0Solver() pcMom = fvmbaseExt.AMG() pcMom.verbosity = 0 momSolver = fvmbaseExt.AMG() #momSolver.preconditioner=pcMom momSolver.relativeTolerance = 1e-1 momSolver.nMaxIterations = 20 momSolver.maxCoarseLevels = 30 momSolver.verbosity = 0 if MPI.COMM_WORLD.Get_rank() == 0: momSolver.verbosity = 0 ######################### semi_bandwidth_con = 3 #spike_storage_con = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_con) #pcCon = fvmbaseExt.SpikeSolver(spike_storage_con)
bc3.bcType = 'NoSlipWall' bc3.setVar('specifiedXVelocity', 1) ## set viscosity and density, this is done per mesh since each mesh has its own VC object vcMap = fmodel.getVCMap() for vc in vcMap.values(): vc.setVar('density', 1.0) vc.setVar('viscosity', 0.1) ######################### conn = meshes[0].getCellCells() semi_bandwidth_mom = 10 spike_storage_mom = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_mom) pcMom = fvmbaseExt.SpikeSolver(spike_storage_mom) #pcMom = fvmbaseExt.JacobiSolver() #pcMom = fvmbaseExt.ILU0Solver() pcMomWriter = fvmbaseExt.AMG() pcMom.verbosity = 0 momSolver = fvmbaseExt.BCGStab() momSolver.preconditioner = pcMom momSolver.relativeTolerance = 1e-1 momSolver.nMaxIterations = 20 momSolver.maxCoarseLevels = 30 momSolver.verbosity = 0 if MPI.COMM_WORLD.Get_rank() == 0: momSolver.verbosity = 0 ######################### semi_bandwidth_con = 10 spike_storage_con = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_con) pcCon = fvmbaseExt.SpikeSolver(spike_storage_con)
bc3 = fmodel.getBCMap()[3] bc3.bcType = 'NoSlipWall' bc3.setVar('specifiedXVelocity', 1) ## set viscosity and density, this is done per mesh since each mesh has its own VC object vcMap = fmodel.getVCMap() for vc in vcMap.values(): vc.setVar('density', 1.0) vc.setVar('viscosity', 0.1) ######################### conn = meshes[0].getCellCells() semi_bandwidth_mom = 3 #spike_storage_mom = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_mom) #pcMom = fvmbaseExt.SpikeSolver(spike_storage_mom) #pcMom = fvmbaseExt.JacobiSolver() pcMom = fvmbaseExt.AMG() pcMom.verbosity = 0 momSolver = fvmbaseExt.CG() momSolver.preconditioner = pcMom momSolver.relativeTolerance = 1e-1 momSolver.nMaxIterations = 20 momSolver.maxCoarseLevels = 30 momSolver.verbosity = 0 if MPI.COMM_WORLD.Get_rank() == 0: momSolver.verbosity = 0 ######################### semi_bandwidth_con = 3 #spike_storage_con = fvmbaseExt.SpikeStorage(conn, semi_bandwidth_con) #pcCon = fvmbaseExt.SpikeSolver(spike_storage_con)
elec_constants['electron_capture_cross'] = electron_capture_cross elec_constants['electron_mobility'] = electron_mobility elec_constants['electron_saturation_velocity'] = electron_saturation_velocity elec_constants['substrate_id'] = botID elec_constants['membrane_id'] = topID elec_constants['nLevel'] = nLevel elec_constants['normal_direction'] = normal_direction elec_constants['nTrap'] = nTrap elec_constants.electron_trapdepth.push_back(electron_trapdepth) elec_constants.electron_trapdensity.push_back(electron_trapdensity) elec_constants.electron_trapdepth.push_back(1.5) elec_constants.electron_trapdensity.push_back(electron_trapdensity) ### setup linear solve options ### pPC = fvmbaseExt.AMG() pPC.verbosity = 0 pSolver = fvmbaseExt.BCGStab() pSolver.preconditioner = pPC pSolver.relativeTolerance = 1e-20 pSolver.nMaxIterations = 100 pSolver.maxCoarseLevels = 20 pSolver.absoluteTolerance = 1e-50 pSolver.verbosity = 0 elec_options.electrostaticsLinearSolver = pSolver cPC = fvmbaseExt.AMG() cPC.verbosity = 0 cSolver = fvmbaseExt.BCGStab() cSolver.preconditioner = cPC cSolver.relativeTolerance = 1e-20
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)