LCOV - code coverage report
Current view: top level - coupling/cell-mappings - ComputeMeanPotentialEnergyMapping.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 21 0
Test Date: 2026-08-21 15:14:06 Functions: 0.0 % 1 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_COMPUTEMEANPOTENTIALENERGYMAPPING_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEMEANPOTENTIALENERGYMAPPING_H_
       7              : 
       8              : #include "coupling/BoundaryForceController.h"
       9              : #include "coupling/interface/MDSolverInterface.h"
      10              : #include "coupling/interface/Molecule.h"
      11              : #include <iostream>
      12              : 
      13              : namespace coupling {
      14              : namespace cellmappings {
      15              : template <class LinkedCell, unsigned int dim> class ComputeMeanPotentialEnergyMapping;
      16              : }
      17              : } // namespace coupling
      18              : 
      19              : /**
      20              :  *      @brief This class computes the mean potential energy over this
      21              :  *coupling 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::ComputeMeanPotentialEnergyMapping {
      27              : public:
      28              :   /** Constructor
      29              :    *    @param mdSolverInterface
      30              :    *    @param boundaryForceController
      31              :    */
      32            0 :   ComputeMeanPotentialEnergyMapping(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface,
      33              :                                     const coupling::BoundaryForceController<LinkedCell, dim>& boundaryForceController)
      34            0 :       : _mdSolverInterface(mdSolverInterface), _meanPotentialEnergy(0.0), _particleCounter(0), _boundaryForceController(boundaryForceController) {}
      35              : 
      36              :   /** Destructor */
      37            0 :   ~ComputeMeanPotentialEnergyMapping() {}
      38              : 
      39              :   /** sets the mean potential energy and the particle counter to zero, before
      40              :    * the iteration process begins.
      41              :    */
      42            0 :   void beginCellIteration() {
      43            0 :     _meanPotentialEnergy = 0.0;
      44            0 :     _particleCounter = 0;
      45              :   }
      46              : 
      47              :   /** computes the mean potential energy in a linked cell, by dividing the
      48              :    * summation of the mean potential energy of all particles inside the cell
      49              :    * over the number of particles.
      50              :    */
      51            0 :   void endCellIteration() {
      52            0 :     if (_particleCounter != 0) {
      53            0 :       _meanPotentialEnergy = _meanPotentialEnergy / _particleCounter;
      54              :     }
      55              :   }
      56              : 
      57              :   /** counts the molecules inside a linked cell and sums up the of the mean
      58              :    *potential energy of all particles inside the 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 :       const coupling::interface::Molecule<dim>& wrapper(it->getConst());
      66            0 :       _meanPotentialEnergy += wrapper.getPotentialEnergy();
      67            0 :       _meanPotentialEnergy += _boundaryForceController.getPotentialEnergy(wrapper.getPosition());
      68            0 :       _particleCounter++;
      69              : 
      70            0 :       it->next();
      71              :     }
      72            0 :     delete it;
      73            0 :   }
      74              : 
      75              :   /** returns the mean potential energy inside a linked cell
      76              :    *    @return _meanPotentialEnergy
      77              :    */
      78            0 :   double getPotentialEnergy() const { return _meanPotentialEnergy; }
      79              : 
      80              : private:
      81              :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      82              :   double _meanPotentialEnergy;
      83              :   unsigned int _particleCounter;
      84              :   const coupling::BoundaryForceController<LinkedCell, dim>& _boundaryForceController;
      85              : };
      86              : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_COMPUTEMEANPOTENTIALENERGYMAPPING_H_
        

Generated by: LCOV version 2.0-1