LCOV - code coverage report
Current view: top level - coupling/cell-mappings - ComputeAvgForceAndVelocity.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 24 0.0 %
Date: 2025-06-25 11:26:37 Functions: 0 4 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_CELLMAPPINGS_COMPUTEAVGFORCEANDVELOCITY_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEAVGFORCEANDVELOCITY_H_
       7             : 
       8             : #include "coupling/interface/MDSolverInterface.h"
       9             : #include <iostream>
      10             : 
      11             : namespace coupling {
      12             : namespace cellmappings {
      13             : template <class LinkedCell, unsigned int dim> class ComputeAvgForceAndVelocity;
      14             : }
      15             : } // namespace coupling
      16             : 
      17             : /** This class sums up all force and velocity vectors and counts molecules
      18             :  *inside a linked cell. Afterwards, the average force/velocity contribution is
      19             :  *computed.
      20             :  *      @brief This class sums up all force/velocity vectors and counts
      21             :  *molecules inside a linked cell
      22             :  *      @tparam LinkedCell cell type
      23             :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      24             :  *  @author Philipp Neumann
      25             :  */
      26             : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::ComputeAvgForceAndVelocity {
      27             : public:
      28             :   /** Constructor
      29             :    *    @param mdSolverInterface
      30             :    */
      31           0 :   ComputeAvgForceAndVelocity(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      32           0 :       : _mdSolverInterface(mdSolverInterface), _force(0.0), _velocity(0.0), _particleCounter(0) {}
      33             : 
      34             :   /** Destructor */
      35           0 :   ~ComputeAvgForceAndVelocity() {}
      36             : 
      37             :   /** sets force, velocity and moluce counter to zero, before the iteration
      38             :    * process begins.
      39             :    */
      40           0 :   void beginCellIteration() {
      41           0 :     _particleCounter = 0;
      42           0 :     _force = tarch::la::Vector<dim, double>(0.0);
      43           0 :     _velocity = tarch::la::Vector<dim, double>(0.0);
      44           0 :   }
      45             : 
      46             :   /** the average force and velocity contribution incide a linked cell are
      47             :    *computed, by dividing the summation calculated in endCellIteration() over
      48             :    *number of the particles inside the cell.
      49             :    */
      50           0 :   void endCellIteration() {
      51           0 :     if (_particleCounter != 0) {
      52           0 :       _force = (1.0 / _particleCounter) * _force;
      53           0 :       _velocity = (1.0 / _particleCounter) * _velocity;
      54             :     }
      55           0 :   }
      56             : 
      57             :   /** sums up all force and velocity vectors and counts molecules inside a
      58             :    *linked cell.
      59             :    *    @param cell
      60             :    */
      61           0 :   void handleCell(LinkedCell& cell) {
      62           0 :     coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
      63           0 :     it->begin();
      64           0 :     while (it->continueIteration()) {
      65           0 :       coupling::interface::Molecule<dim>& wrapper(it->get());
      66           0 :       _particleCounter++;
      67           0 :       _force = _force + wrapper.getForce();
      68           0 :       _velocity = _velocity + wrapper.getVelocity();
      69           0 :       it->next();
      70             :     }
      71           0 :     delete it;
      72           0 :   }
      73             : 
      74             :   /** returns the force vectors inside a linked cell
      75             :    *    @return _force
      76             :    */
      77             :   tarch::la::Vector<dim, double> getAvgForce() const { return _force; }
      78             : 
      79             :   /** returns the velocity vectors inside a linked cell
      80             :    *    @return _velocity
      81             :    */
      82             :   tarch::la::Vector<dim, double> getAvgVelocity() const { return _velocity; }
      83             : 
      84             : private:
      85             :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      86             :   tarch::la::Vector<dim, double> _force;
      87             :   tarch::la::Vector<dim, double> _velocity;
      88             :   unsigned int _particleCounter;
      89             : };
      90             : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEAVGFORCEANDVELOCITY_H_

Generated by: LCOV version 1.14