v0.14.0
unsaturated_transport.cpp
/** \file unsaturated_transport.cpp
\brief Implementation of unsaturated flow problem
\example unsaturated_transport.cpp
\ingroup mofem_mix_transport_elem
*/
#ifndef WITH_ADOL_C
#error "MoFEM need to be compiled with ADOL-C"
#endif
using namespace MoFEM;
using namespace MixTransport;
static char help[] = "...\n\n";
double GenericMaterial::ePsilon0 = 0;
double GenericMaterial::ePsilon1 = 0;
double GenericMaterial::scaleZ = 1;
map<std::string, CommonMaterialData::RegisterHook>
RegisterMaterials::mapOfRegistredMaterials;
int main(int argc, char *argv[]) {
const string default_options = "-ksp_type fgmres\n"
"-pc_type lu \n"
"-pc_factor_mat_solver_type mumps \n"
"-mat_mumps_icntl_20 0 \n";
string param_file = "param_file.petsc";
if (!static_cast<bool>(ifstream(param_file))) {
std::ofstream file(param_file.c_str(), std::ios::ate);
if (file.is_open()) {
file << default_options;
file.close();
}
}
MoFEM::Core::Initialize(&argc, &argv, param_file.c_str(), help);
// Register DM Manager
CHKERR DMRegister_MoFEM("DMMOFEM"); // register MoFEM DM in PETSc
// Register materials
PetscBool test_mat = PETSC_FALSE;
CHKERR PetscOptionsGetBool(PETSC_NULL, "", "-test_mat", &test_mat,
PETSC_NULL);
if (test_mat == PETSC_TRUE) {
// Testing van_genuchten
MaterialVanGenuchten van_genuchten(data);
van_genuchten.printMatParameters(-1, "testing");
van_genuchten.printTheta(-1e-16, -1e4, -1e-12, "hTheta");
van_genuchten.printKappa(-1e-16, -1, -1e-12, "hK");
van_genuchten.printC(-1e-16, -1, -1e-12, "hC");
CHKERR PetscFinalize();
return 0;
}
try {
moab::Core mb_instance;
moab::Interface &moab = mb_instance;
// get file name form command line
PetscBool flg_mesh_file_name = PETSC_TRUE;
char mesh_file_name[255];
PetscBool flg_conf_file_name = PETSC_TRUE;
char conf_file_name[255];
int order = 1;
ierr = PetscOptionsBegin(PETSC_COMM_WORLD, "", "Unsaturated flow options",
"none");
ierr = PetscOptionsString("-my_file", "mesh file name", "", "mesh.h5m",
mesh_file_name, 255, &flg_mesh_file_name);
ierr = PetscOptionsString(
"-configure", "material and bc configuration file name", "",
"unsaturated.cfg", conf_file_name, 255, &flg_conf_file_name);
ierr = PetscOptionsInt("-my_order", "default approximation order", "",
order, &order, PETSC_NULL);
ierr = PetscOptionsEnd();
if (flg_mesh_file_name != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
"File name not set (e.g. -my_name mesh.h5m)");
}
if (flg_conf_file_name != PETSC_TRUE) {
SETERRQ(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
"File name not set (e.g. -config unsaturated.cfg)");
}
// Create MOAB communicator
auto pcomm = ParallelComm::get_pcomm(&moab, MYPCOMM_INDEX);
auto moab_comm_wrap =
boost::make_shared<WrapMPIComm>(PETSC_COMM_WORLD, false);
if (pcomm == NULL)
pcomm =
new ParallelComm(&moab, moab_comm_wrap->get_comm());
const char *option;
option = "PARALLEL=READ_PART;"
"PARALLEL_RESOLVE_SHARED_ENTS;"
"PARTITION=PARALLEL_PARTITION;";
CHKERR moab.load_file(mesh_file_name, 0, option);
// Create mofem interface
MoFEM::Core core(moab);
MoFEM::Interface &m_field = core;
// Add meshsets with material and boundary conditions
MeshsetsManager *meshsets_manager_ptr;
CHKERR m_field.getInterface(meshsets_manager_ptr);
CHKERR meshsets_manager_ptr->setMeshsetFromFile();
PetscPrintf(PETSC_COMM_WORLD,
"Read meshsets and added meshsets from bc.cfg\n");
for (_IT_CUBITMESHSETS_FOR_LOOP_(m_field, it)) {
PetscPrintf(PETSC_COMM_WORLD, "%s",
static_cast<std::ostringstream &>(
std::ostringstream().seekp(0) << *it << endl)
.str()
.c_str());
}
// Set entities bit level
CHKERR m_field.getInterface<BitRefManager>()->setBitRefLevelByDim(
0, 3, BitRefLevel().set(0));
ifstream ini_file(conf_file_name);
po::variables_map vm;
po::options_description config_file_options;
Range domain_ents, bc_boundary_ents;
map<int, CommonMaterialData> material_blocks;
map<int, double> head_blocks;
map<int, double> flux_blocks;
// Set material blocks
if (it->getName().compare(0, 4, "SOIL") != 0)
continue;
// get block id
const int block_id = it->getMeshsetId();
std::string block_name =
"mat_block_" + boost::lexical_cast<std::string>(block_id);
material_blocks[block_id].blockId = block_id;
material_blocks[block_id].addOptions(config_file_options, block_name);
}
if (it->getName().compare(0, 4, "HEAD") != 0)
continue;
// get block id
const int block_id = it->getMeshsetId();
std::string block_name =
"head_block_" + boost::lexical_cast<std::string>(block_id);
config_file_options.add_options()(
(block_name + ".head").c_str(),
po::value<double>(&head_blocks[block_id])->default_value(0));
}
if (it->getName().compare(0, 4, "FLUX") != 0)
continue;
// get block id
const int block_id = it->getMeshsetId();
std::string block_name =
"flux_block_" + boost::lexical_cast<std::string>(block_id);
config_file_options.add_options()(
(block_name + ".flux").c_str(),
po::value<double>(&head_blocks[block_id])->default_value(0));
}
po::parsed_options parsed =
parse_config_file(ini_file, config_file_options, true);
store(parsed, vm);
po::notify(vm);
if (it->getName().compare(0, 4, "SOIL") != 0)
continue;
const int block_id = it->getMeshsetId();
uf.dMatMap[block_id] = RegisterMaterials::mapOfRegistredMaterials.at(
material_blocks[block_id].matName)(material_blocks.at(block_id));
if (!uf.dMatMap.at(block_id)) {
SETERRQ(PETSC_COMM_WORLD, MOFEM_DATA_INCONSISTENCY,
"Material block not set");
}
// get block test
CHKERR m_field.get_moab().get_entities_by_type(
it->meshset, MBTET, uf.dMatMap.at(block_id)->tEts, true);
domain_ents.merge(uf.dMatMap.at(block_id)->tEts);
uf.dMatMap.at(block_id)->printMatParameters(block_id, "Read material");
}
std::vector<std::string> additional_parameters;
additional_parameters =
collect_unrecognized(parsed.options, po::include_positional);
for (std::vector<std::string>::iterator vit = additional_parameters.begin();
vit != additional_parameters.end(); vit++) {
CHKERR PetscPrintf(m_field.get_comm(),
"** WARNING Unrecognized option %s\n", vit->c_str());
}
// Set capillary pressure bc data
if (it->getName().compare(0, 4, "HEAD") != 0)
continue;
// get block id
const int block_id = it->getMeshsetId();
// create block data instance
uf.bcValueMap[block_id] =
boost::shared_ptr<UnsaturatedFlowElement::BcData>(
// get bc value
std::vector<double> attributes;
CHKERR it->getAttributes(attributes);
if (attributes.size() != 1)
SETERRQ1(PETSC_COMM_SELF, MOFEM_INVALID_DATA,
"Wrong number of head parameters %d", attributes.size());
uf.bcValueMap[block_id]->fixValue = attributes[0];
std::string block_name =
"head_block_" + boost::lexical_cast<std::string>(block_id);
if (vm.count((block_name) + ".head")) {
uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
}
// cerr << uf.bcValueMap[block_id]->fixValue << endl;
// CHKERR it->printAttributes(std::cout);
// get faces in the block
CHKERR m_field.get_moab().get_entities_by_type(
it->meshset, MBTRI, uf.bcValueMap[block_id]->eNts, true);
bc_boundary_ents.merge(uf.bcValueMap[block_id]->eNts);
}
int max_flux_id = 0;
// Set water flux bc data
if (it->getName().compare(0, 4, "FLUX") != 0)
continue;
// get block id
const int block_id = it->getMeshsetId();
// create block data instance
uf.bcFluxMap[block_id] =
boost::shared_ptr<UnsaturatedFlowElement::BcData>(
// get bc value
std::vector<double> attributes;
CHKERR it->getAttributes(attributes);
// CHKERR it->printAttributes(std::cout);
uf.bcFluxMap[block_id]->fixValue = attributes[0];
std::string block_name =
"flux_block_" + boost::lexical_cast<std::string>(block_id);
if (vm.count((block_name) + ".flux")) {
uf.bcValueMap[block_id]->fixValue = head_blocks[block_id];
}
// get faces in the block
CHKERR m_field.get_moab().get_entities_by_type(
it->meshset, MBTRI, uf.bcFluxMap[block_id]->eNts, true);
bc_boundary_ents.merge(uf.bcFluxMap[block_id]->eNts);
max_flux_id = max_flux_id > block_id ? max_flux_id : block_id + 1;
}
// Add zero flux on the rest of the boundary
auto get_zero_flux_entities = [&m_field,
&pcomm](const auto &domain_ents,
const auto &bc_boundary_ents) {
Range zero_flux_ents;
Skinner skin(&m_field.get_moab());
Range domain_skin;
CHKERR skin.find_skin(0, domain_ents, false, domain_skin);
// filter not owned entities, those are not on boundary
CHKERR pcomm->filter_pstatus(domain_skin,
PSTATUS_SHARED | PSTATUS_MULTISHARED,
PSTATUS_NOT, -1, &zero_flux_ents);
zero_flux_ents = subtract(zero_flux_ents, bc_boundary_ents);
return zero_flux_ents;
};
CHKERR uf.addFields("VALUES", "FLUXES", order);
CHKERR uf.addFiniteElements("FLUXES", "VALUES");
CHKERR uf.buildProblem(
get_zero_flux_entities(domain_ents, bc_boundary_ents));
CHKERR uf.createMatrices();
CHKERR uf.setFiniteElements();
CHKERR uf.calculateEssentialBc();
CHKERR uf.calculateInitialPc();
CHKERR uf.solveProblem();
CHKERR uf.destroyMatrices();
}
return 0;
}
MoFEM::UnknownInterface::getInterface
MoFEMErrorCode getInterface(IFACE *&iface) const
Get interface refernce to pointer of interface.
Definition: UnknownInterface.hpp:93
main
int main(int argc, char *argv[])
Definition: unsaturated_transport.cpp:31
MYPCOMM_INDEX
#define MYPCOMM_INDEX
default communicator number PCOMM
Definition: definitions.h:215
MixTransport::RegisterMaterials
Definition: MaterialUnsaturatedFlow.hpp:350
MixTransport::UnsaturatedFlowElement::BcData
Class storing information about boundary condition.
Definition: UnsaturatedFlow.hpp:145
MoFEM::CoreTmp< 0 >
Core (interface) class.
Definition: Core.hpp:82
MoFEM::CoreInterface::get_comm
virtual MPI_Comm & get_comm() const =0
MixTransport::CommonMaterialData::printMatParameters
void printMatParameters(const int id, const std::string &prefix) const
Definition: MaterialUnsaturatedFlow.hpp:77
MixTransport::CommonMaterialData
Definition: MaterialUnsaturatedFlow.hpp:13
help
static char help[]
Definition: unsaturated_transport.cpp:22
MixTransport::MaterialVanGenuchten::printKappa
void printKappa(const double b, const double e, double s, const std::string &prefix)
Definition: MaterialUnsaturatedFlow.hpp:328
MixTransport::MaterialVanGenuchten::printTheta
void printTheta(const double b, const double e, double s, const std::string &prefix)
Definition: MaterialUnsaturatedFlow.hpp:315
BasicFiniteElements.hpp
MixTransport::MaterialVanGenuchten
Definition: MaterialUnsaturatedFlow.hpp:254
MoFEM::CoreTmp< 0 >::Finalize
static MoFEMErrorCode Finalize()
Checks for options to be called at the conclusion of the program.
Definition: Core.cpp:112
order
constexpr int order
Definition: dg_projection.cpp:18
MoFEM::DeprecatedCoreInterface
Deprecated interface functions.
Definition: DeprecatedCoreInterface.hpp:16
MoFEM::Interface
DeprecatedCoreInterface Interface
Definition: Interface.hpp:1975
MixTransport::MaterialVanGenuchten::printC
void printC(const double b, const double e, double s, const std::string &prefix)
Definition: MaterialUnsaturatedFlow.hpp:339
CHKERR
#define CHKERR
Inline error check.
Definition: definitions.h:535
UnsaturatedFlow.hpp
Mix implementation of transport element.
MoFEM::CoreInterface::get_moab
virtual moab::Interface & get_moab()=0
MoFEM
implementation of Data Operators for Forces and Sources
Definition: Common.hpp:10
MoFEM::MeshsetsManager::setMeshsetFromFile
MoFEMErrorCode setMeshsetFromFile(const string file_name, const bool clean_file_options=true)
add blocksets reading config file
Definition: MeshsetsManager.cpp:788
MoFEM::DMRegister_MoFEM
PetscErrorCode DMRegister_MoFEM(const char sname[])
Register MoFEM problem.
Definition: DMMoFEM.cpp:47
MixTransport::UnsaturatedFlowElement
Implementation of operators, problem and finite elements for unsaturated flow.
Definition: UnsaturatedFlow.hpp:102
mesh_file_name
char mesh_file_name[255]
Definition: mesh_smoothing.cpp:23
Range
MoFEM::CoreTmp< 0 >::Initialize
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
CATCH_ERRORS
#define CATCH_ERRORS
Catch errors.
Definition: definitions.h:372
_IT_CUBITMESHSETS_BY_SET_TYPE_FOR_LOOP_
#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.
Definition: MeshsetsManager.hpp:71
MixTransport
Definition: MaterialUnsaturatedFlow.hpp:11
MoFEM::Core
CoreTmp< 0 > Core
Definition: Core.hpp:1094
BLOCKSET
@ BLOCKSET
Definition: definitions.h:148
MixTransportElement.hpp
Mix implementation of transport element.
MoFEM::Exceptions::ierr
static MoFEMErrorCodeGeneric< PetscErrorCode > ierr
Definition: Exceptions.hpp:76
MOFEM_DATA_INCONSISTENCY
@ MOFEM_DATA_INCONSISTENCY
Definition: definitions.h:31
MoFEM::MeshsetsManager
Interface for managing meshsets containing materials and boundary conditions.
Definition: MeshsetsManager.hpp:104
MaterialUnsaturatedFlow.hpp
Mix implementation of transport element.
_IT_CUBITMESHSETS_FOR_LOOP_
#define _IT_CUBITMESHSETS_FOR_LOOP_(MESHSET_MANAGER, IT)
Iterator that loops over all the Cubit MeshSets in a moFEM field.
Definition: MeshsetsManager.hpp:34
MoFEM::BitRefManager
Managing BitRefLevels.
Definition: BitRefManager.hpp:21
MoFEM::Types::BitRefLevel
std::bitset< BITREFLEVEL_SIZE > BitRefLevel
Bit structure attached to each entity identifying to what mesh entity is attached.
Definition: Types.hpp:40
CHKERRG
#define CHKERRG(n)
Check error code of MoFEM/MOAB/PETSc function.
Definition: definitions.h:483
MOFEM_INVALID_DATA
@ MOFEM_INVALID_DATA
Definition: definitions.h:36
MoFEM::PetscOptionsGetBool
PetscErrorCode PetscOptionsGetBool(PetscOptions *, const char pre[], const char name[], PetscBool *bval, PetscBool *set)
Definition: DeprecatedPetsc.hpp:182