5#ifndef _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_VELOCITYGRADIENTRELAXATIONMAPPING_H_
6#define _MOLECULARDYNAMICS_COUPLING_CELLMAPPINGS_VELOCITYGRADIENTRELAXATIONMAPPING_H_
8#include "coupling/CouplingMDDefinitions.h"
9#include "coupling/datastructures/CouplingCell.h"
10#include "coupling/indexing/IndexingService.h"
11#include "coupling/interface/MDSolverInterface.h"
12#include "coupling/interface/Molecule.h"
13#include "tarch/la/Matrix.h"
17namespace cellmappings {
52 : _mdSolverInterface(mdSolverInterface), _couplingCells(couplingCells),
_velocityRelaxationFactor(velocityRelaxationFactor),
89#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
90 std::cout <<
"VelocityGradientRelaxationMapping: Process cell " << _cellIdx <<
", molecule " << position << std::endl;
94 bool secondCake =
false;
97 I02 couplingCellIndex[10];
107 oldVelocity = _couplingCells[_cellIdx.get()].getCurrentVelocity();
112#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
113 for (
unsigned int d = 0; d < dim; d++) {
114 if (normalisedPosition[d] > 2.0) {
115 std::cout <<
"ERROR cellmappings::VelocityGradientRelaxationMapping: "
116 "normalisedPosition>2.0! "
117 <<
"Local vector index=" << I03{_cellIdx} <<
" , global vector index=" << I01{_cellIdx} <<
", currentLocalCellIndex=" << _cellIdx
118 <<
", Norm. position=" << normalisedPosition <<
", Actual position=" << position << std::endl;
119 for (
unsigned int i = 0; i < 10; i++) {
120 std::cout << couplingCellIndex[i] <<
" ";
122 std::cout << std::endl;
125 if (normalisedPosition[d] < 0.0) {
126 std::cout <<
"ERROR cellmappings::VelocityGradientRelaxationMapping: "
127 "normalisedPosition<0.0! "
128 << I03{_cellIdx} <<
" ," << normalisedPosition << std::endl;
129 for (
unsigned int i = 0; i < 10; i++) {
130 std::cout << couplingCellIndex[i] <<
" ";
132 std::cout << std::endl;
136 if ((tarch::la::dot(newVelocity, newVelocity) > 1000.0) || (tarch::la::dot(oldVelocity, oldVelocity) > 1000.0)) {
137 for (
unsigned int i = 0; i < 10; i++) {
138 std::cout << couplingCellIndex[i] <<
" ";
140 std::cout << std::endl;
141 std::cout <<
"ERROR: velocity to high! " << oldVelocity <<
" " << newVelocity <<
" " << I03{_cellIdx} << std::endl;
160 bool isInsideOuter =
true;
161 bool isOutsideInner =
false;
162 for (
unsigned int d = 0; d < dim; d++) {
163 isInsideOuter = isInsideOuter && (position[d] > _outerLowerLeft[d]) && (position[d] < _outerUpperRight[d]);
164 isOutsideInner = isOutsideInner || (position[d] <
_innerLowerLeft[d]) || (position[d] > _innerUpperRight[d]);
166 return isInsideOuter && isOutsideInner;
176 bool innerCell =
true;
177 for (
unsigned int d = 0; d < dim; d++) {
209 return IDXS.getGlobalMDDomainOffset() + IDXS.getGlobalMDDomainSize() - 1.5 * IDXS.getCouplingCellSize();
219 return IDXS.getGlobalMDDomainOffset() + IDXS.getGlobalMDDomainSize() - 0.5 * IDXS.getCouplingCellSize();
229 bool& secondCake, I02* res)
const {
235 auto cellSize = IDXS.getCouplingCellSize();
240 for (
unsigned int d = 0; d < dim; d++) {
243#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
244 if ((position[d] < cellMidpoint[d] - 0.5 * cellSize[d]) || (position[d] > cellMidpoint[d] + 0.5 * cellSize[d])) {
245 std::cout <<
"ERROR "
246 "VelocityGradientRelaxationMapping::"
247 "createCouplingCellIndex4SecondOrderInterpolation: "
250 std::cout <<
" out of range of cell " << globalCellIndex <<
"!" << std::endl;
256 if (position[d] < cellMidpoint[d]) {
257 lowerLeftCellIndex[d]--;
258 globalCellIndex[d]--;
262 if (lowerLeftCellIndex[d] == 1) {
263 lowerLeftCellIndex[d]--;
264 globalCellIndex[d]--;
266 lowerLeftCellIndex[d]--;
267 globalCellIndex[d]--;
271 normalisedPosition[d] = (position[d] - (IDXS.getGlobalMDDomainOffset()[d] - 0.5 * cellSize[d]) - globalCellIndex[d] * cellSize[d]) / cellSize[d];
276 std::cout <<
"Not implemented correctly yet!" << std::endl;
278 }
else if (dim == 3) {
293 if (tarch::la::dot(relPos, normal) < 0.0) {
295 res[0] = I02{lowerLeftIndex};
296 res[1] = I02{lowerLeftIndex + 1};
297 res[2] = I02{lowerLeftIndex + 2};
299 res[4] = I02{lowerLeftIndex + localNumber2Cells0};
300 res[5] = I02{lowerLeftIndex + localNumberCells01};
302 res[7] = I02{lowerLeftIndex + 2 * localNumberCells01};
303 res[8] = I02{lowerLeftIndex + 2 * localNumberCells01 + 2};
304 res[9] = I02{lowerLeftIndex + localNumber2Cells01Plus2Cells0};
308 res[0] = I02{lowerLeftIndex + 2};
310 res[2] = I02{lowerLeftIndex + localNumber2Cells0};
311 res[3] = I02{lowerLeftIndex + localNumber2Cells0 + 1};
312 res[4] = I02{lowerLeftIndex + localNumber2Cells0 + 2};
315 res[7] = I02{lowerLeftIndex + 2 * localNumberCells01 + 2};
316 res[8] = I02{lowerLeftIndex + localNumber2Cells01Plus2Cells0};
317 res[9] = I02{lowerLeftIndex + localNumber2Cells01Plus2Cells0 + 2};
320 std::cout <<
"ERROR createCouplingCellIndex4Interpolation(position): "
321 "only 2D/3D supported!"
338 }
else if (dim == 3) {
344 for (
int i = 0; i < 10; i++) {
345 velocity[i] = _couplingCells[cellIndex[i].
get()].getMicroscopicMomentum();
351 2.0 * (velocity[0] + velocity[2] + velocity[9]) + 4.0 * (velocity[5] - velocity[1] - velocity[6] - velocity[3]) + 5.0 * velocity[4] - v78;
353 0.5 * (v78 - velocity[0]) + 2.0 * (velocity[1] - velocity[2] - velocity[5] + velocity[6]) + 4.0 * velocity[3] - 3.5 * velocity[4] - velocity[9];
355 2.0 * (velocity[3] - velocity[0] - velocity[5] + velocity[6]) + 4.0 * velocity[1] - 3.5 * velocity[4] + 0.5 * (v78 - velocity[2]) - velocity[9];
356 coefficients[3] = 0.5 * (v78 - velocity[0] - velocity[2] - velocity[4]) + 2.0 * velocity[6] - 1.5 * velocity[9];
357 coefficients[4] = 0.5 * (velocity[2] + velocity[4]) - velocity[3];
358 coefficients[5] = 0.5 * (velocity[0] + velocity[4]) - velocity[1];
359 coefficients[6] = 0.5 * (velocity[4] + velocity[9]) - velocity[6];
361 0.25 * (velocity[0] + velocity[2] - v78) - velocity[1] - velocity[3] + 1.5 * velocity[4] + velocity[5] - velocity[6] + 0.5 * velocity[9];
362 coefficients[8] = 0.25 * (velocity[2] - velocity[4] - velocity[8] + velocity[9]);
363 coefficients[9] = 0.25 * (velocity[0] - velocity[4] - velocity[7] + velocity[9]);
366 coefficients[0] = velocity[0];
367 coefficients[1] = minus15V0 + 2.0 * velocity[1] - 0.5 * velocity[2];
368 coefficients[2] = minus15V0 + 2.0 * velocity[3] - 0.5 * velocity[4];
369 coefficients[3] = minus15V0 + 2.0 * velocity[5] - 0.5 * velocity[7];
370 coefficients[4] = 0.5 * (velocity[0] + velocity[2]) - velocity[1];
371 coefficients[5] = 0.5 * (velocity[0] + velocity[4]) - velocity[3];
372 coefficients[6] = 0.5 * (velocity[0] + velocity[7]) - velocity[5];
373 coefficients[7] = 1.5 * velocity[0] + velocity[6] - velocity[1] - velocity[3] - velocity[5] + 0.5 * velocity[7] +
374 0.25 * (velocity[2] + velocity[4] - velocity[8] - velocity[9]);
375 coefficients[8] = 0.25 * (velocity[0] - velocity[2] - velocity[7] + velocity[8]);
376 coefficients[9] = 0.25 * (velocity[0] - velocity[4] - velocity[7] + velocity[9]);
381 normalisedPosition[0] *
382 (coefficients[1] + coefficients[4] * normalisedPosition[0] + coefficients[7] * normalisedPosition[1] + coefficients[8] * normalisedPosition[2]);
384 normalisedPosition[1] * (coefficients[2] + coefficients[5] * normalisedPosition[1] + coefficients[9] * normalisedPosition[2]);
387 newVelocity = coefficients[0] + contribution0 + contribution1 + contribution2;
405template <
class LinkedCell,
unsigned int dim>
448 return (position[dim - 1] > coupling::cellmappings::VelocityGradientRelaxationMapping<LinkedCell, dim>::_innerUpperRight[dim - 1]) &&
449 (position[dim - 1] < coupling::cellmappings::VelocityGradientRelaxationMapping<LinkedCell, dim>::_outerUpperRight[dim - 1]);
This class relaxes velocities of molecules towards an interpolated avergaged velocity value.
Definition VelocityGradientRelaxationMapping.h:38
virtual ~VelocityGradientRelaxationMapping()
Definition VelocityGradientRelaxationMapping.h:58
bool _ignoreThisCell
Definition VelocityGradientRelaxationMapping.h:198
tarch::la::Vector< dim, double > getInnerLowerLeftCorner() const
Definition VelocityGradientRelaxationMapping.h:204
void endCellIteration()
Definition VelocityGradientRelaxationMapping.h:66
tarch::la::Vector< dim, double > getOuterUpperRightCorner() const
Definition VelocityGradientRelaxationMapping.h:218
VelocityGradientRelaxationMapping(const double &velocityRelaxationFactor, const tarch::la::Vector< dim, double > ¤tVelocity, const I02 &cellIndex, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface, const coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > *const couplingCells)
Definition VelocityGradientRelaxationMapping.h:49
void beginCellIteration()
Definition VelocityGradientRelaxationMapping.h:62
virtual bool relaxMolecule(const tarch::la::Vector< dim, double > &position) const
Definition VelocityGradientRelaxationMapping.h:158
const tarch::la::Vector< dim, double > _innerLowerLeft
Definition VelocityGradientRelaxationMapping.h:191
const double _velocityRelaxationFactor
Definition VelocityGradientRelaxationMapping.h:186
const tarch::la::Vector< dim, double > _currentVelocity
Definition VelocityGradientRelaxationMapping.h:188
void createCouplingCellIndex4SecondOrderInterpolation(const tarch::la::Vector< dim, double > &position, tarch::la::Vector< dim, double > &normalisedPosition, bool &secondCake, I02 *res) const
Definition VelocityGradientRelaxationMapping.h:228
void handleCell(LinkedCell &cell)
Definition VelocityGradientRelaxationMapping.h:74
bool ignoreThisCell(const I02 &idx) const
Definition VelocityGradientRelaxationMapping.h:174
tarch::la::Vector< dim, double > getInnerUpperRightCorner() const
Definition VelocityGradientRelaxationMapping.h:208
void interpolateVelocitySecondOrder(I02 *cellIndex, const tarch::la::Vector< dim, double > &normalisedPosition, const bool &secondCake, tarch::la::Vector< dim, double > &newVelocity) const
Definition VelocityGradientRelaxationMapping.h:334
tarch::la::Vector< dim, double > getOuterLowerLeftCorner() const
Definition VelocityGradientRelaxationMapping.h:214
This is the same as the class coupling::cellmappings::VelocityGradientRelaxationMapping,...
Definition VelocityGradientRelaxationMapping.h:406
virtual bool relaxMolecule(const tarch::la::Vector< dim, double > &position) const
Definition VelocityGradientRelaxationMapping.h:445
VelocityGradientRelaxationTopOnlyMapping(const double &velocityRelaxationFactor, const tarch::la::Vector< dim, double > ¤tVelocity, const I02 &cellIndex, coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface, const coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > *const couplingCells)
Definition VelocityGradientRelaxationMapping.h:423
defines the cell type with cell-averaged quantities. Derived from the class coupling::datastructures:...
Definition CouplingCellWithLinkedCells.h:26
static tarch::la::Vector< dim, unsigned int > numberCellsInDomain
Definition CellIndex.h:264
value_T get() const
Definition CellIndex.h:138
interface to the MD simulation
Definition MDSolverInterface.h:25
some iterator scheme for traversing the molecules within a linked cell.
Definition MoleculeIterator.h:24
virtual bool continueIteration() const =0
virtual coupling::interface::Molecule< dim > & get()=0
interface to access a single molecule in the MD simulation.
Definition Molecule.h:23
virtual void setVelocity(const tarch::la::Vector< dim, double > &velocity)=0
virtual tarch::la::Vector< dim, double > getVelocity() const =0
virtual tarch::la::Vector< dim, double > getPosition() const =0
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15