Skip to content

Commit

Permalink
Merge pull request #105 from kumiori/andres-practice
Browse files Browse the repository at this point in the history
Andres practice
  • Loading branch information
kumiori authored Dec 6, 2024
2 parents 1e5cd2a + 7820a15 commit 7548a68
Show file tree
Hide file tree
Showing 48 changed files with 8,725 additions and 123 deletions.
14 changes: 9 additions & 5 deletions demo/demo_elasticity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
from dolfinx.io import XDMFFile, gmshio
from mpi4py import MPI
from petsc4py import PETSc
from pyvista.utilities import xvfb

from pyvista.plotting.utilities import xvfb
from irrevolutions.meshes.primitives import mesh_bar_gmshapi
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 @@ -69,7 +69,7 @@
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)
mesh, basix.ufl.element("Lagrange", mesh.basix_cell(), degree=1)
)

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

for f in [zero_u, ux_]:
f.x.petsc_vec.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 +135,9 @@

for i_t, t in enumerate(loads):
u_.interpolate(lambda x: (t * np.ones_like(x[0]), 0 * np.ones_like(x[1])))
u_.x.petsc_vec.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
24 changes: 18 additions & 6 deletions demo/demo_traction.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,27 @@
import ufl
import yaml
from dolfinx.common import list_timings
from dolfinx.fem import (Constant, Function, FunctionSpace, assemble_scalar,
dirichletbc, form, locate_dofs_geometrical, set_bc)
from dolfinx.fem import (
Constant,
Function,
FunctionSpace,
assemble_scalar,
dirichletbc,
form,
locate_dofs_geometrical,
set_bc,
)
from dolfinx.io import XDMFFile, gmshio
from mpi4py import MPI
from petsc4py import PETSc
from pyvista.utilities import xvfb

from pyvista.plotting.utilities import xvfb
from irrevolutions.algorithms.am import AlternateMinimisation, HybridSolver
from irrevolutions.meshes.primitives import mesh_bar_gmshapi
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 @@ -115,7 +123,9 @@
alpha_ub.interpolate(lambda x: np.ones_like(x[0]))

for f in [zero_u, zero_alpha, u_, alpha_lb, alpha_ub]:
f.x.petsc_vec.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 Down Expand Up @@ -177,7 +187,9 @@

for i_t, t in enumerate(loads):
u_.interpolate(lambda x: (t * np.ones_like(x[0]), np.zeros_like(x[1])))
u_.x.petsc_vec.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.x.petsc_vec.copy(alpha_lb.x.petsc_vec)
Expand Down
3 changes: 1 addition & 2 deletions demo/demo_vi.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
from dolfinx.fem.assemble import assemble_scalar
from dolfinx.mesh import CellType
from mpi4py import MPI
from pyvista.utilities import xvfb

from pyvista.plotting.utilities import xvfb
from irrevolutions.solvers import SNESSolver
from irrevolutions.utils.viz import plot_profile, plot_scalar

Expand Down
128 changes: 128 additions & 0 deletions playground/IDRIS-CAMPAING-HYDRA/parameters/1d_parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# === Loading === #
loading:
min: 0
max: 1.001
steps: 10

# === Geometry === #
geometry:
geometric_dimension: 2
geom_type: "bar"
Lx: 1.
Ly: .1
lc: 0.02
mesh_size_factor: 3

# === Material === #
model:
E: 1.
sigma_D0: 1.
ell: 0.1
model_dimension: 1
model_type: "1D"
kappa: 10.
# could be "2D"/ "3D" / "plane_stress" / "plane_strain"
# === Solver === #
solvers:
elasticity:
prefix: elasticity
snes:
snes_type: newtontr
snes_stol: 1e-8
snes_atol: 1e-8
snes_rtol: 1e-8
snes_max_it: 200
# snes_divergence_tolerance: -1.0
snes_monitor: ""
ksp_type: preonly
pc_type: lu
pc_factor_mat_solver_type: mumps

# Damage solver parameters
damage:
type: SNES
prefix: damage
snes:
# Options in the case of SNES solver
snes_type: vinewtonrsls
snes_linesearch_type: basic
ksp_type: preonly
pc_type: lu
pc_factor_mat_solver_type: mumps
snes_atol: 1.0e-8
snes_rtol: 1.0e-8
# snes_stol: 0.0
snes_max_it: 50
# snes_divergence_tolerance: -1.0
snes_monitor: ""
tao:
# Options in the case of TAO solver
tao_type: tron
tao_gpcg_maxpgits: 50
tao_max_it: 100
tao_steptol: 1.0e-7
tao_gatol: 1.0e-8
tao_grtol: 1.0e-8
tao_gttol: 1.0e-8
tao_catol: 0.
tao_crtol: 0.
tao_ls_ftol: 1e-5
tao_ls_gtol: 1e-5
tao_ls_rtol: 1e-5
ksp_rtol: 1e-6
tao_ls_stepmin: 1e-8
tao_ls_stepmax: 1e6
pc_type: lu
tao_monitor: ""

# Damage Elasticity Solver parameters
damage_elasticity:
max_it: 200
alpha_rtol: 1.0e-4
criterion: "alpha_H1"

newton:
snes_type: "vinewtonrsls"
snes_linesearch_type: "basic"
snes_rtol: 1.0e-8
snes_atol: 1.0e-8
snes_max_it: 30
snes_monitor: ""
linesearch_damping: 0.5

stability:
order: 3
maxmodes: 10
checkstability: "True"
continuation: "False"
cont_rtol: 1.0e-10
inactiveset_gatol: 1.e-6
inactiveset_pwtol: 1.e-6
is_elastic_tol: 1.e-6

inertia:
# MUMPS
ksp_type: "preonly"
pc_type: "cholesky"
pc_factor_mat_solver_type: "mumps"
mat_mumps_icntl_24: 1
mat_mumps_icntl_13: 1

eigen:
eps_type: "krylovschur"
# eps_type: "lanczos"
# eps_monitor: ""
eps_tol: 1.e-5
eig_rtol: 1.e-8
eps_max_it: 100

cone:
cone_atol: 1.0e-06
cone_max_it: 3000
cone_rtol: 1.0e-06
maxmodes: 3
scaling: 1.e-5

linesearch:
order: 4
method: 'min'
127 changes: 127 additions & 0 deletions playground/IDRIS-CAMPAING-HYDRA/parameters/2d_parameters.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# === Loading === #
loading:
min: 0
max: 1.001
steps: 10

# === Geometry === #
geometry:
geometric_dimension: 2
geom_type: "circle"
R: 1.
lc: 0.02
mesh_size_factor: 3

# === Material === #
model:
E: 1.
sigma_D0: 1.
ell: 0.1
model_dimension: 1
model_type: "2D"
kappa: 10.
# could be "2D"/ "3D" / "plane_stress" / "plane_strain"
# === Solver === #
solvers:
elasticity:
prefix: elasticity
snes:
snes_type: newtontr
snes_stol: 1e-8
snes_atol: 1e-8
snes_rtol: 1e-8
snes_max_it: 200
# snes_divergence_tolerance: -1.0
snes_monitor: ""
ksp_type: preonly
pc_type: lu
pc_factor_mat_solver_type: mumps

# Damage solver parameters
damage:
type: SNES
prefix: damage
snes:
# Options in the case of SNES solver
snes_type: vinewtonrsls
snes_linesearch_type: basic
ksp_type: preonly
pc_type: lu
pc_factor_mat_solver_type: mumps
snes_atol: 1.0e-8
snes_rtol: 1.0e-8
# snes_stol: 0.0
snes_max_it: 50
# snes_divergence_tolerance: -1.0
snes_monitor: ""
tao:
# Options in the case of TAO solver
tao_type: tron
tao_gpcg_maxpgits: 50
tao_max_it: 100
tao_steptol: 1.0e-7
tao_gatol: 1.0e-8
tao_grtol: 1.0e-8
tao_gttol: 1.0e-8
tao_catol: 0.
tao_crtol: 0.
tao_ls_ftol: 1e-5
tao_ls_gtol: 1e-5
tao_ls_rtol: 1e-5
ksp_rtol: 1e-6
tao_ls_stepmin: 1e-8
tao_ls_stepmax: 1e6
pc_type: lu
tao_monitor: ""

# Damage Elasticity Solver parameters
damage_elasticity:
max_it: 200
alpha_rtol: 1.0e-4
criterion: "alpha_H1"

newton:
snes_type: "vinewtonrsls"
snes_linesearch_type: "basic"
snes_rtol: 1.0e-8
snes_atol: 1.0e-8
snes_max_it: 30
snes_monitor: ""
linesearch_damping: 0.5

stability:
order: 3
maxmodes: 10
checkstability: "True"
continuation: "False"
cont_rtol: 1.0e-10
inactiveset_gatol: 1.e-6
inactiveset_pwtol: 1.e-6
is_elastic_tol: 1.e-6

inertia:
# MUMPS
ksp_type: "preonly"
pc_type: "cholesky"
pc_factor_mat_solver_type: "mumps"
mat_mumps_icntl_24: 1
mat_mumps_icntl_13: 1

eigen:
eps_type: "krylovschur"
# eps_type: "lanczos"
# eps_monitor: ""
eps_tol: 1.e-5
eig_rtol: 1.e-8
eps_max_it: 100

cone:
cone_atol: 1.0e-06
cone_max_it: 3000
cone_rtol: 1.0e-06
maxmodes: 3
scaling: 1.e-5

linesearch:
order: 4
method: 'min'
Loading

0 comments on commit 7548a68

Please sign in to comment.