Skip to content

Commit 6eda838

Browse files
committed
Fix print_BC_info
1 parent 35d19b1 commit 6eda838

6 files changed

Lines changed: 62 additions & 53 deletions

File tree

applications/phase_field_fracture/example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ def val_fn(point):
261261
logger.debug(f"####### max history = {np.max(history)}")
262262
# solve for u
263263
problem_u.set_params([sol_d_list[0], disp])
264-
sol_u_list = solver(problem_u, solver_options={'umfpack_solver':{}})
264+
sol_u_list = solver(problem_u, solver_options={'spsolve_solver':{}})
265265
# history
266266
history = problem_u.compute_history(sol_u_list[0], history_old)
267267
# solve for d
268268
problem_d.set_params(history)
269-
sol_d_list = solver(problem_d, solver_options={'umfpack_solver':{}})
269+
sol_d_list = solver(problem_d, solver_options={'spsolve_solver':{}})
270270
# error
271271
err_u = onp.linalg.norm(sol_u_list[0] - sol_u_old)/onp.linalg.norm(sol_u_list[0])
272272
err_d = onp.linalg.norm(sol_d_list[0] - sol_d_old)/onp.linalg.norm(sol_d_list[0])

docs/source/more/api/api_fe.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
=====================
33

44
.. autoclass:: jax_fem.fe.FiniteElement
5-
:exclude-members: mesh, vec, dim, ele_type, quadrature_order, dirichlet_bc_info, print_BC_info
5+
:exclude-members: mesh, vec, dim, ele_type, quadrature_order, dirichlet_bc_info

docs/source/more/api/api_problem.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
==========================
33

44
.. autoclass:: jax_fem.problem.Problem
5-
:exclude-members: mesh, vec, dim, ele_type, quadrature_order, dirichlet_bc_info, location_fns, additional_info, get_laplace_kernel, get_mass_kernel, get_surface_kernel, pre_jit_fns, split_and_compute_cell, compute_face, compute_residual_vars_helper, compute_residual_vars, compute_newton_vars
5+
:exclude-members: mesh, vec, dim, ele_type, quadrature_order, dirichlet_bc_info, location_fns, additional_info, get_laplace_kernel, get_mass_kernel, get_surface_kernel, pre_jit_fns, split_and_compute_cell, compute_face, compute_residual_vars_helper, compute_residual_vars, compute_newton_vars, print_BC_info

jax_fem/fe.py

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -378,50 +378,3 @@ def sol_to_grad(self, sol):
378378
u_grads = np.take(sol, self.cells, axis=0)[:, None, :, :, None] * self.shape_grads[:, :, :, None, :]
379379
u_grads = np.sum(u_grads, axis=2) # (num_cells, num_quads, vec, dim)
380380
return u_grads
381-
382-
def print_BC_info(self):
383-
"""Print boundary condition information for debugging purposes.
384-
385-
TODO: Not working
386-
"""
387-
if hasattr(self, 'neumann_boundary_inds_list'):
388-
print(f"\n\n### Neumann B.C. is specified")
389-
for i in range(len(self.neumann_boundary_inds_list)):
390-
print(f"\nNeumann Boundary part {i + 1} information:")
391-
print(self.neumann_boundary_inds_list[i])
392-
print(
393-
f"Array.shape = (num_selected_faces, 2) = {self.neumann_boundary_inds_list[i].shape}"
394-
)
395-
print(f"Interpretation:")
396-
print(
397-
f" Array[i, 0] returns the global cell index of the ith selected face"
398-
)
399-
print(
400-
f" Array[i, 1] returns the local face index of the ith selected face"
401-
)
402-
else:
403-
print(f"\n\n### No Neumann B.C. found.")
404-
405-
if len(self.node_inds_list) != 0:
406-
print(f"\n\n### Dirichlet B.C. is specified")
407-
for i in range(len(self.node_inds_list)):
408-
print(f"\nDirichlet Boundary part {i + 1} information:")
409-
bc_array = onp.stack([
410-
self.node_inds_list[i], self.vec_inds_list[i],
411-
self.vals_list[i]
412-
]).T
413-
print(bc_array)
414-
print(
415-
f"Array.shape = (num_selected_dofs, 3) = {bc_array.shape}")
416-
print(f"Interpretation:")
417-
print(
418-
f" Array[i, 0] returns the node index of the ith selected dof"
419-
)
420-
print(
421-
f" Array[i, 1] returns the vec index of the ith selected dof"
422-
)
423-
print(
424-
f" Array[i, 2] returns the value assigned to ith selected dof"
425-
)
426-
else:
427-
print(f"\n\n### No Dirichlet B.C. found.")

jax_fem/problem.py

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,4 +538,60 @@ def mass_fn(u, x, param):
538538
params: `JaxPytree <https://docs.jax.dev/en/latest/pytrees.html>`_
539539
The parameters to be differentiated.
540540
"""
541-
raise NotImplementedError("Child class must implement this function!")
541+
raise NotImplementedError("Child class must implement this function!")
542+
543+
def print_BC_info(self):
544+
"""Print boundary and surface-integral set information for debugging."""
545+
boundary_inds_list = self.boundary_inds_list
546+
if len(boundary_inds_list) != 0:
547+
print("\n\n### Surface integral boundary sets are specified")
548+
for i in range(len(boundary_inds_list)):
549+
print(f"\nSurface boundary set {i + 1} information:")
550+
print(boundary_inds_list[i])
551+
print(
552+
f"Array.shape = (num_selected_faces, 2) = {boundary_inds_list[i].shape}"
553+
)
554+
print("Interpretation:")
555+
print(
556+
" Array[i, 0] returns the global cell index of the ith selected face"
557+
)
558+
print(
559+
" Array[i, 1] returns the local face index of the ith selected face"
560+
)
561+
else:
562+
print("\n\n### No surface integral boundary sets found.")
563+
564+
for var_i, fe in enumerate(self.fes):
565+
var_suffix = (
566+
f" (finite element variable {var_i})"
567+
if self.num_vars > 1
568+
else ""
569+
)
570+
if len(fe.node_inds_list) != 0:
571+
print(f"\n\n### Dirichlet B.C. is specified{var_suffix}")
572+
for i in range(len(fe.node_inds_list)):
573+
print(f"\nDirichlet Boundary part {i + 1} information:")
574+
if len(fe.node_inds_list[i]) == 0:
575+
bc_array = onp.zeros((0, 3))
576+
else:
577+
bc_array = onp.stack([
578+
fe.node_inds_list[i],
579+
fe.vec_inds_list[i],
580+
fe.vals_list[i],
581+
]).T
582+
print(bc_array)
583+
print(
584+
f"Array.shape = (num_selected_dofs, 3) = {bc_array.shape}"
585+
)
586+
print("Interpretation:")
587+
print(
588+
" Array[i, 0] returns the node index of the ith selected dof"
589+
)
590+
print(
591+
" Array[i, 1] returns the vec index of the ith selected dof"
592+
)
593+
print(
594+
" Array[i, 2] returns the value assigned to ith selected dof"
595+
)
596+
else:
597+
print(f"\n\n### No Dirichlet B.C. found{var_suffix}.")

jax_fem/solver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def solver(problem, solver_options={}):
447447
Three solvers are currently available:
448448
449449
- `JAX solver <https://jax.readthedocs.io/en/latest/_autosummary/jax.scipy.sparse.linalg.bicgstab.html>`_
450-
- `SciPy spsolve (sparse direct) <https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.spsolve.html>`_
450+
- `SciPy solver <https://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.linalg.spsolve.html>`_
451451
- `PETSc solver <https://www.mcs.anl.gov/petsc/petsc4py-current/docs/apiref/index.html>`_
452452
453453
The empty choice ::

0 commit comments

Comments
 (0)