23 using namespace MoFEM;
26 #include <boost/math/special_functions/round.hpp>
27 #include <MethodForForceScaling.hpp>
31 #include <petsctime.h>
39 #include <MethodForForceScaling.hpp>
44 static char help[] =
"...\n\n";
46 int main(
int argc,
char *argv[]) {
55 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
57 PetscBool flg = PETSC_TRUE;
60 if(flg != PETSC_TRUE) {
61 SETERRQ(PETSC_COMM_SELF,1,
"*** ERROR -my_file (MESH FILE NEEDED)");
65 if(flg != PETSC_TRUE) {
71 PetscInt mesh_refinement_level;
73 if(flg != PETSC_TRUE) {
74 mesh_refinement_level = 0;
81 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
82 if(pcomm == NULL) pcomm =
new ParallelComm(&moab,PETSC_COMM_WORLD);
94 Range SurTrisNeg, SurTrisPos;
95 ierr = m_field.get_cubit_msId_entities_by_dimension(101,
SIDESET,2,SurTrisNeg,
true); CHKERRQ(
ierr);
96 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 101 = %d\n",SurTrisNeg.size()); CHKERRQ(
ierr);
97 ierr = m_field.get_cubit_msId_entities_by_dimension(102,
SIDESET,2,SurTrisPos,
true); CHKERRQ(
ierr);
98 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 102 = %d\n",SurTrisPos.size()); CHKERRQ(
ierr);
100 Range SurNodesNeg,SurNodesPos;
102 cout<<
" All nodes on negative surfaces " << SurNodesNeg.size()<<endl;
104 cout<<
" All nodes on positive surfaces " << SurNodesPos.size()<<endl;
107 double roundfact=1e3;
double coords_nodes[3];
108 for(Range::iterator nit = SurNodesNeg.begin(); nit!=SurNodesNeg.end(); nit++) {
111 coords_nodes[0]=round(coords_nodes[0]*roundfact)/roundfact;
112 coords_nodes[1]=round(coords_nodes[1]*roundfact)/roundfact;
113 coords_nodes[2]=round(coords_nodes[2]*roundfact)/roundfact;
118 for(Range::iterator nit = SurNodesPos.begin(); nit!=SurNodesPos.end(); nit++) {
122 coords_nodes[0]=round(coords_nodes[0]*roundfact)/roundfact;
123 coords_nodes[1]=round(coords_nodes[1]*roundfact)/roundfact;
124 coords_nodes[2]=round(coords_nodes[2]*roundfact)/roundfact;
141 std::size_t found=it->getName().find(
"PotentialFlow");
142 if (found==std::string::npos)
continue;
145 cout<<
"No. of Fibres for Potential Flow : "<<noOfFibres<<endl;
147 vector<int> fibreList(noOfFibres,0);
152 std::size_t interfaceFound=it->getName().find(
"PotentialFlow_");
153 if (interfaceFound==std::string::npos)
continue;
155 std::string str2 = it->getName().substr (14,50);
157 fibreList[aaa] = atoi(str2.c_str());
175 int def_meshset_info[2] = {0,0};
176 rval = moab.tag_get_handle(
"MESHSET_INFO",2,MB_TYPE_INTEGER,th_meshset_info,MB_TAG_CREAT|MB_TAG_SPARSE,&def_meshset_info);
183 vector<BitRefLevel> bit_levels;
193 std::size_t interfaceFound=cit->getName().find(
"interface");
194 if (interfaceFound==std::string::npos)
continue;
196 ierr = PetscPrintf(PETSC_COMM_WORLD,
"Insert Interface %d\n",cit->getMeshsetId()); CHKERRQ(
ierr);
198 int meshset_data_int[2];
199 rval = moab.tag_get_data(th_meshset_info,&cubit_meshset,1,meshset_data_int);
CHKERRQ_MOAB(
rval);
200 if(meshset_data_int[1]==0){
204 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels.back(),
BitRefLevel().set(),MBTET,ref_level_meshset); CHKERRQ(
ierr);
205 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels.back(),
BitRefLevel().set(),MBPRISM,ref_level_meshset); CHKERRQ(
ierr);
206 Range ref_level_tets;
209 ierr = interface_ptr->
getSides(cubit_meshset,bit_levels.back(),
true); CHKERRQ(
ierr);
213 ierr = interface_ptr->
splitSides(ref_level_meshset,bit_levels.back(),cubit_meshset,
true,
true,0); CHKERRQ(
ierr);
216 int meshset_data_ins[2] = {ll,1};
217 rval = moab.tag_set_data(th_meshset_info,&cubit_meshset,1,meshset_data_ins);
CHKERRQ_MOAB(
rval);
222 ierr = m_field.update_meshset_by_entities_children(cubit_meshset,bit_levels.back(),cubit_meshset,MBVERTEX,
true); CHKERRQ(
ierr);
223 ierr = m_field.update_meshset_by_entities_children(cubit_meshset,bit_levels.back(),cubit_meshset,MBEDGE,
true); CHKERRQ(
ierr);
224 ierr = m_field.update_meshset_by_entities_children(cubit_meshset,bit_levels.back(),cubit_meshset,MBTRI,
true); CHKERRQ(
ierr);
225 ierr = m_field.update_meshset_by_entities_children(cubit_meshset,bit_levels.back(),cubit_meshset,MBTET,
true); CHKERRQ(
ierr);
231 int meshset_data_root[2]={ll,0};
237 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels.back(),
BitRefLevel().set(),MBTET,out_tet_meshset); CHKERRQ(
ierr);
244 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels.back(),
BitRefLevel().set(),MBPRISM,out_meshset_prism); CHKERRQ(
ierr);
250 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);
256 Range LatestRefinedTris;
257 rval = moab.get_entities_by_type(out_meshset, MBTRI,LatestRefinedTris,
true);
CHKERRQ_MOAB(
rval);
292 if(pcomm->rank()==0) {
297 for (
int cc = 0; cc < noOfFibres; cc++) {
298 ostringstream rrr, ppp1, ppp2;
299 rrr <<
"PotentialFlow_" << fibreList[cc];
302 if(it->getName() == rrr.str().c_str() ) {
306 new_tets = intersect(LatestRefinedTets,TetsInBlock);
312 Range new_tris_1, new_tris_2;
314 ppp1 <<
"PressureIO_" << fibreList[cc] <<
"_1";
315 ppp2 <<
"PressureIO_" << fibreList[cc] <<
"_2";
317 if (ppp1.str().c_str()==it->getName()){
320 new_tris_1 = intersect(LatestRefinedTris,tris);
325 if (ppp2.str().c_str()==it->getName()){
328 new_tris_2 = intersect(LatestRefinedTris,tris);
343 ierr = m_field.build_problems(); CHKERRQ(
ierr);
345 ierr = m_field.partition_problem(
"POTENTIAL_PROBLEM" ); CHKERRQ(
ierr);
346 ierr = m_field.partition_finite_elements(
"POTENTIAL_PROBLEM" ); CHKERRQ(
ierr);
347 ierr = m_field.partition_ghost_dofs(
"POTENTIAL_PROBLEM" ); CHKERRQ(
ierr);
349 ierr = m_field.VecCreateGhost(
"POTENTIAL_PROBLEM" ,
ROW,&
F); CHKERRQ(
ierr);
350 ierr = m_field.VecCreateGhost(
"POTENTIAL_PROBLEM" ,
COL,&
D); CHKERRQ(
ierr);
351 ierr = m_field.MatCreateMPIAIJWithArrays(
"POTENTIAL_PROBLEM" ,&
A); CHKERRQ(
ierr);
354 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material); CHKERRQ(
ierr);
356 ostringstream zero_pressure;
357 zero_pressure <<
"ZeroPressure_" << fibreList[cc];
361 if (zero_pressure.str().c_str()==it->getName()){
369 fix_nodes.insert(adj.begin(),adj.end());
371 fix_nodes.insert(adj.begin(),adj.end());
380 ierr = VecGhostUpdateBegin(
F,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
381 ierr = VecGhostUpdateEnd(
F,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
386 boost::ptr_map<string,NeummanForcesSurface> neumann_forces;
387 string fe_name_str =
"FLUX_FE";
390 if (ppp1.str().c_str()==it->getName() || ppp2.str().c_str()==it->getName()){
391 bool ho_geometry = m_field.
check_field(
"MESH_NODE_POSITIONS");
392 ierr = neumann_forces.at(
"FLUX_FE").addFlux(
"POTENTIAL_FIELD",
F,it->getMeshsetId(),ho_geometry); CHKERRQ(
ierr);
395 boost::ptr_map<string,NeummanForcesSurface>::iterator mit = neumann_forces.begin();
396 for(;mit!=neumann_forces.end();mit++) {
400 LaplacianElem elem(m_field,
A,
F);
406 ierr = MatAssemblyBegin(
A,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
407 ierr = MatAssemblyEnd(
A,MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
409 ierr = VecAssemblyBegin(
F); CHKERRQ(
ierr);
413 ierr = MatSetOption(
A,MAT_SPD,PETSC_TRUE); CHKERRQ(
ierr);
416 ierr = KSPCreate(PETSC_COMM_WORLD,&solver); CHKERRQ(
ierr);
417 ierr = KSPSetOperators(solver,
A,
A); CHKERRQ(
ierr);
418 ierr = KSPSetFromOptions(solver); CHKERRQ(
ierr);
419 ierr = KSPSetUp(solver); CHKERRQ(
ierr);
422 ierr = VecGhostUpdateBegin(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
423 ierr = VecGhostUpdateEnd(
D,INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
424 ierr = m_field.set_global_ghost_vector(
"POTENTIAL_PROBLEM",
ROW,
D,INSERT_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
426 if(pcomm->rank()==0) {
440 ierr = KSPDestroy(&solver); CHKERRQ(
ierr);
446 rval = moab.tag_get_handle(
"PHI",1,MB_TYPE_DOUBLE,th_phi,MB_TAG_CREAT|MB_TAG_SPARSE,&def_val);
CHKERRQ_MOAB(
rval);
449 double val = dof->get()->getFieldData();
454 ierr = m_field.
loop_dofs(
"POTENTIAL_FIELD",ent_method_phi_on_10nodeTet); CHKERRQ(
ierr);
455 ent_method_phi_on_10nodeTet.
setNodes =
false;
456 ierr = m_field.
loop_dofs(
"POTENTIAL_FIELD",ent_method_phi_on_10nodeTet); CHKERRQ(
ierr);
458 if(pcomm->rank()==0) {
462 if(pcomm->rank()==0) {
463 rval = moab.write_file(
"out_potential_flow.vtk",
"VTK",
"",&out_meshset_fibres,1);
CHKERRQ_MOAB(
rval);