95 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
98 PetscBool flg = PETSC_TRUE;
101 if(flg != PETSC_TRUE) {
102 SETERRQ(PETSC_COMM_SELF,1,
"*** ERROR -my_file (MESH FILE NEEDED)");
106 if(flg != PETSC_TRUE) {
114 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
115 if(pcomm == NULL) pcomm =
new ParallelComm(&moab,PETSC_COMM_WORLD);
118 PetscLogDouble t1,t2;
119 PetscLogDouble v1,v2;
120 ierr = PetscTime(&v1); CHKERRQ(
ierr);
121 ierr = PetscGetCPUTime(&t1); CHKERRQ(
ierr);
136 ierr = m_field.get_entities_by_ref_level(bit_level0,
BitRefLevel().set(),meshset_level0); CHKERRQ(
ierr);
170 boost::shared_ptr<Hooke<adouble> > hooke_adouble(
new Hooke<adouble>);
171 boost::shared_ptr<Hooke<double> > hooke_double(
new Hooke<double>);
173 ierr = elastic.setBlocks(hooke_double,hooke_adouble); CHKERRQ(
ierr);
174 ierr = elastic.addElement(
"ELASTIC",
"DISPLACEMENT"); CHKERRQ(
ierr);
175 ierr = elastic.setOperators(
"DISPLACEMENT",
"MESH_NODE_POSITIONS",
false,
true); CHKERRQ(
ierr);
179 lagrangian_element.addLagrangiangElement(
"LAGRANGE_ELEM",
"DISPLACEMENT",
"LAGRANGE_MUL_TRAC",
"MESH_NODE_POSITIONS");
180 lagrangian_element.addLagrangiangElement(
"LAGRANGE_ELEM_TRANS",
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",
"MESH_NODE_POSITIONS");
181 lagrangian_element.addLagrangiangElement(
"LAGRANGE_ELEM_ROT",
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_ROT",
"MESH_NODE_POSITIONS");
204 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material); CHKERRQ(
ierr);
213 ierr = m_field.build_problems(); CHKERRQ(
ierr);
219 ierr = m_field.partition_problem(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
220 ierr = m_field.partition_finite_elements(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
222 ierr = m_field.partition_ghost_dofs(
"ELASTIC_MECHANICS"); CHKERRQ(
ierr);
225 ierr = m_field.print_cubit_displacement_set(); CHKERRQ(
ierr);
226 ierr = m_field.print_cubit_force_set(); CHKERRQ(
ierr);
228 ierr = m_field.print_cubit_materials_set(); CHKERRQ(
ierr);
232 ierr = m_field.VecCreateGhost(
"ELASTIC_MECHANICS",
ROW,&
F[0]); CHKERRQ(
ierr);
233 for(
int ii = 1;ii<6;ii++) {
234 ierr = VecDuplicate(
F[0],&
F[ii]); CHKERRQ(
ierr);
238 ierr = m_field.VecCreateGhost(
"ELASTIC_MECHANICS",
COL,&
D); CHKERRQ(
ierr);
241 ierr = m_field.MatCreateMPIAIJWithArrays(
"ELASTIC_MECHANICS",&Aij); CHKERRQ(
ierr);
244 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
245 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
246 ierr = m_field.set_global_ghost_vector(
247 "ELASTIC_MECHANICS",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE
250 for(
int ii = 0;ii<6;ii++) {
251 ierr = VecZeroEntries(
F[ii]); CHKERRQ(
ierr);
252 ierr = VecGhostUpdateBegin(
F[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
253 ierr = VecGhostUpdateEnd(
F[ii],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
255 ierr = MatZeroEntries(Aij); CHKERRQ(
ierr);
258 elastic.getLoopFeLhs().snes_B = Aij;
260 lagrangian_element.setRVEBCsOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_TRAC",
"MESH_NODE_POSITIONS",Aij,
F);
265 lagrangian_element_rigid_body_trans.setRVEBCsRigidBodyTranOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_TRANS",Aij, lagrangian_element.setOfRVEBC);
266 ierr = m_field.
loop_finite_elements(
"ELASTIC_MECHANICS",
"LAGRANGE_ELEM_TRANS",lagrangian_element_rigid_body_trans.getLoopFeRVEBCLhs()); CHKERRQ(
ierr);
269 lagrangian_element_rigid_body_rot.setRVEBCsRigidBodyRotOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_RIGID_ROT",Aij, lagrangian_element.setOfRVEBC);
270 ierr = m_field.
loop_finite_elements(
"ELASTIC_MECHANICS",
"LAGRANGE_ELEM_ROT",lagrangian_element_rigid_body_rot.getLoopFeRVEBCLhs()); CHKERRQ(
ierr);
277 ierr = MatAssemblyBegin(Aij,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
278 ierr = MatAssemblyEnd(Aij,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
280 for(
int ii = 0;ii<6;ii++) {
281 ierr = VecGhostUpdateBegin(
F[ii],ADD_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
282 ierr = VecGhostUpdateEnd(
F[ii],ADD_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
283 ierr = VecAssemblyBegin(
F[ii]); CHKERRQ(
ierr);
284 ierr = VecAssemblyEnd(
F[ii]); CHKERRQ(
ierr);
301 int volume_vec_ghost[] = { 0 };
302 ierr = VecCreateGhost(
303 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?1:0,1,1,volume_vec_ghost,&volume_vec
305 ierr = VecZeroEntries(volume_vec); CHKERRQ(
ierr);
306 vol_elem.getOpPtrVector().push_back(
new VolumeCalculation(
"DISPLACEMENT",volume_vec));
310 ierr = VecAssemblyBegin(volume_vec); CHKERRQ(
ierr);
311 ierr = VecAssemblyEnd(volume_vec); CHKERRQ(
ierr);
313 ierr = VecSum(volume_vec,&rve_volume); CHKERRQ(
ierr);
315 ierr = VecView(volume_vec,PETSC_VIEWER_STDOUT_WORLD); CHKERRQ(
ierr);
316 ierr = PetscPrintf(PETSC_COMM_WORLD,
"RVE Volume %3.2g\n",rve_volume); CHKERRQ(
ierr);
317 ierr = VecDestroy(&volume_vec);
330 void setDoPreProcess() { doPreProcess =
true; }
331 void unSetDoPreProcess() { doPreProcess =
false; }
332 void setDoPostProcess() { doPostProcess =
true; }
333 void unSetDoPostProcess() { doPostProcess =
false; }
342 PetscFunctionReturn(0);
349 PetscFunctionReturn(0);
355 ierr = post_proc.generateReferenceElementMesh(); CHKERRQ(
ierr);
356 ierr = post_proc.addFieldValuesPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
357 ierr = post_proc.addFieldValuesGradientPostProc(
"DISPLACEMENT"); CHKERRQ(
ierr);
358 ierr = post_proc.addFieldValuesPostProc(
"MESH_NODE_POSITIONS"); CHKERRQ(
ierr);
359 ierr = post_proc.addFieldValuesGradientPostProc(
"MESH_NODE_POSITIONS"); CHKERRQ(
ierr);
362 map<int,NonlinearElasticElement::BlockData>::iterator sit = elastic.setOfBlocks.begin();
363 sit != elastic.setOfBlocks.end(); sit++
365 post_proc.getOpPtrVector().push_back(
367 post_proc.postProcMesh,
368 post_proc.mapGaussPts,
371 post_proc.commonData,
376 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
377 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
378 ierr = m_field.set_global_ghost_vector(
379 "ELASTIC_MECHANICS",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE
386 ierr = KSPCreate(PETSC_COMM_WORLD,&solver); CHKERRQ(
ierr);
387 ierr = KSPSetOperators(solver,Aij,Aij); CHKERRQ(
ierr);
388 ierr = KSPSetFromOptions(solver); CHKERRQ(
ierr);
389 ierr = KSPSetUp(solver); CHKERRQ(
ierr);
398 int stress_homo_ghost[] = { 0,1,2,3,4,5,6 };
399 ierr = VecCreateGhost(
400 PETSC_COMM_WORLD,(!m_field.
get_comm_rank())?6:0,6,6,stress_homo_ghost,&stress_homo
403 lagrangian_element.setRVEBCsHomoStressOperators(
"DISPLACEMENT",
"LAGRANGE_MUL_TRAC",
"MESH_NODE_POSITIONS",stress_homo);
406 ierr = VecGetArray(stress_homo,&avec); CHKERRQ(
ierr);
407 for(
int ii = 0;ii<6;ii++) {
409 ierr = KSPSolve(solver,
F[ii],
D); CHKERRQ(
ierr);
410 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
411 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
412 ierr = m_field.set_global_ghost_vector(
413 "ELASTIC_MECHANICS",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE
417 post_proc.setDoPreProcess();
418 post_proc.unSetDoPostProcess();
420 "ELASTIC_MECHANICS",
"ELASTIC",post_proc
422 post_proc.unSetDoPreProcess();
423 post_proc.setDoPostProcess();
426 sss <<
"mode_" <<
"Disp" <<
"_" << ii <<
".h5m";
427 rval = post_proc.postProcMesh.write_file(
428 sss.str().c_str(),
"MOAB",
"PARALLEL=WRITE_PART"
432 ierr = VecZeroEntries(stress_homo); CHKERRQ(
ierr);
434 "ELASTIC_MECHANICS",
"LAGRANGE_ELEM",lagrangian_element.getLoopFeRVEBCStress()
437 PETSC_NULL,
"-my_rve_volume",&rve_volume,PETSC_NULL
439 ierr = VecAssemblyBegin(stress_homo); CHKERRQ(
ierr);
440 ierr = VecAssemblyEnd(stress_homo); CHKERRQ(
ierr);
441 ierr = VecScale(stress_homo,1.0/rve_volume); CHKERRQ(
ierr);
442 ierr = VecGhostUpdateBegin(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
443 ierr = VecGhostUpdateEnd(stress_homo,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
444 for(
int jj=0; jj<6; jj++) {
445 Dmat(jj,ii) = avec[jj];
449 ierr = VecRestoreArray(stress_homo,&avec); CHKERRQ(
ierr);
451 PETSC_COMM_WORLD,
"\nHomogenised Stiffens Matrix = \n\n"
454 for(
int ii=0; ii<6; ii++) {
457 "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",
458 ii,Dmat(ii,0),Dmat(ii,1),Dmat(ii,2),Dmat(ii,3),Dmat(ii,4),Dmat(ii,5)
468 myfile <<
"<<<< Homonenised stress >>>>>" << endl;
470 if(pcomm->rank()==0){
471 for(
int ii=0; ii<6; ii++){
472 myfile << boost::format(
"%.3lf") %
roundn(Dmat(ii,0)) << endl;
482 for(
int ii = 0;ii<6;ii++) {
483 ierr = VecDestroy(&
F[ii]); CHKERRQ(
ierr);
486 ierr = MatDestroy(&Aij); CHKERRQ(
ierr);
487 ierr = KSPDestroy(&solver); CHKERRQ(
ierr);
488 ierr = VecDestroy(&stress_homo); CHKERRQ(
ierr);
490 ierr = PetscTime(&v2);CHKERRQ(
ierr);
491 ierr = PetscGetCPUTime(&t2);CHKERRQ(
ierr);
493 PetscSynchronizedPrintf(PETSC_COMM_WORLD,
"Total Rank %d Time = %f CPU Time = %f\n",pcomm->rank(),v2-v1,t2-t1);