LCOV - code coverage report
Current view: top level - coupling - VelocityGradientRelaxation.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 26 0.0 %
Date: 2025-06-25 11:26:37 Functions: 0 7 0.0 %

          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             : protected:
      78             :   /** the coupling cells to apply the velocity gradient relaxation */
      79             :   const coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>* const _couplingCells;
      80             :   /** defines the strength of the relaxation; 1 means the molecules velocity is
      81             :    * set to the new velocity;
      82             :    *                         O.5 -> the velocity will be set to the avaerage of
      83             :    * the old and the new velocity*/
      84             :   const double _relaxationParam;
      85             : };
      86             : 
      87             : /** In this particular case, however, the velocity is relaxed within a one
      88             :  * cell-wide strip around the molecular domain. For this purpose, the velocity
      89             :  * that shall be imposed in average in the cells that are within a three
      90             :  * cell-wide strip need to be known and stored in the
      91             :  *  microscopicMomentum-buffers (2 cells overlap with the MD simulation, and 1
      92             :  * more (ghost) cell layer surrounding the MD domain). The procedure then only
      93             :  * considers molecules that are located between the midpoints of the cells which
      94             :  * are in the two cell-wide boundary strip. For all these molecules, a
      95             :  * second-order interpolation of the average velocity at their respective
      96             :  * position is carried out and the molecules are then relaxed towards this
      97             :  * particular velocity.
      98             :  *  @brief carries out velocity relaxation (similar to the SetMomentumMapping
      99             :  * procedure).
     100             :  *  @author Philipp Neumann
     101             :  *  @tparam LinkedCell the LinkedCell class is given by the implementation of
     102             :  * linked cells in the molecular dynamics simulation
     103             :  *  @tparam dim  refers to the spacial dimension of the simulation, can be 1, 2,
     104             :  * or 3
     105             :  *  @todo Don't know what this does, just copied the comments from above*/
     106             : template <class LinkedCell, unsigned int dim> class coupling::VelocityGradientRelaxationTopOnly : public coupling::VelocityGradientRelaxation<LinkedCell, dim> {
     107             : public:
     108             :   /** @brief a simple constructor*/
     109           0 :   VelocityGradientRelaxationTopOnly(double relaxationParam, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface,
     110             :                                     const coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>* const couplingCells)
     111           0 :       : coupling::VelocityGradientRelaxation<LinkedCell, dim>(relaxationParam, mdSolverInterface, couplingCells) {}
     112             : 
     113             :   /** @brief a dummy destructor */
     114           0 :   virtual ~VelocityGradientRelaxationTopOnly() {}
     115             : 
     116             :   /** This method does not conserve the kinetic energy of the respective
     117             :    * coupling cell. To conserve the energy as well, see the description of
     118             :    * MomentumController on details how to do that.
     119             :    *  @brief insertes the momentum to the cells according to the params and
     120             :    * velocity gradient relaxation method
     121             :    *  @param cell the coupling cell to insert momentum to
     122             :    *  @param idx the coupling cell's index */
     123           0 :   void insertMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, I02 idx) const override {
     124           0 :     coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> momentumMapping(coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
     125           0 :     tarch::la::Vector<dim, double> oldVelocity(0.0);
     126           0 :     cell.iterateConstCells(momentumMapping);
     127             :     // set current average velocity within this cell
     128           0 :     oldVelocity = momentumMapping.getMeanVelocity();
     129             : 
     130             :     // set new momentum (based on velocity stored in microscopic
     131             :     // momentum-buffer)
     132           0 :     coupling::cellmappings::VelocityGradientRelaxationTopOnlyMapping<LinkedCell, dim> velocityGradientRelaxation(
     133           0 :         coupling::VelocityGradientRelaxation<LinkedCell, dim>::_relaxationParam, oldVelocity, idx,
     134           0 :         coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface, coupling::VelocityGradientRelaxation<LinkedCell, dim>::_couplingCells);
     135           0 :     cell.iterateCells(velocityGradientRelaxation);
     136           0 :   }
     137             : };
     138             : #endif // _MOLECULARDYNAMICS_COUPLING_VELOCITYGRADIENTRELAXATION_H_

Generated by: LCOV version 1.14