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/DataExchangeFromAllMacro2MD.h"
31#include "coupling/sendrecv/FromMD2Macro.h"
32#include "coupling/sendrecv/FromMacro2MD.h"
33#include "tarch/utils/MultiMDService.h"
34
35#include "coupling/filtering/FilterPipeline.h"
36
37namespace coupling {
38namespace services {
39
40template <unsigned int dim> class CouplingCellService;
41
42template <class LinkedCell, unsigned int dim> class CouplingCellServiceImpl;
43} // namespace services
44} // namespace coupling
45
48
50template <unsigned int dim> class coupling::services::CouplingCellService {
51public:
52 CouplingCellService(unsigned int ID, unsigned int topologyOffset) : _id(ID), _topologyOffset(topologyOffset) {
53#if (COUPLING_MD_DEBUG == COUPLING_MD_YES)
54 std::cout << "CouplingCellService::CouplingCellService(): Set ID=" << _id << std::endl;
55#endif
56 }
57 virtual ~CouplingCellService() {}
58
59 virtual double applyFilterPipeline() = 0;
60 virtual void sendFromMacro2MDPreProcess() = 0;
61 virtual void sendFromMacro2MDPostProcess() = 0;
62 virtual void sendFromMacro2MD(const coupling::datastructures::FlexibleCellContainer<dim>& macro2MDBuffer) = 0;
63 virtual void sendFromMD2MacroPreProcess() = 0;
64 virtual void sendFromMD2MacroPostProcess() = 0;
65 virtual double sendFromMD2Macro(const coupling::datastructures::FlexibleCellContainer<dim>& couplingCellContainerFromMacroscopicSolver) = 0;
66 virtual void processInnerCouplingCellAfterMDTimestep() = 0;
67 virtual void computeAndStoreTemperature(double temperature) = 0;
68 virtual void applyTemperatureToMolecules(unsigned int t) = 0;
69 virtual void distributeMass(unsigned int t) = 0;
70 virtual void distributeMomentum(unsigned int t) = 0;
71 virtual void applyBoundaryForce(unsigned int t) = 0;
72 virtual void perturbateVelocity() = 0;
73 virtual void plotEveryMicroscopicTimestep(unsigned int t) = 0;
74 virtual void plotEveryMacroscopicTimestep(unsigned int t) = 0;
75 virtual void setInnerMomentumImposition(bool enable) = 0;
76
77 virtual void initFiltering() {
78 throw std::runtime_error("CouplingCellService: Error: Called "
79 "initFiltering for non-Impl object.");
80 } /*Note: This is not pure virtual, because some implementations of this
81 interface don't have a FilterPipeline. */
82 virtual const coupling::filtering::FilterPipeline<I02, dim>* getFilterPipeline() const {
83 throw std::runtime_error("CouplingCellService: Error: Called getFilterPipeline() in instance "
84 "without FilterPipeline.");
85 } /*Note: This is not pure virtual, because some implementations of this
86 interface don't have a FilterPipeline. */
87
88 unsigned int getID() const { return _id; }
89
90protected:
91 const unsigned int _id;
92 unsigned int _topologyOffset;
93};
94
97 * MD as well as between the coupling tool and the macroscopic solver.
98 * @author Philipp Neumann
99 */
100template <class LinkedCell, unsigned int dim> class coupling::services::CouplingCellServiceImpl : public coupling::services::CouplingCellService<dim> {
101public:
110 * the momentum transfer on MD side transferStrategyConfiguration -
111 * configuration object which determines the respective transfer strategy
112 * parallelTopologyConfiguration - configuratio object which defines the
113 * parallel topology of the simulation (domain decomposition of the MD
114 * simulation) numberMDTimestepsPerCouplingCycle - number of MD time steps per
115 * coupling cycle couplingCellConfiguration - configuration object
116 * which determines the properties of the coupling cells topologyOffset -
117 * offset in linearized topology of ranks topologyGlobalNumberProcesses -
118 * global number of processes available in overall topology
119 *
120 * Note: the interface pointers are used by the CouplingCellServiceImpl;
121 * they are not deleted at the end of the simulation since other (external)
122 * routines may use those as well.
123 */
125 unsigned int ID, coupling::interface::MDSolverInterface<LinkedCell, dim>* mdSolverInterface, // interface to MD simulation
126 coupling::interface::MacroscopicSolverInterface<dim>* macroscopicSolverInterface, // interface to macroscopic solver
127 tarch::la::Vector<dim, unsigned int> numberProcesses, // number of processes in all directions
128 unsigned int rank, // current rank
129 const coupling::configurations::ParticleInsertionConfiguration& particleInsertionConfiguration, // configuration for particle
130 // insertion
131 const coupling::configurations::MomentumInsertionConfiguration& momentumInsertionConfiguration, // configuration for momentum
132 // insertion
133 const coupling::configurations::BoundaryForceConfiguration<dim>& boundaryForceConfiguration, // configuration for boundary forces
134 const coupling::configurations::TransferStrategyConfiguration<dim>& transferStrategyConfiguration, // configuration for transfer strategy
135 const coupling::configurations::ParallelTopologyConfiguration& parallelTopologyConfiguration, // configuration for parallel topology
137 unsigned int numberMDTimestepsPerCouplingCycle, // number MD timesteps per coupling
138 // cycle (required to initialise
139 // transfer strategy)
140 const coupling::configurations::CouplingCellConfiguration<dim>& couplingCellConfiguration, // configuration for coupling cells
141 // and respective plotting
142 const char* filterPipelineConfiguration, const tarch::utils::MultiMDService<dim>& multiMDService, unsigned int topologyOffset, int tws = 0);
143
145 unsigned int ID, coupling::interface::MDSolverInterface<LinkedCell, dim>* mdSolverInterface, // interface to MD simulation
146 coupling::interface::MacroscopicSolverInterface<dim>* macroscopicSolverInterface, // interface to macroscopic solver
147 tarch::la::Vector<dim, unsigned int> numberProcesses, // number of processes in all directions
148 unsigned int rank, // current rank
149 const coupling::configurations::ParticleInsertionConfiguration& particleInsertionConfiguration, // configuration for particle
150 // insertion
151 const coupling::configurations::MomentumInsertionConfiguration& momentumInsertionConfiguration, // configuration for momentum
152 // insertion
153 const coupling::configurations::BoundaryForceConfiguration<dim>& boundaryForceConfiguration, // configuration for boundary forces
154 const coupling::configurations::TransferStrategyConfiguration<dim>& transferStrategyConfiguration, // configuration for transfer strategy
155 const coupling::configurations::ParallelTopologyConfiguration& parallelTopologyConfiguration, // configuration for parallel topology
156 const coupling::configurations::ThermostatConfiguration& thermostatConfiguration,
157 unsigned int numberMDTimestepsPerCouplingCycle, // number MD timesteps per coupling
158 // cycle (required to initialise
159 // transfer strategy)
160 const coupling::configurations::CouplingCellConfiguration<dim>& couplingCellConfiguration, // configuration for coupling cells
161 // and respective plotting
162 const char* filterPipelineConfiguration, const tarch::utils::MultiMDService<dim>& multiMDService)
163 : CouplingCellServiceImpl<LinkedCell, dim>(ID, mdSolverInterface, macroscopicSolverInterface, numberProcesses, rank, particleInsertionConfiguration,
164 momentumInsertionConfiguration, boundaryForceConfiguration, transferStrategyConfiguration,
165 parallelTopologyConfiguration, thermostatConfiguration, numberMDTimestepsPerCouplingCycle,
166 couplingCellConfiguration, filterPipelineConfiguration, multiMDService, 0) {}
167
172
180
190 double sendFromMD2Macro(const coupling::datastructures::FlexibleCellContainer<dim>& macroscopicSolverCellContainer) override;
191
193 double applyFilterPipeline() override;
194
195 void sendFromMacro2MDPreProcess() override;
196
197 void sendFromMacro2MDPostProcess() override;
198
199 void sendFromMD2MacroPreProcess() override;
200
201 void sendFromMD2MacroPostProcess() override {}
202
208
215 void computeAndStoreTemperature(double temperature) override;
216
217 /** applies a thermostat in all non-ghost coupling cells. */
218 void applyTemperatureToMolecules(unsigned int t) override;
219
222 void applyBoundaryForce(unsigned int t) override;
223
225 void distributeMass(unsigned int t) override;
226
228
229 void distributeMomentum(unsigned int t) override;
230
231 /** applies a new velocity to each particle according to its cell's mean
232 * velocity. */
233 void perturbateVelocity() override;
234
240 void plotEveryMicroscopicTimestep(unsigned int t) override;
241 void plotEveryMacroscopicTimestep(unsigned int t) override;
242 void setInnerMomentumImposition(bool enable) override;
243
249 void initFiltering() override {
250 _filterPipeline = new coupling::filtering::FilterPipeline<I02, dim>(_couplingCells, coupling::filtering::Scope::perInstance, _multiMDService,
252 }
253
254 const coupling::filtering::FilterPipeline<I02, dim>* getFilterPipeline() const override { return _filterPipeline; }
255
265 /*
266 * TODO: MOVE COMMENT
267 void addFilterToSequence( const char *sequenceIdentifier,
268 const
269 std::function<std::vector<double> (std::vector<double> cells_s,
270 std::vector<std::array<unsigned int, dim>> indices)>* applyScalar, const
271 std::function<std::vector<std::array<double, dim>>
272 (std::vector<std::array<double, dim>> cells_v, std::vector<std::array<unsigned
273 int, dim>> indices)>* applyVector, int filterIndex = -1
274 );*/
275
279
280private:
281// ------------------- INCLUDE WRAPPER DEFINITIONS
282// -------------------------------------
283#include "CouplingCellTraversalWrappers.cpph"
284
287
288 tarch::la::Vector<dim, double> getPositionOfFirstLocalGhostCell() const;
289
290 std::function<void(Wrapper&)> initCorrectApplicationOfThermostat(const coupling::configurations::ThermostatConfiguration& thermostatConfiguration) {
291 if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::all)
292 return [this](Wrapper& wrapper) { _couplingCells.applyToLocalNonGhostCouplingCellsWithLinkedCells(wrapper); };
293 else if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::outerLayers)
294 return [this, &thermostatConfiguration](Wrapper& wrapper) {
295 _couplingCells.applyXLayersOfGlobalNonGhostCellsWithLinkedCells(wrapper, thermostatConfiguration.getCells2Use());
296 };
297 else if (thermostatConfiguration.getThermostatRegionType() == coupling::configurations::ThermostatConfiguration::ThermostatRegion::onlyOutestLayer)
298 return [this](Wrapper& wrapper) { _couplingCells.applyToFirstLayerOfGlobalNonGhostCellsWithLinkedCells(wrapper); };
299 else
300 return [](Wrapper& wrapper) {};
301 }
302
305
308
311
316 bool _enableInnerImposition;
319
322
325
328 const tarch::utils::MultiMDService<dim> _multiMDService;
329
335 const tarch::la::Vector<dim, unsigned int> _numberLinkedCellsPerCouplingCell;
339
348
349 std::function<void(Wrapper&)> _applyAccordingToConfiguration;
350
352 const std::string _microscopicFilename;
353 const unsigned int _writeEveryMicroscopicTimestep;
354 const std::string _macroscopicFilename;
355 const unsigned int _writeEveryMacroscopicTimestep;
356
359 // start and end coordinate for block loop over coupling cells (with 3
360 // entries always!)
362 tarch::la::Vector<3, unsigned int> _usherCellEnd[1 << dim];
363 tarch::la::Vector<dim, unsigned int> _usherRange[1 << dim];
364 // offset in red-black loops nested within the block loops (always 0 or 1
365 // entries)
366 tarch::la::Vector<3, unsigned int> _usherCellOffset[1 << dim];
367};
368#include "CouplingCellService.cpph"
369
370#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
Definition DataExchangeFromAllMacro2MD.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:100
coupling::sendrecv::FromMacro2MD< coupling::datastructures::CouplingCell< dim >, dim > _fromMacro2MD
Definition CouplingCellService.h:313
coupling::interface::MDSolverInterface< LinkedCell, dim > * _mdSolverInterface
Definition CouplingCellService.h:307
void plotEveryMicroscopicTimestep(unsigned int t) override
void initFiltering() override
Definition CouplingCellService.h:249
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:361
const std::string _microscopicFilename
Definition CouplingCellService.h:352
void distributeMass(unsigned int t) override
coupling::transferstrategies::TransferStrategy< LinkedCell, dim > * _transferStrategy
Definition CouplingCellService.h:338
void distributeMomentum(unsigned int t) override
coupling::ParticleInsertion< LinkedCell, dim > * _particleInsertion
Definition CouplingCellService.h:334
coupling::datastructures::LinkedCellContainer< LinkedCell, dim > & getCouplingCells()
Definition CouplingCellService.h:278
coupling::KineticEnergyController< LinkedCell, dim > _kineticEnergyController
Definition CouplingCellService.h:342
coupling::interface::MacroscopicSolverInterface< dim > * _macroscopicSolverInterface
Definition CouplingCellService.h:310
void applyBoundaryForce(unsigned int t) override
coupling::MomentumInsertion< LinkedCell, dim > * _momentumInsertion
Definition CouplingCellService.h:331
coupling::MomentumController< LinkedCell, dim > _momentumController
Definition CouplingCellService.h:347
coupling::filtering::FilterPipeline< I02, dim > * _filterPipeline
Definition CouplingCellService.h:324
coupling::datastructures::LinkedCellContainer< LinkedCell, dim > _couplingCells
Definition CouplingCellService.h:321
coupling::BoundaryForceController< LinkedCell, dim > * _boundaryForceController
Definition CouplingCellService.h:345
const unsigned int _numberMDTimestepsPerCouplingCycle
Definition CouplingCellService.h:304
const char * _filterPipelineConfiguration
Definition CouplingCellService.h:327
Definition CouplingCellService.h:50
unsigned int _topologyOffset
Definition CouplingCellService.h:92
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