Page MenuHomec4science

volume_potential.hh
No OneTemporary

File Metadata

Created
Fri, May 10, 19:58

volume_potential.hh

/**
* @file
* @section LICENSE
*
* Copyright (©) 2016-19 EPFL (École Polytechnique Fédérale de Lausanne),
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://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>
/* -------------------------------------------------------------------------- */
namespace 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;
/// Initialize fourier buffers
void initialize(UInt source_components, UInt out_components);
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();
}
// Setting output buffer to zero
for (auto&& grid : disp_buffer)
grid = 0;
// 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();
}
}
} // namespace tamaas
#endif // VOLUME_POTENTIAL_HH

Event Timeline