Page MenuHomec4science

AMELCG.cc
No OneTemporary

File Metadata

Created
Wed, Oct 9, 01:47

AMELCG.cc

/* ./amel/AMELCG.cpp
**********************************
Copyright INRIA and CEA
author : Guillaume ANCIAUX (guillaume.anciaux@epfl.ch, g.anciaux@laposte.net)
The LibMultiScale is a C++ parallel framework for the multiscale
coupling methods dedicated to material simulations. This framework
provides an API which makes it possible to program coupled simulations
and integration of already existing codes.
This Project is done in a collaboration between INRIA Futurs Bordeaux
within ScAlApplix team and CEA/DPTA Ile de France.
This software is governed by the CeCILL-C license under French law and
abiding by the rules of distribution of free software. You can use,
modify and/ or redistribute the software under the terms of the CeCILL-C
license as circulated by CEA, CNRS and INRIA at the following URL
"http://www.cecill.info".
As a counterpart to the access to the source code and rights to copy,
modify and redistribute granted by the license, users are provided only
with a limited warranty and the software's author, the holder of the
economic rights, and the successive licensors have only limited
liability.
In this respect, the user's attention is drawn to the risks associated
with loading, using, modifying and/or developing or reproducing the
software by the user in light of its specific status of free software,
that may mean that it is complicated to manipulate, and that also
therefore means that it is reserved for developers and experienced
professionals having in-depth computer knowledge. Users are therefore
encouraged to load and test the software's suitability as regards their
requirements in conditions enabling the security of their systems and/or
data to be ensured and, more generally, to use and operate it in the
same conditions as regards security.
The fact that you are presently reading this means that you have had
knowledge of the CeCILL-C license and that you accept its terms.
***********************************/
#define TIMER
#define MAIN_SOURCE
#include "lm_common.hh"
#include "domain_multiscale.hh"
#include "algebraic_parser.hh"
#include "action_manager.hh"
using namespace libmultiscale;
/* -------------------------------------------------------------------------- */
#include <iostream>
#include <iomanip>
#include <mpi.h>
/* -------------------------------------------------------------------------- */
void Usage(const std::string & name){
std::cout << "Usage : " << name << " config_file nb_quasi_step nb_convergence_step\n"
<< "\t config_file : global config file of the simulation\n"
<< "\t nb_time_step : number of quasi step wanted to be done (>=0)\n"
<< "\t nb_convergence_step : max number of convergence step to be done\n";
lm_exit(LM_EXIT_FAILURE);
}
#define ALPHA_REDUCE 0.5
#define BACKTRACK_SLOPE 0.5
// UInt LineSearchScan(DomainMultiScale & dom,StimulationMultiScale & stimulator,Real dmax,Real & eng, UInt & neval){
// Real fdotdir = dom.getFdotDir();
// Real dirmax = dom.getDirMax();
// //Real dirmax_original = dirmax;
// Real alphamax = dmax/dirmax;
// Real fnorm2 = dom.getFNorm2();
// Real fnorm2_original = fnorm2;
// Real alpha = alphamax;
// Real alpha_previous = 0.0;
// Real delta;
// eng = dom.getEpot();;
// Real eoriginal = eng;
// //Real fmax_original = dom.getFMax();
// //Real fmax = fmax_original;
// // std::cerr << "eng " << eng << " alpha " << alpha << " fmax " << fmax << " fdotdir " << fdotdir << std::endl;
// while (1) {
// delta = alpha - alpha_previous;
// // apply displacement constraUInt (pre force disp update)
// stimulator.stimulate(PRE_STEP1);
// // displace along direction
// dom.displaceTowardsDirection(delta);
// // apply displacement constraUInt (pre force compute)
// stimulator.stimulate(PRE_STEP2);
// // recompute forces
// dom.performStep2();
// // apply post forces stimulations
// stimulator.stimulate(PRE_STEP3);
// // recompute fnorm
// fnorm2 = dom.getFNorm2();
// // fmax = dom.getFMax();
// // get potential energy
// eng = dom.getEpot();
// neval++;
// // DUMPBYPROC("eng " << eng << " fnorm2 " << fnorm2 << " epsilon " << fnorm2_original << " alpha " << alpha << " fmax " << fmax,DBG_ERROR,0);
// // if (lm_my_proc_id == 0)
// // std::cerr << "eng " << eng << " epsilon " << eoriginal << " alpha " << alpha << " delta " << delta << " dirmax " << dirmax << std::endl;
// if (eng <= eoriginal - BACKTRACK_SLOPE*alpha*fdotdir) return 0;
// if (fnorm2 <= fnorm2_original) return 0;
// //if (fmax <= fmax_original) return 0;
// alpha_previous = alpha;
// alpha *= ALPHA_REDUCE;
// if (alpha == 0) {
// dom.displaceTowardsDirection(-alpha_previous);
// // recompute forces
// dom.performStep2();
// // apply post forces stimulations
// stimulator.stimulate(PRE_STEP3);
// return 1;
// }
// }
// }
int main(int argc, char ** argv)
{
if (argc != 4){
Usage(argv[0]);
}
loadModules(argc,argv); //loading the modules macro
UInt nb_step = atoi(argv[2]);
UInt nb_convergence_step = atoi(argv[3]);
MPI_Barrier(MPI_COMM_WORLD);
// UInt frequency = 1;
MPI_Barrier(MPI_COMM_WORLD);
STARTTIMER("Init");
DomainMultiScale & dom = DomainMultiScale::getManager();
dom.build(argv[1]);
ActionManager & actions = dom.getActionManager();
STOPTIMER("Init");
nb_step+= current_step;
// Real norm2 = 0;
UInt fail = 0;
// Real dmax=0.1;
UInt nforce_compute = 0;
UInt max_eval = 1000000;
Real ftol = 1e-3;
Real gg;
Real fdotOldf;
for (UInt i = 0 ; i < nb_step ; ++i) {
current_step = i*nb_convergence_step;
dom.performStep2();
//initialize the things
// apply displacement constraUInt (pre force disp update)
current_stage = PRE_STEP1;
actions.action();
// apply displacement constraUInt (pre force compute)
current_stage = PRE_STEP2;
actions.action();
// recompute forces
dom.performStep2();
// apply post forces stimulations
current_stage = PRE_STEP3;
actions.action();
// compute fnorm
Real fnorm2 = dom.getFNorm2();
gg = fnorm2;
Real eng = dom.getEpot();
// if (lm_my_proc_id == 0)
// std::cerr << "LM SIDE fnorm2_init " << fnorm2 << std::endl;
// Real einitial = dom.getEpot();
// if (lm_my_proc_id == 0)
// std::cerr << "LM SIDE einitial " << einitial << std::endl;
++current_step;
for (; current_step < (i+1)*nb_convergence_step ; ++current_step)
{
// search minimum value along line which is stored in velocity field for convenience
// fail = LineSearchScan(dom,actions,dmax,eng,nforce_compute);
if (fail) {
DUMPBYPROC("linescan FAIL",DBG_MESSAGE,0);
break;
}
if (nforce_compute >= max_eval) LM_FATAL("MAXEVAL " << nforce_compute);
fnorm2 = dom.getFNorm2();
Real fmax = dom.getFMax();
fdotOldf = dom.getFdotOldF();
if (lm_my_proc_id==0)
std::cerr << "converging -> norm force = " << fnorm2 << " fmax " << fmax
<< " epot " << eng << " descending step "
<< nforce_compute << " nb search = " << current_step << std::endl;
// if (lm_my_proc_id == 0)
// std::cerr << "LM SIDE " << fnorm2 << " " << fdotOldf << std::endl;
// force tolerance criterion
if (fmax < ftol) {
DUMPBYPROC("FTOL " << fmax,DBG_MESSAGE,0);
break;
}
// update h from new f = -Grad(x) and old g
//beta = dotall[0]/gg would be Fletcher-Reeves CG
Real beta = std::max(0.0,(fnorm2 - fdotOldf)/gg);
gg = fnorm2;
// if (lm_my_proc_id == 0)
// std::cerr << "LM SIDE beta " << beta << std::endl;
dom.saveForceVector();
dom.updateDirection(beta);
}
}
closeModules(); // closing the modules macro
lm_exit(LM_EXIT_SUCCESS);
}

Event Timeline