Page MenuHomec4science

ref_atom.hh
No OneTemporary

File Metadata

Created
Wed, Jul 10, 14:06

ref_atom.hh

/**
* @file ref_atom.hh
*
* @author Guillaume Anciaux <guillaume.anciaux@epfl.ch>
*
* @date Fri Nov 15 14:49:04 2013
*
* @brief This is the mother class of all atomic reference
*
* @section LICENSE
*
* Copyright INRIA and CEA
*
* 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 was initiated in a collaboration between INRIA Futurs Bordeaux
* within ScAlApplix team and CEA/DPTA Ile de France.
* The project is now continued at the Ecole Polytechnique Fédérale de Lausanne
* within the LSMS/ENAC laboratory.
*
* 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.
*
*/
#ifndef __LIBMULTISCALE_REF_ATOM_HH__
#define __LIBMULTISCALE_REF_ATOM_HH__
/* -------------------------------------------------------------------------- */
#include "cube.hh"
#include "ref_point.hh"
/* -------------------------------------------------------------------------- */
__BEGIN_LIBMULTISCALE__
#define DECLARE_ACCESSOR(name, func) \
inline void get##name(Real * x){ \
for (UInt i = 0; i < Dim; ++i) { \
x[i] = func(i); \
} \
}
/* -------------------------------------------------------------------------- */
template <UInt Dim> class RefAtom;
template <UInt Dim,FieldType ftype>
class AccessorAtomDof {
public:
AccessorAtomDof(RefAtom<Dim> & at, UInt i);
inline operator Real() const{return at;}
template <typename T> inline Real & operator =(const T & val){
at = val;
return at;
}
template <typename T>
inline T operator +=(const T & val){
at += val;
return at;
}
private:
Real & at;
};
/* -------------------------------------------------------------------------- */
/**
* Class Refatome
*
*/
template <UInt Dim>
class RefAtom : public RefPoint<RefAtom,Dim>
{
/* ------------------------------------------------------------------------ */
/* Constructors/Destructors */
/* ------------------------------------------------------------------------ */
public:
virtual ~RefAtom(){};
RefAtom(){};
/* ------------------------------------------------------------------------ */
/* Methods */
/* ------------------------------------------------------------------------ */
virtual Real & position0(UInt i)=0;
virtual Real & position(UInt i)=0;
virtual Real & velocity(UInt i)=0;
virtual AccessorAtomDof<Dim,_displacement> displacement(UInt i)=0;
virtual Real & force(UInt i)=0;
virtual Real mass()=0;
virtual UInt typeID(){LM_TOIMPLEMENT;};
virtual Real & charge()=0;
virtual Real & stress(UInt i){LM_TOIMPLEMENT;};
virtual Real & kinetic_stress(UInt i){LM_TOIMPLEMENT;};
virtual Real getEPot(){LM_TOIMPLEMENT;};
virtual UInt id()=0;
virtual Real & alpha()=0;
virtual UInt tag(){LM_TOIMPLEMENT;};
virtual void setMass(Real mass)=0;
virtual Real electronic_density(){LM_TOIMPLEMENT;};
template<FieldType ftype> AccessorAtomDof<Dim,ftype> field(UInt i);
DECLARE_ACCESSOR(Positions, position);
DECLARE_ACCESSOR(Positions0, position0);
DECLARE_ACCESSOR(Displacements, displacement);
DECLARE_ACCESSOR(Velocities, velocity);
template <FieldType ftype>
inline void getField(Real * x){
for (UInt i = 0; i < Dim; ++i) {
x[i] = field<ftype>(i);
}
};
public:
static const UInt dim = Dim;
};
/* -------------------------------------------------------------------------- */
template <UInt Dim>
template <FieldType ftype>
AccessorAtomDof<Dim,ftype> RefAtom<Dim>::field(UInt i){
AccessorAtomDof<Dim,ftype> acc(*this,i);
return acc;
}
/* -------------------------------------------------------------------------- */
template <UInt Dim,FieldType ftype>
inline AccessorAtomDof<Dim,ftype>::AccessorAtomDof(RefAtom<Dim> & at, UInt i):at(at.position(i)){}
template <>
inline AccessorAtomDof<1,_position0>::AccessorAtomDof(RefAtom<1> & at, UInt i):at(at.position0(i)){}
template <>
inline AccessorAtomDof<2,_position0>::AccessorAtomDof(RefAtom<2> & at, UInt i):at(at.position0(i)){}
template <>
inline AccessorAtomDof<3,_position0>::AccessorAtomDof(RefAtom<3> & at, UInt i):at(at.position0(i)){}
template <>
inline AccessorAtomDof<1,_position>::AccessorAtomDof(RefAtom<1> & at, UInt i):at(at.position(i)){}
template <>
inline AccessorAtomDof<2,_position>::AccessorAtomDof(RefAtom<2> & at, UInt i):at(at.position(i)){}
template <>
inline AccessorAtomDof<3,_position>::AccessorAtomDof(RefAtom<3> & at, UInt i):at(at.position(i)){}
template <>
inline AccessorAtomDof<1,_velocity>::AccessorAtomDof(RefAtom<1> & at, UInt i):at(at.velocity(i)){}
template <>
inline AccessorAtomDof<2,_velocity>::AccessorAtomDof(RefAtom<2> & at, UInt i):at(at.velocity(i)){}
template <>
inline AccessorAtomDof<3,_velocity>::AccessorAtomDof(RefAtom<3> & at, UInt i):at(at.velocity(i)){}
template <>
inline AccessorAtomDof<1,_force>::AccessorAtomDof(RefAtom<1> & at, UInt i):at(at.force(i)){}
template <>
inline AccessorAtomDof<2,_force>::AccessorAtomDof(RefAtom<2> & at, UInt i):at(at.force(i)){}
template <>
inline AccessorAtomDof<3,_force>::AccessorAtomDof(RefAtom<3> & at, UInt i):at(at.force(i)){}
template <>
inline AccessorAtomDof<1,_stress>::AccessorAtomDof(RefAtom<1> & at, UInt i):at(at.stress(i)){}
template <>
inline AccessorAtomDof<2,_stress>::AccessorAtomDof(RefAtom<2> & at, UInt i):at(at.stress(i)){}
template <>
inline AccessorAtomDof<3,_stress>::AccessorAtomDof(RefAtom<3> & at, UInt i):at(at.stress(i)){}
/* -------------------------------------------------------------------------- */
template <UInt Dim>
class AccessorAtomDof<Dim,_displacement> {
public:
AccessorAtomDof(RefAtom<Dim> & at, UInt i):at(at),i(i){
disp = at.position(i) - at.position0(i);
};
inline operator Real() const{
return (at.position(i) - at.position0(i));
};
template <typename T>
inline T operator =(const T & val){
disp = val;
at.position(i) = at.position0(i) + disp;
return disp;
}
template <typename T>
inline T operator +=(const T & val){
disp += val;
at.position(i) = at.position0(i) + disp;
return disp;
}
RefAtom<Dim> & at;
UInt i;
Real disp;
};
/* -------------------------------------------------------------------------- */
#undef DECLARE_ACCESSOR
__END_LIBMULTISCALE__
#endif /* __LIBMULTISCALE_REF_ATOM_HH__ */

Event Timeline