rho=rhoprofile,
                                  rmin=rmin,
                                  rmax=rmax,
                                  thetamin=thetamin,
                                  thetamax=thetamax,
                                  phi=phi,
                                  ntheta=ntheta,
                                  center=(xcenter, ycenter, zcenter),
                                  distributionType=distributionType,
                                  nNodePerh=nPerh,
                                  SPH=SPH)
distributeNodes((nodes, generator))

#-------------------------------------------------------------------------------
# Drop a viz file for inspection.
#-------------------------------------------------------------------------------
Hfield = nodes.Hfield()
HfieldInv = SymTensorField("H inverse", nodes)
for i in xrange(nodes.numNodes):
    HfieldInv[i] = SymTensor(Hfield[i].Inverse())
vizfile = siloPointmeshDump(
    baseName="ratio_sphere_test_" + distributionType,
    baseDirectory="ratio_sphere_test_" + distributionType,
    fields=[
        nodes.massDensity(),
        nodes.mass(),
        nodes.velocity(),
        nodes.specificThermalEnergy(), Hfield, HfieldInv
    ],
)
Exemplo n.º 2
0
    tessellationFileName="test_medial2d_mantle_maxiter=%i_tol=%g" %
    (maxIterations, fracTol),
    nNodePerh=nPerh)

distributeNodes((nodesCore, generatorCore), (nodesMantle, generatorMantle))

#-------------------------------------------------------------------------------
# Drop a viz file for inspection.
#-------------------------------------------------------------------------------
db = DataBase()
for nodes in nodeSet:
    db.appendNodeList(nodes)
vizfile = siloPointmeshDump(
    baseName="test_medial_maxiter=%i_tol=%g" % (maxIterations, fracTol),
    baseDirectory="test_medial2d_sphere_density",
    fieldLists=[
        db.fluidMassDensity, db.fluidMass, db.fluidVelocity,
        db.fluidSpecificThermalEnergy, db.fluidHfield
    ])

#-------------------------------------------------------------------------------
# Plot a few profiles of interest.
#-------------------------------------------------------------------------------
from SpheralGnuPlotUtilities import *
massPlot = plotFieldList(db.fluidMass,
                         xFunction="%s.magnitude()",
                         plotStyle="points",
                         winTitle="mass",
                         colorNodeLists=False,
                         plotGhosts=False)
rhoPlot = plotFieldList(db.fluidMassDensity,
Exemplo n.º 3
0
print "Generator 4"
generator4 = MedialGenerator2d(
    n=n4,
    rho=0.1,
    boundary=outerBox,
    holes=[Hboundary, outerCircle],
    maxIterations=maxIterations,
    fracTol=fracTol,
    #tessellationFileName = "test_medial_nodes4_maxiter=%i_tol=%g" % (maxIterations, fracTol),
    nNodePerh=nPerh)

distributeNodes((nodes1, generator1), (nodes2, generator2),
                (nodes3, generator3), (nodes4, generator4))

#-------------------------------------------------------------------------------
# Drop a viz file for inspection.
#-------------------------------------------------------------------------------
Hfield = nodes.Hfield()
HfieldInv = SymTensorField("H inverse", nodes)
domainField = IntField("Domain", nodes)
for i in xrange(nodes.numNodes):
    HfieldInv[i] = Hfield[i].Inverse()
    domainField[i] = mpi.rank
vizfile = siloPointmeshDump(
    baseName="test_medial_maxiter=%i_tol=%g" % (maxIterations, fracTol),
    baseDirectory="test_medial",
    fields=([x.massDensity() for x in nodeSet] + [x.mass() for x in nodeSet] +
            [x.velocity()
             for x in nodeSet] + [x.specificThermalEnergy() for x in nodeSet] +
            [x.Hfield() for x in nodeSet] + [HfieldInv, domainField]))
Exemplo n.º 4
0
'''
#computeWeightedVoronoiVolume(pos, H, rhof, gradRhof, cm, WT.kernelExtent, bounds, holes, weight,
#                         surfacePoint, vol,deltaCentroid, cells)

print "computed weighted volumes"
'''
pp = plotPolygon(outerCircle, plotVertices=False, plotLabels=False)
xmin = -1.5*Vector.one
xmax = 1.5*Vector.one
pp("set size square; set xrange [%g:%g]; set yrange [%g:%g]" % (xmin.x,xmax.x,xmin.y,xmax.y))
pp.refresh()
for i in xrange(len(cells[0])):
    plotPolygon(cells[0][i],plot=pp,plotVertices=False,plotLabels=False)
'''

#-------------------------------------------------------------------------------
# Drop a viz file for inspection.
#-------------------------------------------------------------------------------

Hfield = nodes1.Hfield()
HfieldInv = SymTensorField("H inverse", nodes1)
Sfield = ScalarField("Size", nodes1, 0.0)
for i in xrange(nodes1.numNodes):
    HfieldInv[i] = Hfield[i].Inverse()
    Sfield[i] = pi * (0.5 * points[i][3])**2

vizfile = siloPointmeshDump(
    baseName="test_medial_maxiter=%i_tol=%g" % (maxIterations, fracTol),
    baseDirectory="test_medial",
    fields=([rhof[0], pos[0], H[0], mass[0], vol[0], HfieldInv, Sfield]))
Exemplo n.º 5
0
flags = [1, 1, 1, 0, 0, 0]

gen = ExtrudedSurfaceGenerator(surface,
                               lconstant=0.05,
                               lextrude=0.5,
                               nextrude=20,
                               dltarget=0.005,
                               dstarget=0.1,
                               rho=1.0,
                               flags=flags,
                               nNodePerh=1.01,
                               SPH=False)

eos = GammaLawGasMKS(5.0 / 3.0, 1.0)
nodes = makeFluidNodeList("test", eos, hminratio=1.0e-10)

distributeNodes3d((nodes, gen))

H = nodes.Hfield()
Hinv = SymTensorField("H inverse", nodes)
for i in xrange(nodes.numNodes):
    Hinv[i] = H[i].Inverse()

siloPointmeshDump(
    "test_void",
    fields=[nodes.mass(),
            nodes.massDensity(),
            nodes.Hfield(), Hinv])
writePolyhedronOBJ(surface, "test_void_surface.obj")
Exemplo n.º 6
0
def centroidalRelaxNodes(nodeListsAndBounds,
                         W,
                         rho,
                         gradrho = None,
                         boundaries = [],
                         maxIterations = 100,
                         maxFracTol = 1.0e-2,
                         avgFracTol = 1.0e-3,
                         correctionOrder = Spheral.LinearOrder,
                         centroidFrac = 0.25,
                         tessellationBaseDir = ".",
                         tessellationFileName = None):

    # Decide on our dimensionality and import the appropriate aliases.
    assert (isinstance(W, Spheral.TableKernel1d) or
            isinstance(W, Spheral.TableKernel2d) or
            isinstance(W, Spheral.TableKernel3d))
    if isinstance(W, Spheral.TableKernel1d):
        import Spheral1d as sph
        FacetedVolume = sph.Box1d
        ndim = 1
    elif isinstance(W, Spheral.TableKernel2d):
        import Spheral2d as sph
        FacetedVolume = sph.Polygon
        ndim = 2
    else:
        import Spheral3d as sph
        FacetedVolume = sph.Polyhedron
        ndim = 3

    # Did we get passed a function or a constant for the density?
    if type(rho) is float:
        rhoConst = True
        class rhofunctor(sph.VectorScalarFunctor):
            def __init__(self):
                sph.VectorScalarFunctor.__init__(self)
            def __call__(self, posi):
                return rho
    else:
        rhoConst = False
        class rhofunctor(sph.VectorScalarFunctor):
            def __init__(self):
                sph.VectorScalarFunctor.__init__(self)
            def __call__(self, posi):
                return rho(posi)
    rhofunc = rhofunctor()

    # What about the gradrho?  Did we get passed anything?
    if gradrho is None:
        useGradRhoFunc = False
        class gradrhofunctor(sph.VectorVectorFunctor):
            def __init__(self):
                sph.VectorVectorFunctor.__init__(self)
            def __call__(self, posi):
                assert "Hey gradrhofunc unimplemented!"
                return 0.0
    else:
        useGradRhoFunc = True
        if type(gradrho) is float:
            class gradrhofunctor(sph.VectorVectorFunctor):
                def __init__(self):
                    sph.VectorVectorFunctor.__init__(self)
                def __call__(self, posi):
                    return gradrho
        else:
            class gradrhofunctor(sph.VectorVectorFunctor):
                def __init__(self):
                    sph.VectorVectorFunctor.__init__(self)
                def __call__(self, posi):
                    return gradrho(posi)
    gradrhofunc = gradrhofunctor()

    # Split out the NodeLists and bounding volumes (if available), depending on what was passed.
    bounds = sph.vector_of_FacetedVolume()
    holes = sph.vector_of_vector_of_FacetedVolume()
    for x in nodeListsAndBounds:
        if type(nodeListsAndBounds[0]) is tuple:
            bounds = sph.vector_of_FacetedVolume([FacetedVolume()]*len(nodeListsAndBounds))
            holes = sph.vector_of_vector_of_FacetedVolume([sph.vector_of_FacetedVolume()]*len(nodeListsAndBounds))
    if len(bounds) > 0:
        nodeLists = []
        for i, xtup in enumerate(nodeListsAndBounds):
            if type(xtup) is tuple:
                nodeLists.append(xtup[0])
                assert len(xtup) in (2,3)
                bounds[i] = xtup[1]
                if len(xtup) == 3:    # Check for holes
                    assert type(xtup[2]) is list
                    for x in xtup[2]:
                        holes[i].append(x)
            else:
                nodeLists.append(xtup)
    else:
        nodeLists = nodeListsAndBounds

    # Build a local DataBase.
    db = sph.DataBase()
    for nodes in nodeLists:
        db.appendNodeList(nodes)

    # We need the boundaries as a vector
    bound_vec = sph.vector_of_Boundary()
    for bc in boundaries:
        bound_vec.append(bc)

    # Prepare the return FieldLists.
    vol = db.newFluidScalarFieldList(0.0, "volume")
    surfacePoint = sph.IntFieldList()
    cells = sph.FacetedVolumeFieldList()
    cellFaceFlags = db.newGlobalvector_of_CellFaceFlagFieldList(sph.vector_of_CellFaceFlag(), "face flags")
    etaVoidPoints = db.newGlobalvector_of_VectorFieldList(eval("sph.vector_of_Vector%id()" % db.nDim), "eta void points")

    # Initialize volume
    massf = db.fluidMass
    rhof = db.fluidMassDensity
    numNodeLists = db.numFluidNodeLists
    for k in xrange(numNodeLists):
        n = massf[k].numInternalElements
        for i in xrange(n):
            assert massf(k,i) > 0.0, "Bad mass (%i,%i), %g" % (k, i, massf(k,i))
            assert rhof(k,i) > 0.0, "Bad density (%i,%i), %g" % (k, i, rhof(k,i))
            vol[k][i] = massf(k,i)/rhof(k,i)

    # We let the C++ method do the heavy lifting.
    iterations = sph.centroidalRelaxNodesImpl(db,
                                              bounds,
                                              holes,
                                              W,
                                              rhofunc,
                                              gradrhofunc,
                                              rhoConst,
                                              useGradRhoFunc,
                                              bound_vec,
                                              maxIterations,
                                              maxFracTol,
                                              avgFracTol,
                                              correctionOrder,
                                              centroidFrac,
                                              vol,
                                              surfacePoint,
                                              cells)

    # Make a final call to computeVoronoiVolume to get the more expensive surfacePoint and cells fields.
    surfacePoint = db.newFluidIntFieldList(0, "surface point")
    deltaMedian = db.newFluidVectorFieldList(sph.Vector.zero, "delta medial position")
    if tessellationFileName:
        cells = db.newFluidFacetedVolumeFieldList(sph.FacetedVolume(), "cells")
    sph.computeVoronoiVolume(db.fluidPosition, 
                             db.fluidHfield, 
                             db.connectivityMap(),
                             sph.SymTensorFieldList(), # no damage
                             bounds,
                             holes,
                             bound_vec,
                             sph.ScalarFieldList(),   # no weights
                             surfacePoint,
                             vol,
                             deltaMedian,
                             etaVoidPoints,
                             cells,
                             cellFaceFlags)

    # Update the masses using rho and volume.
    rho = db.fluidMassDensity
    for k, nodes in enumerate(db.fluidNodeLists()):
        n = nodes.numInternalNodes
        mass = nodes.mass()
        for i in xrange(n):
            assert vol(k,i) > 0.0
            mass[k] = vol(k,i)*rho(k,i)

    # If requested, dump the final info to a diagnostic viz file.
    if tessellationFileName and SpheralVoronoiSiloDump:
        dumper = SpheralVoronoiSiloDump(baseFileName = tessellationFileName,
                                        baseDirectory = tessellationBaseDir,
                                        listOfFieldLists = [vol, surfacePoint, db.fluidMass, db.fluidMassDensity],
                                        boundaries = boundaries,
                                        cells = cells)
        dumper.dump(0.0, iterations)

        siloPointmeshDump(baseName = tessellationFileName + "_points",
                          fieldLists = [vol, surfacePoint, db.fluidMass, db.fluidMassDensity])

    return vol, surfacePoint