Page MenuHomec4science

epot_hook.cc
No OneTemporary

File Metadata

Created
Tue, Jul 9, 11:42

epot_hook.cc

/**
* @file epot_hook.cc
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Fri May 10 14:59:01 2013
*
* @brief LAMMPS hook to recompute potential energy
*
* @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 "lammps.h"
#include "force.h"
#include "pair.h"
#include "atom.h"
#include "modify.h"
#include "atom_vec.h"
#include <vector>
#include "epot_hook.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
EpotHookLammps::EpotHookLammps(LAMMPS_NS::LAMMPS * lmp){
computed = false;
time = 0;
lammps_object = lmp;
}
/* -------------------------------------------------------------------------- */
EpotHookLammps::~EpotHookLammps(){
}
/* -------------------------------------------------------------------------- */
bool EpotHookLammps::isComputed(){
return ((time == current_step) && computed==true);
}
/* -------------------------------------------------------------------------- */
void EpotHookLammps::computeEpot(){
forceBackup();
DUMP("Asking Lammps to delete force for atoms",DBG_INFO);
if (lammps_object->modify->n_pre_force) lammps_object->modify->pre_force(0);
DUMP("Asking Lammps to compute epot for atoms",DBG_INFO);
lammps_object->force->pair->compute(2,0);
if (lammps_object->modify->n_post_force) lammps_object->modify->post_force(0);
computed = true;
time = current_step;
forceRestore();
}
/* -------------------------------------------------------------------------- */
void EpotHookLammps::forceBackup(){
UInt nlocal = lammps_object->atom->nlocal;
Real ** f = lammps_object->atom->f;
force_backup.resize(3*nlocal);
for (UInt i = 0 ; i < nlocal ; ++i){
for (UInt k = 0; k < 3; ++k) {
force_backup[i*3+k] = f[i][k];
}
}
}
/* -------------------------------------------------------------------------- */
void EpotHookLammps::forceRestore(){
UInt nlocal = lammps_object->atom->nlocal;
Real ** f = lammps_object->atom->f;
for (UInt i = 0 ; i < nlocal ; ++i){
for (UInt k = 0; k < 3; ++k) {
f[i][k] = force_backup[i*3+k];
}
}
}
/* -------------------------------------------------------------------------- */
Real EpotHookLammps::epot(UInt i){
return lammps_object->force->pair->eatom[i];
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */

Event Timeline