OGS 6.2.2-330-gf48c72f61.dirty.20200225212913
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, ParameterLib::CoordinateSystem const *const local_coordinate_system)
 

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,
ParameterLib::CoordinateSystem const *const  local_coordinate_system 
)
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().

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