37int main(
int argc,
char *argv[]) {
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) {
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");
78 moab::Core mb_instance;
79 moab::Interface &moab = mb_instance;
82 PetscBool flg_mesh_file_name = PETSC_TRUE;
84 PetscBool flg_conf_file_name = PETSC_TRUE;
85 char conf_file_name[255];
89 PetscOptionsBegin(PETSC_COMM_WORLD,
"",
"Unsaturated flow options",
91 ierr = PetscOptionsString(
"-my_file",
"mesh file name",
"",
"mesh.h5m",
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",
"",
102 if (flg_mesh_file_name != PETSC_TRUE) {
104 "File name not set (e.g. -my_name mesh.h5m)");
106 if (flg_conf_file_name != PETSC_TRUE) {
108 "File name not set (e.g. -config unsaturated.cfg)");
113 auto moab_comm_wrap =
114 boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD,
false);
117 new ParallelComm(&moab, moab_comm_wrap->get_comm());
120 option =
"PARALLEL=READ_PART;"
121 "PARALLEL_RESOLVE_SHARED_ENTS;"
122 "PARTITION=PARALLEL_PARTITION;";
134 PetscPrintf(PETSC_COMM_WORLD,
135 "Read meshsets and added meshsets from bc.cfg\n");
137 PetscPrintf(PETSC_COMM_WORLD,
"%s",
138 static_cast<std::ostringstream &
>(
139 std::ostringstream().seekp(0) << *it << endl)
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;
155 map<int, CommonMaterialData> material_blocks;
156 map<int, double> head_blocks;
157 map<int, double> flux_blocks;
160 if (it->getName().compare(0, 4,
"SOIL") != 0)
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);
170 if (it->getName().compare(0, 4,
"HEAD") != 0)
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));
181 if (it->getName().compare(0, 4,
"FLUX") != 0)
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));
191 po::parsed_options parsed =
192 parse_config_file(ini_file, config_file_options,
true);
196 if (it->getName().compare(0, 4,
"SOIL") != 0)
198 const int block_id = it->getMeshsetId();
200 material_blocks[block_id].matName)(material_blocks.at(block_id));
201 if (!uf.
dMatMap.at(block_id)) {
203 "Material block not set");
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");
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++) {
217 "** WARNING Unrecognized option %s\n", vit->c_str());
221 if (it->getName().compare(0, 4,
"HEAD") != 0)
224 const int block_id = it->getMeshsetId();
227 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
230 std::vector<double> attributes;
231 CHKERR it->getAttributes(attributes);
232 if (attributes.size() != 1)
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];
245 it->meshset, MBTRI, uf.
bcValueMap[block_id]->eNts,
true);
246 bc_boundary_ents.merge(uf.
bcValueMap[block_id]->eNts);
252 if (it->getName().compare(0, 4,
"FLUX") != 0)
255 const int block_id = it->getMeshsetId();
258 boost::shared_ptr<UnsaturatedFlowElement::BcData>(
261 std::vector<double> attributes;
262 CHKERR it->getAttributes(attributes);
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];
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;
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;
284 CHKERR skin.find_skin(0, domain_ents,
false, domain_skin);
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;
296 get_zero_flux_entities(domain_ents, bc_boundary_ents));