39 const string default_options =
"-ksp_type fgmres\n"
41 "-pc_factor_mat_solver_type mumps \n"
42 "-mat_mumps_icntl_20 0 \n";
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);
48 file << default_options;
60 PetscBool test_mat = PETSC_FALSE;
64 if (test_mat == PETSC_TRUE) {
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");
82 PetscBool flg_mesh_file_name = PETSC_TRUE;
84 PetscBool flg_conf_file_name = PETSC_TRUE;
85 char conf_file_name[255];
89 ierr = PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Unsaturated flow options",
92 ierr = PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
95 ierr = PetscOptionsString(
96 "-configure",
"material and bc configuration file name",
"",
97 "unsaturated.cfg", conf_file_name, 255, &flg_conf_file_name);
99 ierr = PetscOptionsInt(
"-my_order",
"default approximation order",
"",
102 ierr = PetscOptionsEnd();
105 if (flg_mesh_file_name != PETSC_TRUE) {
107 "File name not set (e.g. -my_name mesh.h5m)");
109 if (flg_conf_file_name != PETSC_TRUE) {
111 "File name not set (e.g. -config unsaturated.cfg)");
116 auto moab_comm_wrap =
117 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD,
false);
120 new ParallelComm(&moab, moab_comm_wrap->get_comm());
123 option =
"PARALLEL=READ_PART;"
124 "PARALLEL_RESOLVE_SHARED_ENTS;"
125 "PARTITION=PARALLEL_PARTITION;";
137 PetscPrintf(PETSC_COMM_WORLD,
138 "Read meshsets and added meshsets from bc.cfg\n");
140 PetscPrintf(PETSC_COMM_WORLD,
"%s",
141 static_cast<std::ostringstream &
>(
142 std::ostringstream().seekp(0) << *it << endl)
153 ifstream ini_file(conf_file_name);
154 po::variables_map vm;
155 po::options_description config_file_options;
156 Range domain_ents, bc_boundary_ents;
158 map<int, CommonMaterialData> material_blocks;
159 map<int, double> head_blocks;
160 map<int, double> flux_blocks;
163 if (it->getName().compare(0, 4,
"SOIL") != 0)
166 const int block_id = it->getMeshsetId();
167 std::string block_name =
168 "mat_block_" + boost::lexical_cast<std::string>(block_id);
169 material_blocks[block_id].blockId = block_id;
170 material_blocks[block_id].addOptions(config_file_options, block_name);
173 if (it->getName().compare(0, 4,
"HEAD") != 0)
176 const int block_id = it->getMeshsetId();
177 std::string block_name =
178 "head_block_" + boost::lexical_cast<std::string>(block_id);
179 config_file_options.add_options()(
180 (block_name +
".head").c_str(),
181 po::value<double>(&head_blocks[block_id])->default_value(0));
184 if (it->getName().compare(0, 4,
"FLUX") != 0)
187 const int block_id = it->getMeshsetId();
188 std::string block_name =
189 "flux_block_" + boost::lexical_cast<std::string>(block_id);
190 config_file_options.add_options()(
191 (block_name +
".flux").c_str(),
192 po::value<double>(&head_blocks[block_id])->default_value(0));
194 po::parsed_options parsed =
195 parse_config_file(ini_file, config_file_options,
true);
199 if (it->getName().compare(0, 4,
"SOIL") != 0)
201 const int block_id = it->getMeshsetId();
202 uf.dMatMap[block_id] = RegisterMaterials::mapOfRegistredMaterials.at(
203 material_blocks[block_id].matName)(material_blocks.at(block_id));
204 if (!uf.dMatMap.at(block_id)) {
206 "Material block not set");
210 it->meshset, MBTET, uf.dMatMap.at(block_id)->tEts,
true);
211 domain_ents.merge(uf.dMatMap.at(block_id)->tEts);
212 uf.dMatMap.at(block_id)->printMatParameters(block_id,
"Read material");
214 std::vector<std::string> additional_parameters;
215 additional_parameters =
216 collect_unrecognized(parsed.options, po::include_positional);
217 for (std::vector<std::string>::iterator vit = additional_parameters.begin();
218 vit != additional_parameters.end(); vit++) {
220 "** WARNING Unrecognized option %s\n", vit->c_str());
224 if (it->getName().compare(0, 4,
"HEAD") != 0)
227 const int block_id = it->getMeshsetId();
229 uf.bcValueMap[block_id] =
230 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
233 std::vector<double> attributes;
234 CHKERR it->getAttributes(attributes);
235 if (attributes.size() != 1)
237 "Wrong number of head parameters %d", attributes.size());
238 uf.bcValueMap[block_id]->fixValue = attributes[0];
239 std::string block_name =
240 "head_block_" + boost::lexical_cast<std::string>(block_id);
241 if (vm.count((block_name) +
".head")) {
242 uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
248 it->meshset, MBTRI, uf.bcValueMap[block_id]->eNts,
true);
249 bc_boundary_ents.merge(uf.bcValueMap[block_id]->eNts);
255 if (it->getName().compare(0, 4,
"FLUX") != 0)
258 const int block_id = it->getMeshsetId();
260 uf.bcFluxMap[block_id] =
261 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
264 std::vector<double> attributes;
265 CHKERR it->getAttributes(attributes);
267 uf.bcFluxMap[block_id]->fixValue = attributes[0];
268 std::string block_name =
269 "flux_block_" + boost::lexical_cast<std::string>(block_id);
270 if (vm.count((block_name) +
".flux")) {
271 uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
275 it->meshset, MBTRI, uf.bcFluxMap[block_id]->eNts,
true);
276 bc_boundary_ents.merge(uf.bcFluxMap[block_id]->eNts);
277 max_flux_id = max_flux_id > block_id ? max_flux_id : block_id + 1;
281 auto get_zero_flux_entities = [&m_field,
282 &pcomm](
const auto &domain_ents,
283 const auto &bc_boundary_ents) {
284 Range zero_flux_ents;
287 CHKERR skin.find_skin(0, domain_ents,
false, domain_skin);
289 CHKERR pcomm->filter_pstatus(domain_skin,
290 PSTATUS_SHARED | PSTATUS_MULTISHARED,
291 PSTATUS_NOT, -1, &zero_flux_ents);
292 zero_flux_ents = subtract(zero_flux_ents, bc_boundary_ents);
293 return zero_flux_ents;
297 CHKERR uf.addFiniteElements(
"FLUXES",
"VALUES");
299 get_zero_flux_entities(domain_ents, bc_boundary_ents));
300 CHKERR uf.createMatrices();
301 CHKERR uf.setFiniteElements();
302 CHKERR uf.calculateEssentialBc();
303 CHKERR uf.calculateInitialPc();
305 CHKERR uf.destroyMatrices();