// $Id$
// Version: $Name$
//
-// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009 by the deal.II authors
+// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2009, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
virtual void vector_value_list (const std::vector<Point<dim> > &points,
std::vector<Vector<double> > &values) const;
+ /**
+ * For each component of the
+ * function, fill a vector of
+ * values, one for each point.
+ *
+ * The default implementation of
+ * this function in Function calls
+ * value_list() for each
+ * component. In order to improve
+ * performance, this can be
+ * reimplemented in derived
+ * classes to speed up performance.
+ */
+ virtual void vector_values (const std::vector<Point<dim> >& points,
+ std::vector<std::vector<double> >& values) const;
+
/**
* Return the gradient of the
* specified component of the
std::vector<Tensor<1,dim> > &gradients,
const unsigned int component = 0) const;
+ /**
+ * For each component of the
+ * function, fill a vector of
+ * gradient values, one for each point.
+ *
+ * The default implementation of
+ * this function in Function calls
+ * value_list() for each
+ * component. In order to improve
+ * performance, this can be
+ * reimplemented in derived
+ * classes to speed up performance.
+ */
+ virtual void vector_gradients (const std::vector<Point<dim> > &points,
+ std::vector<std::vector<Tensor<1,dim> > > &gradients) const;
+
/**
* Set <tt>gradients</tt> to the gradients of
* the function at the <tt>points</tt>,
template <int dim>
CosineFunction<dim>::CosineFunction (const unsigned int n_components)
:
- Function<dim> (n_components)
-{}
+ Function<dim> (n_components)
+ {}
}
}
+//////////////////////////////////////////////////////////////////////
+
+ template <int dim>
+ CosineGradFunction<dim>::CosineGradFunction ()
+ :
+ Function<dim> (dim)
+ {}
+
+
+ template<int dim>
+ double
+ CosineGradFunction<dim>::value (
+ const Point<dim> &p,
+ const unsigned int d) const
+ {
+ AssertIndexRange(d, dim);
+ const unsigned int d1 = (d+1) % dim;
+ const unsigned int d2 = (d+2) % dim;
+ switch(dim)
+ {
+ case 1:
+ return (-M_PI_2* std::sin(M_PI_2*p(0)));
+ case 2:
+ return (-M_PI_2* std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)));
+ case 3:
+ return (-M_PI_2* std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2)));
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ return 0.;
+ }
+
+
+ template<int dim>
+ void
+ CosineGradFunction<dim>::vector_value (
+ const Point<dim>& p,
+ Vector<double>& result) const
+ {
+ AssertDimension(result.size(), dim);
+ switch(dim)
+ {
+ case 1:
+ result(0) = -M_PI_2* std::sin(M_PI_2*p(0));
+ break;
+ case 2:
+ result(0) = -M_PI_2* std::sin(M_PI_2*p(0)) * std::cos(M_PI_2*p(1));
+ result(1) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::sin(M_PI_2*p(1));
+ break;
+ case 3:
+ result(0) = -M_PI_2* std::sin(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ result(1) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::sin(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ result(2) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::sin(M_PI_2*p(2));
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ }
+
+
+ template<int dim>
+ void
+ CosineGradFunction<dim>::value_list (
+ const std::vector<Point<dim> >& points,
+ std::vector<double>& values,
+ const unsigned int d) const
+ {
+ Assert (values.size() == points.size(),
+ ExcDimensionMismatch(values.size(), points.size()));
+ AssertIndexRange(d, dim);
+ const unsigned int d1 = (d+1) % dim;
+ const unsigned int d2 = (d+2) % dim;
+
+ for (unsigned int i=0;i<points.size();++i)
+ {
+ const Point<dim>& p = points[i];
+ switch(dim)
+ {
+ case 1:
+ values[i] = -M_PI_2* std::sin(M_PI_2*p(d));
+ break;
+ case 2:
+ values[i] = -M_PI_2* std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1));
+ break;
+ case 3:
+ values[i] = -M_PI_2* std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2));
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ }
+ }
+
+
+ template<int dim>
+ void
+ CosineGradFunction<dim>::vector_value_list (
+ const std::vector<Point<dim> > &points,
+ std::vector<Vector<double> > &values) const
+ {
+ Assert (values.size() == points.size(),
+ ExcDimensionMismatch(values.size(), points.size()));
+
+ for (unsigned int i=0;i<points.size();++i)
+ {
+ const Point<dim>& p = points[i];
+ switch(dim)
+ {
+ case 1:
+ values[i](0) = -M_PI_2* std::sin(M_PI_2*p(0));
+ break;
+ case 2:
+ values[i](0) = -M_PI_2* std::sin(M_PI_2*p(0)) * std::cos(M_PI_2*p(1));
+ values[i](1) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::sin(M_PI_2*p(1));
+ break;
+ case 3:
+ values[i](0) = -M_PI_2* std::sin(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ values[i](1) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::sin(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ values[i](2) = -M_PI_2* std::cos(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::sin(M_PI_2*p(2));
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ }
+ }
+
+
+ template<int dim>
+ double
+ CosineGradFunction<dim>::laplacian (
+ const Point<dim> &p,
+ const unsigned int d) const
+ {
+ return -M_PI_2*M_PI_2* value(p,d);
+ }
+
+
+ template<int dim>
+ Tensor<1,dim>
+ CosineGradFunction<dim>::gradient (
+ const Point<dim>& p,
+ const unsigned int d) const
+ {
+ AssertIndexRange(d, dim);
+ const unsigned int d1 = (d+1) % dim;
+ const unsigned int d2 = (d+2) % dim;
+ const double pi2 = M_PI_2*M_PI_2;
+
+ Tensor<1,dim> result;
+ switch(dim)
+ {
+ case 1:
+ result[0] = -pi2* std::cos(M_PI_2*p(0));
+ break;
+ case 2:
+ result[d ] = -pi2*std::cos(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1));
+ result[d1] = pi2*std::sin(M_PI_2*p(d)) * std::sin(M_PI_2*p(d1));
+ break;
+ case 3:
+ result[d ] = -pi2*std::cos(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2));
+ result[d1] = pi2*std::sin(M_PI_2*p(d)) * std::sin(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2));
+ result[d2] = pi2*std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::sin(M_PI_2*p(d2));
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ return result;
+ }
+
+
+ template<int dim>
+ void
+ CosineGradFunction<dim>::gradient_list (
+ const std::vector<Point<dim> > &points,
+ std::vector<Tensor<1,dim> > &gradients,
+ const unsigned int d) const
+ {
+ AssertIndexRange(d, dim);
+ const unsigned int d1 = (d+1) % dim;
+ const unsigned int d2 = (d+2) % dim;
+ const double pi2 = M_PI_2*M_PI_2;
+
+ Assert (gradients.size() == points.size(),
+ ExcDimensionMismatch(gradients.size(), points.size()));
+ for (unsigned int i=0;i<points.size();++i)
+ {
+ const Point<dim>& p = points[i];
+ Tensor<1,dim>& result = gradients[i];
+
+ switch(dim)
+ {
+ case 1:
+ result[0] = -pi2* std::cos(M_PI_2*p(0));
+ break;
+ case 2:
+ result[d ] = -pi2*std::cos(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1));
+ result[d1] = pi2*std::sin(M_PI_2*p(d)) * std::sin(M_PI_2*p(d1));
+ break;
+ case 3:
+ result[d ] = -pi2*std::cos(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2));
+ result[d1] = pi2*std::sin(M_PI_2*p(d)) * std::sin(M_PI_2*p(d1)) * std::cos(M_PI_2*p(d2));
+ result[d2] = pi2*std::sin(M_PI_2*p(d)) * std::cos(M_PI_2*p(d1)) * std::sin(M_PI_2*p(d2));
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ }
+ }
+
+
+ template<int dim>
+ void
+ CosineGradFunction<dim>::vector_gradient_list (
+ const std::vector<Point<dim> > &points,
+ std::vector<std::vector<Tensor<1,dim> > >& gradients) const
+ {
+ AssertVectorVectorDimension(gradients, points.size(), dim);
+ const double pi2 = M_PI_2*M_PI_2;
+
+ for (unsigned int i=0;i<points.size();++i)
+ {
+ const Point<dim>& p = points[i];
+ switch(dim)
+ {
+ case 1:
+ gradients[i][0][0] = -pi2* std::cos(M_PI_2*p(0));
+ break;
+ case 2:
+ if (true)
+ {
+ const double coco = -pi2*std::cos(M_PI_2*p(0)) * std::cos(M_PI_2*p(1));
+ const double sisi = pi2*std::sin(M_PI_2*p(0)) * std::sin(M_PI_2*p(1));
+ gradients[i][0][0] = coco;
+ gradients[i][1][1] = coco;
+ gradients[i][0][1] = sisi;
+ gradients[i][1][0] = sisi;
+ }
+ break;
+ case 3:
+ if (true)
+ {
+ const double cococo = -pi2*std::cos(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ const double sisico = pi2*std::sin(M_PI_2*p(0)) * std::sin(M_PI_2*p(1)) * std::cos(M_PI_2*p(2));
+ const double sicosi = pi2*std::sin(M_PI_2*p(0)) * std::cos(M_PI_2*p(1)) * std::sin(M_PI_2*p(2));
+ const double cosisi = pi2*std::cos(M_PI_2*p(0)) * std::sin(M_PI_2*p(1)) * std::sin(M_PI_2*p(2));
+
+ gradients[i][0][0] = cococo;
+ gradients[i][1][1] = cococo;
+ gradients[i][2][2] = cococo;
+ gradients[i][0][1] = sisico;
+ gradients[i][1][0] = sisico;
+ gradients[i][0][2] = sicosi;
+ gradients[i][2][0] = sicosi;
+ gradients[i][1][2] = cosisi;
+ gradients[i][2][1] = cosisi;
+ }
+ break;
+ default:
+ Assert(false, ExcNotImplemented());
+ }
+ }
+ }
+
+
//////////////////////////////////////////////////////////////////////
template<int dim>
(d==0
? (std::cos(2./3.*phi)*y)
: (-std::cos(2./3.*phi)*x)))
- /r43;
+ /r43;
}
(d==0
? (std::cos(2./3.*phi)*y)
: (-std::cos(2./3.*phi)*x)))
- /r43;
+ /r43;
}
}
double
LSingularityGradFunction::laplacian (const Point<2> &,
- const unsigned int) const
+ const unsigned int) const
{
return 0.;
}
void
LSingularityGradFunction::laplacian_list (const std::vector<Point<2> > &points,
- std::vector<double> &values,
- const unsigned int) const
+ std::vector<double> &values,
+ const unsigned int) const
{
Assert (values.size() == points.size(),
ExcDimensionMismatch(values.size(), points.size()));
template <int dim>
double
SlitSingularityFunction<dim>::laplacian (const Point<dim> &,
- const unsigned int) const
+ const unsigned int) const
{
return 0.;
}
template <int dim>
Tensor<1,dim>
SlitSingularityFunction<dim>::gradient (const Point<dim> &p,
- const unsigned int) const
+ const unsigned int) const
{
double x = p(0);
double y = p(1);
template <int dim>
void
SlitSingularityFunction<dim>::gradient_list (const std::vector<Point<dim> > &points,
- std::vector<Tensor<1,dim> > &gradients,
- const unsigned int) const
+ std::vector<Tensor<1,dim> > &gradients,
+ const unsigned int) const
{
Assert (gradients.size() == points.size(),
ExcDimensionMismatch(gradients.size(), points.size()));
FourierCosineFunction (const Point<dim> &fourier_coefficients)
:
Function<dim> (1),
- fourier_coefficients (fourier_coefficients)
+ fourier_coefficients (fourier_coefficients)
{}
FourierSineFunction (const Point<dim> &fourier_coefficients)
:
Function<dim> (1),
- fourier_coefficients (fourier_coefficients)
+ fourier_coefficients (fourier_coefficients)
{}
const std::vector<double> &weights)
:
Function<dim> (1),
- fourier_coefficients (fourier_coefficients),
- weights (weights)
+ fourier_coefficients (fourier_coefficients),
+ weights (weights)
{
Assert (fourier_coefficients.size() > 0, ExcZero());
Assert (fourier_coefficients.size() == weights.size(),
FourierCosineSum<dim>::
FourierCosineSum (const std::vector<Point<dim> > &fourier_coefficients,
const std::vector<double> &weights)
- :
- Function<dim> (1),
- fourier_coefficients (fourier_coefficients),
- weights (weights)
+ :
+ Function<dim> (1),
+ fourier_coefficients (fourier_coefficients),
+ weights (weights)
{
Assert (fourier_coefficients.size() > 0, ExcZero());
Assert (fourier_coefficients.size() == weights.size(),
template class CosineFunction<1>;
template class CosineFunction<2>;
template class CosineFunction<3>;
+ template class CosineGradFunction<1>;
+ template class CosineGradFunction<2>;
+ template class CosineGradFunction<3>;
template class ExpFunction<1>;
template class ExpFunction<2>;
template class ExpFunction<3>;