00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef MOMENTAENERGYFUNCTORS_H
00011 #define MOMENTAENERGYFUNCTORS_H
00012 #include "VArray.h"
00013
00014 #include "../driverCC/SVertexFunctors.h"
00015
00016 #include <functional>
00017
00018
00019 namespace utilities {
00020 struct LMomentumFunctor;
00021 struct AMomentumFunctor;
00022 struct KEnergyFunctor;
00023 }
00024
00025
00026
00027 struct utilities::LMomentumFunctor :
00028 public std::binary_function<shells::SVertex *,
00029 utilities::VArray<shells::SVertexVelocity::numVar> *, void > {
00030
00031 void operator()(shells::SVertex* vtx,
00032 utilities::VArray<shells::SVertexVelocity::numVar> *momentum) const
00033 {
00034 shells::SVertexVelocity getVelocity;
00035 shells::SVertexMass getMass;
00036
00037 const shells::SVertexVelocity::DataType *velocity = getVelocity(vtx);
00038 const shells::SVertexMass::DataType mass = *(getMass(vtx));
00039
00040 for (unsigned i=0; i<shells::SVertexVelocity::numVar; ++i) {
00041 (*momentum)[i] += velocity[i]*mass;
00042 }
00043 }
00044 };
00045
00046
00047
00048 struct utilities::AMomentumFunctor :
00049 public std::binary_function<shells::SVertex *,
00050 utilities::VArray<shells::SVertexVelocity::numVar> *, void > {
00051
00052 void operator()(shells::SVertex* vtx,
00053 utilities::VArray<shells::SVertexVelocity::numVar> *amomentum) const
00054 {
00055
00056 utilities::LMomentumFunctor getLinearMomentum;
00057 utilities::VArray<3> lmomentum(0);
00058
00059 getLinearMomentum(vtx, &lmomentum);
00060
00061 shells::SVertexCoordinate getCoordinate;
00062 const shells::SVertexCoordinate::DataType *coor = getCoordinate(vtx);
00063
00064 shells::SVertexDisplacement getDisplacement;
00065 const shells::SVertexDisplacement::DataType *disp = getDisplacement(vtx);
00066
00067 const unsigned numVar=shells::SVertexDisplacement::numVar;
00068 shells::SVertexDisplacement::DataType deformed[numVar];
00069
00070 for (unsigned i=0; i<numVar; ++i) {
00071 deformed[i] = disp[i]+coor[i];
00072 }
00073
00074 (*amomentum)[0] += deformed[1]*lmomentum[2]-deformed[2]*lmomentum[1];
00075 (*amomentum)[1] += deformed[2]*lmomentum[0]-deformed[0]*lmomentum[2];
00076 (*amomentum)[2] += deformed[0]*lmomentum[1]-deformed[1]*lmomentum[0];
00077
00078 }
00079 };
00080
00081
00082
00083 struct utilities::KEnergyFunctor :
00084 public std::binary_function<shells::SVertex *, double *, void > {
00085
00086 void operator()(shells::SVertex* vtx, double *energy) const
00087 {
00088 shells::SVertexVelocity getVelocity;
00089 shells::SVertexMass getMass;
00090
00091 const shells::SVertexVelocity::DataType *velocity = getVelocity(vtx);
00092 const shells::SVertexMass::DataType mass = *(getMass(vtx));
00093
00094 for (unsigned i=0; i<shells::SVertexVelocity::numVar; ++i) {
00095 *energy += 0.5*velocity[i]*velocity[i]*mass;
00096 }
00097 }
00098 };
00099
00100 #endif