16 #include <deal.II/base/function_derivative.h> 17 #include <deal.II/base/point.h> 19 #include <deal.II/lac/vector.h> 23 DEAL_II_NAMESPACE_OPEN
48 for (
unsigned int i = 0; i <
incr.size(); ++i)
70 ExcMessage(
"The argument passed to this function does not " 71 "match any known difference formula."));
83 for (
unsigned int i = 0; i < incr.size(); ++i)
93 const unsigned int component)
const 97 "FunctionDerivative was not initialized for constant direction"));
102 return (f.value(p + incr[0], component) -
103 f.value(p - incr[0], component)) /
106 return (f.value(p, component) - f.value(p - incr[0], component)) / h;
108 return (-f.value(p + 2 * incr[0], component) +
109 8 * f.value(p + incr[0], component) -
110 8 * f.value(p - incr[0], component) +
111 f.value(p - 2 * incr[0], component)) /
128 "FunctionDerivative was not initialized for constant direction"));
138 f.vector_value(p - incr[0], aux);
139 result.
sadd(1. / (2 * h), -1. / (2 * h), aux);
143 f.vector_value(p - incr[0], aux);
144 result.
sadd(1. / h, -1. / h, aux);
148 f.vector_value(p + 2 * incr[0], aux);
149 result.
add(-1., aux);
150 f.vector_value(p - incr[0], aux);
151 result.
add(-8., aux);
152 f.vector_value(p + incr[0], aux);
166 std::vector<double> & values,
167 const unsigned int component)
const 169 const unsigned int n = points.size();
170 const bool variable_direction = (incr.size() == 1) ?
false :
true;
171 if (variable_direction)
172 Assert(incr.size() == points.size(),
176 std::vector<double> aux(n);
178 std::vector<Point<dim>> paux(n);
185 for (
unsigned int i = 0; i < n; ++i)
186 paux[i] = points[i] + incr[(variable_direction) ? i : 0U];
187 f.value_list(paux, values, component);
188 for (
unsigned int i = 0; i < n; ++i)
189 paux[i] = points[i] - incr[(variable_direction) ? i : 0U];
190 f.value_list(paux, aux, component);
191 for (
unsigned int i = 0; i < n; ++i)
192 values[i] = (values[i] - aux[i]) / (2 * h);
196 for (
unsigned int i = 0; i < n; ++i)
197 paux[i] = points[i] - incr[(variable_direction) ? i : 0U];
198 f.value_list(paux, aux, component);
199 for (
unsigned int i = 0; i < n; ++i)
200 values[i] = (values[i] - aux[i]) / h;
203 for (
unsigned int i = 0; i < n; ++i)
204 paux[i] = points[i] - 2 * incr[(variable_direction) ? i : 0U];
205 f.value_list(paux, values, component);
206 for (
unsigned int i = 0; i < n; ++i)
207 paux[i] = points[i] + 2 * incr[(variable_direction) ? i : 0U];
208 f.value_list(paux, aux, component);
209 for (
unsigned int i = 0; i < n; ++i)
211 for (
unsigned int i = 0; i < n; ++i)
212 paux[i] = points[i] + incr[(variable_direction) ? i : 0U];
213 f.value_list(paux, aux, component);
214 for (
unsigned int i = 0; i < n; ++i)
215 values[i] += 8. * aux[i];
216 for (
unsigned int i = 0; i < n; ++i)
217 paux[i] = points[i] - incr[(variable_direction) ? i : 0U];
218 f.value_list(paux, aux, component);
219 for (
unsigned int i = 0; i < n; ++i)
220 values[i] = (values[i] - 8. * aux[i]) / (12 * h);
235 return sizeof(*this);
245 DEAL_II_NAMESPACE_CLOSE
virtual double value(const Point< dim > &p, const unsigned int component=0) const override
void sadd(const Number s, const Vector< Number > &V)
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< double > &values, const unsigned int component=0) const override
void set_formula(typename AutoDerivativeFunction< dim >::DifferenceFormula formula=AutoDerivativeFunction< dim >::Euler)
void add(const std::vector< size_type > &indices, const std::vector< OtherNumber > &values)
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void vector_value(const Point< dim > &p, Vector< double > &value) const override
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
std::size_t memory_consumption() const
FunctionDerivative(const Function< dim > &f, const Point< dim > &direction, const double h=1.e-6)
virtual void vector_value(const Point< dim > &p, Vector< RangeNumberType > &values) const
std::vector< Tensor< 1, dim > > incr
virtual void value_list(const std::vector< Point< dim >> &points, std::vector< RangeNumberType > &values, const unsigned int component=0) const
static ::ExceptionBase & ExcNotImplemented()
unsigned int n_components(const DoFHandler< dim, spacedim > &dh)
void set_h(const double h)