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 _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETTEMPERATUREMAPPING_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETTEMPERATUREMAPPING_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 SetTemperatureMapping;
16 : }
17 : } // namespace coupling
18 :
19 : /**
20 : * @brief This class sets a certain temperature over several linked cells.
21 : * @tparam LinkedCell cell type
22 : * @tparam dim Number of dimensions; it can be 1, 2 or 3
23 : * @author Philipp Neumann
24 : */
25 : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::SetTemperatureMapping {
26 : public:
27 : /** Constructor: obtains the old temperature over the region of interest.
28 : *Besides, obtains the new temperature.
29 : * @param oldTemperature
30 : * @param newTemperature
31 : * @param meanVelocity
32 : * @param mdSolverInterface
33 : */
34 0 : SetTemperatureMapping(const double& oldTemperature, const double& newTemperature, const tarch::la::Vector<dim, double>& meanVelocity,
35 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
36 0 : : _mdSolverInterface(mdSolverInterface), _factor(getScalingFactor(oldTemperature, newTemperature)), _meanVelocity(meanVelocity) {}
37 :
38 : /** Destructor */
39 0 : ~SetTemperatureMapping() {}
40 :
41 : /** empty function
42 : */
43 : void beginCellIteration() {}
44 :
45 : /** empty function
46 : */
47 : void endCellIteration() {}
48 :
49 : /** applies a certain temperature over several linked cells, by changing the
50 : *velocity (velocity fluctuation).
51 : * @param cell
52 : */
53 0 : void handleCell(LinkedCell& cell) {
54 0 : coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
55 0 : it->begin();
56 0 : while (it->continueIteration()) {
57 0 : coupling::interface::Molecule<dim>& wrapper(it->get());
58 0 : tarch::la::Vector<dim, double> velocity = wrapper.getVelocity();
59 : // scale velocity
60 0 : velocity = _meanVelocity + _factor * (velocity - _meanVelocity);
61 0 : wrapper.setVelocity(velocity);
62 0 : it->next();
63 : }
64 0 : delete it;
65 0 : }
66 :
67 : private:
68 : /** calculates the scaling factor between the old and new temperatures.
69 : * @param oldTemperature
70 : * @param newTemperature
71 : * @return newTemperature
72 : * @remark only allow re-scaling if the original temperature was not zero
73 : *(can happen in empty cells that just became populated)
74 : */
75 0 : double getScalingFactor(const double& oldTemperature, const double& newTemperature) const {
76 :
77 0 : if (oldTemperature != 0.0) {
78 0 : return sqrt(newTemperature / oldTemperature);
79 : } else {
80 : return 1.0;
81 : }
82 : }
83 :
84 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
85 : const double _factor;
86 : const tarch::la::Vector<dim, double> _meanVelocity;
87 : };
88 : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETTEMPERATUREMAPPING_H_
|