Line data Source code
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 _COUPLING_CELLMAPPINGS_PERTURBATEVELOCITYMAPPING_H_
6 : #define _COUPLING_CELLMAPPINGS_PERTURBATEVELOCITYMAPPING_H_
7 :
8 : #include "coupling/interface/MDSolverInterface.h"
9 : #include "tarch/utils/RandomNumberService.h"
10 :
11 : namespace coupling {
12 : namespace cellmappings {
13 : template <class LinkedCell, unsigned int dim> class PerturbateVelocityMapping;
14 : }
15 : } // namespace coupling
16 :
17 : /** This class is used to superimpose a random perturbation to the mean velocity
18 : *in all directions. It is use for Dynamic MD cases to launch new MD instances
19 : *with independent molecular values (velocities)
20 : * @brief This class is used to superimpose a random perturbation to the
21 : *mean velocity in all directions.
22 : * @tparam LinkedCell cell type
23 : * @tparam dim Number of dimensions; it can be 1, 2 or 3
24 : * @author Niklas Wittmer
25 : */
26 : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::PerturbateVelocityMapping {
27 : public:
28 : /** Constructor
29 : * @param mdSolverInterface
30 : * @param velocity
31 : * @param temperature
32 : */
33 0 : PerturbateVelocityMapping(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface, const tarch::la::Vector<dim, double>& velocity,
34 : const double& temperature)
35 0 : : _mdSolverInterface(mdSolverInterface), _molecularMass(mdSolverInterface->getMoleculeMass()), _kB(mdSolverInterface->getKB()), _temperature(temperature),
36 0 : _velocity(velocity), _sigma(_mdSolverInterface->getMoleculeSigma()) {}
37 :
38 : /** Destructor */
39 0 : ~PerturbateVelocityMapping() {}
40 :
41 : /** empty function
42 : */
43 : void beginCellIteration() {}
44 : /** empty function
45 : */
46 : void endCellIteration() {}
47 :
48 : /** superimposes a random perturbation to the mean velocity in all directions
49 : * @param cell
50 : */
51 0 : void handleCell(LinkedCell& cell) {
52 :
53 0 : double stdDeviation = std::sqrt(dim * _kB * _temperature / _molecularMass);
54 :
55 0 : tarch::la::Vector<dim, double> randomNumbers(0.0);
56 :
57 0 : coupling::interface::MoleculeIterator<LinkedCell, dim>* molecule = _mdSolverInterface->getMoleculeIterator(cell);
58 0 : molecule->begin();
59 0 : while (molecule->continueIteration()) {
60 0 : coupling::interface::Molecule<dim>& wrapper(molecule->get());
61 0 : randomNumbers[0] = tarch::utils::RandomNumberService::getInstance().getGaussianRandomNumber();
62 0 : for (unsigned int d = 1; d < dim; ++d) {
63 0 : randomNumbers[d] = tarch::utils::RandomNumberService::getInstance().getGaussianRandomNumber();
64 : }
65 :
66 0 : tarch::la::Vector<dim, double> mVelocity = wrapper.getVelocity();
67 : if (dim == 3) {
68 0 : mVelocity[0] = _velocity[0] + stdDeviation * (randomNumbers[0] * std::sin(randomNumbers[1]) * std::cos(randomNumbers[2]));
69 0 : mVelocity[1] = _velocity[1] + stdDeviation * (randomNumbers[0] * std::sin(randomNumbers[1]) * std::sin(randomNumbers[2]));
70 0 : mVelocity[2] = _velocity[2] + stdDeviation * (randomNumbers[0] * std::cos(randomNumbers[1]));
71 : } else if (dim == 1) {
72 : mVelocity = _velocity + stdDeviation * randomNumbers;
73 : } else if (dim == 2) {
74 : mVelocity[0] = _velocity[0] + stdDeviation * (randomNumbers[0] * std::cos(randomNumbers[1]));
75 : mVelocity[1] = _velocity[1] + stdDeviation * (randomNumbers[0] * std::sin(randomNumbers[1]));
76 : }
77 0 : wrapper.setVelocity(mVelocity);
78 :
79 0 : molecule->next();
80 : }
81 0 : delete molecule;
82 0 : }
83 :
84 : private:
85 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
86 : const double _molecularMass;
87 : const double _kB;
88 : const double _temperature;
89 : const tarch::la::Vector<dim, double> _velocity;
90 : const double _sigma;
91 : };
92 :
93 : #endif //_COUPLING_CELLMAPPINGS_VARYCHECKPOINTMAPPING_H_
|