MoReFEM
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | Friends
MoReFEM::InputData< TupleT, DoUpdateLuaFileT > Class Template Reference

This class read the input data file and then is in charge of holding the values read. More...

#include <InputData.hpp>

Inheritance diagram for MoReFEM::InputData< TupleT, DoUpdateLuaFileT >:
Collaboration diagram for MoReFEM::InputData< TupleT, DoUpdateLuaFileT >:

Public Types

using self = InputData<TupleT, DoUpdateLuaFileT>
 Self.
 
using parent = Internal::InputDataNS::AbstractClass<TupleT>
 Abstract parent.
 
using const_unique_ptr = std::unique_ptr<const self>
 Alias to smart pointers storing objects.
 
using underlying_tuple_type = TupleT
 The underlying tuple type.
 

Public Member Functions

template<::MoReFEM::Concept::ModelSettingsType ModelSettingsT>
 InputData (const ModelSettingsT &model_settings, const FilesystemNS::File &filename, InputDataNS::DoTrackUnusedFields do_track_unused_fields=InputDataNS::DoTrackUnusedFields::yes)
 Special members.
 
 InputData (const InputData &rhs)=delete
 The copy constructor.
 
 InputData (InputData &&rhs)=delete
 The move constructor.
 
InputDataoperator= (const InputData &rhs)=delete
 The (copy) operator=.
 
InputDataoperator= (InputData &&rhs)=delete
 The (move) operator=.
 
virtual ~InputData () override
 Destructor.
 
const FilesystemNS::FileGetInputFile () const
 
void PrintUnusedLeafs (std::ostream &stream, const ::MoReFEM::Wrappers::Mpi &mpi) const
 Print the list of input data that weren't used in the program.
 
void PrintKeys (std::ostream &stream) const
 Print the complete identifiers of all the expected leaves expected in an input data tuple.
 
std::vector< std::string > ExtractKeys () const
 Extract the complete identifiers of all the expected leaves expected in an input data tuple.
 
std::vector< std::string > ComputeUnusedLeafList (const ::MoReFEM::Wrappers::Mpi &mpi) const
 Compute the list of all leaves that are in fact not used.
 
const underlying_tuple_typeGetTuple () const noexcept
 

Static Public Member Functions

static constexpr std::size_t Size ()
 Size of the tuple.
 
static constexpr std::size_t Nleaves ()
 Returns the number of leaves in the tuple.
 
template<class ItemT >
static constexpr bool Find ()
 Whether ItemT is present in the tuple or not.
 

Static Public Attributes

static constexpr bool ConceptIsInputData = true
 Helper variable to define the InputDataType concept.
 

Protected Types

using tuple_iteration = Internal::InputDataNS::TupleIteration<underlying_tuple_type, 0ul>
 Helper object to iterate upon the tuple (including the in-depth sections).
 

Protected Member Functions

template<::MoReFEM::Advanced::Concept::InputDataNS::LeafType LeafT, ::MoReFEM::InputDataNS::CountAsUsed CountAsUsedT = ::MoReFEM::InputDataNS::CountAsUsed::yes>
auto ExtractLeaf () const -> typename Utilities::ConstRefOrValue< typename LeafT::return_type >::type
 Helper function used to extract value of a leaf.
 
template<Advanced::Concept::InputDataNS::SectionType SectionT>
auto & ExtractSection () const
 Helper function used to extract a section.
 
underlying_tuple_typeGetNonCstTuple ()
 

Private Member Functions

template<::MoReFEM::Advanced::Concept::InputDataNS::LeafType LeafT>
std::filesystem::path ExtractLeafAsPath () const
 Helper function used to handle a path: it is basically handled as a mere string, except that environment variables are replaced on the fly if they respect the format ${...}.
 
void CheckUnboundInputData (const FilesystemNS::File &filename, ::MoReFEM::Wrappers::Lua::OptionFile &lua_option_file, InputDataNS::DoTrackUnusedFields do_track_unused_fields) const
 Check no input data present in the Lua file is actually not known by the input data file tuple.
 
void CheckNoDuplicateKeysInTuple () const
 Throw an exception if there is a duplicate in the keys.
 

Private Attributes

FilesystemNS::File input_data_file_
 Path of the input data file.
 
underlying_tuple_type tuple_
 The tuple that actually stores all the relevant quantities for the problem.
 

Friends

template<::MoReFEM::Advanced::Concept::InputDataNS::LeafType LeafT>
struct ::MoReFEM::Internal::InputDataNS::ExtractLeaf
 Friendship.
 
template<::MoReFEM::Advanced::Concept::InputDataNS::SectionType SectionT>
struct ::MoReFEM::Internal::InputDataNS::ExtractSection
 Friendship.
 

Detailed Description

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
class MoReFEM::InputData< TupleT, DoUpdateLuaFileT >

This class read the input data file and then is in charge of holding the values read.

It hold the charge of checking that mandatory parameters are correctly filled in the data file as soon as possible: we want for instance to avoid a program failure at the end because a path for an output file is invalid.

Template Parameters
DoUpdateLuaFileTIn the case we want to update a Lua file, we need some wiggle room (for instance we may need to load an invalid Lua file if a field no longer exists, which is forbidden in a normal run). Do not choose 'yes' except if ProgramType of your MoReFEMData class is program_type::update_lua_file.
TupleTA tuple which should include a class for each input data to consider in the file. The class for each input datum should derive from InputData::Crtp::InputData and defines several static methods such as Description(), NameInFile() or Section(). Compiler won't let you not define one of those anyway; to see an example of such a class see in Core/InputData or in MoReFEM documentation.

When a model is written, there is need to specify some data that are really specific to this model: how many meshes or finite elements spaces are involved, which unknowns are involved, what are the characteristics of a Solid involved, and so forth...

Up to v23.11.2, all these data were stored in a template class named InputData which parameter is a tuple telling which data is expected in the input file. Doing this enable a rather tight control: we could check that all the data mentioned in said input file are accounted for and are really expected, and there are also no "hidden" value that the end user may not know (said otherwise, if you tackle volumic mass of a solid the field MUST be in the input data file; there is no risk that a value is silently used).

There was however a default doing so: when defining for instance a finite element space, there is (at the time of this writing) 5 leaves to be defined in the input data file:

The problem is that the only ones that are truly expected to be modified by an end user is the shape function list (or numbering subset list in the very specific case of the Stokes model).

So to circumvent this, a new structure named ModelSettings has been introduced. Its goal is to provide a way for a model user to set the values the end user should not modify without breaking completely the infrastructure that has already been implemented for InputData.

So tu put in a nutshell, now model-related data may be stored:

Constructor & Destructor Documentation

◆ InputData() [1/3]

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
template<::MoReFEM::Concept::ModelSettingsType ModelSettingsT>
MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::InputData ( const ModelSettingsT & model_settings,
const FilesystemNS::File & filename,
InputDataNS::DoTrackUnusedFields do_track_unused_fields = InputDataNS::DoTrackUnusedFields::yes )
explicit

Special members.

Constructor.

Parameters
[in]filenameName of the Lua input data list to be read.
[in]do_track_unused_fieldsWhether a field found in the file but not referenced in the tuple yields an exception or not. Should be 'yes' most of the time; I have introduced the 'no' option for cases in which we need only a handful of parameters shared by all models for post-processing purposes (namely mesh-related ones).
Parameters
[in]model_settingsObject which hold the values of all the input data that should not be modifiable by the end user. Example (in most of the models): NumberingSubset in which an Unknown should be allotted in a FEltSpace.

◆ InputData() [2/3]

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::InputData ( const InputData< TupleT, DoUpdateLuaFileT > & rhs)
delete

The copy constructor.

Parameters
[in]rhsThe object from which the construction occurs.

◆ InputData() [3/3]

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::InputData ( InputData< TupleT, DoUpdateLuaFileT > && rhs)
delete

The move constructor.

Parameters
[in]rhsThe object from which the construction occurs.

Member Function Documentation

◆ operator=() [1/2]

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
InputData & MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::operator= ( const InputData< TupleT, DoUpdateLuaFileT > & rhs)
delete

The (copy) operator=.

Parameters
[in]rhsThe object from which the affectation occurs.
Returns
Reference to the object (to enable chained affectation).

◆ operator=() [2/2]

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
InputData & MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::operator= ( InputData< TupleT, DoUpdateLuaFileT > && rhs)
delete

The (move) operator=.

Parameters
[in]rhsThe object from which the affectation occurs.
Returns
Reference to the object (to enable chained affectation).

◆ GetInputFile()

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
const FilesystemNS::File & MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::GetInputFile ( ) const

Get the path to the input data file.

Returns
Path to the input data file.

◆ ExtractLeafAsPath()

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
template<::MoReFEM::Advanced::Concept::InputDataNS::LeafType LeafT>
std::filesystem::path MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::ExtractLeafAsPath ( ) const
private

Helper function used to handle a path: it is basically handled as a mere string, except that environment variables are replaced on the fly if they respect the format ${...}.

Warning
Contrary to what the const suggests (it is there to give the same interface whatever the string input datum is), this method might modify the value stored in the tuple. On first call all environment variables are replaced, and what is stored afterwards is the result after the substitution.

For instance "${HOME}/Codes/MoReFEM" will be resolved on a Mac in /Users/ username /Codes/MoReFEM.

Returns
The requested element in the tuple.

◆ CheckUnboundInputData()

template<Concept::Tuple TupleT, InputDataNS::do_update_lua_file DoUpdateLuaFileT = InputDataNS::do_update_lua_file::no>
void MoReFEM::InputData< TupleT, DoUpdateLuaFileT >::CheckUnboundInputData ( const FilesystemNS::File & filename,
::MoReFEM::Wrappers::Lua::OptionFile & lua_option_file,
InputDataNS::DoTrackUnusedFields do_track_unused_fields ) const
private

Check no input data present in the Lua file is actually not known by the input data file tuple.

Parameters
[in]filenamePath to the input file.
[in]lua_option_fileThe object that helps interpreting the content of the Lua file.
[in]do_track_unused_fieldsSee constructor.

◆ Nleaves()

template<::MoReFEM::Concept::Tuple TupleT>
static constexpr std::size_t MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::Nleaves ( )
staticconstexprinherited

Returns the number of leaves in the tuple.

It is not the same as size: this method explorates the sections to count how many leaves they include.

Returns
Number of leaves found.

◆ PrintUnusedLeafs()

template<::MoReFEM::Concept::Tuple TupleT>
void MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::PrintUnusedLeafs ( std::ostream & stream,
const ::MoReFEM::Wrappers::Mpi & mpi ) const
inherited

Print the list of input data that weren't used in the program.

This method is dedicated to be called at destruction, but when using OpenMPI it is rather uneasy to make it called in the destructor due to racing conditions (error if MPI_Finalize() has already been called.

So this method should be called at the very end of your program if you want the information it gives.

Parameters
[in,out]streamStream upon which object information are written. If nothing added then all input data were used.
[in]mpiMpi object which knows the rank of the processor, the total number of processors, etc...

[internal] This method collects the data from all mpi processors; the list is therefore ensured to be exhaustive.

◆ PrintKeys()

template<::MoReFEM::Concept::Tuple TupleT>
void MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::PrintKeys ( std::ostream & stream) const
inherited

Print the complete identifiers of all the expected leaves expected in an input data tuple.

An identifier being here the chaining of sections and subsections followed by the leaf name, with '.' acting as a separator.

For instance "Section1.SubsectionInSection1.LeafInSubSection1"

Parameters
[in,out]streamStream upon which object information are written.

◆ ExtractKeys()

template<::MoReFEM::Concept::Tuple TupleT>
std::vector< std::string > MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::ExtractKeys ( ) const
inherited

Extract the complete identifiers of all the expected leaves expected in an input data tuple.

An identifier being here the chaining of sections and subsections followed by the leaf name, with '.' acting as a separator.

For instance "Section1.SubsectionInSection1.LeafInSubSection1"

Returns
The list of all extracted items from the tuple.

◆ Find()

template<::MoReFEM::Concept::Tuple TupleT>
template<class ItemT >
static constexpr bool MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::Find ( )
staticconstexprinherited

Whether ItemT is present in the tuple or not.

Template Parameters
ItemTField sought in the tuple.
Returns
True if present.

◆ ComputeUnusedLeafList()

template<::MoReFEM::Concept::Tuple TupleT>
std::vector< std::string > MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::ComputeUnusedLeafList ( const ::MoReFEM::Wrappers::Mpi & mpi) const
inherited

Compute the list of all leaves that are in fact not used.

This is a rather crude indicator: a leaf is considered 'used' if Extract facility is called upon it. Leaf that are present indirectly because their enclosing section is given in the input data tuple are correctly counted.

Attention
In parallel, list is computed only on root processor. A leaf is there in this case only if it is counted as unused in all of the ranks.
Parameters
[in]mpiMpi object which knows the rank of the processor, the total number of processors, etc...
Returns
All the leafs not counted as used, sort in alphabetical order.

◆ ExtractLeaf()

template<::MoReFEM::Concept::Tuple TupleT>
template<::MoReFEM::Advanced::Concept::InputDataNS::LeafType LeafT, ::MoReFEM::InputDataNS::CountAsUsed CountAsUsedT = ::MoReFEM::InputDataNS::CountAsUsed::yes>
auto MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::ExtractLeaf ( ) const -> typename Utilities::ConstRefOrValue< typename LeafT::return_type >::type
protectedinherited

Helper function used to extract value of a leaf.

This should not be used directly by a user; ExtractLeaf class deals with it with a more user-friendly interface (no pesky template keyword to add!).

Template Parameters
AbstractClassTAbstractClass class used to store the wanted input data.
CountAsUsedTWhether the call to the methods counts as an effective use of the input parameter in the program. See CountAsUsed for more details; default value is fine in almost all cases.
Returns
The requested element in the tuple. It is either copied by value or a const reference.

◆ ExtractSection()

template<::MoReFEM::Concept::Tuple TupleT>
template<Advanced::Concept::InputDataNS::SectionType SectionT>
auto & MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::ExtractSection ( ) const
protectedinherited

Helper function used to extract a section.

Currently it is not of much use and you shouldn't have to call it; however it might be handy in the future if we need to extend the class.

Template Parameters
SectionTThe section object we which to extract.

◆ CheckNoDuplicateKeysInTuple()

template<::MoReFEM::Concept::Tuple TupleT>
void MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::CheckNoDuplicateKeysInTuple ( ) const
privateinherited

Throw an exception if there is a duplicate in the keys.

The key for an AbstractClass A class is given by free function AbstractClassKey<A>().

As these keys are what is used by OptionFile to read the value, it is important not to use the same for two parameters.

An additional bonus is that a same AbstractClass class put twice in the tuple will also trigger this exception.

◆ GetTuple()

template<::MoReFEM::Concept::Tuple TupleT>
const underlying_tuple_type & MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::GetTuple ( ) const
noexceptinherited

Accessor to the underlying tuple.

Returns
Underlying tuple.

◆ GetNonCstTuple()

template<::MoReFEM::Concept::Tuple TupleT>
underlying_tuple_type & MoReFEM::Internal::InputDataNS::AbstractClass< TupleT >::GetNonCstTuple ( )
protectedinherited

Non constant accessor to the underlying tuple.

Returns
Underlying tuple.

The documentation for this class was generated from the following file: