5
5
/* Copyright 2017 Battelle Energy Alliance, LLC */
6
6
/* ALL RIGHTS RESERVED */
7
7
/**********************************************************************/
8
+
8
9
#include "FFTBufferBase.h"
9
- #include "MooseTypes.h"
10
10
#include "MyTRIMMesh.h"
11
+
12
+ #include "MooseTypes.h"
13
+ #include "AuxiliarySystem.h"
14
+ #include "AllLocalDofIndicesThread.h"
11
15
#include "RankTwoTensor.h"
12
16
#include "RankThreeTensor.h"
13
17
#include "RankFourTensor.h"
14
18
15
19
#include <type_traits>
16
20
17
- // template <>
18
- // InputParameters
19
- // validParams<FFTBufferBase>()
20
- // {
21
- // InputParameters params = validParams<GeneralUserObject>();
22
- // params.addClassDescription("");
23
- // return params;
24
- // }
25
-
26
21
template < typename T >
27
22
InputParameters
28
23
FFTBufferBase < T > ::validParams ()
29
24
{
30
- InputParameters params = GeneralUserObject ::validParams ();
25
+ InputParameters params = ElementUserObject ::validParams ();
31
26
params .addClassDescription ("Fourier transform data buffer object." );
32
27
params .addRangeCheckedParam < std ::vector < int >>(
33
28
"grid" ,
34
29
"grid > 0" ,
35
30
"Number of grid cells in each dimension to compute "
36
31
"the FFT on (can be omitted when using MyTRIMMesh)" );
37
- params .addParam < unsigned int > (
38
- "max_h_level" , 0 , "Further grid refinement to apply when using MyTRIMMesh with adaptivity" );
32
+ params .addCoupledVar ("moose_variable" ,
33
+ "Optional AuxVariable to take the initial condition of the buffer from." );
34
+
35
+ // make sure we run the object on initial to apply the initial conditions
36
+ params .set < ExecFlagEnum > ("execute_on" ) = EXEC_INITIAL ;
37
+
39
38
return params ;
40
39
}
41
40
42
41
template < typename T >
43
42
FFTBufferBase < T > ::FFTBufferBase (const InputParameters & parameters )
44
- : GeneralUserObject (parameters ),
43
+ : ElementUserObject (parameters ),
45
44
_mesh (_subproblem .mesh ()),
46
45
_dim (_mesh .dimension ()),
47
46
_cell_volume (1.0 ),
48
- _buffer_size (1 )
49
-
47
+ _buffer_size (1 ),
48
+ _moose_variable (coupledComponents ("moose_variable ")),
49
+ _how_many (howMany ())
50
50
{
51
51
// make sure Real is double
52
52
static_assert (
@@ -56,6 +56,12 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
56
56
// FFT needs a regular grid of values to operate on
57
57
if (isParamValid ("grid" ))
58
58
{
59
+ // cannot specify a corresponding MOOSE Variable when running mesh-less
60
+ if (!_moose_variable .empty ())
61
+ paramError ("moose_variable" ,
62
+ "You cannot specify a corresponding MOOSE Variable when running mesh-less, i.e. "
63
+ "using the 'grid' parameter." );
64
+
59
65
// if valid use the user-supplied sampling grid
60
66
_grid = getParam < std ::vector < int >>("grid" );
61
67
if (_grid .size () != _dim )
@@ -72,10 +78,24 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
72
78
_grid .push_back (mytrim_mesh -> getCellCountInDimension (i ));
73
79
}
74
80
75
- // refine grid by max_h_level powers of two
76
- auto max_h_level = getParam < unsigned int > ("max_h_level" );
77
- for (auto & count : _grid )
78
- count = count << max_h_level ;
81
+ // check optional coupled MOOSE variable (only for Real valued buffers)
82
+ if (!_moose_variable .empty ())
83
+ {
84
+ if (_moose_variable .size () != _how_many )
85
+ paramError ("moose_variable" , "Variable needs to have " , _how_many , " components." );
86
+
87
+ for (unsigned i = 0 ; i < _moose_variable .size (); ++ i )
88
+ {
89
+ // check
90
+ auto var = getVar ("moose_variable" , i );
91
+ if (var -> order () != 0 )
92
+ paramError ("moose_variable" , "Variable needs to have CONSTANT order." );
93
+ if (var -> isNodal ())
94
+ paramError ("moose_variable" , "Variable must be elemental." );
95
+
96
+ _moose_variable [i ] = & coupledValue ("moose_variable" );
97
+ }
98
+ }
79
99
80
100
// get mesh extents and calculate space required and estimate spectrum bins
81
101
for (unsigned int i = 0 ; i < _dim ; ++ i )
@@ -98,6 +118,41 @@ FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters)
98
118
istride /= sizeof (Real );
99
119
}
100
120
121
+ template < >
122
+ void
123
+ FFTBufferBase < Real > ::execute ()
124
+ {
125
+ // get grid / buffer location
126
+ Point centroid = _current_elem -> centroid ();
127
+ std ::size_t a = 0 ;
128
+ for (unsigned int i = 0 ; i < _dim ; ++ i )
129
+ a = a * _grid [i ] + std ::floor (((centroid (i ) - _min_corner (i )) * _grid [i ]) / _box_size (i ));
130
+
131
+ // copy solution value from the variables into the buffer
132
+ for (unsigned i = 0 ; i < _moose_variable .size (); ++ i )
133
+ _start [a * _how_many + i ] = (* _moose_variable [i ])[0 ];
134
+ }
135
+
136
+ template < typename T >
137
+ const T &
138
+ FFTBufferBase < T > ::operator ()(const Point & p ) const
139
+ {
140
+ std ::size_t a = 0 ;
141
+ for (unsigned int i = 0 ; i < _dim ; ++ i )
142
+ a = a * _grid [i ] + std ::floor (((p (i ) - _min_corner (i )) * _grid [i ]) / _box_size (i ));
143
+ return _buffer [a ];
144
+ }
145
+
146
+ template < typename T >
147
+ T &
148
+ FFTBufferBase < T > ::operator ()(const Point & p )
149
+ {
150
+ std ::size_t a = 0 ;
151
+ for (unsigned int i = 0 ; i < _dim ; ++ i )
152
+ a = a * _grid [i ] + std ::floor (((p (i ) - _min_corner (i )) * _grid [i ]) / _box_size (i ));
153
+ return _buffer [a ];
154
+ }
155
+
101
156
template < >
102
157
Real *
103
158
FFTBufferBase < Real > ::start (std ::size_t i )
0 commit comments