def genericSetup(self): # Generic parameters for 1-D tests. nx1 = 100 nx2 = 200 nx3 = 50 xRange1 = (0.0, 1.0) xRange2 = (0.0, 1.0) xRange3 = (0.5, 1.0) simulationVolume = (0.0, 1.0) neighborSearchType = GatherScatter numGridLevels = 20 topGridCellSize = 0.25 origin = Vector1d(0.0) # Interpolation kernel. self.WT = TableKernel1d(BSplineKernel1d(), 100) self.kernelExtent = self.WT.kernelExtent # Construct the NodeLists to be distributed self.eos = GammaLawGasMKS1d(2.0, 2.0) self.nodes1 = makeFluidNodeList1d("nodes1", self.eos, NeighborType=TreeNeighbor1d) self.nodes2 = makeFluidNodeList1d("nodes2", self.eos, NeighborType=TreeNeighbor1d) self.nodes3 = makeFluidNodeList1d("nodes3", self.eos, NeighborType=TreeNeighbor1d) # Distribute the nodes. distributeNodesInRange1d([(self.nodes1, nx1, 1.0, xRange1), (self.nodes2, nx2, 1.0, xRange2), (self.nodes3, nx3, 1.0, xRange3)]) # Assign global IDs. self.globalIDField1, self.globalIDField2, self.globalIDField3 = generateGlobalIDs( (self.nodes1, self.nodes2, self.nodes3), globalNodeIDs1d, numGlobalNodes1d) # Put the distributed NodeLists into a DataBase. self.dataBase = DataBase1d() self.dataBase.appendNodeList(self.nodes1) self.dataBase.appendNodeList(self.nodes2) self.dataBase.appendNodeList(self.nodes3) print "Finished genericSetup" return
return v2 def specificEnergy(xi, rhoi): if hfold > 0.0: Pi = P1 + (P2 - P1)/(1.0 + exp(-(xi - x1)/hfold)) elif xi <= x1: Pi = P1 else: Pi = P2 return Pi/((gammaGas - 1.0)*rhoi) #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- if numNodeLists == 1: distributeNodesInRange1d([(nodes1, nx1, rho1, (x0, x1)), (nodes1, nx2, rho2, (x1, x2))]) else: distributeNodesInRange1d([(nodes1, nx1, rho1, (x0, x1)), (nodes2, nx2, rho2, (x1, x2))]) output("nodes1.numNodes") output("nodes2.numNodes") # Set node specific thermal energies for nodes in nodeSet: pos = nodes.positions() eps = nodes.specificThermalEnergy() rho = nodes.massDensity() vel = nodes.velocity() for i in xrange(nodes.numInternalNodes): eps[i] = specificEnergy(pos[i].x, rho[i]) vel[i].x = vel_initial(pos[i].x)
nPerh=nPerh) output("nodes.name") output("nodes.hmin") output("nodes.hmax") output("nodes.hminratio") output("nodes.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- # Add some points above and below the problem to represent the infinite atmosphere. nxbound = 20 dx = (x1 - x0) / nx1 from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, nx1 + 2 * nxbound, rhoT, (x0 - nxbound * dx, x1 + nxbound * dx))], nPerh=nPerh) #Set IC eps = nodes.specificThermalEnergy() pos = nodes.positions() rho = nodes.massDensity() mass = nodes.mass() rhoFunc = ExponentialDensity(rhoB, rhoT, delta) for i in xrange(nodes.numInternalNodes): xi = pos[i].x P0 = rhoT / gamma rho[i] = rhoFunc(xi) mass[i] = dx * rho[i] Pi = P0 + gval * rho[i] * (xi - 0.5) eps0 = Pi / ((gamma - 1.0) * rho[i])
nodesTa = makeSolidNodeList("Tantalum", eosTa, strengthModelTa, nPerh = nPerh, hmin = hmin, hmax = hmax, rhoMin = etamin*rho0Ta, rhoMax = etamax*rho0Ta, xmin = -100.0*Vector.one, xmax = 100.0*Vector.one) nodeSet = [nodesAl, nodesTa] #------------------------------------------------------------------------------- # Set node properties (positions, masses, H's, etc.) #------------------------------------------------------------------------------- print "Generating node distribution." from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodesAl, nxAl, rho0Al, (-1.025, -0.025)), (nodesTa, nxTa, rho0Ta, ( 0.025, 1.025))]) # Set node velocites. vel = nodesAl.velocity() for i in xrange(nodesAl.numInternalNodes): vel[i].x = 0.18 #------------------------------------------------------------------------------- # Construct a DataBase to hold our node list #------------------------------------------------------------------------------- db = DataBase() for n in nodeSet: db.appendNodeList(n) del n output("db") output("db.numNodeLists")
#------------------------------------------------------------------------------- units = CGuS() eos = TillotsonEquationOfState(materialName="aluminum", etamin=0.1, etamax=10.0, units=units) strength = ConstantStrength(materialName="aluminum", units=units) rho0 = eos.referenceDensity #------------------------------------------------------------------------------- # Create the NodeLists. #------------------------------------------------------------------------------- nodes = makeSolidNodeList("nodes", eos, strength) from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, 1000, rho0, (0.0, 1.0))], nPerh=nPerh) #------------------------------------------------------------------------------- # The JC damage model. #------------------------------------------------------------------------------- D1, D2, D3, D4, D5 = 1.0, 2.0, 0.5, 0.25, 0.0 epsilondot0 = 0.1 Tcrit = -2.0 sigmamax = -4.0 efailmin = 0.01 damage = JohnsonCookDamage( nodeList=nodes, D1=D1, D2=D2, D3=D3, D4=D4,
#------------------------------------------------------------------------------- nodes = makeFluidNodeList("nodes", eos, hmin=hmin, hmax=hmax, kernelExtent=kernelExtent, nPerh=nPerh) nodeSet = [nodes] #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- from DistributeNodes import distributeNodesInRange1d rho0 = 1.0 distributeNodesInRange1d([(nodes, [(nx, rho0, (0.0, 1.0))])]) output("nodes.numNodes") # Set the initial conditions. eps1, eps2, eps3 = 1000.0 / 0.4, 0.01 / 0.4, 100.0 / 0.4 hfold = hsmooth * 1.0 / nx def epsfunc(x): if x < 0.1 - hfold: return eps1 elif x < 0.1 + hfold: f = 0.5 * (sin(0.5 * pi * (x - 0.1) / hfold) + 1.0) return (1.0 - f) * eps1 + f * eps2 elif x < 0.9 - hfold: return eps2
def setUp(self): self.ndim = 1 self.xmin = Vector1d(0.0) self.xmax = Vector1d(1.0) self.nsample = vector_of_int() self.nsample.append(100) # Tolerances for the test self.scalarTol = 1.0e-5 self.vectorTol = 1.0e-3 self.tensorTol = 1.0e-4 n = 100 self.rho0 = 10.0 self.v0 = Vector1d(1.0) self.eps0 = -1.0 self.gradv0 = Tensor1d(8.0) x0, x1 = 0.0, 1.0 # Create the nodes and such. self.eos = GammaLawGasMKS1d(5.0 / 3.0, 1.0) self.WT = TableKernel1d(BSplineKernel1d()) self.nodes = makeFluidNodeList1d("nodes", self.eos) self.neighbor = self.nodes.neighbor() # Distribute the nodes. from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(self.nodes, n, self.rho0, (x0, x1))]) # Set the velocities and energies. self.nodes.velocity(VectorField1d("tmp", self.nodes, self.v0)) self.nodes.specificThermalEnergy( ScalarField1d("tmp", self.nodes, self.eps0)) self.db = DataBase1d() self.db.appendNodeList(self.nodes) # Create the boundary conditions. p0 = Plane1d(Vector1d(0.0), Vector1d(1.0)) p1 = Plane1d(Vector1d(1.0), Vector1d(-1.0)) xbc = PeriodicBoundary1d(p0, p1) self.bcs = [xbc] try: dbc = TreeDistributedBoundary1d.instance() self.bcs.append(dbc) except: if mpi.procs > 1: raise RuntimeError, "Unable to get parallel boundary condition" else: pass # Enforce boundaries. db = DataBase1d() db.appendNodeList(self.nodes) for bc in self.bcs: bc.setAllGhostNodes(db) bc.finalizeGhostBoundary() self.neighbor.updateNodes() for bc in self.bcs: bc.applyGhostBoundary(self.nodes.mass()) bc.applyGhostBoundary(self.nodes.massDensity()) bc.applyGhostBoundary(self.nodes.specificThermalEnergy()) bc.applyGhostBoundary(self.nodes.velocity()) for bc in self.bcs: bc.finalizeGhostBoundary() self.H0 = self.nodes.Hfield()[0] return
# Create an instance of our history object to find the interface history. #------------------------------------------------------------------------------- interfaceHistory = InterfaceHistory(None, None, None, None, nodesSapphire1, nodesTantalum, "PlateImpact-interface-history.txt") #------------------------------------------------------------------------------- # Set node properties (positions, masses, H's, etc.) #------------------------------------------------------------------------------- if restoreCycle is None: from DistributeNodes import distributeNodesInRange1d print "Generating node distribution." distributeNodesInRange1d([ (nodesSapphire1, nxSapphire1, rhoSapphire, Sapphire1Range), (nodesTantalum, nxTantalum, rhoTantalum, TantalumRange), (nodesSapphire2, nxSapphire2, rhoSapphire, Sapphire2Range), (nodesTungstenCarbide, nxTungstenCarbide, rhoTungstenCarbide, TungstenCarbideRange), (nodesPMMA, nxPMMA, rhoPMMA, PMMARange) ]) # Explicitly set the mass densities again, 'cause there's some roundoff # issue python->C++ with doing it from the NodeGenerators. This is # necessary to get the initial pressures to be zero to roundoff. for nodes, rho0 in [(nodesSapphire1, rhoSapphire), (nodesTantalum, rhoTantalum), (nodesSapphire2, rhoSapphire), (nodesTungstenCarbide, rhoTungstenCarbide), (nodesPMMA, rhoPMMA)]: nodes.massDensity(ScalarField("tmp", nodes, rho0)) # Set the node velocities.
hmin = hmin, hmax = hmax, nPerh = nPerh, kernelExtent = kernelExtent, rhoMin = rhomin) #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- pos = nodes1.positions() vel = nodes1.velocity() mass = nodes1.mass() eps = nodes1.specificThermalEnergy() H = nodes1.Hfield() from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes1, nRadial, rho0, (0.0, rmax))]) output("mpi.reduce(nodes1.numInternalNodes, mpi.MIN)") output("mpi.reduce(nodes1.numInternalNodes, mpi.MAX)") output("mpi.reduce(nodes1.numInternalNodes, mpi.SUM)") # Set the point source of energy. Esum = 0.0 if smoothSpike or topHatSpike: Wsum = 0.0 for nodeID in xrange(nodes1.numInternalNodes): Hi = H[nodeID] etaij = (Hi*pos[nodeID]).magnitude() if smoothSpike: Wi = WT.kernelValue(etaij/smoothSpikeScale, 1.0) else: if etaij < smoothSpikeScale*kernelExtent:
#------------------------------------------------------------------------------- # Interpolation kernels. #------------------------------------------------------------------------------- WT = TableKernel(BSplineKernel(), 1000) #------------------------------------------------------------------------------- # Make the NodeLists. #------------------------------------------------------------------------------- nodes = makeFluidNodeList("nodes1", eos, hmin=hmin, hmax=hmax, nPerh=nPerh) #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, [(nx, rho0, (x0, x1))])]) output("nodes.numNodes") def setRho(): pos = nodes.positions() rho = nodes.massDensity() for i in xrange(nodes.numInternalNodes): rho[i] = rho0 + rhoSlope * pos[i].x return #------------------------------------------------------------------------------- # Construct a DataBase to hold our node list #------------------------------------------------------------------------------- db = DataBase()
nPerh = nPerh, hmin = hmin, hmax = hmax, rhoMin = etamin*rho0, rhoMax = etamax*rho0, xmin = -100.0*Vector.one, xmax = 100.0*Vector.one) nodeSet = [nodes] #------------------------------------------------------------------------------- # Set node properties (positions, masses, H's, etc.) #------------------------------------------------------------------------------- eps0 = 0.0 print "Generating node distribution." from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, nx, rho0, (xmin, xmax))]) output("mpi.reduce(nodes.numInternalNodes, mpi.MIN)") output("mpi.reduce(nodes.numInternalNodes, mpi.MAX)") output("mpi.reduce(nodes.numInternalNodes, mpi.SUM)") # # Set node specific thermal energies # eps0 = eos.specificThermalEnergy(rho0, 300.0) # nodes.specificThermalEnergy(ScalarField("tmp", nodes, eps0)) # Set node velocites. for i in xrange(nodes.numInternalNodes): nodes.velocity()[i].x = nodes.positions()[i].x/(0.5*length)*v0 # Set an initial damage if requested. if initialBreakRadius > 0.0: pos = nodes.positions()
else: nodes = makeFluidNodeList("nodes", eos, hmin = hmin, hmax = hmax, nPerh = nPerh, kernelExtent = kernelExtent) output("nodes") output("nodes.hmin") output("nodes.hmax") output("nodes.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, nr, rho1, (r0, r1))], nPerh = nPerh) output("nodes.numNodes") # Set the initial conditions. dr = (r1 - r0)/nr pos = nodes.positions() mass = nodes.mass() rho = nodes.massDensity() eps = nodes.specificThermalEnergy() for i in xrange(nodes.numInternalNodes): ri = pos[i].x #mi = trapezoidalIntegration(answer.rhoInitial, ri - 0.5*dr, ri + 0.5*dr, 200) #rho[i] = mi/dr #eps[i] = trapezoidalIntegration(answer.Pinitial, ri - 0.5*dr, ri + 0.5*dr, 200)/((answer.gamma - 1.0)*mi) rho[i] = answer.rho(0.0, ri) mass[i] = rho[i]*dr
#------------------------------------------------------------------------------- # Make the NodeList. #------------------------------------------------------------------------------- nodes1 = makeFluidNodeList("gas", eos, hmin=hmin, hmax=hmax, hminratio=hminratio, nPerh=nPerh) #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- vel = nodes1.velocity() from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes1, nx1, rho1, (0.0, 1.0))], nPerh=nPerh) # Set specific thermal energies eps1 = P1 / ((gamma - 1.0) * rho1) nodes1.specificThermalEnergy(ScalarField("tmp", nodes1, eps1)) # Set node velocities nodes1.velocity(VectorField("tmp", nodes1, Vector(vx1, 0.0))) #------------------------------------------------------------------------------- # Construct a DataBase to hold our node list #------------------------------------------------------------------------------- db = DataBase() db.appendNodeList(nodes1) #-------------------------------------------------------------------------------
hmin=hmin, hmax=hmax, nPerh=nPerh, kernelExtent=kernelExtent) output("nodes") output("nodes.hmin") output("nodes.hmax") output("nodes.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Seed the nodes #------------------------------------------------------------------------------- rho0 = 1.0 if dimension == 1: from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes, nx, rho0, (x0, x1))], nPerh=nPerh) elif dimension == 2: from GenerateNodeDistribution2d import * generator = GenerateNodeDistribution2d(distributionType="lattice", nRadial=nx, nTheta=nx, xmin=(x0, x0), xmax=(x1, x1), rho=rho0, nNodePerh=nPerh) if mpi.procs > 1: from VoronoiDistributeNodes import distributeNodes2d else: from DistributeNodes import distributeNodes2d distributeNodes2d((nodes, generator)) else:
#------------------------------------------------------------------------------- # Make the NodeList. #------------------------------------------------------------------------------- nodes1 = makeFluidNodeList("nodes1", eos, hmin=hmin, hmax=hmax, nPerh=nPerh) output("nodes1") output("nodes1.hmin") output("nodes1.hmax") output("nodes1.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- if testDim == "1d": from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes1, [(nx1, rho1, (x0, x1)), (nx2, rho2, (x1, x2))])], nPerh=nPerh) elif testDim == "2d": from DistributeNodes import distributeNodes2d from GenerateNodeDistribution2d import GenerateNodeDistribution2d from CompositeNodeDistribution import CompositeNodeDistribution gen1 = GenerateNodeDistribution2d(nx1, 2 * nx1, rho1, distributionType="lattice", xmin=(x0, x0), xmax=(x1, x2), nNodePerh=nPerh, SPH=True) gen2 = GenerateNodeDistribution2d(nx2, 2 * nx2,
kernelExtent=WT.kernelExtent, nPerh=nPerh) nodeSet = (outerNodes1, outerNodes2, innerNodes) for nodes in nodeSet: output("nodes.name") output(" nodes.hmin") output(" nodes.hmax") output(" nodes.hminratio") output(" nodes.nodesPerSmoothingScale") del nodes #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- distributeNodesInRange1d([(outerNodes1, [(nx1 / 2, rho1, (x0, x1))]), (innerNodes, [(nx2, rho2, (x1, x2))]), (outerNodes2, [(nx1 / 2, rho1, (x2, x3))])]) for nodes in nodeSet: print nodes.name, ":" output(" mpi.reduce(nodes.numInternalNodes, mpi.MIN)") output(" mpi.reduce(nodes.numInternalNodes, mpi.MAX)") output(" mpi.reduce(nodes.numInternalNodes, mpi.SUM)") del nodes # Set node specific thermal energies for (nodes, gamma, rho, P) in ((outerNodes1, gamma1, rho1, P1), (outerNodes2, gamma1, rho1, P1), (innerNodes, gamma2, rho2, P2)): eps0 = P / ((gamma - 1.0) * rho) nodes.specificThermalEnergy(ScalarField("tmp", nodes, eps0)) vels = nodes.velocity()
output("WT") #------------------------------------------------------------------------------- # Make the NodeList. #------------------------------------------------------------------------------- nodes1 = makeFluidNodeList("nodes1", eos, hmin=hmin, hmax=hmax, nPerh=nPerh) output("nodes1") output("nodes1.hmin") output("nodes1.hmax") output("nodes1.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes1, nx1, rho1, (x0, x1))], nPerh=nPerh) L = x1 - x0 def Minterval(xi0, xi1): return rho1 * ((xi1 - xi0) + A * L / (pi * kfreq) * (sin(pi * kfreq / L * (xi1 - x0)) - sin(pi * kfreq / L * (xi0 - x0)))) # Grab the analytic answer. import StandingWaveSolution dx = (x1 - x0) / nx1 h1 = nPerh * dx cs = sqrt(cs2)
output("WT") #------------------------------------------------------------------------------- # Make the NodeList. #------------------------------------------------------------------------------- nodes1 = makeFluidNodeList("nodes1", eos, hmin=hmin, hmax=hmax, nPerh=nPerh) output("nodes1") output("nodes1.hmin") output("nodes1.hmax") output("nodes1.nodesPerSmoothingScale") #------------------------------------------------------------------------------- # Set the node properties. #------------------------------------------------------------------------------- from DistributeNodes import distributeNodesInRange1d distributeNodesInRange1d([(nodes1, nx1, rho1, (x0, x1))]) nNodesThisDomain1 = nodes1.numInternalNodes output("nodes1.numNodes") # Set node specific thermal energies nodes1.specificThermalEnergy(ScalarField("tmp", nodes1, eps1)) # Displace the nodes in a pattern that looks like the tensile instability clumping. dx = (x1 - x0) / nx1 for i in xrange(nodes1.numInternalNodes): delta = amplitude * ((-1.0)**( i % 2)) * dx # amplitude*sin(2.0*pi*nodes1.positions()[i].x/wavelength) nodes1.positions()[i].x += delta #-------------------------------------------------------------------------------