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 / LICENSE
Last active February 11, 2026 14:19
MED format converter
Copyright 2026 Jørgen S. Dokken and Simula Research Laboratory
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION W
@jorgensd
jorgensd / script.py
Created November 19, 2025 13:59
Compute curvature at quadrature points
# Author Jorgen S. Dokken
# SPDX license identifier: MIT
import gmsh
import scifem
from mpi4py import MPI
import basix.ufl
import dolfinx.fem.petsc
import ufl
import numpy as np
@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