MaMiCo 1.2
Loading...
Searching...
No Matches
SetKineticEnergyMapping.h
1// Copyright (C) 2015 Technische Universitaet Muenchen
2// This file is part of the Mamico project. For conditions of distribution
3// and use, please see the copyright notice in Mamico's main folder, or at
4// www5.in.tum.de/mamico
5#ifndef _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETKINETICENERGYMAPPING_H_
6#define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETKINETICENERGYMAPPING_H_
7
8#include "coupling/interface/MDSolverInterface.h"
9#include "coupling/interface/Molecule.h"
10#include <cmath>
11#include <iostream>
12
13namespace coupling {
14namespace cellmappings {
15template <class LinkedCell, unsigned int dim> class SetKineticEnergyMapping;
16}
17} // namespace coupling
18
25template <class LinkedCell, unsigned int dim> class coupling::cellmappings::SetKineticEnergyMapping {
26public:
35 SetKineticEnergyMapping(const double& oldKineticEnergy, const double& newKineticEnergy, const unsigned int& numberParticles,
37 : _mdSolverInterface(mdSolverInterface), _meanVelocity(meanVelocity),
38 _correctionFactor(getCorrectionFactor(oldKineticEnergy, newKineticEnergy, numberParticles, meanVelocity)) {}
39
42
46
50
55 void handleCell(LinkedCell& cell) {
56 coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
57 it->begin();
58 while (it->continueIteration()) {
61
62 // set new velocity: still with same mean, but re-scale the deviation for
63 // correct thermal energy
64 velocity = _meanVelocity + _correctionFactor * (velocity - _meanVelocity);
65 wrapper.setVelocity(velocity);
66
67 it->next();
68 }
69 delete it;
70 }
71
72private:
80 double getCorrectionFactor(const double& oldKineticEnergy, const double& newKineticEnergy, const unsigned int& numberParticles,
81 const tarch::la::Vector<dim, double>& meanVelocity) const {
82 const double mass = _mdSolverInterface->getMoleculeMass();
83
84 // no correction possible if the correction factor would tend to infinity; I
85 // just hard-coded 1e-7 for this case
86 if (oldKineticEnergy - 0.5 * mass * numberParticles * tarch::la::dot(meanVelocity, meanVelocity) < 1e-7) {
87 return 1.0;
88 }
89
90 double correctionFactor = newKineticEnergy - 0.5 * mass * numberParticles * tarch::la::dot(meanVelocity, meanVelocity);
91 correctionFactor = correctionFactor / (oldKineticEnergy - 0.5 * mass * numberParticles * tarch::la::dot(meanVelocity, meanVelocity));
92 correctionFactor = sqrt(correctionFactor);
93 return correctionFactor;
94 }
95
97 const tarch::la::Vector<dim, double> _meanVelocity;
98 const double _correctionFactor;
99};
100#endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETKINETICENERGYMAPPING_H_
This class sets kinetic energy over several linked cells.
Definition SetKineticEnergyMapping.h:25
void beginCellIteration()
Definition SetKineticEnergyMapping.h:45
~SetKineticEnergyMapping()
Definition SetKineticEnergyMapping.h:41
SetKineticEnergyMapping(const double &oldKineticEnergy, const double &newKineticEnergy, const unsigned int &numberParticles, const tarch::la::Vector< dim, double > &meanVelocity, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
Definition SetKineticEnergyMapping.h:35
void endCellIteration()
Definition SetKineticEnergyMapping.h:49
void handleCell(LinkedCell &cell)
Definition SetKineticEnergyMapping.h:55
double getCorrectionFactor(const double &oldKineticEnergy, const double &newKineticEnergy, const unsigned int &numberParticles, const tarch::la::Vector< dim, double > &meanVelocity) const
Definition SetKineticEnergyMapping.h:80
interface to the MD simulation
Definition MDSolverInterface.h:25
some iterator scheme for traversing the molecules within a linked cell.
Definition MoleculeIterator.h:24
virtual bool continueIteration() const =0
virtual coupling::interface::Molecule< dim > & get()=0
interface to access a single molecule in the MD simulation.
Definition Molecule.h:23
virtual void setVelocity(const tarch::la::Vector< dim, double > &velocity)=0
virtual tarch::la::Vector< dim, double > getVelocity() const =0
Definition Vector.h:24
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15