13 using namespace MoFEM;
34 GAUSS>::OpGradSymTensorGrad<1, SPACE_DIM, SPACE_DIM, 0>;
38 double rho = 7829e-12;
84 auto set_matrial_stiffens = [&]() {
91 auto t_D = getFTensor4DdgFromMat<SPACE_DIM, SPACE_DIM, 0>(*matDPtr);
104 matDPtr = boost::make_shared<MatrixDouble>();
109 CHKERR set_matrial_stiffens();
120 CHKERR createCommonData();
121 CHKERR boundaryCondition();
163 for (
int n = 1;
n != 6; ++
n)
167 auto problem_ptr = mField.get_problem(
simple->getProblemName());
168 auto dofs = problem_ptr->getNumeredRowDofsPtr();
171 const auto bit_number = mField.get_field_bit_number(
"U");
177 auto hi = dofs->upper_bound(lo_uid);
178 std::array<double, 3> coords;
180 for (
auto lo = dofs->lower_bound(lo_uid); lo != hi; ++lo) {
182 if ((*lo)->getPart() == mField.get_comm_rank()) {
184 auto ent = (*lo)->getEnt();
185 CHKERR mField.get_moab().get_coords(&ent, 1, coords.data());
187 if ((*lo)->getDofCoeffIdx() == 0) {
188 CHKERR VecSetValue(rigidBodyMotion[0], (*lo)->getPetscGlobalDofIdx(), 1,
190 CHKERR VecSetValue(rigidBodyMotion[3], (*lo)->getPetscGlobalDofIdx(),
191 -coords[1], INSERT_VALUES);
193 CHKERR VecSetValue(rigidBodyMotion[4], (*lo)->getPetscGlobalDofIdx(),
194 -coords[2], INSERT_VALUES);
196 }
else if ((*lo)->getDofCoeffIdx() == 1) {
197 CHKERR VecSetValue(rigidBodyMotion[1], (*lo)->getPetscGlobalDofIdx(), 1,
199 CHKERR VecSetValue(rigidBodyMotion[3], (*lo)->getPetscGlobalDofIdx(),
200 coords[0], INSERT_VALUES);
202 CHKERR VecSetValue(rigidBodyMotion[5], (*lo)->getPetscGlobalDofIdx(),
203 -coords[2], INSERT_VALUES);
205 }
else if ((*lo)->getDofCoeffIdx() == 2) {
207 CHKERR VecSetValue(rigidBodyMotion[2], (*lo)->getPetscGlobalDofIdx(),
209 CHKERR VecSetValue(rigidBodyMotion[4], (*lo)->getPetscGlobalDofIdx(),
210 coords[0], INSERT_VALUES);
211 CHKERR VecSetValue(rigidBodyMotion[5], (*lo)->getPetscGlobalDofIdx(),
212 coords[1], INSERT_VALUES);
218 for (
int n = 0;
n != rigidBodyMotion.size(); ++
n) {
219 CHKERR VecAssemblyBegin(rigidBodyMotion[
n]);
220 CHKERR VecAssemblyEnd(rigidBodyMotion[
n]);
221 CHKERR VecGhostUpdateBegin(rigidBodyMotion[
n], INSERT_VALUES,
223 CHKERR VecGhostUpdateEnd(rigidBodyMotion[
n], INSERT_VALUES,
237 auto dm =
simple->getDM();
241 auto calculate_stiffness_matrix = [&]() {
243 pipeline_mng->getDomainLhsFE().reset();
245 auto det_ptr = boost::make_shared<VectorDouble>();
246 auto jac_ptr = boost::make_shared<MatrixDouble>();
247 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
248 pipeline_mng->getOpDomainLhsPipeline().push_back(
250 pipeline_mng->getOpDomainLhsPipeline().push_back(
252 pipeline_mng->getOpDomainLhsPipeline().push_back(
254 pipeline_mng->getOpDomainLhsPipeline().push_back(
257 pipeline_mng->getOpDomainLhsPipeline().push_back(
258 new OpK(
"U",
"U", matDPtr));
264 pipeline_mng->getDomainLhsFE()->B =
K;
266 CHKERR pipeline_mng->loopFiniteElements();
267 CHKERR MatAssemblyBegin(
K, MAT_FINAL_ASSEMBLY);
268 CHKERR MatAssemblyEnd(
K, MAT_FINAL_ASSEMBLY);
272 auto calculate_mass_matrix = [&]() {
274 pipeline_mng->getDomainLhsFE().reset();
276 auto det_ptr = boost::make_shared<VectorDouble>();
277 auto jac_ptr = boost::make_shared<MatrixDouble>();
278 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
279 pipeline_mng->getOpDomainLhsPipeline().push_back(
281 pipeline_mng->getOpDomainLhsPipeline().push_back(
283 pipeline_mng->getOpDomainLhsPipeline().push_back(
287 pipeline_mng->getOpDomainLhsPipeline().push_back(
288 new OpMass(
"U",
"U", get_rho));
294 pipeline_mng->getDomainLhsFE()->B =
M;
295 CHKERR pipeline_mng->loopFiniteElements();
296 CHKERR MatAssemblyBegin(
M, MAT_FINAL_ASSEMBLY);
297 CHKERR MatAssemblyEnd(
M, MAT_FINAL_ASSEMBLY);
301 CHKERR calculate_stiffness_matrix();
302 CHKERR calculate_mass_matrix();
314 auto create_eps = [](MPI_Comm comm) {
320 auto deflate_vectors = [&]() {
323 std::array<Vec, 6> deflate_vectors;
324 for (
int n = 0;
n != 6; ++
n) {
325 deflate_vectors[
n] = rigidBodyMotion[
n];
327 CHKERR EPSSetDeflationSpace(ePS, 6, &deflate_vectors[0]);
331 auto print_info = [&]() {
336 PetscInt nev, maxit, its;
338 CHKERR EPSGetIterationNumber(ePS, &its);
340 " Number of iterations of the method: %d", its);
341 CHKERR EPSGetST(ePS, &st);
344 CHKERR EPSGetDimensions(ePS, &nev, NULL, NULL);
345 MOFEM_LOG_C(
"EXAMPLE", Sev::inform,
" Number of requested eigenvalues: %d",
347 CHKERR EPSGetTolerances(ePS, &
tol, &maxit);
349 " Stopping condition: tol=%.4g, maxit=%d", (
double)
tol, maxit);
351 PetscScalar eigr, eigi;
352 for (
int nn = 0; nn < nev; nn++) {
353 CHKERR EPSGetEigenpair(ePS, nn, &eigr, &eigi, PETSC_NULL, PETSC_NULL);
355 " ncov = %d eigr = %.4g eigi = %.4g (inv eigr = %.4g)", nn,
356 eigr, eigi, 1. / eigr);
362 auto setup_eps = [&]() {
364 CHKERR EPSSetProblemType(ePS, EPS_GHEP);
365 CHKERR EPSSetWhichEigenpairs(ePS, EPS_SMALLEST_MAGNITUDE);
366 CHKERR EPSSetFromOptions(ePS);
371 ePS = create_eps(mField.get_comm());
396 pipeline_mng->getDomainLhsFE().reset();
397 auto post_proc_fe = boost::make_shared<PostProcEle>(mField);
399 auto det_ptr = boost::make_shared<VectorDouble>();
400 auto jac_ptr = boost::make_shared<MatrixDouble>();
401 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
402 post_proc_fe->getOpPtrVector().push_back(
404 post_proc_fe->getOpPtrVector().push_back(
406 post_proc_fe->getOpPtrVector().push_back(
409 auto u_ptr = boost::make_shared<MatrixDouble>();
410 auto grad_ptr = boost::make_shared<MatrixDouble>();
411 auto strain_ptr = boost::make_shared<MatrixDouble>();
412 auto stress_ptr = boost::make_shared<MatrixDouble>();
414 post_proc_fe->getOpPtrVector().push_back(
416 post_proc_fe->getOpPtrVector().push_back(
418 post_proc_fe->getOpPtrVector().push_back(
420 post_proc_fe->getOpPtrVector().push_back(
422 "U", strain_ptr, stress_ptr, matDPtr));
426 post_proc_fe->getOpPtrVector().push_back(
429 post_proc_fe->getPostProcMesh(), post_proc_fe->getMapGaussPts(),
443 pipeline_mng->getDomainRhsFE() = post_proc_fe;
445 auto dm =
simple->getDM();
449 CHKERR EPSGetDimensions(ePS, &nev, NULL, NULL);
450 PetscScalar eigr, eigi, nrm2r;
451 for (
int nn = 0; nn < nev; nn++) {
452 CHKERR EPSGetEigenpair(ePS, nn, &eigr, &eigi,
D, PETSC_NULL);
453 CHKERR VecGhostUpdateBegin(
D, INSERT_VALUES, SCATTER_FORWARD);
454 CHKERR VecGhostUpdateEnd(
D, INSERT_VALUES, SCATTER_FORWARD);
455 CHKERR VecNorm(
D, NORM_2, &nrm2r);
457 " ncov = %d omega2 = %.8g omega = %.8g frequency = %.8g", nn,
458 eigr, std::sqrt(std::abs(eigr)),
459 std::sqrt(std::abs(eigr)) / (2 * M_PI));
461 CHKERR pipeline_mng->loopFiniteElements();
462 post_proc_fe->writeFile(
"out_eig_" + boost::lexical_cast<std::string>(nn) +
473 PetscBool test_flg = PETSC_FALSE;
476 PetscScalar eigr, eigi;
477 CHKERR EPSGetEigenpair(
ePS, 0, &eigr, &eigi, PETSC_NULL, PETSC_NULL);
478 constexpr
double regression_value = 12579658;
479 if (fabs(eigr - regression_value) > 1)
481 "Regression test faileed; wrong eigen value.");
487 static char help[] =
"...\n\n";
489 int main(
int argc,
char *argv[]) {
492 const char param_file[] =
"param_file.petsc";
493 SlepcInitialize(&argc, &argv, param_file,
help);
497 auto core_log = logging::core::get();
499 LogManager::createSink(LogManager::getStrmWorld(),
"EXAMPLE"));
500 LogManager::setLog(
"EXAMPLE");
506 DMType dm_name =
"DMMOFEM";