v0.16.0
Loading...
Searching...
No Matches
Classes | Enumerations | Functions | Variables
affine_tet_stress_gram.cpp File Reference

One-tetrahedron diagnostic for the EP stress block. More...

#include <MoFEM.hpp>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
#include <numeric>
#include <sstream>
#include <string>
#include <vector>
#include <MatOps.hpp>
#include <MatElastic.hpp>
#include <EshelbianPlasticity.hpp>

Go to the source code of this file.

Classes

struct  RankDiagnostic
 Stores a short rank summary for the assembled matrix. More...
 

Enumerations

enum class  DiagnosticMatrixType { GRAM , A00 }
 Selects which diagnostic matrix is assembled. More...
 

Functions

static MoFEMErrorCode getDiagnosticMatrixType (DiagnosticMatrixType &type)
 Reads -diag_matrix_type from PETSc options.
 
static const char * getDiagnosticMatrixTypeName (DiagnosticMatrixType type)
 Returns the PETSc option name for a diagnostic matrix type.
 
static MoFEMErrorCode createAffineTet (moab::Interface &moab, EntityHandle &meshset)
 Creates one unit affine tetrahedron mesh.
 
static MoFEMErrorCode getDenseMatrix (Mat A, MatrixDouble &dense)
 Copies a PETSc matrix into a dense uBLAS matrix.
 
static MoFEMErrorCode printDenseMatrix (const MatrixDouble &dense)
 Prints a dense matrix row by row.
 
static MoFEMErrorCode computeRankDiagnostic (const MatrixDouble &dense, const double rel_rank_tol, RankDiagnostic &rank_data)
 Computes rank from the smaller of A*A^T and A^T*A.
 
static MoFEMErrorCode analyseDenseStressBlock (const MatrixDouble &dense, const DiagnosticMatrixType matrix_type, const PetscBool include_bubble, const double rel_rank_tol, const PetscBool check_full_rank, const PetscBool view_matrix)
 Prints a compact rank summary for the assembled matrix.
 
static MoFEMErrorCode assembleStressDiagnostic (const DiagnosticMatrixType matrix_type, const PetscBool include_bubble, const double rel_rank_tol, const PetscBool check_full_rank, const PetscBool view_matrix)
 Builds the affine tet problem and assembles the diagnostic matrix.
 
int main (int argc, char *argv[])
 Parses options, sets logging, and runs the diagnostic.
 

Variables

constexpr int adolc_tag = 1
 
static char help []
 

Detailed Description

One-tetrahedron diagnostic for the EP stress block.

Definition in file affine_tet_stress_gram.cpp.

Enumeration Type Documentation

◆ DiagnosticMatrixType

enum class DiagnosticMatrixType
strong

Selects which diagnostic matrix is assembled.

Enumerator
GRAM 
A00 

Definition at line 36 of file affine_tet_stress_gram.cpp.

Function Documentation

◆ analyseDenseStressBlock()

static MoFEMErrorCode analyseDenseStressBlock ( const MatrixDouble dense,
const DiagnosticMatrixType  matrix_type,
const PetscBool  include_bubble,
const double  rel_rank_tol,
const PetscBool  check_full_rank,
const PetscBool  view_matrix 
)
static

Prints a compact rank summary for the assembled matrix.

Definition at line 231 of file affine_tet_stress_gram.cpp.

234 {
236
237 RankDiagnostic rank_data;
238 CHKERR computeRankDiagnostic(dense, rel_rank_tol, rank_data);
239
240 MOFEM_LOG("EP", Sev::inform)
241 << "diagnostic matrix type: " << getDiagnosticMatrixTypeName(matrix_type);
242 if (matrix_type == DiagnosticMatrixType::GRAM) {
243 MOFEM_LOG("EP", Sev::inform)
244 << "stress basis: " << (include_bubble ? "P+bubble" : "P");
245 } else {
246 MOFEM_LOG("EP", Sev::inform)
247 << "A00 fields: u, bubble, P, omega, wL2";
248 }
249 MOFEM_LOG("EP", Sev::inform)
250 << "matrix size: " << rank_data.rowsNb << " x " << rank_data.colsNb;
251 MOFEM_LOG("EP", Sev::inform)
252 << std::scientific << std::setprecision(16)
253 << "frobenius norm: " << rank_data.frobeniusNorm;
254 if (rank_data.rowsNb == rank_data.colsNb) {
255 MOFEM_LOG("EP", Sev::inform)
256 << std::scientific << std::setprecision(16)
257 << "symmetry defect ||A-A^T||_F: " << rank_data.symmetryDefect;
258 }
259 MOFEM_LOG("EP", Sev::inform)
260 << std::scientific << std::setprecision(16)
261 << "relative rank tolerance: " << rel_rank_tol;
262 MOFEM_LOG("EP", Sev::inform)
263 << std::scientific << std::setprecision(16)
264 << "absolute singular tolerance: " << rank_data.absRankTol;
265 MOFEM_LOG("EP", Sev::inform)
266 << std::scientific << std::setprecision(16)
267 << "singular value range approx: [" << rank_data.minNonzeroSingular
268 << ", " << rank_data.maxSingular << "]";
269 MOFEM_LOG("EP", Sev::inform)
270 << "numerical rank: " << rank_data.rank << " / " << rank_data.maxRank;
271
272 if (view_matrix) {
273 MOFEM_LOG("EP", Sev::inform) << "dense diagnostic matrix:";
275 }
276
277 if (check_full_rank && rank_data.rank != rank_data.maxRank) {
278 SETERRQ(PETSC_COMM_SELF, MOFEM_DATA_INCONSISTENCY,
279 "%s diagnostic block is rank deficient: rank %zu / %zu",
280 getDiagnosticMatrixTypeName(matrix_type), rank_data.rank,
281 rank_data.maxRank);
282 }
283
285}
static const char * getDiagnosticMatrixTypeName(DiagnosticMatrixType type)
Returns the PETSc option name for a diagnostic matrix type.
static MoFEMErrorCode computeRankDiagnostic(const MatrixDouble &dense, const double rel_rank_tol, RankDiagnostic &rank_data)
Computes rank from the smaller of A*A^T and A^T*A.
static MoFEMErrorCode printDenseMatrix(const MatrixDouble &dense)
Prints a dense matrix row by row.
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
#define CHKERR
Inline error check.
#define MOFEM_LOG(channel, severity)
Log.
Stores a short rank summary for the assembled matrix.

◆ assembleStressDiagnostic()

static MoFEMErrorCode assembleStressDiagnostic ( const DiagnosticMatrixType  matrix_type,
const PetscBool  include_bubble,
const double  rel_rank_tol,
const PetscBool  check_full_rank,
const PetscBool  view_matrix 
)
static

Builds the affine tet problem and assembles the diagnostic matrix.

Definition at line 288 of file affine_tet_stress_gram.cpp.

291 {
293
294 int comm_size = 0;
295 MPI_Comm_size(PETSC_COMM_WORLD, &comm_size);
296 if (comm_size != 1) {
297 SETERRQ(PETSC_COMM_WORLD, MOFEM_NOT_IMPLEMENTED,
298 "affine_tet_stress_gram is a serial diagnostic; run with -np 1");
299 }
300
301 DMType dm_name = "DMMOFEM";
302 CHKERR DMRegister_MoFEM(dm_name);
303
304 moab::Core moab_core;
305 moab::Interface &moab = moab_core;
306 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
307 if (pcomm == nullptr) {
308 pcomm = new ParallelComm(&moab, PETSC_COMM_SELF);
309 }
310
311 EntityHandle meshset;
312 CHKERR createAffineTet(moab, meshset);
313
314 MoFEM::Core mofem_core(moab, PETSC_COMM_SELF, -2);
315 MoFEM::Interface &m_field = mofem_core;
316
317 BitRefLevel bit_level0 = BitRefLevel().set(0);
318 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
319 meshset, 3, bit_level0);
320
322 EshelbianCore ep(m_field);
323
324 ep.bcSpatialDispVecPtr = boost::make_shared<BcDispVec>();
325 ep.bcSpatialRotationVecPtr = boost::make_shared<BcRotVec>();
326 ep.bcSpatialTractionVecPtr = boost::make_shared<TractionBcVec>();
327 ep.bcSpatialAnalyticalTractionVecPtr =
328 boost::make_shared<AnalyticalTractionBcVec>();
329 ep.bcSpatialPressureVecPtr = boost::make_shared<PressureBcVec>();
330 ep.bcSpatialNormalDisplacementVecPtr =
331 boost::make_shared<NormalDisplacementBcVec>();
332 ep.bcSpatialAnalyticalDisplacementVecPtr =
333 boost::make_shared<AnalyticalDisplacementBcVec>();
334 ep.externalStrainVecPtr = boost::make_shared<ExternalStrainVec>();
335 ep.bcSpatialFreeTractionVecPtr = boost::make_shared<TractionFreeBc>();
336 CHKERR ep.getTractionFreeBc(meshset, ep.bcSpatialFreeTractionVecPtr,
337 "CONTACT");
338
339 CHKERR ep.addFields(meshset, include_bubble);
340 CHKERR ep.projectGeometry(meshset, 0.0);
341 CHKERR ep.addVolumeFiniteElement(meshset, include_bubble);
342 CHKERR m_field.build_adjacencies(bit_level0, QUIET);
343
344 auto dm = createDM(m_field.get_comm(), "DMMOFEM");
345 CHKERR DMMoFEMCreateMoFEM(dm, &m_field, "AFFINE_TET_EP", bit_level0,
346 BitRefLevel().set());
347 CHKERR DMMoFEMSetDestroyProblem(dm, PETSC_TRUE);
348 CHKERR DMMoFEMSetSquareProblem(dm, PETSC_TRUE);
349 CHKERR DMMoFEMSetIsPartitioned(dm, PETSC_FALSE);
350 CHKERR DMMoFEMAddElement(dm, ep.elementVolumeName);
351 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_TRUE;
352 CHKERR DMSetUp(dm);
353 m_field.getInterface<ProblemsManager>()->buildProblemFromFields = PETSC_FALSE;
354
355 ep.solTSStep = createDMVector(dm);
356 CHKERR VecZeroEntries(ep.solTSStep);
357
358 auto diag_dm = createDM(m_field.get_comm(), "DMMOFEM");
359 CHKERR DMMoFEMCreateSubDM(diag_dm, dm, "AFFINE_TET_STRESS_DIAG");
360 CHKERR DMMoFEMSetDestroyProblem(diag_dm, PETSC_TRUE);
361 CHKERR DMMoFEMSetSquareProblem(diag_dm, PETSC_TRUE);
362 CHKERR DMMoFEMSetIsPartitioned(diag_dm, PETSC_FALSE);
363 CHKERR DMMoFEMAddElement(diag_dm, ep.elementVolumeName);
364
365 switch (matrix_type) {
367 CHKERR DMMoFEMAddSubFieldRow(diag_dm, ep.piolaStress);
368 CHKERR DMMoFEMAddSubFieldCol(diag_dm, ep.piolaStress);
369 if (include_bubble) {
370 CHKERR DMMoFEMAddSubFieldRow(diag_dm, ep.bubbleField);
371 CHKERR DMMoFEMAddSubFieldCol(diag_dm, ep.bubbleField);
372 }
373 break;
375 if (!include_bubble) {
376 SETERRQ(PETSC_COMM_SELF, MOFEM_NOT_IMPLEMENTED,
377 "P-only diagnostic is implemented for -diag_matrix_type gram");
378 }
379 for (const auto field_name : {ep.stretchTensor, ep.bubbleField,
380 ep.piolaStress, ep.rotAxis,
381 ep.spatialL2Disp}) {
384 }
385 break;
386 }
387 CHKERR DMSetUp(diag_dm);
388
389 CHKERR ep.addMaterial_Hencky(5.0, 0.25);
390
391 auto fe_lhs = boost::make_shared<VolumeElementForcesAndSourcesCore>(m_field);
392 CHKERR ep.setBaseVolumeElementOps(adolc_tag, false, true, false, fe_lhs,
393 include_bubble);
394 switch (matrix_type) {
396 if (include_bubble) {
397 CHKERR ep.pushStressGramOps(fe_lhs);
398 } else {
399 CHKERR ep.pushPiolaStressGramOps(fe_lhs);
400 }
401 break;
404 CHKERR ep.pushNoStretchVolumeA00Ops(fe_lhs);
405 } else {
406 CHKERR ep.pushStretchVolumeA00Ops(fe_lhs);
407 }
408 break;
409 }
410
411 auto A = createDMMatrix(diag_dm);
412 CHKERR MatZeroEntries(A);
413 fe_lhs->ksp_B = A;
414 fe_lhs->ts_A = A;
415 fe_lhs->ts_B = A;
416 fe_lhs->ts_u = ep.solTSStep;
417 fe_lhs->ts_u_t = ep.solTSStep;
418 fe_lhs->ts_a = 0.0;
419 fe_lhs->data_ctx = PetscData::CtxSetA | PetscData::CtxSetB |
421 CHKERR DMoFEMLoopFiniteElements(diag_dm, ep.elementVolumeName, fe_lhs);
422 CHKERR MatAssemblyBegin(A, MAT_FINAL_ASSEMBLY);
423 CHKERR MatAssemblyEnd(A, MAT_FINAL_ASSEMBLY);
424
425 MatrixDouble dense;
426 CHKERR getDenseMatrix(A, dense);
427
428 CHKERR analyseDenseStressBlock(dense, matrix_type, include_bubble,
429 rel_rank_tol, check_full_rank, view_matrix);
430
432}
static MoFEMErrorCode analyseDenseStressBlock(const MatrixDouble &dense, const DiagnosticMatrixType matrix_type, const PetscBool include_bubble, const double rel_rank_tol, const PetscBool check_full_rank, const PetscBool view_matrix)
Prints a compact rank summary for the assembled matrix.
static MoFEMErrorCode getDenseMatrix(Mat A, MatrixDouble &dense)
Copies a PETSc matrix into a dense uBLAS matrix.
static MoFEMErrorCode createAffineTet(moab::Interface &moab, EntityHandle &meshset)
Creates one unit affine tetrahedron mesh.
constexpr int adolc_tag
@ QUIET
#define MYPCOMM_INDEX
default communicator number PCOMM
@ MOFEM_NOT_IMPLEMENTED
Definition definitions.h:32
PetscErrorCode DMMoFEMSetIsPartitioned(DM dm, PetscBool is_partitioned)
Definition DMMoFEM.cpp:1113
PetscErrorCode DMMoFEMCreateSubDM(DM subdm, DM dm, const char problem_name[])
Must be called by user to set Sub DM MoFEM data structures.
Definition DMMoFEM.cpp:215
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
Definition DMMoFEM.cpp:488
PetscErrorCode DMMoFEMSetSquareProblem(DM dm, PetscBool square_problem)
set squared problem
Definition DMMoFEM.cpp:450
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
Definition DMMoFEM.cpp:114
PetscErrorCode DMMoFEMAddSubFieldRow(DM dm, const char field_name[])
Definition DMMoFEM.cpp:238
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
PetscErrorCode DMoFEMLoopFiniteElements(DM dm, const char fe_name[], MoFEM::FEMethod *method, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr())
Executes FEMethod for finite elements in DM.
Definition DMMoFEM.cpp:576
auto createDMVector(DM dm, RowColData rc=RowColData::COL)
Get smart vector from DM.
Definition DMMoFEM.hpp:1237
PetscErrorCode DMMoFEMAddSubFieldCol(DM dm, const char field_name[])
Definition DMMoFEM.cpp:280
auto createDMMatrix(DM dm)
Get smart matrix from DM.
Definition DMMoFEM.hpp:1194
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscErrorCode DMMoFEMSetDestroyProblem(DM dm, PetscBool destroy_problem)
Definition DMMoFEM.cpp:434
auto createDM(MPI_Comm comm, const std::string dm_type_name)
Creates smart DM object.
constexpr AssemblyType A
constexpr auto field_name
static enum StretchHandling stretchHandling
static bool hasNonHomogeneousMaterialBlock
Managing BitRefLevels.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MPI_Comm & get_comm() const =0
Core (interface) class.
Definition Core.hpp:83
Deprecated interface functions.
static constexpr Switches CtxSetA
Jacobian matrix switch.
static constexpr Switches CtxSetX
Solution vector switch.
static constexpr Switches CtxSetX_T
First time derivative switch.
static constexpr Switches CtxSetB
Preconditioner matrix switch.
Problem manager is used to build and partition problems.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.

◆ computeRankDiagnostic()

static MoFEMErrorCode computeRankDiagnostic ( const MatrixDouble dense,
const double  rel_rank_tol,
RankDiagnostic rank_data 
)
static

Computes rank from the smaller of A*A^T and A^T*A.

Definition at line 154 of file affine_tet_stress_gram.cpp.

156 {
158
159 rank_data.rowsNb = dense.size1();
160 rank_data.colsNb = dense.size2();
161 rank_data.maxRank = std::min(rank_data.rowsNb, rank_data.colsNb);
162
163 for (size_t rr = 0; rr != rank_data.rowsNb; ++rr) {
164 for (size_t cc = 0; cc != rank_data.colsNb; ++cc) {
165 const double a = dense(rr, cc);
166 rank_data.frobeniusNorm += a * a;
167 if (rank_data.rowsNb == rank_data.colsNb) {
168 const double d = a - dense(cc, rr);
169 rank_data.symmetryDefect += d * d;
170 }
171 }
172 }
173 rank_data.frobeniusNorm = std::sqrt(rank_data.frobeniusNorm);
174 rank_data.symmetryDefect = std::sqrt(rank_data.symmetryDefect);
175
176 if (!rank_data.maxRank)
178
179 const bool use_row_gram = rank_data.rowsNb <= rank_data.colsNb;
180 MatrixDouble gram(rank_data.maxRank, rank_data.maxRank);
181 gram.clear();
182
183 if (use_row_gram) {
184 for (size_t ii = 0; ii != rank_data.rowsNb; ++ii) {
185 for (size_t jj = ii; jj != rank_data.rowsNb; ++jj) {
186 double value = 0;
187 for (size_t cc = 0; cc != rank_data.colsNb; ++cc)
188 value += dense(ii, cc) * dense(jj, cc);
189 gram(ii, jj) = value;
190 gram(jj, ii) = value;
191 }
192 }
193 } else {
194 for (size_t ii = 0; ii != rank_data.colsNb; ++ii) {
195 for (size_t jj = ii; jj != rank_data.colsNb; ++jj) {
196 double value = 0;
197 for (size_t rr = 0; rr != rank_data.rowsNb; ++rr)
198 value += dense(rr, ii) * dense(rr, jj);
199 gram(ii, jj) = value;
200 gram(jj, ii) = value;
201 }
202 }
203 }
204
205 VectorDouble eig(rank_data.maxRank);
206 MatrixDouble eig_vec(rank_data.maxRank, rank_data.maxRank);
207 CHKERR computeEigenValuesSymmetric(gram, eig, eig_vec);
208
209 double max_eig = 0;
210 for (size_t ii = 0; ii != rank_data.maxRank; ++ii)
211 max_eig = std::max(max_eig, std::abs(eig(ii)));
212 rank_data.maxSingular = std::sqrt(std::max(max_eig, 0.0));
213 rank_data.absRankTol =
214 rel_rank_tol * std::max(rank_data.maxSingular, 1.0);
215
216 const double eig_abs_tol = rank_data.absRankTol * rank_data.absRankTol;
217 double min_nonzero = std::numeric_limits<double>::max();
218 for (size_t ii = 0; ii != rank_data.maxRank; ++ii) {
219 const double a = std::abs(eig(ii));
220 if (a > eig_abs_tol) {
221 ++rank_data.rank;
222 min_nonzero = std::min(min_nonzero, std::sqrt(a));
223 }
224 }
225 rank_data.minNonzeroSingular = rank_data.rank ? min_nonzero : 0.0;
226
228}
constexpr double a
#define MoFEMFunctionReturnHot(a)
Last executable line of each PETSc function used for error handling. Replaces return()
MoFEMErrorCode computeEigenValuesSymmetric(const MatrixDouble &mat, VectorDouble &eig, MatrixDouble &eigen_vec)
compute eigenvalues of a symmetric matrix using lapack dsyev

◆ createAffineTet()

static MoFEMErrorCode createAffineTet ( moab::Interface &  moab,
EntityHandle meshset 
)
static

Creates one unit affine tetrahedron mesh.

Definition at line 86 of file affine_tet_stress_gram.cpp.

87 {
89
90 double tet_coords[] = {0, 0, 0, 1.0, 0, 0,
91 0, 1.0, 0, 0, 0, 1.0};
92 EntityHandle nodes[4];
93 for (int nn = 0; nn < 4; nn++) {
94 CHKERR moab.create_vertex(&tet_coords[3 * nn], nodes[nn]);
95 }
96
97 EntityHandle tet;
98 CHKERR moab.create_element(MBTET, nodes, 4, tet);
99 CHKERR moab.create_meshset(MESHSET_SET | MESHSET_TRACK_OWNER, meshset);
100
101 Range tets;
102 tets.insert(tet);
103 CHKERR moab.add_entities(meshset, tets);
104 for (int dim = 0; dim != 3; ++dim) {
105 Range adj;
106 CHKERR moab.get_adjacencies(tets, dim, true, adj,
107 moab::Interface::UNION);
108 CHKERR moab.add_entities(meshset, adj);
109 }
110
112}

◆ getDenseMatrix()

static MoFEMErrorCode getDenseMatrix ( Mat  A,
MatrixDouble dense 
)
static

Copies a PETSc matrix into a dense uBLAS matrix.

Definition at line 115 of file affine_tet_stress_gram.cpp.

115 {
117
118 PetscInt rows_nb, cols_nb;
119 CHKERR MatGetSize(A, &rows_nb, &cols_nb);
120 dense.resize(rows_nb, cols_nb, false);
121 dense.clear();
122
123 std::vector<PetscInt> rows(rows_nb), cols(cols_nb);
124 std::iota(rows.begin(), rows.end(), 0);
125 std::iota(cols.begin(), cols.end(), 0);
126
127 std::vector<PetscScalar> values(rows_nb * cols_nb, 0);
128 CHKERR MatGetValues(A, rows_nb, rows.data(), cols_nb, cols.data(),
129 values.data());
130 for (PetscInt rr = 0; rr != rows_nb; ++rr) {
131 for (PetscInt cc = 0; cc != cols_nb; ++cc) {
132 dense(rr, cc) = PetscRealPart(values[rr * cols_nb + cc]);
133 }
134 }
135
137}

◆ getDiagnosticMatrixType()

static MoFEMErrorCode getDiagnosticMatrixType ( DiagnosticMatrixType type)
static

Reads -diag_matrix_type from PETSc options.

Definition at line 39 of file affine_tet_stress_gram.cpp.

39 {
41
42 char matrix_type[32] = "gram";
43 CHKERR PetscOptionsGetString(PETSC_NULLPTR, "", "-diag_matrix_type",
44 matrix_type, sizeof(matrix_type),
45 PETSC_NULLPTR);
46 const std::string type_name(matrix_type);
47
48 if (type_name == "gram") {
50 } else if (type_name == "a00") {
52 } else {
53 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
54 "Unknown -diag_matrix_type '%s'; use 'gram' or 'a00'",
55 matrix_type);
56 }
57
59}
std::string type
@ MOFEM_INVALID_DATA
Definition definitions.h:36
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)

◆ getDiagnosticMatrixTypeName()

static const char * getDiagnosticMatrixTypeName ( DiagnosticMatrixType  type)
static

Returns the PETSc option name for a diagnostic matrix type.

Definition at line 62 of file affine_tet_stress_gram.cpp.

62 {
63 switch (type) {
65 return "gram";
67 return "a00";
68 }
69 return "unknown";
70}

◆ main()

int main ( int  argc,
char *  argv[] 
)

Parses options, sets logging, and runs the diagnostic.

Definition at line 435 of file affine_tet_stress_gram.cpp.

435 {
436 MoFEM::Core::Initialize(&argc, &argv, (char *)0, help);
437
438 auto core_log = logging::core::get();
439 core_log->add_sink(LogManager::createSink(LogManager::getStrmWorld(), "EP"));
440 LogManager::setLog("EP");
441 MOFEM_LOG_TAG("EP", "affine_tet_stress_gram");
442 core_log->add_sink(
444 LogManager::setLog("EPSELF");
445 MOFEM_LOG_TAG("EPSELF", "affine_tet_stress_gram");
446 core_log->add_sink(
448 LogManager::setLog("EPSYNC");
449 MOFEM_LOG_TAG("EPSYNC", "affine_tet_stress_gram");
450
451 try {
452 PetscBool view_matrix = PETSC_FALSE;
453 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-diag_view_matrix",
454 &view_matrix, PETSC_NULLPTR);
455 double rel_rank_tol = 1e-10;
456 CHKERR PetscOptionsGetReal(PETSC_NULLPTR, "", "-diag_rank_tol",
457 &rel_rank_tol, PETSC_NULLPTR);
458 PetscBool check_full_rank = PETSC_FALSE;
459 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-diag_check_full_rank",
460 &check_full_rank, PETSC_NULLPTR);
461 PetscBool include_bubble = PETSC_TRUE;
462 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-diag_include_bubble",
463 &include_bubble, PETSC_NULLPTR);
464 DiagnosticMatrixType matrix_type;
465 CHKERR getDiagnosticMatrixType(matrix_type);
466 CHKERR assembleStressDiagnostic(matrix_type, include_bubble, rel_rank_tol,
467 check_full_rank, view_matrix);
468 }
470
472 return 0;
473}
static MoFEMErrorCode getDiagnosticMatrixType(DiagnosticMatrixType &type)
Reads -diag_matrix_type from PETSc options.
static char help[]
static MoFEMErrorCode assembleStressDiagnostic(const DiagnosticMatrixType matrix_type, const PetscBool include_bubble, const double rel_rank_tol, const PetscBool check_full_rank, const PetscBool view_matrix)
Builds the affine tet problem and assembles the diagnostic matrix.
DiagnosticMatrixType
Selects which diagnostic matrix is assembled.
#define CATCH_ERRORS
Catch errors.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
PetscErrorCode PetscOptionsGetReal(PetscOptions *, const char pre[], const char name[], PetscReal *dval, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:68
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:123
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmWorld()
Get the strm world object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
static boost::shared_ptr< std::ostream > getStrmSelf()
Get the strm self object.

◆ printDenseMatrix()

static MoFEMErrorCode printDenseMatrix ( const MatrixDouble dense)
static

Prints a dense matrix row by row.

Definition at line 140 of file affine_tet_stress_gram.cpp.

140 {
142 for (size_t rr = 0; rr != dense.size1(); ++rr) {
143 std::ostringstream line;
144 line << std::scientific << std::setprecision(16);
145 for (size_t cc = 0; cc != dense.size2(); ++cc) {
146 line << (cc ? " " : "") << dense(rr, cc);
147 }
148 MOFEM_LOG("EP", Sev::inform) << line.str();
149 }
151}

Variable Documentation

◆ adolc_tag

constexpr int adolc_tag = 1
constexpr

◆ help

char help[]
static
Initial value:
=
"Assemble EP P+bubble stress diagnostics on one affine tet.\n"
" -diag_matrix_type gram|a00\n"
" -diag_include_bubble true|false\n"
" -diag_rank_tol <real>\n"
" -diag_check_full_rank true|false\n"
" -diag_view_matrix true|false\n"
" -broken_hdiv_base demkowicz|ainsworth\n\n"

Definition at line 26 of file affine_tet_stress_gram.cpp.