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_COUPLINGCELLTRAVERSALWRAPPERS_H_ 6 : #define _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLTRAVERSALWRAPPERS_H_ 7 : 8 : /** the following wrappers and smaller functional classes are included in the 9 : * CouplingCellServiceImpl for internal use in this class only. They are used 10 : * together with the applyTo...() methods of CellContainer to bring 11 : * functionality which is defined cellwise onto the grid of coupling cells. 12 : * @author Philipp Neumann 13 : */ 14 : 15 : /** wrapper to carry out functionality on a single coupling cell. This 16 : * function can be called on several coupling cells using the callback 17 : * patterns of CellContainer. In the following, several wrappers are provided 18 : * for the TransferStrategy as well as some further functional stuff which is 19 : * required from the CouplingCellServiceImpl. 20 : */ 21 : class Wrapper { 22 : public: 23 0 : Wrapper(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : _thisPtr(thisPtr) {} 24 0 : virtual ~Wrapper() {} 25 : virtual void beginCellIteration() = 0; 26 : virtual void endCellIteration() = 0; 27 : virtual void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) = 0; 28 : 29 : protected: 30 : coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* _thisPtr; 31 : }; 32 : 33 : /** wrapper for method 34 : * processInnerCouplingCellBeforeReceivingMacroscopicSolverData of 35 : * TransferStrategy */ 36 0 : class Wrapper4ProcessInnerCouplingCellBeforeReceivingMacroscopicSolverData : public Wrapper { 37 : public: 38 0 : Wrapper4ProcessInnerCouplingCellBeforeReceivingMacroscopicSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) 39 0 : : Wrapper(thisPtr) {} 40 : 41 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessInnerCouplingCellsBeforeReceivingMacroscopicSolverData(); } 42 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessInnerCouplingCellsBeforeReceivingMacroscopicSolverData(); } 43 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 44 0 : Wrapper::_thisPtr->_transferStrategy->processInnerCouplingCellBeforeReceivingMacroscopicSolverData(cell, index); 45 0 : } 46 : }; 47 : 48 : /** wrapper for method 49 : * processOuterCouplingCellBeforeReceivingMacroscopicSolverData of 50 : * TransferStrategy */ 51 0 : class Wrapper4ProcessOuterCouplingCellBeforeReceivingMacroscopicSolverData : public Wrapper { 52 : public: 53 0 : Wrapper4ProcessOuterCouplingCellBeforeReceivingMacroscopicSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) 54 0 : : Wrapper(thisPtr) {} 55 : 56 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessOuterCouplingCellsBeforeReceivingMacroscopicSolverData(); } 57 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessOuterCouplingCellsBeforeReceivingMacroscopicSolverData(); } 58 : 59 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 60 0 : Wrapper::_thisPtr->_transferStrategy->processOuterCouplingCellBeforeReceivingMacroscopicSolverData(cell, index); 61 0 : } 62 : }; 63 : 64 : /** wrapper for method 65 : * processInnerCouplingCellAfterReceivingMacroscopicSolverData of 66 : * TransferStrategy */ 67 0 : class Wrapper4ProcessInnerCouplingCellAfterReceivingMacroscopicSolverData : public Wrapper { 68 : public: 69 0 : Wrapper4ProcessInnerCouplingCellAfterReceivingMacroscopicSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) 70 0 : : Wrapper(thisPtr) {} 71 : 72 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessInnerCouplingCellsAfterReceivingMacroscopicSolverData(); } 73 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessInnerCouplingCellsAfterReceivingMacroscopicSolverData(); } 74 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 75 0 : Wrapper::_thisPtr->_transferStrategy->processInnerCouplingCellAfterReceivingMacroscopicSolverData(cell, index); 76 0 : } 77 : }; 78 : 79 : /** wrapper for method 80 : * processOuterCouplingCellAfterReceivingMacroscopicSolverData of 81 : * TransferStrategy */ 82 0 : class Wrapper4ProcessOuterCouplingCellAfterReceivingMacroscopicSolverData : public Wrapper { 83 : public: 84 0 : Wrapper4ProcessOuterCouplingCellAfterReceivingMacroscopicSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) 85 0 : : Wrapper(thisPtr) {} 86 : 87 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessOuterCouplingCellsAfterReceivingMacroscopicSolverData(); } 88 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessOuterCouplingCellsAfterReceivingMacroscopicSolverData(); } 89 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 90 0 : Wrapper::_thisPtr->_transferStrategy->processOuterCouplingCellAfterReceivingMacroscopicSolverData(cell, index); 91 0 : } 92 : }; 93 : 94 : /** wrapper for method processInnerCouplingCellBeforeSendingMDSolverData of 95 : * TransferStrategy */ 96 0 : class Wrapper4ProcessInnerCouplingCellBeforeSendingMDSolverData : public Wrapper { 97 : public: 98 0 : Wrapper4ProcessInnerCouplingCellBeforeSendingMDSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 99 : 100 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessInnerCouplingCellsBeforeSendingMDSolverData(); } 101 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessInnerCouplingCellsBeforeSendingMDSolverData(); } 102 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 103 0 : Wrapper::_thisPtr->_transferStrategy->processInnerCouplingCellBeforeSendingMDSolverData(cell, index); 104 0 : } 105 : }; 106 : 107 : /** wrapper for method processOuterCouplingCellBeforeSendingMDSolverData of 108 : * TransferStrategy */ 109 0 : class Wrapper4ProcessOuterCouplingCellBeforeSendingMDSolverData : public Wrapper { 110 : public: 111 0 : Wrapper4ProcessOuterCouplingCellBeforeSendingMDSolverData(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 112 : 113 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessOuterCouplingCellsBeforeSendingMDSolverData(); } 114 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessOuterCouplingCellsBeforeSendingMDSolverData(); } 115 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 116 0 : Wrapper::_thisPtr->_transferStrategy->processOuterCouplingCellBeforeSendingMDSolverData(cell, index); 117 0 : } 118 : }; 119 : 120 : /** wrapper for method processInnerCouplingCellAfterMDTimestep of 121 : * TransferStrategy */ 122 0 : class Wrapper4ProcessInnerCouplingCellAfterMDTimestep : public Wrapper { 123 : public: 124 0 : Wrapper4ProcessInnerCouplingCellAfterMDTimestep(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 125 : 126 0 : void beginCellIteration() override { Wrapper::_thisPtr->_transferStrategy->beginProcessInnerCouplingCellsAfterMDTimestep(); } 127 0 : void endCellIteration() override { Wrapper::_thisPtr->_transferStrategy->endProcessInnerCouplingCellsAfterMDTimestep(); } 128 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 129 0 : Wrapper::_thisPtr->_transferStrategy->processInnerCouplingCellAfterMDTimestep(cell, index); 130 0 : } 131 : }; 132 : 133 : /** computes and stores the current velocity in each non-ghost coupling cell. 134 : */ 135 0 : class Wrapper4ComputeAndSetCurrentVelocity : public Wrapper { 136 : public: 137 0 : Wrapper4ComputeAndSetCurrentVelocity(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 138 : 139 0 : void beginCellIteration() override {} 140 0 : void endCellIteration() override {} 141 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 142 0 : coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> computeMomentumMapping(Wrapper::_thisPtr->_mdSolverInterface); 143 0 : cell.iterateConstCells(computeMomentumMapping); 144 0 : const tarch::la::Vector<dim, double> velocity = computeMomentumMapping.getMeanVelocity(); 145 0 : cell.setCurrentVelocity(velocity); 146 0 : } 147 : }; 148 : 149 : /** calls the MomentumInsertion-mechanisms on each non-ghost coupling cell, 150 : * including the energy controller */ 151 0 : class Wrapper4DistributeMomentum : public Wrapper { 152 : public: 153 0 : Wrapper4DistributeMomentum(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr, unsigned int t) : Wrapper(thisPtr) {} 154 : 155 0 : void beginCellIteration() override {} 156 0 : void endCellIteration() override {} 157 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 158 0 : const double temperature = Wrapper::_thisPtr->_kineticEnergyController.computeTemperature(cell); 159 0 : Wrapper::_thisPtr->_momentumInsertion->insertMomentum(cell, index); 160 0 : Wrapper::_thisPtr->_kineticEnergyController.setTemperature(cell, temperature); 161 0 : } 162 : }; 163 : 164 : /** computes and stores the temperature value in all non-ghost cells. If the 165 : * temperature parameter is set to -1.0, the current temperature of the 166 : * molecules in this cell is stored. Otherwise, the temperature variable is used 167 : * and applied to the molecules using the thermostat of the 168 : * KineticEnergyController. 169 : */ 170 0 : class Wrapper4ComputeAndStoreTemperature : public Wrapper { 171 : public: 172 0 : Wrapper4ComputeAndStoreTemperature(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr, double temperature) 173 0 : : Wrapper(thisPtr), _temperature(temperature) {} 174 : 175 0 : void beginCellIteration() override {} 176 0 : void endCellIteration() override {} 177 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 178 : // if this value is -1.0, we just set the temperature in the cell according 179 : // to current temperature... 180 0 : if (_temperature == -1.0) { 181 0 : const double myTemperature = Wrapper::_thisPtr->_kineticEnergyController.computeTemperature(cell); 182 0 : cell.setTemperature(myTemperature); 183 : // otherwise we use the temperature value of _setTemperature 184 : } else { 185 0 : cell.setTemperature(_temperature); 186 0 : Wrapper::_thisPtr->_kineticEnergyController.setTemperature(cell, _temperature); 187 : } 188 0 : } 189 : 190 : private: 191 : const double _temperature; 192 : }; 193 : 194 0 : class Wrapper4PerturbateVelocity : public Wrapper { 195 : public: 196 0 : Wrapper4PerturbateVelocity(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 197 : 198 0 : void beginCellIteration() override {} 199 0 : void endCellIteration() override {} 200 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 201 0 : coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> computeMomentumMapping(Wrapper::_thisPtr->_mdSolverInterface); 202 0 : cell.iterateConstCells(computeMomentumMapping); 203 : 204 0 : coupling::cellmappings::ComputeTemperatureMapping<LinkedCell, dim> computeTemperatureMapping(computeMomentumMapping.getMeanVelocity(), 205 0 : Wrapper::_thisPtr->_mdSolverInterface); 206 0 : cell.iterateConstCells(computeTemperatureMapping); 207 : 208 0 : coupling::cellmappings::PerturbateVelocityMapping<LinkedCell, dim> perturbateVelocity( 209 0 : Wrapper::_thisPtr->_mdSolverInterface, computeMomentumMapping.getMeanVelocity(), computeTemperatureMapping.getTemperature()); 210 : 211 0 : cell.iterateCells(perturbateVelocity); 212 0 : } 213 : }; 214 : 215 : /** applies the thermostat in all non-ghost cells */ 216 0 : class Wrapper4ApplyTemperature : public Wrapper { 217 : public: 218 0 : Wrapper4ApplyTemperature(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 219 : 220 0 : void beginCellIteration() override {} 221 0 : void endCellIteration() override {} 222 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 223 0 : const double temperature = cell.getTemperature(); 224 0 : Wrapper::_thisPtr->_kineticEnergyController.setTemperature(cell, temperature); 225 0 : } 226 : }; 227 : 228 : /** applies the boundary force in all non-ghost cells which are close to an open 229 : * boundary */ 230 0 : class Wrapper4ApplyBoundaryForce : public Wrapper { 231 : public: 232 0 : Wrapper4ApplyBoundaryForce(coupling::services::CouplingCellServiceImpl<LinkedCell, dim>* thisPtr) : Wrapper(thisPtr) {} 233 : 234 0 : void beginCellIteration() override {} 235 0 : void endCellIteration() override {} 236 0 : void apply(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, const I02& index) override { 237 0 : Wrapper::_thisPtr->_boundaryForceController->applyBoundaryForce(cell); 238 0 : } 239 : }; 240 : #endif // _MOLECULARDYNAMICS_COUPLING_COUPLINGCELLTRAVERSALWRAPPERS_H_