diff --git a/Applications/ApplicationsLib/ProjectData.cpp b/Applications/ApplicationsLib/ProjectData.cpp index fc71924b38c..58cf4244c20 100644 --- a/Applications/ApplicationsLib/ProjectData.cpp +++ b/Applications/ApplicationsLib/ProjectData.cpp @@ -21,6 +21,7 @@ #include "BaseLib/FileTools.h" #include "BaseLib/uniqueInsert.h" +#include "MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h" #include "MeshLib/Mesh.h" #include "NumLib/ODESolver/TimeDiscretizationBuilder.h" @@ -72,8 +73,10 @@ ProjectData::ProjectData(BaseLib::ConfigTree const& project_config, } _mesh_vec.push_back(mesh); - // process variables + // curves + parseCurves(project_config.getConfSubtreeOptional("curves")); + // process variables parseProcessVariables(project_config.getConfSubtree("process_variables")); // parameters @@ -352,3 +355,42 @@ void ProjectData::parseNonlinearSolvers(BaseLib::ConfigTree const& config) "The nonlinear solver name is not unique"); } } + +static std::unique_ptr +createPiecewiseLinearInterpolation(BaseLib::ConfigTree const& config) +{ + auto coords = config.getConfParam>("coords"); + auto values = config.getConfParam>("values"); + if (coords.empty() || values.empty()) + { + ERR("The given co-ordinates or values vector is empty."); + std::abort(); + } + if (coords.size() != values.size()) + { + ERR("The given co-ordinates and values vector sizes are different."); + std::abort(); + } + + return std::unique_ptr{ + new MathLib::PiecewiseLinearInterpolation{std::move(coords), + std::move(values)}}; +} + +void ProjectData::parseCurves( + boost::optional const& config) +{ + if (!config) return; + + DBUG("Reading curves configuration."); + + for (auto conf : config->getConfSubtreeList("curve")) + { + auto const name = conf.getConfParam("name"); + BaseLib::insertIfKeyUniqueElseError( + _curves, + name, + createPiecewiseLinearInterpolation(conf), + "The curve name is not unique."); + } +} diff --git a/Applications/ApplicationsLib/ProjectData.h b/Applications/ApplicationsLib/ProjectData.h index 2082ed79d5f..f9912e094bd 100644 --- a/Applications/ApplicationsLib/ProjectData.h +++ b/Applications/ApplicationsLib/ProjectData.h @@ -13,7 +13,10 @@ #ifndef PROJECTDATA_H_ #define PROJECTDATA_H_ +#include #include +#include +#include #include "BaseLib/ConfigTree.h" @@ -26,6 +29,9 @@ #include "NumLib/ODESolver/Types.h" +namespace MathLib { + class PiecewiseLinearInterpolation; +} namespace MeshLib { class Mesh; } @@ -193,6 +199,8 @@ class ProjectData final void parseNonlinearSolvers(BaseLib::ConfigTree const& config); + void parseCurves(boost::optional const& config); + private: GeoLib::GEOObjects *_geoObjects = new GeoLib::GEOObjects(); std::vector _mesh_vec; @@ -216,6 +224,8 @@ class ProjectData final using NonlinearSolver = NumLib::NonlinearSolverBase; std::map > _nonlinear_solvers; + std::map> _curves; }; #endif //PROJECTDATA_H_ diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp index 74c8b5ac8bd..6444ca85d27 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp @@ -13,6 +13,7 @@ */ #include #include +#include #include "PiecewiseLinearInterpolation.h" @@ -20,10 +21,12 @@ namespace MathLib { -PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, - bool supp_pnts_sorted) : - _supp_pnts(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) +PiecewiseLinearInterpolation::PiecewiseLinearInterpolation( + std::vector&& supporting_points, + std::vector&& values_at_supp_pnts, + bool supp_pnts_sorted) + : _supp_pnts(std::move(supporting_points)), + _values_at_supp_pnts(std::move(values_at_supp_pnts)) { if (!supp_pnts_sorted) { BaseLib::quicksort(_supp_pnts, static_cast (0), @@ -31,28 +34,6 @@ PiecewiseLinearInterpolation::PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, - const std::vector& points_to_interpolate, - std::vector& values_at_interpol_pnts, - bool supp_pnts_sorted) : - _supp_pnts(supporting_points), _values_at_supp_pnts(values_at_supp_pnts) -{ - if (!supp_pnts_sorted) { - BaseLib::quicksort(_supp_pnts, static_cast (0), - _supp_pnts.size(), - _values_at_supp_pnts); - } - - values_at_interpol_pnts.resize(points_to_interpolate.size()); - std::transform(points_to_interpolate.begin(), points_to_interpolate.end(), - values_at_interpol_pnts.begin(), - [&](double const& p) { return this->getValue(p); } ); -} - -PiecewiseLinearInterpolation::~PiecewiseLinearInterpolation() -{} - double PiecewiseLinearInterpolation::getValue(double pnt_to_interpolate) const { // search interval that has the point inside diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h index 6941d54460b..81136e6eb73 100644 --- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h +++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.h @@ -22,7 +22,7 @@ namespace MathLib /** * This class implements a one dimensional piecewise linear interpolation algorithm. */ -class PiecewiseLinearInterpolation +class PiecewiseLinearInterpolation final { public: /** @@ -44,28 +44,9 @@ class PiecewiseLinearInterpolation * @param supp_pnts_sorted false (default), if it is sure the supporting points are sorted * one can set the switch to true */ - PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, + PiecewiseLinearInterpolation(std::vector&& supporting_points, + std::vector&& values_at_supp_pnts, bool supp_pnts_sorted = false); - /** - * The same requirements on the input vectors supporting_points and values_at_supp_pnts - * have to apply as for the previous constructor. - * @param supporting_points vector of supporting points - * @param values_at_supp_pnts vector of values at the supporting points - * @param points_to_interpolate The points should be located within the range - * \f$[x_{\min}, x_{\max}]\f$, where \f$x_{\min} = \min_{1 \le j \le n} x_j\f$ and - * \f$x_{\max} = \max_{1 \le j \le n} x_j\f$. Points outside of this interval are extrapolated. - * @param values_at_interpol_pnts The interpolated values corresponding to the entries - * of the vector points_to_interpolate. - * @param supp_pnts_sorted Is set to false per default. If it is sure that the supporting - * points are sorted one can set the switch to true. - */ - PiecewiseLinearInterpolation(const std::vector& supporting_points, - const std::vector& values_at_supp_pnts, - const std::vector& points_to_interpolate, - std::vector& values_at_interpol_pnts, - bool supp_pnts_sorted = false); - virtual ~PiecewiseLinearInterpolation(); /** * \brief Calculates the interpolation value. diff --git a/NumLib/Function/LinearInterpolationAlongPolyline.cpp b/NumLib/Function/LinearInterpolationAlongPolyline.cpp index a9ad05c2ce6..115978a9bbc 100644 --- a/NumLib/Function/LinearInterpolationAlongPolyline.cpp +++ b/NumLib/Function/LinearInterpolationAlongPolyline.cpp @@ -55,7 +55,8 @@ MathLib::PiecewiseLinearInterpolation LinearInterpolationAlongPolyline::createIn } } - return MathLib::PiecewiseLinearInterpolation(vec_known_dist, vec_known_values); + return MathLib::PiecewiseLinearInterpolation{std::move(vec_known_dist), + std::move(vec_known_values)}; } double LinearInterpolationAlongPolyline::operator()(const MathLib::Point3d& pnt) const diff --git a/Tests/MathLib/TestPiecewiseLinearInterpolation.cpp b/Tests/MathLib/TestPiecewiseLinearInterpolation.cpp index e6fdbfc22f7..2d65607999a 100644 --- a/Tests/MathLib/TestPiecewiseLinearInterpolation.cpp +++ b/Tests/MathLib/TestPiecewiseLinearInterpolation.cpp @@ -32,7 +32,8 @@ TEST(MathLibInterpolationAlgorithms, PiecewiseLinearInterpolation) } } - MathLib::PiecewiseLinearInterpolation interpolation(supp_pnts, values); + MathLib::PiecewiseLinearInterpolation interpolation{std::move(supp_pnts), + std::move(values)}; // Interpolation for (std::size_t k(0); k::epsilon()); @@ -67,7 +68,8 @@ TEST(MathLibInterpolationAlgorithms, PiecewiseLinearInterpolationSupportPntsInRe } } - MathLib::PiecewiseLinearInterpolation interpolation(supp_pnts, values); + MathLib::PiecewiseLinearInterpolation interpolation{std::move(supp_pnts), + std::move(values)}; // Interpolation for (std::size_t k(0); k::epsilon());