v0.14.0
Loading...
Searching...
No Matches
unsatu2dFlow_prob.cpp
Go to the documentation of this file.
1#include <stdlib.h>
4
5using namespace MoFEM;
6using namespace UFOperators2D;
7
8static char help[] = "...\n\n";
9template <int dim>
10struct UFProblem {
11public:
12 UFProblem(moab::Core &mb_instance, MoFEM::Core &core, const int order, const int n_species)
13 : moab( mb_instance)
14 , m_field(core)
15 , order(order)
16 , nb_species(n_species)
17 , cOmm(m_field.get_comm())
18 , rAnk(m_field.get_comm_rank()) {
19 vol_ele_stiff_rhs = boost::shared_ptr<VolEle>(new VolEle(m_field));
20 vol_ele_stiff_lhs = boost::shared_ptr<VolEle>(new VolEle(m_field));
21
22 boundary_ele_rhs = boost::shared_ptr<FaceEle>(new FaceEle(m_field));
23
24
25 post_proc = boost::shared_ptr<PostProc>(
26 new PostProc(m_field));
27
28 data.resize(nb_species);
29 values_ptr.resize(nb_species);
30 grads_ptr.resize(nb_species);
31 dots_ptr.resize(nb_species);
33
34 for(int i = 0; i < nb_species; ++i){
35 data[i] = boost::shared_ptr<PreviousData>(new PreviousData());
36 grads_ptr[i] = boost::shared_ptr<MatrixDouble>(data[i], &data[i]->grads);
37 values_ptr[i] = boost::shared_ptr<VectorDouble>(data[i], &data[i]->values);
38 dots_ptr[i] = boost::shared_ptr<VectorDouble>(data[i], &data[i]->dot_values);
39 }
40
41 }
42
43 // UFProblem(const int order) : order(order){}
45
46private:
48 MoFEMErrorCode add_fe(std::string field_name);
49 MoFEMErrorCode set_blockData(std::map<int, BlockData> &block_data_map);
50
51 MoFEMErrorCode set_initial_values(std::string field_name, int block_id,
52 Range &surface, double &init_val);
53
54
55
57
58
59
60
61
62 MoFEMErrorCode update_vol_fe(boost::shared_ptr<VolEle> &vol_ele,
63 boost::shared_ptr<PreviousData> &data);
65 boost::shared_ptr<VectorDouble> &values_ptr,
66 boost::shared_ptr<MatrixDouble> &grads_ptr,
67 boost::shared_ptr<VectorDouble> &dots_ptr);
68
70 boost::shared_ptr<PreviousData> &data,
71 std::map<int, BlockData> &block_map);
72
74 boost::shared_ptr<VectorDouble> &values_ptr,
75 boost::shared_ptr<MatrixDouble> &grads_ptr);
77 boost::shared_ptr<PreviousData> &data,
78 std::map<int, BlockData> &block_map);
79
81
82
87
90
91 moab::Interface &moab;
92
95
96
98
99 std::vector<Range> inner_surface;
100
102
103 MPI_Comm cOmm;
104 const int rAnk;
105
106 int order;
108
109 std::map<int, BlockData> material_blocks;
110
111 boost::shared_ptr<VolEle> vol_ele_stiff_rhs;
112 boost::shared_ptr<VolEle> vol_ele_stiff_lhs;
113 boost::shared_ptr<FaceEle> boundary_ele_rhs;
114
115 boost::shared_ptr<VolEle> vol_mass_ele;
116
117 boost::shared_ptr<PostProc> post_proc;
118 boost::shared_ptr<Monitor> monitor_ptr;
119
120
121 std::vector<boost::shared_ptr<PreviousData>> data;
122
123 std::vector<boost::shared_ptr<MatrixDouble>> grads_ptr;
124 std::vector<boost::shared_ptr<VectorDouble>> values_ptr;
125 std::vector<boost::shared_ptr<VectorDouble>> dots_ptr;
126
127 boost::shared_ptr<ForcesAndSourcesCore> null;
128};
129template <int dim>
132 CHKERR m_field.getInterface(simple_interface);
133 CHKERR simple_interface->getOptions();
134 CHKERR simple_interface->loadFile();
136}
137
138template <int dim>
141 CHKERR simple_interface->addDomainField(field_name, H1, AINSWORTH_LEGENDRE_BASE, 1);
142
143 CHKERR simple_interface->addBoundaryField(field_name, H1,
145 CHKERR simple_interface->setFieldOrder(field_name, order);
146
147
149}
150
151template <int dim>
155 string name = it->getName();
156 const int id = it->getMeshsetId();
157 if (name.compare(0, 14, "REGION1") == 0) {
158 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
159 id, BLOCKSET, dim, block_map[id].block_ents, true);
160 // cout << "Name: " << name << endl;
161
162 // block_map[id].block_ents.print();
163 // cout << "size: ";
164 // cout << block_map[id].block_ents.size() << endl;
165
166
167 block_map[id].block_id = id;
168 block_map[id].K_s = 1.000;
169 block_map[id].h_s = 0.000;
170 block_map[id].theta_s = 0.43000;
171 block_map[id].theta_m = 0.43000;
172 block_map[id].theta_r = 0.04500;
173 block_map[id].alpha = 1.812500;
174 block_map[id].nn = 5.3800;
175
176 } else if (name.compare(0, 14, "REGION2") == 0) {
177 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
178 id, BLOCKSET, dim, block_map[id].block_ents, true);
179
180 block_map[id].block_id = id;
181 } else if (name.compare(0, 14, "REGION3") == 0) {
182 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
183 id, BLOCKSET, dim, block_map[id].block_ents, true);
184
185 block_map[id].block_id = id;
186 } else if (name.compare(0, 14, "REGION4") == 0) {
187 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
188 id, BLOCKSET, dim, block_map[id].block_ents, true);
189
190 block_map[id].block_id = id;
191 } else if (name.compare(0, 14, "REGION5") == 0) {
192 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
193 id, BLOCKSET, dim, block_map[id].block_ents, true);
194
195 block_map[id].block_id = id;
196 }
197 }
199}
200
201template <int dim>
203 int block_id, Range &surface, double &init_val) {
205 if (m_field.getInterface<MeshsetsManager>()->checkMeshset(block_id,
206 BLOCKSET)) {
207 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
208 block_id, BLOCKSET, dim, surface, true);
209 }
210 if (!surface.empty()) {
211 Range surface_verts;
212
213 CHKERR moab.get_connectivity(surface, surface_verts, false);
214 CHKERR m_field.getInterface<FieldBlas>()->setField(
215 init_val, MBVERTEX, surface_verts, field_name);
216 }
217
219}
220
221
222
223template <int dim>
224MoFEMErrorCode UFProblem<dim>::update_vol_fe(boost::shared_ptr<VolEle> &vol_ele,
225 boost::shared_ptr<PreviousData> &data) {
227 auto det_ptr = boost::make_shared<VectorDouble>();
228 auto jac_ptr = boost::make_shared<MatrixDouble>();
229 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
230 vol_ele->getOpPtrVector().push_back(new OpCalculateHOJacForFace(jac_ptr));
231 vol_ele->getOpPtrVector()
232 push_back(new OpInvertMatrix<2>(jac_ptr, det_ptr, inv_jac_ptr));
233 vol_ele->getOpPtrVector().push_back(new OpSetInvJacH1ForFace(data->invJac));
235}
236
237template <int dim>
239 boost::shared_ptr<VectorDouble> &values_ptr,
240 boost::shared_ptr<MatrixDouble> &grads_ptr,
241 boost::shared_ptr<VectorDouble> &dots_ptr) {
242
244
245 vol_ele_stiff_rhs->getOpPtrVector().push_back(
247 vol_ele_stiff_rhs->getOpPtrVector().push_back(
249 vol_ele_stiff_rhs->getOpPtrVector().push_back(
252}
253template <int dim>
255 boost::shared_ptr<PreviousData> &data,
256 std::map<int, BlockData> &block_map) {
258
259 vol_ele_stiff_rhs->getOpPtrVector().push_back(
261 // boundary_ele_rhs->getOpPtrVector().push_back(
262 // new OpAssembleNaturalBCRhs(field_name,natural_bdry_ents));
264}
265
266template <int dim>
268 boost::shared_ptr<VectorDouble> &values_ptr,
269 boost::shared_ptr<MatrixDouble> &grads_ptr) {
271 vol_ele_stiff_lhs->getOpPtrVector().push_back(
273
274 vol_ele_stiff_lhs->getOpPtrVector().push_back(
277}
278template <int dim>
280 boost::shared_ptr<PreviousData> &data,
281 std::map<int, BlockData> &block_map) {
283
284 vol_ele_stiff_lhs->getOpPtrVector().push_back(
286
288}
289template <int dim>
292 auto vol_rule = [](int, int, int p) -> int { return 2 * p; };
293
294
295 vol_ele_stiff_rhs->getRuleHook = vol_rule;
296
297 vol_ele_stiff_lhs->getRuleHook = vol_rule;
298 boundary_ele_rhs->getRuleHook = vol_rule;
300}
301
302
303template <int dim>
306 CHKERR TSSetType(ts, TSARKIMEX);
307 CHKERR TSARKIMEXSetType(ts, TSARKIMEXA2);
308
309 CHKERR DMMoFEMTSSetIJacobian(dm, simple_interface->getDomainFEName(),
310 vol_ele_stiff_lhs, null, null);
311
312 CHKERR DMMoFEMTSSetIFunction(dm, simple_interface->getDomainFEName(),
313 vol_ele_stiff_rhs, null, null);
314
315 CHKERR DMMoFEMTSSetIFunction(dm, simple_interface->getBoundaryFEName(),
316 boundary_ele_rhs, null, null);
317
319}
320template <int dim>
323 post_proc->addFieldValuesPostProc(field_name);
325}
326
327template <int dim>
330 CHKERR DMMoFEMTSSetMonitor(dm, ts, simple_interface->getDomainFEName(),
331 monitor_ptr, null, null);
333}
334template <int dim>
337 // Create solution vector
340 CHKERR DMoFEMMeshToLocalVector(dm, X, INSERT_VALUES, SCATTER_FORWARD);
341 // Solve problem
342 double ftime = 1;
343 CHKERR TSSetDM(ts, dm);
344 CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
345 CHKERR TSSetSolution(ts, X);
346 CHKERR TSSetFromOptions(ts);
347 CHKERR TSSolve(ts, X);
349}
350template <int dim>
353 global_error = 0;
354 std::vector<std::string> mass_names(nb_species);
355
356 for(int i = 0; i < nb_species; ++i){
357 mass_names[i] = "h" + boost::lexical_cast<std::string>(i+1);
358 }
359 CHKERR setup_system();
360 for (int i = 0; i < nb_species; ++i) {
361 add_fe(mass_names[i]);
362 }
363
364
365
366 CHKERR simple_interface->setUp();
367
369 string name = it->getName();
370 if (name.compare(0, 14, "ESSENTIAL") == 0) {
371 CHKERR it->getMeshsetIdEntitiesByDimension(m_field.get_moab(), dim-1,
372 natural_bdry_ents, true);
373 }
374 }
375 // Range face_edges;
376
377 // CHKERR moab.get_adjacencies(natural_bdry_ents, dim-1, false, face_edges, moab::Interface::UNION);
378
379 Range edges_verts;
380 CHKERR moab.get_connectivity(natural_bdry_ents, edges_verts, false);
381
382 Range bdry_ents;
383 bdry_ents = unite(natural_bdry_ents, edges_verts);
384 // bdry_ents = unite(bdry_ents, face_edges_verts);
385
386 // bdry_ents.print();
387 // cout << "size: " <<endl;
388 // cout << bdry_ents.size() <<endl;
389 // cout << bdry_ents <<endl;
390
391 CHKERR m_field.getInterface<ProblemsManager>()->removeDofsOnEntities(
392 "SimpleProblem", mass_names[0], bdry_ents);
393
394 CHKERR set_blockData(material_blocks);
395
396 cout << "Material Block Size: " << material_blocks.size() << endl;
397
398 material_blocks[1003].block_ents.print();
399 cout << "size: ";
400 cout << material_blocks[1003].block_ents.size() << endl;
401
402 VectorDouble initVals;
403 initVals.resize(3, false);
404 initVals.clear();
405
406 initVals[0] = -0.8;
407 initVals[1] = 0.0;
408 initVals[2] = 0.0;
409
410 for (int i = 0; i < nb_species; ++i) {
411 CHKERR set_initial_values(mass_names[i], i + 2, inner_surface[i], initVals[i]);
412
413 }
414
415 if (!natural_bdry_ents.empty()) {
416 Range surface_verts;
417
418 CHKERR moab.get_connectivity(natural_bdry_ents, surface_verts, false);
419 CHKERR m_field.getInterface<FieldBlas>()->setField(
420 0.0, MBVERTEX, surface_verts, mass_names[0]);
421 }
422
423
424
425
426
427
428
429 dm = simple_interface->getDM();
430
431 CHKERR update_vol_fe(vol_ele_stiff_rhs, data[0]);
432
433 for (int i = 0; i < nb_species; ++i) {
434 CHKERR update_stiff_rhs(mass_names[i], values_ptr[i], grads_ptr[i],
435 dots_ptr[i]);
436 CHKERR push_stiff_rhs(mass_names[i], data[i], material_blocks);
437 }
438
439
440 CHKERR update_vol_fe(vol_ele_stiff_lhs, data[0]);
441
442 for (int i = 0; i < nb_species; ++i) {
443 CHKERR update_stiff_lhs(mass_names[i], values_ptr[i], grads_ptr[i]);
444 CHKERR push_stiff_lhs(mass_names[i], data[i],
445 material_blocks); // nb_species times
446 }
447
448
449 CHKERR set_integration_rule();
450
451 ts = createTS(m_field.get_comm());
452
453 CHKERR set_fe_in_loop();
454
455 post_proc->generateReferenceElementMesh(); // only once
456
457 for (int i = 0; i < nb_species; ++i) {
458 CHKERR post_proc_fields(mass_names[i]);
459 }
460
461 monitor_ptr = boost::shared_ptr<Monitor>(
462 new Monitor(cOmm, rAnk, dm, post_proc, global_error)); // nb_species times
463 CHKERR output_result(); // only once
464
465 CHKERR solve(); // only once
466
468}
469
470int main(int argc, char *argv[]) {
471 const char param_file[] = "param_file.petsc";
473 try {
474 moab::Core mb_instance;
475 moab::Interface &moab = mb_instance;
476 MoFEM::Core core(moab);
477 DMType dm_name = "DMMOFEM";
478 CHKERR DMRegister_MoFEM(dm_name);
479
480
481 int order = 1;
482 CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-order", &order, PETSC_NULL);
483 int nb_species = 1;
484 UFProblem<2> unsatu_flow_problem(mb_instance, core, order, nb_species);
485 CHKERR unsatu_flow_problem.run_analysis();
486 }
489 return 0;
490 }
static Index< 'p', 3 > p
std::string param_file
int main()
Definition: adol-c_atom.cpp:46
MoFEM::FaceElementForcesAndSourcesCore FaceEle
static char help[]
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
Definition: definitions.h:60
@ H1
continuous field
Definition: definitions.h:85
#define MoFEMFunctionBegin
First executable line of each MoFEM function, used for error handling. Final line of MoFEM functions ...
Definition: definitions.h:346
@ BLOCKSET
Definition: definitions.h:148
#define MoFEMFunctionReturn(a)
Last executable line of each PETSc function used for error handling. Replaces return()
Definition: definitions.h:416
#define CHKERR
Inline error check.
Definition: definitions.h:535
constexpr int order
const int dim
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
Definition: DMMoFEM.cpp:786
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode)
set local (or ghosted) vector values on mesh for partition only
Definition: DMMoFEM.cpp:509
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
Definition: DMMoFEM.cpp:839
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
Definition: DMMoFEM.cpp:1153
bool checkMeshset(const int ms_id, const CubitBCType cubit_bc_type) const
check for CUBIT Id and CUBIT type
#define _IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_(MESHSET_MANAGER, CUBITBCTYPE, IT)
Iterator that loops over a specific Cubit MeshSet having a particular BC meshset in a moFEM field.
FTensor::Index< 'i', SPACE_DIM > i
PetscErrorCode MoFEMErrorCode
MoFEM/PETSc error code.
Definition: Exceptions.hpp:56
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
PetscErrorCode DMMoFEMTSSetMonitor(DM dm, TS ts, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
Set Monitor To TS solver.
Definition: DMMoFEM.cpp:1042
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
OpCalculateHOJacForFaceImpl< 2 > OpCalculateHOJacForFace
OpCalculateScalarFieldValuesDot OpCalculateScalarValuesDot
auto createTS(MPI_Comm comm)
PostProcFaceOnRefinedMesh PostProc
constexpr auto field_name
Core (interface) class.
Definition: Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition: Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
Deprecated interface functions.
Basic algebra on fields.
Definition: FieldBlas.hpp:21
Interface for managing meshsets containing materials and boundary conditions.
Get field gradients at integration pts for scalar filed rank 0, i.e. vector field.
Get value at integration points for scalar field.
Problem manager is used to build and partition problems.
Simple interface for fast problem set-up.
Definition: Simple.hpp:27
intrusive_ptr for managing petsc objects
SmartPetscObj< TS > ts
MoFEMErrorCode push_stiff_lhs(std::string field_name, boost::shared_ptr< PreviousData > &data, std::map< int, BlockData > &block_map)
boost::shared_ptr< VolEle > vol_ele_stiff_rhs
boost::shared_ptr< VolEle > vol_mass_ele
MoFEMErrorCode update_stiff_lhs(std::string field_name, boost::shared_ptr< VectorDouble > &values_ptr, boost::shared_ptr< MatrixDouble > &grads_ptr)
MoFEM::Interface & m_field
Simple * simple_interface
std::vector< boost::shared_ptr< MatrixDouble > > grads_ptr
std::vector< boost::shared_ptr< PreviousData > > data
std::map< int, BlockData > material_blocks
MoFEMErrorCode set_initial_values(std::string field_name, int block_id, Range &surface, double &init_val)
MoFEMErrorCode solve()
MoFEMErrorCode run_analysis()
boost::shared_ptr< Monitor > monitor_ptr
MoFEMErrorCode update_vol_fe(boost::shared_ptr< VolEle > &vol_ele, boost::shared_ptr< PreviousData > &data)
MoFEMErrorCode push_mass_ele(std::string field_name)
MoFEMErrorCode set_fe_in_loop()
SmartPetscObj< DM > dm
std::vector< Range > inner_surface
Range natural_bdry_ents
boost::shared_ptr< VolEle > vol_ele_stiff_lhs
MoFEMErrorCode update_stiff_rhs(std::string field_name, boost::shared_ptr< VectorDouble > &values_ptr, boost::shared_ptr< MatrixDouble > &grads_ptr, boost::shared_ptr< VectorDouble > &dots_ptr)
MoFEMErrorCode output_result()
MoFEMErrorCode set_integration_rule()
MoFEMErrorCode post_proc_fields(std::string field_name)
MoFEMErrorCode push_stiff_rhs(std::string field_name, boost::shared_ptr< PreviousData > &data, std::map< int, BlockData > &block_map)
MoFEMErrorCode setup_system()
MoFEMErrorCode set_blockData(std::map< int, BlockData > &block_data_map)
moab::Interface & moab
boost::shared_ptr< ForcesAndSourcesCore > null
std::vector< boost::shared_ptr< VectorDouble > > values_ptr
MoFEMErrorCode add_fe(std::string field_name)
boost::shared_ptr< PostProc > post_proc
std::vector< boost::shared_ptr< VectorDouble > > dots_ptr
UFProblem(moab::Core &mb_instance, MoFEM::Core &core, const int order, const int n_species)
boost::shared_ptr< FaceEle > boundary_ele_rhs
VolumeElementForcesAndSourcesCore VolEle