MaMiCo 1.2
Loading...
Searching...
No Matches
AveragingTransferStrategy.h
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_AVERAGINGTRANSFERSTRATEGY_H_
6#define _MOLECULARDYNAMICS_COUPLING_TRANSFERSTRATEGIES_AVERAGINGTRANSFERSTRATEGY_H_
7
8#include "coupling/cell-mappings/ComputeMassMapping.h"
9#include "coupling/cell-mappings/ComputeMomentumMapping.h"
10#include "coupling/indexing/IndexingService.h"
11#include "coupling/transferstrategies/TransferStrategy.h"
12#include <list>
13#include <map>
14
15namespace coupling {
19template <class LinkedCell, unsigned int dim> class AveragingTransferStrategy;
20}
21} // namespace coupling
22
31template <class LinkedCell, unsigned int dim>
33public:
37 : coupling::transferstrategies::TransferStrategy<LinkedCell, dim>(mdSolverInterface), _massMapping(mdSolverInterface),
38 _momentumMapping(mdSolverInterface), _sampleCounter(0), _rank(IDXS.getRank()) {}
39
42
45 // reset sample counter for each coupling cycle
47 }
48
54 I02 index) override {
55 // reset buffers for sampling mass and momentum in each inner coupling
56 // cell
57 cell.setMacroscopicMass(0.0);
59 }
60
64 // output information of last sampling...
65 if (_rank == 0) {
66 std::cout << "Global quantities of sampling no. " << _sampleCounter << " on rank 0: mass=" << _avgMass << ", momentum=" << _avgMomentum << std::endl;
67 }
68 // reset avg. mass and momentum...
69 _avgMass = 0.0;
71 // and increment sample counter
73 }
74
80 // compute total mass/momentum from previous samples
81 const double oldMass = (_sampleCounter - 1) * cell.getMacroscopicMass();
82 const tarch::la::Vector<dim, double> oldMomentum = ((double)(_sampleCounter - 1)) * cell.getMacroscopicMomentum();
83
84 // compute new averaged mass and momentum
87 const double mass = (1.0 / _sampleCounter) * (oldMass + _massMapping.getMass());
88 const tarch::la::Vector<dim, double> momentum = (1.0 / _sampleCounter) * (oldMomentum + _momentumMapping.getMomentum());
89 _avgMass += mass;
90 _avgMomentum = _avgMomentum + momentum;
91 // set mass and momentum in buffers
92 cell.setMacroscopicMass(mass);
93 cell.setMacroscopicMomentum(momentum);
94 }
95
96private:
102 unsigned int _sampleCounter;
104 const unsigned int _rank;
110 double _avgMass;
111};
112#endif // _MOLECULARDYNAMICS_COUPLING_TRANSFERSTRATEGIES_AVERAGINGTRANSFERSTRATEGY_H_
This class computes the mass over certain linked cells.
Definition ComputeMassMapping.h:23
This class computes the momentum over certain linked cells.
Definition ComputeMomentumMapping.h:24
defines the cell type with cell-averaged quantities. Derived from the class coupling::datastructures:...
Definition CouplingCellWithLinkedCells.h:26
void iterateConstCells(A &a) const
Definition CouplingCellWithLinkedCells.h:90
const tarch::la::Vector< dim, double > & getMacroscopicMomentum() const
Definition CouplingCell.h:64
void setMacroscopicMomentum(const tarch::la::Vector< dim, double > &momentum)
Definition CouplingCell.h:61
const double & getMacroscopicMass() const
Definition CouplingCell.h:58
void setMacroscopicMass(const double &mass)
Definition CouplingCell.h:55
interface to the MD simulation
Definition MDSolverInterface.h:25
Definition AveragingTransferStrategy.h:32
coupling::cellmappings::ComputeMomentumMapping< LinkedCell, dim > _momentumMapping
Definition AveragingTransferStrategy.h:100
void beginProcessInnerCouplingCellsBeforeReceivingMacroscopicSolverData() override
reset the sample counter before processing any cell
Definition AveragingTransferStrategy.h:44
tarch::la::Vector< dim, double > _avgMomentum
Definition AveragingTransferStrategy.h:107
const unsigned int _rank
Definition AveragingTransferStrategy.h:104
AveragingTransferStrategy(coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
a simple constructor
Definition AveragingTransferStrategy.h:36
void beginProcessInnerCouplingCellsAfterMDTimestep() override
values are reseted before the cells are processes and on rank=0 info is written to the stdstream
Definition AveragingTransferStrategy.h:63
virtual ~AveragingTransferStrategy()
a dummy destructor
Definition AveragingTransferStrategy.h:41
coupling::cellmappings::ComputeMassMapping< LinkedCell, dim > _massMapping
Definition AveragingTransferStrategy.h:98
double _avgMass
Definition AveragingTransferStrategy.h:110
void processInnerCouplingCellBeforeReceivingMacroscopicSolverData(coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > &cell, I02 index) override
macroscopicMass and -Momentum are reset before the data from the macro solver is transferred
Definition AveragingTransferStrategy.h:53
unsigned int _sampleCounter
Definition AveragingTransferStrategy.h:102
void processInnerCouplingCellAfterMDTimestep(coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > &cell, I02 index) override
the averaging operation is applied to the cell
Definition AveragingTransferStrategy.h:79
Definition TransferStrategy.h:25
TransferStrategy(coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface)
a simple destructor
Definition TransferStrategy.h:29
Definition Vector.h:24
the namespace is used for transferstrategies
Definition AveragingTransferStrategy.h:18
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15