144int main(
int argc,
char *argv[]) {
146 const string default_options =
"-ksp_type fgmres \n"
148 "-pc_factor_mat_solver_type mumps \n"
149 "-mat_mumps_icntl_20 0 \n"
151 "-snes_type newtonls \n"
152 "-snes_linesearch_type basic \n"
153 "-snes_max_it 100 \n"
159 "-ts_exact_final_time stepover \n";
161 string param_file =
"param_file.petsc";
162 if (!
static_cast<bool>(ifstream(param_file))) {
163 std::ofstream file(param_file.c_str(), std::ios::ate);
164 if (file.is_open()) {
165 file << default_options;
172 auto core_log = logging::core::get();
180 PetscBool flg = PETSC_TRUE;
181 char mesh_file_name[255];
183 mesh_file_name, 255, &flg);
184 if(flg != PETSC_TRUE) {
186 "*** ERROR -my_file (MESH FILE NEEDED)");
189 char time_data_file_for_ground_surface[255];
190 PetscBool ground_temperature_analysis = PETSC_FALSE;
192 time_data_file_for_ground_surface,255,&ground_temperature_analysis);
193 if(ground_temperature_analysis) {
196 "*** ERROR to do ground thermal analysis MoFEM need to be compiled "
202 moab::Core mb_instance;
203 moab::Interface& moab = mb_instance;
206 CHKERR moab.load_file(mesh_file_name, 0, option);
211 DMType dm_name =
"DMTHERMAL";
215 CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
216 CHKERR DMSetType(dm, dm_name);
238 EntityHandle root_set = moab.get_root_set();
246 if (flg != PETSC_TRUE) {
265 "MESH_NODE_POSITIONS");
273 PetscBool block_config;
274 char block_config_file[255];
276 block_config_file, 255, &block_config);
277 std::map<int,BlockOptionData> block_data;
278 bool solar_radiation =
false;
281 ifstream ini_file(block_config_file);
283 po::variables_map vm;
284 po::options_description config_file_options;
287 std::ostringstream str_order;
288 str_order <<
"block_" << it->getMeshsetId() <<
".temperature_order";
289 config_file_options.add_options()(
290 str_order.str().c_str(),
291 po::value<int>(&block_data[it->getMeshsetId()].oRder)
292 ->default_value(
order));
294 std::ostringstream str_cond;
295 str_cond <<
"block_" << it->getMeshsetId() <<
".heat_conductivity";
296 config_file_options.add_options()(
297 str_cond.str().c_str(),
298 po::value<double>(&block_data[it->getMeshsetId()].cOnductivity)
299 ->default_value(-1));
301 std::ostringstream str_capa;
302 str_capa <<
"block_" << it->getMeshsetId() <<
".heat_capacity";
303 config_file_options.add_options()(
304 str_capa.str().c_str(),
305 po::value<double>(&block_data[it->getMeshsetId()].cApacity)
306 ->default_value(-1));
308 std::ostringstream str_init_temp;
309 str_init_temp <<
"block_" << it->getMeshsetId()
310 <<
".initial_temperature";
311 config_file_options.add_options()(
312 str_init_temp.str().c_str(),
313 po::value<double>(&block_data[it->getMeshsetId()].initTemp)
316 config_file_options.add_options()(
317 "climate_model.solar_radiation",
318 po::value<bool>(&solar_radiation)->default_value(
false));
320 po::parsed_options parsed =
321 parse_config_file(ini_file, config_file_options,
true);
326 if (block_data[it->getMeshsetId()].oRder == -1)
328 if (block_data[it->getMeshsetId()].oRder ==
order)
330 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d oRder to %d\n",
331 it->getMeshsetId(), block_data[it->getMeshsetId()].oRder);
333 CHKERR moab.get_entities_by_handle(it->meshset, block_ents,
true);
334 Range ents_to_set_order;
335 CHKERR moab.get_adjacencies(block_ents, 3,
false, ents_to_set_order,
336 moab::Interface::UNION);
337 ents_to_set_order = ents_to_set_order.subset_by_type(MBTET);
338 CHKERR moab.get_adjacencies(block_ents, 2,
false, ents_to_set_order,
339 moab::Interface::UNION);
340 CHKERR moab.get_adjacencies(block_ents, 1,
false, ents_to_set_order,
341 moab::Interface::UNION);
343 block_data[it->getMeshsetId()].oRder);
345 block_data[it->getMeshsetId()].oRder);
347 std::vector<std::string> additional_parameters;
348 additional_parameters =
349 collect_unrecognized(parsed.options, po::include_positional);
350 for (std::vector<std::string>::iterator vit =
351 additional_parameters.begin();
352 vit != additional_parameters.end(); vit++) {
353 CHKERR PetscPrintf(PETSC_COMM_WORLD,
354 "** WARRING Unrecognised option %s\n", vit->c_str());
357 }
catch (
const std::exception& ex) {
358 std::ostringstream ss;
359 ss << ex.what() << std::endl;
377 "MESH_NODE_POSITIONS");
380 "MESH_NODE_POSITIONS");
384 std::map<int, ThermalElement::BlockData>::iterator mit;
386 for (; mit != thermal_elements.
setOfBlocks.end(); mit++) {
390 if (block_data[mit->first].cOnductivity != -1) {
391 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d heat conductivity to %3.2e\n",
392 mit->first, block_data[mit->first].cOnductivity);
393 for (
int dd = 0; dd < 3; dd++) {
394 mit->second.cOnductivity_mat(dd, dd) =
395 block_data[mit->first].cOnductivity;
398 if (block_data[mit->first].cApacity != -1) {
399 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d heat capacity to %3.2e\n",
400 mit->first, block_data[mit->first].cApacity);
401 mit->second.cApacity = block_data[mit->first].cApacity;
405#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
406 GroundSurfaceTemperature ground_surface(m_field);
407 CrudeClimateModel time_data(time_data_file_for_ground_surface);
408 GroundSurfaceTemperature::PreProcess exectuteGenericClimateModel(&time_data);
409 if (ground_temperature_analysis) {
410 CHKERR ground_surface.addSurfaces(
"TEMP");
411 CHKERR ground_surface.setOperators(&time_data,
"TEMP");
421 "MESH_NODE_POSITIONS");
426 for (; mit != thermal_elements.
setOfBlocks.end(); mit++) {
427 if (mit->second.initTemp != 0) {
429 CHKERR moab.get_connectivity(mit->second.tEts, vertices,
true);
431 mit->second.initTemp, MBVERTEX, vertices,
"TEMP");
436 if (std::regex_match(it->getName(), std::regex(
"INT_THERMAL(.*)"))) {
437 std::vector<double> data;
438 CHKERR it->getAttributes(data);
439 if (data.size() != 1)
440 SETERRQ(PETSC_COMM_SELF, 1,
"Data inconsistency");
441 Range block_ents, block_verts;
442 CHKERR moab.get_entities_by_handle(it->getMeshset(), block_ents,
true);
443 CHKERR moab.get_connectivity(block_ents, block_verts,
true);
445 block_verts,
"TEMP");
450 if (block_data[it->getMeshsetId()].initTemp != 0) {
452 CHKERR moab.get_entities_by_handle(it->meshset, block_ents,
true);
454 CHKERR moab.get_connectivity(block_ents, vertices,
true);
456 block_data[it->getMeshsetId()].initTemp, MBVERTEX, vertices,
"TEMP");
460 MPI_Comm moab_comm_world;
461 MPI_Comm_dup(PETSC_COMM_WORLD, &moab_comm_world);
462 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
464 pcomm =
new ParallelComm(&moab, moab_comm_world);
466 PetscBool is_partitioned = PETSC_FALSE;
468 &is_partitioned, PETSC_NULLPTR);
470 Range thermal_element_ents;
472 thermal_element_ents);
474 PetscBool save_skin = PETSC_TRUE;
476 &save_skin, PETSC_NULLPTR);
480 CHKERR skin.find_skin(0, thermal_element_ents,
false, skin_faces);
482 if (is_partitioned) {
483 CHKERR pcomm->filter_pstatus(skin_faces,
484 PSTATUS_SHARED | PSTATUS_MULTISHARED,
485 PSTATUS_NOT, -1, &proc_skin);
487 proc_skin = skin_faces;
496 "MESH_NODE_POSITIONS");
517 std::vector<std::array<double, 3>> eval_points;
518 eval_points.resize(0);
519 PetscBool eval_points_flg = PETSC_FALSE;
520 char eval_points_file[255];
522 eval_points_file, 255, &eval_points_flg);
523 if (eval_points_flg) {
524 std::ifstream in_file(eval_points_file, std::ios::in);
525 if (!in_file.is_open()) {
530 while (in_file >> x >> y >> z) {
531 eval_points.push_back({x, y, z});
537 CHKERR DMSetFromOptions(dm);
546#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
547 if (ground_temperature_analysis) {
579#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
581 &exectuteGenericClimateModel, NULL);
583 if (solar_radiation) {
585 GroundSurfaceTemperature::SolarRadiationPreProcessor>::iterator it,
587 it = ground_surface.preProcessShade.begin();
588 hi_it = ground_surface.preProcessShade.end();
589 for (; it != hi_it; it++) {
605#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
606 if (ground_temperature_analysis) {
608 &ground_surface.getFeGroundSurfaceRhs(), NULL,
620#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
621 if (ground_temperature_analysis) {
623 &ground_surface.getFeGroundSurfaceLhs(), NULL,
640 CHKERR TSCreate(PETSC_COMM_WORLD,&ts);
641 CHKERR TSSetType(ts,TSBEULER);
643 CHKERR TSSetIFunction(ts,
F,PETSC_NULLPTR,PETSC_NULLPTR);
644 CHKERR TSSetIJacobian(ts,
A,
A,PETSC_NULLPTR,PETSC_NULLPTR);
653 CHKERR TSSetDuration(ts,PETSC_DEFAULT,ftime);
654 CHKERR TSSetFromOptions(ts);
658 CHKERR TSGetTime(ts,&ftime);
663 PetscInt steps,snesfails,rejects,nonlinits,linits;
664 CHKERR TSGetTimeStepNumber(ts,&steps);
665 CHKERR TSGetSNESFailures(ts,&snesfails);
666 CHKERR TSGetStepRejections(ts,&rejects);
667 CHKERR TSGetSNESIterations(ts,&nonlinits);
668 CHKERR TSGetKSPIterations(ts,&linits);
670 PetscPrintf(PETSC_COMM_WORLD,
671 "steps %D (%D rejected, %D SNES fails), ftime %g, nonlinits %D, "
673 steps, rejects, snesfails, ftime, nonlinits, linits);
677 PetscBool save_solution = PETSC_TRUE;
679 &save_solution, PETSC_NULLPTR);
682 if (is_partitioned) {
683 CHKERR moab.write_file(
"solution.h5m");
686 CHKERR moab.write_file(
"solution.h5m");