146 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
149 PetscBool flg = PETSC_TRUE;
152 if(flg != PETSC_TRUE) {
153 SETERRQ(PETSC_COMM_SELF,1,
"*** ERROR -my_file (MESH FILE NEEDED)");
157 if(flg != PETSC_TRUE) {
162 double myapplied_strain[6];
166 applied_strain.resize(6);
167 cblas_dcopy(6, &myapplied_strain[0], 1, &applied_strain(0), 1);
175 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
176 if(pcomm == NULL) pcomm =
new ParallelComm(&moab,PETSC_COMM_WORLD);
179 PetscLogDouble t1,t2;
180 PetscLogDouble v1,v2;
181 ierr = PetscTime(&v1); CHKERRQ(
ierr);
182 ierr = PetscGetCPUTime(&t1); CHKERRQ(
ierr);
197 ierr = m_field.get_entities_by_ref_level(bit_level0,
BitRefLevel().set(),meshset_level0); CHKERRQ(
ierr);
205 ierr = m_field.get_cubit_msId_entities_by_dimension(101,
SIDESET,2,SurTrisNeg,
true); CHKERRQ(
ierr);
206 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 101 = %d\n",SurTrisNeg.size()); CHKERRQ(
ierr);
208 double TriCen[3], coords_Tri[9];
209 for(Range::iterator it = SurTrisNeg.begin(); it!=SurTrisNeg.end(); it++) {
218 TriCen[0]= (coords_Tri[0]+coords_Tri[3]+coords_Tri[6])/3.0;
219 TriCen[1]= (coords_Tri[1]+coords_Tri[4]+coords_Tri[7])/3.0;
220 TriCen[2]= (coords_Tri[2]+coords_Tri[5]+coords_Tri[8])/3.0;
223 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;
224 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;
225 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;
229 Face_CenPos_Handle_varNeg.insert(
Face_CenPos_Handle(TriCen[0], TriCen[1], TriCen[2], *it));
243 ierr = m_field.get_cubit_msId_entities_by_dimension(102,
SIDESET,2,SurTrisPos,
true); CHKERRQ(
ierr);
244 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 102 = %d\n",SurTrisPos.size()); CHKERRQ(
ierr);
245 for(Range::iterator it = SurTrisPos.begin(); it!=SurTrisPos.end(); it++) {
254 TriCen[0]= (coords_Tri[0]+coords_Tri[3]+coords_Tri[6])/3.0;
255 TriCen[1]= (coords_Tri[1]+coords_Tri[4]+coords_Tri[7])/3.0;
256 TriCen[2]= (coords_Tri[2]+coords_Tri[5]+coords_Tri[8])/3.0;
259 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;
260 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;
261 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;
265 Face_CenPos_Handle_varPos.insert(
Face_CenPos_Handle(TriCen[0], TriCen[1], TriCen[2], *it));
269 double XcoordMin, YcoordMin, ZcoordMin, XcoordMax, YcoordMax, ZcoordMax;
270 typedef Face_CenPos_Handle_multiIndex::index<xcoord_tag>::type::iterator Tri_Xcoord_iterator;
271 typedef Face_CenPos_Handle_multiIndex::index<ycoord_tag>::type::iterator Tri_Ycoord_iterator;
272 typedef Face_CenPos_Handle_multiIndex::index<zcoord_tag>::type::iterator Tri_Zcoord_iterator;
273 Tri_Xcoord_iterator XcoordMin_it, XcoordMax_it;
274 Tri_Ycoord_iterator YcoordMin_it, YcoordMax_it;
275 Tri_Zcoord_iterator ZcoordMin_it, ZcoordMax_it;
278 XcoordMin_it=Face_CenPos_Handle_varNeg.get<
xcoord_tag>().begin(); XcoordMin=XcoordMin_it->xcoord;
279 XcoordMax_it=Face_CenPos_Handle_varPos.get<
xcoord_tag>().end(); XcoordMax_it--; XcoordMax=XcoordMax_it->xcoord;
280 YcoordMin_it=Face_CenPos_Handle_varNeg.get<
ycoord_tag>().begin(); YcoordMin=YcoordMin_it->ycoord;
281 YcoordMax_it=Face_CenPos_Handle_varPos.get<
ycoord_tag>().end(); YcoordMax_it--; YcoordMax=YcoordMax_it->ycoord;
282 ZcoordMin_it=Face_CenPos_Handle_varNeg.get<
zcoord_tag>().begin(); ZcoordMin=ZcoordMin_it->zcoord;
283 ZcoordMax_it=Face_CenPos_Handle_varPos.get<
zcoord_tag>().end(); ZcoordMax_it--; ZcoordMax=ZcoordMax_it->zcoord;
288 double LxRVE, LyRVE, LzRVE;
289 LxRVE=XcoordMax-XcoordMin;
290 LyRVE=YcoordMax-YcoordMin;
291 LzRVE=ZcoordMax-ZcoordMin;
295 typedef Face_CenPos_Handle_multiIndex::index<Tri_Hand_tag>::type::iterator Tri_Hand_iterator;
296 Tri_Hand_iterator Tri_Neg;
297 typedef Face_CenPos_Handle_multiIndex::index<Composite_xyzcoord>::type::iterator xyzcoord_iterator;
298 xyzcoord_iterator Tri_Pos;
300 double XPos, YPos, ZPos;
304 for(Range::iterator it = SurTrisNeg.begin(); it!=SurTrisNeg.end(); it++) {
306 Tri_Neg=Face_CenPos_Handle_varNeg.get<
Tri_Hand_tag>().find(*it);
310 if(Tri_Neg->xcoord==XcoordMin){XPos=XcoordMax; YPos=Tri_Neg->ycoord; ZPos=Tri_Neg->zcoord;};
311 if(Tri_Neg->ycoord==YcoordMin){XPos=YPos=Tri_Neg->xcoord; YPos=YcoordMax; ZPos=Tri_Neg->zcoord;};
312 if(Tri_Neg->zcoord==ZcoordMin){XPos=YPos=Tri_Neg->xcoord; YPos=Tri_Neg->ycoord; ZPos=ZcoordMax; };
313 Tri_Pos=Face_CenPos_Handle_varPos.get<
Composite_xyzcoord>().find(boost::make_tuple(XPos, YPos, ZPos));
320 vector<EntityHandle> TriNodesNeg, TriNodesPos;
321 double CoordNodeNeg[9], CoordNodePos[9];
326 for(
int ii=0; ii<3; ii++){
327 PrismNodes[ii]=TriNodesNeg[ii];
337 double XNodeNeg, YNodeNeg, ZNodeNeg, XNodePos, YNodePos, ZNodePos;
338 for(
int ii=0; ii<3; ii++){
339 if(Tri_Neg->xcoord==XcoordMin){XNodeNeg=XcoordMax; YNodeNeg=CoordNodeNeg[3*ii+1]; ZNodeNeg=CoordNodeNeg[3*ii+2];};
340 if(Tri_Neg->ycoord==YcoordMin){XNodeNeg=CoordNodeNeg[3*ii]; YNodeNeg=YcoordMax; ZNodeNeg=CoordNodeNeg[3*ii+2];};
341 if(Tri_Neg->zcoord==ZcoordMin){XNodeNeg=CoordNodeNeg[3*ii]; YNodeNeg=CoordNodeNeg[3*ii+1]; ZNodeNeg=ZcoordMax;};
342 for(
int jj=0; jj<3; jj++){
345 if(XNodeNeg>=0) XNodeNeg=
double(
int(XNodeNeg*1000.0+0.5))/1000.0;
else XNodeNeg=
double(
int(XNodeNeg*1000.0-0.5))/1000.0;
346 if(YNodeNeg>=0) YNodeNeg=
double(
int(YNodeNeg*1000.0+0.5))/1000.0;
else YNodeNeg=
double(
int(YNodeNeg*1000.0-0.5))/1000.0;
347 if(ZNodeNeg>=0) ZNodeNeg=
double(
int(ZNodeNeg*1000.0+0.5))/1000.0;
else ZNodeNeg=
double(
int(ZNodeNeg*1000.0-0.5))/1000.0;
349 XNodePos=CoordNodePos[3*jj]; YNodePos=CoordNodePos[3*jj+1]; ZNodePos=CoordNodePos[3*jj+2];
350 if(XNodePos>=0) XNodePos=
double(
int(XNodePos*1000.0+0.5))/1000.0;
else XNodePos=
double(
int(XNodePos*1000.0-0.5))/1000.0;
351 if(YNodePos>=0) YNodePos=
double(
int(YNodePos*1000.0+0.5))/1000.0;
else YNodePos=
double(
int(YNodePos*1000.0-0.5))/1000.0;
352 if(ZNodePos>=0) ZNodePos=
double(
int(ZNodePos*1000.0+0.5))/1000.0;
else ZNodePos=
double(
int(ZNodePos*1000.0-0.5))/1000.0;
354 if(XNodeNeg==XNodePos && YNodeNeg==YNodePos && ZNodeNeg==ZNodePos){
355 PrismNodes[3+ii]=TriNodesPos[jj];
361 double CoordNodesPrisms[18];
370 PrismRange.insert(PeriodicPrism);
377 ierr = m_field.get_entities_by_ref_level(bit_level0,
BitRefLevel().set(),meshset_level0); CHKERRQ(
ierr);
443 boost::shared_ptr<Hooke<adouble> > hooke_adouble(
new Hooke<adouble>);
444 boost::shared_ptr<Hooke<double> > hooke_double(
new Hooke<double>);
446 ierr = elastic.setBlocks(hooke_double,hooke_adouble); CHKERRQ(
ierr);
447 ierr = elastic.addElement(
"ELASTIC",
"DISPLACEMENT"); CHKERRQ(
ierr);
448 ierr = elastic.setOperators(
"DISPLACEMENT",
"MESH_NODE_POSITIONS",
false,
true); CHKERRQ(
ierr);
453 lagrangian_element_periodic.addLagrangiangElement(
"LAGRANGE_ELEM",
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",PrismRange);
454 lagrangian_element_trac.addLagrangiangElement(
"LAGRANGE_ELEM_TRANS",
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",
"MESH_NODE_POSITIONS");
476 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material); CHKERRQ(
ierr);
486 ierr = m_field.build_problems(); CHKERRQ(
ierr);
492 ierr = m_field.partition_problem(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
493 ierr = m_field.partition_finite_elements(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
495 ierr = m_field.partition_ghost_dofs(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
498 ierr = m_field.print_cubit_displacement_set(); CHKERRQ(
ierr);
499 ierr = m_field.print_cubit_force_set(); CHKERRQ(
ierr);
501 ierr = m_field.print_cubit_materials_set(); CHKERRQ(
ierr);
506 ierr = m_field.VecCreateGhost(
"ELASTIC_MECHANICS",
ROW,&
F[0]); CHKERRQ(
ierr);
507 for(
int ii = 1;ii<6;ii++) {
508 ierr = VecDuplicate(
F[0],&
F[ii]); CHKERRQ(
ierr);
511 ierr = m_field.VecCreateGhost(
"ELASTIC_MECHANICS",
COL,&
D); CHKERRQ(
ierr);
513 ierr = m_field.MatCreateMPIAIJWithArrays(
"ELASTIC_MECHANICS",&Aij); CHKERRQ(
ierr);
515 for(
int ii = 0;ii<6;ii++) {
516 ierr = VecZeroEntries(
F[ii]); CHKERRQ(
ierr);
517 ierr = VecGhostUpdateBegin(
F[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
518 ierr = VecGhostUpdateEnd(
F[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
521 ierr = MatZeroEntries(Aij); CHKERRQ(
ierr);
525 elastic.getLoopFeLhs().snes_B = Aij;
528 lagrangian_element_periodic.setRVEBCsOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",Aij,
F);
529 ierr = m_field.
loop_finite_elements(
"ELASTIC_MECHANICS",
"LAGRANGE_ELEM",lagrangian_element_periodic.getLoopFeRVEBCLhs()); CHKERRQ(
ierr);
530 ierr = m_field.
loop_finite_elements(
"ELASTIC_MECHANICS",
"LAGRANGE_ELEM",lagrangian_element_periodic.getLoopFeRVEBCRhs()); CHKERRQ(
ierr);
533 lagrangian_element_rigid_body_trans.setRVEBCsRigidBodyTranOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",Aij, lagrangian_element_periodic.setOfRVEBC);
534 ierr = m_field.
loop_finite_elements(
"ELASTIC_MECHANICS",
"LAGRANGE_ELEM_TRANS",lagrangian_element_rigid_body_trans.getLoopFeRVEBCLhs()); CHKERRQ(
ierr);
536 for(
int ii = 0;ii<6;ii++) {
537 ierr = VecGhostUpdateBegin(
F[ii],ADD_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
538 ierr = VecGhostUpdateEnd(
F[ii],ADD_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
539 ierr = VecAssemblyBegin(
F[ii]); CHKERRQ(
ierr);
540 ierr = VecAssemblyEnd(
F[ii]); CHKERRQ(
ierr);
543 ierr = MatAssemblyBegin(Aij,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
544 ierr = MatAssemblyEnd(Aij,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
550 int volume_vec_ghost[] = { 0 };
551 ierr = VecCreateGhost(
552 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?1:0,1,1,volume_vec_ghost,&volume_vec
554 ierr = VecZeroEntries(volume_vec); CHKERRQ(
ierr);
555 vol_elem.getOpPtrVector().push_back(
new VolumeCalculation(
"DISPLACEMENT",volume_vec));
559 ierr = VecAssemblyBegin(volume_vec); CHKERRQ(
ierr);
560 ierr = VecAssemblyEnd(volume_vec); CHKERRQ(
ierr);
562 ierr = VecSum(volume_vec,&rve_volume); CHKERRQ(
ierr);
564 ierr = VecView(volume_vec,PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(
ierr);
565 ierr = PetscPrintf(PETSC_COMM_WORLD,
"RVE Volume %3.2g\n",rve_volume); CHKERRQ(
ierr);
566 ierr = VecDestroy(&volume_vec);
580 void setDoPreProcess() { doPreProcess =
true; }
581 void unSetDoPreProcess() { doPreProcess =
false; }
582 void setDoPostProcess() { doPostProcess =
true; }
583 void unSetDoPostProcess() { doPostProcess =
false; }
592 PetscFunctionReturn(0);
599 PetscFunctionReturn(0);
605 ierr = post_proc.generateReferenceElementMesh(); CHKERRQ(
ierr);
606 ierr = post_proc.addFieldValuesPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
607 ierr = post_proc.addFieldValuesGradientPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
608 ierr = post_proc.addFieldValuesPostProc(
"MESH_NODE_POSITIONS"); CHKERRQ(
ierr);
609 ierr = post_proc.addFieldValuesGradientPostProc(
"MESH_NODE_POSITIONS"); CHKERRQ(
ierr);
612 map<int,NonlinearElasticElement::BlockData>::iterator sit = elastic.setOfBlocks.begin();
613 sit != elastic.setOfBlocks.end(); sit++
615 post_proc.getOpPtrVector().push_back(
617 post_proc.postProcMesh,
618 post_proc.mapGaussPts,
621 post_proc.commonData,
626 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
627 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
628 ierr = m_field.set_global_ghost_vector(
629 "ELASTIC_MECHANICS",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE
636 ierr = KSPCreate(PETSC_COMM_WORLD,&solver); CHKERRQ(
ierr);
637 ierr = KSPSetOperators(solver,Aij,Aij); CHKERRQ(
ierr);
638 ierr = KSPSetFromOptions(solver); CHKERRQ(
ierr);
639 ierr = KSPSetUp(solver); CHKERRQ(
ierr);
648 int stress_homo_ghost[] = { 0,1,2,3,4,5,6 };
649 ierr = VecCreateGhost(
650 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?6:0,6,6,stress_homo_ghost,&stress_homo
653 lagrangian_element_periodic.setRVEBCsHomoStressOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_PERIODIC",
"MESH_NODE_POSITIONS",stress_homo);
656 ierr = VecGetArray(stress_homo,&avec); CHKERRQ(
ierr);
657 for(
int ii = 0;ii<6;ii++) {
659 ierr = KSPSolve(solver,
F[ii],
D); CHKERRQ(
ierr);
660 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
661 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
662 ierr = m_field.set_global_ghost_vector(
663 "ELASTIC_MECHANICS",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE
667 post_proc.setDoPreProcess();
668 post_proc.unSetDoPostProcess();
670 "ELASTIC_MECHANICS",
"ELASTIC",post_proc
672 post_proc.unSetDoPreProcess();
673 post_proc.setDoPostProcess();
676 sss <<
"mode_" <<
"Disp" <<
"_" << ii <<
".h5m";
677 rval = post_proc.postProcMesh.write_file(
678 sss.str().c_str(),
"MOAB",
"PARALLEL=WRITE_PART"
682 ierr = VecZeroEntries(stress_homo); CHKERRQ(
ierr);
684 "ELASTIC_MECHANICS",
"LAGRANGE_ELEM",lagrangian_element_periodic.getLoopFeRVEBCStress()
687 PETSC_NULL,
"-my_rve_volume",&rve_volume,PETSC_NULL
689 ierr = VecAssemblyBegin(stress_homo); CHKERRQ(
ierr);
690 ierr = VecAssemblyEnd(stress_homo); CHKERRQ(
ierr);
691 ierr = VecScale(stress_homo,1.0/rve_volume); CHKERRQ(
ierr);
692 ierr = VecGhostUpdateBegin(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
693 ierr = VecGhostUpdateEnd(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
694 for(
int jj=0; jj<6; jj++) {
695 Dmat(jj,ii) = avec[jj];
699 ierr = VecRestoreArray(stress_homo,&avec); CHKERRQ(
ierr);
701 PETSC_COMM_WORLD,
"\nHomogenised Stiffens Matrix = \n\n"
704 for(
int ii=0; ii<6; ii++) {
707 "stress %d\t\t%8.5e\t\t%8.5e\t\t%8.5e\t\t%8.5e\t\t%8.5e\t\t%8.5e\n",
708 ii,Dmat(ii,0),Dmat(ii,1),Dmat(ii,2),Dmat(ii,3),Dmat(ii,4),Dmat(ii,5)
718 myfile <<
"<<<< Homonenised stress >>>>>" << endl;
720 if(pcomm->rank()==0){
721 for(
int ii=0; ii<6; ii++){
722 myfile << boost::format(
"%.3lf") %
roundn(Dmat(ii,0)) << endl;
732 for(
int ii = 0;ii<6;ii++) {
733 ierr = VecDestroy(&
F[ii]); CHKERRQ(
ierr);
736 ierr = MatDestroy(&Aij); CHKERRQ(
ierr);
737 ierr = KSPDestroy(&solver); CHKERRQ(
ierr);
738 ierr = VecDestroy(&stress_homo); CHKERRQ(
ierr);
740 ierr = PetscTime(&v2);CHKERRQ(
ierr);
741 ierr = PetscGetCPUTime(&t2);CHKERRQ(
ierr);
743 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"Total Rank %d Time = %f CPU Time = %f\n",pcomm->rank(),v2-v1,t2-t1);