v0.14.0
Loading...
Searching...
No Matches
unsaturate_flow.cpp
Go to the documentation of this file.
1#include <stdlib.h>
4
5using namespace MoFEM;
6using namespace UFOperators;
7
8static char help[] = "...\n\n";
9
10struct UFProblem {
11public:
12 UFProblem(moab::Core &mb_instance, MoFEM::Core &core, const int order,
13 const int n_species)
14 : moab(mb_instance), m_field(core), order(order), nb_species(n_species),
15 cOmm(m_field.get_comm()), rAnk(m_field.get_comm_rank()) {
16 vol_ele_stiff_rhs = boost::shared_ptr<VolEle>(new VolEle(m_field));
17 vol_ele_stiff_lhs = boost::shared_ptr<VolEle>(new VolEle(m_field));
18
19 boundary_ele_rhs = boost::shared_ptr<FaceEle>(new FaceEle(m_field));
20
21 post_proc = boost::shared_ptr<PostProcVolumeOnRefinedMesh>(
23
24 data.resize(nb_species);
25 values_ptr.resize(nb_species);
26 grads_ptr.resize(nb_species);
27 dots_ptr.resize(nb_species);
29
30 for (int i = 0; i < nb_species; ++i) {
31 data[i] = boost::shared_ptr<PreviousData>(new PreviousData());
32 grads_ptr[i] = boost::shared_ptr<MatrixDouble>(data[i], &data[i]->grads);
33 values_ptr[i] =
34 boost::shared_ptr<VectorDouble>(data[i], &data[i]->values);
35 dots_ptr[i] =
36 boost::shared_ptr<VectorDouble>(data[i], &data[i]->dot_values);
37 }
38 }
39
40 // UFProblem(const int order) : order(order){}
42
43private:
46 MoFEMErrorCode set_blockData(std::map<int, BlockData> &block_data_map);
47
48 MoFEMErrorCode set_initial_values(std::string field_name, int block_id,
49 Range &surface, double &init_val);
50
52
53 MoFEMErrorCode update_vol_fe(boost::shared_ptr<VolEle> &vol_ele,
54 boost::shared_ptr<PreviousData> &data);
56 boost::shared_ptr<VectorDouble> &values_ptr,
57 boost::shared_ptr<MatrixDouble> &grads_ptr,
58 boost::shared_ptr<VectorDouble> &dots_ptr);
59
61 boost::shared_ptr<PreviousData> &data,
62 std::map<int, BlockData> &block_map);
63
65 boost::shared_ptr<VectorDouble> &values_ptr,
66 boost::shared_ptr<MatrixDouble> &grads_ptr);
68 boost::shared_ptr<PreviousData> &data,
69 std::map<int, BlockData> &block_map);
70
72
77
80
81 moab::Interface &moab;
82
85
87
88 std::vector<Range> inner_surface;
89
90 double global_error;
91
92 MPI_Comm cOmm;
93 const int rAnk;
94
95 int order;
96 int nb_species;
97
98 std::map<int, BlockData> material_blocks;
99
100 boost::shared_ptr<VolEle> vol_ele_stiff_rhs;
101 boost::shared_ptr<VolEle> vol_ele_stiff_lhs;
102 boost::shared_ptr<FaceEle> boundary_ele_rhs;
103
104 boost::shared_ptr<VolEle> vol_mass_ele;
105
106 boost::shared_ptr<PostProcVolumeOnRefinedMesh> post_proc;
107 boost::shared_ptr<Monitor> monitor_ptr;
108
109 std::vector<boost::shared_ptr<PreviousData>> data;
110
111 std::vector<boost::shared_ptr<MatrixDouble>> grads_ptr;
112 std::vector<boost::shared_ptr<VectorDouble>> values_ptr;
113 std::vector<boost::shared_ptr<VectorDouble>> dots_ptr;
114
115 boost::shared_ptr<ForcesAndSourcesCore> null;
116};
117
124}
129
133
135}
136
137MoFEMErrorCode UFProblem::set_blockData(std::map<int, BlockData> &block_map) {
140 string name = it->getName();
141 const int id = it->getMeshsetId();
142 if (name.compare(0, 14, "REGION1") == 0) {
143 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
144 id, BLOCKSET, 3, block_map[id].block_ents, true);
145
146 block_map[id].block_id = id;
147 block_map[id].K_s = 1.000;
148 block_map[id].h_s = 0.000;
149 block_map[id].theta_s = 0.43000;
150 block_map[id].theta_m = 0.43000;
151 block_map[id].theta_r = 0.04500;
152 block_map[id].alpha = 1.812500;
153 block_map[id].nn = 5.3800;
154
155 } else if (name.compare(0, 14, "REGION2") == 0) {
156 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
157 id, BLOCKSET, 3, block_map[id].block_ents, true);
158
159 block_map[id].block_id = id;
160 } else if (name.compare(0, 14, "REGION3") == 0) {
161 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
162 id, BLOCKSET, 3, block_map[id].block_ents, true);
163
164 block_map[id].block_id = id;
165 } else if (name.compare(0, 14, "REGION4") == 0) {
166 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
167 id, BLOCKSET, 3, block_map[id].block_ents, true);
168
169 block_map[id].block_id = id;
170 } else if (name.compare(0, 14, "REGION5") == 0) {
171 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
172 id, BLOCKSET, 3, block_map[id].block_ents, true);
173
174 block_map[id].block_id = id;
175 }
176 }
178}
179
181 int block_id, Range &surface,
182 double &init_val) {
185 BLOCKSET)) {
186 CHKERR m_field.getInterface<MeshsetsManager>()->getEntitiesByDimension(
187 block_id, BLOCKSET, 3, surface, true);
188 }
189 if (!surface.empty()) {
190 Range surface_verts;
191
192 CHKERR moab.get_connectivity(surface, surface_verts, false);
194 init_val, MBVERTEX, surface_verts, field_name);
195 }
196
198}
199
200MoFEMErrorCode UFProblem::update_vol_fe(boost::shared_ptr<VolEle> &vol_ele,
201 boost::shared_ptr<PreviousData> &data) {
203 auto det_ptr = boost::make_shared<VectorDouble>();
204 auto jac_ptr = boost::make_shared<MatrixDouble>();
205 auto inv_jac_ptr = boost::make_shared<MatrixDouble>();
206 vol_ele->getOpPtrVector().push_back(new OpCalculateHOJacForFace(jac_ptr));
207 vol_ele->getOpPtrVector().push_back(
208 new OpInvertMatrix<2>(jac_ptr, det_ptr, inv_jac_ptr));
209 vol_ele->getOpPtrVector().push_back(new OpSetInvJacH1ForFace(inv_jac_ptr));
211}
212
215 boost::shared_ptr<VectorDouble> &values_ptr,
216 boost::shared_ptr<MatrixDouble> &grads_ptr,
217 boost::shared_ptr<VectorDouble> &dots_ptr) {
218
220 vol_ele_stiff_rhs->getOpPtrVector().push_back(
222 vol_ele_stiff_rhs->getOpPtrVector().push_back(
224 vol_ele_stiff_rhs->getOpPtrVector().push_back(
227}
229 boost::shared_ptr<PreviousData> &data,
230 std::map<int, BlockData> &block_map) {
232
233 vol_ele_stiff_rhs->getOpPtrVector().push_back(
234 new OpAssembleStiffRhs<3>(field_name, data, block_map));
235 // boundary_ele_rhs->getOpPtrVector().push_back(
236 // new OpAssembleNaturalBCRhs(field_name,natural_bdry_ents));
238}
239
242 boost::shared_ptr<VectorDouble> &values_ptr,
243 boost::shared_ptr<MatrixDouble> &grads_ptr) {
245 vol_ele_stiff_lhs->getOpPtrVector().push_back(
247
248 vol_ele_stiff_lhs->getOpPtrVector().push_back(
251}
252
254 boost::shared_ptr<PreviousData> &data,
255 std::map<int, BlockData> &block_map) {
257
258 vol_ele_stiff_lhs->getOpPtrVector().push_back(
259 new OpAssembleStiffLhs<3>(field_name, data, block_map));
260
262}
263
266 auto vol_rule = [](int, int, int p) -> int { return 2 * p; };
267
268 vol_ele_stiff_rhs->getRuleHook = vol_rule;
269
270 vol_ele_stiff_lhs->getRuleHook = vol_rule;
271 boundary_ele_rhs->getRuleHook = vol_rule;
273}
274
277 CHKERR TSSetType(ts, TSARKIMEX);
278 CHKERR TSARKIMEXSetType(ts, TSARKIMEXA2);
279
282
285
288
290}
291
294 post_proc->addFieldValuesPostProc(field_name);
296}
297
303}
304
307 // Create solution vector
310 CHKERR DMoFEMMeshToLocalVector(dm, X, INSERT_VALUES, SCATTER_FORWARD);
311 // Solve problem
312 double ftime = 1;
313 CHKERR TSSetDM(ts, dm);
314 CHKERR TSSetDuration(ts, PETSC_DEFAULT, ftime);
315 CHKERR TSSetSolution(ts, X);
316 CHKERR TSSetFromOptions(ts);
317 CHKERR TSSolve(ts, X);
319}
320
323 global_error = 0;
324 std::vector<std::string> mass_names(nb_species);
325
326 for (int i = 0; i < nb_species; ++i) {
327 mass_names[i] = "h" + boost::lexical_cast<std::string>(i + 1);
328 }
330 for (int i = 0; i < nb_species; ++i) {
331 add_fe(mass_names[i]);
332 }
333
335
337 string name = it->getName();
338 if (name.compare(0, 14, "ESSENTIAL") == 0) {
339 CHKERR it->getMeshsetIdEntitiesByDimension(m_field.get_moab(), 2,
340 natural_bdry_ents, true);
341 }
342 }
343 Range face_edges;
344
345 CHKERR moab.get_adjacencies(natural_bdry_ents, 2, false, face_edges,
346 moab::Interface::UNION);
347
348 Range face_edges_verts;
349 CHKERR moab.get_connectivity(face_edges, face_edges_verts, false);
350
351 Range bdry_ents;
352 bdry_ents = unite(natural_bdry_ents, face_edges_verts);
353 bdry_ents = unite(bdry_ents, face_edges_verts);
354
355 bdry_ents.print();
356 cout << "size: " << endl;
357 cout << bdry_ents.size() << endl;
358 cout << bdry_ents << endl;
359
360 CHKERR m_field.getInterface<ProblemsManager>()->removeDofsOnEntities(
361 "SimpleProblem", mass_names[0], bdry_ents);
362
364
365 VectorDouble initVals;
366 initVals.resize(3, false);
367 initVals.clear();
368
369 initVals[0] = -0.8;
370 initVals[1] = 0.0;
371 initVals[2] = 0.0;
372
373 for (int i = 0; i < nb_species; ++i) {
374 CHKERR set_initial_values(mass_names[i], i + 2, inner_surface[i],
375 initVals[i]);
376 }
377
378 if (!natural_bdry_ents.empty()) {
379 Range surface_verts;
380
381 CHKERR moab.get_connectivity(natural_bdry_ents, surface_verts, false);
383 0.0, MBVERTEX, surface_verts, mass_names[0]);
384 }
385
387
388 // CHKERR update_vol_fe(vol_ele_stiff_rhs, data[0]);
389
390 for (int i = 0; i < nb_species; ++i) {
392 dots_ptr[i]);
394 }
395
396 // CHKERR update_vol_fe(vol_ele_stiff_lhs, data[0]);
397
398 for (int i = 0; i < nb_species; ++i) {
400 CHKERR push_stiff_lhs(mass_names[i], data[i],
401 material_blocks); // nb_species times
402 }
403 // vol_ele_stiff_lhs->getOpPtrVector().push_back(
404 // new OpError(ExactFunction(), ExactFunctionLap(), ExactFunctionGrad(),
405 // data[0], material_blocks, global_error));
406
408
410
412
413 post_proc->generateReferenceElementMesh(); // only once
414
415 for (int i = 0; i < nb_species; ++i) {
416 CHKERR post_proc_fields(mass_names[i]);
417 }
418
419 monitor_ptr = boost::shared_ptr<Monitor>(
420 new Monitor(cOmm, rAnk, dm, post_proc, global_error)); // nb_species times
421 CHKERR output_result(); // only once
422
423 CHKERR solve(); // only once
424
426}
427
428int main(int argc, char *argv[]) {
429 const char param_file[] = "param_file.petsc";
431 try {
432 moab::Core mb_instance;
433 moab::Interface &moab = mb_instance;
434 MoFEM::Core core(moab);
435 DMType dm_name = "DMMOFEM";
436 CHKERR DMRegister_MoFEM(dm_name);
437
438 int order = 1;
439 CHKERR PetscOptionsGetInt(PETSC_NULL, "", "-order", &order, PETSC_NULL);
440 int nb_species = 1;
441 UFProblem unsatu_flow_problem(mb_instance, core, order, nb_species);
442 CHKERR unsatu_flow_problem.run_analysis();
443 }
446 return 0;
447}
static Index< 'p', 3 > p
std::string param_file
int main()
Definition: adol-c_atom.cpp:46
MoFEM::FaceElementForcesAndSourcesCore FaceEle
#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
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)
constexpr auto field_name
virtual moab::Interface & get_moab()=0
virtual MPI_Comm & get_comm() const =0
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
const std::string getBoundaryFEName() const
Get the Boundary FE Name.
Definition: Simple.hpp:348
MoFEMErrorCode loadFile(const std::string options, const std::string mesh_file_name, LoadFileFunc loadFunc=defaultLoadFileFunc)
Load mesh file.
Definition: Simple.cpp:194
MoFEMErrorCode addDomainField(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_ZERO, int verb=-1)
Add field on domain.
Definition: Simple.cpp:264
MoFEMErrorCode getOptions()
get options
Definition: Simple.cpp:180
MoFEMErrorCode getDM(DM *dm)
Get DM.
Definition: Simple.cpp:667
MoFEMErrorCode setFieldOrder(const std::string field_name, const int order, const Range *ents=NULL)
Set field order.
Definition: Simple.cpp:473
MoFEMErrorCode addBoundaryField(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_ZERO, int verb=-1)
Add field on boundary.
Definition: Simple.cpp:282
MoFEMErrorCode setUp(const PetscBool is_partitioned=PETSC_TRUE)
Setup problem.
Definition: Simple.cpp:611
const std::string getDomainFEName() const
Get the Domain FE Name.
Definition: Simple.hpp:341
intrusive_ptr for managing petsc objects
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Post processing.
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)
boost::shared_ptr< PostProcVolumeOnRefinedMesh > post_proc
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
static char help[]