MaMiCo
1.2
Toggle main menu visibility
Loading...
Searching...
No Matches
coupling
cell-mappings
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
13
namespace
coupling
{
14
namespace
cellmappings {
15
template
<
class
LinkedCell,
unsigned
int
dim>
class
SetKineticEnergyMapping
;
16
}
17
}
// namespace coupling
18
25
template
<
class
LinkedCell,
unsigned
int
dim>
class
coupling::cellmappings::SetKineticEnergyMapping
{
26
public
:
35
SetKineticEnergyMapping
(
const
double
& oldKineticEnergy,
const
double
& newKineticEnergy,
const
unsigned
int
& numberParticles,
36
const
tarch::la::Vector<dim, double>
& meanVelocity,
coupling::interface::MDSolverInterface<LinkedCell, dim>
*
const
mdSolverInterface)
37
: _mdSolverInterface(mdSolverInterface), _meanVelocity(meanVelocity),
38
_correctionFactor(
getCorrectionFactor
(oldKineticEnergy, newKineticEnergy, numberParticles, meanVelocity)) {}
39
41
~SetKineticEnergyMapping
() {}
42
45
void
beginCellIteration
() {}
46
49
void
endCellIteration
() {}
50
55
void
handleCell
(LinkedCell& cell) {
56
coupling::interface::MoleculeIterator<LinkedCell, dim>
* it = _mdSolverInterface->getMoleculeIterator(cell);
57
it->
begin
();
58
while
(it->
continueIteration
()) {
59
coupling::interface::Molecule<dim>
& wrapper(it->
get
());
60
tarch::la::Vector<dim, double>
velocity = wrapper.
getVelocity
();
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
72
private
:
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
96
coupling::interface::MDSolverInterface<LinkedCell, dim>
*
const
_mdSolverInterface;
97
const
tarch::la::Vector<dim, double>
_meanVelocity;
98
const
double
_correctionFactor;
99
};
100
#endif
// _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETKINETICENERGYMAPPING_H_
coupling::cellmappings::SetKineticEnergyMapping
This class sets kinetic energy over several linked cells.
Definition
SetKineticEnergyMapping.h:25
coupling::cellmappings::SetKineticEnergyMapping::beginCellIteration
void beginCellIteration()
Definition
SetKineticEnergyMapping.h:45
coupling::cellmappings::SetKineticEnergyMapping::~SetKineticEnergyMapping
~SetKineticEnergyMapping()
Definition
SetKineticEnergyMapping.h:41
coupling::cellmappings::SetKineticEnergyMapping::SetKineticEnergyMapping
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
coupling::cellmappings::SetKineticEnergyMapping::endCellIteration
void endCellIteration()
Definition
SetKineticEnergyMapping.h:49
coupling::cellmappings::SetKineticEnergyMapping::handleCell
void handleCell(LinkedCell &cell)
Definition
SetKineticEnergyMapping.h:55
coupling::cellmappings::SetKineticEnergyMapping::getCorrectionFactor
double getCorrectionFactor(const double &oldKineticEnergy, const double &newKineticEnergy, const unsigned int &numberParticles, const tarch::la::Vector< dim, double > &meanVelocity) const
Definition
SetKineticEnergyMapping.h:80
coupling::interface::MDSolverInterface
interface to the MD simulation
Definition
MDSolverInterface.h:25
coupling::interface::MoleculeIterator
some iterator scheme for traversing the molecules within a linked cell.
Definition
MoleculeIterator.h:24
coupling::interface::MoleculeIterator::continueIteration
virtual bool continueIteration() const =0
coupling::interface::MoleculeIterator::next
virtual void next()=0
coupling::interface::MoleculeIterator::begin
virtual void begin()=0
coupling::interface::MoleculeIterator::get
virtual coupling::interface::Molecule< dim > & get()=0
coupling::interface::Molecule
interface to access a single molecule in the MD simulation.
Definition
Molecule.h:23
coupling::interface::Molecule::setVelocity
virtual void setVelocity(const tarch::la::Vector< dim, double > &velocity)=0
coupling::interface::Molecule::getVelocity
virtual tarch::la::Vector< dim, double > getVelocity() const =0
tarch::la::Vector
Definition
Vector.h:25
coupling
everything necessary for coupling operations, is defined in here
Definition
AdditiveMomentumInsertion.h:15
Generated by
1.17.0