Skip to content
Snippets Groups Projects
Commit 8b6da9cc authored by Christoph Lehmann's avatar Christoph Lehmann
Browse files

[PL] separate files for specific parameter implementations

parent a406436e
No related branches found
No related tags found
No related merge requests found
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "ConstantParameter.h"
#include <logog/include/logog.hpp>
#include "BaseLib/ConfigTree.h"
namespace ProcessLib
{
std::unique_ptr<ParameterBase> createConstantParameter(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{parameter__type}
config.checkConfigParameter("type", "Constant");
//! \ogs_file_param{parameter__Constant__value}
auto value = config.getConfigParameter<double>("value");
DBUG("Using value %g", value);
return std::unique_ptr<ParameterBase>(new ConstantParameter<double>(value));
}
} // ProcessLib
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef PROCESSLIB_CONSTANTPARAMETER_H
#define PROCESSLIB_CONSTANTPARAMETER_H
#include "Parameter.h"
namespace ProcessLib
{
/// Single, constant value parameter.
template <typename T>
struct ConstantParameter final : public Parameter<T> {
ConstantParameter(T const& value) : _value{{value}} {}
std::vector<T> const& getTuple(
double const /*t*/, SpatialPosition const& /*pos*/) const override
{
return _value;
}
private:
std::vector<T> _value;
};
std::unique_ptr<ParameterBase> createConstantParameter(
BaseLib::ConfigTree const& config);
} // ProcessLib
#endif // PROCESSLIB_CONSTANTPARAMETER_H
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#include "MeshElementParameter.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "MeshLib/Mesh.h"
namespace ProcessLib
{
std::unique_ptr<ParameterBase> createMeshElementParameter(
BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh)
{
//! \ogs_file_param{parameter__type}
config.checkConfigParameter("type", "MeshProperty");
//! \ogs_file_param{parameter__MeshProperty__field_name}
auto field_name = config.getConfigParameter<std::string>("field_name");
DBUG("Using field_name %s", field_name.c_str());
if (!mesh.getProperties().hasPropertyVector(field_name)) {
OGS_FATAL("The required property %s does not exists in the mesh.",
field_name.c_str());
}
// TODO other data types than only double
auto const& property =
mesh.getProperties().template getPropertyVector<double>(field_name);
if (!property) {
OGS_FATAL("The required property %s is not of the requested type.",
field_name.c_str());
}
return std::unique_ptr<ParameterBase>(
new MeshElementParameter<double>(*property));
}
} // ProcessLib
/**
* \copyright
* Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*
*/
#ifndef PROCESSLIB_MESHELEMENTPARAMETER_H
#define PROCESSLIB_MESHELEMENTPARAMETER_H
#include "Parameter.h"
namespace MeshLib
{
template <typename T>
class PropertyVector;
} // MeshLib
namespace ProcessLib
{
/// A parameter represented by a mesh property vector.
template <typename T>
struct MeshElementParameter final : public Parameter<T> {
MeshElementParameter(MeshLib::PropertyVector<T> const& property)
: _property(property)
{
}
std::vector<T> const& getTuple(double const /*t*/,
SpatialPosition const& pos) const override
{
auto const e = pos.getElementID();
assert(e);
_cache.front() = _property[*e];
return _cache;
}
private:
MeshLib::PropertyVector<T> const& _property;
// TODO multi-component
mutable std::vector<double> _cache = std::vector<double>(1);
};
std::unique_ptr<ParameterBase> createMeshElementParameter(
BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh);
} // ProcessLib
#endif // PROCESSLIB_MESHELEMENTPARAMETER_H
...@@ -8,50 +8,44 @@ ...@@ -8,50 +8,44 @@
*/ */
#include "Parameter.h" #include "Parameter.h"
#include "BaseLib/ConfigTree.h"
#include <boost/optional.hpp>
#include <logog/include/logog.hpp>
#include "BaseLib/Error.h" #include "BaseLib/Error.h"
#include "MeshLib/Elements/Element.h"
#include "ConstantParameter.h"
#include "MeshElementParameter.h"
namespace ProcessLib namespace ProcessLib
{ {
std::unique_ptr<ParameterBase> createConstParameter(
BaseLib::ConfigTree const& config)
{
//! \ogs_file_param{parameter__type}
config.checkConfigParameter("type", "Constant");
//! \ogs_file_param{parameter__Constant__value}
auto value = config.getConfigParameter<double>("value");
DBUG("Using value %g", value);
return std::unique_ptr<ParameterBase>(new ConstParameter<double>(value));
}
std::unique_ptr<ParameterBase> createMeshPropertyParameter( std::unique_ptr<ParameterBase> createParameter(
BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh) BaseLib::ConfigTree const& config, std::vector<MeshLib::Mesh*> const& meshes)
{ {
//! \ogs_file_param{parameter__name}
auto name = config.getConfigParameter<std::string>("name");
//! \ogs_file_param{parameter__type} //! \ogs_file_param{parameter__type}
config.checkConfigParameter("type", "MeshProperty"); auto type = config.peekConfigParameter<std::string>("type");
//! \ogs_file_param{parameter__MeshProperty__field_name}
auto field_name = config.getConfigParameter<std::string>("field_name");
DBUG("Using field_name %s", field_name.c_str());
if (!mesh.getProperties().hasPropertyVector(field_name)) // Create parameter based on the provided type.
if (type == "Constant")
{ {
OGS_FATAL("The required property %s does not exists in the mesh.", INFO("ConstantParameter: %s", name.c_str());
field_name.c_str()); auto param = createConstantParameter(config);
param->name = name;
return param;
} }
auto const& property = else if (type == "MeshElement")
mesh.getProperties().template getPropertyVector<double>(field_name);
if (!property)
{ {
OGS_FATAL("The required property %s is not of the requested type.", INFO("MeshElementParameter: %s", name.c_str());
field_name.c_str()); auto param = createMeshElementParameter(config, *meshes.front());
param->name = name;
return param;
}
else
{
OGS_FATAL("Cannot construct property of given type \'%s\'.",
type.c_str());
} }
return std::unique_ptr<ParameterBase>(
new MeshElementParameter<double>(*property));
} }
} // namespace ProcessLib
} // ProcessLib
...@@ -11,19 +11,18 @@ ...@@ -11,19 +11,18 @@
#define PROCESS_LIB_PARAMETER_H_ #define PROCESS_LIB_PARAMETER_H_
#include <memory> #include <memory>
#include <vector>
#include <logog/include/logog.hpp>
#include <boost/optional.hpp>
#include "BaseLib/ConfigTree.h"
#include "MeshLib/Elements/Element.h"
#include "SpatialPosition.h" #include "SpatialPosition.h"
namespace BaseLib
{
class ConfigTree;
} // BaseLib
namespace MeshLib namespace MeshLib
{ {
template <typename T> class Mesh;
class PropertyVector; } // MeshLib
}
namespace ProcessLib namespace ProcessLib
{ {
...@@ -47,48 +46,9 @@ struct Parameter : public ParameterBase ...@@ -47,48 +46,9 @@ struct Parameter : public ParameterBase
double const t, SpatialPosition const& pos) const = 0; double const t, SpatialPosition const& pos) const = 0;
}; };
/// Single, constant value parameter. std::unique_ptr<ParameterBase> createParameter(
template <typename T> BaseLib::ConfigTree const& config,
struct ConstParameter final : public Parameter<T> { const std::vector<MeshLib::Mesh*>& meshes);
ConstParameter(T const& value) : _value{{value}} {}
std::vector<T> const& getTuple(
double const /*t*/, SpatialPosition const& /*pos*/) const override
{
return _value;
}
private:
std::vector<T> _value;
};
std::unique_ptr<ParameterBase> createConstParameter(BaseLib::ConfigTree const& config);
/// A parameter represented by a mesh property vector.
template <typename T>
struct MeshElementParameter final
: public Parameter<T>
{
MeshElementParameter(MeshLib::PropertyVector<T> const& property)
: _property(property)
{
}
std::vector<T> const& getTuple(
double const /*t*/, SpatialPosition const& pos) const override
{
auto const e = pos.getElementID();
assert(e);
_cache.front() = _property[*e];
return _cache;
}
private:
MeshLib::PropertyVector<T> const& _property;
// TODO multi-component
mutable std::vector<double> _cache = std::vector<double>(1);
};
std::unique_ptr<ParameterBase> createMeshPropertyParameter(BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh);
} // namespace ProcessLib } // namespace ProcessLib
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment