* Given a wavenumber vector generate a cosine function. The
* wavenumber coefficient is given as a @p{d}-dimensional point @p{k}
* in Fourier space, and the function is then recovered as @p{f(x) =
- * \prod_i cos(k_i x_i) = Re(\exp(i k.x))}.
+ * cos(\sum_i k_i x_i) = Re(\exp(i k.x))}.
*
* The class has its name from the fact that it resembles one
* component of a Fourier cosine decomposition.
* Given a wavenumber vector generate a sine function. The
* wavenumber coefficient is given as a @p{d}-dimensional point @p{k}
* in Fourier space, and the function is then recovered as @p{f(x) =
- * \prod_i sin(k_i x_i) = Im(\exp(i k.x))}.
+ * sin(\sum_i k_i x_i) = Im(\exp(i k.x))}.
*
* The class has its name from the fact that it resembles one
* component of a Fourier sine decomposition.
* of sine functions. Each wavenumber coefficient is given as a
* @p{d}-dimensional point @p{k} in Fourier space, and the entire
* function is then recovered as
- * @p{f(x) = \sum_j w_j \prod_i sin(k_i x_i) = Im(\sum_j w_j \exp(i k.x))}.
+ * @p{f(x) = \sum_j w_j sin(\sum_i k_i x_i) = Im(\sum_j w_j \exp(i k.x))}.
*
* @author Wolfgang Bangerth, 2001
*/
* of cosine functions. Each wavenumber coefficient is given as a
* @p{d}-dimensional point @p{k} in Fourier space, and the entire
* function is then recovered as
- * @p{f(x) = \sum_j w_j \prod_i cos(k_i x_i) = Re(\sum_j w_j \exp(i k.x))}.
+ * @p{f(x) = \sum_j w_j cos(\sum_i k_i x_i) = Re(\sum_j w_j \exp(i k.x))}.
*
* @author Wolfgang Bangerth, 2001
*/
-/* ---------------------- FourierSineFunction ----------------------- */
+/* ---------------------- FourierCosineFunction ----------------------- */
template <int dim>
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- double val=1;
- for (unsigned int i=0; i<dim; ++i)
- val *= std::cos(fourier_coefficients[i] * p[i]);
- return val;
+ return std::cos(fourier_coefficients * p);
};
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- Tensor<1,dim> grad;
- for (unsigned int i=0; i<dim; ++i)
- grad[i] = 1;
-
- for (unsigned int i=0; i<dim; ++i)
- {
- const double cos_i = std::cos(fourier_coefficients[i] * p[i]);
- const double sin_i = std::sin(fourier_coefficients[i] * p[i]);
-
- for (unsigned int d=0; d<dim; ++d)
- if (d==i)
- grad[d] *= - fourier_coefficients[i] * sin_i;
- else
- grad[d] *= cos_i;
- };
-
- return grad;
+ return -fourier_coefficients * std::sin(fourier_coefficients * p);
};
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- double val = -(fourier_coefficients*fourier_coefficients);
- for (unsigned int i=0; i<dim; ++i)
- val *= std::cos(fourier_coefficients[i] * p[i]);
- return val;
+ return fourier_coefficients.square() * (-std::cos(fourier_coefficients * p));
};
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- double val=1;
- for (unsigned int i=0; i<dim; ++i)
- val *= std::sin(fourier_coefficients[i] * p[i]);
- return val;
+ return std::sin(fourier_coefficients * p);
};
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- Tensor<1,dim> grad;
- for (unsigned int i=0; i<dim; ++i)
- grad[i] = 1;
-
- for (unsigned int i=0; i<dim; ++i)
- {
- const double cos_i = std::cos(fourier_coefficients[i] * p[i]);
- const double sin_i = std::sin(fourier_coefficients[i] * p[i]);
-
- for (unsigned int d=0; d<dim; ++d)
- if (d==i)
- grad[d] *= fourier_coefficients[i] * cos_i;
- else
- grad[d] *= sin_i;
- };
-
- return grad;
+ return fourier_coefficients * std::cos(fourier_coefficients * p);
};
const unsigned int component) const
{
Assert (component==0, ExcIndexRange(component,0,1));
- double val = -(fourier_coefficients*fourier_coefficients);
- for (unsigned int i=0; i<dim; ++i)
- val *= std::sin(fourier_coefficients[i] * p[i]);
- return val;
+ return fourier_coefficients.square() * (-std::sin(fourier_coefficients * p));
};
const unsigned int n = weights.size();
double sum = 0;
for (unsigned int s=0; s<n; ++s)
- {
- double val=1;
- for (unsigned int i=0; i<dim; ++i)
- val *= std::sin(fourier_coefficients[s][i] * p[i]);
- sum += weights[s] * val;
- };
+ sum += weights[s] * std::sin(fourier_coefficients[s] * p);
return sum;
};
const unsigned int n = weights.size();
Tensor<1,dim> sum;
for (unsigned int s=0; s<n; ++s)
- {
- Tensor<1,dim> grad;
- for (unsigned int i=0; i<dim; ++i)
- grad[i] = 1;
-
- for (unsigned int i=0; i<dim; ++i)
- {
- const double cos_i = std::cos(fourier_coefficients[s][i] * p[i]);
- const double sin_i = std::sin(fourier_coefficients[s][i] * p[i]);
-
- for (unsigned int d=0; d<dim; ++d)
- if (d==i)
- grad[d] *= fourier_coefficients[s][i] * cos_i;
- else
- grad[d] *= sin_i;
- };
-
- grad *= weights[s];
- sum += grad;
- };
+ sum += fourier_coefficients[s] * std::cos(fourier_coefficients[s] * p);
return sum;
};
const unsigned int n = weights.size();
double sum = 0;
for (unsigned int s=0; s<n; ++s)
- {
- double val = -(fourier_coefficients[s]*fourier_coefficients[s]);
- for (unsigned int i=0; i<dim; ++i)
- val *= std::sin(fourier_coefficients[s][i] * p[i]);
- sum += val * weights[s];
- };
+ sum -= fourier_coefficients[s].square() * std::sin(fourier_coefficients[s] * p);
return sum;
};
const unsigned int n = weights.size();
double sum = 0;
for (unsigned int s=0; s<n; ++s)
- {
- double val=1;
- for (unsigned int i=0; i<dim; ++i)
- val *= std::cos(fourier_coefficients[s][i] * p[i]);
- sum += weights[s] * val;
- };
+ sum += weights[s] * std::cos(fourier_coefficients[s] * p);
return sum;
};
const unsigned int n = weights.size();
Tensor<1,dim> sum;
for (unsigned int s=0; s<n; ++s)
- {
- Tensor<1,dim> grad;
- for (unsigned int i=0; i<dim; ++i)
- grad[i] = 1;
-
- for (unsigned int i=0; i<dim; ++i)
- {
- const double cos_i = std::cos(fourier_coefficients[s][i] * p[i]);
- const double sin_i = std::sin(fourier_coefficients[s][i] * p[i]);
-
- for (unsigned int d=0; d<dim; ++d)
- if (d==i)
- grad[d] *= -fourier_coefficients[s][i] * sin_i;
- else
- grad[d] *= cos_i;
- };
-
- grad *= weights[s];
- sum += grad;
- };
+ sum -= fourier_coefficients[s] * std::sin(fourier_coefficients[s] * p);
return sum;
};
const unsigned int n = weights.size();
double sum = 0;
for (unsigned int s=0; s<n; ++s)
- {
- double val = -(fourier_coefficients[s]*fourier_coefficients[s]);
- for (unsigned int i=0; i<dim; ++i)
- val *= std::cos(fourier_coefficients[s][i] * p[i]);
- sum += val * weights[s];
- };
+ sum -= fourier_coefficients[s].square() * std::cos(fourier_coefficients[s] * p);
return sum;
};