From dc2ee7a8b7ba9b5761caf3078fbb4d998a8807b2 Mon Sep 17 00:00:00 2001 From: wolf Date: Wed, 18 Jul 2001 09:50:43 +0000 Subject: [PATCH] FourierSine and FourierCosineFunction git-svn-id: https://svn.dealii.org/trunk@4849 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/function_lib.h | 118 ++++++++++++++++++ deal.II/base/source/function_lib.cc | 149 +++++++++++++++++++++++ deal.II/doc/news/2001/c-3-1.html | 7 +- 3 files changed, 273 insertions(+), 1 deletion(-) diff --git a/deal.II/base/include/base/function_lib.h b/deal.II/base/include/base/function_lib.h index 1172b3a2e8..10c42f8e52 100644 --- a/deal.II/base/include/base/function_lib.h +++ b/deal.II/base/include/base/function_lib.h @@ -525,5 +525,123 @@ class JumpFunction : public Function +/** + * 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))}. + * + * The class has its name from the fact that it resembles one + * component of a Fourier cosine decomposition. + * + * @author Wolfgang Bangerth, 2001 + */ +template +class FourierCosineFunction : public Function +{ + public: + /** + * Constructor. Take the Fourier + * coefficients in each space + * direction as argument. + */ + FourierCosineFunction (const Point &fourier_coefficients); + + /** + * Return the value of the + * function at the given + * point. Unless there is only + * one component (i.e. the + * function is scalar), you + * should state the component you + * want to have evaluated; it + * defaults to zero, i.e. the + * first component. + */ + virtual double value (const Point &p, + const unsigned int component = 0) const; + + /** + * Return the gradient of the + * specified component of the + * function at the given point. + */ + virtual Tensor<1,dim> gradient (const Point &p, + const unsigned int component = 0) const; + + /** + * Compute the Laplacian of a + * given component at point @p{p}. + */ + virtual double laplacian (const Point &p, + const unsigned int component = 0) const; + private: + /** + * Stored Fourier coefficients. + */ + const Point fourier_coefficients; +}; + + + +/** + * 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))}. + * + * The class has its name from the fact that it resembles one + * component of a Fourier sine decomposition. + * + * @author Wolfgang Bangerth, 2001 + */ +template +class FourierSineFunction : public Function +{ + public: + /** + * Constructor. Take the Fourier + * coefficients in each space + * direction as argument. + */ + FourierSineFunction (const Point &fourier_coefficients); + + /** + * Return the value of the + * function at the given + * point. Unless there is only + * one component (i.e. the + * function is scalar), you + * should state the component you + * want to have evaluated; it + * defaults to zero, i.e. the + * first component. + */ + virtual double value (const Point &p, + const unsigned int component = 0) const; + + /** + * Return the gradient of the + * specified component of the + * function at the given point. + */ + virtual Tensor<1,dim> gradient (const Point &p, + const unsigned int component = 0) const; + + /** + * Compute the Laplacian of a + * given component at point @p{p}. + */ + virtual double laplacian (const Point &p, + const unsigned int component = 0) const; + private: + /** + * Stored Fourier coefficients. + */ + const Point fourier_coefficients; +}; + + + #endif diff --git a/deal.II/base/source/function_lib.cc b/deal.II/base/source/function_lib.cc index 36c52c679a..5da39ec8f9 100644 --- a/deal.II/base/source/function_lib.cc +++ b/deal.II/base/source/function_lib.cc @@ -1112,6 +1112,148 @@ JumpFunction::memory_consumption () const }; + + + +/* ---------------------- FourierSineFunction ----------------------- */ + + +template +FourierCosineFunction:: +FourierCosineFunction (const Point &fourier_coefficients) + : + Function (1), + fourier_coefficients (fourier_coefficients) +{}; + + + +template +double +FourierCosineFunction::value (const Point &p, + const unsigned int component) const +{ + Assert (component==0, ExcIndexRange(component,0,1)); + double val=1; + for (unsigned int i=0; i +Tensor<1,dim> +FourierCosineFunction::gradient (const Point &p, + const unsigned int component) const +{ + Assert (component==0, ExcIndexRange(component,0,1)); + Tensor<1,dim> grad; + for (unsigned int i=0; i +double +FourierCosineFunction::laplacian (const Point &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 +FourierSineFunction:: +FourierSineFunction (const Point &fourier_coefficients) + : + Function (1), + fourier_coefficients (fourier_coefficients) +{}; + + + +template +double +FourierSineFunction::value (const Point &p, + const unsigned int component) const +{ + Assert (component==0, ExcIndexRange(component,0,1)); + double val=1; + for (unsigned int i=0; i +Tensor<1,dim> +FourierSineFunction::gradient (const Point &p, + const unsigned int component) const +{ + Assert (component==0, ExcIndexRange(component,0,1)); + Tensor<1,dim> grad; + for (unsigned int i=0; i +double +FourierSineFunction::laplacian (const Point &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; template class SquareFunction<2>; template class SquareFunction<3>; @@ -1130,3 +1272,10 @@ template class ExpFunction<3>; template class JumpFunction<1>; template class JumpFunction<2>; template class JumpFunction<3>; +template class FourierCosineFunction<1>; +template class FourierCosineFunction<2>; +template class FourierCosineFunction<3>; +template class FourierSineFunction<1>; +template class FourierSineFunction<2>; +template class FourierSineFunction<3>; + diff --git a/deal.II/doc/news/2001/c-3-1.html b/deal.II/doc/news/2001/c-3-1.html index 548eecb0f2..d1595b8c44 100644 --- a/deal.II/doc/news/2001/c-3-1.html +++ b/deal.II/doc/news/2001/c-3-1.html @@ -158,9 +158,14 @@ documentation, etc.

base

    -
  1. + New: classes FourierSineFunction and + FourierCosineFunction, resembling + one mode of a Fourier decomposition. +
    + (GK 2001/07/18) +

  2. New: class vector2d was introduced in analogy to STL class vector. The bew class provides a two-dimensional array and replaces the use -- 2.39.5