Skip to content

Commit

Permalink
Formatting udpates
Browse files Browse the repository at this point in the history
  • Loading branch information
garth-wells committed Jun 16, 2024
1 parent 3e5ed8f commit f3d604d
Show file tree
Hide file tree
Showing 27 changed files with 101 additions and 287 deletions.
3 changes: 1 addition & 2 deletions python/demos/box_key_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ def _torque(x, alpha):
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = _fem.form(F, jit_options=jit_options)
J_compiled = _fem.form(J, jit_options=jit_options)
Expand Down
10 changes: 3 additions & 7 deletions python/demos/demo_christmas_tree_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ def identifier(x, z):
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = _fem.form(F, jit_options=jit_options)
J_compiled = _fem.form(J, jit_options=jit_options)

# create initial guess
tree_cells = domain_marker.find(1)

Expand Down Expand Up @@ -250,11 +250,7 @@ def _u_initial(x):
search_mode = [ContactMode.ClosestPoint for _ in range(len(contact_pairs))]
contact_problem = ContactProblem([facet_marker], surfaces, contact_pairs, mesh, args.q_degree, search_mode)
contact_problem.generate_contact_data(
FrictionLaw.Frictionless,
V,
{"u": u, "du": du, "mu": mu0, "lambda": lmbda0},
E * gamma,
theta,
FrictionLaw.Frictionless, V, {"u": u, "du": du, "mu": mu0, "lambda": lmbda0}, E * gamma, theta
)
solver_outfile = None
log.set_log_level(log.LogLevel.WARNING)
Expand Down
17 changes: 3 additions & 14 deletions python/demos/demo_nitsche_meshties.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def run_demo(simplex, E, nu, gamma, theta, lifting, outfile, ksp_view, timing_vi
)

# compile forms
cffi_options = []
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
F = form(F, jit_options=jit_options)
J = form(J, jit_options=jit_options)

Expand Down Expand Up @@ -171,19 +170,9 @@ def run_demo(simplex, E, nu, gamma, theta, lifting, outfile, ksp_view, timing_vi
# solver_outfile = outfile if ksp_view else None

# initialise meshties
meshties = MeshTie(
[facet_marker._cpp_object],
surfaces,
contact,
mesh._cpp_object,
quadrature_degree=5,
)
meshties = MeshTie([facet_marker._cpp_object], surfaces, contact, mesh._cpp_object, quadrature_degree=5)
meshties.generate_kernel_data(
Problem.Elasticity,
V._cpp_object,
{"lambda": lmbda._cpp_object, "mu": mu._cpp_object},
E * gamma,
theta,
Problem.Elasticity, V._cpp_object, {"lambda": lmbda._cpp_object, "mu": mu._cpp_object}, E * gamma, theta
)

# create matrix, vector
Expand Down
3 changes: 1 addition & 2 deletions python/demos/demo_nitsche_unbiased.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,7 @@ def bottom_contact(x):
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = []
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = form(F, jit_options=jit_options)
J_compiled = form(J, jit_options=jit_options)
Expand Down
9 changes: 2 additions & 7 deletions python/demos/demo_sliding_wedges.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,7 @@
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = form(F, jit_options=jit_options)
J_compiled = form(J, jit_options=jit_options)
Expand Down Expand Up @@ -201,11 +200,7 @@ def _pressure(x):
# Solve contact problem using Nitsche's method
contact_problem = ContactProblem([facet_marker], surfaces, contact, mesh, args.q_degree, search_mode)
contact_problem.generate_contact_data(
FrictionLaw.Coulomb,
V,
{"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg, "fric": fric_dg},
E * 10,
-1,
FrictionLaw.Coulomb, V, {"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg, "fric": fric_dg}, E * 10, -1
)

# define functions for newton solver
Expand Down
9 changes: 2 additions & 7 deletions python/demos/demo_thermo_mech_boxkey3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ def sigma(w, T):
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = form(F, jit_options=jit_options)
J_compiled = form(J, jit_options=jit_options)
Expand All @@ -211,11 +210,7 @@ def sigma(w, T):
search_mode = [ContactMode.ClosestPoint for _ in range(len(contact_pairs))]
contact_problem = ContactProblem([facet_marker], surfaces, contact_pairs, mesh, 5, search_mode)
contact_problem.generate_contact_data(
FrictionLaw.Frictionless,
V,
{"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg},
E * gamma,
theta,
FrictionLaw.Frictionless, V, {"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg}, E * gamma, theta
)
# define functions for newton solver

Expand Down
15 changes: 3 additions & 12 deletions python/demos/demo_thermo_mech_xmas2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ def sigma(w, T):
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = _fem.form(F, jit_options=jit_options)
J_compiled = _fem.form(J, jit_options=jit_options)
Expand Down Expand Up @@ -182,11 +181,7 @@ def sigma(w, T):


# Solve contact problem using Nitsche's method
problem_parameters = {
"gamma": np.float64((1 - alpha) * E * gamma),
"theta": np.float64(theta),
"fric": np.float64(0.4),
}
problem_parameters = {"gamma": np.float64((1 - alpha) * E * gamma), "theta": np.float64(theta), "fric": np.float64(0.4)}
log.set_log_level(log.LogLevel.WARNING)
size = mesh.comm.size
outname = f"results/xmas_{tdim}D_{size}"
Expand All @@ -196,11 +191,7 @@ def sigma(w, T):
search_mode = [ContactMode.ClosestPoint for _ in range(len(contact_pairs))]
contact_problem = ContactProblem([facet_marker], surfaces, contact_pairs, mesh, 5, search_mode)
contact_problem.generate_contact_data(
FrictionLaw.Frictionless,
V,
{"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg},
E * gamma,
theta,
FrictionLaw.Frictionless, V, {"u": u, "du": du, "mu": mu_dg, "lambda": lmbda_dg}, E * gamma, theta
)
# define functions for newton solver

Expand Down
3 changes: 1 addition & 2 deletions python/demos/hertz_contact/demo_friction_cylinders.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = form(F, jit_options=jit_options)
J_compiled = form(J, jit_options=jit_options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@
J = ufl.derivative(F, du, w)

# compiler options to improve performance
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
# compiled forms for rhs and tangen system
F_compiled = form(F, jit_options=jit_options)
J_compiled = form(J, jit_options=jit_options)
Expand Down
43 changes: 9 additions & 34 deletions python/demos/meshtie_convergence.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,11 @@ def u_fun_2d(x: npt.NDArray[np.float64], d: float, gdim: int) -> npt.NDArray[np.
def fun_2d(x: npt.NDArray[np.float64], d: float, mu: float, lmbda: float, gdim: int) -> npt.NDArray[np.float64]:
a = 2 * np.pi / 5
b = 2 * np.pi

vals = np.zeros((gdim, x.shape[1]))
f1 = -(lmbda + mu) * a * b * np.cos(a * x[0]) * np.cos(b * x[1])

f2 = (mu * a**2 + (2 * mu + lmbda) * b**2) * np.sin(a * x[0]) * np.sin(b * x[1])
vals[0, :] = d * f1[:]
vals[1, :] = d * f2[:]

return vals


Expand All @@ -90,9 +87,7 @@ def fun_3d(x: npt.NDArray[np.float64], d: float, mu: float, lmbda: float, gdim:
b = 2 * np.pi
c = 2 * np.pi
f1 = -(lmbda + mu) * a * b * np.cos(a * x[0]) * np.cos(b * x[1]) * np.sin(c * x[2])

f2 = (mu * (a**2 + c**2) + (2 * mu + lmbda) * b**2) * np.sin(a * x[0]) * np.sin(b * x[1]) * np.sin(c * x[2])

f3 = -(lmbda + mu) * b * c * np.sin(a * x[0]) * np.cos(b * x[1]) * np.cos(c * x[2])
vals = np.zeros((gdim, x.shape[1]))
vals[0, :] = d * f1[:]
Expand All @@ -118,7 +113,6 @@ def unsplit_domain(threed: bool = False, runs: int = 1):
res = 0.6 # mesh resolution (input to gmsh)
# parameter for surface approximation
num_segments = 2 * np.ceil(5.0 / (1.2 * 0.7)).astype(np.int32)

for i in range(1, runs + 1):
print(f"Run {i}")
# create mesh
Expand Down Expand Up @@ -181,10 +175,7 @@ def unsplit_domain(threed: bool = False, runs: int = 1):

b = assemble_vector(F)
apply_lifting(b, [J], bcs=[[bc]])
b.ghostUpdate(
addv=PETSc.InsertMode.ADD, # type: ignore
mode=PETSc.ScatterMode.REVERSE, # type: ignore
)
b.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)
set_bc(b, [bc])

# Set solver options
Expand Down Expand Up @@ -232,6 +223,7 @@ def unsplit_domain(threed: bool = False, runs: int = 1):
errors.append(np.sqrt(mesh.comm.allreduce(error, op=MPI.SUM)))
res = 0.5 * res
num_segments = 2 * num_segments

ncells = mesh.topology.index_map(tdim).size_local
indices = np.array(range(ncells), dtype=np.int32)
values = mesh.comm.rank * np.ones(ncells, dtype=np.int32)
Expand All @@ -247,10 +239,10 @@ def unsplit_domain(threed: bool = False, runs: int = 1):


def test_meshtie(threed: bool = False, simplex: bool = True, runs: int = 5):
"""
This function computes the finite element solution on mesh
"""This function computes the finite element solution on mesh
split along a surface, where the mesh and the surface discretisation
are not matching along the surface
threed: tdim=gdim=3 if True, 2 otherwise
simplex: If true use tet/triangle mesh if false use hex/quad mesh
runs: number of refinements
Expand Down Expand Up @@ -379,8 +371,7 @@ def force_func(x):
F += -theta * ufl.inner(sigma(v) * n, g) * ds(tag) + E * gamma / h * ufl.inner(g, v) * ds(tag)

# compile forms
cffi_options = ["-Ofast", "-march=native"]
jit_options = {"cffi_extra_compile_args": cffi_options, "cffi_libraries": ["m"]}
jit_options = {"cffi_extra_compile_args": [], "cffi_libraries": ["m"]}
F = form(F, jit_options=jit_options)
J = form(J, jit_options=jit_options)

Expand All @@ -391,19 +382,9 @@ def force_func(x):
surfaces = adjacencylist(data, offsets)

# initialise meshties
meshties = MeshTie(
[facet_marker._cpp_object],
surfaces,
contact,
mesh._cpp_object,
quadrature_degree=5,
)
meshties = MeshTie([facet_marker._cpp_object], surfaces, contact, mesh._cpp_object, quadrature_degree=5)
meshties.generate_kernel_data(
Problem.Elasticity,
V._cpp_object,
{"lambda": lmbda._cpp_object, "mu": mu._cpp_object},
E * gamma,
theta,
Problem.Elasticity, V._cpp_object, {"lambda": lmbda._cpp_object, "mu": mu._cpp_object}, E * gamma, theta
)

# create matrix, vector
Expand All @@ -412,15 +393,9 @@ def force_func(x):

# Assemble right hand side
b.zeroEntries()
b.ghostUpdate(
addv=PETSc.InsertMode.INSERT, # type: ignore
mode=PETSc.ScatterMode.FORWARD, # type: ignore
)
b.ghostUpdate(addv=PETSc.InsertMode.INSERT, mode=PETSc.ScatterMode.FORWARD)
assemble_vector(b, F)
b.ghostUpdate(
addv=PETSc.InsertMode.ADD, # type: ignore
mode=PETSc.ScatterMode.REVERSE, # type: ignore
)
b.ghostUpdate(addv=PETSc.InsertMode.ADD, mode=PETSc.ScatterMode.REVERSE)

# Assemble matrix
A.zeroEntries()
Expand Down
Loading

0 comments on commit f3d604d

Please sign in to comment.