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 / bash_commands.md
Last active February 27, 2025 08:13
Commands for bash file for rebuilding dolfinx/dolfinx-mpc

Bash commands

compile_demo(){
    cmake -G Ninja -B build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION} -DCMAKE_BUILD_TYPE=${DOLFINX_CMAKE_BUILD_TYPE} -DCMAKE_CXX_FLAGS="${DOLFINX_CMAKE_CXX_FLAGS}" . && ninja -j8 -C build-dir-${DOLFINX_MODE}${DOLFINX_PRECISION}
}

rebuild(){
    BASEDIR=$(pwd)
    cd /root/shared/"$1"
@jorgensd
jorgensd / generate_team30_meshes.py
Last active March 1, 2022 23:15
Team 30 single phase engine with GMSH Python API
import gmsh
import numpy as np
from mpi4py import MPI
import argparse
rank = MPI.COMM_WORLD.rank
# http://www.compumag.org/jsite/images/stories/TEAM/problem30a.pdf
r1 = 0.02
@jorgensd
jorgensd / two_tetrahedra.py
Last active January 25, 2023 11:58
Script for creating a two tetrahedra mesh in DOLFINx
import dolfinx
import numpy as np
import ufl
from mpi4py import MPI
gdim = 3
shape = "tetrahedron"
degree = 1
@jorgensd
jorgensd / mesh_checker.py
Last active June 20, 2024 11:39
Mesh topology verification, testing if there are cells that are only connected through edges or vertices
# Copyright (C) 2021 Chris Richardson, Jørgen S. Dokken
#
# SPDX-License-Identifier: LGPL-3.0-or-later
import numba
import networkx
from collections import defaultdict
import h5py
import numpy as np
import datetime
@jorgensd
jorgensd / plot_function.py
Created June 25, 2021 10:33
Plotting of a dolfin-x function
import dolfinx.plot
import pyvista
def plot(u, filename="figure.png"):
V = u.function_space
topology, cell_types = dolfinx.plot.create_vtk_topology(V)
# As we are dealing with a vector field, we reshape the underlying dof array to accommedate for the three dimensional space
num_dofs = V.dofmap.index_map.size_local + V.dofmap.index_map.num_ghosts
geometry = V.tabulate_dof_coordinates()
@jorgensd
jorgensd / run.sh
Last active September 30, 2021 08:22
Spack on ubuntu 18.04
docker run -ti -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v $(pwd):/root/shared -w /root/shared --name=test-spack ubuntu:18.04
cd ..
apt-get update && apt-get install -y git
git clone https://github.com/spack/spack.git
apt-get install -y python
apt-get install -y build-essential
apt-get install -y make zip
. ./spack/share/spack/setup-env.sh
spack install [email protected]
@jorgensd
jorgensd / convert_masters.cpp
Last active October 26, 2021 22:15
MPC convert masters to local index
/// Given the global indices of the master dofs in the multi point constraint,
/// create a new index map where all masters that where not previously ghosted
/// are added as ghosts. This function also converts the global master indices
/// @param[in] global_masters The list of master dofs (global index)
/// @param[in] offsets The offsets of the masters (relative to the slave
/// index)
void convert_masters_to_local_index(std::vector<std::int64_t>& global_masters,
std::vector<std::int32_t> offsets)
{
dolfinx::common::Timer timer("~MPC: Create new index map a");
@jorgensd
jorgensd / dof_to_vertex_map.py
Created November 11, 2021 23:00
Code illustrating that the vertex to dof map is an identity map for spaces where the coordinate element match the finite element of the function space
# Copyright (C) 2021 Jørgen S. Dokken
#
# SPDX-License-Identifier: MIT
#
# Code illustrating that the vertex to dof map for a vector CG-1 space is the identity
import dolfinx.io
from IPython import embed
import dolfinx
from mpi4py import MPI
@jorgensd
jorgensd / submesh_problem.py
Created April 5, 2022 15:06
Solve a problem of parts of a unit square mesh
import dolfinx
from mpi4py import MPI
import ufl
import numpy as np
from petsc4py.PETSc import ScalarType
def transfer_submesh_data(u_parent: dolfinx.fem.Function, u_sub: dolfinx.fem.Function,
sub_to_parent_cells: np.ndarray, inverse: bool = False):
"""
@jorgensd
jorgensd / Dockerfile
Last active February 16, 2023 12:49
Simple DASH AIS graphical interface
FROM ubuntu:22.04
ENV DEB_PYTHON_INSTALL_LAYOUT=deb_system
RUN apt-get update && \
apt-get install -q -y python3-pip
RUN python3 -m pip install --upgrade pip setuptools
RUN python3 -m pip install vaex dash numpy