LCOV - code coverage report
Current view: top level - coupling/cell-mappings - DeleteParticleMapping.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 22 0.0 %
Date: 2025-06-25 11:26:37 Functions: 0 2 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_DELETEPARTICLEMAPPING_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_DELETEPARTICLEMAPPING_H_
       7             : 
       8             : #include "coupling/datastructures/Molecule.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 DeleteParticleMapping;
      16             : }
      17             : } // namespace coupling
      18             : 
      19             : /**
      20             :  *      @brief This class deletes a certain particle from a coupling cell.
      21             :  *      @tparam LinkedCell cell type
      22             :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      23             :  *  @author Philipp Neumann
      24             :  */
      25             : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::DeleteParticleMapping {
      26             : public:
      27             :   /** Constructor
      28             :    *    @param particle
      29             :    *    @param mdSolverInterface
      30             :    */
      31           0 :   DeleteParticleMapping(const unsigned int& particle, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      32           0 :       : _mdSolverInterface(mdSolverInterface), _particle(particle), _particleCounter(0),
      33           0 :         _deletedMoleculeCopy(tarch::la::Vector<dim, double>(0.0), tarch::la::Vector<dim, double>(0.0), tarch::la::Vector<dim, double>(0.0), 0.0) {}
      34             : 
      35             :   /** Destructor */
      36           0 :   ~DeleteParticleMapping() {}
      37             : 
      38             :   /** sets the particle counter to zero, before the iteration process begins.
      39             :    */
      40           0 :   void beginCellIteration() { _particleCounter = 0; }
      41             : 
      42             :   /** empty function
      43             :    */
      44             :   void endCellIteration() {}
      45             : 
      46             :   /** This function saves a copy of particle that has to be deleted, then
      47             :    *deletes the molecule from MD simulation. It does nothiung, if the particle
      48             :    *is already deleted.
      49             :    *    @param cell
      50             :    */
      51           0 :   void handleCell(LinkedCell& cell) {
      52             :     // return, if we already deleted the respective particle
      53           0 :     if (_particleCounter > _particle) {
      54             :       return;
      55             :     }
      56             : 
      57             :     // otherwise: loop over particles
      58           0 :     coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell);
      59           0 :     it->begin();
      60           0 :     while (it->continueIteration()) {
      61             :       // if we reached the respective particle, delete it
      62           0 :       if (_particleCounter == _particle) {
      63           0 :         const coupling::interface::Molecule<dim>& myMolecule(it->getConst());
      64             : 
      65             :         // save copy of particle
      66           0 :         const tarch::la::Vector<dim, double> position = myMolecule.getPosition();
      67           0 :         const tarch::la::Vector<dim, double> velocity = myMolecule.getVelocity();
      68           0 :         const tarch::la::Vector<dim, double> force = myMolecule.getForce();
      69           0 :         const double potentialEnergy = myMolecule.getPotentialEnergy();
      70           0 :         _deletedMoleculeCopy = coupling::datastructures::Molecule<dim>(position, velocity, force, potentialEnergy);
      71             : 
      72             :         // delete molecule from MD simulation
      73           0 :         _mdSolverInterface->deleteMoleculeFromMDSimulation(myMolecule, cell);
      74           0 :         _particleCounter++;
      75             :         break;
      76             :       }
      77           0 :       _particleCounter++;
      78             : 
      79           0 :       it->next();
      80             :     }
      81           0 :     delete it;
      82             :   }
      83             : 
      84             :   /** returns a copy of the deleted molecule.
      85             :    *    @return _deletedMoleculeCopy
      86             :    */
      87             :   coupling::datastructures::Molecule<dim> getDeletedMolecule() const { return _deletedMoleculeCopy; }
      88             : 
      89             : private:
      90             :   coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface;
      91             :   const unsigned int _particle;
      92             :   unsigned int _particleCounter;
      93             :   coupling::datastructures::Molecule<dim> _deletedMoleculeCopy;
      94             : };
      95             : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_DELETEPARTICLEMAPPING_H_

Generated by: LCOV version 1.14