for p, filename in plots:
        p.figure.savefig(os.path.join(dataDir, filename))

    # Report the error norms.
    rmin, rmax = 0.05, 0.35
    r = mpi.allreduce([x.magnitude() for x in nodes1.positions().internalValues()], mpi.SUM)
    rho = mpi.allreduce(list(nodes1.massDensity().internalValues()), mpi.SUM)
    v = mpi.allreduce([x.magnitude() for x in nodes1.velocity().internalValues()], mpi.SUM)
    eps = mpi.allreduce(list(nodes1.specificThermalEnergy().internalValues()), mpi.SUM)
    Pf = ScalarField("pressure", nodes1)
    nodes1.pressure(Pf)
    P = mpi.allreduce(list(Pf.internalValues()), mpi.SUM)
    if mpi.rank == 0:
        from SpheralTestUtilities import multiSort
        import Pnorm
        multiSort(r, rho, v, eps, P)
        rans, vans, epsans, rhoans, Pans, hans = answer.solution(control.time(), r)
        print "\tQuantity \t\tL1 \t\t\tL2 \t\t\tLinf"
        for (name, data, ans) in [("Mass Density", rho, rhoans),
                                  ("Pressure", P, Pans),
                                  ("Velocity", v, vans),
                                  ("Thermal E", eps, epsans)]:
            assert len(data) == len(ans)
            error = [data[i] - ans[i] for i in xrange(len(data))]
            Pn = Pnorm.Pnorm(error, r)
            L1 = Pn.gridpnorm(1, rmin, rmax)
            L2 = Pn.gridpnorm(2, rmin, rmax)
            Linf = Pn.gridpnorm("inf", rmin, rmax)
            print "\t%s \t\t%g \t\t%g \t\t%g" % (name, L1, L2, Linf)

#-------------------------------------------------------------------------------
Exemple #2
0
    eps = state.scalarFields(HydroFieldNames.specificThermalEnergy)
    Hfield = state.symTensorFields(HydroFieldNames.H)
    S = state.symTensorFields(SolidFieldNames.deviatoricStress)
    D = state.symTensorFields(SolidFieldNames.effectiveTensorDamage)
    xprof = mpi.reduce([x.x for x in internalValues(pos)], mpi.SUM)
    rhoprof = mpi.reduce(internalValues(rho), mpi.SUM)
    Pprof = mpi.reduce(internalValues(P), mpi.SUM)
    vprof = mpi.reduce([v.x for v in internalValues(vel)], mpi.SUM)
    epsprof = mpi.reduce(internalValues(eps), mpi.SUM)
    hprof = mpi.reduce([1.0/sqrt(H.Determinant()) for H in internalValues(Hfield)], mpi.SUM)
    sprof = mpi.reduce([x.xx for x in internalValues(S)], mpi.SUM)
    dprof = mpi.reduce([x.xx for x in internalValues(D)], mpi.SUM)
    mof = mortonOrderIndices(db)
    mo = mpi.reduce(internalValues(mof), mpi.SUM)
    if mpi.rank == 0:
        multiSort(mo, xprof, rhoprof, Pprof, vprof, epsprof, hprof, sprof, dprof)
        f = open(outputFile, "w")
        f.write(("#" + 8*" %16s" + "\n") % ("x", "rho", "P", "v", "eps", "h", "S", "D"))
        for (xi, rhoi, Pi, vi, epsi, hi, si, di) in zip(xprof, rhoprof, Pprof, vprof, epsprof, hprof, sprof, dprof):
            f.write((8*"%16.12e " + "\n") %
                    (xi, rhoi, Pi, vi, epsi, hi, si, di))
        f.close()

        #---------------------------------------------------------------------------
        # Check the floating values for the state against reference data.
        #---------------------------------------------------------------------------
        import filearraycmp as fcomp
        assert fcomp.filearraycmp(outputFile, referenceFile, testtol, testtol)
        print "Floating point comparison test passed."

        #---------------------------------------------------------------------------
# Compute the radial profiles
#-------------------------------------------------------------------------------
from SpheralTestUtilities import multiSort
import numpy.polynomial.polynomial as poly
xprof = mpi.reduce(nodes.positions().internalValues(), mpi.SUM)
rprof = [x.magnitude() for x in xprof]
vprof = mpi.reduce(nodes.velocity().internalValues(), mpi.SUM)
Hprof = mpi.reduce(nodes.Hfield().internalValues(), mpi.SUM)
phi = gravity.potential
phiprof = mpi.reduce(phi[0].internalValues(), mpi.SUM)
mof = mortonOrderIndices(db)
mo = mpi.reduce(mof[0].internalValues(), mpi.SUM)
coefs, phifit = None, None
if mpi.rank == 0:
    from SpheralTestUtilities import multiSort
    multiSort(rprof, mo, xprof, vprof, Hprof, phiprof)

    # Fit phi(r)
    coefs = poly.polyfit(rprof, np.log(-np.array(phiprof)), 2)
    phifit = -np.exp(poly.polyval(rprof, coefs))
    print "Fit coefficients: ", coefs
    sigphi = np.std(np.array(phiprof) - phifit)
    print "Standard deviation: ", sigphi

coefs = mpi.bcast(coefs, root=0)
phifit = mpi.bcast(phifit, root=0)

if graphics:
    from SpheralMatplotlib import *
    EPlot = plotEHistory(control.conserve)
    phiPlot = plotFieldList(gravity.potential,
Exemple #4
0
# If requested, write out the state in a global ordering to a file.
#-------------------------------------------------------------------------------
if outputFile != "None":
    outputFile = os.path.join(dataDir, outputFile)
    from SpheralTestUtilities import multiSort
    xprof = mpi.reduce(nodes.positions().internalValues(), mpi.SUM)
    rprof = [x.magnitude() for x in xprof]
    vprof = mpi.reduce(nodes.velocity().internalValues(), mpi.SUM)
    Hprof = mpi.reduce(nodes.Hfield().internalValues(), mpi.SUM)
    phi = gravity.potential()
    phiprof = mpi.reduce(phi[0].internalValues(), mpi.SUM)
    mof = mortonOrderIndices(db)
    mo = mpi.reduce(mof[0].internalValues(), mpi.SUM)
    if mpi.rank == 0:
        from SpheralTestUtilities import multiSort
        multiSort(mo, rprof, xprof, vprof, Hprof, phiprof)
        f = open(outputFile, "w")
        f.write(("# " + 14*"%15s " + "\n") % ("r", "x", "y", "z", "vx", "vy", "vz", "Hxx", "Hxy", "Hxz", "Hyy", "Hyz", "Hzz", "phi"))
        for (ri, xi, vi, Hi, phii, moi) in zip(rprof, xprof, vprof, Hprof, phiprof, mo):
            f.write((14*" %16.12e" + "\n") % (ri, xi.x, xi.y, xi.z, vi.x, vi.y, vi.z, 
                                              Hi.xx, Hi.xy, Hi.xz, Hi.yy, Hi.yz, Hi.zz, phii))
        f.close()

        #---------------------------------------------------------------------------
        # Also we can optionally compare the current results with another file.
        #---------------------------------------------------------------------------
        if comparisonFile != "None":
            print "Comparing to reference %s" % comparisonFile
            import filearraycmp as fcomp
            assert fcomp.filearraycmp(outputFile, comparisonFile)