23 using namespace MoFEM;
25 #include <boost/program_options.hpp>
27 namespace po = boost::program_options;
29 #include <boost/numeric/ublas/vector_proxy.hpp>
30 #include <boost/numeric/ublas/matrix.hpp>
31 #include <boost/numeric/ublas/matrix_proxy.hpp>
32 #include <boost/numeric/ublas/vector.hpp>
33 #include <boost/numeric/ublas/symmetric.hpp>
36 #include <MethodForForceScaling.hpp>
37 #include <TimeForceScale.hpp>
45 #error "MoFEM need to be compiled with ADOL-C"
47 #include <adolc/adolc.h>
51 #include <adolc/adolc.h>
52 #include <SmallStrainPlasticity.hpp>
53 #include <SmallStrainPlasticityMaterialModels.hpp>
61 using namespace boost::numeric;
70 int main(
int argc,
char *argv[]) {
77 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
78 if(pcomm == NULL) pcomm =
new ParallelComm(&moab,PETSC_COMM_WORLD);
80 PetscBool flg = PETSC_TRUE;
83 if(flg != PETSC_TRUE) {
84 SETERRQ(PETSC_COMM_SELF,1,
"*** ERROR -my_file (MESH FILE NEEDED)");
89 if(flg != PETSC_TRUE) {
92 PetscInt bubble_order;
94 if(flg != PETSC_TRUE) {
100 PetscBool is_partitioned = PETSC_FALSE;
104 double mygiven_strain[6];
108 given_strain.resize(6);
109 cblas_dcopy(6, &mygiven_strain[0], 1, &given_strain(0), 1);
110 cout<<
"given_strain ="<<given_strain<<endl;
113 if(is_partitioned == PETSC_TRUE) {
115 option =
"PARALLEL=BCAST_DELETE;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION=PARALLEL_PARTITION;";
178 SmallStrainJ2Plasticity cp;
202 PetscPrintf(PETSC_COMM_WORLD,
"young_modulus = %4.2e \n",
young_modulus);
203 PetscPrintf(PETSC_COMM_WORLD,
"poisson_ratio = %4.2e \n",
poisson_ratio);
204 PetscPrintf(PETSC_COMM_WORLD,
"sIgma_y = %4.2e \n",cp.sIgma_y);
205 PetscPrintf(PETSC_COMM_WORLD,
"H = %4.2e \n",cp.H);
206 PetscPrintf(PETSC_COMM_WORLD,
"K = %4.2e \n",cp.K);
207 PetscPrintf(PETSC_COMM_WORLD,
"phi = %4.2e \n",cp.phi);
210 cp.sTrain.resize(6,
false);
212 cp.plasticStrain.resize(6,
false);
213 cp.plasticStrain.clear();
214 cp.internalVariables.resize(7,
false);
215 cp.internalVariables.clear();
230 vector<BitRefLevel> bit_levels;
233 int def_meshset_info[2] = {0,0};
234 rval = moab.tag_get_handle(
235 "MESHSET_INFO",2,MB_TYPE_INTEGER,th_meshset_info,MB_TAG_CREAT|MB_TAG_SPARSE,&def_meshset_info
240 if(meshset_data[0]==0) {
245 bit_levels.push_back(
BitRefLevel().set(meshset_data[0]-1));
252 ierr = m_field.get_entities_by_ref_level(bit_levels.back(),
BitRefLevel().set(),out_meshset); CHKERRQ(
ierr);
253 Range LatestRefinedTets;
254 rval = moab.get_entities_by_type(out_meshset, MBTET,LatestRefinedTets,
true);
CHKERRQ_MOAB(
rval);
255 Range LatestRefinedPrisms;
256 rval = moab.get_entities_by_type(out_meshset, MBPRISM,LatestRefinedPrisms,
true);
CHKERRQ_MOAB(
rval);
258 cout<<
"========================== LatestRefinedPrisms "<<LatestRefinedPrisms.size()<<endl;
259 cout<<
"========================== LatestRefinedTets "<<LatestRefinedTets.size()<<endl;
271 Range prims_on_problem_bit_level;
272 ierr = m_field.get_entities_by_type_and_ref_level(
273 problem_bit_level,
BitRefLevel().set(),MBPRISM,prims_on_problem_bit_level
275 Range tets_on_problem_bit_level;
276 ierr = m_field.get_entities_by_type_and_ref_level(
277 problem_bit_level,
BitRefLevel().set(),MBTET,tets_on_problem_bit_level
283 rval = moab.add_entities(meshset_prims_on_problem_bit_level,prims_on_problem_bit_level);
CHKERRQ_MOAB(
rval);
284 ierr = m_field.seed_ref_level_MESHSET(meshset_prims_on_problem_bit_level,
BitRefLevel().set()); CHKERRQ(
ierr);
297 if(it->getName().compare(0,12,
"AllBoundSurf") == 0 || it->getMeshsetId() == 103) {
325 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material,0); CHKERRQ(
ierr);
339 if(it->getName() !=
"MAT_PLASTIC")
continue;
341 int id = it->getMeshsetId();
344 meshset,MBTET,newtets,
true
348 newtets = intersect(newtets,LatestRefinedTets);
349 ierr = m_field.seed_finite_elements(newtets); CHKERRQ(
ierr);
363 std::map<int,boost::shared_ptr<SmallStrainTranverslyIsotropicADouble> > tranversly_isotropic_adouble_ptr_map;
364 std::map<int,boost::shared_ptr<SmallStrainTranverslyIsotropicDouble> > tranversly_isotropic_double_ptr_map;
365 bool trans_iso_blocks =
false;
368 string name = it->getName();
369 if (name.compare(0,20,
"MAT_ELASTIC_TRANSISO") == 0) {
370 cout<<
"================================ it is MAT_ELASTIC_TRANSISO "<<endl;
371 trans_iso_blocks =
true;
372 int id = it->getMeshsetId();
374 ierr = it->getAttributeDataStructure(mydata); CHKERRQ(
ierr);
375 tranversly_isotropic_adouble_ptr_map[id] = boost::make_shared<SmallStrainTranverslyIsotropicADouble>();
376 tranversly_isotropic_double_ptr_map[id] = boost::make_shared<SmallStrainTranverslyIsotropicDouble>();
378 tranversly_isotropic_adouble_ptr_map.at(
id)->E_p = mydata.
data.Youngp;
379 tranversly_isotropic_double_ptr_map.at(
id)->E_p = mydata.
data.Youngp;
380 tranversly_isotropic_adouble_ptr_map.at(
id)->E_z = mydata.
data.Youngz;
381 tranversly_isotropic_double_ptr_map.at(
id)->E_z = mydata.
data.Youngz;
382 tranversly_isotropic_adouble_ptr_map.at(
id)->nu_p = mydata.
data.Poissonp;
383 tranversly_isotropic_double_ptr_map.at(
id)->nu_p = mydata.
data.Poissonp;
384 tranversly_isotropic_adouble_ptr_map.at(
id)->nu_pz = mydata.
data.Poissonpz;
385 tranversly_isotropic_double_ptr_map.at(
id)->nu_pz = mydata.
data.Poissonpz;
387 if(mydata.
data.Shearzp!=0) {
388 shear_zp = mydata.
data.Shearzp;
390 shear_zp = mydata.
data.Youngz/(2*(1+mydata.
data.Poissonpz));
392 tranversly_isotropic_adouble_ptr_map.at(it->getMeshsetId())->G_zp = shear_zp;
393 tranversly_isotropic_double_ptr_map.at(it->getMeshsetId())->G_zp = shear_zp;
397 meshset,MBTET,trans_elastic.
setOfBlocks[
id].tEts,
true
410 trans_elastic.
setOfBlocks[id].materialDoublePtr = tranversly_isotropic_double_ptr_map.at(
id);
411 trans_elastic.
setOfBlocks[id].materialAdoublePtr = tranversly_isotropic_adouble_ptr_map.at(
id);
428 map<int,NonlinearElasticElement::BlockData>::iterator sit = trans_elastic.
setOfBlocks.begin();
441 map<int,NonlinearElasticElement::BlockData>::iterator sit = trans_elastic.
setOfBlocks.begin();
471 boost::ptr_vector<CohesiveInterfaceElement::PhysicalEquation> interface_materials;
477 double interface_beta, interface_ft, interface_Gf, interface_h;
484 cout << endl << *it << endl;
486 string name = it->getName();
487 if (name.compare(0,10,
"MAT_INTERF") == 0) {
489 ierr = it->getAttributeDataStructure(mydata); CHKERRQ(
ierr);
493 interface_materials.back().youngModulus = mydata.
data.alpha;
498 interface_materials.back().h = interface_h;
499 interface_materials.back().beta = interface_beta;
500 interface_materials.back().ft = interface_ft;
501 interface_materials.back().Gf = interface_Gf;
508 interface_materials.back().pRisms = ents3d.subset_by_type(MBPRISM);
514 boost::ptr_vector<CohesiveInterfaceElement::PhysicalEquation>::iterator pit = interface_materials.begin();
515 for(; pit != interface_materials.end();pit++) {
520 ierr = cohesive_elements.
addOps(
"DISPLACEMENT",interface_materials); CHKERRQ(
ierr);
524 lagrangian_element_disp.
addLagrangiangElement(
"LAGRANGE_ELEM",
"DISPLACEMENT",
"LAGRANGE_MUL_DISP",
"MESH_NODE_POSITIONS");
535 DMType dm_name =
"PLASTIC_PROB";
539 ierr = DMCreate(PETSC_COMM_WORLD,&dm);CHKERRQ(
ierr);
540 ierr = DMSetType(dm,dm_name);CHKERRQ(
ierr);
544 ierr = DMSetFromOptions(dm); CHKERRQ(
ierr);
561 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
562 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
564 ierr = MatZeroEntries(Aij); CHKERRQ(
ierr);
567 for(
int ii = 0;ii<6;ii++) {
568 ierr = VecDuplicate(
D,&Fvec[ii]); CHKERRQ(
ierr);
569 ierr = VecZeroEntries(Fvec[ii]); CHKERRQ(
ierr);
570 ierr = VecGhostUpdateBegin(Fvec[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
571 ierr = VecGhostUpdateEnd(Fvec[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
575 SmallStrainPlasticity small_strain_plasticity(m_field);
577 PetscBool bbar = PETSC_TRUE;
579 small_strain_plasticity.commonData.bBar = bbar;
582 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
583 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
584 "DISPLACEMENT",small_strain_plasticity.commonData
587 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
588 new SmallStrainPlasticity::OpCalculateStress(
589 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp
592 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
593 new SmallStrainPlasticity::OpAssembleRhs(
594 "DISPLACEMENT",small_strain_plasticity.commonData
597 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
598 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
599 "DISPLACEMENT",small_strain_plasticity.commonData
602 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
603 new SmallStrainPlasticity::OpCalculateStress(
604 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp
607 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
608 new SmallStrainPlasticity::OpAssembleLhs(
609 "DISPLACEMENT",small_strain_plasticity.commonData
612 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
613 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
614 "DISPLACEMENT",small_strain_plasticity.commonData
617 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
618 new SmallStrainPlasticity::OpCalculateStress(
619 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp
622 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
623 new SmallStrainPlasticity::OpUpdate(
624 "DISPLACEMENT",small_strain_plasticity.commonData
627 ierr = small_strain_plasticity.createInternalVariablesTag(); CHKERRQ(
ierr);
654 ierr = SNESCreate(PETSC_COMM_WORLD,&snes); CHKERRQ(
ierr);
659 ierr = SNESSetFromOptions(snes); CHKERRQ(
ierr);
672 int volume_vec_ghost[] = { 0 };
673 ierr = VecCreateGhost(
674 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?1:0,1,1,volume_vec_ghost,&volume_vec
676 ierr = VecZeroEntries(volume_vec); CHKERRQ(
ierr);
682 ierr = VecAssemblyBegin(volume_vec); CHKERRQ(
ierr);
683 ierr = VecAssemblyEnd(volume_vec); CHKERRQ(
ierr);
685 ierr = VecSum(volume_vec,&rve_volume); CHKERRQ(
ierr);
688 ierr = PetscPrintf(PETSC_COMM_WORLD,
"RVE Volume %3.2g\n",rve_volume); CHKERRQ(
ierr);
689 ierr = VecDestroy(&volume_vec);
692 double final_time = 1,delta_time = 0.1;
695 double delta_time0 = delta_time;
702 ierr = VecDuplicate(
D,&D0); CHKERRQ(
ierr);
706 SNESConvergedReason reason = SNES_CONVERGED_ITERATING;
707 for(;
t<final_time;step++) {
714 PETSC_COMM_WORLD,
"Step %d Time %6.4g final time %3.2g\n",step,
t,final_time
719 ierr = VecAssemblyBegin(
D);
720 ierr = VecAssemblyEnd(
D);
722 if(step == 0 || reason < 0) {
723 ierr = SNESSetLagJacobian(snes,-2); CHKERRQ(
ierr);
725 ierr = SNESSetLagJacobian(snes,-1); CHKERRQ(
ierr);
727 ierr = SNESSolve(snes,PETSC_NULL,
D); CHKERRQ(
ierr);
730 ierr = SNESGetIterationNumber(snes,&its); CHKERRQ(
ierr);
733 PETSC_COMM_WORLD,
"number of Newton iterations = %D\n",its
736 ierr = SNESGetConvergedReason(snes,&reason); CHKERRQ(
ierr);
742 }
else {
const int its_d = 60;
743 const double gamma = 0.5;
744 const double max_reudction = 1;
745 const double min_reduction = 1e-1;
747 reduction = pow((
double)its_d/(
double)(its+1),gamma);
748 if(delta_time >= max_reudction*delta_time0 && reduction > 1) {
750 }
else if(delta_time <= min_reduction*delta_time0 && reduction < 1) {
756 "reduction delta_time = %6.4e delta_time = %6.4e\n",
759 delta_time *= reduction;
760 if(reduction>1 && delta_time < min_reduction*delta_time0) {
761 delta_time = min_reduction*delta_time0;
765 dm,
D,INSERT_VALUES,SCATTER_REVERSE
769 dm,
"PLASTIC",&small_strain_plasticity.feUpdate
775 dm,
"INTERFACE",&cohesive_elements.
feHistory
782 dm,
"PLASTIC",&post_proc
786 std::ostringstream stm;
787 stm <<
"out_" << step <<
".h5m";
800 StressHomo.resize(6);
806 int stress_homo_ghost[] = { 0,1,2,3,4,5,6 };
807 ierr = VecCreateGhost(
808 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?6:0,6,6,stress_homo_ghost,&stress_homo
815 ierr = VecGetArray(stress_homo,&avec); CHKERRQ(
ierr);
816 ierr = VecZeroEntries(stress_homo); CHKERRQ(
ierr);
821 PETSC_NULL,
"-my_rve_volume",&rve_volume,PETSC_NULL
823 ierr = VecAssemblyBegin(stress_homo); CHKERRQ(
ierr);
824 ierr = VecAssemblyEnd(stress_homo); CHKERRQ(
ierr);
825 ierr = VecScale(stress_homo,1.0/rve_volume); CHKERRQ(
ierr);
826 ierr = VecGhostUpdateBegin(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
827 ierr = VecGhostUpdateEnd(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
829 for(
int jj=0; jj<6; jj++) {
830 StressHomo(jj) = avec[jj];
836 PetscPrintf(PETSC_COMM_WORLD,
837 "Macro_Strain Homo_Stress Path "
841 for(
int ii=0; ii<6; ii++) {
850 for(
int ii=0; ii<6; ii++) {
858 PetscPrintf(PETSC_COMM_WORLD,
864 ierr = VecDestroy(&D0); CHKERRQ(
ierr);
866 ierr = MatDestroy(&Aij); CHKERRQ(
ierr);