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_CELLMAPPINGS_NIEVELOCITYIMPOSITIONMAPPING_H_ 6 : #define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_NIEVELOCITYIMPOSITIONMAPPING_H_ 7 : 8 : #include "coupling/CouplingMDDefinitions.h" 9 : #include "coupling/datastructures/CouplingCell.h" 10 : #include "coupling/interface/MDSolverInterface.h" 11 : #include "coupling/interface/Molecule.h" 12 : #include "tarch/la/Matrix.h" 13 : #include <iostream> 14 : 15 : namespace coupling { 16 : namespace cellmappings { 17 : template <class LinkedCell, unsigned int dim> class NieVelocityImpositionMapping; 18 : } 19 : } // namespace coupling 20 : 21 : /** employs an acceleration based on velocity gradients (in time) using the 22 : *forcing term of the molecules. We currently expect that valid force entries 23 : *are provided in each molecule, that is all molecule-molecule interactions have 24 : *previously been computed. The scheme follows the descriptions in the paper by 25 : *Nie et al., J. Fluid. Mech. 500, 55-64, 2004. However, we only average over 26 : *single grid cells (no averaging over one (periodic) dimension or similar 27 : *tricks ;-) ). 28 : * @brief This class employs an acceleration based on velocity gradients 29 : *(in time) using the forcing term of the molecules. 30 : * @tparam LinkedCell cell type 31 : * @tparam dim Number of dimensions; it can be 1, 2 or 3 32 : * @author Philipp Neumann 33 : */ 34 : template <class LinkedCell, unsigned int dim> class coupling::cellmappings::NieVelocityImpositionMapping { 35 : public: 36 : /** Constructor 37 : * @param continuumVelocity current velocity in this coupling cell 38 : *(=velocity from continuum solver) 39 : * @param avgMDVelocity current avg. velocity of molecules 40 : * @param avgForce average force within this 41 : *coupling cell 42 : * @param mdSolverInterface MD solver interface, required for 43 : *molecule iterator and molecule mass 44 : */ 45 0 : NieVelocityImpositionMapping(const tarch::la::Vector<dim, double>& continuumVelocity, const tarch::la::Vector<dim, double>& avgMDVelocity, 46 : const tarch::la::Vector<dim, double>& avgForce, coupling::interface::MDSolverInterface<LinkedCell, dim>* const mdSolverInterface) 47 0 : : _mdSolverInterface(mdSolverInterface), _continuumVelocity(continuumVelocity), _avgMDVelocity(avgMDVelocity), _avgForce(avgForce) {} 48 : 49 : /** Destructor */ 50 0 : virtual ~NieVelocityImpositionMapping() {} 51 : 52 : /** empty function 53 : */ 54 : void beginCellIteration() {} 55 : 56 : /** empty function 57 : */ 58 : void endCellIteration() {} 59 : 60 : /** This function computes average force contribution inside this linked cell 61 : * @param cell 62 : */ 63 0 : void handleCell(LinkedCell& cell) { 64 0 : coupling::interface::MoleculeIterator<LinkedCell, dim>* it = _mdSolverInterface->getMoleculeIterator(cell); 65 : 66 0 : it->begin(); 67 0 : while (it->continueIteration()) { 68 0 : coupling::interface::Molecule<dim>& wrapper(it->get()); 69 0 : tarch::la::Vector<dim, double> force(wrapper.getForce()); 70 0 : force = force - _avgForce - (_mdSolverInterface->getMoleculeMass() / _mdSolverInterface->getDt()) * (_avgMDVelocity - _continuumVelocity); 71 0 : wrapper.setForce(force); 72 0 : it->next(); 73 : } 74 0 : delete it; 75 0 : } 76 : 77 : private: 78 : /** MD solver interface, required for molecule iterator and molecule mass */ 79 : coupling::interface::MDSolverInterface<LinkedCell, dim>* const _mdSolverInterface; 80 : /** current velocity in this coupling cell (=velocity from continuum 81 : * solver) */ 82 : const tarch::la::Vector<dim, double> _continuumVelocity; 83 : /** current avg. velocity of molecules */ 84 : const tarch::la::Vector<dim, double> _avgMDVelocity; 85 : /** average force within this coupling cell */ 86 : const tarch::la::Vector<dim, double> _avgForce; 87 : }; 88 : 89 : #endif // _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_NIEVELOCITYIMPOSITIONMAPPING_H_