18 #include <deal.II/fe/fe_series.h> 19 #include <deal.II/base/numbers.h> 24 #include <deal.II/base/config.h> 25 #ifdef DEAL_II_WITH_GSL 26 #include <gsl/gsl_sf_legendre.h> 30 DEAL_II_NAMESPACE_OPEN
41 for (
unsigned int i=0; i<N; ++i)
50 for (
unsigned int i=0; i<N; ++i)
51 for (
unsigned int j=0; j<N; ++j)
62 for (
unsigned int i=0; i<N; ++i)
63 for (
unsigned int j=0; j<N; ++j)
64 for (
unsigned int k=0; k<N; ++k)
78 fe_collection(&fe_collection),
79 q_collection(&q_collection),
80 fourier_transform_matrices(fe_collection.size())
88 const unsigned int cell_active_fe_index,
89 Table<dim,std::complex<double> > &fourier_coefficients)
91 ensure_existence(cell_active_fe_index);
94 std::fill(unrolled_coefficients.begin(),
95 unrolled_coefficients.end(),
96 std::complex<double>(0.));
98 Assert (unrolled_coefficients.size() == matrix.m(),
101 Assert (local_dof_values.
size() == matrix.n(),
104 for (
unsigned int i = 0; i < unrolled_coefficients.size(); i++)
105 for (
unsigned int j = 0; j < local_dof_values.
size(); j++)
106 unrolled_coefficients[i] += matrix[i][j] *
109 fourier_coefficients.fill(unrolled_coefficients.begin());
116 const unsigned int j)
118 std::complex<double> sum = 0;
119 for (
unsigned int q=0; q<quadrature.
size(); ++q)
122 sum += std::exp(std::complex<double>(0,1) *
134 Assert (fe < fe_collection->size(),
137 if (fourier_transform_matrices[fe].m() == 0)
139 fourier_transform_matrices[fe].reinit(k_vectors.n_elements(),
140 (*fe_collection)[fe].dofs_per_cell);
143 for (
unsigned int k1=0; k1<k_vectors.size(0); ++k1)
144 for (
unsigned int k2=0; k2<k_vectors.size(1); ++k2,k++)
145 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
146 fourier_transform_matrices[fe](k,j) = integrate((*fe_collection)[fe],
156 Assert (fe < fe_collection->size(),
159 if (fourier_transform_matrices[fe].m() == 0)
161 fourier_transform_matrices[fe].reinit(k_vectors.n_elements(),
162 (*fe_collection)[fe].dofs_per_cell);
165 for (
unsigned int k1=0; k1<k_vectors.size(0); ++k1)
166 for (
unsigned int k2=0; k2<k_vectors.size(1); ++k2)
167 for (
unsigned int k3=0; k3<k_vectors.size(2); ++k3, k++)
168 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
169 fourier_transform_matrices[fe](k,j) = integrate((*fe_collection)[fe],
179 Assert (fe < fe_collection->size(),
182 if (fourier_transform_matrices[fe].m() == 0)
184 fourier_transform_matrices[fe].reinit(k_vectors.n_elements(),
185 (*fe_collection)[fe].dofs_per_cell);
187 for (
unsigned int k=0; k<k_vectors.size(0); ++k)
188 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
189 fourier_transform_matrices[fe](k,j) = integrate((*fe_collection)[fe],
199 <<
"x["<<arg1 <<
"] = "<<arg2 <<
" is not in [0,1]");
208 #ifdef DEAL_II_WITH_GSL 210 for (
unsigned int d = 0;
d < dim;
d++)
212 const double x = 2.0*(x_q[
d]-0.5);
213 Assert ( (x_q[d] <= 1.0) && (x_q[d] >= 0.),
215 const int ind = indices[
d];
216 res *= sqrt(2.0) * gsl_sf_legendre_Pl (ind, x);
225 "in order to use Legendre transformation."));
237 for (
unsigned int d = 0;
d < dim;
d++)
238 res *= (0.5+indices[d]);
249 N(size_in_each_direction),
250 fe_collection(&fe_collection),
251 q_collection(&q_collection),
252 legendre_transform_matrices(fe_collection.size()),
253 unrolled_coefficients(
Utilities::fixed_power<dim>(N),
260 const unsigned int cell_active_fe_index,
263 ensure_existence(cell_active_fe_index);
266 std::fill(unrolled_coefficients.begin(),
267 unrolled_coefficients.end(),
270 Assert (unrolled_coefficients.size() == matrix.m(),
273 Assert (local_dof_values.size() == matrix.n(),
276 for (
unsigned int i = 0; i < unrolled_coefficients.size(); i++)
277 for (
unsigned int j = 0; j < local_dof_values.size(); j++)
278 unrolled_coefficients[i] += matrix[i][j] *
281 legendre_coefficients.
fill(unrolled_coefficients.begin());
289 const unsigned int dof)
292 for (
unsigned int q=0; q<quadrature.
size(); ++q)
295 sum += Lh(x_q, indices) *
299 return sum * multiplier(indices);
305 Assert (fe < fe_collection->size(),
307 if (legendre_transform_matrices[fe].m() == 0)
309 legendre_transform_matrices[fe].reinit(N,
310 (*fe_collection)[fe].dofs_per_cell);
312 for (
unsigned int k=0; k<N; ++k)
313 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
314 legendre_transform_matrices[fe](k,j) =
315 integrate_Legendre((*fe_collection)[fe],
327 Assert (fe < fe_collection->size(),
330 if (legendre_transform_matrices[fe].m() == 0)
332 legendre_transform_matrices[fe].reinit(N*N,
333 (*fe_collection)[fe].dofs_per_cell);
336 for (
unsigned int k1=0; k1<N; ++k1)
337 for (
unsigned int k2=0; k2<N; ++k2,k++)
338 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
339 legendre_transform_matrices[fe](k,j) =
340 integrate_Legendre((*fe_collection)[fe],
350 Assert (fe < fe_collection->size(),
353 if (legendre_transform_matrices[fe].m() == 0)
355 legendre_transform_matrices[fe].reinit(N*N*N,
356 (*fe_collection)[fe].dofs_per_cell);
359 for (
unsigned int k1=0; k1<N; ++k1)
360 for (
unsigned int k2=0; k2<N; ++k2)
361 for (
unsigned int k3=0; k3<N; ++k3, k++)
362 for (
unsigned int j=0; j<(*fe_collection)[fe].dofs_per_cell; ++j)
363 legendre_transform_matrices[fe](k,j) =
364 integrate_Legendre((*fe_collection)[fe],
373 const std::vector<double> &y)
378 Assert (x.size() == y.size(),
379 ExcMessage(
"x and y are expected to have the same size"));
382 ::ExcMessage(
"at least two points are required for linear regression fit"));
390 for (
unsigned int i = 0; i < x.size(); i++)
408 invK.
vmult(X,B,
false);
410 return std::make_pair(X(1),X(0));
428 DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcLegendre(int arg1, double arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
void ensure_existence(const unsigned int fe_index)
void vmult(Vector< number2 > &w, const Vector< number2 > &v, const bool adding=false) const
const Point< dim > & point(const unsigned int i) const
Legendre(const unsigned int size_in_each_direction, const hp::FECollection< dim > &fe_collection, const hp::QCollection< dim > &q_collection)
std::pair< double, double > linear_regression(const std::vector< double > &x, const std::vector< double > &y)
#define AssertThrow(cond, exc)
void calculate(const ::Vector< double > &local_dof_values, const unsigned int cell_active_fe_index, Table< dim, double > &legendre_coefficients)
Fourier(const unsigned int size_in_each_direction, const hp::FECollection< dim > &fe_collection, const hp::QCollection< dim > &q_collection)
static ::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
size_type n_elements() const
std::vector< std::complex< double > > unrolled_coefficients
static ::ExceptionBase & ExcMessage(std::string arg1)
void invert(const FullMatrix< number2 > &M)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void calculate(const ::Vector< double > &local_dof_values, const unsigned int cell_active_fe_index, Table< dim, std::complex< double > > &fourier_coefficients)
SymmetricTensor< 2, dim, Number > d(const Tensor< 2, dim, Number > &F, const Tensor< 2, dim, Number > &dF_dt)
void ensure_existence(const unsigned int fe_index)
unsigned int size() const
virtual double shape_value(const unsigned int i, const Point< dim > &p) const
Table< dim, Tensor< 1, dim > > k_vectors
void fill(InputIterator entries, const bool C_style_indexing=true)
double weight(const unsigned int i) const
static ::ExceptionBase & ExcInternalError()