v0.15.0
Loading...
Searching...
No Matches
unsaturated_transport.cpp File Reference

Implementation of unsaturated flow problem. More...

#include <MoFEM.hpp>
#include <MethodForForceScaling.hpp>
#include <TimeForceScale.hpp>
#include <boost/program_options.hpp>
#include <MixTransportElement.hpp>
#include <UnsaturatedFlow.hpp>
#include <MaterialUnsaturatedFlow.hpp>

Go to the source code of this file.

Functions

int main (int argc, char *argv[])
 

Variables

static char help [] = "...\n\n"
 

Detailed Description

Implementation of unsaturated flow problem.

Definition in file unsaturated_transport.cpp.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 37 of file unsaturated_transport.cpp.

37 {
38
39 const string default_options = "-ksp_type fgmres\n"
40 "-pc_type lu \n"
41 "-pc_factor_mat_solver_type mumps \n"
42 "-mat_mumps_icntl_20 0 \n";
43
44 string param_file = "param_file.petsc";
45 if (!static_cast<bool>(ifstream(param_file))) {
46 std::ofstream file(param_file.c_str(), std::ios::ate);
47 if (file.is_open()) {
48 file << default_options;
49 file.close();
50 }
51 }
52
53 MoFEM::Core::Initialize(&argc, &argv, param_file.c_str(), help);
54
55 // Register DM Manager
56 CHKERR DMRegister_MoFEM("DMMOFEM"); // register MoFEM DM in PETSc
57 // Register materials
59
60 PetscBool test_mat = PETSC_FALSE;
61 CHKERR PetscOptionsGetBool(PETSC_NULLPTR, "", "-test_mat", &test_mat,
62 PETSC_NULLPTR);
63
64 if (test_mat == PETSC_TRUE) {
66 // Testing van_genuchten
67 MaterialVanGenuchten van_genuchten(data);
68 van_genuchten.printMatParameters(-1, "testing");
69 van_genuchten.printTheta(-1e-16, -1e4, -1e-12, "hTheta");
70 van_genuchten.printKappa(-1e-16, -1, -1e-12, "hK");
71 van_genuchten.printC(-1e-16, -1, -1e-12, "hC");
72 CHKERR PetscFinalize();
73 return 0;
74 }
75
76 try {
77
78 moab::Core mb_instance;
79 moab::Interface &moab = mb_instance;
80
81 // get file name form command line
82 PetscBool flg_mesh_file_name = PETSC_TRUE;
83 char mesh_file_name[255];
84 PetscBool flg_conf_file_name = PETSC_TRUE;
85 char conf_file_name[255];
86
87 int order = 1;
88
89 PetscOptionsBegin(PETSC_COMM_WORLD, "", "Unsaturated flow options",
90 "none");
91 ierr = PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
92 mesh_file_name, 255, &flg_mesh_file_name);
94 ierr = PetscOptionsString(
95 "-configure", "material and bc configuration file name", "",
96 "unsaturated.cfg", conf_file_name, 255, &flg_conf_file_name);
98 ierr = PetscOptionsInt("-my_order", "default approximation order", "",
99 order, &order, PETSC_NULLPTR);
100 PetscOptionsEnd();
101
102 if (flg_mesh_file_name != PETSC_TRUE) {
103 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
104 "File name not set (e.g. -my_name mesh.h5m)");
105 }
106 if (flg_conf_file_name != PETSC_TRUE) {
107 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
108 "File name not set (e.g. -config unsaturated.cfg)");
109 }
110
111 // Create MOAB communicator
112 auto pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
113 auto moab_comm_wrap =
114 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
115 if (pcomm == NULL)
116 pcomm =
117 new ParallelComm(&moab, moab_comm_wrap->get_comm());
118
119 const char *option;
120 option = "PARALLEL=READ_PART;"
121 "PARALLEL_RESOLVE_SHARED_ENTS;"
122 "PARTITION=PARALLEL_PARTITION;";
123 CHKERR moab.load_file(mesh_file_name, 0, option);
124
125 // Create mofem interface
126 MoFEM::Core core(moab);
127 MoFEM::Interface &m_field = core;
128
129 // Add meshsets with material and boundary conditions
130 MeshsetsManager *meshsets_manager_ptr;
131 CHKERR m_field.getInterface(meshsets_manager_ptr);
132 CHKERR meshsets_manager_ptr->setMeshsetFromFile();
133
134 PetscPrintf(PETSC_COMM_WORLD,
135 "Read meshsets and added meshsets from bc.cfg\n");
136 for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, it)) {
137 PetscPrintf(PETSC_COMM_WORLD, "%s",
138 static_cast<std::ostringstream &>(
139 std::ostringstream().seekp(0) << *it << endl)
140 .str()
141 .c_str());
142 }
143
144 // Set entities bit level
145 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
146 0, 3, BitRefLevel().set(0));
147
148 UnsaturatedFlowElement uf(m_field);
149
150 ifstream ini_file(conf_file_name);
151 po::variables_map vm;
152 po::options_description config_file_options;
153 Range domain_ents, bc_boundary_ents;
154
155 map<int, CommonMaterialData> material_blocks;
156 map<int, double> head_blocks;
157 map<int, double> flux_blocks;
158 // Set material blocks
160 if (it->getName().compare(0, 4, "SOIL") != 0)
161 continue;
162 // get block id
163 const int block_id = it->getMeshsetId();
164 std::string block_name =
165 "mat_block_" + boost::lexical_cast<std::string>(block_id);
166 material_blocks[block_id].blockId = block_id;
167 material_blocks[block_id].addOptions(config_file_options, block_name);
168 }
170 if (it->getName().compare(0, 4, "HEAD") != 0)
171 continue;
172 // get block id
173 const int block_id = it->getMeshsetId();
174 std::string block_name =
175 "head_block_" + boost::lexical_cast<std::string>(block_id);
176 config_file_options.add_options()(
177 (block_name + ".head").c_str(),
178 po::value<double>(&head_blocks[block_id])->default_value(0));
179 }
181 if (it->getName().compare(0, 4, "FLUX") != 0)
182 continue;
183 // get block id
184 const int block_id = it->getMeshsetId();
185 std::string block_name =
186 "flux_block_" + boost::lexical_cast<std::string>(block_id);
187 config_file_options.add_options()(
188 (block_name + ".flux").c_str(),
189 po::value<double>(&head_blocks[block_id])->default_value(0));
190 }
191 po::parsed_options parsed =
192 parse_config_file(ini_file, config_file_options, true);
193 store(parsed, vm);
194 po::notify(vm);
196 if (it->getName().compare(0, 4, "SOIL") != 0)
197 continue;
198 const int block_id = it->getMeshsetId();
199 uf.dMatMap[block_id] = RegisterMaterials::mapOfRegistredMaterials.at(
200 material_blocks[block_id].matName)(material_blocks.at(block_id));
201 if (!uf.dMatMap.at(block_id)) {
202 SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
203 "Material block not set");
204 }
205 // get block test
206 CHKERR m_field.get_moab().get_entities_by_type(
207 it->meshset, MBTET, uf.dMatMap.at(block_id)->tEts, true);
208 domain_ents.merge(uf.dMatMap.at(block_id)->tEts);
209 uf.dMatMap.at(block_id)->printMatParameters(block_id, "Read material");
210 }
211 std::vector<std::string> additional_parameters;
212 additional_parameters =
213 collect_unrecognized(parsed.options, po::include_positional);
214 for (std::vector<std::string>::iterator vit = additional_parameters.begin();
215 vit != additional_parameters.end(); vit++) {
216 CHKERR PetscPrintf(m_field.get_comm(),
217 "** WARNING Unrecognized option %s\n", vit->c_str());
218 }
219 // Set capillary pressure bc data
221 if (it->getName().compare(0, 4, "HEAD") != 0)
222 continue;
223 // get block id
224 const int block_id = it->getMeshsetId();
225 // create block data instance
226 uf.bcValueMap[block_id] =
227 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
229 // get bc value
230 std::vector<double> attributes;
231 CHKERR it->getAttributes(attributes);
232 if (attributes.size() != 1)
233 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
234 "Wrong number of head parameters %d", attributes.size());
235 uf.bcValueMap[block_id]->fixValue = attributes[0];
236 std::string block_name =
237 "head_block_" + boost::lexical_cast<std::string>(block_id);
238 if (vm.count((block_name) + ".head")) {
239 uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
240 }
241 // cerr << uf.bcValueMap[block_id]->fixValue << endl;
242 // CHKERR it->printAttributes(std::cout);
243 // get faces in the block
244 CHKERR m_field.get_moab().get_entities_by_type(
245 it->meshset, MBTRI, uf.bcValueMap[block_id]->eNts, true);
246 bc_boundary_ents.merge(uf.bcValueMap[block_id]->eNts);
247 }
248
249 int max_flux_id = 0;
250 // Set water flux bc data
252 if (it->getName().compare(0, 4, "FLUX") != 0)
253 continue;
254 // get block id
255 const int block_id = it->getMeshsetId();
256 // create block data instance
257 uf.bcFluxMap[block_id] =
258 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
260 // get bc value
261 std::vector<double> attributes;
262 CHKERR it->getAttributes(attributes);
263 // CHKERR it->printAttributes(std::cout);
264 uf.bcFluxMap[block_id]->fixValue = attributes[0];
265 std::string block_name =
266 "flux_block_" + boost::lexical_cast<std::string>(block_id);
267 if (vm.count((block_name) + ".flux")) {
268 uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
269 }
270 // get faces in the block
271 CHKERR m_field.get_moab().get_entities_by_type(
272 it->meshset, MBTRI, uf.bcFluxMap[block_id]->eNts, true);
273 bc_boundary_ents.merge(uf.bcFluxMap[block_id]->eNts);
274 max_flux_id = max_flux_id > block_id ? max_flux_id : block_id + 1;
275 }
276
277 // Add zero flux on the rest of the boundary
278 auto get_zero_flux_entities = [&m_field,
279 &pcomm](const auto &domain_ents,
280 const auto &bc_boundary_ents) {
281 Range zero_flux_ents;
282 Skinner skin(&m_field.get_moab());
283 Range domain_skin;
284 CHKERR skin.find_skin(0, domain_ents, false, domain_skin);
285 // filter not owned entities, those are not on boundary
286 CHKERR pcomm->filter_pstatus(domain_skin,
287 PSTATUS_SHARED | PSTATUS_MULTISHARED,
288 PSTATUS_NOT, -1, &zero_flux_ents);
289 zero_flux_ents = subtract(zero_flux_ents, bc_boundary_ents);
290 return zero_flux_ents;
291 };
292
293 CHKERR uf.addFields("VALUES", "FLUXES", order);
294 CHKERR uf.addFiniteElements("FLUXES", "VALUES");
295 CHKERR uf.buildProblem(
296 get_zero_flux_entities(domain_ents, bc_boundary_ents));
297 CHKERR uf.createMatrices();
298 CHKERR uf.setFiniteElements();
299 CHKERR uf.calculateEssentialBc();
300 CHKERR uf.calculateInitialPc();
301 CHKERR uf.solveProblem();
302 CHKERR uf.destroyMatrices();
303
304 }
306
308
309 return 0;
310}
#define CATCH_ERRORS
Catch errors.
#define MYPCOMM_INDEX
default communicator number PCOMM
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
@ BLOCKSET
@ MOFEM_DATA_INCONSISTENCY
Definition definitions.h:31
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define CHKERR
Inline error check.
constexpr int order
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition DMMoFEM.cpp:43
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
#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.
char mesh_file_name[255]
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
static map< std::string, CommonMaterialData::RegisterHook > mapOfRegistredMaterials
Class storing information about boundary condition.
Implementation of operators, problem and finite elements for unsaturated flow.
Managing BitRefLevels.
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:118
Deprecated interface functions.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
static char help[]

Variable Documentation

◆ help

char help[] = "...\n\n"
static

Definition at line 28 of file unsaturated_transport.cpp.