123 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
124 if(pcomm == NULL) pcomm =
new ParallelComm(&moab,PETSC_COMM_WORLD);
126 PetscBool flg = PETSC_TRUE;
129 if(flg != PETSC_TRUE) {
130 SETERRQ(PETSC_COMM_SELF,1,
"*** ERROR -my_file (MESH FILE NEEDED)");
135 if(flg != PETSC_TRUE) {
138 PetscInt bubble_order;
140 if(flg != PETSC_TRUE) {
141 bubble_order =
order;
146 PetscBool is_partitioned = PETSC_FALSE;
150 double mygiven_strain[6];
154 given_strain.resize(6);
155 cblas_dcopy(6, &mygiven_strain[0], 1, &given_strain(0), 1);
156 cout<<
"given_strain ="<<given_strain<<endl;
159 if(is_partitioned == PETSC_TRUE) {
161 option =
"PARALLEL=BCAST_DELETE;PARALLEL_RESOLVE_SHARED_ENTS;PARTITION=PARALLEL_PARTITION;";
183 ierr = m_field.get_entities_by_ref_level(bit_level0,
BitRefLevel().set(),meshset_level0); CHKERRQ(
ierr);
193 ierr = m_field.get_cubit_msId_entities_by_dimension(101,
SIDESET,2,SurTrisNeg,
true); CHKERRQ(
ierr);
194 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 101 = %d\n",SurTrisNeg.size()); CHKERRQ(
ierr);
196 double TriCen[3], coords_Tri[9];
197 for(Range::iterator it = SurTrisNeg.begin(); it!=SurTrisNeg.end(); it++) {
206 TriCen[0]= (coords_Tri[0]+coords_Tri[3]+coords_Tri[6])/3.0;
207 TriCen[1]= (coords_Tri[1]+coords_Tri[4]+coords_Tri[7])/3.0;
208 TriCen[2]= (coords_Tri[2]+coords_Tri[5]+coords_Tri[8])/3.0;
211 if(TriCen[0]>=0) TriCen[0]=
double(
int(TriCen[0]*1000.0+0.5))/1000.0;
else TriCen[0]=
double(
int(TriCen[0]*1000.0-0.5))/1000.0;
212 if(TriCen[1]>=0) TriCen[1]=
double(
int(TriCen[1]*1000.0+0.5))/1000.0;
else TriCen[1]=
double(
int(TriCen[1]*1000.0-0.5))/1000.0;
213 if(TriCen[2]>=0) TriCen[2]=
double(
int(TriCen[2]*1000.0+0.5))/1000.0;
else TriCen[2]=
double(
int(TriCen[2]*1000.0-0.5))/1000.0;
217 Face_CenPos_Handle_varNeg.insert(
Face_CenPos_Handle(TriCen[0], TriCen[1], TriCen[2], *it));
231 ierr = m_field.get_cubit_msId_entities_by_dimension(102,
SIDESET,2,SurTrisPos,
true); CHKERRQ(
ierr);
232 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 102 = %d\n",SurTrisPos.size()); CHKERRQ(
ierr);
233 for(Range::iterator it = SurTrisPos.begin(); it!=SurTrisPos.end(); it++) {
242 TriCen[0]= (coords_Tri[0]+coords_Tri[3]+coords_Tri[6])/3.0;
243 TriCen[1]= (coords_Tri[1]+coords_Tri[4]+coords_Tri[7])/3.0;
244 TriCen[2]= (coords_Tri[2]+coords_Tri[5]+coords_Tri[8])/3.0;
247 if(TriCen[0]>=0) TriCen[0]=
double(
int(TriCen[0]*1000.0+0.5))/1000.0;
else TriCen[0]=
double(
int(TriCen[0]*1000.0-0.5))/1000.0;
248 if(TriCen[1]>=0) TriCen[1]=
double(
int(TriCen[1]*1000.0+0.5))/1000.0;
else TriCen[1]=
double(
int(TriCen[1]*1000.0-0.5))/1000.0;
249 if(TriCen[2]>=0) TriCen[2]=
double(
int(TriCen[2]*1000.0+0.5))/1000.0;
else TriCen[2]=
double(
int(TriCen[2]*1000.0-0.5))/1000.0;
253 Face_CenPos_Handle_varPos.insert(
Face_CenPos_Handle(TriCen[0], TriCen[1], TriCen[2], *it));
257 double XcoordMin, YcoordMin, ZcoordMin, XcoordMax, YcoordMax, ZcoordMax;
258 typedef Face_CenPos_Handle_multiIndex::index<xcoord_tag>::type::iterator Tri_Xcoord_iterator;
259 typedef Face_CenPos_Handle_multiIndex::index<ycoord_tag>::type::iterator Tri_Ycoord_iterator;
260 typedef Face_CenPos_Handle_multiIndex::index<zcoord_tag>::type::iterator Tri_Zcoord_iterator;
261 Tri_Xcoord_iterator XcoordMin_it, XcoordMax_it;
262 Tri_Ycoord_iterator YcoordMin_it, YcoordMax_it;
263 Tri_Zcoord_iterator ZcoordMin_it, ZcoordMax_it;
266 XcoordMin_it=Face_CenPos_Handle_varNeg.get<
xcoord_tag>().begin(); XcoordMin=XcoordMin_it->xcoord;
267 XcoordMax_it=Face_CenPos_Handle_varPos.get<
xcoord_tag>().end(); XcoordMax_it--; XcoordMax=XcoordMax_it->xcoord;
268 YcoordMin_it=Face_CenPos_Handle_varNeg.get<
ycoord_tag>().begin(); YcoordMin=YcoordMin_it->ycoord;
269 YcoordMax_it=Face_CenPos_Handle_varPos.get<
ycoord_tag>().end(); YcoordMax_it--; YcoordMax=YcoordMax_it->ycoord;
270 ZcoordMin_it=Face_CenPos_Handle_varNeg.get<
zcoord_tag>().begin(); ZcoordMin=ZcoordMin_it->zcoord;
271 ZcoordMax_it=Face_CenPos_Handle_varPos.get<
zcoord_tag>().end(); ZcoordMax_it--; ZcoordMax=ZcoordMax_it->zcoord;
276 double LxRVE, LyRVE, LzRVE;
277 LxRVE=XcoordMax-XcoordMin;
278 LyRVE=YcoordMax-YcoordMin;
279 LzRVE=ZcoordMax-ZcoordMin;
283 typedef Face_CenPos_Handle_multiIndex::index<Tri_Hand_tag>::type::iterator Tri_Hand_iterator;
284 Tri_Hand_iterator Tri_Neg;
285 typedef Face_CenPos_Handle_multiIndex::index<Composite_xyzcoord>::type::iterator xyzcoord_iterator;
286 xyzcoord_iterator Tri_Pos;
288 double XPos, YPos, ZPos;
292 for(Range::iterator it = SurTrisNeg.begin(); it!=SurTrisNeg.end(); it++) {
294 Tri_Neg=Face_CenPos_Handle_varNeg.get<
Tri_Hand_tag>().find(*it);
298 if(Tri_Neg->xcoord==XcoordMin){XPos=XcoordMax; YPos=Tri_Neg->ycoord; ZPos=Tri_Neg->zcoord;};
299 if(Tri_Neg->ycoord==YcoordMin){XPos=YPos=Tri_Neg->xcoord; YPos=YcoordMax; ZPos=Tri_Neg->zcoord;};
300 if(Tri_Neg->zcoord==ZcoordMin){XPos=YPos=Tri_Neg->xcoord; YPos=Tri_Neg->ycoord; ZPos=ZcoordMax; };
301 Tri_Pos=Face_CenPos_Handle_varPos.get<
Composite_xyzcoord>().find(boost::make_tuple(XPos, YPos, ZPos));
308 vector<EntityHandle> TriNodesNeg, TriNodesPos;
309 double CoordNodeNeg[9], CoordNodePos[9];
314 for(
int ii=0; ii<3; ii++){
315 PrismNodes[ii]=TriNodesNeg[ii];
325 double XNodeNeg, YNodeNeg, ZNodeNeg, XNodePos, YNodePos, ZNodePos;
326 for(
int ii=0; ii<3; ii++){
327 if(Tri_Neg->xcoord==XcoordMin){XNodeNeg=XcoordMax; YNodeNeg=CoordNodeNeg[3*ii+1]; ZNodeNeg=CoordNodeNeg[3*ii+2];};
328 if(Tri_Neg->ycoord==YcoordMin){XNodeNeg=CoordNodeNeg[3*ii]; YNodeNeg=YcoordMax; ZNodeNeg=CoordNodeNeg[3*ii+2];};
329 if(Tri_Neg->zcoord==ZcoordMin){XNodeNeg=CoordNodeNeg[3*ii]; YNodeNeg=CoordNodeNeg[3*ii+1]; ZNodeNeg=ZcoordMax;};
330 for(
int jj=0; jj<3; jj++){
333 if(XNodeNeg>=0) XNodeNeg=
double(
int(XNodeNeg*1000.0+0.5))/1000.0;
else XNodeNeg=
double(
int(XNodeNeg*1000.0-0.5))/1000.0;
334 if(YNodeNeg>=0) YNodeNeg=
double(
int(YNodeNeg*1000.0+0.5))/1000.0;
else YNodeNeg=
double(
int(YNodeNeg*1000.0-0.5))/1000.0;
335 if(ZNodeNeg>=0) ZNodeNeg=
double(
int(ZNodeNeg*1000.0+0.5))/1000.0;
else ZNodeNeg=
double(
int(ZNodeNeg*1000.0-0.5))/1000.0;
337 XNodePos=CoordNodePos[3*jj]; YNodePos=CoordNodePos[3*jj+1]; ZNodePos=CoordNodePos[3*jj+2];
338 if(XNodePos>=0) XNodePos=
double(
int(XNodePos*1000.0+0.5))/1000.0;
else XNodePos=
double(
int(XNodePos*1000.0-0.5))/1000.0;
339 if(YNodePos>=0) YNodePos=
double(
int(YNodePos*1000.0+0.5))/1000.0;
else YNodePos=
double(
int(YNodePos*1000.0-0.5))/1000.0;
340 if(ZNodePos>=0) ZNodePos=
double(
int(ZNodePos*1000.0+0.5))/1000.0;
else ZNodePos=
double(
int(ZNodePos*1000.0-0.5))/1000.0;
342 if(XNodeNeg==XNodePos && YNodeNeg==YNodePos && ZNodeNeg==ZNodePos){
343 PrismNodes[3+ii]=TriNodesPos[jj];
349 double CoordNodesPrisms[18];
358 PrismRange.insert(PeriodicPrism);
365 ierr = m_field.get_entities_by_ref_level(bit_level0,
BitRefLevel().set(),meshset_level0); CHKERRQ(
ierr);
393 SmallStrainParaboloidalPlasticity cp;
430 PetscPrintf(PETSC_COMM_WORLD,
"young_modulus = %4.2e \n",
young_modulus);
431 PetscPrintf(PETSC_COMM_WORLD,
"poisson_ratio = %4.2e \n",
poisson_ratio);
433 PetscPrintf(PETSC_COMM_WORLD,
"sIgma_yt = %4.2e \n",cp.sIgma_yt);
434 PetscPrintf(PETSC_COMM_WORLD,
"sIgma_yc = %4.2e \n",cp.sIgma_yt);
436 PetscPrintf(PETSC_COMM_WORLD,
"nup = %4.2e \n",cp.nup);
438 cp.sTrain.resize(6,
false);
440 cp.plasticStrain.resize(6,
false);
441 cp.plasticStrain.clear();
442 cp.internalVariables.resize(2,
false);
443 cp.internalVariables.clear();
513 Range surface_negative;
514 ierr = m_field.get_cubit_msId_entities_by_dimension(101,
SIDESET,2,surface_negative,
true); CHKERRQ(
ierr);
515 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 101 = %d\n",surface_negative.size()); CHKERRQ(
ierr);
539 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material,0); CHKERRQ(
ierr);
553 lagrangian_element_periodic.addLagrangiangElement(
"LAGRANGE_ELEM",
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",PrismRange);
554 lagrangian_element_trac.addLagrangiangElement(
"LAGRANGE_ELEM_TRANS",
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",
"MESH_NODE_POSITIONS");
562 DMType dm_name =
"PLASTIC_PROB";
566 ierr = DMCreate(PETSC_COMM_WORLD,&dm);CHKERRQ(
ierr);
567 ierr = DMSetType(dm,dm_name);CHKERRQ(
ierr);
571 ierr = DMSetFromOptions(dm); CHKERRQ(
ierr);
587 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
588 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
592 ierr = VecGhostUpdateBegin(
F,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
593 ierr = VecGhostUpdateEnd(
F,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
596 ierr = MatZeroEntries(Aij); CHKERRQ(
ierr);
599 for(
int ii = 0;ii<6;ii++) {
600 ierr = VecDuplicate(
D,&Fvec[ii]); CHKERRQ(
ierr);
601 ierr = VecZeroEntries(Fvec[ii]); CHKERRQ(
ierr);
602 ierr = VecGhostUpdateBegin(Fvec[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
603 ierr = VecGhostUpdateEnd(Fvec[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
607 SmallStrainPlasticity small_strain_plasticity(m_field);
609 PetscBool bbar = PETSC_TRUE;
611 small_strain_plasticity.commonData.bBar = bbar;
614 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
615 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
616 "DISPLACEMENT",small_strain_plasticity.commonData
619 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
620 new SmallStrainPlasticity::OpCalculateStress(
621 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp,
false
624 small_strain_plasticity.feRhs.getOpPtrVector().push_back(
625 new SmallStrainPlasticity::OpAssembleRhs(
626 "DISPLACEMENT",small_strain_plasticity.commonData
629 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
630 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
631 "DISPLACEMENT",small_strain_plasticity.commonData
634 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
635 new SmallStrainPlasticity::OpCalculateStress(
636 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp,
false
639 small_strain_plasticity.feLhs.getOpPtrVector().push_back(
640 new SmallStrainPlasticity::OpAssembleLhs(
641 "DISPLACEMENT",small_strain_plasticity.commonData
644 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
645 new SmallStrainPlasticity::OpGetCommonDataAtGaussPts(
646 "DISPLACEMENT",small_strain_plasticity.commonData
649 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
650 new SmallStrainPlasticity::OpCalculateStress(
651 m_field,
"DISPLACEMENT",small_strain_plasticity.commonData,cp,
false
654 small_strain_plasticity.feUpdate.getOpPtrVector().push_back(
655 new SmallStrainPlasticity::OpUpdate(
656 "DISPLACEMENT",small_strain_plasticity.commonData
659 ierr = small_strain_plasticity.createInternalVariablesTag(); CHKERRQ(
ierr);
662 lagrangian_element_periodic.setRVEBCsOperatorsNonlinear(
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",Aij,Fvec,
F,given_strain);
665 lagrangian_element_rigid_body_trans.setRVEBCsRigidBodyTranOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",Aij, lagrangian_element_periodic.setOfRVEBC);
668 TimeForceScale time_force_scale(
"-my_macro_strian_history",
false);
669 lagrangian_element_periodic.methodsOp.push_back(
new TimeForceScale(
"-my_macro_strian_history",
false));
689 ierr = SNESCreate(PETSC_COMM_WORLD,&snes); CHKERRQ(
ierr);
694 ierr = SNESSetFromOptions(snes); CHKERRQ(
ierr);
697 ierr = post_proc.generateReferenceElementMesh(); CHKERRQ(
ierr);
698 ierr = post_proc.addFieldValuesPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
699 ierr = post_proc.addFieldValuesGradientPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
700 ierr = post_proc.addFieldValuesPostProc(
"MESH_NODE_POSITIONS"); CHKERRQ(
ierr);
706 int volume_vec_ghost[] = { 0 };
707 ierr = VecCreateGhost(
708 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?1:0,1,1,volume_vec_ghost,&volume_vec
710 ierr = VecZeroEntries(volume_vec); CHKERRQ(
ierr);
711 vol_elem.getOpPtrVector().push_back(
new VolumeCalculation(
"DISPLACEMENT",volume_vec));
715 ierr = VecAssemblyBegin(volume_vec); CHKERRQ(
ierr);
716 ierr = VecAssemblyEnd(volume_vec); CHKERRQ(
ierr);
718 ierr = VecSum(volume_vec,&rve_volume); CHKERRQ(
ierr);
721 ierr = PetscPrintf(PETSC_COMM_WORLD,
"RVE Volume %3.2g\n",rve_volume); CHKERRQ(
ierr);
722 ierr = VecDestroy(&volume_vec);
725 double final_time = 1,delta_time = 0.1;
728 double delta_time0 = delta_time;
735 ierr = VecDuplicate(
D,&D0); CHKERRQ(
ierr);
739 SNESConvergedReason reason = SNES_CONVERGED_ITERATING;
740 for(;
t<final_time;step++) {
747 PETSC_COMM_WORLD,
"Step %d Time %6.4g final time %3.2g\n",step,
t,final_time
750 lagrangian_element_periodic.getLoopFeRVEBCRhs().ts_t =
t;
752 ierr = VecAssemblyBegin(
D);
753 ierr = VecAssemblyEnd(
D);
756 if(step == 0 || reason < 0) {
757 ierr = SNESSetLagJacobian(snes,-2); CHKERRQ(
ierr);
759 ierr = SNESSetLagJacobian(snes,-1); CHKERRQ(
ierr);
763 ierr = SNESSolve(snes,PETSC_NULL,
D); CHKERRQ(
ierr);
765 ierr = SNESGetIterationNumber(snes,&its); CHKERRQ(
ierr);
768 PETSC_COMM_WORLD,
"number of Newton iterations = %D\n",its
771 ierr = SNESGetConvergedReason(snes,&reason); CHKERRQ(
ierr);
778 }
else {
const int its_d = 20;
779 const double gamma = 0.5;
780 const double max_reudction = 1;
781 const double min_reduction = 1e-1;
783 reduction = pow((
double)its_d/(
double)(its+1),gamma);
784 if(delta_time >= max_reudction*delta_time0 && reduction > 1) {
786 }
else if(delta_time <= min_reduction*delta_time0 && reduction < 1) {
792 "reduction delta_time = %6.4e delta_time = %6.4e\n",
795 delta_time *= reduction;
796 if(reduction>1 && delta_time < min_reduction*delta_time0) {
797 delta_time = min_reduction*delta_time0;
801 dm,
D,INSERT_VALUES,SCATTER_REVERSE
804 dm,
"PLASTIC",&small_strain_plasticity.feUpdate
810 dm,
"PLASTIC",&post_proc
814 std::ostringstream stm;
815 stm <<
"out_" << step <<
".h5m";
821 rval = post_proc.postProcMesh.write_file(
827 StressHomo.resize(6);
833 int stress_homo_ghost[] = { 0,1,2,3,4,5,6 };
834 ierr = VecCreateGhost(
835 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?6:0,6,6,stress_homo_ghost,&stress_homo
838 lagrangian_element_periodic.setRVEBCsHomoStressOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",stress_homo);
841 ierr = VecGetArray(stress_homo,&avec); CHKERRQ(
ierr);
842 ierr = VecZeroEntries(stress_homo); CHKERRQ(
ierr);
844 "PLASTIC_PROB",
"LAGRANGE_ELEM",lagrangian_element_periodic.getLoopFeRVEBCStress()
847 PETSC_NULL,
"-my_rve_volume",&rve_volume,PETSC_NULL
849 ierr = VecAssemblyBegin(stress_homo); CHKERRQ(
ierr);
850 ierr = VecAssemblyEnd(stress_homo); CHKERRQ(
ierr);
851 ierr = VecScale(stress_homo,1.0/rve_volume); CHKERRQ(
ierr);
852 ierr = VecGhostUpdateBegin(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
853 ierr = VecGhostUpdateEnd(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
855 for(
int jj=0; jj<6; jj++) {
856 StressHomo(jj) = avec[jj];
862 PetscPrintf(PETSC_COMM_WORLD,
863 "Macro_Strain Homo_Stress Path "
867 for(
int ii=0; ii<6; ii++) {
876 for(
int ii=0; ii<6; ii++) {
884 PetscPrintf(PETSC_COMM_WORLD,
893 ierr = VecDestroy(&D0); CHKERRQ(
ierr);
894 ierr = MatDestroy(&Aij); CHKERRQ(
ierr);