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_COMPUTETEMPERATUREMAPPING_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTETEMPERATUREMAPPING_H_
7 :
8 : #include "coupling/interface/MDSolverInterface.h"
9 : #include "coupling/interface/Molecule.h"
10 : #include <iostream>
11 :
12 : namespace coupling {
13 : namespace cellmappings {
14 : template <class LinkedCell, unsigned int dim> class ComputeTemperatureMapping;
15 : }
16 : } // namespace coupling
17 :
18 : /**
19 : * @brief This class computes the temperature in a certain (coupling)
20 : *cell.
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::ComputeTemperatureMapping {
26 : public:
27 : /** Constructor
28 : * @param meanVelocity
29 : * @param mdSolverInterface
30 : */
31 0 : ComputeTemperatureMapping(const tarch::la::Vector<dim, double>& meanVelocity,
32 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
33 0 : : _mdSolverInterface(mdSolverInterface), _meanVelocity(meanVelocity), _temperature(0.0), _particleCounter(0) {}
34 :
35 : /** Destructor */
36 0 : ~ComputeTemperatureMapping() {}
37 :
38 : /** sets the temperature and the particle counter to zero, before the
39 : * iteration process begins.
40 : */
41 0 : void beginCellIteration() {
42 0 : _temperature = 0.0;
43 0 : _particleCounter = 0;
44 : }
45 :
46 : /** computes the temperature in a linked cell, based on equilibrium
47 : * statistical mechanics.
48 : */
49 0 : void endCellIteration() {
50 0 : _temperature = _temperature * _mdSolverInterface->getMoleculeMass();
51 0 : if (_particleCounter != 0) {
52 0 : _temperature = _temperature / (dim * _mdSolverInterface->getKB() * _particleCounter);
53 : }
54 0 : }
55 :
56 : /** sums up the velocity fluctuation (from the mean flow velocity) of all
57 : *particles
58 : * @param cell
59 : */
60 0 : void handleCell(LinkedCell& cell) {
61 0 : coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
62 0 : it->begin();
63 0 : while (it->continueIteration()) {
64 0 : const coupling::interface::Molecule<dim>& wrapper(it->getConst());
65 0 : _temperature += tarch::la::dot((wrapper.getVelocity() - _meanVelocity), (wrapper.getVelocity() - _meanVelocity));
66 0 : _particleCounter++;
67 :
68 0 : it->next();
69 : }
70 0 : delete it;
71 0 : }
72 :
73 : /** returns the temperature inside a linked cell
74 : * @return _temperature
75 : */
76 0 : double getTemperature() const { return _temperature; }
77 :
78 : private:
79 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
80 : const tarch::la::Vector<dim, double> _meanVelocity;
81 : double _temperature;
82 : unsigned int _particleCounter;
83 : };
84 : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTETEMPERATUREMAPPING_H_
|