Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
818b85d
[docs] Add the LinearSmallStrainFEMForceField notebook
th-skam Oct 12, 2026
a0cdd9e
[verification] Add the LinearSmallStrainFEMForceField/Quadratic1D case
th-skam Oct 12, 2026
a80e971
[verification] Add the LinearSmallStrainFEMForceField/Quadratic2D_Qua…
th-skam Oct 12, 2026
061d27d
[verification] Add the LinearSmallStrainFEMForceField/Quadratic2D_Tri…
th-skam Oct 12, 2026
e0f0e67
[verification] Add the LinearSmallStrainFEMForceField/Quadratic3D_Hex…
th-skam Oct 12, 2026
3e6ffb0
[verification] Add the LinearSmallStrainFEMForceField/Quadratic3D_Tet…
th-skam Oct 12, 2026
7d23399
[verification] Add the LinearSmallStrainFEMForceField/Quartic2D_Quad …
th-skam Oct 12, 2026
4ea2d77
[verification] Add the LinearSmallStrainFEMForceField/Quartic2D_Tri case
th-skam Oct 12, 2026
fb9e2ea
[verification] Add the LinearSmallStrainFEMForceField/Quartic3D_Hexa …
th-skam Oct 12, 2026
f450011
[verification] Add the LinearSmallStrainFEMForceField/Quartic3D_Tetra…
th-skam Oct 12, 2026
1580ae9
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric1D…
th-skam Oct 12, 2026
6316c82
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric2D…
th-skam Oct 12, 2026
dc39ed2
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric2D…
th-skam Oct 12, 2026
260fc11
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric2D…
th-skam Oct 12, 2026
7bb3148
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric2D…
th-skam Oct 12, 2026
b05781d
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric2D…
th-skam Oct 12, 2026
24725ee
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric3D…
th-skam Oct 12, 2026
6fc75da
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric3D…
th-skam Oct 12, 2026
42f37f9
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric3D…
th-skam Oct 12, 2026
11a306c
[verification] Add the LinearSmallStrainFEMForceField/Trigonometric3D…
th-skam Oct 12, 2026
738f9ed
[docs] Update README
th-skam Oct 12, 2026
3bb3970
[validation] Adjust to new integration schemes
th-skam Nov 6, 2026
3cc29df
[all] Ignore validation results
th-skam Oct 12, 2026
36efe75
[fenics] Add the dolfinx grid meshes
th-skam Oct 12, 2026
ba51165
[fenics] Export the grid meshes
th-skam Oct 12, 2026
76e9c99
[fenics] Add the fenics package
th-skam Oct 12, 2026
9f52632
[sofa] Share the controllers with the validation suite
th-skam Oct 12, 2026
5aa79d0
[validation] Add the validation package
th-skam Oct 12, 2026
17252b9
[validation] Add the study package
th-skam Oct 12, 2026
6cb82b5
[validation] Add the comparison metrics
th-skam Oct 12, 2026
2f3ca74
[validation] Add the validation study
th-skam Oct 12, 2026
d6c9229
[validation] Add the validation runner
th-skam Oct 12, 2026
0276bda
[docs] Introduce the validation suite in the README
th-skam Oct 12, 2026
6758a2a
[validation] Add the LinearSmallStrainFEMForceField/1D/DistributedAxi…
th-skam Oct 12, 2026
4256daf
[validation] Add the LinearSmallStrainFEMForceField/2D/AxialCompressi…
th-skam Oct 12, 2026
f3afd09
[validation] Add the LinearSmallStrainFEMForceField/2D/DistributedTra…
th-skam Oct 12, 2026
fb5c3c2
[validation] Add the LinearSmallStrainFEMForceField/2D/ThreePointBend…
th-skam Oct 12, 2026
e1ffda5
[validation] Add the LinearSmallStrainFEMForceField/3D/AxialCompressi…
th-skam Oct 12, 2026
1b49ed6
[validation] Add the LinearSmallStrainFEMForceField/3D/DistributedTra…
th-skam Oct 12, 2026
79e6559
[validation] Add the LinearSmallStrainFEMForceField/3D/ThreePointBend…
th-skam Oct 12, 2026
1f10dd5
[docs] Add LinearSmallStrainFEMForceField doc
th-skam Oct 12, 2026
168b73b
[validation] Store solutions as well
th-skam Oct 12, 2026
e2b3a57
[validation] Make 3-point bending symmetric
th-skam Oct 12, 2026
922b100
[validation] Update linear doc
th-skam Oct 12, 2026
24afe0b
[docs] Add a generic validation doc
th-skam Oct 12, 2026
a6555c2
[validation] Improve plotting functionality
th-skam Oct 12, 2026
9fbc951
[common] Make force field and solver addition functions static and sh…
th-skam Oct 12, 2026
96bd52a
[validation] Axial compression on a circular beam
th-skam Oct 12, 2026
c1d5dcd
[validation] Add Circular beam transverse traction case
th-skam Oct 12, 2026
3e01121
[validation] Circular beam under torsion
th-skam Oct 12, 2026
36eb7a9
[validation] Increase loads to make solutions visible
th-skam Oct 12, 2026
1d193ad
[validation] Remove all reference solutions from FEniCS
th-skam Oct 12, 2026
07ad93e
[validation] Make plots in deformed shape
th-skam Oct 12, 2026
42ff309
[docs] Update IntroductionValidation.ipynb
th-skam Oct 12, 2026
bc43a6e
[docs] Update LineaerSmallStrainFEMForceField.ipynb
th-skam Oct 12, 2026
c227685
[validation] Re-generate references
th-skam Oct 12, 2026
7e0e10e
[verification] Adjust to integration schemes
th-skam Nov 6, 2026
cdc522e
[verification] Rotate manufactured problems, constant or varying
th-skam Oct 12, 2026
7408fc3
[verification] Export the rotation matrix
th-skam Oct 12, 2026
da67662
[sofa] Start the clamp from the rotated configuration
th-skam Oct 12, 2026
43b565c
[verification] Ramp the manufactured loads over excitation steps
th-skam Oct 12, 2026
990cfd3
[verification] Ramp the loads in the MMS scene
th-skam Oct 12, 2026
cd60bf2
[verification] Measure gradients in the unrotated frame
th-skam Oct 12, 2026
69c30de
[verification] Add the norm agreement study
th-skam Oct 12, 2026
e287d86
[verification] Parse rotation, excitation steps and comparison
th-skam Oct 12, 2026
b77ef78
[verification] Run CorotationalFEMForceField cases after their refere…
th-skam Oct 12, 2026
263f077
[docs] List CorotationalFEMForceField in the intro notebook
th-skam Oct 12, 2026
f92a811
[docs] Add the CorotationalFEMForceField notebook
th-skam Oct 12, 2026
0cd41bf
[docs] List CorotationalFEMForceField in the README
th-skam Oct 12, 2026
af557ef
[verification] Add the CorotationalFEMForceField/Trigonometric2D_Quad…
th-skam Oct 12, 2026
01cf248
[verification] Add the CorotationalFEMForceField/Trigonometric2D_Tri …
th-skam Oct 12, 2026
787611f
[verification] Add the CorotationalFEMForceField/Trigonometric3D_Hexa…
th-skam Oct 12, 2026
0416c62
[verification] Add the CorotationalFEMForceField/Trigonometric3D_Tetr…
th-skam Oct 12, 2026
2f956a0
[verification] Add the CorotationalFEMForceField/Trigonometric2D_Quad…
th-skam Oct 12, 2026
38d4c51
[all] Enable full nodal stress tensor with StressSourceTerm
th-skam Oct 13, 2026
8ccb272
[verification] Remove TODO related to symmetric nodal stress in case.py
th-skam Oct 13, 2026
06c861e
[verification] Apply full clamps on rotated boundaries for relevant f…
th-skam Oct 13, 2026
a38e2a7
[verification] Include 3D varying rotatino in CorotationalFEMForceFie…
th-skam Oct 14, 2026
8f0cc4a
[verification] Adjust cases to integration schemes
th-skam Nov 6, 2026
08380ac
[verification] update corotational tests with new sofa changes
th-skam Nov 6, 2026
0148415
[verification] Add the hyperelastic material laws
th-skam Oct 12, 2026
c49baf3
[sofa] Link the force field to its material component
th-skam Oct 12, 2026
780a638
[sofa] Pass the vector template to the grid force field
th-skam Oct 12, 2026
83a8000
[sofa] Pass the vector template to the tire force field
th-skam Oct 12, 2026
f8a1e87
[verification] Load the HyperElastic plugin in the MMS scene
th-skam Oct 12, 2026
3b33165
[verification] Parse the hyperelastic materials
th-skam Oct 12, 2026
6a8beea
[verification] Run HyperelasticityFEMForceField cases
th-skam Oct 12, 2026
34e20e2
[docs] List HyperelasticityFEMForceField in the intro notebook
th-skam Oct 12, 2026
d8ddd09
[docs] List HyperelasticityFEMForceField in the README
th-skam Oct 12, 2026
d3a6b0b
[verification] Add the HyperelasticityFEMForceField/MooneyRivlin/Trig…
th-skam Oct 12, 2026
84c85b9
[verification] Add the HyperelasticityFEMForceField/MooneyRivlin/Trig…
th-skam Oct 12, 2026
00ee875
[verification] Add the HyperelasticityFEMForceField/MooneyRivlin/Trig…
th-skam Oct 12, 2026
771c107
[verification] Add the HyperelasticityFEMForceField/MooneyRivlin/Trig…
th-skam Oct 12, 2026
69df305
[verification] Add the HyperelasticityFEMForceField/NeoHookean/Trigon…
th-skam Oct 12, 2026
8859bef
[verification] Add the HyperelasticityFEMForceField/NeoHookean/Trigon…
th-skam Oct 12, 2026
228e162
[verification] Add the HyperelasticityFEMForceField/NeoHookean/Trigon…
th-skam Oct 12, 2026
9ba0986
[verification] Add the HyperelasticityFEMForceField/NeoHookean/Trigon…
th-skam Oct 12, 2026
0f2be0a
[verification] Add the HyperelasticityFEMForceField/Ogden/Trigonometr…
th-skam Oct 12, 2026
51c7742
[verification] Add the HyperelasticityFEMForceField/Ogden/Trigonometr…
th-skam Oct 12, 2026
776a3d9
[verification] Add the HyperelasticityFEMForceField/Ogden/Trigonometr…
th-skam Oct 12, 2026
a16a6bc
[verification] Add the HyperelasticityFEMForceField/Ogden/Trigonometr…
th-skam Oct 12, 2026
67c693e
[verification] Add the HyperelasticityFEMForceField/Ogden/Trigonometr…
th-skam Oct 12, 2026
4a69fe6
[verification] Add the HyperelasticityFEMForceField/SaintVenantKirchh…
th-skam Oct 12, 2026
41aed5c
[verification] Add the HyperelasticityFEMForceField/SaintVenantKirchh…
th-skam Oct 12, 2026
dc613b8
[verification] Add the HyperelasticityFEMForceField/SaintVenantKirchh…
th-skam Oct 12, 2026
4d25ba0
[verification] Add the HyperelasticityFEMForceField/SaintVenantKirchh…
th-skam Oct 12, 2026
4ae4df5
[common] Move materials.py to common
th-skam Oct 13, 2026
34fe6a1
[common] Add sympy to UFL conversions for re-using materials in FEniCS
th-skam Oct 13, 2026
dd44821
[validation] Adjust study to include generic dictionary keyes
th-skam Oct 13, 2026
911eff5
[validation] Add Circular beam in torsion for hyperelastic materials
th-skam Oct 13, 2026
98cfc62
[validation] Generate references for FEniCS
th-skam Oct 13, 2026
6ed6ed8
[validation] Add a LoadRamp controller for ramping up load in steps
th-skam Oct 13, 2026
999b21b
[validation] Add Distributed Transverse Traction case
th-skam Oct 13, 2026
ad66c70
[validation] Add ThreePointBending case
th-skam Oct 13, 2026
340516d
[validation] Add DistributedTransverseTraction in 3D case
th-skam Oct 13, 2026
d7f78f9
[validation] Add ThreePointBending in 3D case
th-skam Oct 13, 2026
f111e7b
[validation] Generate FEniCS references
th-skam Oct 13, 2026
6ac2e9d
[validation] Enforce 3-degree rule for hexahedra on FEniCS scripts
th-skam Oct 13, 2026
66d324b
[validation] Add similarity references for hexahedral quadrature rule…
th-skam Oct 13, 2026
18bfda2
[validation] Apply custom SOFA quad rule
th-skam Oct 13, 2026
c091cc0
[validation] Store FEniCS references
th-skam Oct 13, 2026
0ced426
[validation] Add cruciform geometry test
th-skam Oct 13, 2026
e1028f2
[validation] Generate references for cruciform biaxial test
th-skam Oct 13, 2026
42a20ef
[docs] Update README
th-skam Oct 13, 2026
5683018
[docs] Add Notebook for Hyperelasticity
th-skam Oct 13, 2026
eb6fb61
[validation] Increase thickness of cruciform geometry
th-skam Oct 13, 2026
0f32e06
[validation] Add references for thicker cruciform
th-skam Oct 13, 2026
3158736
[verification] Add non-symmetric example for hyperelasticity
th-skam Oct 14, 2026
fc5e46a
[verification] Adjust to new integration schemes
th-skam Nov 6, 2026
bf65b5e
[verification] Use symbols for manufactured solution parameters
th-skam Oct 13, 2026
b77e370
[common] Use symbols for the material parameters
th-skam Oct 13, 2026
a8fd190
[verification] Pass symbols to manufactured problem class
th-skam Oct 13, 2026
8fc9215
[common] replace symbol with value on the FEniCS side
th-skam Oct 13, 2026
b1e131e
[docs] Remove rounded now that symbols are being in use
th-skam Oct 13, 2026
c38bcdd
[common] Rename stress to fpk_stress and add Cauchy stress function
th-skam Oct 14, 2026
58f7f24
[verification] Add Cauchy stress measurement in metrics.py
th-skam Oct 14, 2026
476fd15
[verification] Add the Cauchy stress evaluation in study.py
th-skam Oct 14, 2026
0eab6b8
[docs] Update docs with cauchy stress computation
th-skam Oct 14, 2026
16a2f97
[verification] Add Cauchy stress evaluation in all cases
th-skam Oct 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

# a run's own output
verification/results/

# a validation run's own output
validation/**/results/
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,45 @@
# Verification-Validation
Initially funded by TIRREX, this repository proposes a framework for verification and validation. It relies on both manufactured solutions and comparison with alternative simulation technologies. This work therefore proves the reliability and compliance of the SOFA models & algorithms.

## Verification
## Verification and validation

**Verification** uses the method of manufactured solutions: an exact displacement is chosen, the
loads that produce it are derived, and SOFA solves the problem on a sequence of refined meshes.
The error must shrink at the rate the discretisation predicts. Covered force fields:
- `LinearSmallStrainFEMForceField`
- `LinearSmallStrainFEMForceField` [`verification/docs/LinearSmallStrainFEMForceField.ipynb`](verification/docs/LinearSmallStrainFEMForceField.ipynb)
- `CorotationalFEMForceField` [`verification/docs/CorotationalFEMForceField.ipynb`](verification/docs/CorotationalFEMForceField.ipynb)
- `HyperelasticityFEMForceField` covering the following material laws:
- `Saint Venant-Kirchhoff`
- `Neo-Hookean`
- `Mooney-Rivlin`
- `Ogden`

To get started, read [`verification/docs/IntroductionMMS.ipynb`](verification/docs/IntroductionMMS.ipynb): it presents the method and builds one verification study step by step, from the manufactured solution to the input file the suite runs.

**Validation** compares SOFA against reference results computed with FEniCS, and against an
analytic solution where one exists. Covered force fields:
- `LinearSmallStrainFEMForceField`
- `HyperelasticityFEMForceField` [`validation/docs/HyperelasticityFEMForceField.ipynb`](validation/docs/HyperelasticityFEMForceField.ipynb) covering the following material laws:
- `Saint Venant-Kirchhoff`
- `Neo-Hookean`
- `Mooney-Rivlin`

## Layout

```
common/ shared code: geometry and SOFA helpers
common/ code shared by both suites: geometry, SOFA and FEniCS helpers
verification/ the verification suite
cases/<Component>/**.json one test case per file
validation/ the validation suite
cases/<Component>/<dim>D/<Case>/ sofa_scene.py, fenics_scene.py, case.json,
reference_solution.json, analytic_solution.py (optional)
```

## Requirements

- SOFA with SofaPython3
- numpy, sympy, matplotlib
- FEniCSx (dolfinx, petsc4py, mpi4py), only to regenerate validation references with `--fenics`

## Running

Expand All @@ -31,7 +49,13 @@ python verification/run.py --all # every test case, then one summ
python verification/run.py --clean # delete previous results
```

Results are written to `verification/results/`.
```bash
python validation/run.py <path-to-case-folder> # one case
python validation/run.py --all # every case
python validation/run.py --all --fenics # regenerate the FEniCS references first
```

Results are written to `verification/results/` and `validation/results/`.

To inspect one mesh of a case in the SOFA GUI, the runner also acts as a SOFA scene file:

Expand Down
2 changes: 2 additions & 0 deletions common/fenics/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .prefabs import GridMesh, BarMesh, BeamMesh
from .materials import strain_energy_density
17 changes: 17 additions & 0 deletions common/fenics/materials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""Converts the sympy material laws of common/materials.py into UFL."""

import sympy as sp
import ufl

from ..materials import MATERIALS


def strain_energy_density(material, gradient):
"""Converts the strain energy density of `material` from sympy to UFL, in the displacement gradient `gradient`."""
dim = gradient.ufl_shape[0]
law = MATERIALS[material['type']]
symbols = sp.Matrix(dim, dim, lambda i, j: sp.Symbol(f"G_{i}_{j}"))
constitutive_law = law(*law.get_material_parameters(material, dim))
energy = constitutive_law.energy_density(symbols).xreplace(constitutive_law.parameter_values)
return sp.lambdify(list(symbols), energy, modules=[{'log': ufl.ln}])(
*[gradient[i, j] for i in range(dim) for j in range(dim)])
1 change: 1 addition & 0 deletions common/fenics/prefabs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .grid import GridMesh, BarMesh, BeamMesh
133 changes: 133 additions & 0 deletions common/fenics/prefabs/grid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
"""FEniCS (dolfinx) meshes built from tool-agnostic Geometry."""

import basix.ufl
import numpy as np
import ufl
from dolfinx import mesh as dmesh
from mpi4py import MPI


class GridMesh:
"""A dolfinx mesh built from a Grid geometry, matching its extents and cell resolution.

dolfinx renumbers a mesh's nodes on construction, so a direct comparison with a SOFA solution
is not readily available. `inverse` undoes this remap allowing the comparison to happen.
The inversion only holds for a degree-1 Lagrange space, where each DOF is one mesh node.
"""

def __init__(self, geometry, resolution):
self.geometry = geometry
self.resolution = resolution
self.inverse = None

def build(self, comm=MPI.COMM_WORLD):
raise NotImplementedError


class BarMesh(GridMesh):
"""A 1D interval mesh matching a Bar1D geometry."""

def build(self, comm=MPI.COMM_WORLD):
cells = self.resolution[0] - 1
mesh = dmesh.create_interval(comm, cells, [0.0, self.geometry.length])
self.inverse = np.argsort(mesh.geometry.input_global_indices)
return mesh


class BeamMesh(GridMesh):
"""A dolfinx mesh matching a Beam2D or Beam3D geometry, as SOFA would mesh it: quadrilaterals
or triangles in 2D, hexahedra or tetrahedra in 3D.

The nodes are ordered i + nx*(j + ny*k) like SOFA's RegularGridTopology (2D: i + nx*j). In 2D,
each quad splits in two triangles along a diagonal; with `swapping`, this diagonal alternates
per quad in a checkerboard pattern, else every quad splits the same way. In 3D, each
hexahedron splits into 6 tets, following SOFA's Hexa2TetraTopologicalMapping: with `swapping`,
a cell's corners are mirrored along X/Y/Z depending on its grid position before the tet
pattern is applied; without it, every hexahedron splits the same way.
"""

# SOFA's Hexahedron corner convention (n0..n7) and edge/tet patterns, from
# sofa::geometry::Hexahedron and Hexa2TetraTopologicalMapping.cpp.
SOFA_CORNERS = ((0, 0, 0), (1, 0, 0), (1, 1, 0), (0, 1, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1))
X_EDGES = ((0, 1), (4, 5), (3, 2), (7, 6))
Y_EDGES = ((4, 7), (5, 6), (1, 2), (0, 3))
Z_EDGES = ((4, 0), (5, 1), (6, 2), (7, 3))
NON_SWAPPED = ((0, 5, 1, 6), (0, 1, 3, 6), (1, 3, 6, 2), (6, 3, 0, 7), (6, 7, 0, 5), (7, 5, 4, 0))
SWAPPED = ((0, 5, 6, 1), (0, 1, 6, 3), (1, 3, 2, 6), (6, 3, 7, 0), (6, 7, 5, 0), (7, 5, 0, 4))
# Hex cells need corners in basix's (0,0,0)..(1,1,1) lexicographic order, not SOFA's.
BASIX_ORDER = (0, 1, 3, 2, 4, 5, 7, 6)

def __init__(self, geometry, resolution, element='quad', swapping=True):
super().__init__(geometry, resolution)
self.element = element
self.swapping = swapping

def build(self, comm=MPI.COMM_WORLD):
if self.geometry.dim == 2:
nx, ny = self.resolution[0], self.resolution[1]
dx, dy = self.geometry.length / (nx - 1), self.geometry.width / (ny - 1)

def node(i, j):
return i + nx * j

points = np.array([[i * dx, j * dy] for j in range(ny) for i in range(nx)])

cells = []
for j in range(ny - 1):
for i in range(nx - 1):
p0, p1, p2, p3 = node(i, j), node(i + 1, j), node(i + 1, j + 1), node(i, j + 1)
if self.element == 'quad':
cells.append([p0, p1, p3, p2])
else:
if self.swapping and (i ^ j) & 1:
cells += [[p0, p1, p3], [p2, p3, p1]]
else:
cells += [[p1, p2, p0], [p3, p0, p2]]

cell_type = "quadrilateral" if self.element == 'quad' else "triangle"
cell_element = basix.ufl.element("Lagrange", cell_type, 1, shape=(2,))
mesh = dmesh.create_mesh(comm, np.array(cells), points, ufl.Mesh(cell_element))
self.inverse = np.argsort(mesh.geometry.input_global_indices)
return mesh

nx, ny, nz = self.resolution[0], self.resolution[1], self.resolution[2]
dx, dy, dz = (self.geometry.length / (nx - 1), self.geometry.width / (ny - 1),
self.geometry.height / (nz - 1))

def node(i, j, k):
return i + nx * (j + ny * k)

points = np.array([[i * dx, j * dy, k * dz]
for k in range(nz) for j in range(ny) for i in range(nx)])

cells = []
for k in range(nz - 1):
for j in range(ny - 1):
for i in range(nx - 1):
corners = [node(i + di, j + dj, k + dk) for di, dj, dk in self.SOFA_CORNERS]
if self.element == 'hexa':
cells.append([corners[c] for c in self.BASIX_ORDER])
continue

swapped = False
if self.swapping:
if i % 2 == 0:
for v0, v1 in self.X_EDGES:
corners[v0], corners[v1] = corners[v1], corners[v0]
swapped = not swapped
if j % 2 == 1:
for v0, v1 in self.Y_EDGES:
corners[v0], corners[v1] = corners[v1], corners[v0]
swapped = not swapped
if k % 2 == 1:
for v0, v1 in self.Z_EDGES:
corners[v0], corners[v1] = corners[v1], corners[v0]
swapped = not swapped
pattern = self.SWAPPED if swapped else self.NON_SWAPPED
cells += [[corners[c] for c in tet] for tet in pattern]

cell_type = "hexahedron" if self.element == 'hexa' else "tetrahedron"
cell_element = basix.ufl.element("Lagrange", cell_type, 1, shape=(3,))
mesh = dmesh.create_mesh(comm, np.array(cells), points, ufl.Mesh(cell_element))
self.inverse = np.argsort(mesh.geometry.input_global_indices)
return mesh
Loading