Page MenuHomec4science

model.cpp
No OneTemporary

File Metadata

Created
Fri, May 31, 17:39

model.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 "model.hh"
#include "be_engine.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
/* -------------------------------------------------------------------------- */
Model::Model(const std::vector<Real>& system_size,
const std::vector<UInt>& discretization)
: system_size(system_size), discretization(discretization) {}
/* -------------------------------------------------------------------------- */
Model::~Model() = default;
/* -------------------------------------------------------------------------- */
void Model::setElasticity(Real E, Real nu) {
this->E = E;
this->nu = nu;
updateOperators();
}
/* -------------------------------------------------------------------------- */
Real Model::getHertzModulus() const { return E / (1 - nu * nu); }
/* -------------------------------------------------------------------------- */
GridBase<Real>& Model::getTraction() { return *traction; }
const GridBase<Real>& Model::getTraction() const { return *traction; }
/* -------------------------------------------------------------------------- */
GridBase<Real>& Model::getDisplacement() { return *displacement; }
const GridBase<Real>& Model::getDisplacement() const { return *displacement; }
/* -------------------------------------------------------------------------- */
const std::vector<Real>& Model::getSystemSize() const { return system_size; }
/* -------------------------------------------------------------------------- */
const std::vector<UInt>& Model::getDiscretization() const {
return discretization;
}
/* -------------------------------------------------------------------------- */
void Model::solveNeumann() {
engine->registerNeumann();
engine->solveNeumann(*traction, *displacement);
}
void Model::solveDirichlet() {
engine->registerDirichlet();
engine->solveDirichlet(*displacement, *traction);
}
/* -------------------------------------------------------------------------- */
IntegralOperator* Model::getIntegralOperator(const std::string& name) {
return operators[name].get();
}
/* -------------------------------------------------------------------------- */
void Model::updateOperators() {
for (auto& op : operators)
op.second->updateFromModel();
}
/* -------------------------------------------------------------------------- */
void Model::addDumper(std::shared_ptr<ModelDumper> dumper) {
this->dumpers.push_back(dumper);
}
void Model::dump() const {
for (auto& dumper : dumpers)
if (dumper)
dumper->dump(*this);
}
/* -------------------------------------------------------------------------- */
void Model::registerField(const std::string& name,
const GridBase<Real>& field) {
fields[name] = &field;
}
const GridBase<Real>& Model::getField(const std::string& name) const try {
return *fields.at(name);
} catch (std::out_of_range&e) {
std::cerr << "Field " << name << " not registered in model\n";
throw e;
}
/* -------------------------------------------------------------------------- */
std::ostream& operator<<(std::ostream& o, const Model& _this) {
o << "Model<" << _this.getType() << "> (E = " << _this.getYoungModulus()
<< ", nu = " << _this.getPoissonRatio() << ")\n";
// Printing domain size
o << " - domain = [";
std::for_each(_this.getSystemSize().begin(), _this.getSystemSize().end() - 1,
[&o](const Real& x) { o << x << ", "; });
o << _this.getSystemSize().back() << "]\n";
// Printing discretization
o << " - discretization = [";
std::for_each(_this.getDiscretization().begin(),
_this.getDiscretization().end() - 1,
[&o](const UInt& x) { o << x << ", "; });
o << _this.getDiscretization().back() << "]";
return o;
}
/* -------------------------------------------------------------------------- */
__END_TAMAAS__

Event Timeline