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

[PL] added mesh node parameter

parent 04a20e3b
No related branches found
No related tags found
No related merge requests found
......@@ -18,8 +18,8 @@ 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}
config.checkConfigParameter("type", "MeshElement");
//! \ogs_file_param{parameter__MeshElement__field_name}
auto field_name = config.getConfigParameter<std::string>("field_name");
DBUG("Using field_name %s", field_name.c_str());
......
/**
* \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 "MeshNodeParameter.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "MeshLib/Mesh.h"
namespace ProcessLib
{
std::unique_ptr<ParameterBase> createMeshNodeParameter(
BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh)
{
//! \ogs_file_param{parameter__type}
config.checkConfigParameter("type", "MeshNode");
//! \ogs_file_param{parameter__MeshNode__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 mesh property `%s' is not of the requested type.",
field_name.c_str());
}
if (property->getMeshItemType() != MeshLib::MeshItemType::Node) {
OGS_FATAL("The mesh property `%s' is not a nodal property.",
field_name.c_str());
}
return std::unique_ptr<ParameterBase>(
new MeshNodeParameter<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_MESHNODEPARAMETER_H
#define PROCESSLIB_MESHNODEPARAMETER_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 MeshNodeParameter final : public Parameter<T> {
MeshNodeParameter(MeshLib::PropertyVector<T> const& property)
: _property(property)
, _cache(_property.getNumberOfComponents())
{
}
unsigned getNumberOfComponents() const override
{
return _property.getNumberOfComponents();
}
std::vector<T> const& getTuple(double const /*t*/,
SpatialPosition const& pos) const override
{
auto const e = pos.getNodeID();
assert(e);
auto const num_comp = _property.getNumberOfComponents();
for (std::size_t c=0; c<num_comp; ++c) {
_cache[c] = _property.getComponent(*e, c);
}
return _cache;
}
private:
MeshLib::PropertyVector<T> const& _property;
mutable std::vector<double> _cache;
};
std::unique_ptr<ParameterBase> createMeshNodeParameter(
BaseLib::ConfigTree const& config, MeshLib::Mesh const& mesh);
} // ProcessLib
#endif // PROCESSLIB_MESHNODEPARAMETER_H
......@@ -13,6 +13,7 @@
#include "ConstantParameter.h"
#include "MeshElementParameter.h"
#include "MeshNodeParameter.h"
namespace ProcessLib
{
......@@ -41,6 +42,13 @@ std::unique_ptr<ParameterBase> createParameter(
param->name = name;
return param;
}
else if (type == "MeshNode")
{
INFO("MeshElementParameter: %s", name.c_str());
auto param = createMeshNodeParameter(config, *meshes.front());
param->name = name;
return param;
}
else
{
OGS_FATAL("Cannot construct property of given type \'%s\'.",
......
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