144 {
145
146 const string default_options = "-ksp_type fgmres \n"
147 "-pc_type lu \n"
148 "-pc_factor_mat_solver_type mumps \n"
149 "-mat_mumps_icntl_20 0 \n"
150 "-ksp_monitor \n"
151 "-snes_type newtonls \n"
152 "-snes_linesearch_type basic \n"
153 "-snes_max_it 100 \n"
154 "-snes_atol 1e-8 \n"
155 "-snes_rtol 1e-8 \n"
156 "-snes_monitor \n"
157 "-ts_monitor \n"
158 "-ts_type beuler \n"
159 "-ts_exact_final_time stepover \n";
160
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;
167 }
168 }
169
171
172 auto core_log = logging::core::get();
173 core_log->add_sink(
177
178 try {
179
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)");
187 }
188
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) {
194#ifndef WITH_ADOL_C
196 "*** ERROR to do ground thermal analysis MoFEM need to be compiled "
197 "with ADOL-C");
198#endif
199 }
200
201
202 moab::Core mb_instance;
203 moab::Interface& moab = mb_instance;
204 const char *option;
205 option = "";
206 CHKERR moab.load_file(mesh_file_name, 0, option);
207
210
211 DMType dm_name = "DMTHERMAL";
213
214 DM dm;
215 CHKERR DMCreate(PETSC_COMM_WORLD, &dm);
216 CHKERR DMSetType(dm, dm_name);
217
218
219
221 bit_level0.set(0);
223 bit_level0);
224
225
230
231
232
235 );
236
237
238 EntityHandle root_set = moab.get_root_set();
239
242
245
246 if (flg != PETSC_TRUE) {
248 }
249
250
251
252
257
262
263
265 "MESH_NODE_POSITIONS");
270
271
272
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;
279 if (block_config) {
280 try {
281 ifstream ini_file(block_config_file);
282
283 po::variables_map vm;
284 po::options_description config_file_options;
286
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));
293
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));
300
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));
307
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)
314 ->default_value(0));
315 }
316 config_file_options.add_options()(
317 "climate_model.solar_radiation",
318 po::value<bool>(&solar_radiation)->default_value(false));
319
320 po::parsed_options parsed =
321 parse_config_file(ini_file, config_file_options, true);
322 store(parsed,vm);
323 po::notify(vm);
324
326 if (block_data[it->getMeshsetId()].oRder == -1)
327 continue;
328 if (block_data[it->getMeshsetId()].oRder ==
order)
329 continue;
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);
346 }
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());
355 }
356
357 } catch (const std::exception& ex) {
358 std::ostringstream ss;
359 ss << ex.what() << std::endl;
361 }
362 }
363
364
366 CHKERR thermal_elements.addThermalElements(
"TEMP");
367 CHKERR thermal_elements.addThermalFluxElement(
"TEMP");
368 CHKERR thermal_elements.addThermalConvectionElement(
"TEMP");
369 CHKERR thermal_elements.addThermalRadiationElement(
"TEMP");
370
372 "TEMP_RATE");
373
374
376 thermal_elements.getLoopFeRhs().getOpPtrVector(), {H1},
377 "MESH_NODE_POSITIONS");
379 thermal_elements.getLoopFeLhs().getOpPtrVector(), {H1},
380 "MESH_NODE_POSITIONS");
381 CHKERR thermal_elements.setTimeSteppingProblem(
"TEMP",
"TEMP_RATE");
382
383
384 std::map<int, ThermalElement::BlockData>::iterator mit;
385 mit = thermal_elements.setOfBlocks.begin();
386 for (; mit != thermal_elements.setOfBlocks.end(); mit++) {
387
388
389
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;
396 }
397 }
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;
402 }
403 }
404
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");
412 }
413#endif
414
415
416
417
419
421 "MESH_NODE_POSITIONS");
423
424
425 mit = thermal_elements.setOfBlocks.begin();
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");
432 }
433 }
434
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");
446 }
447 }
448
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");
457 }
458 }
459
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);
463 if (pcomm == NULL)
464 pcomm = new ParallelComm(&moab, moab_comm_world);
465
466 PetscBool is_partitioned = PETSC_FALSE;
468 &is_partitioned, PETSC_NULLPTR);
469
470 Range thermal_element_ents;
472 thermal_element_ents);
473
474 PetscBool save_skin = PETSC_TRUE;
476 &save_skin, PETSC_NULLPTR);
477
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);
486 } else {
487 proc_skin = skin_faces;
488 }
489
490 if (save_skin) {
496 "MESH_NODE_POSITIONS");
498 "POST_PROC_SKIN");
499 }
500
501
503
505
506
510
511
512
513
515 }
516
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()) {
527 eval_points_file);
528 }
529 double x, y, z;
530 while (in_file >> x >> y >> z) {
531 eval_points.push_back({x, y, z});
532 }
533 }
534
535
537 CHKERR DMSetFromOptions(dm);
538
543 if (save_skin)
545
546#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
547 if (ground_temperature_analysis) {
549 }
550#endif
551
553
554
560
563 "TEMP_RATE");
565 eval_points);
567
568
573
574
576 NULL);
579#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
581 &exectuteGenericClimateModel, NULL);
582 {
583 if (solar_radiation) {
584 boost::ptr_vector<
585 GroundSurfaceTemperature::SolarRadiationPreProcessor>::iterator it,
586 hi_it;
587 it = ground_surface.preProcessShade.begin();
588 hi_it = ground_surface.preProcessShade.end();
589 for (; it != hi_it; it++) {
591 }
592 }
593 }
594#endif
595
596
598 NULL);
600 NULL, NULL);
602 &thermal_elements.feConvectionRhs, NULL, NULL);
604 &thermal_elements.feRadiationRhs, NULL, NULL);
605#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
606 if (ground_temperature_analysis) {
608 &ground_surface.getFeGroundSurfaceRhs(), NULL,
609 NULL);
610 }
611#endif
612
613
615 NULL);
617 &thermal_elements.feConvectionLhs, NULL, NULL);
619 &thermal_elements.feRadiationLhs, NULL, NULL);
620#ifdef __GROUND_SURFACE_TEMPERATURE_HPP
621 if (ground_temperature_analysis) {
623 &ground_surface.getFeGroundSurfaceLhs(), NULL,
624 NULL);
625 }
626#endif
627
628
631
634
637
638
639 TS ts;
640 CHKERR TSCreate(PETSC_COMM_WORLD,&ts);
641 CHKERR TSSetType(ts,TSBEULER);
642
643 CHKERR TSSetIFunction(ts,
F,PETSC_NULLPTR,PETSC_NULLPTR);
644 CHKERR TSSetIJacobian(ts,A,A,PETSC_NULLPTR,PETSC_NULLPTR);
645
647
649
651
652 double ftime = 1;
653 CHKERR TSSetDuration(ts,PETSC_DEFAULT,ftime);
654 CHKERR TSSetFromOptions(ts);
656
658 CHKERR TSGetTime(ts,&ftime);
659
660
662
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);
669
670 PetscPrintf(PETSC_COMM_WORLD,
671 "steps %D (%D rejected, %D SNES fails), ftime %g, nonlinits %D, "
672 "linits %D\n",
673 steps, rejects, snesfails, ftime, nonlinits, linits);
674
675
676
677 PetscBool save_solution = PETSC_TRUE;
679 &save_solution, PETSC_NULLPTR);
680
681 if (save_solution) {
682 if (is_partitioned) {
683 CHKERR moab.write_file(
"solution.h5m");
684 } else {
686 CHKERR moab.write_file(
"solution.h5m");
687 }
688 }
689 }
690
694
696
697 }
699
701}
#define CATCH_ERRORS
Catch errors.
@ AINSWORTH_LEGENDRE_BASE
Ainsworth Cole (Legendre) approx. base .
#define MYPCOMM_INDEX
default communicator number PCOMM
@ MOFEM_STD_EXCEPTION_THROW
@ MOFEM_DATA_INCONSISTENCY
#define CHKERR
Inline error check.
PetscErrorCode DMoFEMMeshToGlobalVector(DM dm, Vec g, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set ghosted vector values on all existing mesh entities
PetscErrorCode DMMoFEMAddElement(DM dm, std::string fe_name)
add element to dm
PetscErrorCode DMMoFEMTSSetIFunction(DM dm, const char fe_name[], MoFEM::FEMethod *method, MoFEM::BasicMethod *pre_only, MoFEM::BasicMethod *post_only)
set TS implicit function evaluation function
PetscErrorCode DMMoFEMCreateMoFEM(DM dm, MoFEM::Interface *m_field_ptr, const char problem_name[], const MoFEM::BitRefLevel bit_level, const MoFEM::BitRefLevel bit_mask=MoFEM::BitRefLevel().set())
Must be called by user to set MoFEM data structures.
PetscErrorCode DMCreateMatrix_MoFEM(DM dm, Mat *M)
PetscErrorCode DMMoFEMGetTsCtx(DM dm, MoFEM::TsCtx **ts_ctx)
get MoFEM::TsCtx data structure
PetscErrorCode DMoFEMMeshToLocalVector(DM dm, Vec l, InsertMode mode, ScatterMode scatter_mode, RowColData rc=RowColData::COL)
set local (or ghosted) vector values on mesh for partition only
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
PetscErrorCode DMMoFEMTSSetIJacobian(DM dm, const std::string fe_name, boost::shared_ptr< MoFEM::FEMethod > method, boost::shared_ptr< MoFEM::BasicMethod > pre_only, boost::shared_ptr< MoFEM::BasicMethod > post_only)
set TS Jacobian evaluation function
PetscErrorCode DMCreateGlobalVector_MoFEM(DM dm, Vec *g)
DMShellSetCreateGlobalVector.
PetscErrorCode DMoFEMPreProcessFiniteElements(DM dm, MoFEM::FEMethod *method)
execute finite element method for each element in dm (problem)
virtual MoFEMErrorCode add_ents_to_finite_element_by_dim(const EntityHandle entities, const int dim, const std::string name, const bool recursive=true)=0
add entities to finite element
virtual MoFEMErrorCode add_finite_element(const std::string &fe_name, enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
add finite element
virtual MoFEMErrorCode build_finite_elements(int verb=DEFAULT_VERBOSITY)=0
Build finite elements.
virtual MoFEMErrorCode modify_finite_element_add_field_col(const std::string &fe_name, const std::string name_row)=0
set field col which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_row(const std::string &fe_name, const std::string name_row)=0
set field row which finite element use
virtual MoFEMErrorCode modify_finite_element_add_field_data(const std::string &fe_name, const std::string name_field)=0
set finite element field data
virtual MoFEMErrorCode build_fields(int verb=DEFAULT_VERBOSITY)=0
virtual MoFEMErrorCode get_finite_element_entities_by_dimension(const std::string name, int dim, Range &ents) const =0
get entities in the finite element by dimension
virtual MoFEMErrorCode set_field_order(const EntityHandle meshset, const EntityType type, const std::string &name, const ApproximationOrder order, int verb=DEFAULT_VERBOSITY)=0
Set order approximation of the entities in the field.
virtual MoFEMErrorCode add_ents_to_field_by_type(const Range &ents, const EntityType type, const std::string &name, int verb=DEFAULT_VERBOSITY)=0
Add entities to field meshset.
static LoggerType & setLog(const std::string channel)
Set ans resset chanel logger.
#define MOFEM_LOG_TAG(channel, tag)
Tag channel.
virtual MoFEMErrorCode loop_dofs(const Problem *problem_ptr, const std::string &field_name, RowColData rc, DofMethod &method, int lower_rank, int upper_rank, int verb=DEFAULT_VERBOSITY)=0
Make a loop over dofs.
#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.
virtual MoFEMErrorCode finalize_series_recorder(const std::string &serie_name)
virtual bool check_series(const std::string &name) const
check if series is in database
virtual MoFEMErrorCode initialize_series_recorder(const std::string &serie_name)
virtual MoFEMErrorCode add_series_recorder(const std::string &series_name)
virtual MoFEMErrorCode delete_recorder_series(const std::string &series_name)
const FTensor::Tensor2< T, Dim, Dim > Vec
const Tensor2_symmetric_Expr< const ddTensor0< T, Dim, i, j >, typename promote< T, double >::V, Dim, i, j > dd(const Tensor0< T * > &a, const Index< i, Dim > index1, const Index< j, Dim > index2, const Tensor1< int, Dim > &d_ijk, const Tensor1< double, Dim > &d_xyz)
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
PetscErrorCode TsMonitorSet(TS ts, PetscInt step, PetscReal t, Vec u, void *ctx)
Set monitor for TS solver.
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Add operators pushing bases from local to physical configuration.
virtual moab::Interface & get_moab()=0
virtual MoFEMErrorCode build_adjacencies(const Range &ents, int verb=DEFAULT_VERBOSITY)=0
build adjacencies
virtual MoFEMErrorCode add_field(const std::string name, const FieldSpace space, const FieldApproximationBase base, const FieldCoefficientsNumber nb_of_coefficients, const TagType tag_type=MB_TAG_SPARSE, const enum MoFEMTypes bh=MF_EXCL, int verb=DEFAULT_VERBOSITY)=0
Add field.
virtual int get_comm_rank() const =0
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Deprecated interface functions.
static boost::shared_ptr< SinkType > createSink(boost::shared_ptr< std::ostream > stream_ptr, std::string comm_filter)
Create a sink object.
static boost::shared_ptr< std::ostream > getStrmSync()
Get the strm sync object.
Projection of edge entities with one mid-node on hierarchical basis.
Interface for Time Stepping (TS) solver.
BasicMethodsSequence & getPostProcessMonitor()
Get the postProcess to do Monitor object.
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
TS monitore it records temperature at time steps.
this calass is to control time stepping
structure grouping operators and data used for thermal problems