159int main(
int argc,
char *argv[]) {
161 const string default_options =
"-ksp_type fgmres \n"
163 "-pc_factor_mat_solver_type mumps\n"
164 "-mat_mumps_icntl_20 0\n"
169 "-snes_type newtonls \n"
170 "-snes_linesearch_type l2 \n"
171 "-snes_linesearch_monitor \n"
175 "-snes_converged_reason \n";
177 string param_file =
"param_file.petsc";
178 if (!
static_cast<bool>(ifstream(param_file))) {
179 std::ofstream file(param_file.c_str(), std::ios::ate);
180 if (file.is_open()) {
181 file << default_options;
189 moab::Core mb_instance;
190 moab::Interface &moab = mb_instance;
192 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
195 PetscBool flg = PETSC_TRUE;
199 if (flg != PETSC_TRUE) {
201 "*** ERROR -my_file (MESH FILE NEEDED)");
204 PetscScalar step_size_reduction;
206 &step_size_reduction, &flg);
207 if (flg != PETSC_TRUE) {
208 step_size_reduction = 1.;
214 if (flg != PETSC_TRUE) {
220 if (flg != PETSC_TRUE) {
227 if (flg != PETSC_TRUE) {
233 if (std::string(
mesh_file_name).find(
"restart") == std::string::npos) {
243 Tag th_step_size, th_step;
244 double def_step_size = 1;
245 rval = moab.tag_get_handle(
"_STEPSIZE", 1, MB_TYPE_DOUBLE, th_step_size,
246 MB_TAG_CREAT | MB_TAG_MESH, &def_step_size);
247 if (
rval == MB_ALREADY_ALLOCATED)
251 rval = moab.tag_get_handle(
"_STEP", 1, MB_TYPE_INTEGER, th_step,
252 MB_TAG_CREAT | MB_TAG_MESH, &def_step);
253 if (
rval == MB_ALREADY_ALLOCATED)
256 const void *tag_data_step_size[1];
258 CHKERR moab.tag_get_by_ptr(th_step_size, &root, 1, tag_data_step_size);
259 double &step_size = *(
double *)tag_data_step_size[0];
260 const void *tag_data_step[1];
261 CHKERR moab.tag_get_by_ptr(th_step, &root, 1, tag_data_step);
262 int &step = *(
int *)tag_data_step[0];
264 CHKERR PetscPrintf(PETSC_COMM_WORLD,
265 "Start step %D and step_size = %6.4e\n", step,
278 "_MY_REFINEMENT_LEVEL",
sizeof(
BitRefLevel), MB_TYPE_OPAQUE,
279 th_my_ref_level, MB_TAG_CREAT | MB_TAG_SPARSE | MB_TAG_BYTES,
283 CHKERR m_field.
get_moab().tag_get_by_ptr(th_my_ref_level, &root_meshset, 1,
284 (
const void **)&ptr_bit_level0);
294 std::vector<BitRefLevel> bit_levels;
301 CHKERR PetscPrintf(PETSC_COMM_WORLD,
"Insert Interface %d\n",
302 cit->getMeshsetId());
307 CHKERR moab.create_meshset(MESHSET_SET, ref_level_meshset);
309 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
313 ->getEntitiesByTypeAndRefLevel(bit_levels.back(),
316 Range ref_level_tets;
317 CHKERR moab.get_entities_by_handle(ref_level_meshset, ref_level_tets,
320 CHKERR interface_ptr->
getSides(cubit_meshset, bit_levels.back(),
true,
326 cubit_meshset,
true,
true, 0);
328 CHKERR moab.delete_entities(&ref_level_meshset, 1);
334 ->updateMeshsetByEntitiesChildren(cubit_meshset,
336 cubit_meshset, MBMAXTYPE,
true);
340 bit_level0 = bit_levels.back();
341 problem_bit_level = bit_level0;
368 "ELASTIC",
"MESH_NODE_POSITIONS");
383 "INTERFACE",
"MESH_NODE_POSITIONS");
422 problem_bit_level,
BitRefLevel().set(),
"ELASTIC", MBTET);
424 problem_bit_level,
BitRefLevel().set(),
"INTERFACE", MBPRISM);
431 const double coords[] = {0, 0, 0};
433 Range range_no_field_vertex;
434 range_no_field_vertex.insert(no_field_vertex);
440 range_no_field_vertex);
445 CHKERR moab.create_meshset(MESHSET_SET, meshset_fe_arc_length);
446 CHKERR moab.add_entities(meshset_fe_arc_length, &no_field_vertex, 1);
452 meshset_fe_arc_length,
"ARC_LENGTH",
false);
504 CHKERR m_field.
get_moab().get_entities_by_type(it->meshset, MBTET, tets,
517 "MESH_NODE_POSITIONS");
547 Vec
F, F_body_force,
D;
549 "ELASTIC_MECHANICS",
COL, &
F);
551 CHKERR VecDuplicate(
F, &F_body_force);
554 ->createMPIAIJWithArrays<PetscGlobalIdx_mi_tag>(
"ELASTIC_MECHANICS",
561 boost::ptr_vector<CohesiveInterfaceElement::PhysicalEquation>
567 cout << std::endl << *it << std::endl;
570 string name = it->getName();
572 if (name.compare(0, 11,
"MAT_ELASTIC") == 0) {
574 CHKERR it->getAttributeDataStructure(mydata);
578 }
else if (name.compare(0, 10,
"MAT_INTERF") == 0) {
580 CHKERR it->getAttributeDataStructure(mydata);
583 interface_materials.push_back(
585 interface_materials.back().h = 1;
586 interface_materials.back().youngModulus = mydata.
data.alpha;
587 interface_materials.back().beta = mydata.
data.beta;
588 interface_materials.back().ft = mydata.
data.ft;
589 interface_materials.back().Gf = mydata.
data.Gf;
593 rval = moab.get_entities_by_type(meshset, MBTRI, tris,
true);
596 rval = moab.get_adjacencies(tris, 3,
false, ents3d,
597 moab::Interface::UNION);
599 interface_materials.back().pRisms = ents3d.subset_by_type(MBPRISM);
604 boost::ptr_vector<CohesiveInterfaceElement::PhysicalEquation>::iterator
605 pit = interface_materials.begin();
606 for (; pit != interface_materials.end(); pit++) {
611 boost::shared_ptr<ArcLengthCtx> arc_ctx = boost::shared_ptr<ArcLengthCtx>(
613 boost::scoped_ptr<ArcLengthElement> my_arc_method_ptr(
615 ArcLengthSnesCtx snes_ctx(m_field,
"ELASTIC_MECHANICS", arc_ctx);
622 boost::shared_ptr<Hooke<adouble>> hooke_adouble_ptr(
new Hooke<adouble>);
623 boost::shared_ptr<Hooke<double>> hooke_double_ptr(
new Hooke<double>);
630 elastic.
setOfBlocks[id].materialDoublePtr = hooke_double_ptr;
631 elastic.
setOfBlocks[id].materialAdoublePtr = hooke_adouble_ptr;
636 false,
false,
false);
638 false,
false,
false);
640 false,
false,
false);
645 CHKERR cohesive_elements.
addOps(
"DISPLACEMENT", interface_materials);
648 CHKERR MatGetSize(Aij, &M, &
N);
650 MatGetLocalSize(Aij, &
m, &
n);
651 boost::scoped_ptr<ArcLengthMatShell> mat_ctx(
654 CHKERR MatCreateShell(PETSC_COMM_WORLD,
m,
n, M,
N, (
void *)mat_ctx.get(),
656 CHKERR MatShellSetOperation(ShellAij, MATOP_MULT,
666 CHKERR VecZeroEntries(F_body_force);
667 CHKERR VecGhostUpdateBegin(F_body_force, INSERT_VALUES, SCATTER_FORWARD);
668 CHKERR VecGhostUpdateEnd(F_body_force, INSERT_VALUES, SCATTER_FORWARD);
671 CHKERR VecGhostUpdateBegin(F_body_force, ADD_VALUES, SCATTER_REVERSE);
672 CHKERR VecGhostUpdateEnd(F_body_force, ADD_VALUES, SCATTER_REVERSE);
673 CHKERR VecAssemblyBegin(F_body_force);
674 CHKERR VecAssemblyEnd(F_body_force);
677 boost::ptr_map<std::string, NeumannForcesSurface> neumann_forces;
678 string fe_name_str =
"FORCE_FE";
681 neumann_forces.at(fe_name_str).getLoopFe(),
false,
685 CHKERR neumann_forces.at(fe_name_str)
686 .addForce(
"DISPLACEMENT", arc_ctx->F_lambda, it->getMeshsetId());
688 fe_name_str =
"PRESSURE_FE";
691 neumann_forces.at(fe_name_str).getLoopFe(),
false,
695 CHKERR neumann_forces.at(fe_name_str)
696 .addPressure(
"DISPLACEMENT", arc_ctx->F_lambda, it->getMeshsetId());
699 boost::ptr_map<std::string, NodalForce> nodal_forces;
700 fe_name_str =
"FORCE_FE";
701 nodal_forces.insert(fe_name_str,
new NodalForce(m_field));
704 CHKERR nodal_forces.at(fe_name_str)
705 .addForce(
"DISPLACEMENT", arc_ctx->F_lambda, it->getMeshsetId());
709 CHKERR SNESCreate(PETSC_COMM_WORLD, &snes);
710 CHKERR SNESSetApplicationContext(snes, &snes_ctx);
712 CHKERR SNESSetJacobian(snes, ShellAij, Aij,
SnesMat, &snes_ctx);
713 CHKERR SNESSetFromOptions(snes);
716 CHKERR SNESGetKSP(snes, &ksp);
718 CHKERR KSPGetPC(ksp, &pc);
719 boost::scoped_ptr<PCArcLengthCtx> pc_ctx(
721 CHKERR PCSetType(pc, PCSHELL);
722 CHKERR PCShellSetContext(pc, pc_ctx.get());
728 snes_ctx.getComputeRhs();
729 snes_ctx.getPreProcComputeRhs().push_back(&my_dirichlet_bc);
730 snes_ctx.getPreProcComputeRhs().push_back(&pre_post_proc_fe);
732 "INTERFACE", &cohesive_elements.
getFeRhs()));
733 loops_to_do_Rhs.push_back(
735 loops_to_do_Rhs.push_back(
737 snes_ctx.getPostProcComputeRhs().push_back(&pre_post_proc_fe);
738 snes_ctx.getPostProcComputeRhs().push_back(&my_dirichlet_bc);
742 snes_ctx.getSetOperators();
743 snes_ctx.getPreProcSetOperators().push_back(&my_dirichlet_bc);
745 "INTERFACE", &cohesive_elements.
getFeLhs()));
746 loops_to_do_Mat.push_back(
748 loops_to_do_Mat.push_back(
750 snes_ctx.getPostProcSetOperators().push_back(&my_dirichlet_bc);
752 double gamma = 0.5, reduction = 1;
755 step_size = step_size_reduction;
757 reduction = step_size_reduction;
761 boost::ptr_map<std::string, NeumannForcesSurface>::iterator mit =
762 neumann_forces.begin();
763 CHKERR VecZeroEntries(arc_ctx->F_lambda);
764 CHKERR VecGhostUpdateBegin(arc_ctx->F_lambda, INSERT_VALUES,
766 CHKERR VecGhostUpdateEnd(arc_ctx->F_lambda, INSERT_VALUES, SCATTER_FORWARD);
767 for (; mit != neumann_forces.end(); mit++) {
769 mit->second->getLoopFe());
771 CHKERR VecGhostUpdateBegin(arc_ctx->F_lambda, ADD_VALUES, SCATTER_REVERSE);
772 CHKERR VecGhostUpdateEnd(arc_ctx->F_lambda, ADD_VALUES, SCATTER_REVERSE);
773 CHKERR VecAssemblyBegin(arc_ctx->F_lambda);
774 CHKERR VecAssemblyEnd(arc_ctx->F_lambda);
775 for (std::vector<int>::iterator vit = my_dirichlet_bc.
dofsIndices.begin();
777 CHKERR VecSetValue(arc_ctx->F_lambda, *vit, 0, INSERT_VALUES);
779 CHKERR VecAssemblyBegin(arc_ctx->F_lambda);
780 CHKERR VecAssemblyEnd(arc_ctx->F_lambda);
782 CHKERR VecDot(arc_ctx->F_lambda, arc_ctx->F_lambda, &arc_ctx->F_lambda2);
783 PetscPrintf(PETSC_COMM_WORLD,
"\tFlambda2 = %6.4e\n", arc_ctx->F_lambda2);
787 "ELASTIC_MECHANICS",
COL,
D, INSERT_VALUES, SCATTER_FORWARD);
789 "ELASTIC_MECHANICS",
"DISPLACEMENT",
"X0_DISPLACEMENT",
COL,
790 arc_ctx->x0, INSERT_VALUES, SCATTER_FORWARD);
792 CHKERR VecNorm(arc_ctx->x0, NORM_2, &x0_nrm);
793 CHKERR PetscPrintf(PETSC_COMM_WORLD,
794 "\tRead x0_nrm = %6.4e dlambda = %6.4e\n", x0_nrm,
796 CHKERR arc_ctx->setAlphaBeta(1, 0);
799 CHKERR arc_ctx->setAlphaBeta(0, 1);
812 bool converged_state =
false;
813 for (; step < max_steps; step++) {
816 CHKERR PetscPrintf(PETSC_COMM_WORLD,
"Load Step %D step_size = %6.4e\n",
818 CHKERR arc_ctx->setS(step_size);
819 CHKERR arc_ctx->setAlphaBeta(0, 1);
820 CHKERR VecCopy(
D, arc_ctx->x0);
822 CHKERR my_arc_method_ptr->calculate_init_dlambda(&dlambda);
823 CHKERR my_arc_method_ptr->set_dlambda_to_x(
D, dlambda);
824 }
else if (step == 2) {
825 CHKERR arc_ctx->setAlphaBeta(1, 0);
826 CHKERR my_arc_method_ptr->calculate_dx_and_dlambda(
D);
827 CHKERR my_arc_method_ptr->calculate_lambda_int(step_size);
828 CHKERR arc_ctx->setS(step_size);
829 double dlambda = arc_ctx->dLambda;
831 CHKERR VecNorm(arc_ctx->dx, NORM_2, &dx_nrm);
832 CHKERR PetscPrintf(PETSC_COMM_WORLD,
833 "Load Step %D step_size = %6.4e dlambda0 = %6.4e "
834 "dx_nrm = %6.4e dx2 = %6.4e\n",
835 step, step_size, dlambda, dx_nrm, arc_ctx->dx2);
836 CHKERR VecCopy(
D, arc_ctx->x0);
837 CHKERR VecAXPY(
D, 1., arc_ctx->dx);
838 CHKERR my_arc_method_ptr->set_dlambda_to_x(
D, dlambda);
840 CHKERR my_arc_method_ptr->calculate_dx_and_dlambda(
D);
841 CHKERR my_arc_method_ptr->calculate_lambda_int(step_size);
844 step_size *= reduction;
845 CHKERR arc_ctx->setS(step_size);
846 double dlambda = reduction * arc_ctx->dLambda;
847 CHKERR VecScale(arc_ctx->dx, reduction);
849 CHKERR VecNorm(arc_ctx->dx, NORM_2, &dx_nrm);
850 CHKERR PetscPrintf(PETSC_COMM_WORLD,
851 "Load Step %D step_size = %6.4e dlambda0 = %6.4e "
852 "dx_nrm = %6.4e dx2 = %6.4e\n",
853 step, step_size, dlambda, dx_nrm, arc_ctx->dx2);
854 CHKERR VecCopy(
D, arc_ctx->x0);
855 CHKERR VecAXPY(
D, 1., arc_ctx->dx);
856 CHKERR my_arc_method_ptr->set_dlambda_to_x(
D, dlambda);
859 CHKERR SNESSolve(snes, PETSC_NULLPTR,
D);
863 "ELASTIC_MECHANICS",
COL,
D, INSERT_VALUES, SCATTER_REVERSE);
868 CHKERR my_arc_method_ptr->remove_damaged_prisms_nodes();
871 CHKERR SNESGetIterationNumber(snes, &its);
872 CHKERR PetscPrintf(PETSC_COMM_WORLD,
"number of Newton iterations = %D\n",
875 SNESConvergedReason reason;
876 CHKERR SNESGetConvergedReason(snes, &reason);
879 CHKERR arc_ctx->setAlphaBeta(1, 0);
881 converged_state =
false;
884 if (step > 1 && converged_state) {
885 reduction = pow((
double)its_d / (
double)(its + 1), gamma);
886 CHKERR PetscPrintf(PETSC_COMM_WORLD,
"reduction step_size = %6.4e\n",
892 "ELASTIC_MECHANICS",
COL,
D, INSERT_VALUES, SCATTER_REVERSE);
894 "ELASTIC_MECHANICS",
"DISPLACEMENT",
"X0_DISPLACEMENT",
COL,
895 arc_ctx->x0, INSERT_VALUES, SCATTER_REVERSE);
896 converged_state =
true;
901 PetscFOpen(PETSC_COMM_SELF,
DATAFILENAME,
"a+", &datafile);
902 PetscFPrintf(PETSC_COMM_WORLD, datafile,
"%d %d ", reason, its);
904 CHKERR my_arc_method_ptr->postProcessLoadPath();
911 std::ostringstream ss;
912 ss <<
"out_values_" << step <<
".h5m";
919 "ELASTIC_MECHANICS",
COL,
D, INSERT_VALUES, SCATTER_REVERSE);
924 CHKERR VecDestroy(&F_body_force);
926 CHKERR SNESDestroy(&snes);
927 CHKERR MatDestroy(&ShellAij);