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_TRANSFERSTRATEGIES_DIRECTTRANSFERSTRATEGY_H_ 6 : #define _MOLECULARDYNAMICS_COUPLING_TRANSFERSTRATEGIES_DIRECTTRANSFERSTRATEGY_H_ 7 : 8 : #include "coupling/cell-mappings/ComputeMassMapping.h" 9 : #include "coupling/cell-mappings/ComputeMomentumMapping.h" 10 : #include "coupling/transferstrategies/TransferStrategy.h" 11 : #include "tarch/la/Vector.h" 12 : 13 : namespace coupling { 14 : namespace transferstrategies { 15 : template <class LinkedCell, unsigned int dim> class DirectTransferStrategy; 16 : } 17 : } // namespace coupling 18 : 19 : /** transfers and introduces mass and momentum directly into MD and to 20 : * macroscopic solver. So, for example, if mass M is coming from the macroscopic 21 : * solver, M is to be inserted into MD. 22 : * @author Philipp Neumann 23 : * @tparam LinkedCell the LinkedCell class is given by the implementation of 24 : * linked cells in the molecular dynamics simulation 25 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2, 26 : * or 3 */ 27 : template <class LinkedCell, unsigned int dim> 28 : class coupling::transferstrategies::DirectTransferStrategy : public coupling::transferstrategies::TransferStrategy<LinkedCell, dim> { 29 : public: 30 : /** @brief a simple constructor 31 : * @param mdSolverInterface interface for the md solver*/ 32 4 : DirectTransferStrategy(coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) 33 4 : : coupling::transferstrategies::TransferStrategy<LinkedCell, dim>(mdSolverInterface), _massMapping(mdSolverInterface), 34 4 : _momentumMapping(mdSolverInterface) {} 35 : 36 : /** @brief a dummy destructor*/ 37 0 : virtual ~DirectTransferStrategy() {} 38 : 39 : /** @brief the microscopicMass and -Momentum are set to 0 40 : * @param cell coupling cell to process 41 : * @param index index of the coupling cell */ 42 0 : void processInnerCouplingCellBeforeReceivingMacroscopicSolverData(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, 43 : I02 index) override { 44 : // reset quantities 45 0 : const tarch::la::Vector<dim, double> zero(0.0); 46 0 : cell.setMicroscopicMass(0.0); 47 0 : cell.setMicroscopicMomentum(zero); 48 0 : } 49 : 50 : /** @brief the microscopicMass and -Momentum are set to 0 51 : * @param cell coupling cell to process 52 : * @param index index of the coupling cell */ 53 0 : void processOuterCouplingCellBeforeReceivingMacroscopicSolverData(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, 54 : I02 index) override { 55 : // reset quantities 56 0 : const tarch::la::Vector<dim, double> zero(0.0); 57 0 : cell.setMicroscopicMass(0.0); 58 0 : cell.setMicroscopicMomentum(zero); 59 0 : } 60 : 61 : /** @brief the mass and momentum is evaluated for the cell and written to the 62 : * macroscopic quantities 63 : * @param cell coupling cell to process 64 : * @param index index of the coupling cell */ 65 0 : void processInnerCouplingCellBeforeSendingMDSolverData(coupling::datastructures::CouplingCellWithLinkedCells<LinkedCell, dim>& cell, I02 index) override { 66 0 : cell.iterateConstCells(_massMapping); 67 0 : cell.iterateConstCells(_momentumMapping); 68 0 : cell.setMacroscopicMass(_massMapping.getMass()); 69 0 : cell.setMacroscopicMomentum(_momentumMapping.getMomentum()); 70 0 : } 71 : 72 : private: 73 : /** necessary to compute the mass in every single cell */ 74 : coupling::cellmappings::ComputeMassMapping<LinkedCell, dim> _massMapping; 75 : /** necessary to compute the momentum in every single cell */ 76 : coupling::cellmappings::ComputeMomentumMapping<LinkedCell, dim> _momentumMapping; 77 : }; 78 : #endif // _MOLECULARDYNAMICS_COUPLING_TRANSFERSTRATEGIES_DIRECTTRANSFERSTRATEGY_H_