OGS 6.2.1-372-g67eca524a.dirty.20190919230349
anonymous_namespace{CreateComponent.cpp} Namespace Reference

Functions

std::unique_ptr< MaterialPropertyLib::ComponentcreateComponent (BaseLib::ConfigTree const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
 

Function Documentation

◆ createComponent()

std::unique_ptr<MaterialPropertyLib::Component> anonymous_namespace{CreateComponent.cpp}::createComponent ( BaseLib::ConfigTree const &  config,
std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &  parameters 
)
Input File Parameter:
prj__media__medium__phases__phase__components__component__name
Input File Parameter:
prj__media__medium__phases__phase__components__component__properties

Definition at line 23 of file CreateComponent.cpp.

References MaterialPropertyLib::createProperties(), BaseLib::ConfigTree::getConfigParameter(), BaseLib::ConfigTree::getConfigSubtreeOptional(), and OGS_FATAL.

Referenced by MaterialPropertyLib::createComponents().

26 {
27  using namespace MaterialPropertyLib;
28  // Parsing the component name
30  auto const& component_name = config.getConfigParameter<std::string>("name");
31 
32  // Check whether a name is given or not
33  if (component_name.empty())
34  {
35  OGS_FATAL("Component name is a mandatory field and cannot be empty.");
36  }
37 
38  // Parsing component properties. If a component name is given and this
39  // component is predefined in the class implementation, properties
40  // become optional. The default values of properties will be overwritten
41  // if specified.
42  std::unique_ptr<PropertyArray> properties =
44  createProperties(config.getConfigSubtreeOptional("properties"),
45  parameters);
46 
47  // If a name is given, it must conform with one of the derived component
48  // names in the following list:
49  if (boost::iequals(component_name, "water"))
50  {
51  return std::make_unique<Water>(std::move(properties));
52  }
53 
54  if (!properties)
55  {
56  // No component properties are provided. If the component is not
57  // specified, this results in a fatal error, since an unspecified
58  // component has no properties.
59  OGS_FATAL("No Properties defined for unspecified component");
60  }
61 
62  return std::make_unique<Component>(component_name, std::move(properties));
63 }
std::unique_ptr< PropertyArray > createProperties(boost::optional< BaseLib::ConfigTree > const &config, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters)
#define OGS_FATAL(fmt,...)
Definition: Error.h:64