示例#1
0
def getMeshingparameters(filename):
    standard = [MeshingParameters()] + [MeshingParameters(ms)  for ms in (meshsize.very_coarse, meshsize.coarse, meshsize.moderate, meshsize.fine, meshsize.very_fine)]
    if filename == "shell.geo":
        return [] # do not test this example cause it needs so long...
    if filename == "manyholes2.geo":
        return [standard[1]] # this gets too big for finer meshsizes
    if filename in ("manyholes.geo", "frame.step"):
        return standard[:3] # this gets too big for finer meshsizes
    if filename == "extrusion.geo":
        return standard[:-1]
    if filename == "screw.step":
        return standard[3:] # coarser meshes don't work here
    if filename == "cylsphere.geo":
        return standard[0:2] + standard[3:] # coarse gives inconsistent reults (other mesh on MacOS)
    if filename == "part1.stl":
        return standard[0:1] + standard[2:] # very coarse does not work
    return standard
示例#2
0
def getMeshingparameters(filename):
    standard = [MeshingParameters()] + [
        MeshingParameters(ms)
        for ms in (meshsize.very_coarse, meshsize.coarse, meshsize.moderate,
                   meshsize.fine, meshsize.very_fine)
    ]
    if filename == "shell.geo":
        return []  # do not test this example cause it needs so long...
    if filename == "extrusion.geo":
        return []  # this segfaults right now
    if filename == "manyholes2.geo":
        return [standard[1]]  # this gets too big for finer meshsizes
    if filename in ("manyholes.geo", "frame.step"):
        return standard[:3]  # this gets too big for finer meshsizes
    if filename == "screw.step":
        return standard[3:]  # coarser meshes don't work here
    return standard
示例#3
0
def test_geoFiles(filename, mp, i, refdata):
    ref = refdata[filename]
    import filecmp
    print("load geo", filename)
    mp = MeshingParameters(mp, parallel_meshing=False)
    mesh = generateMesh(filename, mp)
    mesh.Save(filename+'_seq.vol.gz')
    with TaskManager():
        mesh_par = generateMesh(filename, mp)
        mesh_par.Save(filename+'_par.vol.gz')

    assert filecmp.cmp(filename+'_seq.vol.gz', filename+'_par.vol.gz')
    checkData(mesh, mp, ref[i])
示例#4
0
from ngsolve import *
from netgen.geom2d import SplineGeometry
from netgen.meshing import MeshingParameters


geo = SplineGeometry()
geo.AddRectangle( (0, 0), (1, 0.1), bcs = ("bottom", "right", "top", "left"))

mp = MeshingParameters(maxh=0.05)
mp.RestrictH(0,0,0, h=0.01)
mp.RestrictH(0,0.1,0, h=0.01)
mesh = Mesh( geo.GenerateMesh(mp=mp))



from ngs_templates.Elasticity import *

loadfactor = Parameter(0)

model = Elasticity(mesh=mesh, materiallaw=NeoHookeMaterial(200,0.2), \
                       # dirichlet="left",
                       # volumeforce=loadfactor*CoefficientFunction((0,1)), \
                       boundarydisplacement = { "left" : (0,0) },
                       boundaryforce = { "right" : loadfactor*(0,1) },
                       # boundarydisplacement = { "left" : (0,0), "right" : loadfactor*(0,1) },
                       nonlinear=True, order=4)

                       
Draw (model.displacement)
Draw (model.stress, mesh, "stress")
SetVisualization (deformation=True)
示例#5
0
from ngsolve import *
from math import pi

from netgen.geom2d import SplineGeometry
from netgen.meshing import MeshingParameters

ngsglobals.pajetrace = True


geom = SplineGeometry("chip.in2d")
mp = MeshingParameters (maxh=0.1)
mesh = Mesh(geom.GenerateMesh (mp=mp))


# one coefficient per sub-domain
lam = DomainConstantCF([1, 1000, 10])

# source in sub-domain 3
source = DomainConstantCF([0, 0, 1])

v = H1(mesh, order=2, dirichlet=[1])

u = GridFunction(v)

a = BilinearForm(v, symmetric=True)
a += Laplace(lam)

f = LinearForm(v)
f += Source(source)

c = Preconditioner(a, type="multigrid", flags={ "inverse" : "sparsecholesky" })
示例#6
0
def stokesCIP(baseorderQ=1,
              baseorderV=2,
              bonusorderV=0,
              boundaryStab=1.0,
              cipStab=1.0,
              cipStab2=1.0,
              refinements=0):

    geom = SplineGeometry("circleInCircle.in2d")
    mp = MeshingParameters(maxh=0.12)
    ng_mesh = geom.GenerateMesh(mp)
    mesh = Mesh(ng_mesh)

    curveorder = 2
    mesh.Curve(curveorder)

    V = FESpace("h1ho", mesh, order=baseorderV, dirichlet=[2])

    if bonusorderV > 0:
        AddEdgeFunctions(mesh, V, baseorderV + bonusorderV, bidx=1)
        print("V.ndof = ", V.ndof)

    Q = FESpace("h1ho", mesh, order=baseorderQ)
    QF = bcip.SurfaceFacetFESpace(mesh)
    print(" Q.ndof = ", Q.ndof)
    print("QF.ndof = ", QF.ndof)
    X = FESpace([V, V, Q, QF], flags={"dgjumps": True})

    u, v, p, pf = X.TrialFunction()
    wu, wv, wp, wpf = X.TestFunction()

    gradu = u.Deriv()
    gradv = v.Deriv()
    gradwu = wu.Deriv()
    gradwv = wv.Deriv()

    e1 = VariableCF("(1,0)")
    e2 = VariableCF("(0,1)")

    # e1 = CoefficientFunction((1,0))
    # e2 = CoefficientFunction((0,1))

    a = BilinearForm(X, symmetric=True)
    a += SymbolicBFI(gradu * gradwu + gradv * gradwv + u * wu + v * wv -
                     (gradu[0] + gradv[1]) * wp - (gradwu[0] + gradwv[1]) * p)

    if boundaryStab > 0:
        bval = DomainConstantCF([0, -boundaryStab])
        if True:
            a += BFI(name="bcip", dim=2, coef=-boundaryStab)
        else:
            a.components[2] += BFI(name="BoundLaplace", dim=2, coef=bval)

    a.components[2] += BFI(name="cip", dim=2, coef=-cipStab)
    a.components[2] += BFI(name="cip2ndorder", dim=2, coef=-cipStab2)

    a.Assemble()

    #source = ConstantCF(1)
    f = LinearForm(X)
    f.Assemble()

    #set global for keeping in memory for gui
    global sol
    sol = GridFunction(X)
    sol.components[0].Set(VariableCF("5*x"))
    sol.components[1].Set(VariableCF("5*y"))

    c = Preconditioner(a, type="direct", flags={"inverse": "pardiso"})
    c.Update()
    bvp = BVP(bf=a, lf=f, gf=sol, pre=c, maxsteps=20)
    bvp.Do()

    global vel
    vel = e1 * sol.components[0] + e2 * sol.components[1]
    #Draw(mesh=mesh,cf=vel,name="velocity")

    ## Visualize pressure solution and reference pressure
    global ref_pressure
    ref_pressure = VariableCF("(-0.2-0.2*log(sqrt(x*x+y*y)))")
    Draw(mesh=mesh, cf=ref_pressure, name="ref_pressure")
    global pressure
    pressure = sol.components[2]
    err_pre = (ref_pressure - pressure) * (ref_pressure - pressure)
    Draw(pressure)
    # Draw(sol.components[2])

    ## Visualize velocity solution and reference velocity
    global ref_vel
    ref_vel = VariableCF("(0.2/(x*x+y*y) * x, 0.2/(x*x+y*y) * y)")
    # Draw(mesh=mesh,cf=ref_vel,name="ref_vel")

    global err_vel
    err_vel = (ref_vel - vel) * (ref_vel - vel)

    global l_vel
    global l_pre
    l_vel = []
    l_pre = []
    l_vel.append(sqrt(Integrate(err_vel, mesh, VOL)))
    l_pre.append(sqrt(Integrate(err_pre, mesh, VOL)))
    print("vel errors:", l_vel)
    print("pre errors:", l_pre)

    def MyRefine():
        mesh.Refine()
        mesh.Curve(curveorder)
        ## Update:
        X.Update()
        if bonusorderV > 0:
            AddEdgeFunctions(mesh, V, baseorderV + bonusorderV, bidx=1)
            print("V.ndof = ", V.ndof)

        sol.Update()
        a.Assemble()
        f.Assemble()
        ## Set Boundary conditions
        sol.components[0].Set(VariableCF("5*x"))
        sol.components[1].Set(VariableCF("5*y"))
        c.Update()
        bvp.Do()
        ## Measure Error
        l_vel.append(sqrt(Integrate(err_vel, mesh, VOL)))
        l_pre.append(sqrt(Integrate(err_pre, mesh, VOL)))
        print("vel errors:", l_vel)
        print("pre errors:", l_pre)
        Redraw()

    for i in range(refinements):
        #sleep(5)
        MyRefine()