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_VELOCITYGRADIENTRELAXATION_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_VELOCITYGRADIENTRELAXATION_H_
7 :
8 : #include "coupling/MomentumInsertion.h"
9 : #include "coupling/cell-mappings/ComputeMomentumMapping.h"
10 : #include "coupling/cell-mappings/VelocityGradientRelaxationMapping.h"
11 : #include "coupling/interface/MDSolverInterface.h"
12 :
13 : namespace coupling {
14 : template <class LinkedCell, unsigned int dim> class VelocityGradientRelaxation;
15 : template <class LinkedCell, unsigned int dim> class VelocityGradientRelaxationTopOnly;
16 : } // namespace coupling
17 :
18 : /** Carries out velocity relaxation (similar to the SetMomentumMapping procedure).
19 : * In this particular case, however, the velocity is relaxed within a one
20 : * cell-wide strip around the molecular domain. For this purpose, the velocity
21 : * that shall be imposed in average in the cells that are within a three
22 : * cell-wide strip need to be known and stored in the
23 : * microscopicMomentum-buffers (2 cells overlap with the MD simulation, and 1
24 : * more (ghost) cell layer surrounding the MD domain). The procedure then only
25 : * considers molecules that are located between the midpoints of the cells which
26 : * are in the two cell-wide boundary strip. For all these molecules, a
27 : * second-order interpolation of the average velocity at their respective
28 : * position is carried out and the molecules are then relaxed towards this
29 : * particular velocity.
30 : * @brief carries out velocity relaxation (similar to the SetMomentumMapping
31 : * procedure).
32 : * @author Philipp Neumann
33 : * @tparam LinkedCell the LinkedCell class is given by the implementation of
34 : * linked cells in the molecular dynamics simulation
35 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
36 : * or 3 */
37 : template <class LinkedCell, unsigned int dim> class coupling::VelocityGradientRelaxation : public coupling::MomentumInsertion<LinkedCell, dim> {
38 : public:
39 : /** @brief a simple constructor
40 : * @param relaxationParam defines the strength of the relaxation; 1 means the
41 : * molecules velocity is set to the new velocity; O.5 -> the velocity will be
42 : * set to the avaerage of the old and the new velocity
43 : * @param mdSolverInterface interface for the md solver
44 : * @param couplingCells the coupling cells to apply the velocity
45 : * gradient relaxation */
46 0 : VelocityGradientRelaxation(double relaxationParam, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface,
47 : const coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>* const couplingCells)
48 0 : : coupling::MomentumInsertion<LinkedCell, dim>(mdSolverInterface), _couplingCells(couplingCells), _relaxationParam(relaxationParam) {}
49 : /** @brief a dummy destructor */
50 0 : virtual ~VelocityGradientRelaxation() {}
51 :
52 : /** @brief returns the time step interval for the momentum insertion, always
53 : * one for this method
54 : * @return the time step interval for momentum insertion */
55 0 : unsigned int getTimeIntervalPerMomentumInsertion() const override { return 1; }
56 :
57 : /** This method does not conserve the kinetic energy of the respective
58 : * coupling cell. To conserve the energy as well, see the description of
59 : * MomentumController on details how to do that.
60 : * @brief insertes the momentum to the cells according to the params and
61 : * velocity gradient relaxation method
62 : * @param cell the coupling cell to insert momentum to
63 : * @param idx the coupling cell's index */
64 0 : void insertMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, I02 idx) const override {
65 0 : coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> momentumMapping(coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
66 0 : tarch::la::Vector<dim, double> oldVelocity(0.0);
67 0 : cell.iterateConstCells(momentumMapping);
68 : // set current average velocity within this cell
69 0 : oldVelocity = momentumMapping.getMeanVelocity();
70 : // set new momentum (based on velocity stored in microscopic
71 : // momentum-buffer)
72 0 : coupling::cellmappings::VelocityGradientRelaxationMapping<LinkedCell, dim> velocityGradientRelaxation(
73 0 : _relaxationParam, oldVelocity, idx, coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface, _couplingCells);
74 0 : cell.iterateCells(velocityGradientRelaxation);
75 0 : }
76 :
77 0 : void setInnerImposition(bool enable) override {
78 0 : throw std::runtime_error(std::string("coupling::AdditiveMomentumInsertion::setInnerImposition not implemented"));
79 : }
80 :
81 : protected:
82 : /** the coupling cells to apply the velocity gradient relaxation */
83 : const coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>* const _couplingCells;
84 : /** defines the strength of the relaxation; 1 means the molecules velocity is
85 : * set to the new velocity;
86 : * O.5 -> the velocity will be set to the avaerage of
87 : * the old and the new velocity*/
88 : const double _relaxationParam;
89 : };
90 :
91 : /** In this particular case, however, the velocity is relaxed within a one
92 : * cell-wide strip around the molecular domain. For this purpose, the velocity
93 : * that shall be imposed in average in the cells that are within a three
94 : * cell-wide strip need to be known and stored in the
95 : * microscopicMomentum-buffers (2 cells overlap with the MD simulation, and 1
96 : * more (ghost) cell layer surrounding the MD domain). The procedure then only
97 : * considers molecules that are located between the midpoints of the cells which
98 : * are in the two cell-wide boundary strip. For all these molecules, a
99 : * second-order interpolation of the average velocity at their respective
100 : * position is carried out and the molecules are then relaxed towards this
101 : * particular velocity.
102 : * @brief carries out velocity relaxation (similar to the SetMomentumMapping
103 : * procedure).
104 : * @author Philipp Neumann
105 : * @tparam LinkedCell the LinkedCell class is given by the implementation of
106 : * linked cells in the molecular dynamics simulation
107 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
108 : * or 3
109 : * @todo Don't know what this does, just copied the comments from above*/
110 : template <class LinkedCell, unsigned int dim> class coupling::VelocityGradientRelaxationTopOnly : public coupling::VelocityGradientRelaxation<LinkedCell, dim> {
111 : public:
112 : /** @brief a simple constructor*/
113 0 : VelocityGradientRelaxationTopOnly(double relaxationParam, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface,
114 : const coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>* const couplingCells)
115 0 : : coupling::VelocityGradientRelaxation<LinkedCell, dim>(relaxationParam, mdSolverInterface, couplingCells) {}
116 :
117 : /** @brief a dummy destructor */
118 0 : virtual ~VelocityGradientRelaxationTopOnly() {}
119 :
120 : /** This method does not conserve the kinetic energy of the respective
121 : * coupling cell. To conserve the energy as well, see the description of
122 : * MomentumController on details how to do that.
123 : * @brief insertes the momentum to the cells according to the params and
124 : * velocity gradient relaxation method
125 : * @param cell the coupling cell to insert momentum to
126 : * @param idx the coupling cell's index */
127 0 : void insertMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, I02 idx) const override {
128 0 : coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> momentumMapping(coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
129 0 : tarch::la::Vector<dim, double> oldVelocity(0.0);
130 0 : cell.iterateConstCells(momentumMapping);
131 : // set current average velocity within this cell
132 0 : oldVelocity = momentumMapping.getMeanVelocity();
133 :
134 : // set new momentum (based on velocity stored in microscopic
135 : // momentum-buffer)
136 0 : coupling::cellmappings::VelocityGradientRelaxationTopOnlyMapping<LinkedCell, dim> velocityGradientRelaxation(
137 0 : coupling::VelocityGradientRelaxation<LinkedCell, dim>::_relaxationParam, oldVelocity, idx,
138 0 : coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface, coupling::VelocityGradientRelaxation<LinkedCell, dim>::_couplingCells);
139 0 : cell.iterateCells(velocityGradientRelaxation);
140 0 : }
141 : };
142 : #endif // _MOLECULARDYNAMICS_COUPLING_VELOCITYGRADIENTRELAXATION_H_
|