13 using namespace MoFEM;
15 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
17 #include <GenericClimateModel.hpp>
18 #include <GroundSurfaceTemperature.hpp>
24 #include <CrudeClimateModel.hpp>
26 #endif // __GROUND_SURFACE_TEMPERATURE_HPP
32 "-my_file mesh file\n"
33 "-order set approx. order to all blocks\n"
34 "-my_block_config set block data\n"
35 "-my_ground_analysis_data data for crude climate model\n"
61 :
FEMethod(), mField(m_field), postProc(m_field), skinPostProc(m_field),
64 PetscBool flg = PETSC_TRUE;
67 CHKERRABORT(PETSC_COMM_WORLD,
ierr);
68 if (flg != PETSC_TRUE) {
71 saveSkin = PETSC_TRUE;
73 &saveSkin, PETSC_NULL);
105 CHKERR TSGetTimeStepNumber(ts, &step);
107 if (pRT && (step) % pRT == 0) {
115 std::ostringstream sss;
116 sss <<
"out_skin_" << step <<
".h5m";
124 int main(
int argc,
char *argv[]) {
126 const string default_options =
"-ksp_type fgmres \n"
128 "-pc_factor_mat_solver_type mumps \n"
129 "-mat_mumps_icntl_20 0 \n"
131 "-snes_type newtonls \n"
132 "-snes_linesearch_type basic \n"
133 "-snes_max_it 100 \n"
139 "-ts_exact_final_time stepover \n";
141 string param_file =
"param_file.petsc";
142 if (!
static_cast<bool>(ifstream(param_file))) {
143 std::ofstream file(param_file.c_str(), std::ios::ate);
144 if (file.is_open()) {
145 file << default_options;
152 auto core_log = logging::core::get();
160 PetscBool flg = PETSC_TRUE;
164 if(flg != PETSC_TRUE) {
166 "*** ERROR -my_file (MESH FILE NEEDED)");
169 char time_data_file_for_ground_surface[255];
170 PetscBool ground_temperature_analysis = PETSC_FALSE;
172 time_data_file_for_ground_surface,255,&ground_temperature_analysis);
173 if(ground_temperature_analysis) {
176 "*** ERROR to do ground thermal analysis MoFEM need to be compiled "
178 #endif // WITH_ADOL_C
191 DMType dm_name =
"DMTHERMAL";
195 CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
196 CHKERR DMSetType(dm, dm_name);
226 if (flg != PETSC_TRUE) {
245 "MESH_NODE_POSITIONS");
253 PetscBool block_config;
254 char block_config_file[255];
256 block_config_file, 255, &block_config);
257 std::map<int,BlockOptionData> block_data;
258 bool solar_radiation =
false;
261 ifstream ini_file(block_config_file);
263 po::variables_map vm;
264 po::options_description config_file_options;
267 std::ostringstream str_order;
268 str_order <<
"block_" << it->getMeshsetId() <<
".temperature_order";
269 config_file_options.add_options()(
270 str_order.str().c_str(),
271 po::value<int>(&block_data[it->getMeshsetId()].oRder)
272 ->default_value(
order));
274 std::ostringstream str_cond;
275 str_cond <<
"block_" << it->getMeshsetId() <<
".heat_conductivity";
276 config_file_options.add_options()(
277 str_cond.str().c_str(),
278 po::value<double>(&block_data[it->getMeshsetId()].cOnductivity)
279 ->default_value(-1));
281 std::ostringstream str_capa;
282 str_capa <<
"block_" << it->getMeshsetId() <<
".heat_capacity";
283 config_file_options.add_options()(
284 str_capa.str().c_str(),
285 po::value<double>(&block_data[it->getMeshsetId()].cApacity)
286 ->default_value(-1));
288 std::ostringstream str_init_temp;
289 str_init_temp <<
"block_" << it->getMeshsetId()
290 <<
".initial_temperature";
291 config_file_options.add_options()(
292 str_init_temp.str().c_str(),
293 po::value<double>(&block_data[it->getMeshsetId()].initTemp)
296 config_file_options.add_options()(
297 "climate_model.solar_radiation",
298 po::value<bool>(&solar_radiation)->default_value(
false));
300 po::parsed_options parsed =
301 parse_config_file(ini_file, config_file_options,
true);
306 if (block_data[it->getMeshsetId()].oRder == -1)
308 if (block_data[it->getMeshsetId()].oRder ==
order)
310 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d oRder to %d\n",
311 it->getMeshsetId(), block_data[it->getMeshsetId()].oRder);
313 CHKERR moab.get_entities_by_handle(it->meshset, block_ents,
true);
314 Range ents_to_set_order;
315 CHKERR moab.get_adjacencies(block_ents, 3,
false, ents_to_set_order,
316 moab::Interface::UNION);
317 ents_to_set_order = ents_to_set_order.subset_by_type(MBTET);
318 CHKERR moab.get_adjacencies(block_ents, 2,
false, ents_to_set_order,
319 moab::Interface::UNION);
320 CHKERR moab.get_adjacencies(block_ents, 1,
false, ents_to_set_order,
321 moab::Interface::UNION);
323 block_data[it->getMeshsetId()].oRder);
325 block_data[it->getMeshsetId()].oRder);
327 std::vector<std::string> additional_parameters;
328 additional_parameters =
329 collect_unrecognized(parsed.options, po::include_positional);
330 for (std::vector<std::string>::iterator vit =
331 additional_parameters.begin();
332 vit != additional_parameters.end(); vit++) {
333 CHKERR PetscPrintf(PETSC_COMM_WORLD,
334 "** WARRING Unrecognised option %s\n", vit->c_str());
337 }
catch (
const std::exception& ex) {
338 std::ostringstream ss;
339 ss << ex.what() << std::endl;
356 false,
false,
false);
358 false,
false,
false);
362 std::map<int, ThermalElement::BlockData>::iterator mit;
364 for (; mit != thermal_elements.
setOfBlocks.end(); mit++) {
368 if (block_data[mit->first].cOnductivity != -1) {
369 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d heat conductivity to %3.2e\n",
370 mit->first, block_data[mit->first].cOnductivity);
371 for (
int dd = 0;
dd < 3;
dd++) {
372 mit->second.cOnductivity_mat(
dd,
dd) =
373 block_data[mit->first].cOnductivity;
376 if (block_data[mit->first].cApacity != -1) {
377 PetscPrintf(PETSC_COMM_WORLD,
"Set block %d heat capacity to %3.2e\n",
378 mit->first, block_data[mit->first].cApacity);
379 mit->second.cApacity = block_data[mit->first].cApacity;
383 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
384 GroundSurfaceTemperature ground_surface(m_field);
385 CrudeClimateModel time_data(time_data_file_for_ground_surface);
386 GroundSurfaceTemperature::PreProcess exectuteGenericClimateModel(&time_data);
387 if (ground_temperature_analysis) {
388 CHKERR ground_surface.addSurfaces(
"TEMP");
389 CHKERR ground_surface.setOperators(&time_data,
"TEMP");
391 #endif //__GROUND_SURFACE_TEMPERATURE_HPP
399 "MESH_NODE_POSITIONS");
404 for (; mit != thermal_elements.
setOfBlocks.end(); mit++) {
405 if (mit->second.initTemp != 0) {
407 CHKERR moab.get_connectivity(mit->second.tEts, vertices,
true);
409 mit->second.initTemp, MBVERTEX, vertices,
"TEMP");
414 if (std::regex_match(it->getName(), std::regex(
"INT_THERMAL(.*)"))) {
415 std::vector<double> data;
416 CHKERR it->getAttributes(data);
417 if (data.size() != 1)
418 SETERRQ(PETSC_COMM_SELF, 1,
"Data inconsistency");
419 Range block_ents, block_verts;
420 CHKERR moab.get_entities_by_handle(it->getMeshset(), block_ents,
true);
421 CHKERR moab.get_connectivity(block_ents, block_verts,
true);
423 block_verts,
"TEMP");
428 if (block_data[it->getMeshsetId()].initTemp != 0) {
430 CHKERR moab.get_entities_by_handle(it->meshset, block_ents,
true);
432 CHKERR moab.get_connectivity(block_ents, vertices,
true);
434 block_data[it->getMeshsetId()].initTemp, MBVERTEX, vertices,
"TEMP");
438 MPI_Comm moab_comm_world;
439 MPI_Comm_dup(PETSC_COMM_WORLD, &moab_comm_world);
440 ParallelComm *pcomm = ParallelComm::get_pcomm(&moab,
MYPCOMM_INDEX);
442 pcomm =
new ParallelComm(&moab, moab_comm_world);
444 PetscBool is_partitioned = PETSC_FALSE;
446 &is_partitioned, PETSC_NULL);
448 Range thermal_element_ents;
450 thermal_element_ents);
452 PetscBool save_skin = PETSC_TRUE;
454 &save_skin, PETSC_NULL);
458 CHKERR skin.find_skin(0, thermal_element_ents,
false, skin_faces);
460 if (is_partitioned) {
461 CHKERR pcomm->filter_pstatus(skin_faces,
462 PSTATUS_SHARED | PSTATUS_MULTISHARED,
463 PSTATUS_NOT, -1, &proc_skin);
465 proc_skin = skin_faces;
474 "MESH_NODE_POSITIONS");
495 std::vector<std::array<double, 3>> eval_points;
496 eval_points.resize(0);
497 PetscBool eval_points_flg = PETSC_FALSE;
498 char eval_points_file[255];
500 eval_points_file, 255, &eval_points_flg);
501 if (eval_points_flg) {
502 std::ifstream in_file(eval_points_file, std::ios::in);
503 if (!in_file.is_open()) {
508 while (in_file >> x >> y >> z) {
509 eval_points.push_back({x, y, z});
515 CHKERR DMSetFromOptions(dm);
524 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
525 if (ground_temperature_analysis) {
528 #endif //__GROUND_SURFACE_TEMPERATURE_HPP
557 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
559 &exectuteGenericClimateModel, NULL);
561 if (solar_radiation) {
563 GroundSurfaceTemperature::SolarRadiationPreProcessor>::iterator it,
565 it = ground_surface.preProcessShade.begin();
566 hi_it = ground_surface.preProcessShade.end();
567 for (; it != hi_it; it++) {
572 #endif //__GROUND_SURFACE_TEMPERATURE_HPP
583 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
584 if (ground_temperature_analysis) {
586 &ground_surface.getFeGroundSurfaceRhs(), NULL,
589 #endif //__GROUND_SURFACE_TEMPERATURE_HPP
598 #ifdef __GROUND_SURFACE_TEMPERATURE_HPP
599 if (ground_temperature_analysis) {
601 &ground_surface.getFeGroundSurfaceLhs(), NULL,
604 #endif //__GROUND_SURFACE_TEMPERATURE_HPP
618 CHKERR TSCreate(PETSC_COMM_WORLD,&ts);
619 CHKERR TSSetType(ts,TSBEULER);
621 CHKERR TSSetIFunction(ts,
F,PETSC_NULL,PETSC_NULL);
622 CHKERR TSSetIJacobian(ts,
A,
A,PETSC_NULL,PETSC_NULL);
631 CHKERR TSSetDuration(ts,PETSC_DEFAULT,ftime);
632 CHKERR TSSetFromOptions(ts);
636 CHKERR TSGetTime(ts,&ftime);
641 PetscInt steps,snesfails,rejects,nonlinits,linits;
642 CHKERR TSGetTimeStepNumber(ts,&steps);
643 CHKERR TSGetSNESFailures(ts,&snesfails);
644 CHKERR TSGetStepRejections(ts,&rejects);
645 CHKERR TSGetSNESIterations(ts,&nonlinits);
646 CHKERR TSGetKSPIterations(ts,&linits);
648 PetscPrintf(PETSC_COMM_WORLD,
649 "steps %D (%D rejected, %D SNES fails), ftime %g, nonlinits %D, "
651 steps, rejects, snesfails, ftime, nonlinits, linits);
655 PetscBool save_solution = PETSC_TRUE;
657 &save_solution, PETSC_NULL);
660 if (is_partitioned) {
661 CHKERR moab.write_file(
"solution.h5m");
664 CHKERR moab.write_file(
"solution.h5m");