LCOV - code coverage report
Current view: top level - coupling - MomentumController.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 10.0 % 20 2
Test Date: 2026-08-21 15:14:06 Functions: 0.0 % 3 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_MOMENTUMCONTROLLER_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_MOMENTUMCONTROLLER_H_
       7              : 
       8              : #include "coupling/cell-mappings/ComputeMassMapping.h"
       9              : #include "coupling/cell-mappings/ComputeMomentumMapping.h"
      10              : #include "coupling/cell-mappings/SetMomentumMapping.h"
      11              : #include "coupling/datastructures/CouplingCell.h"
      12              : #include "tarch/la/Vector.h"
      13              : 
      14              : namespace coupling {
      15              : template <class LinkedCell, unsigned int dim> class MomentumController;
      16              : }
      17              : 
      18              : /** This class can compute the momentum and set a certain value for the
      19              :  * momentum.
      20              :  *  @brief controls the momentum in a coupling cell.
      21              :  *  @author Philipp Neumann
      22              :  *  @tparam LinkedCell the LinkedCell class is given by the implementation of
      23              :  * linked cells in the molecular dynamics simulation
      24              :  *  @tparam dim  refers to the spacial dimension of the simulation, can be 1, 2,
      25              :  * or 3 */
      26              : template <class LinkedCell, unsigned int dim> class coupling::MomentumController {
      27              : public:
      28              :   /** @brief a simple constructor
      29              :    *  @param mdSolverInterface interface to the md solver */
      30            4 :   MomentumController(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      31            4 :       : _computeMassMapping(mdSolverInterface), _computeMomentumMapping(mdSolverInterface), _mdSolverInterface(mdSolverInterface) {}
      32              : 
      33              :   /** a simple destructor */
      34            0 :   ~MomentumController() {}
      35              : 
      36              :   /** @brief computes and returns the momentum and mean velocity of a
      37              :    * coupling cell
      38              :    *  @param cell the coupling cell, for which the values shall be calculated
      39              :    *  @param momentum vector to which the momentum of the cell will be written
      40              :    * to
      41              :    *  @param meanVelocity vector to which the mean velocity of the cell will be
      42              :    * written to*/
      43            0 :   void computeMomentumAndMeanVelocity(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, tarch::la::Vector<dim, double>& momentum,
      44              :                                       tarch::la::Vector<dim, double>& meanVelocity) {
      45            0 :     cell.iterateConstCells(_computeMomentumMapping);
      46            0 :     momentum = _computeMomentumMapping.getMomentum();
      47            0 :     meanVelocity = _computeMomentumMapping.getMeanVelocity();
      48            0 :   }
      49              : 
      50              :   /** @brief computes and returns the momentum of a coupling cell
      51              :    * @param cell the coupling cell, for which the values shall be calculated
      52              :    *  @param momentum vector to which the momentum of the cell will be written
      53              :    * to */
      54            0 :   void computeMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, tarch::la::Vector<dim, double>& momentum) {
      55            0 :     cell.iterateConstCells(_computeMomentumMapping);
      56            0 :     momentum = _computeMomentumMapping.getMomentum();
      57            0 :   }
      58              : 
      59              :   /** computes and returns the mean velocity of a coupling cell
      60              :    *  @param cell the coupling cell, for which the values shall be calculated
      61              :    *  @param meanVelocity vector to which the mean velocity of the cell will be
      62              :    * written to*/
      63              :   void computeMeanVelocity(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, tarch::la::Vector<dim, double>& meanVelocity) {
      64              :     cell.iterateConstCells(_computeMomentumMapping);
      65              :     meanVelocity = _computeMomentumMapping.getMeanVelocity();
      66              :   }
      67              : 
      68              :   /** This cell does not consider the kinetic energy of the system, so the
      69              :    * kinetic energy will be different after executing this method! In order to
      70              :    * also retain the kinetic energy, one might compute the kinetic energy before
      71              :    * calling this method (using the KineticEnergyController) and set the old
      72              :    * kinetic energy afterwards (again using the KineticEnergyController). This
      73              :    * will then set the right kinetic energy again, conserving both mass and
      74              :    * momentum over this cell.
      75              :    *  @brief sets the momentum of a coupling cell to the input value.
      76              :    *  @param cell the coupling cell in which the momentum shall be changed
      77              :    *  @param newMomentum the value to which the momentum will be set */
      78            0 :   void setMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const tarch::la::Vector<dim, double>& newMomentum) {
      79            0 :     tarch::la::Vector<dim, double> currentMomentum(0.0);
      80            0 :     computeMomentum(cell, currentMomentum);
      81            0 :     cell.iterateConstCells(_computeMassMapping);
      82            0 :     unsigned int numberParticles = _computeMassMapping.getNumberOfParticles();
      83            0 :     coupling::cellmappings::SetMomentumMapping<LinkedCell, dim> setMomentumMapping(currentMomentum, newMomentum, numberParticles, _mdSolverInterface);
      84            0 :     cell.iterateCells(setMomentumMapping);
      85            0 :   }
      86              : 
      87              : private:
      88              :   /** instance of the ComputeMassMapping */
      89              :   coupling::cellmappings::ComputeMassMapping<LinkedCell, dim> _computeMassMapping;
      90              :   /** instance of the ComputeMomentumMapping*/
      91              :   coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> _computeMomentumMapping;
      92              :   /** interface to the md solver*/
      93              :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      94              : };
      95              : #endif // _MOLECULARDYNAMICS_COUPLING_MOMENTUMCONTROLLER_H_
        

Generated by: LCOV version 2.0-1