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

Add license. Make sure all code is up to date and running #6

Merged
merged 1 commit into from
Jul 15, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Jørgen Schartum Dokken

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 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 10 additions & 2 deletions implementation/compare_nitsche_snes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import argparse

import dolfinx
Expand All @@ -12,8 +16,8 @@


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Compare Nitsche's metood for contact against a straight plane"
+ " with PETSc SNES",
description = "Compare Nitsche's method for contact against a straight plane with PETSc SNES"
parser = argparse.ArgumentParser(description=description,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--theta", default=1, type=np.float64, dest="theta",
help="Theta parameter for Nitsche, 1 symmetric, -1 skew symmetric, 0 Penalty-like")
Expand Down Expand Up @@ -41,6 +45,7 @@
dest="refs", help="Number of mesh refinements")
_gap = parser.add_argument(
"--gap", default=0.02, type=np.float64, dest="gap", help="Gap between plane and y=0")

# Parse input arguments or set to defualt values
args = parser.parse_args()

Expand Down Expand Up @@ -103,6 +108,7 @@ def bottom(x):
# Refine mesh
mesh.topology.create_entities(mesh.topology.dim - 2)
mesh = dolfinx.mesh.refine(mesh)

# Create meshtag for top and bottom markers
tdim = mesh.topology.dim
top_facets = dolfinx.mesh.locate_entities_boundary(mesh, tdim - 1, top)
Expand Down Expand Up @@ -137,6 +143,8 @@ def bottom(x):
e_abs.append(E_L2)
e_rel.append(E_L2 / u2_L2)
dofs_global.append(V.dofmap.index_map.size_global * V.dofmap.index_map_bs)

# Output absolute and relative errors of Nitsche compared to SNES
if rank == 0:
print(f"Num dofs {dofs_global}")
print(f"Absolute error {e_abs}")
Expand Down
8 changes: 6 additions & 2 deletions implementation/create_contact_meshes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken
#
# SPDX-License-Identifier: MIT

import argparse
import warnings

Expand Down Expand Up @@ -41,11 +45,11 @@ def create_circle_plane_mesh(filename: str):
# Synchronize and create physical tags
gmsh.model.occ.synchronize()
gmsh.model.addPhysicalGroup(2, [surface])
bndry = gmsh.model.getBoundary((2, surface))
bndry = gmsh.model.getBoundary([(2, surface)])
[gmsh.model.addPhysicalGroup(b[0], [b[1]]) for b in bndry]

gmsh.model.addPhysicalGroup(2, [surface2], 2)
bndry2 = gmsh.model.getBoundary((2, surface2))
bndry2 = gmsh.model.getBoundary([(2, surface2)])
[gmsh.model.addPhysicalGroup(b[0], [b[1]]) for b in bndry2]

gmsh.model.mesh.field.add("Distance", 1)
Expand Down
3 changes: 3 additions & 0 deletions implementation/create_mesh.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2021 Jørgen S. Dokken
#
# SPDX-License-Identifier: MIT

import argparse
import warnings
Expand Down
4 changes: 4 additions & 0 deletions implementation/helpers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

from typing import List

import dolfinx
Expand Down
13 changes: 8 additions & 5 deletions implementation/nitsche_bc_plane_stress_beam_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import argparse
import os

Expand All @@ -12,7 +16,7 @@
from helpers import epsilon, lame_parameters, sigma_func


def solve_manufactured(nx, ny, theta, gamma, nitsche, strain, linear_solver, L=10):
def solve_manufactured(nx: int, ny: int, theta: float, gamma: float, nitsche: bool, strain: bool, linear_solver: bool, L: float = 10):
"""
Solve the manufactured problem
u = [(nu + 1) / E * x[1]**4, (nu + 1) / E * x[0]**4]
Expand Down Expand Up @@ -128,9 +132,9 @@ def _u_ex(x):


if __name__ == "__main__":
desc = "Manufatured solution test for the linear elasticity equation using Nitsche-Dirichlet boundary conditions"
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description="Manufatured solution test for the linear elasticity equation"
+ " using Nitsche-Dirichlet boundary conditions")
description=desc)
parser.add_argument("--theta", default=1, type=np.float64, dest="theta",
help="Theta parameter for Nitsche, 1 symmetric, -1 skew symmetric, 0 Penalty-like")
parser.add_argument("--gamma", default=1000, type=np.float64, dest="gamma",
Expand Down Expand Up @@ -160,5 +164,4 @@ def _u_ex(x):
nx, ny, theta, gamma, nitsche, strain, linear_solver)
errors[i] = E
hs[i] = h
print(
f"Convergence rate: {np.log(errors[:-1]/errors[1:])/np.log(hs[:-1]/hs[1:])}")
print(f"Convergence rate: {np.log(errors[:-1]/errors[1:])/np.log(hs[:-1]/hs[1:])}")
20 changes: 12 additions & 8 deletions implementation/nitsche_euler_bernoulli.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import argparse
import os
from typing import List
Expand All @@ -13,15 +17,14 @@
from helpers import epsilon, lame_parameters, sigma_func


def solve_euler_bernoulli(nx, ny, theta, gamma, linear_solver, plane_strain, nitsche, L=47, H=2.73,
E=1e5, nu=0.3, rho_g=1e-2):
def solve_euler_bernoulli(nx: int, ny: int, theta: float, gamma: float, linear_solver: bool, plane_strain: bool, nitsche: bool,
L: float = 47, H: float = 2.73, E: float = 1e5, nu: float = 0.3, rho_g: float = 1e-2):
"""
Solve the Euler-Bernoulli equations for a (0,0)x(L,H) beam
(https://en.wikipedia.org/wiki/Euler%E2%80%93Bernoulli_beam_theory#Cantilever_beams)
"""
mesh = dolfinx.RectangleMesh(
MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([L, H, 0])], [nx, ny],
CellType.triangle, GhostMode.none)
mesh = dolfinx.RectangleMesh(MPI.COMM_WORLD, [np.array([0, 0, 0]), np.array([L, H, 0])], [nx, ny],
CellType.triangle, GhostMode.none)

def left(x):
return np.isclose(x[0], 0)
Expand Down Expand Up @@ -129,9 +132,10 @@ def top(x):


if __name__ == "__main__":
parser = argparse.ArgumentParser(
description="Verification of Nitsche-Dirichlet boundary conditions for"
+ "linear elasticity solving the Euler-Bernoulli equiation", formatter_class=argparse.ArgumentDefaultsHelpFormatter)
desc = description = "Verification of Nitsche-Dirichlet boundary conditions for linear elasticity solving" +\
"the Euler-Bernoulli equiation",
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description=desc)
parser.add_argument("--theta", default=1, type=np.float64, dest="theta",
help="Theta parameter for Nitsche, 1 symmetric, -1 skew symmetric, 0 Penalty-like")
parser.add_argument("--gamma", default=1000, type=np.float64, dest="gamma",
Expand Down
15 changes: 9 additions & 6 deletions implementation/nitsche_one_way.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import dolfinx
import dolfinx.io
import numpy as np
import ufl
from mpi4py import MPI
from petsc4py import PETSc

from helpers import (epsilon, lame_parameters, rigid_motions_nullspace,
sigma_func, R_minus)
from typing import Tuple
from helpers import (epsilon, lame_parameters, rigid_motions_nullspace, sigma_func, R_minus)


def nitsche_one_way(mesh, mesh_data, physical_parameters, refinement=0,
nitsche_parameters={"gamma": 1, "theta": 1, "s": 0}, g=0.0,
vertical_displacement=-0.1, nitsche_bc=False):
def nitsche_one_way(mesh: dolfinx.cpp.mesh.Mesh, mesh_data: Tuple[dolfinx.MeshTags, int, int], physical_parameters: dict, refinement: int = 0,
nitsche_parameters: dict = {"gamma": 1, "theta": 1, "s": 0}, g: float = 0.0,
vertical_displacement: float = -0.1, nitsche_bc: bool = False):
(facet_marker, top_value, bottom_value) = mesh_data

with dolfinx.io.XDMFFile(MPI.COMM_WORLD, "results/mf_nitsche.xdmf", "w") as xdmf:
Expand Down
14 changes: 10 additions & 4 deletions implementation/nitsche_rigid_surface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import dolfinx
import dolfinx.io
import numpy as np
Expand All @@ -6,13 +10,15 @@
from petsc4py import PETSc
import dolfinx_cuas.cpp as cuas

from typing import Tuple
from helpers import (epsilon, lame_parameters, rigid_motions_nullspace,
sigma_func, R_minus)


def nitsche_rigid_surface(mesh, mesh_data, physical_parameters,
nitsche_parameters={"gamma": 1, "theta": 1},
vertical_displacement=-0.1, nitsche_bc=False):
def nitsche_rigid_surface(mesh: dolfinx.cpp.mesh.Mesh, mesh_data: Tuple[dolfinx.MeshTags, int, int, int, int],
physical_parameters: dict,
nitsche_parameters: dict = {"gamma": 1, "theta": 1},
vertical_displacement: dict = -0.1, nitsche_bc: bool = False):
(facet_marker, top_value, bottom_value, surface_value, surface_bottom) = mesh_data

# Nitche parameters and variables
Expand Down Expand Up @@ -43,7 +49,7 @@ def sigma_n(v):
gdim = mesh.geometry.dim
fdim = mesh.topology.dim - 1
mesh_geometry = mesh.geometry.x
contact = cuas.Contact(facet_marker, bottom_value, surface_value)
contact = cuas.Contact(facet_marker, bottom_value, surface_value, V._cpp_object)
contact.create_distance_map(0)
lookup = contact.map_0_to_1()
bottom_facets = contact.facet_0()
Expand Down
13 changes: 7 additions & 6 deletions implementation/snes_against_plane.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import dolfinx
import dolfinx.io
import dolfinx.log
import numpy as np
import ufl
from mpi4py import MPI
from petsc4py import PETSc

from typing import Tuple
from helpers import NonlinearPDE_SNESProblem, lame_parameters, epsilon, sigma_func, rigid_motions_nullspace


def snes_solver(mesh, mesh_data, physical_parameters, refinement=0, g=0.0, vertical_displacement=-0.1):
def snes_solver(mesh: dolfinx.cpp.mesh.Mesh, mesh_data: Tuple[dolfinx.MeshTags, int, int], physical_parameters: dict,
refinement: int = 0, g: float = 0.0, vertical_displacement: float = -0.1):
(facet_marker, top_value, bottom_value) = mesh_data
"""
Solving contact problem against a rigid plane with gap -g from y=0 using PETSc SNES solver
Expand Down Expand Up @@ -153,7 +158,3 @@ def _u_initial(x):
xdmf.write_function(u)

return u


if __name__ == "__main__":
snes_solver()
8 changes: 6 additions & 2 deletions implementation/test_nitsche_rigid_surface.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Copyright (C) 2021 Jørgen S. Dokken and Sarah Roggendorf
#
# SPDX-License-Identifier: MIT

import argparse

import dolfinx
Expand All @@ -8,8 +12,8 @@
from nitsche_rigid_surface import nitsche_rigid_surface

if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Compare Nitsche's metood for contact against a straight plane"
+ " with PETSc SNES",
desc = "Compare Nitsche's metood for contact against a straight plane with PETSc SNES"
parser = argparse.ArgumentParser(description=desc,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("--theta", default=1, type=np.float64, dest="theta",
help="Theta parameter for Nitsche, 1 symmetric, -1 skew symmetric, 0 Penalty-like")
Expand Down