LCOV - code coverage report
Current view: top level - coupling - SetGivenVelocity4MomentumInsertion.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 % 4 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_SETGIVENVELOCITY4MOMENTUMINSERTION_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_SETGIVENVELOCITY4MOMENTUMINSERTION_H_
       7              : 
       8              : #include "coupling/MomentumInsertion.h"
       9              : #include "coupling/cell-mappings/ComputeMassMapping.h"
      10              : #include "coupling/cell-mappings/ComputeMomentumMapping.h"
      11              : #include "coupling/cell-mappings/SetMomentumMapping.h"
      12              : #include "coupling/interface/MDSolverInterface.h"
      13              : 
      14              : namespace coupling {
      15              : template <class LinkedCell, unsigned int dim> class SetGivenVelocity4MomentumInsertion;
      16              : }
      17              : 
      18              : /** interpretes the microscopicMomentum-buffer as velocity and sets this value
      19              :  * in the respective coupling cell.
      20              :  *  @author Philipp Neumann
      21              :  *  @tparam LinkedCell the LinkedCell class is given by the implementation of
      22              :  * linked cells in the molecular dynamics simulation
      23              :  *  @tparam dim  refers to the spacial dimension of the simulation, can be 1, 2,
      24              :  * or 3  */
      25              : template <class LinkedCell, unsigned int dim> class coupling::SetGivenVelocity4MomentumInsertion : public coupling::MomentumInsertion<LinkedCell, dim> {
      26              : public:
      27              :   /** @brief a simple constructor
      28              :    *  @param mdSolverInterface interface for the md solver */
      29            0 :   SetGivenVelocity4MomentumInsertion(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface)
      30            0 :       : coupling::MomentumInsertion<LinkedCell, dim>(mdSolverInterface) {}
      31              : 
      32              :   /** @brief a simple destructor */
      33            0 :   virtual ~SetGivenVelocity4MomentumInsertion() {}
      34              : 
      35              :   /** @brief returns 1, since momentum insertions will be applied in every md
      36              :    * timestep
      37              :    *  @returns the time step interval for momentum insertion */
      38            0 :   unsigned int getTimeIntervalPerMomentumInsertion() const override { return 1; }
      39              : 
      40              :   /** This method does not conserve the kinetic energy of the respective
      41              :    * coupling cell. To conserve the energy as well, see the description of
      42              :    * MomentumController on details how to do that.
      43              :    *  @brief updates the momentum based on the microscopic momentum
      44              :    *  @param cell coupling cell
      45              :    */
      46            0 :   void insertMomentum(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, I02 idx) const override {
      47            0 :     coupling::cellmappings::ComputeMassMapping<LinkedCell, dim> massMapping(coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
      48            0 :     coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> momentumMapping(coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
      49              : 
      50              :     // old and new momentum
      51            0 :     tarch::la::Vector<dim, double> oldMomentum(0.0);
      52            0 :     tarch::la::Vector<dim, double> newMomentum(0.0);
      53            0 :     unsigned int particleCounter = 0;
      54              : 
      55            0 :     cell.iterateConstCells(massMapping);
      56            0 :     cell.iterateConstCells(momentumMapping);
      57              :     // set old momentum
      58            0 :     oldMomentum = momentumMapping.getMomentum();
      59              :     // set new momentum (only number of particles is missing)
      60            0 :     newMomentum = massMapping.getMass() * cell.getMicroscopicMomentum();
      61            0 :     particleCounter = massMapping.getNumberOfParticles();
      62              : 
      63              :     // set new momentum (based on velocity stored in microscopic
      64              :     // momentum-buffer)
      65            0 :     coupling::cellmappings::SetMomentumMapping<LinkedCell, dim> setMomentumMapping(oldMomentum, newMomentum, particleCounter,
      66            0 :                                                                                    coupling::MomentumInsertion<LinkedCell, dim>::_mdSolverInterface);
      67            0 :     cell.iterateCells(setMomentumMapping);
      68            0 :   }
      69              : 
      70            0 :   void setInnerImposition(bool enable) override {
      71            0 :     throw std::runtime_error(std::string("coupling::AdditiveMomentumInsertion::setInnerImposition not implemented"));
      72              :   }
      73              : };
      74              : #endif // _MOLECULARDYNAMICS_COUPLING_SETGIVENVELOCITY4MOMENTUMINSERTION_H_
        

Generated by: LCOV version 2.0-1