v0.14.0
Loading...
Searching...
No Matches
h_adaptive_transport.cpp File Reference

Example implementation of transport problem using mixed formulation. More...

#include <MoFEM.hpp>
#include <MethodForForceScaling.hpp>
#include <MixTransportElement.hpp>

Go to the source code of this file.

Classes

struct  BcFluxData
 
struct  MyTransport
 Application of mix transport data structure. More...
 

Typedefs

typedef map< int, BcFluxDataBcFluxMap
 

Functions

int main (int argc, char *argv[])
 

Variables

static char help []
 

Detailed Description

Example implementation of transport problem using mixed formulation.

Todo
Should be implemented and tested problem from this article Demkowicz, Leszek, and Jayadeep Gopalakrishnan. "Analysis of the DPG method for the Poisson equation." SIAM Journal on Numerical Analysis 49.5 (2011): 1788-1809.

Definition in file h_adaptive_transport.cpp.

Typedef Documentation

◆ BcFluxMap

typedef map<int, BcFluxData> BcFluxMap

Definition at line 37 of file h_adaptive_transport.cpp.

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 357 of file h_adaptive_transport.cpp.

357 {
358
359 const string default_options = "-ksp_type fgmres \n"
360 "-pc_type lu \n"
361 "-pc_factor_mat_solver_type mumps \n"
362 "-mat_mumps_icntl_20 0 \n"
363 "-ksp_monitor\n";
364
365 string param_file = "param_file.petsc";
366 if (!static_cast<bool>(ifstream(param_file))) {
367 std::ofstream file(param_file.c_str(), std::ios::ate);
368 if (file.is_open()) {
369 file << default_options;
370 file.close();
371 }
372 }
373
374 MoFEM::Core::Initialize(&argc, &argv, param_file.c_str(), help);
375
376 try {
377
378 moab::Core mb_instance;
379 moab::Interface &moab = mb_instance;
380 int rank;
381 MPI_Comm_rank(PETSC_COMM_WORLD, &rank);
382
383 // get file name form command line
384 PetscBool flg = PETSC_TRUE;
385 char mesh_file_name[255];
386 CHKERR PetscOptionsGetString(PETSC_NULL, PETSC_NULL, "-my_file",
387 mesh_file_name, 255, &flg);
388 if (flg != PETSC_TRUE) {
389 SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
390 "*** ERROR -my_file (MESH FILE NEEDED)");
391 }
392
393 const char *option;
394 option = "";
395 CHKERR moab.load_file(mesh_file_name, 0, option);
396
397 // Create mofem interface
398 MoFEM::Core core(moab);
399 MoFEM::Interface &m_field = core;
400
401 // Add meshsets with material and boundary conditions
402 MeshsetsManager *meshsets_manager_ptr;
403 CHKERR m_field.getInterface(meshsets_manager_ptr);
404 CHKERR meshsets_manager_ptr->setMeshsetFromFile();
405
406 PetscPrintf(PETSC_COMM_WORLD,
407 "Read meshsets add added meshsets for bc.cfg\n");
408 for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, it)) {
409 PetscPrintf(PETSC_COMM_WORLD, "%s",
410 static_cast<std::ostringstream &>(
411 std::ostringstream().seekp(0) << *it << endl)
412 .str()
413 .c_str());
414 cerr << *it << endl;
415 }
416
417 // set entities bit level
418 BitRefLevel ref_level;
419 ref_level.set(0);
420 CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
421 0, 3, ref_level);
422
423 // set app. order
424 // see Hierarchic Finite Element Bases on Unstructured Tetrahedral Meshes
425 // (Mark Ainsworth & Joe Coyle)
426 PetscInt order;
427 CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-my_order", &order,
428 &flg);
429 if (flg != PETSC_TRUE) {
430 order = 0;
431 }
432
433 // finite elements
434
435 BcFluxMap bc_flux_map;
436 MyTransport ufe(m_field, bc_flux_map);
437
438 // Initially calculate problem on coarse mesh
439
440 CHKERR ufe.addFields("VALUES", "FLUXES", order);
441 CHKERR ufe.addFiniteElements("FLUXES", "VALUES");
442 // Set boundary conditions
443 CHKERR ufe.addBoundaryElements(ref_level);
444 CHKERR ufe.buildProblem(ref_level);
445 CHKERR ufe.createMatrices();
446 CHKERR ufe.solveLinearProblem();
447 CHKERR ufe.calculateResidual();
448 CHKERR ufe.evaluateError();
449 CHKERR ufe.destroyMatrices();
450 CHKERR ufe.postProc("out_0.h5m");
451
452 int nb_levels = 5; // default number of refinement levels
453 // get number of refinement levels form command line
454 CHKERR PetscOptionsGetInt(PETSC_NULL, PETSC_NULL, "-nb_levels", &nb_levels,
455 PETSC_NULL);
456
457 // refine mesh, solve problem and do it again until number of refinement
458 // levels are exceeded.
459 for (int ll = 1; ll != nb_levels; ll++) {
460 const int nb_levels = ll;
461 CHKERR ufe.squashBits();
462 CHKERR ufe.refineMesh(ufe, nb_levels, order);
463 ref_level = BitRefLevel().set(nb_levels);
464 bc_flux_map.clear();
465 CHKERR ufe.addBoundaryElements(ref_level);
466 CHKERR ufe.buildProblem(ref_level);
467 CHKERR ufe.createMatrices();
468 CHKERR ufe.solveLinearProblem();
469 CHKERR ufe.calculateResidual();
470 CHKERR ufe.evaluateError();
471 CHKERR ufe.destroyMatrices();
472 CHKERR ufe.postProc(
473 static_cast<std::ostringstream &>(std::ostringstream().seekp(0)
474 << "out_" << nb_levels << ".h5m")
475 .str());
476 }
477 }
479
481
482 return 0;
483}
#define CATCH_ERRORS
Catch errors.
@ MOFEM_INVALID_DATA
Definition definitions.h:36
#define CHKERR
Inline error check.
constexpr int order
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
static char help[]
map< int, BcFluxData > BcFluxMap
constexpr int nb_levels
Definition level_set.cpp:58
char mesh_file_name[255]
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition Types.hpp:40
PetscErrorCode PetscOptionsGetInt(PetscOptions *, const char pre[], const char name[], PetscInt *ivalue, PetscBool *set)
PetscErrorCode PetscOptionsGetString(PetscOptions *, const char pre[], const char name[], char str[], size_t size, PetscBool *set)
Managing BitRefLevels.
Core (interface) class.
Definition Core.hpp:82
static MoFEMErrorCode Initialize(int *argc, char ***args, const char file[], const char help[])
Initializes the MoFEM database PETSc, MOAB and MPI.
Definition Core.cpp:72
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition Core.cpp:112
Deprecated interface functions.
Interface for managing meshsets containing materials and boundary conditions.
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface reference to pointer of interface.
Application of mix transport data structure.

Variable Documentation

◆ help

char help[]
static
Initial value:
= "-my_file input file"
"-my_order order of approximation"
"-nb_levels number of refinements levels"
"\n\n"

Definition at line 23 of file h_adaptive_transport.cpp.