Skip to content

Commit ee72a7f

Browse files
committed
Add FFTData (idaholab#401)
1 parent 4ff3845 commit ee72a7f

File tree

11 files changed

+290
-26
lines changed

11 files changed

+290
-26
lines changed

include/problems/FFTProblem.h

-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class FFTProblem : public FEProblem
3939

4040
/// dummy system for the FFT variables
4141
AuxiliarySystem _fft_dummy_system;
42-
43-
unsigned int _fft_var_number;
4442
};
4543

4644
template <typename T>

include/userobjects/FFTBufferBase.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ class FFTBufferBase;
1818
#define usingFFTBufferBaseMembers \
1919
using ElementUserObject::_perf_graph; \
2020
using FFTBufferBase<T>::_dim; \
21-
using FFTBufferBase<T>::_real_space_grid; \
22-
using FFTBufferBase<T>::_reciprocal_space_grid; \
21+
using FFTBufferBase<T>::_grid; \
2322
using FFTBufferBase<T>::_real_space_data; \
2423
using FFTBufferBase<T>::_reciprocal_space_data; \
2524
using FFTBufferBase<T>::_real_space_data_start; \

include/utils/ComplexTypes.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
#include "libmesh/vector_value.h"
1818

1919
typedef std::complex<Real> Complex;
20-
typedef VectorValue<std::complex<Real>> ComplexVectorValue;
21-
typedef RankTwoTensorTempl<std::complex<Real>> ComplexRankTwoTensor;
22-
typedef RankThreeTensorTempl<std::complex<Real>> ComplexRankThreeTensor;
23-
typedef RankFourTensorTempl<std::complex<Real>> ComplexRankFourTensor;
20+
typedef VectorValue<Complex> ComplexVectorValue;
21+
typedef RankTwoTensorTempl<Complex> ComplexRankTwoTensor;
22+
typedef RankThreeTensorTempl<Complex> ComplexRankThreeTensor;
23+
typedef RankFourTensorTempl<Complex> ComplexRankFourTensor;
2424

2525
// helper template to select the corresponding complex tensor type
2626
template <typename T>

include/utils/FFTData.h

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**********************************************************************/
2+
/* DO NOT MODIFY THIS HEADER */
3+
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
4+
/* */
5+
/* Copyright 2017 Battelle Energy Alliance, LLC */
6+
/* ALL RIGHTS RESERVED */
7+
/**********************************************************************/
8+
9+
#pragma once
10+
11+
#include "ComplexTypes.h"
12+
13+
// helper template to select the corresponding scalar type
14+
template <typename T>
15+
struct FFTScalarType
16+
{
17+
using type = Real;
18+
};
19+
20+
template <typename T>
21+
struct FFTScalarType<std::complex<T>>
22+
{
23+
using type = Complex;
24+
};
25+
26+
/**
27+
* Helper class to hold the reciprocal space data
28+
*/
29+
template <typename T>
30+
class FFTData
31+
{
32+
using ScalarT = typename FFTScalarType<T>::type;
33+
34+
public:
35+
FFTData(std::size_t size = 0) { resize(size); }
36+
void resize(std::size_t size) { _buffer.resize(size); }
37+
38+
///@{ data access by index
39+
const T & operator[](std::size_t i) const { return _buffer[i]; }
40+
T & operator[](std::size_t i) { return _buffer[i]; }
41+
///@}
42+
43+
///@{ convenience math operators
44+
FFTData<T> & operator+=(FFTData<T> const & rhs);
45+
FFTData<T> & operator-=(FFTData<T> const & rhs);
46+
FFTData<T> & operator*=(FFTData<ScalarT> const & rhs);
47+
FFTData<T> & operator/=(FFTData<ScalarT> const & rhs);
48+
FFTData<T> & operator*=(Real rhs);
49+
FFTData<T> & operator/=(Real rhs);
50+
FFTData<T> & operator=(FFTData<T> const & rhs);
51+
///@}
52+
53+
/// return the number of proper grid cells
54+
std::size_t size() const { return _buffer.size(); }
55+
56+
/// get the addres of the first data element of the ith object in the buffer
57+
void * start(std::size_t i);
58+
59+
/// get the number of transforms required for type T
60+
std::size_t howMany() const;
61+
62+
protected:
63+
/// FFT data buffer
64+
std::vector<T> _buffer;
65+
};

include/variables/MooseFFTVariable.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class MooseFFTVariable : public MooseVariable
5353
{
5454
mooseError("Nodal FFT variables are not supported.");
5555
}
56-
virtual void reinitNodesNeighbor(const std::vector<dof_id_type> & nodes)
56+
virtual void reinitNodesNeighbor(const std::vector<dof_id_type> &)
5757
{
5858
mooseError("Nodal FFT variables are not supported.");
5959
}

src/executioners/SpectralExecutionerBase.C

+16-11
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ SpectralExecutionerBase::execute()
5959
// back and forth test
6060
auto & c_buffer = getFFTBuffer<Real>("c");
6161
auto c = c_buffer.realSpace();
62+
auto c_tilde = c_buffer.reciprocalSpace();
6263
c_buffer.forward();
6364

6465
auto & R_buffer = getFFTBuffer<RealVectorValue>("R");
@@ -114,24 +115,25 @@ SpectralExecutionerBase::kVectorMultiply(const FFTBufferBase<Real> & in_buffer,
114115
{
115116
case 1:
116117
{
118+
const auto & ivec = in_buffer.kTable(0);
117119
const int ni = grid[0];
118-
for (int i = 0; i < ni; ++i)
119-
{
120-
out[i](0) = in[i] * i;
121-
}
120+
for (int i = 0; i * 2 <= ni; ++i)
121+
out[i](0) = in[i] * ivec[i];
122122
return;
123123
}
124124

125125
case 2:
126126
{
127127
std::size_t index = 0;
128+
const auto & ivec = in_buffer.kTable(0);
129+
const auto & jvec = in_buffer.kTable(1);
128130
const int ni = grid[0];
129131
const int nj = grid[1];
130132
for (int i = 0; i < ni; ++i)
131-
for (int j = 0; j < nj; ++j)
133+
for (int j = 0; j * 2 <= nj; ++j)
132134
{
133-
out[index](0) = in[index] * i;
134-
out[index](1) = in[index] * j;
135+
out[index](0) = in[index] * ivec[i];
136+
out[index](1) = in[index] * jvec[j];
135137
index++;
136138
}
137139
return;
@@ -140,16 +142,19 @@ SpectralExecutionerBase::kVectorMultiply(const FFTBufferBase<Real> & in_buffer,
140142
case 3:
141143
{
142144
std::size_t index = 0;
145+
const auto & ivec = in_buffer.kTable(0);
146+
const auto & jvec = in_buffer.kTable(1);
147+
const auto & kvec = in_buffer.kTable(2);
143148
const int ni = grid[0];
144149
const int nj = grid[1];
145150
const int nk = grid[2];
146151
for (int i = 0; i < ni; ++i)
147152
for (int j = 0; j < nj; ++j)
148-
for (int k = 0; k < nk; ++k)
153+
for (int k = 0; k * 2 <= nk; ++k)
149154
{
150-
out[index](0) = in[index] * i;
151-
out[index](1) = in[index] * j;
152-
out[index](2) = in[index] * k;
155+
out[index](0) = in[index] * ivec[i];
156+
out[index](1) = in[index] * jvec[j];
157+
out[index](2) = in[index] * kvec[k];
153158
index++;
154159
}
155160
return;

src/problems/FFTProblem.C

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ FFTProblem::getVariable(THREAD_ID tid,
8585
auto params = MooseVariableBase::validParams();
8686
params.set<MooseEnum>("order") = "CONSTANT";
8787
params.set<MooseEnum>("family") = "MONOMIAL";
88-
params.set<unsigned int>("_var_num") = _fft_var_number;
88+
params.set<unsigned int>("_var_num") = fft_var_number;
8989
params.set<THREAD_ID>("tid") = tid;
9090
params.set<THREAD_ID>("_tid") = tid;
9191
params.set<Moose::VarKindType>("_var_kind") = Moose::VarKindType::VAR_AUXILIARY;

src/userobjects/FFTBufferBase.C

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
4545
_dim(_mesh.dimension()),
4646
_cell_volume(1.0),
4747
_moose_variable(coupledComponents("moose_variable")),
48+
_k_table(_dim),
4849
_how_many(_real_space_data.howMany())
4950
{
5051
// make sure Real is double

src/utils/ComplexTypes.C

+7-4
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ absoluteFuzzyEqual(const std::complex<Real> & var1,
3737
#include "RankThreeTensorImplementation.h"
3838
#include "RankFourTensorImplementation.h"
3939

40-
template class VectorValue<std::complex<Real>>;
40+
namespace libMesh
41+
{
42+
template class VectorValue<Complex>;
43+
}
4144

42-
template class RankTwoTensorTempl<std::complex<Real>>;
43-
template class RankThreeTensorTempl<std::complex<Real>>;
44-
template class RankFourTensorTempl<std::complex<Real>>;
45+
template class RankTwoTensorTempl<Complex>;
46+
template class RankThreeTensorTempl<Complex>;
47+
template class RankFourTensorTempl<Complex>;

0 commit comments

Comments
 (0)