From f0a5dad7618d674729bde7134ea7fdcd86cbf56a Mon Sep 17 00:00:00 2001
From: "Dmitry Yu. Naumov" <github@naumov.de>
Date: Tue, 1 Sep 2015 23:06:51 +0000
Subject: [PATCH] [PL] Move InitialCondition config parsing.

Remove config tree from ctor and add a createUniformInitialCondition method.
---
 ProcessLib/InitialCondition.cpp | 39 +++++++++++++++++++++++++++++++++
 ProcessLib/InitialCondition.h   | 19 +++++++---------
 ProcessLib/ProcessVariable.cpp  |  4 ++--
 3 files changed, 49 insertions(+), 13 deletions(-)
 create mode 100644 ProcessLib/InitialCondition.cpp

diff --git a/ProcessLib/InitialCondition.cpp b/ProcessLib/InitialCondition.cpp
new file mode 100644
index 00000000000..8e6bd1a75d0
--- /dev/null
+++ b/ProcessLib/InitialCondition.cpp
@@ -0,0 +1,39 @@
+/**
+ * \copyright
+ * Copyright (c) 2012-2015, 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 "InitialCondition.h"
+
+#include <boost/property_tree/ptree.hpp>
+#include <boost/optional.hpp>
+#include <logog/include/logog.hpp>
+
+#include "MathLib/Point3d.h"
+#include "MeshLib/Elements/Element.h"
+#include "MeshLib/Mesh.h"
+
+namespace ProcessLib
+{
+using ConfigTree = boost::property_tree::ptree;
+
+std::unique_ptr<InitialCondition> createUniformInitialCondition(
+    ConfigTree const& config)
+{
+	auto value = config.get_optional<double>("value");
+	if (!value)
+	{
+		ERR("Could not find required parameter value.");
+		std::abort();
+	}
+	DBUG("Using value %g", *value);
+
+	return std::unique_ptr<InitialCondition>(
+	    new UniformInitialCondition(*value));
+}
+
+}  // namespace ProcessLib
diff --git a/ProcessLib/InitialCondition.h b/ProcessLib/InitialCondition.h
index 02a49728f97..8833a680b12 100644
--- a/ProcessLib/InitialCondition.h
+++ b/ProcessLib/InitialCondition.h
@@ -10,11 +10,9 @@
 #ifndef PROCESS_LIB_INITIAL_CONDITION_H_
 #define PROCESS_LIB_INITIAL_CONDITION_H_
 
-#include <boost/property_tree/ptree.hpp>
-#include "logog/include/logog.hpp"
-
-#include "MeshLib/Mesh.h"
+#include <boost/property_tree/ptree_fwd.hpp>
 #include "MeshLib/Node.h"
+#include "MeshLib/PropertyVector.h"
 
 namespace ProcessLib
 {
@@ -30,15 +28,9 @@ public:
 /// Uniform value initial condition
 class UniformInitialCondition : public InitialCondition
 {
-	using ConfigTree = boost::property_tree::ptree;
-
 public:
-	UniformInitialCondition(ConfigTree const& config)
+	UniformInitialCondition(double const value) : _value(value)
 	{
-		DBUG("Constructing Uniform initial condition");
-
-		_value = config.get<double>("value", 0);
-		DBUG("Read value %g", _value);
 	}
 
 	virtual double getValue(MeshLib::Node const&) const override
@@ -50,6 +42,11 @@ private:
 	double _value;
 };
 
+using ConfigTree = boost::property_tree::ptree;
+/// Construct a UniformInitialCondition from configuration.
+std::unique_ptr<InitialCondition> createUniformInitialCondition(
+    ConfigTree const& config);
+
 }  // namespace ProcessLib
 
 #endif  // PROCESS_LIB_INITIAL_CONDITION_H_
diff --git a/ProcessLib/ProcessVariable.cpp b/ProcessLib/ProcessVariable.cpp
index 08862373000..0c142c02f6d 100644
--- a/ProcessLib/ProcessVariable.cpp
+++ b/ProcessLib/ProcessVariable.cpp
@@ -37,8 +37,8 @@ ProcessVariable::ProcessVariable(ConfigTree const& config,
 		    config.get<std::string>("initial_condition.type");
 		if (type == "Uniform")
 		{
-			_initial_condition.reset(
-			    new UniformInitialCondition(ic_config->second));
+			_initial_condition =
+			    createUniformInitialCondition(ic_config->second);
 		}
 		else
 		{
-- 
GitLab