Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F62915272
model.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
Thu, May 16, 12:12
Size
5 KB
Mime Type
text/x-c
Expires
Sat, May 18, 12:12 (2 d)
Engine
blob
Format
Raw Data
Handle
17698068
Attached To
rTAMAAS tamaas
model.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.hh"
#include "be_engine.hh"
#include "logger.hh"
/* -------------------------------------------------------------------------- */
namespace tamaas {
/* -------------------------------------------------------------------------- */
Model::Model(std::vector<Real> system_size, std::vector<UInt> discretization)
: system_size(std::move(system_size)),
discretization(std::move(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 getField("traction"); }
const GridBase<Real>& Model::getTraction() const {
return getField("traction");
}
/* -------------------------------------------------------------------------- */
GridBase<Real>& Model::getDisplacement() { return getField("displacement"); }
const GridBase<Real>& Model::getDisplacement() const {
return getField("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(getField("traction"), getField("displacement"));
}
void Model::solveDirichlet() {
engine->registerDirichlet();
engine->solveDirichlet(getField("displacement"), getField("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(std::move(dumper));
}
void Model::dump() const {
for (auto& dumper : dumpers)
if (dumper)
dumper->dump(*this);
}
/* -------------------------------------------------------------------------- */
void Model::registerField(const std::string& name,
std::shared_ptr<GridBase<Real>> field) {
fields[name] = std::move(field);
}
const GridBase<Real>& Model::getField(const std::string& name) const try {
return *fields.at(name);
} catch (std::out_of_range& e) {
Logger().get(LogLevel::warning)
<< "Field " << name << " not registered in model\n";
throw e;
}
GridBase<Real>& Model::getField(const std::string& name) try {
return *fields.at(name);
} catch (std::out_of_range& e) {
Logger().get(LogLevel::warning)
<< "Field " << name << " not registered in model\n";
throw e;
}
std::vector<std::string> Model::getFields() const {
std::vector<std::string> keys;
keys.reserve(fields.size());
std::transform(fields.begin(), fields.end(), std::back_inserter(keys),
[](auto&& pair) { return pair.first; });
return keys;
}
/* -------------------------------------------------------------------------- */
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;
}
/* -------------------------------------------------------------------------- */
} // namespace tamaas
Event Timeline
Log In to Comment