From 2eed87797e8cfbbf4698f481c743ccc4a1e67b09 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Fri, 12 Feb 2016 18:17:01 +0100
Subject: [PATCH] [PL] Move getting of mesh property in process var.

---
 ProcessLib/Process.h           | 24 ++----------------------
 ProcessLib/ProcessVariable.cpp | 20 ++++++++++++++++++++
 ProcessLib/ProcessVariable.h   |  4 ++++
 3 files changed, 26 insertions(+), 22 deletions(-)

diff --git a/ProcessLib/Process.h b/ProcessLib/Process.h
index cd1c68436b8..338e893307b 100644
--- a/ProcessLib/Process.h
+++ b/ProcessLib/Process.h
@@ -272,31 +272,11 @@ private:
 		_x->copyValues(x_copy);
 
 		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()
-				             .template createNewPropertyVector<double>(
-				                 property_name, MeshLib::MeshItemType::Node);
-			}
-
-			assert(result);
+			auto& output_data = pv.getOrCreateMeshProperty();
 
 			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)
 			{
 				MeshLib::Location const l(_mesh.getID(),
diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp
index 3f9d64a5eb8..a59717318fe 100644
--- a/ProcessLib/ProcessVariable.cpp
+++ b/ProcessLib/ProcessVariable.cpp
@@ -114,4 +114,24 @@ MeshLib::Mesh const& ProcessVariable::getMesh() const
 	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
diff --git a/ProcessLib/ProcessVariable.h b/ProcessLib/ProcessVariable.h
index 3efe3671772..6e16f4df674 100644
--- a/ProcessLib/ProcessVariable.h
+++ b/ProcessLib/ProcessVariable.h
@@ -96,6 +96,10 @@ public:
 		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:
 	std::string const _name;
 	MeshLib::Mesh& _mesh;
-- 
GitLab