Page MenuHomec4science

bem_penalty.cpp
No OneTemporary

File Metadata

Created
Tue, May 7, 00:51

bem_penalty.cpp

/**
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @section LICENSE
*
* Copyright (©) 2016 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 "bem_penalty.hh"
#include "surface.hh"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <vector>
/* -------------------------------------------------------------------------- */
#define TIMER
#include "surface_timer.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
void BemPenalty::computeTractionsFromDisplacements() {
this->applyInverseInfluenceFunctions(this->true_displacements,
this->surface_tractions);
}
Real BemPenalty::computeEquilibrium(Real epsilon, Real mean_displacement,
Real penalization_parameter) {
this->computeSpectralInfluenceOverDisplacement();
this->search_direction = 0.;
this->true_displacements = 0;
this->true_displacements = mean_displacement;
this->computeGaps();
std::ofstream file("output.txt");
Real f = 1e300;
std::cout << "moyenne deplacement "
<< SurfaceStatistics::computeAverage(this->true_displacements, 0)
<< std::endl;
convergence_iterations.clear();
nb_iterations = 0;
max_iterations = 5000;
while (f > epsilon && nb_iterations++ < max_iterations) {
this->functional->computeGradFU();
this->computeSearchDirection(mean_displacement, penalization_parameter);
Real alpha = 0.001;
this->old_displacements = this->true_displacements;
this->updateUnknown(alpha, mean_displacement);
this->computeGaps();
f = computeStoppingCriterion();
if (nb_iterations % dump_freq == 0) {
std::cout << std::scientific << std::setprecision(10) << nb_iterations
<< " " << f << std::fixed << std::endl;
this->computePressures(mean_displacement);
Real orth = 0.;
UInt n = surface.size();
UInt size = n * n;
#pragma omp parallel for reduction(+ : orth)
for (UInt i = 0; i < size; ++i) {
orth += std::abs(surface_tractions(i) *
(this->true_displacements(i) - surface(i)));
}
file << std::scientific << std::setprecision(10) << nb_iterations << " "
<< f << " " << orth << std::endl;
}
convergence_iterations.push_back(f);
}
this->computePressures(mean_displacement);
file.close();
return f;
}
/* -------------------------------------------------------------------------- */
Real BemPenalty::computeStoppingCriterion() {
Real crit = 0.;
Real disp_norm = 0.;
UInt n = surface.size();
UInt size = n * n;
#pragma omp parallel for reduction(+ : crit, disp_norm)
for (UInt i = 0; i < size; ++i) {
crit += this->search_direction(i) * this->search_direction(i);
disp_norm += (true_displacements(i) * true_displacements(i));
}
return crit / disp_norm;
}
/* -------------------------------------------------------------------------- */
void BemPenalty::computeSearchDirection(Real mean_displacement,
Real penalization_parameter) {
STARTTIMER("computeOptimalStep");
UInt n = surface.size();
UInt size = n * n;
const Surface<Real>& gradF = this->functional->getGradF();
#pragma omp parallel for
for (UInt i = 1; i < size; ++i) {
this->search_direction(i) = gradF(i);
if (gap(i) < 0) {
this->search_direction(i) += penalization_parameter * gap(i);
}
}
}
/* -------------------------------------------------------------------------- */
Real BemPenalty::computeOptimalStep() {
STARTTIMER("computeOptimalStep");
this->applyInverseInfluenceFunctions(search_direction, surface_r);
UInt n = surface.size();
UInt size = n * n;
Real numerator = 0., denominator = 0.;
#pragma omp parallel for reduction(+ : numerator, denominator)
for (UInt i = 0; i < size; ++i) {
numerator += search_direction(i) * search_direction(i);
denominator += surface_r(i) * search_direction(i);
}
Real alpha = numerator / denominator;
STOPTIMER("computeOptimalStep");
return alpha;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void BemPenalty::updateUnknown(Real alpha, Real mean_displacement) {
STARTTIMER("updateDisplacements");
UInt n = surface.size();
UInt size = n * n;
#pragma omp parallel for
for (UInt i = 0; i < size; ++i) {
this->true_displacements(i) -= alpha * this->search_direction(i);
}
Real moyenne = SurfaceStatistics::computeAverage(this->true_displacements, 0);
for (UInt i = 0; i < size; ++i) {
this->true_displacements(i) =
this->true_displacements(i) - moyenne + mean_displacement;
}
STOPTIMER("updateDisplacements");
}
/* -------------------------------------------------------------------------- */
void BemPenalty::computePressures(Real mean_displacement) {
this->computeTractionsFromDisplacements();
this->functional->computeGradFU();
// const Surface<Real> & gradF = this->functional->getGradF();
// Real min = SurfaceStatistics::computeMinimum(gradF);
this->surface_tractions -= this->surface_tractions(0);
}
/* -------------------------------------------------------------------------- */
__END_TAMAAS__

Event Timeline