Flow123d  JS_before_hm-2208-gb971e62bf
Input Classes

Overview of data input classes

We assume that the input data of the program can be represented by a tree. The leave nodes of the tree contain actual data and has one of the 'scalar' types represented by the classes in Input::Type namespace : Bool, Integer, Double, String, and FileName. The branching nodes of the input tree can be either of type Array or type Record (or Abstract). Classes derived from Input::Type::TypeBase only describes structure of the input tree which is independent of actual format of the input data. All nodes of tree allows definition of input attributes, which are optional for every node. Base attributes are defined in Input::Type::Attributes, special attributes of Flow123D in FlowAttributes. These structures contain common attributes, user can define other else.

Instances of the classes from the Input::Type namespace form a declaration-tree that is later used by a reader of the particular file format (currently we support YAML and JSON through the Input::ReaderToStorage reader) to interpret the input data, check its structure, possibly use default values and put the raw data into an intermediate storage-tree formed be Input:Storage classes.

Finally, the data are accessible through accessors Input::Record, Input::Array, and Input::AbstractRecord. These accessors holds pointers into declaration tree as well as into the data storage tree and provides unified access to the data.

Furthermore, the declaration-tree can output itself provided a basic documentation of the input data structure, that is consistent with the actual state.

Here is simple scheme of information exchange between classes:

Practical usage

In order to use input interface you have to create declaration-tree, namely Selection, Record, and Abstract types has to be declared by specification of its keys. We suggest to have a static method that returns Input::Type::Record for ever class which is initialized from input interface. Example of usage follows:

class Mesh {
using namespace Input::Type;
return Record("Mesh", "Full description of computational mesh.")
.declare_key("mesh_name", String(), Default::optional(),"Optional name of the mesh")
.declare_key("mesh_file", FileName::input(), Default("mesh.msh"), "Principial mesh input file")
.declare_key("materials_to_remove", Array(Integer()), "Removes elements with material ID that appears in this list.")
.close();
}
: name( input.val<string>("mesh_name") )
{
string fname = input.val<FilePath>("mesh_file");
boundary = new Boundary( input.val<Input::Record>("boundary") );
std::vector<int> ids_to_remove;
input.val<Input::Array>("materials_to_remove").copy_to( ids_to_remove );
}
}

The accessor for the root Input::Record is provided by the reader class ( ReaderToStorage.get_root_interface<>() )

Input::Type::Integer
Class for declaration of the integral input data.
Definition: type_base.hh:483
Input::Record::val
const Ret val(const string &key) const
Definition: accessors_impl.hh:31
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
Mesh::get_input_type
static const Input::Type::Record & get_input_type()
Definition: mesh.cc:213
Mesh::boundary
Boundary boundary(uint edge_idx) const override
Definition: mesh.cc:328
std::vector< int >
Input::Type::Default
Class Input::Type::Default specifies default value of keys of a Input::Type::Record.
Definition: type_record.hh:61
Input::Record
Accessor to the data with type Type::Record.
Definition: accessors.hh:291
Input::Type::Record::declare_key
Record & declare_key(const string &key, std::shared_ptr< TypeBase > type, const Default &default_value, const string &description, TypeBase::attribute_map key_attributes=TypeBase::attribute_map())
Declares a new key of the Record.
Definition: type_record.cc:503
Input::Type::Record::close
Record & close() const
Close the Record for further declarations of keys.
Definition: type_record.cc:304
Input::Type
Definition: balance.hh:41
Input::Type::Record
Record type proxy class.
Definition: type_record.hh:182
Mesh
Definition: mesh.h:355
Input::Type::Array
Class for declaration of inputs sequences.
Definition: type_base.hh:339
Input::Type::String
Class for declaration of the input data that are in string format.
Definition: type_base.hh:582
Input::Array
Accessor to input data conforming to declared Array.
Definition: accessors.hh:566
Mesh::Mesh
Mesh()
Definition: mesh.cc:239
Mesh::Boundary
friend class Boundary
Definition: mesh.h:684