15#include "libmesh/nonlinear_solver.h"
16#include "libmesh/nonlinear_implicit_system.h"
17#include "libmesh/petsc_matrix.h"
29 "The petsc binary mat file containing the matrix. If this "
30 "parameter is not provided, then the system matrix is used");
32 "symmetry_tol", 1e-8,
"The tolerance (both relative and absolute) for comparing symmetry");
36 "A binary file may contain multiple writes of a matrix. This parameter can be used to load a "
37 "particular matrix from the binary file. By default we load the first written matrix");
43 _mat_from_file(isParamValid(
"mat")),
44 _mat_file_name(_mat_from_file ? getParam<
std::string>(
"mat") :
""),
45 _symm_tol(getParam<Real>(
"symmetry_tol")),
46 _mat_number_to_load(getParam<unsigned
int>(
"mat_number_to_load")),
51 "This parameter should only be set in conjunction with the 'mat' parameter");
59 const SparseMatrix<Number> * mat;
63 std::unique_ptr<SparseMatrix<Number>> file_mat_wrapper;
68 mat = file_mat_wrapper.get();
73 mooseAssert(nl_solver,
"This should be non-null");
74 auto & sys_mat = nl_solver->system().get_system_matrix();
78 for (
const auto i : make_range(mat->row_start(), mat->row_stop()))
79 for (
const auto j : make_range(mat->col_start(), mat->col_stop()))
81 const auto val1 = (*mat)(i, j);
82 const auto val2 = (*mat)(j, i);
83 if (!MooseUtils::relativeFuzzyEqual(val1, val2,
_symm_tol) &&
84 !MooseUtils::absoluteFuzzyEqual(val1, val2,
_symm_tol))
registerMooseObject("MooseApp", MatrixSymmetryCheck)
void ErrorVector unsigned int
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
This class is here to combine the Postprocessor interface and the base class Postprocessor object alo...
static InputParameters validParams()
Checks whether the nonlinear system matrix is symmetric.
static InputParameters validParams()
const Real _symm_tol
Tolerance for the comparison between coefficients and transpose counterparts.
const bool _mat_from_file
Whether the matrix we are checking for symmetry is from a file.
const unsigned int _mat_number_to_load
A binary file may contain multiple writes of a matrix.
virtual Real getValue() const override
This will get called to actually grab the final value the postprocessor has calculated.
bool _equiv
Whether the matrix is symmetric.
const std::string _mat_file_name
The matrix from file name. Empty string if _mat_from_file is false.
MatrixSymmetryCheck(const InputParameters ¶meters)
virtual void execute() override
Execute method.
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
void min(const T &r, T &o, Request &req) const
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
const Parallel::Communicator & _communicator
std::unique_ptr< PetscMatrix< Number > > createMatrixFromFile(const libMesh::Parallel::Communicator &comm, Mat &petsc_mat, const std::string &binary_mat_file, unsigned int mat_number_to_load=1)
Create a matrix from a binary file.