MaMiCo 1.2
Loading...
Searching...
No Matches
CouplingCellService.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_SERVICES_COUPLINGCELLSERVICE_H_
6#define _MOLECULARDYNAMICS_COUPLING_SERVICES_COUPLINGCELLSERVICE_H_
7
8#pragma once
9
10#include "coupling/CouplingCellPlotter.h"
11#include "coupling/KineticEnergyController.h"
12#include "coupling/MomentumController.h"
13#include "coupling/cell-mappings/ComputeMeanPotentialEnergyMapping.h"
14#include "coupling/cell-mappings/ComputeMomentumMapping.h"
15#include "coupling/cell-mappings/PerturbateVelocityMapping.h"
16#include "coupling/configurations/BoundaryForceConfiguration.h"
17#include "coupling/configurations/CouplingCellConfiguration.h"
18#include "coupling/configurations/MaMiCoConfiguration.h"
19#include "coupling/configurations/MomentumInsertionConfiguration.h"
20#include "coupling/configurations/ParallelTopologyConfiguration.h"
21#include "coupling/configurations/ParticleInsertionConfiguration.h"
22#include "coupling/configurations/ThermostatConfiguration.h"
23#include "coupling/configurations/TransferStrategyConfiguration.h"
24#include "coupling/datastructures/CellContainer.h"
25#include "coupling/indexing/IndexingService.h"
26#include "coupling/interface/MDSolverInterface.h"
27#include "coupling/interface/MacroscopicSolverInterface.h"
28#include "coupling/sendrecv/DataExchangeFromMD2Macro.h"
29#include "coupling/sendrecv/DataExchangeFromMacro2MD.h"
30#include "coupling/sendrecv/FromMD2Macro.h"
31#include "coupling/sendrecv/FromMacro2MD.h"
32#include "tarch/utils/MultiMDService.h"
33
34#include "coupling/filtering/FilterPipeline.h"
35
36namespace coupling {
37namespace services {
38
39template <unsigned int dim> class CouplingCellService;
40
41template <class LinkedCell, unsigned int dim> class CouplingCellServiceImpl;
42} // namespace services
43} // namespace coupling
44
48
49template <unsigned int dim> class coupling::services::CouplingCellService {
50public:
51 CouplingCellService(unsigned int ID, unsigned int topologyOffset) : _id(ID), _topologyOffset(topologyOffset) {
52#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
53 std::cout << "CouplingCellService::CouplingCellService(): Set ID=" << _id << std::endl;
54#endif
55 }
56 virtual ~CouplingCellService() {}
57
58 virtual double applyFilterPipeline() = 0;
59 virtual void sendFromMacro2MDPreProcess() = 0;
60 virtual void sendFromMacro2MDPostProcess() = 0;
61 virtual void sendFromMacro2MD(const coupling::datastructures::FlexibleCellContainer<dim>& macro2MDBuffer) = 0;
62 virtual void sendFromMD2MacroPreProcess() = 0;
63 virtual void sendFromMD2MacroPostProcess() = 0;
64 virtual double sendFromMD2Macro(const coupling::datastructures::FlexibleCellContainer<dim>& couplingCellContainerFromMacroscopicSolver) = 0;
65 virtual void processInnerCouplingCellAfterMDTimestep() = 0;
66 virtual void computeAndStoreTemperature(double temperature) = 0;
67 virtual void applyTemperatureToMolecules(unsigned int t) = 0;
68 virtual void distributeMass(unsigned int t) = 0;
69 virtual void distributeMomentum(unsigned int t) = 0;
70 virtual void applyBoundaryForce(unsigned int t) = 0;
71 virtual void perturbateVelocity() = 0;
72 virtual void plotEveryMicroscopicTimestep(unsigned int t) = 0;
73 virtual void plotEveryMacroscopicTimestep(unsigned int t) = 0;
74
75 virtual void initFiltering() {
76 throw std::runtime_error("CouplingCellService: Error: Called "
77 "initFiltering for non-Impl object.");
78 } /*Note: This is not pure virtual, because some implementations of this
79 interface don't have a FilterPipeline. */
80 virtual const coupling::filtering::FilterPipeline<I02, dim>* getFilterPipeline() const {
81 throw std::runtime_error("CouplingCellService: Error: Called getFilterPipeline() in instance "
82 "without FilterPipeline.");
83 } /*Note: This is not pure virtual, because some implementations of this
84 interface don't have a FilterPipeline. */
85
86 unsigned int getID() const { return _id; }
87
88protected:
89 const unsigned int _id;
90 unsigned int _topologyOffset;
91};
92
94
97 */
98template <class LinkedCell, unsigned int dim> class coupling::services::CouplingCellServiceImpl : public coupling::services::CouplingCellService<dim> {
99public:
110 * parallelTopologyConfiguration - configuratio object which defines the
111 * parallel topology of the simulation (domain decomposition of the MD
112 * simulation) numberMDTimestepsPerCouplingCycle - number of MD time steps per
113 * coupling cycle couplingCellConfiguration - configuration object
114 * which determines the properties of the coupling cells topologyOffset -
115 * offset in linearized topology of ranks topologyGlobalNumberProcesses -
116 * global number of processes available in overall topology
117 *
118 * Note: the interface pointers are used by the CouplingCellServiceImpl;
119 * they are not deleted at the end of the simulation since other (external)
120 * routines may use those as well.
121 */
123 unsigned int ID, coupling::interface::MDSolverInterface<LinkedCell, dim>* mdSolverInterface, // interface to MD simulation
124 coupling::interface::MacroscopicSolverInterface<dim>* macroscopicSolverInterface, // interface to macroscopic solver
125 tarch::la::Vector<dim, unsigned int> numberProcesses, // number of processes in all directions
126 unsigned int rank, // current rank
127 const coupling::configurations::ParticleInsertionConfiguration& particleInsertionConfiguration, // configuration for particle
128 // insertion
129 const coupling::configurations::MomentumInsertionConfiguration& momentumInsertionConfiguration, // configuration for momentum
130 // insertion
131 const coupling::configurations::BoundaryForceConfiguration<dim>& boundaryForceConfiguration, // configuration for boundary forces
132 const coupling::configurations::TransferStrategyConfiguration<dim>& transferStrategyConfiguration, // configuration for transfer strategy
133 const coupling::configurations::ParallelTopologyConfiguration& parallelTopologyConfiguration, // configuration for parallel topology
134 const coupling::configurations::ThermostatConfiguration& thermostatConfiguration,
135 unsigned int numberMDTimestepsPerCouplingCycle, // number MD timesteps per coupling
136 // cycle (required to initialise
137 // transfer strategy)
138 const coupling::configurations::CouplingCellConfiguration<dim>& couplingCellConfiguration, // configuration for coupling cells
139 // and respective plotting
140 const char* filterPipelineConfiguration, const tarch::utils::MultiMDService<dim>& multiMDService, unsigned int topologyOffset, int tws = 0);
141
143 unsigned int ID, coupling::interface::MDSolverInterface<LinkedCell, dim>* mdSolverInterface, // interface to MD simulation
144 coupling::interface::MacroscopicSolverInterface<dim>* macroscopicSolverInterface, // interface to macroscopic solver
145 tarch::la::Vector<dim, unsigned int> numberProcesses, // number of processes in all directions
146 unsigned int rank, // current rank
147 const coupling::configurations::ParticleInsertionConfiguration& particleInsertionConfiguration, // configuration for particle
148 // insertion
149 const coupling::configurations::MomentumInsertionConfiguration& momentumInsertionConfiguration, // configuration for momentum
150 // insertion
151 const coupling::configurations::BoundaryForceConfiguration<dim>& boundaryForceConfiguration, // configuration for boundary forces
152 const coupling::configurations::TransferStrategyConfiguration<dim>& transferStrategyConfiguration, // configuration for transfer strategy
153 const coupling::configurations::ParallelTopologyConfiguration& parallelTopologyConfiguration, // configuration for parallel topology
154 const coupling::configurations::ThermostatConfiguration& thermostatConfiguration,
155 unsigned int numberMDTimestepsPerCouplingCycle, // number MD timesteps per coupling
156 // cycle (required to initialise
157 // transfer strategy)
158 const coupling::configurations::CouplingCellConfiguration<dim>& couplingCellConfiguration, // configuration for coupling cells
159 // and respective plotting
160 const char* filterPipelineConfiguration, const tarch::utils::MultiMDService<dim>& multiMDService)
161 : CouplingCellServiceImpl<LinkedCell, dim>(ID, mdSolverInterface, macroscopicSolverInterface, numberProcesses, rank, particleInsertionConfiguration,
162 momentumInsertionConfiguration, boundaryForceConfiguration, transferStrategyConfiguration,
163 parallelTopologyConfiguration, thermostatConfiguration, numberMDTimestepsPerCouplingCycle,
164 couplingCellConfiguration, filterPipelineConfiguration, multiMDService, 0) {}
165
170
171 /** sends information from macroscopic solver to MD. The cell information from
172 * the macroscopic solver is handed over as a flexible cell container
173 * The coupling tool internally triggers send/recv-operations
174 * (this also comprises the distributed memory parallelisation via MPI)
175 * and writes the respective information to the coupling cells of the tool
176 */
178
188 double sendFromMD2Macro(const coupling::datastructures::FlexibleCellContainer<dim>& macroscopicSolverCellContainer) override;
189
191 double applyFilterPipeline() override;
192
193 void sendFromMacro2MDPreProcess() override;
194
195 void sendFromMacro2MDPostProcess() override;
196
197 void sendFromMD2MacroPreProcess() override;
198
199 void sendFromMD2MacroPostProcess() override {}
200
206
213 void computeAndStoreTemperature(double temperature) override;
214
215
216 void applyTemperatureToMolecules(unsigned int t) override;
220 void applyBoundaryForce(unsigned int t) override;
221
223 void distributeMass(unsigned int t) override;
224
227 void distributeMomentum(unsigned int t) override;
228
231 void perturbateVelocity() override;
232
238 void plotEveryMicroscopicTimestep(unsigned int t) override;
239 void plotEveryMacroscopicTimestep(unsigned int t) override;
240
246 void initFiltering() override {
247 _filterPipeline = new coupling::filtering::FilterPipeline<I02, dim>(_couplingCells, coupling::filtering::Scope::perInstance, _multiMDService,
249 }
250
251 const coupling::filtering::FilterPipeline<I02, dim>* getFilterPipeline() const override { return _filterPipeline; }
252
262 /*
263 * TODO: MOVE COMMENT
264 void addFilterToSequence( const char *sequenceIdentifier,
265 const
266 std::function<std::vector<double> (std::vector<double> cells_s,
267 std::vector<std::array<unsigned int, dim>> indices)>* applyScalar, const
268 std::function<std::vector<std::array<double, dim>>
269 (std::vector<std::array<double, dim>> cells_v, std::vector<std::array<unsigned
270 int, dim>> indices)>* applyVector, int filterIndex = -1
271 );*/
272
276
277private:
278// ------------------- INCLUDE WRAPPER DEFINITIONS
279// -------------------------------------
280#include "CouplingCellTraversalWrappers.cpph"
281
284
285 tarch::la::Vector<dim, double> getPositionOfFirstLocalGhostCell() const;
286
287 std::function<void(Wrapper&)> initCorrectApplicationOfThermostat(const coupling::configurations::ThermostatConfiguration& thermostatConfiguration) {
288 if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::all)
289 return [this](Wrapper& wrapper) { _couplingCells.applyToLocalNonGhostCouplingCellsWithLinkedCells(wrapper); };
290 else if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::outerLayers)
291 return [this, &thermostatConfiguration](Wrapper& wrapper) {
292 _couplingCells.applyXLayersOfGlobalNonGhostCellsWithLinkedCells(wrapper, thermostatConfiguration.getCells2Use());
293 };
294 else if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::onlyOutestLayer)
295 return [this](Wrapper& wrapper) { _couplingCells.applyToFirstLayerOfGlobalNonGhostCellsWithLinkedCells(wrapper); };
296 else
297 return [](Wrapper& wrapper) {};
298 }
299
302
305
308
314
317
320
323 const tarch::utils::MultiMDService<dim> _multiMDService;
324
330 const tarch::la::Vector<dim, unsigned int> _numberLinkedCellsPerCouplingCell;
334
343
344 std::function<void(Wrapper&)> _applyAccordingToConfiguration;
345
347 const std::string _microscopicFilename;
348 const unsigned int _writeEveryMicroscopicTimestep;
349 const std::string _macroscopicFilename;
350 const unsigned int _writeEveryMacroscopicTimestep;
351
354 // start and end coordinate for block loop over coupling cells (with 3
355 // entries always!)
357 tarch::la::Vector<3, unsigned int> _usherCellEnd[1 << dim];
358 tarch::la::Vector<dim, unsigned int> _usherRange[1 << dim];
359 // offset in red-black loops nested within the block loops (always 0 or 1
360 // entries)
361 tarch::la::Vector<3, unsigned int> _usherCellOffset[1 << dim];
362};
363#include "CouplingCellService.cpph"
364
365#endif // _MOLECULARDYNAMICS_COUPLING_SERVICES_COUPLINGCELLSERVICE_H_
controller for forces acting at open MD boundaries
Definition BoundaryForceController.h:25
controles and regulates the kinetic energy of the MD system.
Definition KineticEnergyController.h:27
controls the momentum in a coupling cell.
Definition MomentumController.h:26
used to manipulate the momentum/ velocity of the molecules contained in a coupling cell.
Definition MomentumInsertion.h:23
interface for particle insertion/removal on coupling cell basis.
Definition ParticleInsertion.h:23
reads boundary force tag
Definition BoundaryForceConfiguration.h:27
configuration for output of coupling cell data to vtk files.
Definition CouplingCellConfiguration.h:24
momentum insertion configuration. friend class: NieTest
Definition MomentumInsertionConfiguration.h:31
MomentumInsertionType
Definition MomentumInsertionConfiguration.h:39
reads parallel topology configuration. XYZ and ZYX are supported.
Definition ParallelTopologyConfiguration.h:25
configuration for particle insertion algorithm (e.g.: USHER).
Definition ParticleInsertionConfiguration.h:28
ParticleInsertionType
Definition ParticleInsertionConfiguration.h:82
Definition ThermostatConfiguration.h:23
transfer strategy configuration, i.e. algorithm/combin. of quantity transfer steps and quantity inter...
Definition TransferStrategyConfiguration.h:34
provides access to coupling cells, which may belong to different indexing domains
Definition FlexibleCellContainer.h:30
provides access to the coupling cells with linked cells.
Definition LinkedCellContainer.h:21
Definition FilterPipeline.h:44
interface to the MD simulation
Definition MDSolverInterface.h:25
interface for the macroscopic, i.e. continuum solver
Definition MacroscopicSolverInterface.h:23
data exchange from the MD solver to the macroscopic solver. Derived from the class coupling::sendrecv...
Definition DataExchangeFromMD2Macro.h:36
data exchange from the macroscopic solver to the MD solver. Derived from the class coupling::sendrecv...
Definition DataExchangeFromMacro2MD.h:36
sends coupling cell information from MaMiCo to the macroscopic solver. Derived from the class couplin...
Definition FromMD2Macro.h:29
SendReceiveBuffer for transfer of quantities from a macroscopic solver to the coupling cells....
Definition FromMacro2MD.h:28
Definition CouplingCellService.h:22
Definition CouplingCellService.h:98
coupling::sendrecv::FromMacro2MD< coupling::datastructures::CouplingCell< dim >, dim > _fromMacro2MD
Definition CouplingCellService.h:310
coupling::interface::MDSolverInterface< LinkedCell, dim > * _mdSolverInterface
Definition CouplingCellService.h:304
void plotEveryMicroscopicTimestep(unsigned int t) override
void initFiltering() override
Definition CouplingCellService.h:246
void applyTemperatureToMolecules(unsigned int t) override
CouplingCellServiceImpl(unsigned int ID, coupling::interface::MDSolverInterface< LinkedCell, dim > *mdSolverInterface, coupling::interface::MacroscopicSolverInterface< dim > *macroscopicSolverInterface, tarch::la::Vector< dim, unsigned int > numberProcesses, unsigned int rank, const coupling::configurations::ParticleInsertionConfiguration &particleInsertionConfiguration, const coupling::configurations::MomentumInsertionConfiguration &momentumInsertionConfiguration, const coupling::configurations::BoundaryForceConfiguration< dim > &boundaryForceConfiguration, const coupling::configurations::TransferStrategyConfiguration< dim > &transferStrategyConfiguration, const coupling::configurations::ParallelTopologyConfiguration &parallelTopologyConfiguration, const coupling::configurations::ThermostatConfiguration &thermostatConfiguration, unsigned int numberMDTimestepsPerCouplingCycle, const coupling::configurations::CouplingCellConfiguration< dim > &couplingCellConfiguration, const char *filterPipelineConfiguration, const tarch::utils::MultiMDService< dim > &multiMDService, unsigned int topologyOffset, int tws=0)
double sendFromMD2Macro(const coupling::datastructures::FlexibleCellContainer< dim > &macroscopicSolverCellContainer) override
void sendFromMacro2MD(const coupling::datastructures::FlexibleCellContainer< dim > &macro2MDBuffer) override
void computeAndStoreTemperature(double temperature) override
tarch::la::Vector< 3, unsigned int > _usherCellStart[1<< dim]
Definition CouplingCellService.h:356
const std::string _microscopicFilename
Definition CouplingCellService.h:347
void distributeMass(unsigned int t) override
coupling::transferstrategies::TransferStrategy< LinkedCell, dim > * _transferStrategy
Definition CouplingCellService.h:333
void distributeMomentum(unsigned int t) override
coupling::ParticleInsertion< LinkedCell, dim > * _particleInsertion
Definition CouplingCellService.h:329
coupling::datastructures::LinkedCellContainer< LinkedCell, dim > & getCouplingCells()
Definition CouplingCellService.h:275
coupling::KineticEnergyController< LinkedCell, dim > _kineticEnergyController
Definition CouplingCellService.h:337
coupling::interface::MacroscopicSolverInterface< dim > * _macroscopicSolverInterface
Definition CouplingCellService.h:307
void applyBoundaryForce(unsigned int t) override
coupling::MomentumInsertion< LinkedCell, dim > * _momentumInsertion
Definition CouplingCellService.h:326
coupling::MomentumController< LinkedCell, dim > _momentumController
Definition CouplingCellService.h:342
coupling::filtering::FilterPipeline< I02, dim > * _filterPipeline
Definition CouplingCellService.h:319
coupling::datastructures::LinkedCellContainer< LinkedCell, dim > _couplingCells
Definition CouplingCellService.h:316
coupling::BoundaryForceController< LinkedCell, dim > * _boundaryForceController
Definition CouplingCellService.h:340
const unsigned int _numberMDTimestepsPerCouplingCycle
Definition CouplingCellService.h:301
const char * _filterPipelineConfiguration
Definition CouplingCellService.h:322
Definition CouplingCellService.h:49
unsigned int _topologyOffset
Definition CouplingCellService.h:90
Definition TransferStrategy.h:25
Definition Vector.h:24
Definition MultiMDService.h:30
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15