From 0d8641a290b3259aec00d425dbb4677d3d880856 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 16 Aug 2001 11:03:24 +0000 Subject: [PATCH] Think about using global std::vector objects in the value_list function, in order to avoid repeated memory allocation for these objects. However, no way springs to mind as apparent, basically because the length of these vectors depends on the number of points at which the derivative is to be computed, which may vary between successive calls to the function and we don't want to grow the vectors beyond all bounds if once many points are required and usually only a few. Nevertheless, clean up some things... git-svn-id: https://svn.dealii.org/trunk@4884 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/source/function_derivative.cc | 110 +++++++++++++-------- 1 file changed, 67 insertions(+), 43 deletions(-) diff --git a/deal.II/base/source/function_derivative.cc b/deal.II/base/source/function_derivative.cc index a78ab3a6f3..5b7f940164 100644 --- a/deal.II/base/source/function_derivative.cc +++ b/deal.II/base/source/function_derivative.cc @@ -56,6 +56,8 @@ FunctionDerivative::set_formula (DifferenceFormula form) formula = form; } + + template double FunctionDerivative::value (const Point &p, @@ -86,10 +88,7 @@ FunctionDerivative::value (const Point &p, using namespace std; #endif -//TODO:[WB] Optimize construction of vectors thread-safe -// Right now, vectors are allocated each time value_list is called. -// This costs a lot of time and should be replaced by a static object, -// but that would not be thread-safe anymore. + template void @@ -98,7 +97,7 @@ FunctionDerivative::value_list (const typename std::vector > &po const unsigned int component) const { const unsigned int n = points.size(); - bool variable_direction = (incr.size() == 1) ? false : true; + const bool variable_direction = (incr.size() == 1) ? false : true; if (variable_direction) Assert (incr.size() == points.size(), ExcDimensionMismatch(incr.size(), points.size())); @@ -107,65 +106,88 @@ FunctionDerivative::value_list (const typename std::vector > &po { case Euler: { - std::vector > p1(n); - std::vector > p2(n); - std::vector e2(n); - for (unsigned int i=0;i > p1 = points; + std::vector > p2 = points; + + for (unsigned int i=0; i values2(n); + f.value_list(p1, values, component); + f.value_list(p2, values2, component); + + // finally compute finite + // differences + for (unsigned int i=0; i > p2(n); - std::vector e2(n); - for (unsigned int i=0;i > p2 = points; + for (unsigned int i=0; i values2(n); + f.value_list(points, values, component); + f.value_list(p2, values2, component); + + // compute finite differences + for (unsigned int i=0; i > p_p(n); + // first compute evaluation + // points + std::vector > p_p = points; std::vector > p_pp(n); - std::vector > p_m(n); + std::vector > p_m = points; std::vector > p_mm(n); - std::vector e_p(n); - std::vector e_pp(n); - std::vector e_m(n); for (unsigned int i=0;i e_p(n); + std::vector e_pp(n); + std::vector e_m(n); + f.value_list(p_mm, values, component); - f.value_list(p_pp, e_pp, component); - f.value_list(p_p, e_p, component); - f.value_list(p_m, e_m, component); - - for (unsigned int i=0;i::memory_consumption () const }; + +// explicit instantiations template class FunctionDerivative<1>; template class FunctionDerivative<2>; template class FunctionDerivative<3>; -- 2.39.5