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 672 : TransferStrategyConfiguration() : _type(DirectTransferStrategy), _massFluxBoundary(false), _isValid(true) {} 50 : 51 : /** Destructor */ 52 340 : virtual ~TransferStrategyConfiguration() {} 53 : 54 : /** parseSubtag 55 : * @param node 56 : */ 57 4 : void parseSubtag(tinyxml2::XMLElement* node) { 58 4 : std::string value; 59 8 : 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 48 : 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 28 : } 93 4 : } 94 : 95 : /** Returns name of xml tag that is associated to the configuration. 96 : * @return name of xml tag that is associated to the configuration 97 : */ 98 16 : std::string getTag() const { return "transfer-strategy"; } 99 : 100 : /** checks if the configuration is valid. This operation usually fails, if 101 : *e.g. 102 : * 1. parseSubtag() hasn't been called, i.e. configuration has not been 103 : *used, or 104 : * 2. parseSubtag() failed due to a wrong file. 105 : * 3. If a tag ain't optional and parseSubtag() was not called (first case) 106 : * @return _isValid 107 : */ 108 4 : bool isValid() const { return _isValid; } 109 : 110 : /** Returns transfer strategy configuration. 111 : * @tparam LinkedCell type of the cell 112 : * @param mdSolverInterface 113 : * @param numberOfMDTimesteps 114 : * @return transfer strategy config 115 : */ 116 : template <class LinkedCell> 117 : coupling::transferstrategies::TransferStrategy<LinkedCell, dim>* 118 4 : interpreteConfiguration(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface, unsigned int numberOfMDTimesteps) const { 119 4 : if (_type == DirectTransferStrategy) { 120 4 : return new coupling::transferstrategies::DirectTransferStrategy<LinkedCell, dim>(mdSolverInterface); 121 0 : } else if (_type == DifferenceTransferStrategy) { 122 0 : return new coupling::transferstrategies::DifferenceTransferStrategy<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps); 123 0 : } else if (_type == TransferStrategy4SchwarzCoupling) { 124 0 : return new coupling::transferstrategies::TransferStrategy4SchwarzCoupling<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps); 125 0 : } else if (_type == TransferStrategy4NieCoupling) { 126 0 : return new coupling::transferstrategies::TransferStrategy4NieCoupling<LinkedCell, dim>(mdSolverInterface, numberOfMDTimesteps, _shiftTimestep, 127 0 : _massFluxBoundary); 128 0 : } else if (_type == AveragingTransferStrategy) { 129 0 : return new coupling::transferstrategies::AveragingTransferStrategy<LinkedCell, dim>(mdSolverInterface); 130 : } else { 131 : return NULL; 132 : } 133 : } 134 : 135 : /** Returns the transfer strategy type. 136 : * @return _type 137 : */ 138 : StrategyType getStrategyType() const { return _type; } 139 : 140 : protected: 141 4 : TransferStrategyConfiguration(StrategyType type, tarch::la::Vector<2 * dim, bool> massFluxBoundary, double shiftTimestep) 142 4 : : _type(type), _massFluxBoundary(massFluxBoundary), _shiftTimestep(shiftTimestep), _isValid(true) {} 143 : 144 : private: 145 : StrategyType _type; 146 : tarch::la::Vector<2 * dim, bool> _massFluxBoundary; // true in each component, if one of the 2*dim 147 : // boundaries allows for mass flux 148 : double _shiftTimestep; // used for Nie coupling: time interval by which the 149 : // evaluation of the continuum flow field should be 150 : // shifted. See also TransferStrategy4NieCoupling for 151 : // more details. 152 : 153 : bool _isValid; 154 : }; 155 : 156 : #endif // _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_STRATEGYCONFIGURATION_H_