-
Notifications
You must be signed in to change notification settings - Fork 7
config
The run of all tools is controlled by a configuration tree. The tree is built from structures when a tool is started. Each structure that is a part of the configuration tree must inherit from ECFDescription
that contains a holder for structure's metadata and must define the constructor that correctly sets these metadata. Metadata are used during reading of Example Configuration File (ecf) that can be used for the library configuration. Relation between configuration structures and ecf file is described by the following code:
struct Options: public ECFDescription {
int ivalue;
double dvalue;
std::map<std::string, int> map;
Options();
}
struct LibrarySettings: public ECFDescription {
ECFExpression exp;
Options options;
LibrarySettings();
}
LIBRARY_SETTINGS {
EXP 10 * std::sqrt(COORDINATE_X * COORDINATE_Y);
OPTIONS {
IVALUE 10;
DVALUE .5;
MAP {
REGION1 10;
REGION2 20;
}
}
}
The above simple example contains library settings with an expression parameter and several options. The options are wrapped inside another structure. According to the above classes is then generated the above ecf file. The structures inside the code are reflected by the structures inside the ecf file. Values inside the ecf file are parsed according to the data types defined inside constructors. The code below shows a possible implementation of the above structures constructors:
Options::Options()
{
REGISTER(ivalue, ECFMetaData()
.setdescription({ "Integer parameter." })
.setdatatype({ ECFDataType::POSITIVE_INTEGER }));
REGISTER(dvalue, ECFMetaData()
.setdescription({ "Double parameter." })
.setdatatype({ ECFDataType::FLOAT }));
REGISTER(map, ECFMetaData()
.setdescription({ "Map first argument description.", "Map second argument description." })
.setdatatype({ ECFDataType::ELEMENT_REGION, ECFDataType::INTEGER })
.setpattern({ "REGION", "REGION_VALUE" }));
}
LibrarySettings::LibrarySettings()
{
REGISTER(exp, ECFMetaData()
.setdescription({ "Expression parameter." })
.setdatatype({ ECFDataType::EXPRESSION }));
REGISTER(options, ECFMetaData()
.setdescription({ "Another options." }));
}
All parameters that should be visible (and readable) in an ecf file should be registered by macro REGISTER
. This macro accepts two parameters - a parameter and its metadata. The parameter inside the macro is used for setting of the parameter's name as #parameter
. Metadata are used for configuration of the parameter attributes. Allowed attributes are located in src/config/metadata.h
. The following code shows allowed data types and examples how to configure commonly used parameters:
enum class ECFDataType {
BOOL,
STRING,
INTEGER,
POSITIVE_INTEGER,
NONNEGATIVE_INTEGER,
FLOAT,
ENUM_FLAGS,
OPTION,
REGION,
BOUNDARY_REGION,
ELEMENTS_REGION,
MATERIAL,
LOAD_STEP,
EXPRESSION,
TENSOR,
INTERVAL,
SPACE,
SEPARATOR,
BEGINBLOCK,
ENDBLOCK,
BEGINCOLLAPSEBLOCK
};
Configuration::Configuration()
{
// integer value
REGISTER(ivalue, ECFMetaData()
.setdescription({ "Integer parameter." })
.setdatatype({ ECFDataType::POSITIVE_INTEGER })); //
// double value
REGISTER(dvalue, ECFMetaData()
.setdescription({ "Integer parameter." })
.setdatatype({ ECFDataType::FLOAT }));
// std::map<std::string, STRUCT> map
REGISTER(map, ECFMetaData()
.setdescription({ "Settings for each load step", "LoadStep" })
.setdatatype({ ECFDataType::LOAD_STEP });
// std::map<std::string, ECFExpression> temperature
REGISTER(temperature, ECFMetaData()
.setdescription({ "The name of a region.", "Temperature" })
.setdatatype({ ECFDataType::BOUNDARY_REGION, ECFDataType::EXPRESSION })
.setpattern({ "MY_REGION", "273.15" }),
ECFMetaData::getboundaryconditionvariables()); // set allowed parameters inside the expression
// enum class OPTION { OPT1, OPT2, OPT3 };
// OPTION options;
option = OPTION::OPT1;
REGISTER(option, ECFMetaData()
.setdescription({ "Option paramters." })
.setdatatype({ ECFDataType::OPTION })
.addoption(ECFOption().setname("OPT1").setdescription("Option 1."))
.addoption(ECFOption().setname("OPT2").setdescription("Option 2."))
.addoption(ECFOption().setname("OPT3").setdescription("Option 3.")));
}