Skip to content
Snippets Groups Projects
Commit 2eed8779 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

[PL] Move getting of mesh property in process var.

parent 2fec8952
Branches
Tags
No related merge requests found
...@@ -272,31 +272,11 @@ private: ...@@ -272,31 +272,11 @@ private:
_x->copyValues(x_copy); _x->copyValues(x_copy);
std::size_t const n = _mesh.getNNodes(); std::size_t const n = _mesh.getNNodes();
for (ProcessVariable const& pv : _process_variables) for (ProcessVariable& pv : _process_variables)
{
std::string const property_name = pv.getName();
// Get or create a property vector for results.
boost::optional<MeshLib::PropertyVector<double>&> result;
if (_mesh.getProperties().hasPropertyVector(property_name))
{
result =
_mesh.getProperties().template getPropertyVector<double>(
property_name);
}
else
{ {
result = _mesh.getProperties() auto& output_data = pv.getOrCreateMeshProperty();
.template createNewPropertyVector<double>(
property_name, MeshLib::MeshItemType::Node);
}
assert(result);
int const n_components = pv.getTupleSize(); int const n_components = pv.getTupleSize();
// result's resize function is from std::vector not accounting the
// tuple size.
result->resize(x_copy.size() * n_components);
for (std::size_t i = 0; i < n; ++i) for (std::size_t i = 0; i < n; ++i)
{ {
MeshLib::Location const l(_mesh.getID(), MeshLib::Location const l(_mesh.getID(),
......
...@@ -114,4 +114,24 @@ MeshLib::Mesh const& ProcessVariable::getMesh() const ...@@ -114,4 +114,24 @@ MeshLib::Mesh const& ProcessVariable::getMesh() const
return _mesh; return _mesh;
} }
MeshLib::PropertyVector<double>& ProcessVariable::getOrCreateMeshProperty()
{
boost::optional<MeshLib::PropertyVector<double>&> result;
if (_mesh.getProperties().hasPropertyVector(_name))
{
result =
_mesh.getProperties().template getPropertyVector<double>(_name);
assert(result);
assert(result->size() == _mesh.getNNodes() * _tuple_size);
}
else
{
result = _mesh.getProperties().template createNewPropertyVector<double>(
_name, MeshLib::MeshItemType::Node);
assert(result);
result->resize(_mesh.getNNodes() * _tuple_size);
}
return *result;
}
} // namespace ProcessLib } // namespace ProcessLib
...@@ -96,6 +96,10 @@ public: ...@@ -96,6 +96,10 @@ public:
return _initial_condition->getValue(n, component_id); return _initial_condition->getValue(n, component_id);
} }
// Get or create a property vector for results.
// The returned mesh property size is number of mesh nodes times tuple size.
MeshLib::PropertyVector<double>& getOrCreateMeshProperty();
private: private:
std::string const _name; std::string const _name;
MeshLib::Mesh& _mesh; MeshLib::Mesh& _mesh;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment