* Return the gradient of the function
* at the given point.
*/
- virtual Point<dim> gradient (const Point<dim> &p) const;
+ virtual Tensor<1,dim> gradient (const Point<dim> &p) const;
/**
* Set #gradients# to the gradients of
* the same size as the #points# array.
*/
virtual void gradient_list (const vector<Point<dim> > &points,
- vector<Point<dim> > &gradients) const;
+ vector<Tensor<1,dim> > &gradients) const;
/**
* Return the value of the time variable/
* Return the gradient of the function
* at the given point.
*/
- virtual Point<dim> gradient (const Point<dim> &p) const;
+ virtual Tensor<1,dim> gradient (const Point<dim> &p) const;
/**
* Set #gradients# to the gradients of
* the same size as the #points# array.
*/
virtual void gradient_list (const vector<Point<dim> > &points,
- vector<Point<dim> > &gradients) const;
+ vector<Tensor<1,dim> > &gradients) const;
};
*/
Tensor<rank_,dim> & operator /= (const double &factor);
+ /**
+ * Add two tensors. If possible, use
+ * #operator +=# instead since this does not
+ * need to copy a point at least once.
+ */
+ Tensor<rank_,dim> operator + (const Tensor<rank_,dim> &) const;
+
+ /**
+ * Subtract two tensors. If possible, use
+ * #operator +=# instead since this does not
+ * need to copy a point at least once.
+ */
+ Tensor<rank_,dim> operator - (const Tensor<rank_,dim> &) const;
+
/**
* Reset all values to zero.
*/
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim>
+Tensor<rank_,dim>::operator + (const Tensor<rank_,dim> &t) const {
+ Tensor<rank_,dim> tmp(*this);
+
+ for (unsigned int i=0; i<dim; ++i)
+ tmp.subtensor[i] += t.subtensor[i];
+
+ return tmp;
+};
+
+
+
+template <int rank_, int dim>
+inline
+Tensor<rank_,dim>
+Tensor<rank_,dim>::operator - (const Tensor<rank_,dim> &t) const {
+ Tensor<rank_,dim> tmp(*this);
+
+ for (unsigned int i=0; i<dim; ++i)
+ tmp.subtensor[i] -= t.subtensor[i];
+
+ return tmp;
+};
+
+
+
template <int rank_, int dim>
inline
void Tensor<rank_,dim>::clear () {
/**
* Returns the scalar product of two vectors.
*/
- double operator * (const Tensor<1,dim> &) const;
+ double operator * (const Tensor<1,dim> &) const;
+
+ /**
+ * Add two tensors. If possible, use
+ * #operator +=# instead since this does not
+ * need to copy a point at least once.
+ */
+ Tensor<1,dim> operator + (const Tensor<1,dim> &) const;
+
+ /**
+ * Subtract two tensors. If possible, use
+ * #operator +=# instead since this does not
+ * need to copy a point at least once.
+ */
+ Tensor<1,dim> operator - (const Tensor<1,dim> &) const;
/**
* Reset all values to zero.
+template <int dim>
+inline
+Tensor<1,dim> Tensor<1,dim>::operator + (const Tensor<1,dim> &p) const {
+ return (Tensor<1,dim>(*this) += p);
+};
+
+
+
+template <int dim>
+inline
+Tensor<1,dim> Tensor<1,dim>::operator - (const Tensor<1,dim> &p) const {
+ return (Tensor<1,dim>(*this) -= p);
+};
+
+
+
template <int dim>
inline
void Tensor<1,dim>::clear () {
template <int dim>
-Point<dim> Function<dim>::gradient (const Point<dim> &) const {
+Tensor<1,dim> Function<dim>::gradient (const Point<dim> &) const {
Assert (false, ExcPureFunctionCalled());
return Point<dim>();
};
template <int dim>
void Function<dim>::gradient_list (const vector<Point<dim> > &points,
- vector<Point<dim> > &gradients) const {
+ vector<Tensor<1,dim> > &gradients) const {
Assert (gradients.size() == points.size(),
ExcVectorHasWrongSize(gradients.size(), points.size()));
template <int dim>
-Point<dim> ZeroFunction<dim>::gradient (const Point<dim> &) const {
- return Point<dim>();
+Tensor<1,dim> ZeroFunction<dim>::gradient (const Point<dim> &) const {
+ return Tensor<1,dim>();
};
template <int dim>
void ZeroFunction<dim>::gradient_list (const vector<Point<dim> > &points,
- vector<Point<dim> > &gradients) const {
+ vector<Tensor<1,dim> > &gradients) const {
Assert (gradients.size() == points.size(),
ExcVectorHasWrongSize(gradients.size(), points.size()));
- fill_n (gradients.begin(), points.size(), Point<dim>());
+ gradients.clear ();
};