scrimp.utils

This folder contains useful functions that are beyond the port-Hamiltonian framework used in SCRIMP.

Config

  • file: utils/config.py

  • authors: Ghislain Haine

  • date: 23 jun. 2023

  • brief: functions to configure SCRIMP

scrimp.utils.config.set_paths(path=None, *, create=True)

Set the default path of scrimp

Parameters:
  • path – Optional base working directory.

  • create – Allocate legacy outputs/log,png,mesh,pv folders. Explicit callers retain the historical default (True). The SCRIMP package import uses create=False, preventing unrelated shared folders beside outputs/<system_name>/.

scrimp.utils.config.set_verbose(verbose=1)

Set the verbosity level of scrimp (0: quiet, 1: info, 2: debug)

In quiet mode, debug are saved in a log file.

Args:

verbose (int): the level of verbosity, defaults to 1

scrimp.utils.config.set_verbose_gf(verbose)

Set the verbosity level of getfem

Args:

verbose (int): the level of verbosity

Linear algebra

  • file: utils/linalg.py

  • authors: Ghislain Haine, Florian Monteghetti

  • date: 29 nov. 2022

  • brief: linear algebra functions

scrimp.utils.linalg.EPS_get_spectrum(EPS, transform_hermitian=False)
scrimp.utils.linalg.EPS_print_results(EPS)
scrimp.utils.linalg.EPS_print_short(EPS)
scrimp.utils.linalg.convert_PETSc_to_scipy(A)

Convert from PETSc.Mat to scipy sparse (csr).

Args:

A (PETSc Mat): The matrix to convert

Returns:

scipy.sparse.csr.csr_matrix: the matrix A in scipy.sparse.csr.csr_matrix format

scrimp.utils.linalg.convert_gmm_to_petsc(M, B, comm=petsc4py.PETSc.COMM_WORLD, *, profiler=None, profile_label=None, distributed_coo_eligible=True)

Transfer GetFEM’s globally numbered matrix into distributed PETSc.

SCRIMP_GETFEM_MATRIX_MODE selects ASSEMBLY SEMANTICS: - replicated: insert owned PETSc rows once (INSERT_VALUES). - distributed: sum all global contributions (ADD_VALUES).

SCRIMP_GETFEM_BRIDGE_REPLICATED controls only extraction in replicated mode: ‘full’ (default) or experimental ‘owned_rows’.

With distributed GetFEM assembly, all production matrix transfers default to PETSc’s native COO preallocation/assembly, including the state-dependent nonlinear mass and stiffness tangents. The GetFEM contributions may change sparsity between Newton iterations: setPreallocationCOO is rerun for EACH assembly before setValuesCOO, using the SAME PETSc Mat handle (not a new Mat per iteration). The owned structural diagonal is always retained.

SCRIMP_GETFEM_BRIDGE_DISTRIBUTED=csr or ijv remains an EXPLICIT historical diagnostic override for source-era benchmark parity; it is no longer a production default or the nonlinear assembly path. Replicated GetFEM extraction is retained for serial compatibility. PETSc stores the assembled sparse matrix as AIJ (CSR-like): COO is the assembly API, not the storage format.

The native-MPI benchmark and complete acoustic trajectory tests cover 1/2/4/6 ranks and three-repeat runs for linear operators. Preservation of the PETSc Mat handle and explicit diagonal slots is required. Nonlinear COO is NOT enabled without separate tests.

Optional profiler/profile_label use SCRIMP’s existing TimingProfiler for bridge subphases. No MPI collectives or matrix changes are added. The bridge total is already measured by the DPHS assembly methods.

scrimp.utils.linalg.extract_gmm_to_scipy(I, J, M)

Extract a sub-matrix A from M, on interval I, J

Args:

I (Numpy array): line interval [begin, lenght] J (Numpy array): column interval [begin, lenght] M (SPMat GetFEM): matrix from which to extract the submatrix

Returns:

PETSc.Mat: matrix with value M(I,J) in CSR format

Returns:

scipy.sparse.csr.csr_matrix: the matrix A in scipy.sparse.csr.csr_matrix format

scrimp.utils.linalg.monitor_EPS_short(EPS, it, nconv, eig, err, it_skip)

Concise monitor for EPS.solve().

Parameters

epsslepc4py.SLEPc.EPS

Eigenvalue Problem Solver class.

itint

Current iteration number.

nconvint

Number of converged eigenvalue.

eiglist

Eigenvalues

errlist

Computed errors.

it_skipint

Iteration skip.

Returns

None.

scrimp.utils.linalg.solve_GEP_shiftinvert(A, B, problem_type=slepc4py.SLEPc.EPS.ProblemType.GNHEP, solver=slepc4py.SLEPc.EPS.Type.KRYLOVSCHUR, which=slepc4py.SLEPc.EPS.Which.TARGET_MAGNITUDE, nev=10, tol=1e-06, max_it=10, target=0.0, shift=0.0, defl_space=[], transform_hermitian=False)

Solve generalized eigenvalue problem A=lambda*B using shift-and-invert as spectral transform method.

Parameters

A,B : PETSc.Mat problem_type : SLEPc.EPS.ProblemType, optional solver : SLEPc.EPS.Type., optional

nevint, optional

Number of requested eigenvalues.

tolfloat, optional

Tolerance.

max_itint, optional

Maximum number of iterations.

targetfloat, optional

Target eigenvalue. Also used for sorting.

shiftfloat, optional

Shift ‘sigma’ used in shift-and-invert.

defl_space: list of petsc4py.PETSc.Vec, optional

Deflation space.

transform_hermitianbool

Whether to transform the problem into a Hermitian generalized EVP.

Returns

eigvallist of complex

Converged eigenvalues.

eigvec_rlist of PETSc.Vec

Converged eigenvector (real_part)

eigvec_ilist of PETSc.Vec

Converged eigenvectors (imag_part)

Mesh

  • file: utils/mesh.py

  • authors: Ghislain Haine

  • date: 22 nov. 2022

  • brief: built-in geometries for direct use in SCRIMP

scrimp.utils.mesh.Ball(parameters={'R': 1.0, 'h': 0.1}, refine=0, terminal=1, mesh_output_dir=None)

The geometry of a Ball of radius R centered in (0,0,0) with mesh size h

  • Domain Omega: 1,

  • Boundary Gamma: 10

Args:
  • parameters (dict): The dictionary of parameters for the geometry

  • refine (int): Ask for iterative refinements by splitting elements

  • terminal (int): An option to print meshing infos in the prompt, value 0 (quiet) or 1 (verbose, default)

Returns:

list[gf.Mesh, int, dict, dict]: The mesh to use with getfem, the dimension, a dict of regions with getfem indices for dim n and a dict of regions with getfem indices for dim n-1

scrimp.utils.mesh.Concentric(parameters={'R': 1.0, 'h': 0.1, 'r': 0.6}, refine=0, terminal=1, mesh_output_dir=None)

The geometry of a Disk of radius r surrounded by an annulus of radii r and R with mesh size h

  • Domain Omega_Disk: 1,

  • Domain Omega_Annulus: 2,

  • Interface Interface: 10,

  • Boundary Gamma: 20

Args:
  • parameters (dict): The dictionary of parameters for the geometry

  • refine (int): Ask for iterative refinements by splitting elements

  • terminal (int): An option to print meshing infos in the prompt, value 0 (quiet) or 1 (verbose, default)

Returns:

list[gf.Mesh, int, dict, dict]: The mesh to use with getfem, the dimension, a dict of regions with getfem indices for dim n and a dict of regions with getfem indices for dim n-1

scrimp.utils.mesh.Disk(parameters={'R': 1.0, 'h': 0.1}, refine=0, terminal=1, mesh_output_dir=None)

The geometry of a Disk center in (0,0) with radius R and mesh size h

  • Domain Omega: 1,

  • Boundary Gamma: 10

Args:
  • parameters (dict): The dictionary of parameters for the geometry

  • refine (int): Ask for iterative refinements by splitting elements

  • terminal (int): An option to print meshing infos in the prompt, value 0 (quiet) or 1 (verbose, default)

Returns:

list[gf.Mesh, int, dict, dict]: The mesh to use with getfem, the dimension, a dict of regions with getfem indices for dim n and a dict of regions with getfem indices for dim n-1

scrimp.utils.mesh.Interval(parameters={'L': 1.0, 'h': 0.05}, refine=0, terminal=1, mesh_output_dir=None)

The geometry of a segment (0,L) with mesh size h

  • Domain Omega: 1,

  • Left boundary Gamma_Left: 10,

  • Right boundary Gamma_Right: 11

Args:
  • parameters (dict): The dictionary of parameters for the geometry

  • refine (int): Ask for iterative refinements by splitting elements

  • terminal (int): An option to print meshing infos in the prompt, value 0 (quiet) or 1 (verbose, default)

Returns:

list[gf.Mesh, int, dict, dict]: The mesh to use with getfem, the dimension, a dict of regions with getfem indices for dim n and a dict of regions with getfem indices for dim n-1

scrimp.utils.mesh.Rectangle(parameters={'L': 2.0, 'h': 0.1, 'l': 1}, refine=0, terminal=1, mesh_output_dir=None)

The geometry of a Rectangle (0,L)x(0,l) with mesh size h

  • Domain Omega: 1,

  • Bottom boundary Gamma_Bottom: 10,

  • Right boundary Gamma_Right: 11,

  • Top boundary Gamma_Top: 12,

  • Left boundary Gamma_Left: 13

Args:
  • parameters (dict): The dictionary of parameters for the geometry

  • refine (int): Ask for iterative refinements by splitting elements

  • terminal (int): An option to print meshing infos in the prompt, value 0 (quiet) or 1 (verbose, default)

Returns:

list[gf.Mesh, int, dict, dict]: The mesh to use with getfem, the dimension, a dict of regions with getfem indices for dim n and a dict of regions with getfem indices for dim n-1

scrimp.utils.mesh.built_in_geometries()

A function to get all the infos about available built_in geometries