Page MenuHomec4science

stimulation_temperature_point.cc
No OneTemporary

File Metadata

Created
Sun, Aug 4, 05:15

stimulation_temperature_point.cc

/**
* @file stimulation_temperature_point.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
* @author Srinivasa Babu Ramisetti <srinivasa.ramisetti@epfl.ch>
*
* @date Thu Sep 18 16:13:19 2014
*
* @brief Set a given temperature to a set of DOFs
*
* @section LICENSE
*
* Copyright (©) 2010-2011 EPFL (Ecole Polytechnique Fédérale de Lausanne)
* Laboratory (LSMS - Laboratoire de Simulation en Mécanique des Solides)
*
* LibMultiScale 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.
*
* LibMultiScale 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 LibMultiScale. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
#include "lm_common.hh"
#include "stimulation_temperature.hh"
#include "lib_md.hh"
#include "lib_dd.hh"
#include "lib_continuum.hh"
#include "filter.hh"
#include "compute_ekin.hh"
#include "math_tools.hh"
#include "ref_point_data.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
// Needed for Gaussian distribution when reassigning velocities/temperature
Real GaussianRand(){
Real x1, x2, w;
//UInt *seed = &randSeed;
do{
x1 = 2.0 * drand48() - 1.0;
x2 = 2.0 * drand48() - 1.0;
//x1 = RANDOM_abs1( seed );
//x2 = RANDOM_abs1( seed );
w = x1*x1 + x2*x2;
}
while( w >= 1.0 );
w = sqrt( (-2.0 * log( w )) / w );
return x1 * w;
}
/* -------------------------------------------------------------------------- */
template <typename Cont>
void StimulationTemperature<Cont>::stimulate(Cont & cont, UInt stage)
{
static const UInt Dim = Cont::Dim;
MathTools::setSeed(seed);
typedef typename Cont::Ref RefDof;
typename Cont::iterator it = cont.getIterator();
for (RefDof at = it.getFirst() ; !it.end() ; at = it.getNext()) {
Real pos0[Dim];
at.getPositions0(pos0);
for (UInt i = 0 ; i < Dim ; ++i) at.velocity(i) = GaussianRand(); //drand48()-.5;
}
ComputeEKin<Cont> compute_ekin("ComputeEkin:"+this->getID(),Dim);
compute_ekin.build(cont);
Real T_ = compute_ekin.get(1);
Real alpha = sqrt(temperature/T_);
for (RefDof at = it.getFirst() ; !it.end() ; at = it.getNext()) {
DUMP("procede a la stimulation de l'atome a la position " << at,DBG_INFO);
for (UInt i = 0; i < Dim; ++i) at.velocity(i) *= alpha;
}
}
/* -------------------------------------------------------------------------- */
DECLARE_STIMULATION(StimulationTemperature,LIST_ATOM_MODEL)
DECLARE_STIMULATION(StimulationTemperature,LIST_DD_MODEL)
DECLARE_STIMULATION_REFPOINT(StimulationTemperature)
DECLARE_STIMULATION_GENERIC_MESH(StimulationTemperature)
__END_LIBMULTISCALE__

Event Timeline