Skip to content

Commit

Permalink
Make FFTBufferAux more flexible (idaholab#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen authored and recuero committed Apr 29, 2020
1 parent a97a514 commit 5b56b55
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 4 deletions.
14 changes: 13 additions & 1 deletion include/auxkernels/FFTBufferAux.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,17 @@ class FFTBufferAux : public AuxKernel
protected:
virtual Real computeValue() override;

const FFTBufferBase<Real> & _buffer;
/// buffer reference as generic parent class
const UserObject & _buffer;

///@{ specific buffer type, only one of those will be non-null
const FFTBufferBase<Real> * _real_buffer;
const FFTBufferBase<RealVectorValue> * _realvectorvalue_buffer;
const FFTBufferBase<RankTwoTensor> * _ranktwotensor_buffer;
const FFTBufferBase<RankThreeTensor> * _rankthreetensor_buffer;
const FFTBufferBase<RankFourTensor> * _rankfourtensor_buffer;
///@}

/// component to access
const std::vector<unsigned int> _component;
};
62 changes: 59 additions & 3 deletions src/auxkernels/FFTBufferAux.C
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,73 @@ validParams<FFTBufferAux>()
InputParameters params = validParams<AuxKernel>();
params.addClassDescription("Fetch values from an FFT buffer.");
params.addRequiredParam<UserObjectName>("fft_buffer", "Real valued FFT buffer object");
params.addParam<std::vector<unsigned int>>(
"component", std::vector<unsigned int>(), "Component to access for higher order types");
return params;
}

FFTBufferAux::FFTBufferAux(const InputParameters & parameters)
: AuxKernel(parameters), _buffer(getUserObject<FFTBufferBase<Real>>("fft_buffer"))
: AuxKernel(parameters),
_buffer(getUserObject<UserObject>("fft_buffer")),
_component(getParam<std::vector<unsigned int>>("component"))
{
// cast into all possible buffer options
_real_buffer = dynamic_cast<const FFTBufferBase<Real> *>(&_buffer);
_realvectorvalue_buffer = dynamic_cast<const FFTBufferBase<RealVectorValue> *>(&_buffer);
_ranktwotensor_buffer = dynamic_cast<const FFTBufferBase<RankTwoTensor> *>(&_buffer);
_rankthreetensor_buffer = dynamic_cast<const FFTBufferBase<RankThreeTensor> *>(&_buffer);
_rankfourtensor_buffer = dynamic_cast<const FFTBufferBase<RankFourTensor> *>(&_buffer);

// one of those should not result in a nullptr
if (_real_buffer)
{
if (_component.size() != 0)
paramError("component", "Do not specify a comonent for Real type FFT buffers.");
}
else if (_realvectorvalue_buffer)
{
if (_component.size() != 1)
paramError("component",
"Specify one index value to access a RealVectorValue type FFT buffer component.");
}
else if (_ranktwotensor_buffer)
{
if (_component.size() != 2)
paramError("component",
"Specify two index values to access a RankTwoTensor type FFT buffer component.");
}
else if (_rankthreetensor_buffer)
{
if (_component.size() != 3)
paramError(
"component",
"Specify three index values to access a RankThreeTensor type FFT buffer component.");
}
else if (_rankfourtensor_buffer)
{
if (_component.size() != 4)
paramError("component",
"Specify four index values to access a RankFourTensor type FFT buffer component.");
}
else
paramError("fft_buffer", "Unsupported buffer type");
}

Real
FFTBufferAux::computeValue()
{
std::cout << 'B';
return _buffer(_current_elem->centroid());
if (_real_buffer)
return (*_real_buffer)(_current_elem->centroid());
if (_realvectorvalue_buffer)
return (*_realvectorvalue_buffer)(_current_elem->centroid())(_component[0]);
if (_ranktwotensor_buffer)
return (*_ranktwotensor_buffer)(_current_elem->centroid())(_component[0], _component[1]);
if (_rankthreetensor_buffer)
return (*_rankthreetensor_buffer)(_current_elem->centroid())(
_component[0], _component[1], _component[2]);
if (_rankfourtensor_buffer)
return (*_rankfourtensor_buffer)(_current_elem->centroid())(
_component[0], _component[1], _component[2], _component[3]);
else
paramError("fft_buffer", "Unsupported buffer type");
}

0 comments on commit 5b56b55

Please sign in to comment.