LCOV - code coverage report
Current view: top level - coupling/configurations - TransferStrategyConfiguration.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 58.8 % 51 30
Test Date: 2026-08-21 15:14:06 Functions: 40.0 % 5 2

            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_STRATEGYCONFIGURATION_H_
       6              : #define _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_STRATEGYCONFIGURATION_H_
       7              : 
       8              : #include "coupling/transferstrategies/AveragingTransferStrategy.h"
       9              : #include "coupling/transferstrategies/DifferenceTransferStrategy.h"
      10              : #include "coupling/transferstrategies/DirectTransferStrategy.h"
      11              : #include "coupling/transferstrategies/TransferStrategy.h"
      12              : #include "coupling/transferstrategies/TransferStrategy4NieCoupling.h"
      13              : #include "coupling/transferstrategies/TransferStrategy4SchwarzCoupling.h"
      14              : #include "tarch/configuration/Configuration.h"
      15              : #include "tarch/configuration/ParseConfiguration.h"
      16              : #include "tarch/la/Vector.h"
      17              : #include <iostream>
      18              : 
      19              : namespace coupling {
      20              : namespace configurations {
      21              : template <unsigned int dim> class TransferStrategyConfiguration;
      22              : }
      23              : } // namespace coupling
      24              : 
      25              : /** transfer strategy configuration, i.e. algorithm/combin. of quantity transfer
      26              :  *steps and quantity interpretation (e.g. momentum vs. velocity). Derive from
      27              :  *the class tarch::configuration::Configuration
      28              :  *      @brief transfer strategy configuration, i.e. algorithm/combin. of
      29              :  *quantity transfer steps and quantity interpretation (e.g. momentum vs.
      30              :  *velocity).
      31              :  *      @tparam dim Number of dimensions; it can be 1, 2 or 3
      32              :  *  @author Philipp Neumann
      33              :  */
      34              : template <unsigned int dim> class coupling::configurations::TransferStrategyConfiguration : public tarch::configuration::Configuration {
      35              : public:
      36              :   /** transfer strategy types that are implemented.
      37              :    *    @enum StrategyType
      38              :    */
      39              :   enum StrategyType {
      40              :     DirectTransferStrategy = 0 /**< DirectTransferStrategy*/,
      41              :     DifferenceTransferStrategy = 1 /**< DifferenceTransferStrategy*/,
      42              :     TransferStrategy4FluxCoupling = 2 /**< TransferStrategy4FluxCoupling*/,
      43              :     TransferStrategy4SchwarzCoupling = 3 /**< TransferStrategy4SchwarzCoupling*/,
      44              :     AveragingTransferStrategy = 4 /**< AveragingTransferStrategy*/,
      45              :     TransferStrategy4NieCoupling = 5 /**< TransferStrategy4NieCoupling*/
      46              :   };
      47              : 
      48              :   /** Constructor, initializes the class  */
      49          816 :   TransferStrategyConfiguration() : _type(DirectTransferStrategy), _massFluxBoundary(false), _isValid(true) {}
      50              : 
      51              :   /** Destructor */
      52          412 :   virtual ~TransferStrategyConfiguration() {}
      53              : 
      54              :   /** parseSubtag
      55              :    *    @param node
      56              :    */
      57            4 :   void parseSubtag(tinyxml2::XMLElement* node) {
      58            4 :     std::string value;
      59            4 :     tarch::configuration::ParseConfiguration::readStringMandatory(value, node, "type");
      60            4 :     if (value == "direct-transfer") {
      61            0 :       _type = DirectTransferStrategy;
      62            4 :     } else if (value == "difference-transfer") {
      63            0 :       _type = DifferenceTransferStrategy;
      64            4 :     } else if (value == "schwarz-transfer") {
      65            0 :       _type = TransferStrategy4SchwarzCoupling;
      66            4 :     } else if (value == "nie-transfer") {
      67            4 :       _type = TransferStrategy4NieCoupling;
      68            0 :     } else if (value == "averaging") {
      69            0 :       _type = AveragingTransferStrategy;
      70              :     } else {
      71            0 :       std::cout << "ERROR coupling::TransferStrategyConfiguration: Wrong "
      72              :                    "insertion type!"
      73            0 :                 << std::endl;
      74            0 :       _isValid = false;
      75            0 :       exit(EXIT_FAILURE);
      76              :     }
      77              : 
      78            4 :     if (_type == TransferStrategy4NieCoupling) {
      79           28 :       const std::string boundaries[6] = {"mass-flux-west", "mass-flux-east", "mass-flux-south", "mass-flux-north", "mass-flux-bottom", "mass-flux-top"};
      80           28 :       for (unsigned int d = 0; d < 2 * dim; d++) {
      81           72 :         tarch::configuration::ParseConfiguration::readBoolMandatory(_massFluxBoundary[d], node, boundaries[d]);
      82              :       }
      83              :       // by default: no shifting of time interval
      84            4 :       _shiftTimestep = 0.0;
      85            4 :       tarch::configuration::ParseConfiguration::readDoubleOptional(_shiftTimestep, node, "shift-by-timesteps");
      86            4 :       if (_shiftTimestep < 0.0 || _shiftTimestep > 1.0) {
      87            0 :         std::cout << "Warning "
      88              :                      "coupling::configurations::TransferStrategyConfiguration: "
      89              :                      "shift-by-timesteps="
      90            0 :                   << _shiftTimestep << "; typical values range between 0 and 1!" << std::endl;
      91              :       }
      92              : 
      93            4 :       _energyCorrection = false;
      94            4 :       _density = 1;
      95            4 :       tarch::configuration::ParseConfiguration::readBoolOptional(_energyCorrection, node, "energy-correction");
      96            4 :       if (_energyCorrection) {
      97            0 :         tarch::configuration::ParseConfiguration::readDoubleMandatory(_density, node, "density");
      98              :       }
      99           28 :     }
     100            4 :   }
     101              : 
     102              :   /** Returns name of xml tag that is associated to the configuration.
     103              :    *    @return name of xml tag that is associated to the configuration
     104              :    */
     105           16 :   std::string getTag() const { return "transfer-strategy"; }
     106              : 
     107              :   /** checks if the configuration is valid. This operation usually fails, if
     108              :    *e.g.
     109              :    *    1. parseSubtag() hasn't been called, i.e. configuration has not been
     110              :    *used, or
     111              :    *  2. parseSubtag() failed due to a wrong file.
     112              :    *  3. If a tag ain't optional and parseSubtag() was not called (first case)
     113              :    *    @return _isValid
     114              :    */
     115            4 :   bool isValid() const { return _isValid; }
     116              : 
     117              :   /** Returns transfer strategy configuration.
     118              :    *    @tparam LinkedCell type of the cell
     119              :    *    @param mdSolverInterface
     120              :    *    @param numberOfMDTimesteps
     121              :    *    @return transfer strategy config
     122              :    */
     123              :   template <class LinkedCell>
     124              :   coupling::transferstrategies::TransferStrategy<LinkedCell, dim>*
     125            4 :   interpreteConfiguration(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface, unsigned int numberOfMDTimesteps) const {
     126            4 :     if (_type == DirectTransferStrategy) {
     127            4 :       return new coupling::transferstrategies::DirectTransferStrategy<LinkedCell, dim>(mdSolverInterface);
     128            0 :     } else if (_type == DifferenceTransferStrategy) {
     129            0 :       return new coupling::transferstrategies::DifferenceTransferStrategy<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps);
     130            0 :     } else if (_type == TransferStrategy4SchwarzCoupling) {
     131            0 :       return new coupling::transferstrategies::TransferStrategy4SchwarzCoupling<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps);
     132            0 :     } else if (_type == TransferStrategy4NieCoupling) {
     133            0 :       return new coupling::transferstrategies::TransferStrategy4NieCoupling<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps, _shiftTimestep,
     134            0 :                                                                                              _massFluxBoundary, _energyCorrection, _density);
     135            0 :     } else if (_type == AveragingTransferStrategy) {
     136            0 :       return new coupling::transferstrategies::AveragingTransferStrategy<LinkedCell, dim>(mdSolverInterface);
     137              :     } else {
     138              :       return NULL;
     139              :     }
     140              :   }
     141              : 
     142              :   /** Returns the transfer strategy type.
     143              :    *    @return _type
     144              :    */
     145              :   StrategyType getStrategyType() const { return _type; }
     146              : 
     147              : protected:
     148            4 :   TransferStrategyConfiguration(StrategyType type, tarch::la::Vector<2 * dim, bool> massFluxBoundary, double shiftTimestep)
     149            4 :       : _type(type), _massFluxBoundary(massFluxBoundary), _shiftTimestep(shiftTimestep), _isValid(true) {}
     150              : 
     151              : private:
     152              :   StrategyType _type;
     153              :   tarch::la::Vector<2 * dim, bool> _massFluxBoundary; // true in each component, if one of the 2*dim
     154              :                                                       // boundaries allows for mass flux
     155              :   double _shiftTimestep;                              // used for Nie coupling: time interval by which the
     156              :                                                       // evaluation of the continuum flow field should be
     157              :                                                       // shifted. See also TransferStrategy4NieCoupling for
     158              :                                                       // more details.
     159              : 
     160              :   bool _isValid;
     161              :   bool _energyCorrection;
     162              :   double _density;
     163              : };
     164              : 
     165              : #endif // _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_STRATEGYCONFIGURATION_H_
        

Generated by: LCOV version 2.0-1