xfem package

Submodules

Module contents

(ngs)xfem

A module for unfitted finite element discretizations in NGSolve

Submodules: xfem.cutmg … MultiGrid for CutFEM xfem.lsetcurving … isoparametric unfitted FEM xfem.lset_spacetime … isoparametric unfitted space-time FEM xfem.mlset … multiple level sets xfem.utils … some example level set geometries

xfem.AggEmbedding(EA, fes, deformation=None, heapsize=1000000)

Computes and returns embedding matrix for a patchwise polynomial extension (realized through ghost penalties), followed by averaging if some dofs are shared by multiple patches.

Parameters

elaggElementAggregation

ElementAggregation instace defining the patches which are aggregated into a single element

fesngsolve.FESpace

The finite element space which is aggregated.

deformationngsolve.GridFunction [mesh.dim]

The mesh deformation (needed for Ghost penalty assembly)

heapsizeint

heapsize for local computations.

xfem.CutRatioGF(cutinfo)

Ratio between negative and full part of an element. Vector taken from CutInfo and put into a piecewise constant GridFunction.

xfem.DrawDC(levelset, fneg, fpos, *args, **kwargs)

Visualization method for functions that are non-smooth across level set interfaces. Effectively calls ngsolve.solve.Draw with a few manipulations.

Parameters

levelsetCoefficientFunction

(scalar) CoefficientFunction that describes the (implicit) geometry

fnegCoefficientFunction

CoefficientFunction that is evaluated where the level set function is negative

fposCoefficientFunction

CoefficientFunction that is evaluated where the level set function is positive

deformationdeformation (optional)

(vectorial) CoefficientFunction that describes the deformation of the background mesh

remainder*

all remainder arguments are passed to ngsolve.solve.Draw

xfem.DrawDiscontinuous_std(StdDraw, levelset, fneg, fpos, *args, **kwargs)
xfem.DrawDiscontinuous_webgui(WebGuiDraw, levelset, fneg, fpos, *args, **kwargs)
class xfem.DummyScene

Bases: object

Redraw(blocking=False)
xfem.HAS(domain_type)

For a given domain_type return the combined domain type that includes all elements that have a part in the domain type.

xfem.IndicatorCF(mesh, ba, facets=False)

Returns a CoefficientFunction that evaluates a BitArray. On elements/facets with an index i where the BitArray evaluates to true the CoefficientFunction will evaluate as 1, otherwise as 0. Similar functionality (only on elements) can be obtained with BitArrayCF.

xfem.Integrate(levelset_domain=None, *args, **kwargs)

Integrate-wrapper. If a dictionary ‘levelset_domain’ is provided integration will be done on the level set part of the mesh. The dictionary contains the level set function (CoefficientFunciton or GridFunction) and the domain-type (NEG/POS/IF). If the dictionary is not provided, the standard Integrate function from NGSolve will be called.

Parameters

levelset_domaindictionary

entries: * “levelset”:

singe level setngsolve.CoefficientFunction

CoefficientFunction that describes the geometry. In the best case lset is a GridFunction of an FESpace with scalar continuous piecewise (multi-) linear basis functions.

multiple level sets: tuple(ngsolve.GridFunction)

Tuple of GridFunctions that describe the geometry.

  • “domain_type” : single level set: {NEG,POS,IF} (ENUM)

    Integration on the domain where either: * the level set function is negative (NEG) * the level set function is positive (POS) * the level set function is zero (IF )

    multiple level sets: {tuple({ENUM}), list(tuple(ENUM)), DomainTypeArray}

    Integration on the domains specified

  • “subdivlvl” : int On simplex meshes a subtriangulation is created on which the level set function lset is interpolated piecewise linearly. Based on this approximation, the integration rule is constructed. Note: this argument only works on simplices.

  • “order” : int (default: entry does not exist or value -1) overwrites “order”-arguments in the integration (affects only spatial integration)

  • “time_order” : int defines integration order in time (for space-time integrals only)

  • “quad_dir_policy” : {FIRST, OPTIMAL, FALLBACK} (ENUM) Integration direction policy for iterated integrals approach * first direction is used unless not applicable (FIRST) * best direction (in terms of transformation constant) is used (OPTIMAL) * subdivision into simplices is always used (FALLBACK)

mesh :

Mesh to integrate on (on some part)

cfngsolve.CoefficientFunction

the integrand

orderint (default = 5)

integration order. Can be overruled by “order”-entry of the levelset_domain dictionary.

time_orderint (default = -1)

integration order in time (for space-time integration), default: -1 (no space-time integrals)

region_wisebool

(only active for non-levelset version)

element_wisebool

integration result is return per element

deformationgridfunction (or None)

deformation of the mesh (only active if levelset_domain is not None)

ip_containerlist (or None)

a list to store integration points (for debugging or visualization purposes only!)

heapsizeint

heapsize for local computations.

xfem.Integrate_X_special_args(levelset_domain={}, cf=None, mesh=None, VOL_or_BND=<VorB.VOL: 0>, order=5, time_order=-1, region_wise=False, element_wise=False, heapsize=1000000, deformation=None, ip_container=None)

Integrate_X_special_args should not be called directly. See documentation of Integrate.

xfem.IsCut(mesh, lset_approx, subdivlvl=0)

GridFunction that is 1 on cut elements, 0 otherwise (deprecated). Use CutInfo-functionality (perhaps combined with BitArrayCF).

xfem.MakeDiscontinuousDraw(Draw)

Generates a Draw-like visualization function. If Draw is from the webgui, a special evaluator is used to draw a pixel-sharp discontinuity otherwise an IfPos-CoefficientFunction is used.

class xfem.NoDeformation(mesh=None, levelset=None, warn=True)

Bases: object

Dummy deformation class. Does nothing to the mesh. Has two dummy members:
  • lset_p1 : ngsolve.GridFunction The piecewise linear level set function

  • deform : ngsolve.GridFunction A zero GridFunction (for compatibility with netgen Draw(… deformation=))

Has method
  • self.CalcDeformation() Convenience function for code compatibility with LevelSetMeshAdaptation class

CalcDeformation(levelset)

P1 interpolation of levelset function for compatibility with

xfem.RestrictedBilinearForm(space=None, name='blf', element_restriction=None, facet_restriction=None, trialspace=None, testspace=None, **kwargs)

Creates a restricted bilinear form, which is bilinear form with a reduced MatrixGraph compared to the usual BilinearForm. BitArray(s) define on which elements/facets entries will be created.

Use cases:

  • ghost penalty type stabilization: Facet-stabilization that are introduced only act on a few facets in the mesh. By providing the information on the corresponding facets, these additional couplings will only be introduced where necessary.

  • fictitious domain methods (domain decomposition methods): When PDE problems are only solved on a part of a domain while a finite element space is used that is still defined on the whole domain, a BitArray can be used to mark the ‘active’ part of the mesh.

Parameters

space: ngsolve.FESpace

finite element space on which the bilinear form is defined. If trial space and test space are different they can be specified using the trialspace and testspace arguments.

namestring

name of the bilinear form

element_restrictionngsolve.BitArray

BitArray defining the ‘active mesh’ element-wise

facet_restrictionngsolve.BitArray

BitArray defining the ‘active facets’. This is only relevant if FESpace has DG-terms (dgjumps=True)

trialspacengsolve.FESpace

finite element space on which the bilinear form is defined (trial space).

testspacengsolve.FESpace

finite element space on which the bilinear form is defined (test space).

kwargskeyword arguments

kwargs are pasre to flags and passed to bilinearform

xfem.SpaceTimeSet(self, cf, *args, **kwargs)

Overrides the NGSolve version of Set in case of a space-time FESpace. In this case the usual Set() is used on each nodal dof in time.

xfem.SpaceTimeWeakSet(gfu_e, cf, space_fes)

Ondocumented feature

xfem.SymbolicBFI(levelset_domain=None, *args, **kwargs)

Wrapper around SymbolicBFI to allow for integrators on level set domains (see also SymbolicCutBFI). The dictionary contains the level set function (CoefficientFunciton or GridFunction) and the domain-type (NEG/POS/IF). If the dictionary is not provided, the standard SymbolicBFI function from NGSolve will be called.

Parameters

levelset_domaindictionary

entries: * “levelset”:

singe level setngsolve.CoefficientFunction

CoefficientFunction that describes the geometry. In the best case lset is a GridFunction of an FESpace with scalar continuous piecewise (multi-) linear basis functions.

multiple level sets: tuple(ngsolve.GridFunction)

Tuple of GridFunctions that describe the geometry.

  • “domain_type” : single level set: {NEG,POS,IF} (ENUM)

    Integration on the domain where either: * the level set function is negative (NEG) * the level set function is positive (POS) * the level set function is zero (IF )

    multiple level sets: {tuple({ENUM}), list(tuple(ENUM)), DomainTypeArray}

    Integration on the domains specified

  • “subdivlvl” : int On simplex meshes a subtriangulation is created on which the level set function lset is interpolated piecewise linearly. Based on this approximation, the integration rule is constructed. Note: this argument only works on simplices.

  • “order” : int (default: entry does not exist or value -1) overwrites “order”-arguments in the integration

  • “quad_dir_policy” : {FIRST, OPTIMAL, FALLBACK} (ENUM) Integration direction policy for iterated integrals approach * first direction is used unless not applicable (FIRST) * best direction (in terms of transformation constant) is used (OPTIMAL) * subdivision into simplices is always used (FALLBACK)

Other Parameters :

formngsolve.CoefficientFunction

form to integrate

VOL_or_BND{VOL,BND}

integrator is defined in the volume or boundary

element_boundaryboolean

Integration of the boundary of an element (not active for level set domains)

skeletonboolean

Integration over element-interface

definedonRegion

Domain description on where the integrator is defined

definedonelements: BitArray

BitArray that allows integration only on elements or facets (if skeleton=True) that are marked True.

deformationGridFunction

Specify a specific mesh deformation for a bilinear form

orderint

Modifies the order of the quadrature rule used. This is overruled by “order”-entry of the levelset_domain dictionary, if the dictionary entry exists.

time_orderint

order in time that is used in the space-time integration. time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations.

xfem.SymbolicBFIWrapper(levelset_domain=None, *args, **kwargs)

Wrapper around SymbolicBFI to allow for integrators on level set domains (see also SymbolicCutBFI). The dictionary contains the level set function (CoefficientFunciton or GridFunction) and the domain-type (NEG/POS/IF). If the dictionary is not provided, the standard SymbolicBFI function from NGSolve will be called.

Parameters

levelset_domaindictionary

entries: * “levelset”:

singe level setngsolve.CoefficientFunction

CoefficientFunction that describes the geometry. In the best case lset is a GridFunction of an FESpace with scalar continuous piecewise (multi-) linear basis functions.

multiple level sets: tuple(ngsolve.GridFunction)

Tuple of GridFunctions that describe the geometry.

  • “domain_type” : single level set: {NEG,POS,IF} (ENUM)

    Integration on the domain where either: * the level set function is negative (NEG) * the level set function is positive (POS) * the level set function is zero (IF )

    multiple level sets: {tuple({ENUM}), list(tuple(ENUM)), DomainTypeArray}

    Integration on the domains specified

  • “subdivlvl” : int On simplex meshes a subtriangulation is created on which the level set function lset is interpolated piecewise linearly. Based on this approximation, the integration rule is constructed. Note: this argument only works on simplices.

  • “order” : int (default: entry does not exist or value -1) overwrites “order”-arguments in the integration

  • “quad_dir_policy” : {FIRST, OPTIMAL, FALLBACK} (ENUM) Integration direction policy for iterated integrals approach * first direction is used unless not applicable (FIRST) * best direction (in terms of transformation constant) is used (OPTIMAL) * subdivision into simplices is always used (FALLBACK)

Other Parameters :

formngsolve.CoefficientFunction

form to integrate

VOL_or_BND{VOL,BND}

integrator is defined in the volume or boundary

element_boundaryboolean

Integration of the boundary of an element (not active for level set domains)

skeletonboolean

Integration over element-interface

definedonRegion

Domain description on where the integrator is defined

definedonelements: BitArray

BitArray that allows integration only on elements or facets (if skeleton=True) that are marked True.

deformationGridFunction

Specify a specific mesh deformation for a bilinear form

orderint

Modifies the order of the quadrature rule used. This is overruled by “order”-entry of the levelset_domain dictionary, if the dictionary entry exists.

time_orderint

order in time that is used in the space-time integration. time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations.

xfem.SymbolicLFI(levelset_domain=None, *args, **kwargs)

Wrapper around SymbolicLFI to allow for integrators on level set domains (see also SymbolicCutLFI). The dictionary contains the level set function (CoefficientFunciton or GridFunction) and the domain-type (NEG/POS/IF). If the dictionary is not provided, the standard SymbolicLFI function from NGSolve will be called.

Parameters

levelset_domaindictionary

entries: * “levelset”:

singe level setngsolve.CoefficientFunction

CoefficientFunction that describes the geometry. In the best case lset is a GridFunction of an FESpace with scalar continuous piecewise (multi-) linear basis functions.

multiple level sets: tuple(ngsolve.GridFunction)

Tuple of GridFunctions that describe the geometry.

  • “domain_type” : single level set: {NEG,POS,IF} (ENUM)

    Integration on the domain where either: * the level set function is negative (NEG) * the level set function is positive (POS) * the level set function is zero (IF )

    multiple level sets: {tuple({ENUM}), list(tuple(ENUM)), DomainTypeArray}

    Integration on the domains specified

  • “subdivlvl” : int On simplex meshes a subtriangulation is created on which the level set function lset is interpolated piecewise linearly. Based on this approximation, the integration rule is constructed. Note: this argument only works on simplices.

  • “order” : int (default: entry does not exist or value -1) overwrites “order”-arguments in the integration

  • “quad_dir_policy” : {FIRST, OPTIMAL, FALLBACK} (ENUM) Integration direction policy for iterated integrals approach * first direction is used unless not applicable (FIRST) * best direction (in terms of transformation constant) is used (OPTIMAL) * subdivision into simplices is always used (FALLBACK)

Other Parameters :

formngsolve.CoefficientFunction

form to integrate

VOL_or_BND{VOL,BND}

integrator is defined in the volume or boundary

element_boundaryboolean

Integration of the boundary of an element (not active for level set domains)

skeletonboolean

Integration over element-interface

definedonRegion

Domain description on where the integrator is defined

definedonelements: BitArray

BitArray that allows integration only on elements or facets (if skeleton=True) that are marked True.

deformationGridFunction

Specify a specific mesh deformation for a linear form

orderint

Modifies the order of the quadrature rule used. This is overruled by “order”-entry of the levelset_domain dictionary, if the dictionary entry exists.

time_orderint

order in time that is used in the space-time integration. time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations. Note that time_order can only be active if the key “time_order” of the levelset_domain is not set (or -1)

xfem.SymbolicLFIWrapper(levelset_domain=None, *args, **kwargs)

Wrapper around SymbolicLFI to allow for integrators on level set domains (see also SymbolicCutLFI). The dictionary contains the level set function (CoefficientFunciton or GridFunction) and the domain-type (NEG/POS/IF). If the dictionary is not provided, the standard SymbolicLFI function from NGSolve will be called.

Parameters

levelset_domaindictionary

entries: * “levelset”:

singe level setngsolve.CoefficientFunction

CoefficientFunction that describes the geometry. In the best case lset is a GridFunction of an FESpace with scalar continuous piecewise (multi-) linear basis functions.

multiple level sets: tuple(ngsolve.GridFunction)

Tuple of GridFunctions that describe the geometry.

  • “domain_type” : single level set: {NEG,POS,IF} (ENUM)

    Integration on the domain where either: * the level set function is negative (NEG) * the level set function is positive (POS) * the level set function is zero (IF )

    multiple level sets: {tuple({ENUM}), list(tuple(ENUM)), DomainTypeArray}

    Integration on the domains specified

  • “subdivlvl” : int On simplex meshes a subtriangulation is created on which the level set function lset is interpolated piecewise linearly. Based on this approximation, the integration rule is constructed. Note: this argument only works on simplices.

  • “order” : int (default: entry does not exist or value -1) overwrites “order”-arguments in the integration

  • “quad_dir_policy” : {FIRST, OPTIMAL, FALLBACK} (ENUM) Integration direction policy for iterated integrals approach * first direction is used unless not applicable (FIRST) * best direction (in terms of transformation constant) is used (OPTIMAL) * subdivision into simplices is always used (FALLBACK)

Other Parameters :

formngsolve.CoefficientFunction

form to integrate

VOL_or_BND{VOL,BND}

integrator is defined in the volume or boundary

element_boundaryboolean

Integration of the boundary of an element (not active for level set domains)

skeletonboolean

Integration over element-interface

definedonRegion

Domain description on where the integrator is defined

definedonelements: BitArray

BitArray that allows integration only on elements or facets (if skeleton=True) that are marked True.

deformationGridFunction

Specify a specific mesh deformation for a linear form

orderint

Modifies the order of the quadrature rule used. This is overruled by “order”-entry of the levelset_domain dictionary, if the dictionary entry exists.

time_orderint

order in time that is used in the space-time integration. time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations. Note that time_order can only be active if the key “time_order” of the levelset_domain is not set (or -1)

xfem.TimeSlider_Draw(cf, mesh, *args, **kwargs)
xfem.TimeSlider_DrawDC(cf1, cf2, cf3, mesh, *args, **kwargs)
xfem.dCut(levelset, domain_type, order=None, subdivlvl=None, time_order=-1, levelset_domain=None, **kwargs)

Differential symbol for cut integration.

Parameters

levelsetngsolve.GridFunction

The level set fct. describing the geometry (desirable: P1 approximation).

domain_type{POS, IF, NEG, mlset.DomainTypeArray}

The domain type of interest.

orderint

Modify the order of the integration rule used.

subdivlvlint

Number of additional subdivision used on cut elements to generate the cut quadrature rule. Note: subdivlvl >0 only makes sense if you don’t provide a P1 level set function and no isoparametric mapping is used.

definedonRegion

Domain description on where the integrator is defined.

vb{VOL, BND, BBND}

Integration on mesh volume or its (B)boundary. Default: VOL (if combined with skeleton=True VOL refers to interior facets

BND refers to boundary facets)

element_boundarybool

Integration on each element boundary. Default: False

element_vb{VOL, BND, BBND}

Integration on each element or its (B)boundary. Default: VOL (is overwritten by element_boundary if element_boundary is True)

skeletonbool

Integration over element-interface. Default: False.

deformationngsolve.GridFunction

Mesh deformation that is applied. Default: None.

definedonelementsngsolve.BitArray

Allows integration only on elements or facets (if skeleton=True) that are marked True. Default: None.

time_orderint

Order in time that is used in the space-time integration. Default: time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations.

treffloat

turns a spatial integral resulting in spatial integration rules into a space-time quadrature rule with fixed reference time tref

levelset_domaindict

description of integration domain through a dictionary (deprecated).

Returns

CutDifferentialSymbol(VOL)

xfem.dFacetPatch(**kwargs)

Differential symbol for facet patch integrators.

Parameters

definedonRegion

Domain description on where the integrator is defined.

deformationngsolve.GridFunction

Mesh deformation that is applied during integration. Default: None.

definedonelementsngsolve.BitArray

Allows integration only on a set of facets that are marked True. Default: None.

time_orderint

Order in time that is used in the space-time integration. Default: time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations.

trefdouble

Turn spatial integration into space-time integration with fixed time tref.

downscaledouble

Downscale integration rule around facet.

Returns

FacetPatchDifferentialSymbol(VOL)

xfem.ddtref(func)

Evaluates the 2nd time derivative (w.r.t. the reference time interval) of a Space-Time function.

xfem.dmesh(mesh=None, *args, **kwargs)

Differential symbol for the integration over all elements in the mesh.

Parameters

meshngsolve.Mesh

The spatial mesh. The domain type of interest.

definedonRegion

Domain description on where the integrator is defined.

element_boundarybool

Integration on each element boundary. Default: False

element_vb{VOL, BND, BBND}

Integration on each element or its (B)boundary. Default: VOL (is overwritten by element_boundary if element_boundary is True)

skeletonbool

Integration over element-interface. Default: False.

deformationngsolve.GridFunction

Mesh deformation. Default: None.

definedonelementsngsolve.BitArray

Allows integration only on elements or facets (if skeleton=True) that are marked True. Default: None.

treffloat

turns a spatial integral resulting in spatial integration rules into a space-time quadrature rule with fixed reference time tref

Return

CutDifferentialSymbol(VOL)

xfem.dt(func)

Deprecated: use “dtref” instead

xfem.dtref(func)

Evaluates the time derivative (w.r.t. the reference time interval) of a Space-Time function.

xfem.dxtref(mesh, order=None, time_order=-1, **kwargs)

Differential symbol for the integration over all elements extruded by the reference interval [0,1] to space-time prisms.

Parameters

meshngsolve.Mesh

The spatial mesh. The domain type of interest.

orderint

Modify the order of the integration rule used.

definedonRegion

Domain description on where the integrator is defined.

vb{VOL, BND, BBND}

Integration on domains volume or boundary. Default: VOL (if combined with skeleton VOL means interior facets,

BND means boundary facets)

element_boundarybool

Integration on each element boundary. Default: False

element_vb{VOL, BND, BBND}

Integration on each element or its (B)boundary. Default: VOL (is overwritten by element_boundary if element_boundary is True)

skeletonbool

Integration over element-interface. Default: False.

deformationngsolve.GridFunction

Mesh deformation. Default: None.

definedonelementsngsolve.BitArray

Allows integration only on elements or facets (if skeleton=True) that are marked True. Default: None.

time_orderint

Order in time that is used in the space-time integration. Default: time_order=-1 means that no space-time rule will be applied. This is only relevant for space-time discretizations.

Return

CutDifferentialSymbol(VOL)

xfem.extend(func)

Evaluates the XFiniteElement-function independent of the level set domains.

Note: This will lead to the same behavior as the function that the XFiniteElement-function is based on.

xfem.extend_grad(func)

Evaluates the gradient of an XFiniteElement-function independent of the level set domains.

Note: This will lead to the same behavior as the function that the XFiniteElement-function is based on.

xfem.fix_t(obj, time, *args, **kwargs)

Deprecated: use “fix_tref” instead

xfem.fix_t_coef(obj, time, *args, **kwargs)
xfem.fix_t_gf(obj, time, *args, **kwargs)
xfem.fix_t_proxy(obj, time, *args, **kwargs)
xfem.fix_tref(obj, time, *args, **kwargs)

Takes a (possibly space-time) CoefficientFunction and fixes the temporal variable to time and return this as a new CoefficientFunction. Note that all operations are done on the unit interval it is the reference time that is fixed.

xfem.kappa(mesh, lset_approx, subdivlvl=0)

Tuple of ratios between negative/positive and full part of an element (deprecated).

xfem.neg(func)

Evaluates an XFiniteElement-function assuming a negative level set domain.

Note: This can lead to non-zero values also in domains where the level set function is non-negative.

xfem.neg_grad(func)

Evaluates the gradient of an XFiniteElement-function assuming a negative level set domain.

Note: This can lead to non-zero values also in domains where the level set function is non-negative.

xfem.pos(func)

Evaluates an XFiniteElement-function assuming a positive level set domain.

Note: This can lead to non-zero values also in domains where the level set function is non-positive.

xfem.pos_grad(func)

Evaluates the gradient of an XFiniteElement-function assuming a positive level set domain.

Note: This can lead to non-zero values also in domains where the level set function is non-positive.