Page MenuHomec4science

import_lammps.hh
No OneTemporary

File Metadata

Created
Fri, Aug 2, 23:20

import_lammps.hh

/**
* @file import_lammps.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Mon Oct 28 19:23:14 2013
*
* @brief The programming hooks to let LM be aware of processor migrations
*
* @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/>.
*
*/
#ifndef __LIBMULTISCALE_IMPORT_LAMMPS_HH__
#define __LIBMULTISCALE_IMPORT_LAMMPS_HH__
/* -------------------------------------------------------------------------- */
#include "reference_manager_lammps.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
/* -------------------------------------------------------------------------- */
class ImportLammpsInterface {
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public:
template <UInt Dim>
static void createImportLammps(ReferenceManagerLammps<Dim> & ref_manager);
static ImportLammpsInterface & getImport(){
if (import == NULL) LM_FATAL("function createImportLammps was not previously called");
return *import;
};
static void setGeom(Geometry * g,UInt itype = 0){
import->geom[itype] = g;
};
Geometry & getGeom(UInt itype = 0){
if (import->geom.count(itype) == 0)
return *import->geom[0];
else
return *import->geom[itype];
};
virtual void init(LAMMPS_NS::Domain & domain,LAMMPS_NS::Atom & atom,
LAMMPS_NS::Comm & comm, MPI_Comm & world,
int me, int nprocs) = 0;
virtual void moveAtom(UInt i, UInt j) = 0;
virtual void atomCommunications() = 0;
virtual void updateRefSubSets() = 0;
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
private:
std::map<UInt,Geometry *> geom;
static ImportLammpsInterface * import;
};
/* -------------------------------------------------------------------------- */
template <UInt Dim>
class ImportLammps : public ImportLammpsInterface {
/* ------------------------------------------------------------------------ */
/* Typedefs */
/* ------------------------------------------------------------------------ */
class Tensor{
public:
void resize(int nb[3]){
// DUMP("resize " << nb[0] << " " << nb[1] << " " << nb[2],DBG_MESSAGE);
array.resize(nb[0]*nb[1]*nb[2]);
for (UInt i = 0; i < 3; ++i) sizes[i] = nb[i];
};
int & operator [](int index[3]){
// DUMP("access " << index[0] << " " << index[1] << " " << index[2],DBG_MESSAGE);
// for (UInt i = 0; i < sizes[0]*sizes[1]*sizes[2]; ++i) {
// DUMP("val[" << i << "] = " << array[i],DBG_MESSAGE);
// }
return array[index[0] + index[1]*sizes[0] + index[2]*sizes[0]*sizes[1]];
};
private:
std::vector<int> array;
UInt sizes[3];
};
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
ImportLammps(ReferenceManagerLammps<Dim> & r): ref_manager(r){};
virtual ~ImportLammps(){};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
public:
void init(LAMMPS_NS::Domain & domain,LAMMPS_NS::Atom & atom,
LAMMPS_NS::Comm & comm, MPI_Comm & world, int me, int nprocs);
void setPeriodic(int per[3]){
for (UInt i = 0; i < 3; ++i) periodic[i] = per[i];
};
void setPeriodic(int perx, int pery, int perz){
periodic[0] = perx;
periodic[1] = pery;
periodic[2] = perz;
};
inline void registerSend(UInt at, UInt toProc);
void registerSends();
void atomCommunications();
void atomCommunication();
void setupTopology();
int getProcNumber(int index[3], int offset[3]);
void checkConsistency();
void unPackAtoms(UInt procDe);
void acceptAtom(UInt i,UInt fromProc){ref_manager.acceptAtom(i,fromProc);};
void sendAtom(UInt i,UInt toProc){ref_manager.sendAtom(i,toProc);};
void moveAtom(UInt i,UInt j){ref_manager.moveAtom(i,j);};
void updateRefSubSets(){ref_manager.updateRefSubSets();};
private:
/* ------------------------------------------------------------------------ */
/* Accessors */
/* ------------------------------------------------------------------------ */
public:
/* ------------------------------------------------------------------------ */
/* Class Members */
/* ------------------------------------------------------------------------ */
private:
int periodic[3];
Real * Xlo;
Real * Xhi;
int comProcs[26];
std::vector<std::vector<Real> > buf_send;
std::vector<std::vector<Real> > buf_recv;
std::vector<UInt> proc_comm;
UInt packSize;
int nbrProc[3];
Tensor proc_matrix;
ReferenceManagerLammps<Dim> & ref_manager;
int me;
MPI_Comm world;
int nprocs;
int old_nlocal;
LAMMPS_NS::Atom * atom;
LAMMPS_NS::Domain * domain;
LAMMPS_NS::Comm * comm;
};
/* -------------------------------------------------------------------------- */
template <UInt Dim>
void ImportLammpsInterface::createImportLammps(ReferenceManagerLammps<Dim> & ref_manager){
import = new ImportLammps<Dim>(ref_manager);
}
/* -------------------------------------------------------------------------- */
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_IMPORT_LAMMPS_HH__ */

Event Timeline