Getting No. of Fibres and their index to be used for Potential Flow Problem
48 {
49
50 try {
51
53
54 moab::Core mb_instance;
55 moab::Interface& moab = mb_instance;
56 int rank;
57 MPI_Comm_rank(PETSC_COMM_WORLD,&rank);
58
59 PetscBool flg = PETSC_TRUE;
62 if(flg != PETSC_TRUE) {
63 SETERRQ(PETSC_COMM_SELF,1,"*** ERROR -my_file (MESH FILE NEEDED)");
64 }
67 if(flg != PETSC_TRUE) {
69 }
70
71 PetscInt mesh_refinement_level;
73 if(flg != PETSC_TRUE) {
74 mesh_refinement_level = 0;
75 }
76
77 const char *option;
78 option = "";
80 ParallelComm* pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
81 if(pcomm == NULL) pcomm = new ParallelComm(&moab,PETSC_COMM_WORLD);
82
83
86
87
88
89
90
91
92 Range SurTrisNeg, SurTrisPos;
93 ierr = m_field.get_cubit_msId_entities_by_dimension(101,
SIDESET,2,SurTrisNeg,
true); CHKERRQ(
ierr);
94 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 101 = %d\n",SurTrisNeg.size()); CHKERRQ(
ierr);
95 ierr = m_field.get_cubit_msId_entities_by_dimension(102,
SIDESET,2,SurTrisPos,
true); CHKERRQ(
ierr);
96 ierr = PetscPrintf(PETSC_COMM_WORLD,
"number of SideSet 102 = %d\n",SurTrisPos.size()); CHKERRQ(
ierr);
97
98 Range SurNodesNeg,SurNodesPos;
100 cout<<" All nodes on negative surfaces " << SurNodesNeg.size()<<endl;
102 cout<<" All nodes on positive surfaces " << SurNodesPos.size()<<endl;
103
104
105 double roundfact=1e3; double coords_nodes[3];
106
107 for(Range::iterator nit = SurNodesNeg.begin(); nit!=SurNodesNeg.end(); nit++) {
109
110 if(coords_nodes[0]>=0) coords_nodes[0]=
double(
int(coords_nodes[0]*roundfact+0.5))/roundfact;
else coords_nodes[0]=
double(
int(coords_nodes[0]*roundfact-0.5))/roundfact;
111 if(coords_nodes[1]>=0) coords_nodes[1]=
double(
int(coords_nodes[1]*roundfact+0.5))/roundfact;
else coords_nodes[1]=
double(
int(coords_nodes[1]*roundfact-0.5))/roundfact;
112 if(coords_nodes[2]>=0) coords_nodes[2]=
double(
int(coords_nodes[2]*roundfact+0.5))/roundfact;
else coords_nodes[2]=
double(
int(coords_nodes[2]*roundfact-0.5))/roundfact;
114
115 }
116
117
118 for(Range::iterator nit = SurNodesPos.begin(); nit!=SurNodesPos.end(); nit++) {
120
121 if(coords_nodes[0]>=0) coords_nodes[0]=
double(
int(coords_nodes[0]*roundfact+0.5))/roundfact;
else coords_nodes[0]=
double(
int(coords_nodes[0]*roundfact-0.5))/roundfact;
122 if(coords_nodes[1]>=0) coords_nodes[1]=
double(
int(coords_nodes[1]*roundfact+0.5))/roundfact;
else coords_nodes[1]=
double(
int(coords_nodes[1]*roundfact-0.5))/roundfact;
123 if(coords_nodes[2]>=0) coords_nodes[2]=
double(
int(coords_nodes[2]*roundfact+0.5))/roundfact;
else coords_nodes[2]=
double(
int(coords_nodes[2]*roundfact-0.5))/roundfact;
125
126 }
127
128
129
132
133
134 int noOfFibres=0;
136
137 std::size_t found=it->getName().find("PotentialFlow");
138 if (found==std::string::npos) continue;
139 noOfFibres += 1;
140 }
141 cout<<"No. of Fibres for Potential Flow : "<<noOfFibres<<endl;
142
143 vector<int> fibreList(noOfFibres,0);
144 int aaa=0;
145
147
148 std::size_t interfaceFound=it->getName().find("PotentialFlow_");
149 if (interfaceFound==std::string::npos) continue;
150
151 std::string str2 = it->getName().substr (14,50);
152
153 fibreList[aaa] = atoi(str2.c_str());
154 aaa += 1;
155 }
156
157
158
159 for (int cc = 0; cc < noOfFibres; cc++) {
160
161 ostringstream sss, rrr;
162
163
164 sss << "POTENTIAL_ELEM" << fibreList[cc];
165 cout<<sss.str().c_str()<<endl;
171
172
173 rrr << "POTENTIAL_PROBLEM" << fibreList[cc];
175
177
178 }
179
181 int def_meshset_info[2] = {0,0};
182 rval = moab.tag_get_handle(
183 "MESHSET_INFO",2,MB_TYPE_INTEGER,th_meshset_info,MB_TAG_CREAT|MB_TAG_SPARSE,&def_meshset_info
184 );
185
186 int meshset_data[2];
189
191 vector<BitRefLevel> bit_levels;
193
194
195 int ll = 1;
196
197 int meshset_data_root[2]={ll,0};
199
200
203 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels.back(),
BitRefLevel().set(),MBTET,out_tet_meshset); CHKERRQ(
ierr);
205
206
209 ierr = m_field.get_entities_by_ref_level(bit_levels.back(),
BitRefLevel().set(),out_meshset); CHKERRQ(
ierr);
211 Range LatestRefinedTets;
212 rval = moab.get_entities_by_type(out_meshset, MBTET,LatestRefinedTets,
true);
CHKERRQ_MOAB(
rval);
213
214
216
217
218
219 for (int cc = 0; cc < noOfFibres; cc++) {
220
222
223
224
225
226
227 ostringstream sss,rrr;
228
229 sss << "POTENTIAL_ELEM" << fibreList[cc];
230 rrr << "PotentialFlow_" << fibreList[cc];
231
232 if(it->getName() == rrr.str().c_str() ) {
235 Range block_rope_bit_level = intersect(LatestRefinedTets,TetsInBlock);
236
239
240
242
243 }
244 }
245 }
246
251
256
257
258 struct myMetaNeummanForces{
259
260 static PetscErrorCode addNeumannFluxBCElements(
262 const string problem_name,
264 const int fibre_id,
265 const string mesh_nodals_positions = "MESH_NODE_POSITIONS") {
266
267 PetscFunctionBegin;
268
269
270
271 ostringstream sss,rrr,ppp;
272 ppp << "PressureIO_" << fibre_id <<"_1";
273 sss << "PressureIO_" << fibre_id <<"_2";
274 rrr << "FLUX_FE" <<fibre_id;
280
281
282
283 if (ppp.str().c_str()==it->getName() || sss.str().c_str()==it->getName()){
284
287 }
292 }
293 }
294
295 PetscFunctionReturn(0);
296 }
297
298 static PetscErrorCode setNeumannFluxFiniteElementOperators(
300 boost::ptr_map<string,NeummanForcesSurface> &neumann_forces,
301 Vec &
F,
const string field_name,
const int fibre_id,
const string mesh_nodals_positions =
"MESH_NODE_POSITIONS") {
302
303 PetscFunctionBegin;
304
305 string fe_name;
306
307 ostringstream sss,rrr,ppp;
308 ppp << "PressureIO_" << fibre_id<<"_1";
309 sss << "PressureIO_" << fibre_id<<"_2";
310 rrr << "FLUX_FE" <<fibre_id;
311 fe_name = rrr.str().c_str();
314
315
316
317 if (ppp.str().c_str()==it->getName() || sss.str().c_str()==it->getName()){
318 bool ho_geometry = m_field.
check_field(mesh_nodals_positions);
319 ierr = neumann_forces.at(fe_name).addFlux(
field_name,
F,it->getMeshsetId(),ho_geometry); CHKERRQ(
ierr);
320
321
322
323
324 }
325 }
326 PetscFunctionReturn(0);
327 }
328
329 };
330
331 for (int cc = 0; cc < noOfFibres; cc++) {
332 ostringstream sss;
333 sss << "POTENTIAL_PROBLEM" << fibreList[cc];
334
335
336 ierr = myMetaNeummanForces::addNeumannFluxBCElements(m_field,sss.str().c_str(),
"POTENTIAL_FIELD",fibreList[cc]); CHKERRQ(
ierr);
337
339 }
340
341
343
345
347
348 ierr = m_field.build_problems(); CHKERRQ(
ierr);
349
350
351
352 for (int cc = 0; cc < noOfFibres; cc++) {
353 ostringstream sss;
354 sss << "POTENTIAL_PROBLEM" << fibreList[cc];
355 ierr = m_field.partition_problem( sss.str().c_str() ); CHKERRQ(
ierr);
356 ierr = m_field.partition_finite_elements( sss.str().c_str() ); CHKERRQ(
ierr);
357 ierr = m_field.partition_ghost_dofs( sss.str().c_str() ); CHKERRQ(
ierr);
358 }
359
360
361 ierr = m_field.print_cubit_displacement_set(); CHKERRQ(
ierr);
362 ierr = m_field.print_cubit_pressure_set(); CHKERRQ(
ierr);
363
364
365 vector<Vec>
F(noOfFibres);
366 vector<Vec>
D(noOfFibres);
367 vector<Mat>
A(noOfFibres);
368
369 for (int cc = 0; cc < noOfFibres; cc++) {
370 ostringstream sss,rrr,ttt;
371 sss << "POTENTIAL_PROBLEM" << fibreList[cc];
372 rrr << "POTENTIAL_ELEM" << fibreList[cc];
373 ttt << "ZeroPressure_" << fibreList[cc];
374 ierr = m_field.VecCreateGhost( sss.str().c_str() ,
ROW,&
F[cc]); CHKERRQ(
ierr);
375 ierr = m_field.VecCreateGhost( sss.str().c_str() ,
COL,&
D[cc]); CHKERRQ(
ierr);
376 ierr = m_field.MatCreateMPIAIJWithArrays( sss.str().c_str() ,&A[cc]); CHKERRQ(
ierr);
377
379 ierr = m_field.
loop_dofs(
"MESH_NODE_POSITIONS",ent_method_material); CHKERRQ(
ierr);
380
381
384
385
386 if (ttt.str().c_str()==it->getName()){
394 fix_nodes.insert(adj.begin(),adj.end());
396 fix_nodes.insert(adj.begin(),adj.end());
398 }
399 }
401
403
404
405 boost::ptr_map<string,NeummanForcesSurface> neumann_forces;
406 ierr = myMetaNeummanForces::setNeumannFluxFiniteElementOperators(m_field,neumann_forces,
F[cc],
"POTENTIAL_FIELD",fibreList[cc]); CHKERRQ(
ierr);
407 boost::ptr_map<string,NeummanForcesSurface>::iterator mit = neumann_forces.begin();
408 for(;mit!=neumann_forces.end();mit++) {
410 }
411
412 LaplacianElem elem(m_field,A[cc],
F[cc]);
413
414 ierr = MatZeroEntries(A[cc]); CHKERRQ(
ierr);
416
417
419
420 ierr = MatAssemblyBegin(A[cc],MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
421 ierr = MatAssemblyEnd(A[cc],MAT_FINAL_ASSEMBLY); CHKERRQ(
ierr);
422
423 ierr = VecAssemblyBegin(
F[cc]); CHKERRQ(
ierr);
424 ierr = VecAssemblyEnd(
F[cc]); CHKERRQ(
ierr);
425
426
427
428 ierr = MatSetOption(A[cc],MAT_SPD,PETSC_TRUE); CHKERRQ(
ierr);
429
430 KSP solver;
431 ierr = KSPCreate(PETSC_COMM_WORLD,&solver); CHKERRQ(
ierr);
432 ierr = KSPSetOperators(solver,A[cc],A[cc]); CHKERRQ(
ierr);
433 ierr = KSPSetFromOptions(solver); CHKERRQ(
ierr);
434 ierr = KSPSetUp(solver); CHKERRQ(
ierr);
435
436 ierr = KSPSolve(solver,
F[cc],
D[cc]); CHKERRQ(
ierr);
437 ierr = VecGhostUpdateBegin(
D[cc],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
438 ierr = VecGhostUpdateEnd(
D[cc],INSERT_VALUES,SCATTER_FORWARD); CHKERRQ(
ierr);
439 ierr = m_field.set_global_ghost_vector( sss.str().c_str() ,
ROW,
D[cc],INSERT_VALUES,SCATTER_REVERSE); CHKERRQ(
ierr);
440
441 ierr = KSPDestroy(&solver); CHKERRQ(
ierr);
442 ierr = VecDestroy(&
F[cc]); CHKERRQ(
ierr);
443 ierr = VecDestroy(&
D[cc]); CHKERRQ(
ierr);
444 ierr = MatDestroy(&A[cc]); CHKERRQ(
ierr);
445 }
446
448 double def_val = 0;
449 rval = moab.tag_get_handle(
"PHI",1,MB_TYPE_DOUBLE,th_phi,MB_TAG_CREAT|MB_TAG_SPARSE,&def_val);
CHKERRQ_MOAB(
rval);
452 double val = dof->get()->getFieldData();
454 }
455
457 ierr = m_field.
loop_dofs(
"POTENTIAL_FIELD",ent_method_phi_on_10nodeTet); CHKERRQ(
ierr);
458 ent_method_phi_on_10nodeTet.setNodes = false;
459 ierr = m_field.
loop_dofs(
"POTENTIAL_FIELD",ent_method_phi_on_10nodeTet); CHKERRQ(
ierr);
460
461 if(pcomm->rank()==0) {
463 }
464
467 ierr = m_field.get_entities_by_type_and_ref_level(bit_levels[0],
BitRefLevel().set(),MBTET,out_meshset1); CHKERRQ(
ierr);
469
470 if(pcomm->rank()==0) {
473
474 for (int cc = 0; cc < noOfFibres; cc++) {
477 ostringstream sss,rrr,ttt;
478 sss << "POTENTIAL_PROBLEM" << fibreList[cc];
479 rrr << "POTENTIAL_ELEM" << fibreList[cc];
480 ttt << "out_potential_flow" << fibreList[cc] <<".vtk";
483
486 }
487
490 }
491
493
494 }
496
497}
DEPRECATED typedef DirichletFixFieldAtEntitiesBc FixBcAtEntities
DEPRECATED typedef NeumannForcesSurface NeummanForcesSurface
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base nme:nme847.
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHKERRQ_MOAB(a)
check error code of MoAB function
#define _IT_GET_DOFS_FIELD_BY_NAME_FOR_LOOP_(MFIELD, NAME, IT)
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode add_ents_to_finite_element_by_type(const EntityHandle entities, const EntityType type, const std::string &name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
virtual bool check_field(const std::string &name) const =0
check if field is in database
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
virtual MoFEMErrorCode problem_basic_method_postProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode loop_finite_elements(const std::string problem_name, const std::string &fe_name, FEMethod &method, boost::shared_ptr< NumeredEntFiniteElement_multiIndex > fe_ptr=nullptr, MoFEMTypes bh=MF_EXIST, CacheTupleWeakPtr cache_ptr=CacheTupleSharedPtr(), int verb=DEFAULT_VERBOSITY)=0
Make a loop over finite elements.
#define _IT_CUBITMESHSETS_BY_BCDATA_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet in a moFEM field.
virtual MoFEMErrorCode get_problem_finite_elements_entities(const std::string name, const std::string &fe_name, const EntityHandle meshset)=0
add finite elements to the meshset
virtual MoFEMErrorCode add_problem(const std::string &name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add problem.
virtual MoFEMErrorCode modify_problem_ref_level_add_bit(const std::string &name_problem, const BitRefLevel &bit)=0
add ref level to problem
virtual MoFEMErrorCode modify_problem_add_finite_element(const std::string name_problem, const std::string &fe_name)=0
add finite element to problem, this add entities assigned to finite element to a particular problem
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
static MoFEMErrorCodeGeneric< moab::ErrorCode > rval
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
constexpr auto field_name
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode problem_basic_method_preProcess(const Problem *problem_ptr, BasicMethod &method, int verb=DEFAULT_VERBOSITY)=0
Set data for BasicMethod.
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
DEPRECATED MoFEMErrorCode seed_ref_level_3D(const EntityHandle meshset, const BitRefLevel &bit, int verb=-1)
seed 2D entities in the meshset and their adjacencies (only TETs adjacencies) in a particular BitRefL...
Projection of edge entities with one mid-node on hierarchical basis.