/* * molecule_template.hpp * * Created on: Oct 6, 2009 * Author: heber */ #ifndef MOLECULE_TEMPLATE_HPP_ #define MOLECULE_TEMPLATE_HPP_ /*********************************************** includes ***********************************/ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include "atom.hpp" /********************************************** declarations *******************************/ // ================== Acting on all Vectors ========================== // // zero arguments template void molecule::ActOnAllVectors( res (Vector::*f)() ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(); } }; template void molecule::ActOnAllVectors( res (Vector::*f)() const ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(); } }; // one argument template void molecule::ActOnAllVectors( res (Vector::*f)(T), T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t); } }; template void molecule::ActOnAllVectors( res (Vector::*f)(T) const, T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t); } }; template void molecule::ActOnAllVectors( res (Vector::*f)(T&), T &t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t); } }; template void molecule::ActOnAllVectors( res (Vector::*f)(T&) const, T &t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t); } }; // two arguments template void molecule::ActOnAllVectors( res (Vector::*f)(T, U), T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t, u); } }; template void molecule::ActOnAllVectors( res (Vector::*f)(T, U) const, T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t, u); } }; // three arguments template void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V), T t, U u, V v) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t, u, v); } }; template void molecule::ActOnAllVectors( res (Vector::*f)(T, U, V) const, T t, U u, V v) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (((*iter)->node)->*f)(t, u, v); } }; // ========================= Summing over each Atoms =================================== // // zero arguments template res molecule::SumPerAtom(res (typ::*f)() ) const { res result = 0; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { result += ((*iter)->*f)(); } return result; }; template res molecule::SumPerAtom(res (typ::*f)() const ) const { res result = 0; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { result += ((*iter)->*f)(); } return result; }; // one argument template res molecule::SumPerAtom(res (typ::*f)(T), T t ) const { res result = 0; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { result += ((*iter)->*f)(t); } return result; }; template res molecule::SumPerAtom(res (typ::*f)(T) const, T t ) const { res result = 0; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { result += ((*iter)->*f)(t); } return result; }; // ================== Acting with each Atoms on same molecule ========================== // // zero arguments template void molecule::ActWithEachAtom( res (molecule::*f)(atom *)) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*f)((*iter)); } }; template void molecule::ActWithEachAtom( res (molecule::*f)(atom *) const) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*f)((*iter)); } }; // ================== Acting with each Atoms on copy molecule ========================== // // zero arguments template void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) , molecule *copy) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtom( res (molecule::*f)(atom *) const, molecule *copy) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (copy->*f)((*iter)); } }; // ================== Acting with each Atoms on copy molecule if true ========================== // // zero arguments template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)()) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) () const ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)()) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const , molecule *copy, bool (atom::*condition) () ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)()) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) () const ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)()) (copy->*f)((*iter)); } }; // one argument template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T), T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T) const, T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T), T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T) const, T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t)) (copy->*f)((*iter)); } }; // two arguments template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U), T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U) const, T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u)) (copy->*f)((*iter)); } }; // three arguments template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u,v)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) , molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u,v)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V), T t, U u, V v ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u,v)) (copy->*f)((*iter)); } }; template void molecule::ActOnCopyWithEachAtomIfTrue( res (molecule::*f)(atom *) const, molecule *copy, bool (atom::*condition) (T, U, V) const, T t, U u, V v ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { if (((*iter)->*condition)(t,u,v)) (copy->*f)((*iter)); } }; // ================== Acting on all Atoms ========================== // // zero arguments template void molecule::ActOnAllAtoms( res (typ::*f)()) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(); } }; template void molecule::ActOnAllAtoms( res (typ::*f)() const) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(); } }; // one argument template void molecule::ActOnAllAtoms( res (typ::*f)(T), T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t); } }; template void molecule::ActOnAllAtoms( res (typ::*f)(T) const, T t ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t); } }; // two argument template void molecule::ActOnAllAtoms( res (typ::*f)(T, U), T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u); } }; template void molecule::ActOnAllAtoms( res (typ::*f)(T, U) const, T t, U u ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u); } }; // three argument template void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V), T t, U u, V v) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u, v); } }; template void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V) const, T t, U u, V v) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u, v); } }; // four arguments template void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W), T t, U u, V v, W w) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u, v, w); } }; template void molecule::ActOnAllAtoms( res (typ::*f)(T, U, V, W) const, T t, U u, V v, W w) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { ((*iter)->*f)(t, u, v, w); } }; // ===================== Accessing arrays indexed by some integer for each atom ====================== // for atom ints template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *) ) const { int inc = 1; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->*index)], &inc); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->*index)], &value); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, void (*Setor)(T *, T *), T *value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->*index)], value); } }; // for element ints template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *) ) const { int inc = 1; for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->type->*index)], &inc); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->type->*index)], &value); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int element::*index, void (*Setor)(T *, T *), T *value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*Setor) (&array[((*iter)->type->*index)], value); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ atom::*value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ atom::*value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { array[((*iter)->*index)] = ((*iter)->*Setor) ((*iter)->*value); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &), typ &vect ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { array[((*iter)->*index)] = ((*iter)->*Setor) (vect); } }; template void molecule::SetIndexedArrayForEachAtomTo ( T *array, int ParticleInfo::*index, T (atom::*Setor)(typ &) const, typ &vect ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { array[((*iter)->*index)] = ((*iter)->*Setor) (vect); } }; template void molecule::SetAtomValueToIndexedArray ( T *array, int typ::*index, T typ2::*value ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*iter)->*value = array[((*iter)->*index)]; //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*value); << endl; } }; template void molecule::SetAtomValueToValue ( T value, T typ::*ptr ) const { for (molecule::const_iterator iter = begin(); iter != end(); ++iter) { (*iter)->*ptr = value; //Log() << Verbose(2) << *(*iter) << " gets " << ((*iter)->*ptr) << endl; } }; #endif /* MOLECULE_TEMPLATE_HPP_ */