Skip to content

Commit

Permalink
FFT buffer base class template (idaholab#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Jan 16, 2020
1 parent 7563af3 commit 401fadc
Show file tree
Hide file tree
Showing 2 changed files with 215 additions and 0 deletions.
63 changes: 63 additions & 0 deletions include/userobjects/FFTBufferBase.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/

#pragma once

#include "GeneralUserObject.h"

template <typename T>
class FFTBufferBase;

/**
*
*/
template <typename T>
class FFTBufferBase : public GeneralUserObject
{
public:
FFTBufferBase(const InputParameters & parameters);

virtual void initialize() {}
virtual void execute() {}
virtual void finalize() {}

// transforms
virtual void forward() = 0;
virtual void backward() = 0;

// data access
const T & operator[](std::size_t i) const { return _buffer[i]; }
T & operator[](std::size_t i) { return _buffer[i]; }

// size buffer
void resize();
void resize(std::size_t ni);
void resize(std::size_t ni, std::size_t nj);
void resize(std::size_t ni, std::size_t nj, std::size_t nk);

protected:
/// get the addres of the first data element of the ith object in the bufefr
Real * start(std::size_t i);

/// get the number of transforms required for type T
std::size_t howMany() const;

std::size_t _dim;

std::size_t _ni;
std::size_t _nj;
std::size_t _nk;

std::vector<T> _buffer;

/// pointer to the start of the data
Real * _start;

/// stride in units of double size
std::ptrdiff_t _stride;
};
152 changes: 152 additions & 0 deletions src/userobjects/FFTBufferBase.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
/**********************************************************************/
/* DO NOT MODIFY THIS HEADER */
/* MAGPIE - Mesoscale Atomistic Glue Program for Integrated Execution */
/* */
/* Copyright 2017 Battelle Energy Alliance, LLC */
/* ALL RIGHTS RESERVED */
/**********************************************************************/
#include "FFTBufferBase.h"
#include "MooseTypes.h"
#include "RankTwoTensor.h"
#include "RankThreeTensor.h"
#include "RankFourTensor.h"

// template <>
// InputParameters
// validParams<FFTBufferBase>()
// {
// InputParameters params = validParams<GeneralUserObject>();
// params.addClassDescription("");
// return params;
// }

template <typename T>
FFTBufferBase<T>::FFTBufferBase(const InputParameters & parameters) : GeneralUserObject(parameters)
{
}

template <typename T>
void
FFTBufferBase<T>::resize()
{
if (sizeof(Real) != sizeof(double))
mooseError("Invalid Real type size");
_buffer.resize(_ni * _nj * _nk);

// redo plan / pointers
auto istart = start(0);
std::ptrdiff_t istride = reinterpret_cast<char *>(start(1)) - reinterpret_cast<char *>(istart);
if (istride % sizeof(Real) != 0)
mooseError("Invalid data alignment");
istride /= sizeof(Real);
}

template <typename T>
void
FFTBufferBase<T>::resize(std::size_t ni)
{
_ni = ni;
_nj = 1;
_nk = 1;
_dim = 1;
resize();
}

template <typename T>
void
FFTBufferBase<T>::resize(std::size_t ni, std::size_t nj)
{
_ni = ni;
_nj = nj;
_nk = 1;
_dim = 2;
resize();
}

template <typename T>
void
FFTBufferBase<T>::resize(std::size_t ni, std::size_t nj, std::size_t nk)
{
_ni = ni;
_nj = nj;
_nk = nk;
_dim = 3;
resize();
}

template <>
Real *
FFTBufferBase<Real>::start(std::size_t i)
{
return &_buffer[i];
}

template <>
Real *
FFTBufferBase<RealVectorValue>::start(std::size_t i)
{
return &_buffer[i](0);
}

template <>
Real *
FFTBufferBase<RankTwoTensor>::start(std::size_t i)
{
return &_buffer[i](0, 0);
}

template <>
Real *
FFTBufferBase<RankThreeTensor>::start(std::size_t i)
{
return &_buffer[i](0, 0, 0);
}

template <>
Real *
FFTBufferBase<RankFourTensor>::start(std::size_t i)
{
return &_buffer[i](0, 0, 0, 0);
}

template <>
std::size_t
FFTBufferBase<Real>::howMany() const
{
return 1;
}

template <>
std::size_t
FFTBufferBase<RealVectorValue>::howMany() const
{
return LIBMESH_DIM;
}

template <>
std::size_t
FFTBufferBase<RankTwoTensor>::howMany() const
{
return LIBMESH_DIM * LIBMESH_DIM;
}

template <>
std::size_t
FFTBufferBase<RankThreeTensor>::howMany() const
{
return LIBMESH_DIM * LIBMESH_DIM * LIBMESH_DIM;
}

template <>
std::size_t
FFTBufferBase<RankFourTensor>::howMany() const
{
return LIBMESH_DIM * LIBMESH_DIM * LIBMESH_DIM * LIBMESH_DIM;
}

// explicit instantiation
template class FFTBufferBase<Real>;
template class FFTBufferBase<RealVectorValue>;
template class FFTBufferBase<RankTwoTensor>;
template class FFTBufferBase<RankThreeTensor>;
template class FFTBufferBase<RankFourTensor>;

0 comments on commit 401fadc

Please sign in to comment.