Page MenuHomec4science

ve_engine.hh
No OneTemporary

File Metadata

Created
Mon, Nov 4, 20:33

ve_engine.hh

/**
* @file
*
* @author Lucas Frérot <lucas.frerot@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2017 EPFL (Ecole Polytechnique Fédérale de
* Lausanne) Laboratory (LSMS - Laboratoire de Simulation en Mécanique des
* Solides)
*
* Tamaas is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* Tamaas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tamaas. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
#ifndef __VE_ENGINE_HH__
#define __VE_ENGINE_HH__
/* -------------------------------------------------------------------------- */
#include "tamaas.hh"
#include "grid_base.hh"
#include "grid_view.hh"
#include "grid_hermitian.hh"
#include "model_type.hh"
#include "fft_plan_manager.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/// Forward declaration
class Model;
/**
* @brief Volume equation engine class. Applies the operators for computation
* of displacements and strains due to residual/eigen strains
*/
class VEEngine {
public:
/// Constructor
VEEngine(Model* model) : model(model) {}
/// Destructor
virtual ~VEEngine() = default;
// Methods to override
public:
/// Compute displacement field in volume to to a volume force distribution
virtual void applyVolumeForcePotential(GridBase<Real>& source,
GridBase<Real>& out) const = 0;
/// Compute displacement field in volume due to an initial stress distribution
virtual void applyVolumeStressPotential(GridBase<Real>& source,
GridBase<Real>& out) const = 0;
/// Compute strain field in volume due to an initial stress distribution
virtual void applyHypersingularStressPotential(GridBase<Real>& source,
GridBase<Real>& out) const = 0;
protected:
Model* model;
};
/**
* @brief Templated class to manage application of functor on fields in Fourier
* space.
*/
template <model_type type>
class VEEngineTmpl : public VEEngine {
using trait = model_type_traits<type>;
public:
VEEngineTmpl(Model * model);
protected:
/// Function to handle layer-by-layer Fourier treatment of operators
template <typename Func>
void fourierApply(Func func, GridBase<Real>& in, GridBase<Real>& out) const;
protected:
Grid<Real, trait::boundary_dimension> wavevectors;
using BufferType = GridHermitian<Real, trait::boundary_dimension>;
mutable std::vector<BufferType> source_buffers;
mutable std::vector<BufferType> disp_buffers;
};
/* -------------------------------------------------------------------------- */
/* Template implementation */
/* -------------------------------------------------------------------------- */
template <model_type type>
template <typename Func>
void VEEngineTmpl<type>::fourierApply(Func func, GridBase<Real>& in,
GridBase<Real>& out) const {
constexpr UInt dim = trait::dimension;
Grid<Real, dim>& i = dynamic_cast<decltype(i)>(in);
Grid<Real, dim>& o = dynamic_cast<decltype(o)>(out);
TAMAAS_ASSERT(i.sizes().front() == o.sizes().front(),
"Number of layers does not match");
for (UInt layer : Loop::range(i.sizes().front())) {
auto in_layer = make_view(i, layer);
FFTPlanManager::get()
.createPlan(in_layer, source_buffers[layer])
.forwardTransform();
}
func(source_buffers, disp_buffers);
for (UInt layer : Loop::range(i.sizes().front())) {
auto out_layer = make_view(o, layer);
FFTPlanManager::get()
.createPlan(out_layer, disp_buffers[layer])
.backwardTransform();
}
}
__END_TAMAAS__
#endif // __VE_ENGINE_HH__

Event Timeline