LCOV - code coverage report
Current view: top level - simplemd/services - MoleculeService.h Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-21 15:14:06 Functions: - 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_SERVICES_MOLECULESERVICE_H_
       6              : #define _MOLECULARDYNAMICS_SERVICES_MOLECULESERVICE_H_
       7              : 
       8              : #include "simplemd/MolecularDynamicsDefinitions.h"
       9              : #include "simplemd/Molecule.h"
      10              : #include "simplemd/MoleculeContainer.h"
      11              : #include "simplemd/molecule-mappings/ComputeMeanVelocityMapping.h"
      12              : #include "simplemd/molecule-mappings/SetMeanVelocityMapping.h"
      13              : #include "simplemd/services/MolecularPropertiesService.h"
      14              : #include "tarch/utils/RandomNumberService.h"
      15              : #include <cmath>
      16              : #include <cstdio>
      17              : #include <cstdlib>
      18              : #include <fstream>
      19              : #include <iostream>
      20              : #include <list>
      21              : #include <sstream>
      22              : #include <vector>
      23              : 
      24              : #include <Kokkos_Core.hpp>
      25              : 
      26              : namespace simplemd {
      27              : namespace services {
      28              : class MoleculeService;
      29              : 
      30              : // forward declarations to remove circular dependencies
      31              : class ParallelTopologyService;
      32              : } // namespace services
      33              : } // namespace simplemd
      34              : 
      35              : /** data service storing and managing all molecules which are lying on one
      36              :  * process.
      37              :  *
      38              :  *  @author Philipp Neumann
      39              :  */
      40              : class simplemd::services::MoleculeService {
      41              : public:
      42              :   ~MoleculeService();
      43              : 
      44              :   /** initialises the molecules. Therefore, the molecules are put onto a regular Cartesian grid with moleculesPerDirection
      45              :    *  molecules in each spatial direction within the domain described by domainSize and domainOffset.
      46              :    *  meanVelocity describes a mean flow velocity, temperature a temperature (controlling fluctuations).
      47              :    *  In addition, the numberMoleculesPerAllocation can be set: In case that molecules are added to the system, we need to
      48              :    *  allocate more memory. If more memory is needed, a block of numberMoleculesPerAllocation is to be introduced.
      49              :    */
      50              :   MoleculeService(const tarch::la::Vector<MD_DIM, double>& domainSize, const tarch::la::Vector<MD_DIM, double>& domainOffset,
      51              :                   const tarch::la::Vector<MD_DIM, unsigned int>& moleculesPerDirection, const tarch::la::Vector<MD_DIM, double>& meanVelocity, const double& kB,
      52              :                   const double& temperature, const double capacityFactor, const simplemd::services::MolecularPropertiesService& molecularPropertiesService,
      53              :                   const simplemd::services::ParallelTopologyService& parallelTopologyService);
      54              : 
      55              :   /** initialises the MD simulation from a checkpoint-file. For a parallel simulation, this method parses
      56              :    *  checkpoint files for each rank, respectively. If multiple MD simulations are executed, make sure that the rank of the current
      57              :    *  MD simulation matches the respective rank of the checkpoint file.
      58              :    */
      59              :   MoleculeService(const std::string& checkPointFileStem, const double capacityFactor,
      60              :                   const simplemd::services::ParallelTopologyService& parallelTopologyService);
      61              :   /** initialises a potentially parallel MD simulation from a sequential checkpoint file. */
      62              :   MoleculeService(const tarch::la::Vector<MD_DIM, double>& domainSize, const tarch::la::Vector<MD_DIM, double>& domainOffset,
      63              :                   const std::string& checkPointFileStem, const double capacityFactor,
      64              :                   const simplemd::services::ParallelTopologyService& parallelTopologyService);
      65              : 
      66              :   /** returns the number of molecules */
      67              :   unsigned int getLocalNumberOfMoleculesWithGhost() const;
      68              : 
      69              :   /** shuts down the service */
      70              :   void shutdown();
      71              : 
      72              :   /** creates initial velocity for molecule from meanVelocity and given temperature and stores the result in initialVelocity */
      73              :   void getInitialVelocity(const tarch::la::Vector<MD_DIM, double>& meanVelocity, const double& kB, const double& temperature,
      74              :                           const simplemd::services::MolecularPropertiesService& molecularPropertiesService,
      75              :                           tarch::la::Vector<MD_DIM, double>& initialVelocity) const;
      76              : 
      77              :   /** writes a checkpoint containing:
      78              :    *  - the number of molecules and the dimension of the problem (1,2 or 3) in one line
      79              :    *  - each molecule in one line consisting of position, velocity and force_old.
      80              :    *  In parallel cases, each process writes its own checkpoint data. The file will be named
      81              :    *  filestem_t_rank.dat in any case (rank=0 in the serial case).
      82              :    *  The mapping WriteCheckPointMapping is used.
      83              :    */
      84              :   void writeCheckPoint(const simplemd::services::ParallelTopologyService& parallelTopologyService, const std::string& filestem, const unsigned int& t);
      85              : 
      86              :   /** resets the velocity over the whole molecule system to the mean velocity specified at the beginning */
      87              :   void resetMeanVelocity();
      88              : 
      89            4 :   inline simplemd::MoleculeContainer& getContainer() const { return *_moleculeContainer; }
      90              : 
      91              :   tarch::la::Vector<MD_DIM, double> getLocalDomainSize() { return _localDomainSize; }
      92              : 
      93              :   static bool tarchDebugIsOn();
      94              : 
      95         4000 :   inline size_t getNextMoleculeID() { return _nextMoleculeID++; }
      96              : 
      97              : private:
      98              :   void initContainer(ParallelTopologyService parallelTopologyService, size_t moleculeCount, double capacityFactor);
      99              : 
     100              :   /** stores the mean velocity for normalisation */
     101              :   tarch::la::Vector<MD_DIM, double> _meanVelocity;
     102              : 
     103              :   /** stores the spatial extent of the local domain */
     104              :   const tarch::la::Vector<MD_DIM, double> _localDomainSize;
     105              : 
     106              :   simplemd::MoleculeContainer* _moleculeContainer = nullptr;
     107              : 
     108              :   size_t _nextMoleculeID = 0;
     109              : };
     110              : 
     111              : #endif // _MOLECULARDYNAMICS_SERVICES_MOLECULESERVICE_H_
        

Generated by: LCOV version 2.0-1