Page MenuHomec4science

bem_penalty.cpp
No OneTemporary

File Metadata

Created
Mon, Jul 8, 08:02

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 <vector>
#include "surface.hh"
#include "bem_penalty.hh"
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <sstream>
#include <cmath>
/* -------------------------------------------------------------------------- */
#define TIMER
#include "surface_timer.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_TAMAAS__
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();
Real f = 1e300;
std::cout << "moyenne deplacement "<< SurfaceStatistics::computeAverage(this->true_displacements, 0)<< std::endl;
convergence_iterations.clear();
nb_iterations = 0;
max_iterations =100000;
while (f> epsilon && nb_iterations++ < max_iterations) {
this->functional->computeGradF();
this->computeSearchDirection(mean_displacement,penalization_parameter);
Real alpha=0.0005;
// alpha=computeOptimalStep();
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;
}
// std::cout << "moyenne deplacement "<< SurfaceStatistics::computeAverage(this->true_displacements, 0)<< std::endl;
convergence_iterations.push_back(f);
// if(nb_iterations == 4) return 0;
}
this->computePressures(mean_displacement);
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;
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");
search_direction.FFTTransform(spectral_search_direction, nthreads);
UInt n = surface.size();
UInt size = n*n;
spectral_search_direction(0) = 0;
#pragma omp parallel for
for (UInt i = 1; i < size; ++i) {
spectral_search_direction(i) /= this->surface_spectral_influence_disp(i);
}
// /!\ does not contain the spectral search direction anymore
spectral_search_direction.FFTITransform(nthreads);
// Real average = SurfaceStatistics::computeAverage(spectral_search_direction.real(), 0);
//spectral_search_direction -= average;
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 += spectral_search_direction(i).real() * 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) {
UInt n = surface.size();
UInt size = n*n;
Real moy_surface=SurfaceStatistics::computeAverage(this->surface, 0);
this->true_displacements.FFTTransform(this->surface_spectral_tractions, nthreads);
this->surface_spectral_tractions(0) = 0;
#pragma omp parallel for
for (UInt i = 1 ; i < size ; ++i) {
this->surface_spectral_tractions(i) /= this->surface_spectral_influence_disp(i);
}
this->surface_spectral_tractions.FFTITransform(this->surface_tractions, nthreads);
Real true_pressure = 0.;
for (UInt i = 0 ; i < n * n ; i++) {
if (gap(i)>=0.){
true_pressure+=this->surface_tractions(i)*(this->true_displacements(i)-mean_displacement-this->surface(i))-0.002/2.071e-3 * exp(- gap(i) / 2.071e-3)*gap(i);
// true_pressure+=this->surface_tractions(i)*(this->true_displacements(i)-mean_displacement-this->surface(i));
}
}
true_pressure/=(moy_surface*size-mean_displacement*size);
// std::cout << "true_pressure "<< true_pressure << std::endl;
//this->surface_tractions += true_pressure;
//this->surface_tractions= this->old_displacements - true_displacements;
}
/* -------------------------------------------------------------------------- */
__END_TAMAAS__

Event Timeline