Page MenuHomec4science

volume_potential.hh
No OneTemporary

File Metadata

Created
Fri, May 10, 01:36

volume_potential.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 VOLUME_POTENTIAL_HH
#define VOLUME_POTENTIAL_HH
/* -------------------------------------------------------------------------- */
#include "fft_plan_manager.hh"
#include "grid_hermitian.hh"
#include "grid_view.hh"
#include "integral_operator.hh"
#include "model_type.hh"
/* -------------------------------------------------------------------------- */
#include <functional>
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/**
* @brief Volume potential operator class. Applies the operators for computation
* of displacements and strains due to residual/eigen strains
*/
template <model_type type>
class VolumePotential : public IntegralOperator {
using trait = model_type_traits<type>;
protected:
using filter_t = std::function<bool(UInt)>;
public:
VolumePotential(Model* model);
/// Update from model (does nothing)
void updateFromModel() override {}
/// Kind
IntegralOperator::kind getKind() const override {
return IntegralOperator::neumann;
}
/// Type
model_type getType() const override;
/// Applying to all source
void apply(GridBase<Real>& input, GridBase<Real>& output) const override {
applyIf(input, output, [](UInt) { return true; });
}
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 {
fourierApplyIf(func, in, out, [](UInt) { return true; });
}
/// Function to handle layer-by-layer Fourier treatment of operators
template <typename Func>
void fourierApplyIf(Func func, GridBase<Real>& in, GridBase<Real>& out,
filter_t pred) const;
protected:
Grid<Real, trait::boundary_dimension> wavevectors;
using BufferType = GridHermitian<Real, trait::boundary_dimension>;
mutable std::vector<BufferType> source_buffer;
mutable std::vector<BufferType> disp_buffer;
};
/* -------------------------------------------------------------------------- */
/* Template implementation */
/* -------------------------------------------------------------------------- */
template <model_type type>
template <typename Func>
void VolumePotential<type>::fourierApplyIf(Func func, GridBase<Real>& in,
GridBase<Real>& out,
filter_t pred) 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");
// ^^^^ not applicable for Boussinesq
// Transforming source
for (UInt layer : Loop::range(i.sizes().front())) {
if (not pred(layer))
continue;
auto in_layer = make_view(i, layer);
FFTPlanManager::get()
.createPlan(in_layer, source_buffer[layer])
.forwardTransform();
}
// Applying operator
func(source_buffer, disp_buffer);
// Transforming output
for (UInt layer : Loop::range(o.sizes().front())) {
auto out_layer = make_view(o, layer);
FFTPlanManager::get()
.createPlan(out_layer, disp_buffer[layer])
.backwardTransform();
}
}
__END_TAMAAS__
#endif // VOLUME_POTENTIAL_HH

Event Timeline