Skip to content

Instantly share code, notes, and snippets.

View jorgensd's full-sized avatar

Jørgen Schartum Dokken jorgensd

View GitHub Profile
@jorgensd
jorgensd / script.py
Last active May 13, 2025 13:49
Nullspace extraction using mumps
from mpi4py import MPI
try:
from petsc4py import PETSc
import dolfinx
if not dolfinx.has_petsc:
print("This demo requires DOLFINx to be compiled with PETSc enabled.")
exit(0)
@jorgensd
jorgensd / minimal_example.py
Created May 13, 2025 11:34
Partitioned T-joint
import dolfinx
import ufl
import basix
import numpy as np
from mpi4py import MPI
comm = MPI.COMM_WORLD
# (3)
# |
@jorgensd
jorgensd / example.py
Created March 25, 2025 11:45
Nanson's formula + quadrature point cloud visualization
from mpi4py import MPI
import numpy as np
import dolfinx
import ufl
import basix.ufl
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1, (2,)))
u = dolfinx.fem.Function(V)
@jorgensd
jorgensd / script.py
Created March 12, 2025 13:09
Hermite coordinate element
"""
Hermite as coordinate element in DOLFINx
Author: Jørgen S. Dokken
SPDX License identifier: MIT
"""
from mpi4py import MPI
import dolfinx
import basix.ufl
from dataclasses import dataclass
import shutil
from mpi4py import MPI
from petsc4py import PETSc
import dolfinx.fem.petsc
from dolfinx_external_operator import (
FEMExternalOperator,
evaluate_external_operators,
evaluate_operands,
@jorgensd
jorgensd / create_cube_dolfinx.py
Last active January 23, 2025 15:54
Refine troublesome cell
from mpi4py import MPI
import dolfinx
import numpy as np
from pathlib import Path
cube = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, nx=3, ny=3, nz=3)
def left_cells(x):
@jorgensd
jorgensd / script.py
Created October 28, 2024 10:51
Consistent orientation of bifurcation integrals
# Consistently orient jump integrals on a mesh with a bifurcation
#
# The idea of this demo is to say that the jump at a bifurcation with three cells should be:
# u(0) - u(1) - u(2) where u(0) is taken from the cell with the lowest value, while u(1) and u(2) are taken from the two other cells.
#
# \ /
# \ u1 / u2
# \ /
# \ /
# \ /
@jorgensd
jorgensd / CMakeLists.txt
Last active September 18, 2024 12:40
Prototype real space
# This file was generated by running
#
# python cmake/scripts/generate-cmakefiles.py from dolfinx/cpp
#
cmake_minimum_required(VERSION 3.19)
set(PROJECT_NAME demo_real_space)
project(${PROJECT_NAME} LANGUAGES C CXX)
# Set C++20 standard
@jorgensd
jorgensd / script.py
Last active August 20, 2024 09:17
Submesh `ds` integral
# Illustration of submesh facet integral with parent coefficient
# Author: Jørgen S. Dokken
# SPDX-License-Identifier: MIT
def transfer_meshtags_to_submesh(
mesh, entity_tag, submesh, sub_vertex_to_parent, sub_cell_to_parent
):
"""
Transfer a meshtag from a parent mesh to a sub-mesh.
@jorgensd
jorgensd / mwe_minimal_mesh.py
Last active March 12, 2025 12:34
Read mixed mesh in DOLFINx from VTKHDF
# Author: Jørgen S. Dokken
# SPDX-License-Identifier: MIT
import numpy as np
from mesh_converter import Mesh, CellType, vtk
points = np.array(
[[0.0, 0.0], [1.0, 0.0], [1.0, 1.0], [0.0, 1.0], [2.0, 0.0],
[2., 2.], [3., 2.],[3,3],[2.5,2],[3, 2.5], [2.3, 2.7]], dtype=np.float64
)