LCOV - code coverage report
Current view: top level - coupling/cell-mappings - ComputeMomentumMapping.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 25 8.0 %
Date: 2025-06-25 11:26:37 Functions: 1 4 25.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_CELLMAPPINGS_COMPUTEMOMENTUMMAPPING_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEMOMENTUMMAPPING_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 ComputeMomentumMapping;
      15             : }
      16             : } // namespace coupling
      17             : 
      18             : /**
      19             :  *      @brief This class computes the momentum over certain linked cells.
      20             :  *      @tparam LinkedCell cell type
      21             :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      22             :  *  @author Philipp Neumann
      23             :  */
      24             : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::ComputeMomentumMapping {
      25             : public:
      26             :   /** Constructor
      27             :    *    @param mdSolverInterface
      28             :    */
      29           8 :   ComputeMomentumMapping(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      30          16 :       : _mdSolverInterface(mdSolverInterface), _momentum(0.0), _meanVelocity(0.0), _particleCounter(0) {}
      31             : 
      32             :   /** Destructor */
      33           0 :   ~ComputeMomentumMapping() {}
      34             : 
      35             :   /** sets the mean velocity, momentum and the particle counter to zero, before
      36             :    * the iteration process begins.
      37             :    */
      38           0 :   void beginCellIteration() {
      39           0 :     _momentum = tarch::la::Vector<dim, double>(0.0);
      40           0 :     _meanVelocity = tarch::la::Vector<dim, double>(0.0);
      41           0 :     _particleCounter = 0;
      42           0 :   }
      43             : 
      44             :   /** computes the mean velocity, momentum in a linked cell,
      45             :    *    by dividing and multiplying the summation of the velocities computed in
      46             :    *handleCell(...) over the number if particle and in particle mass
      47             :    *respectively.
      48             :    */
      49           0 :   void endCellIteration() {
      50           0 :     if (_particleCounter != 0) {
      51           0 :       _meanVelocity = (1.0 / ((double)_particleCounter)) * _momentum;
      52           0 :       _momentum = _mdSolverInterface->getMoleculeMass() * _momentum;
      53             :     }
      54           0 :   }
      55             : 
      56             :   /** counts the molecules inside a linked cell and sums up the of the velocity
      57             :    *of all particles inside the cell and saves it as momentum.
      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 :       _momentum += wrapper.getVelocity();
      66           0 :       _particleCounter++;
      67             : 
      68           0 :       it->next();
      69             :     }
      70           0 :     delete it;
      71           0 :   }
      72             : 
      73             :   /** returns the momentum inside a linked cell
      74             :    *    @return _momentum
      75             :    */
      76           0 :   tarch::la::Vector<dim, double> getMomentum() const { return _momentum; }
      77             : 
      78             :   /** returns the mean velocity inside a linked cell
      79             :    *    @return _meanVelocity
      80             :    */
      81           0 :   tarch::la::Vector<dim, double> getMeanVelocity() const { return _meanVelocity; }
      82             : 
      83             : private:
      84             :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      85             :   tarch::la::Vector<dim, double> _momentum;
      86             :   tarch::la::Vector<dim, double> _meanVelocity;
      87             :   unsigned int _particleCounter;
      88             : };
      89             : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEMOMENTUMMAPPING_H_

Generated by: LCOV version 1.14