LCOV - code coverage report
Current view: top level - coupling/configurations - ParticleInsertionConfiguration.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 15 86.7 %
Date: 2025-10-27 21:19:12 Functions: 1 3 33.3 %

          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_CONFIGURATIONS_PARTICLEINSERTIONCONFIGURATION_H_
       6             : #define _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_PARTICLEINSERTIONCONFIGURATION_H_
       7             : 
       8             : #include "coupling/NoParticleInsertion.h"
       9             : #include "coupling/UsherParticleInsertion.h"
      10             : #include "coupling/interface/MDSolverInterface.h"
      11             : #include "tarch/configuration/Configuration.h"
      12             : #include "tarch/configuration/ParseConfiguration.h"
      13             : #include "tarch/la/Vector.h"
      14             : #include <iostream>
      15             : 
      16             : namespace coupling {
      17             : namespace configurations {
      18             : class ParticleInsertionConfiguration;
      19             : }
      20             : } // namespace coupling
      21             : 
      22             : /** configuration for particle insertion algorithm (e.g.: USHER). Derive from
      23             :  *the class tarch::configuration::Configuration
      24             :  *      @brief configuration for particle insertion algorithm (e.g.: USHER).
      25             :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      26             :  *  @author Philipp Neumann
      27             :  */
      28             : class coupling::configurations::ParticleInsertionConfiguration : public tarch::configuration::Configuration {
      29             : public:
      30             :   /** Constructor, initializes the class  */
      31         336 :   ParticleInsertionConfiguration()
      32         336 :       : _insertDeleteMassEveryTimestep(1), _rSigmaCoeff(0.0), _meanPotentialEnergyFactor(0.0), _uOverlapCoeff(0.0), _stepRefCoeff(0.0), _iterMax(0),
      33         336 :         _restartMax(0), _tolerance(0.0), _offsetFromOuterBoundary(0.0) {}
      34             : 
      35             :   /** Destructor */
      36         340 :   virtual ~ParticleInsertionConfiguration() {}
      37             : 
      38             :   /** parseSubtag
      39             :    *    @param node
      40             :    */
      41             :   void parseSubtag(tinyxml2::XMLElement* node);
      42             : 
      43             :   /** Returns name of xml tag that is associated to the configuration.
      44             :    *    @return name of xml tag that is associated to the configuration
      45             :    */
      46             :   std::string getTag() const;
      47             : 
      48             :   /** checks if the configuration is valid. This operation usually fails, if
      49             :    *e.g.
      50             :    *    1. parseSubtag() hasn't been called, i.e. configuration has not been
      51             :    *used, or
      52             :    *  2. parseSubtag() failed due to a wrong file.
      53             :    *  3. If a tag ain't optional and parseSubtag() was not called (first case)
      54             :    *    @return _isValid
      55             :    */
      56             :   bool isValid() const;
      57             : 
      58             :   /** Returns particle insertion config
      59             :    *    @tparam LinkedCell type of the cell
      60             :    *    @tparam dim Number of dimensions; it can be 1, 2 or 3
      61             :    *    @param mdSolverInterface
      62             :    *    @return particle insertion config
      63             :    */
      64             :   template <class LinkedCell, unsigned int dim>
      65             :   coupling::ParticleInsertion<LinkedCell, dim>*
      66           4 :   interpreteConfiguration(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) const {
      67           4 :     if (_particleInsertionType == USHER) {
      68           0 :       return new coupling::UsherParticleInsertion<LinkedCell, dim>(_insertDeleteMassEveryTimestep, _rSigmaCoeff, _meanPotentialEnergyFactor, _uOverlapCoeff,
      69           0 :                                                                    _stepRefCoeff, _iterMax, _restartMax, _tolerance, _offsetFromOuterBoundary,
      70             :                                                                    mdSolverInterface);
      71           4 :     } else if (_particleInsertionType == NO_INSERTION) {
      72           4 :       return new coupling::NoParticleInsertion<LinkedCell, dim>();
      73             :     }
      74             : 
      75             :     // this case should never appear
      76             :     return NULL;
      77             :   }
      78             : 
      79             :   /** particle insertion types that are implemented.
      80             :    *    @enum ParticleInsertionType
      81             :    */
      82             :   enum ParticleInsertionType {
      83             :     USHER = 0 /**< Usher*/,
      84             :     NO_INSERTION = 1 /**< no particle insertion */
      85             :   };
      86             : 
      87             :   /** Returns the particle insertion type.
      88             :    *    @return _particleInsertionType
      89             :    */
      90           4 :   ParticleInsertionType getParticleInsertionType() const { return _particleInsertionType; }
      91             : 
      92             : protected:
      93           4 :   ParticleInsertionConfiguration(unsigned int insertDeleteMassEveryTimestep, double rSigmaCoeff, double meanPotentialEnergyFactor, double uOverlapCoeff,
      94             :                                  double stepRefCoeff, unsigned int iterMax, unsigned int restartMax, double tolerance, double offsetFromOuterBoundary,
      95             :                                  ParticleInsertionType particleInsertionType)
      96           4 :       : _insertDeleteMassEveryTimestep(insertDeleteMassEveryTimestep), _rSigmaCoeff(rSigmaCoeff), _meanPotentialEnergyFactor(meanPotentialEnergyFactor),
      97           4 :         _uOverlapCoeff(uOverlapCoeff), _stepRefCoeff(stepRefCoeff), _iterMax(iterMax), _restartMax(restartMax), _tolerance(tolerance),
      98           4 :         _offsetFromOuterBoundary(offsetFromOuterBoundary), _particleInsertionType(particleInsertionType) {};
      99             : 
     100             : private:
     101             :   static const std::string INSERT_DELETE_MASS_EVERY_TIMESTEP;
     102             :   static const std::string RSIGMA_COEFF;
     103             :   static const std::string MEAN_POTENTIAL_ENERGY_FACTOR;
     104             :   static const std::string UOVERLAP_COEFF;
     105             :   static const std::string STEPREF_COEFF;
     106             :   static const std::string ITER_MAX;
     107             :   static const std::string RESTART_MAX;
     108             :   static const std::string TOLERANCE;
     109             :   static const std::string OFFSET_FROM_OUTER_BOUNDARY;
     110             : 
     111             :   /** used to trigger mass insertion/deletion actions only every X time steps.
     112             :    * For NoParticleInsertion, a value of 1 is used since this is irrelevant in
     113             :    * this case. If the value is not specified in the configuration, a default
     114             :    * value of 1 is used. */
     115             :   unsigned int _insertDeleteMassEveryTimestep;
     116             : 
     117             :   /** r_sigma value. In the USHER paper, this value resembles the respective
     118             :    * parameter for choosing the stepsize when two particles overlap. In the
     119             :    * paper, it is stated that it should be close to unity (in sigma units; the
     120             :    *  parameter here is also used in sigma units of the respective molecules)
     121             :    * and is chosen to be 0.9. If the parameter is not defined in the config,
     122             :    * _rSigmaCoeff is also set to 0.9.
     123             :    */
     124             :   double _rSigmaCoeff;
     125             :   double _meanPotentialEnergyFactor;
     126             : 
     127             :   /** overlap energy. If not defined in the config, this value is set to 10^4.
     128             :    * It is typically given in units of epsilon (energy parameter of the LJ
     129             :    * fluid).
     130             :    */
     131             :   double _uOverlapCoeff;
     132             : 
     133             :   /** coefficient determining a reference step size when stepping towards the
     134             :    * right energy level. From the USHER paper (Usher - An algorithm for particle
     135             :    * insertion in dense fluids), this coefficient is optimally chosen to be 0.1
     136             :    * (in sigma units; this configuration also determines this parameter in sigma
     137             :    * units). Thus, the parameter is set to 0.1, if it is not defined within the
     138             :    * configuration.
     139             :    */
     140             :   double _stepRefCoeff;
     141             : 
     142             :   /** maximum number of USHER iteration steps within one insertion cycle */
     143             :   unsigned int _iterMax;
     144             : 
     145             :   /** maximum number of USHER restarts, that is USHER insertion cycles */
     146             :   unsigned int _restartMax;
     147             : 
     148             :   /** tolerance for USHER stopping criterion. If this is not specified, we
     149             :    *  set it to _meanPotentialEnergyFactor*2.0.
     150             :    */
     151             :   double _tolerance;
     152             : 
     153             :   /** enables valid particle positions only if the particle is at least at this
     154             :    * distance from an outer boundary. This is useful since open boundary forces
     155             :    * are not considered in the current USHER implementation. Inserting a
     156             :    * particle close to an outer open boundary may thus result in very strong
     157             :    * forces and, thus, yield instabilities.
     158             :    */
     159             :   double _offsetFromOuterBoundary;
     160             : 
     161             :   /** type of particle insertion algorithm */
     162             :   ParticleInsertionType _particleInsertionType;
     163             : };
     164             : #endif // _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_PARTICLEINSERTIONCONFIGURATION_H_

Generated by: LCOV version 1.14