My code works with a STEP file that contains the geometry and faces names.
Here is the stp file :
PoutreCoupe.stp (13.4 KB)
Here is my code:
from netgen.occ import *
from ngsolve import *
# Variable
E = 210000
nu = 0.3
# Dirichlet Boundaries
Face_Dirichletx = 'Face7'
Face_Dirichlety = 'Face7'
Face_Dirichletz = 'Face7'
# Loaded Faces
FaceForce = 'Face1'
# Mesh the geometry and get the boundaries --------------------------------------------------
geo = OCCGeometry('PoutreCoupe.stp')
geo.Glue()
mesh = Mesh(geo.GenerateMesh(maxh=5))
boundaries = list(mesh.GetBoundaries())
print(boundaries)
def stress(strain, mu, lam):
return 2 * mu * strain + lam * Trace(strain) * Id(3)
def mu(E, nu):
return E / 2 / (1 + nu)
def lam(E, nu):
return E * nu / ((1 + nu) * (1 - 2 * nu))
# FE Space ---------------------------------------------------------------------------------
fes = VectorH1(mesh, order=2, dirichletx=Face_Dirichletx, dirichlety=Face_Dirichlety, dirichletz=Face_Dirichletz)
u, v = fes.TnT()
gfu = GridFunction(fes)
# Assemble a ----------------------------------------------------------------------------
a = BilinearForm(fes)
a += SymbolicBFI(InnerProduct(stress(Sym(Grad(u)), mu=mu(E, nu), lam=lam(E, nu)), Sym(Grad(v))))
pre = Preconditioner(a, "bddc")
a.Assemble()
# Load ----------------------------------------------------------------------------
domaine = mesh.Boundaries(FaceForce)
area = Integrate(1, domaine)
Load = 200/area
force = CF((0, 0, Load))
f = LinearForm(fes)
f += force * v * ds(FaceForce)
f.Assemble()
# Run the Solver --------------------------------------------------------------------------
from ngsolve.krylovspace import CGSolver
inv = CGSolver(a.mat, pre, printrates='\r', tol=1e-6, maxiter=500)
gfu.vec.data = inv * f.vec
# Print Result --------------------------------------------------------------------------
with TaskManager():
EFstress = MatrixValued(H1(mesh, order=2), symmetric=True)
StressT = GridFunction(EFstress)
volumes = geo.shape
StressT.Interpolate(stress(Sym(Grad(gfu)),mu(E, nu),lam(E, nu)))
In this code, the boundaries list printed is:
[‘default’, ‘default’, ‘default’, ‘Face3’, ‘default’, ‘default’, ‘default’, ‘Face7’, ‘default’, ‘default’, ‘default’]
But, if you delete the “geo.Glue()”, the boundaries list print:
[‘Face0’, ‘Face1’, ‘Face2’, ‘Face3’, ‘Face4’, ‘Face5’, ‘Face6’, ‘Face7’, ‘Face8’, ‘Face9’, ‘Face10’, ‘Face11’]
I need the face names to apply the force (“Face1”).
Thomas