Skip to content

Commit

Permalink
Merge pull request #89 from jorgensd/dokken/v0.9.0
Browse files Browse the repository at this point in the history
v0.9.0
  • Loading branch information
kumiori authored Nov 25, 2024
2 parents 0f79d74 + dd7c546 commit 6868c5c
Show file tree
Hide file tree
Showing 51 changed files with 1,921 additions and 1,875 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/workflow_dolfinx_container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ on:
jobs:
set-up-computing-environment:
runs-on: ubuntu-latest
container: ghcr.io/fenics/dolfinx/lab:v0.7.2
container: ghcr.io/fenics/dolfinx/lab:nightly
# container: ghcr.io/fenics/dolfinx/lab:v0.7.2

steps:
- name: Checkout repository
Expand All @@ -25,4 +26,4 @@ jobs:
run: pytest -v test/test_1d.py

- name: Run tests
run: cd test && pytest -v .
run: cd test && pytest -v .
18 changes: 10 additions & 8 deletions demo/demo_bifurcation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import dolfinx
import dolfinx.mesh
import dolfinx.plot
import basix.ufl

import numpy as np
import pandas as pd
import petsc4py
Expand Down Expand Up @@ -74,10 +76,10 @@
file.write_mesh(mesh)

# Function spaces
element_u = ufl.VectorElement("Lagrange", mesh.ufl_cell(), degree=1, dim=tdim)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1, shape=(tdim,))
V_u = FunctionSpace(mesh, element_u)

element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
V_alpha = FunctionSpace(mesh, element_alpha)

# Define the state
Expand Down Expand Up @@ -110,7 +112,7 @@
alpha_ub.interpolate(lambda x: np.ones_like(x[0]))

for f in [zero_u, zero_alpha, u_, alpha_lb, alpha_ub]:
f.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
f.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

bc_u_left = dirichletbc(np.array([0, 0], dtype=PETSc.ScalarType), dofs_u_left, V_u)

Expand All @@ -127,8 +129,8 @@
)
]

set_bc(alpha_ub.vector, bcs_alpha)
alpha_ub.vector.ghostUpdate(
set_bc(alpha_ub.x.petsc_vec, bcs_alpha)
alpha_ub.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down Expand Up @@ -170,11 +172,11 @@

for i_t, t in enumerate(loads):
u_.interpolate(lambda x: (t * np.ones_like(x[0]), np.zeros_like(x[1])))
u_.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
u_.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

# update the lower bound
alpha.vector.copy(alpha_lb.vector)
alpha_lb.vector.ghostUpdate(
alpha.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
alpha_lb.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
14 changes: 7 additions & 7 deletions demo/demo_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from irrevolutions.models import ElasticityModel
from irrevolutions.solvers import SNESSolver as ElasticitySolver
from irrevolutions.utils.viz import plot_vector

import basix.ufl
logging.basicConfig(level=logging.INFO)


Expand Down Expand Up @@ -66,10 +66,10 @@
file.write_mesh(mesh)

# Function spaces
element_u = ufl.VectorElement("Lagrange", mesh.ufl_cell(), degree=1, dim=tdim)
V_u = dolfinx.fem.FunctionSpace(mesh, element_u)
V_ux = dolfinx.fem.FunctionSpace(
mesh, ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1, shape=(tdim,))
V_u = dolfinx.fem.functionspace(mesh, element_u)
V_ux = dolfinx.fem.functionspace(
mesh,basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
)

# Define the state
Expand All @@ -96,7 +96,7 @@
ux_.interpolate(lambda x: np.ones_like(x[0]))

for f in [zero_u, ux_]:
f.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
f.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

bcs_u = [
dolfinx.fem.dirichletbc(zero_u, dofs_u_left),
Expand Down Expand Up @@ -133,7 +133,7 @@

for i_t, t in enumerate(loads):
u_.interpolate(lambda x: (t * np.ones_like(x[0]), 0 * np.ones_like(x[1])))
u_.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
u_.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

logging.info(f"-- Solving for t = {t:3.2f} --")

Expand Down
18 changes: 9 additions & 9 deletions demo/demo_traction.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from irrevolutions.models import DamageElasticityModel as Brittle
from irrevolutions.utils.plots import plot_energies, plot_force_displacement
from irrevolutions.utils.viz import plot_scalar, plot_vector

import basix.ufl
logging.basicConfig(level=logging.INFO)


Expand Down Expand Up @@ -79,10 +79,10 @@
file.write_mesh(mesh)

# Function spaces
element_u = ufl.VectorElement("Lagrange", mesh.ufl_cell(), degree=1, dim=tdim)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1, shape=(tdim,))
V_u = FunctionSpace(mesh, element_u)

element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
V_alpha = FunctionSpace(mesh, element_alpha)

# Define the state
Expand Down Expand Up @@ -115,7 +115,7 @@
alpha_ub.interpolate(lambda x: np.ones_like(x[0]))

for f in [zero_u, zero_alpha, u_, alpha_lb, alpha_ub]:
f.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
f.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

bc_u_left = dirichletbc(np.array([0, 0], dtype=PETSc.ScalarType), dofs_u_left, V_u)

Expand All @@ -134,8 +134,8 @@

bcs_alpha = []

set_bc(alpha_ub.vector, bcs_alpha)
alpha_ub.vector.ghostUpdate(
set_bc(alpha_ub.x.petsc_vec, bcs_alpha)
alpha_ub.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down Expand Up @@ -177,11 +177,11 @@

for i_t, t in enumerate(loads):
u_.interpolate(lambda x: (t * np.ones_like(x[0]), np.zeros_like(x[1])))
u_.vector.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
u_.x.petsc_vec.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)

# update the lower bound
alpha.vector.copy(alpha_lb.vector)
alpha_lb.vector.ghostUpdate(
alpha.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
alpha_lb.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
6 changes: 3 additions & 3 deletions demo/demo_vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
V = FunctionSpace(mesh, ("CG", 1))

zero = Function(V)
with zero.vector.localForm() as loc:
with zero.x.petsc_vec.localForm() as loc:
loc.set(0.0)

one = Function(V)
with one.vector.localForm() as loc:
with one.x.petsc_vec.localForm() as loc:
loc.set(1.0)


Expand Down Expand Up @@ -94,7 +94,7 @@ def monitor(snes, its, fgnorm):


solver_snes.setMonitor(monitor)
solver_snes.solve(None, u.vector)
solver_snes.solve(None, u.x.petsc_vec)
# solver_snes.view()

prefix = os.path.join("output", "test-vi")
Expand Down
17 changes: 9 additions & 8 deletions playground/benchmark-umut-at2/vs_analytics_at2.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from mpi4py import MPI
from petsc4py import PETSc
from pyvista.utilities import xvfb
import basix.ufl

from irrevolutions.algorithms.am import HybridSolver
from irrevolutions.algorithms.so import BifurcationSolver, StabilitySolver
Expand Down Expand Up @@ -145,11 +146,11 @@ def run_computation(parameters, storage=None):
file.write_mesh(mesh)

# Functional Setting
element_u = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)

V_u = dolfinx.fem.FunctionSpace(mesh, element_u)
V_alpha = dolfinx.fem.FunctionSpace(mesh, element_alpha)
V_u = dolfinx.fem.functionspace(mesh, element_u)
V_alpha = dolfinx.fem.functionspace(mesh, element_alpha)

u = dolfinx.fem.Function(V_u, name="Displacement")
dolfinx.fem.Function(V_u, name="BoundaryDisplacement")
Expand Down Expand Up @@ -192,7 +193,7 @@ def run_computation(parameters, storage=None):
u_zero.interpolate(lambda x: eps_t / 2.0 * (2 * x[0] - Lx))

for f in [zero_u, u_zero, alpha_lb, alpha_ub]:
f.vector.ghostUpdate(
f.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down Expand Up @@ -234,13 +235,13 @@ def run_computation(parameters, storage=None):
eps_t.value = t

u_zero.interpolate(lambda x: eps_t / 2.0 * (2 * x[0] - Lx))
u_zero.vector.ghostUpdate(
u_zero.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

# update the lower bound
alpha.vector.copy(alpha_lb.vector)
alpha_lb.vector.ghostUpdate(
alpha.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
alpha_lb.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
15 changes: 8 additions & 7 deletions playground/benchmark-umut-at2/vs_analytics_at2_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from mpi4py import MPI
from petsc4py import PETSc
from pyvista.utilities import xvfb
import basix.ufl

from irrevolutions.algorithms.am import HybridSolver
from irrevolutions.algorithms.so import BifurcationSolver, StabilitySolver
Expand Down Expand Up @@ -101,11 +102,11 @@ def run_computation(parameters, storage=None):
file.write_mesh(mesh)

# Functional Setting
element_u = ufl.VectorElement("Lagrange", mesh.ufl_cell(), degree=1, dim=tdim)
element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1, shape=(tdim,))
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)

V_u = dolfinx.fem.FunctionSpace(mesh, element_u)
V_alpha = dolfinx.fem.FunctionSpace(mesh, element_alpha)
V_u = dolfinx.fem.functionspace(mesh, element_u)
V_alpha = dolfinx.fem.functionspace(mesh, element_alpha)

u = dolfinx.fem.Function(V_u, name="Displacement")
dolfinx.fem.Function(V_u, name="BoundaryDisplacement")
Expand Down Expand Up @@ -145,7 +146,7 @@ def run_computation(parameters, storage=None):
# eps_t = dolfinx.fem.Constant(mesh, np.array(1., dtype=PETSc.ScalarType))

for f in [zero_u, u_zero, alpha_lb, alpha_ub]:
f.vector.ghostUpdate(
f.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down Expand Up @@ -194,8 +195,8 @@ def run_computation(parameters, storage=None):
tau.value = t

# update the lower bound
alpha.vector.copy(alpha_lb.vector)
alpha_lb.vector.ghostUpdate(
alpha.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
alpha_lb.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
24 changes: 12 additions & 12 deletions playground/pizza-notch/pizza-notch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
history_data, set_vector_to_constant)
from irrevolutions.utils.lib import _local_notch_asymptotic
from irrevolutions.utils.viz import plot_mesh, plot_scalar, plot_vector

import basix.ufl
description = """We solve here a basic 2d of a notched specimen.
Imagine a dinner a pizza which is missing a slice, and lots of hungry friends
that pull from the sides of the pizza. Will a real pizza will break at the centre?
Expand Down Expand Up @@ -85,10 +85,10 @@ def run_computation(parameters, storage):
hashlib.md5(str(parameters).encode("utf-8")).hexdigest()

# Function spaces
element_u = ufl.VectorElement("Lagrange", mesh.ufl_cell(), degree=1, dim=2)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1, shape=(2,))
V_u = FunctionSpace(mesh, element_u)

element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
V_alpha = FunctionSpace(mesh, element_alpha)

# Define the state
Expand Down Expand Up @@ -135,7 +135,7 @@ def run_computation(parameters, storage):
alpha_ub.interpolate(lambda x: np.ones_like(x[0]))

for f in [alpha_lb, alpha_ub]:
f.vector.ghostUpdate(
f.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand All @@ -149,8 +149,8 @@ def run_computation(parameters, storage):
)
]
bcs_alpha = []
set_bc(alpha_ub.vector, bcs_alpha)
alpha_ub.vector.ghostUpdate(
set_bc(alpha_ub.x.petsc_vec, bcs_alpha)
alpha_ub.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand All @@ -162,10 +162,10 @@ def run_computation(parameters, storage):
u_ub = Function(V_u, name="displacement upper bound")
alpha_lb = Function(V_alpha, name="damage lower bound")
alpha_ub = Function(V_alpha, name="damage upper bound")
set_vector_to_constant(u_lb.vector, PETSc.NINFINITY)
set_vector_to_constant(u_ub.vector, PETSc.PINFINITY)
set_vector_to_constant(alpha_lb.vector, 0)
set_vector_to_constant(alpha_ub.vector, 1)
set_vector_to_constant(u_lb.x.petsc_vec, PETSc.NINFINITY)
set_vector_to_constant(u_ub.x.petsc_vec, PETSc.PINFINITY)
set_vector_to_constant(alpha_lb.x.petsc_vec, 0)
set_vector_to_constant(alpha_ub.x.petsc_vec, 1)

model = Brittle(parameters["model"])

Expand Down Expand Up @@ -205,8 +205,8 @@ def run_computation(parameters, storage):
)

# update the lower bound
alpha.vector.copy(alpha_lb.vector)
alpha_lb.vector.ghostUpdate(
alpha.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
alpha_lb.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
13 changes: 7 additions & 6 deletions playground/rayleigh/rayleigh.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
from pathlib import Path

import basix.ufl
import dolfinx
import matplotlib.pyplot as plt
import numpy as np
Expand Down Expand Up @@ -103,11 +104,11 @@ def test_rayleigh(parameters=None, storage=None):
#
_D = (np.pi**2 * _a / (_b * _c**2)) ** (1 / 3)

element_u = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_alpha = ufl.FiniteElement("Lagrange", mesh.ufl_cell(), degree=1)
element_u = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
element_alpha = basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)

V_u = dolfinx.fem.FunctionSpace(mesh, element_u)
V_alpha = dolfinx.fem.FunctionSpace(mesh, element_alpha)
V_u = dolfinx.fem.functionspace(mesh, element_u)
V_alpha = dolfinx.fem.functionspace(mesh, element_alpha)
u = dolfinx.fem.Function(V_u, name="Displacement")

alpha = dolfinx.fem.Function(V_alpha, name="Damage")
Expand All @@ -120,12 +121,12 @@ def test_rayleigh(parameters=None, storage=None):

for zero in [zero_u, zero_alpha]:
zero.interpolate(lambda x: np.zeros_like(x[0]))
zero.vector.ghostUpdate(
zero.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

one_alpha.interpolate(lambda x: np.zeros_like(x[0]))
one_alpha.vector.ghostUpdate(
one_alpha.x.petsc_vec.ghostUpdate(
addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD
)

Expand Down
Loading

0 comments on commit 6868c5c

Please sign in to comment.