Page MenuHomec4science

westergaard.cpp
No OneTemporary

File Metadata

Created
Wed, May 8, 21:24

westergaard.cpp

/**
* @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/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "westergaard.hh"
#include "fft_plan_manager.hh"
#include "types.hh"
#include "loop.hh"
#include "static_types.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
template <model_type type>
Westergaard<type>::Westergaard(Model * model):
BEEngine(model)
{
// Copy sizes
std::array<UInt, trait::dimension> sizes;
std::copy(model->getDiscretization().begin(),
model->getDiscretization().end(),
sizes.begin());
auto hermitian_sizes =
GridHermitian<Real, trait::dimension>::hermitianDimensions(sizes);
// Copy boundary sizes
auto sizes_it = sizes.begin();
std::array<UInt, trait::boundary_dimension> boundary_hermitian_sizes;
// Ignoring first dimension if model is volumetric
if (trait::dimension > trait::boundary_dimension) ++sizes_it;
std::copy(sizes_it, sizes.end(), boundary_hermitian_sizes.begin());
boundary_hermitian_sizes =
GridHermitian<Real, trait::boundary_dimension>::
hermitianDimensions(boundary_hermitian_sizes);
constexpr UInt nb_components = trait::components;
buffer.setNbComponents(nb_components);
buffer.resize(boundary_hermitian_sizes);
influence.setNbComponents(nb_components * nb_components);
influence.resize(hermitian_sizes);
}
/* -------------------------------------------------------------------------- */
template <model_type type>
void Westergaard<type>::initInfluence() {
TAMAAS_EXCEPTION("Not implemented");
}
#define INFLUENCE_BASIC_MACRO do { \
constexpr UInt bdim = trait::boundary_dimension; \
auto wavevectors = \
FFTransform<Real, bdim>::computeFrequencies<true>(influence.sizes()); \
Real E_star = model->getHertzModulus(); \
StaticVector<const Real, bdim> domain(model->getSystemSize()[0]); \
Loop::stridedLoop \
([domain,E_star] CUDA_LAMBDA (StaticVector<Real, bdim>&& q_vec, Complex & inf) { \
q_vec *= 2 * M_PI; \
q_vec /= domain; \
inf = 2. / (q_vec.l2norm() * E_star); \
}, wavevectors, influence); \
influence(0) = 0; \
} while(0)
template <>
void Westergaard<model_type::basic_2d>::initInfluence() {
INFLUENCE_BASIC_MACRO;
}
template <>
void Westergaard<model_type::basic_1d>::initInfluence() {
INFLUENCE_BASIC_MACRO;
}
/* -------------------------------------------------------------------------- */
#define SOLVE_BASIC(op) do { \
Grid<Real, trait::boundary_dimension> \
& i = dynamic_cast<decltype(i)>(in); \
Grid<Real, trait::boundary_dimension> \
& o = dynamic_cast<decltype(o)>(out); \
\
auto & fwd = FFTPlanManager::get().createPlan(i, buffer); \
auto & bwd = FFTPlanManager::get().createPlan(o, buffer); \
\
fwd.forwardTransform(); \
buffer op influence; \
buffer(0) = 0; \
bwd.backwardTransform(); \
} while(0)
template <>
void Westergaard<model_type::basic_1d>::solveNeumann(GridBase<Real> & in,
GridBase<Real> & out) try {
SOLVE_BASIC(*=);
} catch(const std::bad_cast & e) {
TAMAAS_EXCEPTION("Neumann and dirichlet types do not match model type");
}
template <>
void Westergaard<model_type::basic_1d>::solveDirichlet(GridBase<Real> & in,
GridBase<Real> & out) try {
SOLVE_BASIC(/=);
} catch(const std::bad_cast & e) {
TAMAAS_EXCEPTION("Neumann and dirichlet types do not match model type");
}
template <>
void Westergaard<model_type::basic_2d>::solveNeumann(GridBase<Real> & in,
GridBase<Real> & out) try {
SOLVE_BASIC(*=);
} catch(const std::bad_cast & e) {
TAMAAS_EXCEPTION("Neumann and dirichlet types do not match model type");
}
template <>
void Westergaard<model_type::basic_2d>::solveDirichlet(GridBase<Real> & in,
GridBase<Real> & out) try {
SOLVE_BASIC(/=);
} catch(const std::bad_cast & e) {
TAMAAS_EXCEPTION("Neumann and dirichlet types do not match model type");
}
/* -------------------------------------------------------------------------- */
template <model_type type>
void Westergaard<type>::solveNeumann(GridBase<Real> & neumann,
GridBase<Real> & dirichlet) {
TAMAAS_EXCEPTION("Not yet implemented");
}
/* -------------------------------------------------------------------------- */
template <model_type type>
void Westergaard<type>::solveDirichlet(GridBase<Real> & neumann,
GridBase<Real> & dirichlet) {
TAMAAS_EXCEPTION("Not yet implemented");
}
/* -------------------------------------------------------------------------- */
/* Template instanciation */
/* -------------------------------------------------------------------------- */
template class Westergaard<model_type::basic_1d>;
template class Westergaard<model_type::basic_2d>;
template class Westergaard<model_type::surface_1d>;
template class Westergaard<model_type::surface_2d>;
template class Westergaard<model_type::volume_1d>;
template class Westergaard<model_type::volume_2d>;
/* -------------------------------------------------------------------------- */
__END_TAMAAS__
/* -------------------------------------------------------------------------- */

Event Timeline