LCOV - code coverage report
Current view: top level - coupling/cell-mappings - SetMomentumMapping.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 19 0
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_CELLMAPPINGS_SETMOMENTUMMAPPING_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETMOMENTUMMAPPING_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 SetMomentumMapping;
      15              : }
      16              : } // namespace coupling
      17              : 
      18              : /**
      19              :  *      @brief This class sets a certain momentum over several 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::SetMomentumMapping {
      25              : public:
      26              :   /** obtains the old momentum over the region of interest. Besides,
      27              :    *  obtains the new momentum that shall be set and the number of particles
      28              :    *  contained in the coupling cell.
      29              :    *    @param oldMomentum
      30              :    *    @param newMomentum
      31              :    *    @param numberParticles
      32              :    *    @param mdSolverInterface
      33              :    */
      34            0 :   SetMomentumMapping(const tarch::la::Vector<dim, double>& oldMomentum, const tarch::la::Vector<dim, double>& newMomentum, const unsigned int& numberParticles,
      35              :                      coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      36            0 :       : _mdSolverInterface(mdSolverInterface), _oldVelocity(getVelocity(numberParticles, oldMomentum)),
      37            0 :         _newVelocity(getVelocity(numberParticles, newMomentum)) {}
      38              : 
      39              :   /** Destructor */
      40            0 :   ~SetMomentumMapping() {}
      41              : 
      42              :   /** empty function
      43              :    */
      44              :   void beginCellIteration() {}
      45              : 
      46              :   /** empty function
      47              :    */
      48              :   void endCellIteration() {}
      49              : 
      50              :   /** applies a certain momentum over several linked cells, by steering the
      51              :    *velocity.
      52              :    *    @param cell
      53              :    */
      54            0 :   void handleCell(LinkedCell& cell) {
      55            0 :     coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
      56            0 :     it->begin();
      57            0 :     while (it->continueIteration()) {
      58            0 :       coupling::interface::Molecule<dim>& wrapper(it->get());
      59            0 :       tarch::la::Vector<dim, double> velocity = wrapper.getVelocity();
      60            0 :       velocity = velocity - _oldVelocity + _newVelocity;
      61            0 :       wrapper.setVelocity(velocity);
      62              : 
      63            0 :       it->next();
      64              :     }
      65            0 :     delete it;
      66            0 :   }
      67              : 
      68              : private:
      69              :   /** returns mean velocity og the cell
      70              :    *    @param numberParticles
      71              :    *    @param momentum
      72              :    *    @return mean velocity og the cell
      73              :    */
      74            0 :   tarch::la::Vector<dim, double> getVelocity(const unsigned int& numberParticles, const tarch::la::Vector<dim, double>& momentum) const {
      75            0 :     if (numberParticles != 0) {
      76            0 :       return (1.0 / (numberParticles * _mdSolverInterface->getMoleculeMass())) * momentum;
      77              :     } else {
      78            0 :       return tarch::la::Vector<dim, double>(0.0);
      79              :     }
      80              :   }
      81              : 
      82              :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      83              :   tarch::la::Vector<dim, double> _oldVelocity;
      84              :   tarch::la::Vector<dim, double> _newVelocity;
      85              : };
      86              : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_SETMOMENTUMMAPPING_H_
        

Generated by: LCOV version 2.0-1