diff --git a/src/model/kelvin.cpp b/src/model/kelvin.cpp index e886a94..11599e8 100644 --- a/src/model/kelvin.cpp +++ b/src/model/kelvin.cpp @@ -1,140 +1,144 @@ /** * @file * @section LICENSE * * Copyright (©) 2016-2020 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 . * */ /* -------------------------------------------------------------------------- */ #include "kelvin.hh" #include "logger.hh" /* -------------------------------------------------------------------------- */ namespace tamaas { /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ /* Constructors */ /* -------------------------------------------------------------------------- */ template Kelvin::Kelvin(Model* model) : VolumePotential(model) { setIntegrationMethod(integration_method::linear, 1e-12); } template void Kelvin::setIntegrationMethod(integration_method method, Real cutoff) { this->method = method; this->cutoff = cutoff; + Logger logger; + if (this->method == integration_method::linear) { - Logger().get(LogLevel::debug) + logger.get(LogLevel::debug) << "[Kelvin " << this << "] Setting linear integration method\n"; this->initialize(dtrait::template source_components, dtrait::template out_components, this->model->getDiscretization()[0]); } else { - Logger().get(LogLevel::debug) + logger.get(LogLevel::debug) << "[Kelvin " << this << "] Setting cutoff integration method (cutoff " << this->cutoff << ")\n"; this->initialize(dtrait::template source_components, dtrait::template out_components, 1); } auto max_q = Loop::reduce( [](auto qv) { return qv.l2norm(); }, range>( this->wavevectors)); if (this->method == integration_method::linear and not std::isfinite(std::exp(max_q * this->model->getSystemSize()[0]))) - TAMAAS_EXCEPTION("Probable overflow of integral computation (change " - "integration method to integration_method::cutoff)"); + logger.get(LogLevel::warning) + << "[Kelvin " << this + << "] Probable overflow of integral computation (consider " + "changing integration method to integration_method::cutoff)\n"; } /* -------------------------------------------------------------------------- */ /* Operator implementation */ /* -------------------------------------------------------------------------- */ template void Kelvin::applyIf(GridBase& source, GridBase& out, filter_t pred) const { KelvinInfluence kelvin(this->model->getShearModulus(), this->model->getPoissonRatio()); parent::transformSource(source, pred); // Reset buffer values for (auto&& layer : this->out_buffer) layer = 0; if (method == integration_method::linear) { linearIntegral(out, kelvin); } else { cutoffIntegral(out, kelvin); } } template void Kelvin::linearIntegral(GridBase& out, KelvinInfluence& kelvin) const { detail::KelvinHelper helper; helper.applyIntegral(this->source_buffer, this->out_buffer, this->wavevectors, this->model->getSystemSize().front(), kelvin); helper.applyFreeTerm(this->source_buffer, this->out_buffer, kelvin); helper.makeFundamentalGreatAgain(this->out_buffer); parent::transformOutput( [](auto&& out_buffer, auto layer) -> typename parent::BufferType& { return out_buffer[layer]; }, out); } template void Kelvin::cutoffIntegral(GridBase& out, KelvinInfluence& kelvin) const { detail::KelvinHelper helper; auto func = [&](auto&& out_buffer, auto layer) -> typename parent::BufferType& { auto&& out = out_buffer.front(); out = 0; helper.applyIntegral(this->source_buffer, out, layer, this->wavevectors, this->model->getSystemSize().front(), cutoff, kelvin); helper.applyFreeTerm(this->source_buffer[layer], out, kelvin); helper.makeFundamentalGreatAgain(out); return out; }; parent::transformOutput(func, out); } /* -------------------------------------------------------------------------- */ /* Template instanciation */ /* -------------------------------------------------------------------------- */ template class Kelvin; template class Kelvin; template class Kelvin; /* -------------------------------------------------------------------------- */ } // namespace tamaas