Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to 0.8.0 #76

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
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
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
Loading