Exemplo n.º 1
0
def test(meshtype, testname, methods, paramdict, testtype):
    if testname == "cdrexp":
        paramdict["diff"] = 0.001
        paramdict["beta"] = "east"
        paramdict["alpha"] = 0.0
        paramdict["application"]="cdexplayer"
    elif testname == "rdcosh":
        paramdict["symmetric"] = False
        paramdict["diff"] = 0.0001
        paramdict["beta"] = "zero"
        paramdict["alpha"] = 1.0
        paramdict["gamma"] = 2.0
        paramdict["application"]="rdcosh"
    elif testname == "poisson":
        paramdict["diff"] = 1.0
        paramdict["beta"] = "zero"
        paramdict["alpha"] = 0.0
        paramdict["application"]="quadratic"
        # application="cosinus"
        # application="linear"
    solver = simfemcdr.Solver()
    if testtype == 'hmean':
        hmean = None
        params=[0.5*0.5**i for i in range(10)]
        # params=[0.5*0.5**i for i in range(4)]
    elif testtype == 'diff':
        hmean=0.02
        params=[0.1*0.1**i for i in range(5)]
    simfemplot = tools.plot.SimFemPlot(methods, params=params, param=testtype)
    simfemplot.methodsnames["traditionalintegration"] = "trad"
    simfemplot.methodsnames["nitscheintegration"] = "nit"
    simfemplot.methodsnames["newnitscheintegration"] = "new"
    simfemplot.paramname = "h"
    simfemplot.order = False
    simfemplot.filename = testname+'.png'
    errs = ["L1"]
    simfemtesterrors = tools.testerrors.SimFemTestErrors(solver=solver, errs=errs, plotter=simfemplot, meshtype=meshtype, paramdict=paramdict, methods=methods, param=testtype, params=params, hmean=hmean, verbose=0)
    simfemtesterrors.run()
Exemplo n.º 2
0
def test(meshtype, testname, methods, hmeans, fem):
    if meshtype == "LineMesh":
        from mesh.geometries.unitline import GeometryClass
    elif meshtype == "TriangleMesh":
        from mesh.geometries.unitsquare import GeometryClass
    elif meshtype == "TetrahedralMesh":
        from mesh.geometries.unitcube import GeometryClass

    simfemplot = tools.plot.SimFemPlot()
    simfemplot = tools.plot.SimFemPlot(methods, params=hmeans, param='hmean')
    if testname == "cdrexp":
        diff = 0.001
        beta = "east"
        alpha = 0.0
        application = "cdexplayer"
    elif testname == "rdcosh":
        diff = 0.0001
        beta = "zero"
        alpha = 1.0
        application = "rdcosh"
    elif testname == "poisson":
        diff = 1.0
        beta = "zero"
        alpha = 0.0
        application = "quadratic"
        # application="cosinus"
        # application="linear"
    # application="cosinus"
    # application="quadratic"
    # application="linear"
    # application="constant"
    errL1 = {}
    errL2 = {}
    errH1 = {}
    times = {}
    for method in methods:
        times[method] = 0.0
    for im, method in enumerate(methods):
        print("####### %s #####" % (method))
        errL1[method] = np.zeros(len(hmeans))
        errL2[method] = np.zeros(len(hmeans))
        errH1[method] = np.zeros(len(hmeans))
        start = time.time()
        for ih, hmean in enumerate(hmeans):
            print("---- hmean=", hmean)
            geom = GeometryClass(hmean=hmean)
            geom.runGmsh(outdir="Data")
            partion_id = 1
            construct_bdrymeshes = False
            mesh = simfempy.create(meshtype, partion_id, construct_bdrymeshes)
            mesh.readGmsh("Data/" + geom.name + '.msh')
            mesh.addGeometryObject('MeasureOfCell')
            mesh.addGeometryObject('Normals')
            # mesh.save("Data/"+geom.name+'.h5')
            solver = simfemcdr.Solver()
            solver.setParameter("method", method)
            solver.setParameter("application", application)
            solver.setParameter("beta", beta)
            solver.setParameter("fem", fem)
            solver.setParameter("diff", diff)
            solver.setParameter("alpha", alpha)
            solver.setParameter("deltasupg", 0.5)
            solver.setMesh(mesh)
            # solver.loadMesh(meshtype, "Data/"+geom.name+'.h5')
            solver.init()
            info = solver.getInfo()
            print(info)
            d = solver.run()
            errL1[method][ih] = d["L1"]
            errL2[method][ih] = d["L2"]
            errH1[method][ih] = d["H1"]
            # print("d=",d)
            solver.writeXdmf()
        times[method] = time.time() - start
    for method in methods:
        print("errL2 %-20s" % (method), errL2[method])
    print()
    for method in methods:
        print("errL1 %-20s" % (method), errL1[method])
    print()
    for method in methods:
        print("errH1 %-20s" % (method), errH1[method])
    # for method in methods:
    #     errH1[method] = np.sqrt( diff*errH1[method]**2 + errL2[method]**2)
    for method in methods:
        print("%-20s %10g" % (method, times[method]))

    datatoplot = {}
    datatoplot['L1'] = errL1
    # datatoplot['L2'] = errL2
    # datatoplot['H1'] = errH1

    simfemplot.methodsnames["traditionalintegration"] = "trad"
    simfemplot.methodsnames["nitscheintegration"] = "nit"
    simfemplot.methodsnames["newnitscheintegration"] = "new"
    simfemplot.order = False
    simfemplot.ploterrors(datatoplot)
Exemplo n.º 3
0
def main():
    testname = "poisson"
    fem = "P1"
    hmeans = [0.5 * 0.5**i for i in range(3)]
    methods = ["traditional"]

    from mesh.geometries.unitsquare import GeometryClass

    meshtype = "TriangleMesh"
    simfemplot = tools.plot.SimFemPlot()
    simfemplot = tools.plot.SimFemPlot(methods, params=hmeans, param='hmean')
    diff = 1.0
    beta = "zero"
    alpha = 1.0
    application = "quadratic"
    errL1 = {}
    errL2 = {}
    errH1 = {}
    times = {}
    for method in methods:
        times[method] = 0.0
    geom = GeometryClass(hmean=1)
    name = geom.runGmsh(outdir="Data", number=0)
    for ih in range(3):
        print("---- ih=", ih)
        name = geom.runGmshRefine(number=0, outdir="Data")
        print("name", name)
        partion_id = 1
        construct_bdrymeshes = False
        mesh = simfempy.create(meshtype, partion_id, construct_bdrymeshes)
        mesh.readGmsh("Data/" + name + '.msh')
        mesh.addGeometryObject('MeasureOfCell')
        mesh.addGeometryObject('Normals')
        mesh.save("Data/" + name + '.h5')
        print("mesh", mesh)
        for im, method in enumerate(methods):
            print("####### %s #####" % (method))
            errL1[method] = np.zeros(len(hmeans))
            errL2[method] = np.zeros(len(hmeans))
            errH1[method] = np.zeros(len(hmeans))
            start = time.time()
            solver = simfemcdr.Solver()
            solver.setParameter("method", method)
            solver.setParameter("application", application)
            solver.setParameter("beta", beta)
            solver.setParameter("fem", fem)
            solver.setParameter("diff", diff)
            solver.setParameter("alpha", alpha)
            solver.setParameter("deltasupg", 0.5)
            solver.setMesh(mesh)
            # solver.loadMesh(meshtype, "Data/"+name+'.h5')
            solver.init()
            info = solver.getInfo()
            print(info)
            d = solver.run()
            errL1[method][ih] = d["L1"]
            errL2[method][ih] = d["L2"]
            errH1[method][ih] = d["H1"]
            # print("d=",d)
            solver.writeXdmf()
        times[method] = time.time() - start
    for method in methods:
        print("errL2 %-20s" % (method), errL2[method])
    print()
    for method in methods:
        print("errL1 %-20s" % (method), errL1[method])
    print()
    for method in methods:
        print("errH1 %-20s" % (method), errH1[method])
    # for method in methods:
    #     errH1[method] = np.sqrt( diff*errH1[method]**2 + errL2[method]**2)
    for method in methods:
        print("%-20s %10g" % (method, times[method]))

    datatoplot = {}
    datatoplot['L1'] = errL1
    datatoplot['L2'] = errL2
    datatoplot['H1'] = errH1
    methodsnames = {}
    methodsnames["traditionalintegration"] = "trad"
    methodsnames["nitscheintegration"] = "nit"
    methodsnames["newnitscheintegration"] = "new"
    methodsnames["traditional"] = "trad"
    methodsnames["nitsche"] = "nit"
    methodsnames["newnitsche"] = "new"

    simfemplot.ploterrors(datatoplot)