Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61221289
model_template.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sun, May 5, 07:31
Size
5 KB
Mime Type
text/x-c++
Expires
Tue, May 7, 07:31 (2 d)
Engine
blob
Format
Raw Data
Handle
17482118
Attached To
rTAMAAS tamaas
model_template.cpp
View Options
/**
* @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/>.
*
*/
/* -------------------------------------------------------------------------- */
#include "model_template.hh"
#include "influence.hh"
#include "westergaard.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
template <model_type type>
ModelTemplate<type>::ModelTemplate(const std::vector<Real>& system_size,
const std::vector<UInt>& discretization)
: Model(system_size, discretization) {
constexpr UInt dim = trait::dimension;
constexpr UInt dim_b = trait::boundary_dimension;
constexpr UInt nb_components = trait::components;
if (system_size.size() != dim)
TAMAAS_EXCEPTION("System size does not match model type");
if (discretization.size() != dim)
TAMAAS_EXCEPTION("Discretization size does not match model type");
// Copying sizes for traction grid
std::array<UInt, dim_b> traction_size;
auto disc_it = discretization.begin();
if (dim > dim_b)
++disc_it;
std::copy(disc_it, discretization.end(), traction_size.begin());
// Allocating
traction = std::make_unique<Grid<Real, dim_b>>(traction_size, nb_components);
displacement =
std::make_unique<Grid<Real, dim>>(discretization, nb_components);
registerField("traction", getTraction());
registerField("displacement", getDisplacement());
this->initializeBEEngine();
}
/* -------------------------------------------------------------------------- */
template <model_type type>
void ModelTemplate<type>::initializeBEEngine() {
engine = std::make_unique<BEEngineTmpl<type>>(this);
}
namespace {
template <typename T>
std::vector<T> extract(const std::vector<T>& v, UInt n) {
std::vector<T> ex(v.size() - n);
std::copy(v.begin() + n, v.end(), ex.begin());
return ex;
}
} // namespace
template <model_type type>
std::vector<UInt> ModelTemplate<type>::getBoundaryDiscretization() const {
return getDiscretization();
}
template <>
std::vector<UInt>
ModelTemplate<model_type::volume_1d>::getBoundaryDiscretization() const {
return extract(getDiscretization(), 1);
}
template <>
std::vector<UInt>
ModelTemplate<model_type::volume_2d>::getBoundaryDiscretization() const {
return extract(getDiscretization(), 1);
}
template <model_type type>
std::vector<Real> ModelTemplate<type>::getBoundarySystemSize() const {
return getSystemSize();
}
template <>
std::vector<Real>
ModelTemplate<model_type::volume_1d>::getBoundarySystemSize() const {
return extract(getSystemSize(), 1);
}
template <>
std::vector<Real>
ModelTemplate<model_type::volume_2d>::getBoundarySystemSize() const {
return extract(getSystemSize(), 1);
}
/* -------------------------------------------------------------------------- */
template <model_type type>
void ModelTemplate<type>::applyElasticity(GridBase<Real>& stress,
const GridBase<Real>& strain) const {
const influence::ElasticHelper<dim> elasticity(getShearModulus(),
getPoissonRatio());
// Checking number of components
if (strain.getNbComponents() == dim * dim) {
Loop::loop([&elasticity](auto sigma,
auto epsilon) { sigma = elasticity(epsilon); },
range<MatrixProxy<Real, dim, dim>>(stress),
range<MatrixProxy<const Real, dim, dim>>(strain));
}
// in case we have voigt notation
else if (strain.getNbComponents() == voigt_size<dim>::value) {
Loop::loop([&elasticity](auto sigma,
auto epsilon) { sigma = elasticity(epsilon); },
range<SymMatrixProxy<Real, dim>>(stress),
range<SymMatrixProxy<const Real, dim>>(strain));
}
else
TAMAAS_EXCEPTION("Strain components do not match dimension");
}
/* -------------------------------------------------------------------------- */
/* Template instanciation */
/* -------------------------------------------------------------------------- */
template class ModelTemplate<model_type::basic_1d>;
template class ModelTemplate<model_type::basic_2d>;
template class ModelTemplate<model_type::surface_1d>;
template class ModelTemplate<model_type::surface_2d>;
template class ModelTemplate<model_type::volume_1d>;
template class ModelTemplate<model_type::volume_2d>;
__END_TAMAAS__
Event Timeline
Log In to Comment