MaMiCo 1.2
Loading...
Searching...
No Matches
CouetteScenario.h
1// This file is part of the Mamico project. For conditions of distribution
2// and use, please see the copyright notice in Mamico's main folder, or at
3// www5.in.tum.de/mamico
4#ifndef _COUPLING_SCENARIO_COUETTESCENARIO_H_
5#define _COUPLING_SCENARIO_COUETTESCENARIO_H_
6
7#include "coupling/ErrorEstimation.h"
8#include "coupling/InstanceHandling.h"
9#include "coupling/MultiMDMediator.h"
10#include "coupling/services/ParallelTimeIntegrationService.h"
11#include "coupling/solvers/CouetteSolver.h"
12#include "coupling/solvers/LBCouetteSolver.h"
13#include "simplemd/configurations/MolecularDynamicsConfiguration.h"
14#include "tarch/configuration/ParseConfiguration.h"
15#include "tarch/utils/MultiMDService.h"
16#include "tarch/utils/RandomNumberService.h"
17#include "tarch/utils/Utils.h"
18#if (BUILD_WITH_OPENFOAM)
19#include "coupling/solvers/IcoFoamInterface.h"
20#endif
21#include "coupling/configurations/CouetteConfiguration.h"
22#include "coupling/configurations/MaMiCoConfiguration.h"
23#include "coupling/indexing/IndexingService.h"
24#include "coupling/interface/MDSimulationFactory.h"
25#include "coupling/interface/impl/SimpleMD/SimpleMDSolverInterface.h"
26#include "coupling/services/MultiMDCellService.h"
27#include "coupling/solvers/CouetteSolverInterface.h"
28#include "coupling/solvers/FDCouetteSolver.h"
29#include "coupling/solvers/LBCouetteSolverInterface.h"
30
31#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
32#include <mpi.h>
33#endif
34#include <chrono>
35#include <math.h>
36#include <random>
37#include <sys/time.h>
38
39#if defined(LS1_MARDYN)
40#include "coupling/interface/impl/ls1/LS1MDSolverInterface.h"
41#include "coupling/interface/impl/ls1/LS1StaticCommData.h"
42#include "utils/Logger.h"
43using Log::global_log;
44#endif
45
46// This is ignored if you dont use synthetic MD. For further instructions cf.
47// SYNTHETIC part of initSolvers().
48#define SYNTHETICMD_SEQUENCE "SYNTHETIC-MD"
49
69class CouetteScenario : public Scenario {
70public:
72 CouetteScenario() : Scenario("CouetteScenario"), _generator(std::chrono::system_clock::now().time_since_epoch().count()) {}
74 virtual ~CouetteScenario() {}
75
78 void run() override {
79 init();
80 if (_cfg.twsLoop) {
81 twsLoop();
82 return;
83 }
84 _timeIntegrationService->run(_cfg.couplingCycles);
85 shutdown();
86 }
87
90 void init() override {
91#if defined(LS1_MARDYN)
92 Log::global_log = std::make_unique<Log::Logger>(Log::Error); // Log::Info
93#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
94 global_log->set_mpi_output_root(0);
95#endif
96#endif
100 }
101
107 void runOneCouplingCycle(int cycle) override {
108 advanceMacro(cycle);
109 varyMD(cycle);
110 advanceMicro(cycle);
111 computeSNR(cycle);
112 twoWayCoupling(cycle);
113 if (_cfg.totalNumberMDSimulations < 0) // dynamic MD
114 _multiMDCellService->finishCycle(cycle, *_instanceHandling);
115 if (_isRootRank) {
116 // Output status info only every 10 seconds
117 gettimeofday(&_tv.end, NULL);
118 int runtime_ms = (int)(((_tv.end.tv_sec - _tv.output.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.output.tv_usec)) / 1000);
119 if (runtime_ms > 10000) {
120 std::cout << "Finish coupling cycle " << cycle << std::endl;
121 gettimeofday(&_tv.output, NULL);
122 }
123 }
124 }
125
128 void equilibrateMicro() override {
130
132 for (auto pair : _couplingBuffer.macro2MDBuffer) buffer << pair;
133 for (auto pair : _couplingBuffer.md2macroBuffer) buffer << pair;
134 fillSendBuffer(_cfg.density, *_couetteSolver, buffer);
135
136 _multiMDCellService->setInnerMomentumImposition(true);
137 const int EQUI_CYCLES = 3; // 2 cycles should be sufficient (10 cycles without inner imposition on MD30), 3 cycles is even safer
138 for(int i = 0; i < EQUI_CYCLES; i++){
139 _multiMDCellService->sendFromMacro2MD(buffer);
140 _instanceHandling->simulateTimesteps(_simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps(),
142 }
143 _mdStepCounter += EQUI_CYCLES*_simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps();
144
145 _multiMDCellService->setInnerMomentumImposition(false);
146 }
147
148 coupling::solvers::AbstractCouetteSolver<3>* getSolver() override { return _couetteSolver; }
149
150protected:
152 void getRootRank() {
153 int rank = 0;
154#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
155 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
156#endif
157 _isRootRank = (rank == 0);
158 }
159
161 void twsLoop() {
162 for (_tws = _cfg.twsLoopMin; _tws <= _cfg.twsLoopMax; _tws += _cfg.twsLoopStep) {
163 init();
164 for (int cycle = 0; cycle < _cfg.couplingCycles; cycle++)
165 runOneCouplingCycle(cycle);
166 shutdown();
167 }
168 }
169
173 std::string filename("couette.xml");
174
177 if (!_simpleMDConfig.isValid()) {
178 std::cout << "ERROR CouetteScenario: Invalid SimpleMD config!" << std::endl;
179 exit(EXIT_FAILURE);
180 }
182 if (!_mamicoConfig.isValid()) {
183 std::cout << "ERROR CouetteScenario: Invalid MaMiCo config!" << std::endl;
184 exit(EXIT_FAILURE);
185 }
186
188
190 _simpleMDConfig.getDomainDecompConfiguration().getDecompType() ==
191 simplemd::configurations::DomainDecompConfiguration::DecompositionType::STATIC_IRREG_RECT_GRID) {
192 std::cout << "ERROR Currently, only LS1 supports irregular rectilinear domain decomposition! Please change md type to ls1, or decomposition to default!"
193 << std::endl;
194 exit(EXIT_FAILURE);
195 }
196
197#if defined(LS1_MARDYN)
198 auto offset = _simpleMDConfig.getDomainConfiguration().getGlobalDomainOffset();
199 coupling::interface::LS1StaticCommData::getInstance().setConfigFilename("ls1config.xml");
200 coupling::interface::LS1StaticCommData::getInstance().setBoxOffsetAtDim(0, offset[0]); // temporary till ls1 offset is natively supported
201 coupling::interface::LS1StaticCommData::getInstance().setBoxOffsetAtDim(1, offset[1]);
202 coupling::interface::LS1StaticCommData::getInstance().setBoxOffsetAtDim(2, offset[2]);
203#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
204 auto subdomainWeights = _simpleMDConfig.getDomainDecompConfiguration().getSubdomainWeights();
205 coupling::interface::LS1StaticCommData::getInstance().setSubdomainWeights(subdomainWeights);
206#endif
207#endif
208 }
209
212 void initSolvers() {
213 _timeIntegrationService = std::make_unique<coupling::services::ParallelTimeIntegrationService<3>>(_mamicoConfig, this);
214 _rank = _timeIntegrationService->getRank(); // returns the rank inside local time domain
215
217 _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[0], _simpleMDConfig.getDomainConfiguration().getGlobalDomainOffset(),
218 _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize(), getGlobalNumberCouplingCells(_simpleMDConfig, _mamicoConfig),
219 _mamicoConfig.getMomentumInsertionConfiguration().getInnerOverlap());
220
221 // init indexing
222 if (_simpleMDConfig.getDomainDecompConfiguration().getDecompType() ==
223 simplemd::configurations::DomainDecompConfiguration::DecompositionType::STATIC_IRREG_RECT_GRID) {
224 coupling::indexing::IndexingService<3>::getInstance().initWithMDSize(
225 _simpleMDConfig.getDomainDecompConfiguration().getSubdomainWeights(), _simpleMDConfig.getDomainConfiguration().getGlobalDomainSize(),
226 _simpleMDConfig.getDomainConfiguration().getGlobalDomainOffset(), _simpleMDConfig.getMPIConfiguration().getNumberOfProcesses(),
227 _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize(), _mamicoConfig.getParallelTopologyConfiguration().getParallelTopologyType(),
228 _mamicoConfig.getMomentumInsertionConfiguration().getInnerOverlap(), (unsigned int)_rank
229#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
230 ,
231 _timeIntegrationService->getPintComm()
232#endif
233 );
234 } else {
235 coupling::indexing::IndexingService<3>::getInstance().initWithMDSize(
236 _simpleMDConfig.getDomainConfiguration().getGlobalDomainSize(), _simpleMDConfig.getDomainConfiguration().getGlobalDomainOffset(),
237 _simpleMDConfig.getMPIConfiguration().getNumberOfProcesses(), _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize(),
238 _mamicoConfig.getParallelTopologyConfiguration().getParallelTopologyType(), _mamicoConfig.getMomentumInsertionConfiguration().getInnerOverlap(),
239 (unsigned int)_rank
240#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
241 ,
242 _timeIntegrationService->getPintComm()
243#endif
244 );
245 }
246
247 // for timing measurements
248 _tv.micro = 0;
249 _tv.macro = 0;
250 _tv.filter = 0;
251
252 // even if _cfg.miSolverType == SYNTHETIC then
253 // multiMDService, _mdSimulations, _mdSolverInterface etc need to be initialized
254
255 unsigned int totNumMD;
256 if (_cfg.totalNumberMDSimulations > 0)
257 totNumMD = _cfg.totalNumberMDSimulations;
258 else // dynamic case, start with _cfg.lowerBoundNumberMDSimulations MD
259 totNumMD = _cfg.lowerBoundNumberMDSimulations;
260
261 _multiMDService = new tarch::utils::MultiMDService<3>(_simpleMDConfig.getMPIConfiguration().getNumberOfProcesses(), totNumMD
262#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
263 ,
264 _timeIntegrationService->getPintComm()
265#endif
266 );
267
269 if (_instanceHandling == nullptr) {
270 std::cout << "ERROR CouetteScenario::initSolvers() : _instanceHandling == NULL!" << std::endl;
271 std::exit(EXIT_FAILURE);
272 }
273
274 _mdStepCounter = 0;
275 if (_isRootRank) {
276 gettimeofday(&_tv.start, NULL);
277 gettimeofday(&_tv.output, NULL);
278 }
279
281 // equilibrate MD
282 _instanceHandling->switchOffCoupling();
283 _instanceHandling->equilibrate(_cfg.equSteps, _mdStepCounter);
284 _instanceHandling->switchOnCoupling();
285 _mdStepCounter += _cfg.equSteps;
286 }
287
288 // allocate coupling interfaces
289 _instanceHandling->setMDSolverInterface();
290 _mdSolverInterface = _instanceHandling->getMDSolverInterface();
291
292 if (_cfg.twsLoop) {
293 // initialise coupling cell service for multi-MD case and set single
294 // cell services in each MD simulation
296 _mamicoConfig, "couette.xml", *_multiMDService, _tws);
297 } else {
298 // initialise coupling cell service for multi-MD case and set single
299 // cell services in each MD simulation
301 _mamicoConfig, "couette.xml", *_multiMDService);
302 }
303
304 // init filtering for all md instances
305 _multiMDCellService->constructFilterPipelines();
306
307 _multiMDMediator = new coupling::MultiMDMediator<MY_LINKEDCELL, 3>(*_multiMDCellService, *_instanceHandling, *_multiMDService, couetteSolverInterface);
308
309 // allocate solvers
310 _couetteSolver = NULL;
312 getCouetteSolver(_mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[0],
313 _simpleMDConfig.getSimulationConfiguration().getDt() * _simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps());
314 _MDBoundarySetupDone = false;
315
317 // set couette solver interface in MamicoInterfaceProvider
319
320 _instanceHandling->setCouplingCellServices(*_multiMDCellService);
321 // compute and store temperature in coupling cells (temp=1.1
322 // everywhere)
323 _multiMDCellService->computeAndStoreTemperature(_cfg.temp);
324 }
325
326 /*
327 * A synthethic solver is modeled using a dynamically linked filter,
328 * i.e. a lambda function producing artifical data in every filter step.
329 *
330 * This is how to properly instanciate and use a synthethic solver:
331 * - Create a sequence named like the macro SYNTHETICMD_SEQUENCE in xml. Use
332 * whatever input, but make sure the filter system's output is set to this
333 * sequence.
334 * - Set filtered-values = "macro-mass macro-momentum" for that sequence.
335 * - Use that sequence as input for all sequences that want (unfiltered) MD
336 * input.
337 *
338 * Note that this synthethic solver is designed to be used on sequential
339 * mode only and with only one MD instance.
340 *
341 * TODO
342 * - major bug when there is ONLY a FFF in a sequence
343 * - reduce capture: most variables in lambda can be defined beforehand as
344 * they are const (e.g. everything coming from cfg)
345 * - totalNumberMDSimulations > 1 is theoretically possible with this
346 * redesign. test it and remove the restriction for it to be 1
347 */
348
350 // Synthetic MD runs sequentially only, as described above.
351 if (_cfg.macro2Md || _cfg.totalNumberMDSimulations != 1 || _cfg.lbNumberProcesses[0] != 1 || _cfg.lbNumberProcesses[1] != 1 ||
352 _cfg.lbNumberProcesses[2] != 1) {
353 throw std::runtime_error("ERROR: Syntethic MD is only available in sequential mode!");
354 }
355
356 // set couette solver interface in MamicoInterfaceProvider
358
361
362 // Create new FilterFromFunction instance and insert it into Filtering
363 // System.
364 try {
365 _multiMDCellService->getCouplingCellService(0)
366 .getFilterPipeline()
367 ->getSequence(SYNTHETICMD_SEQUENCE)
368 ->addFilter(
369 new std::function<std::vector<double>(std::vector<double>, std::vector<std::array<unsigned int, 3>>)>{
370 // applyScalar
371 [this](std::vector<double> inputScalars, // not actually used as input:
372 // matching MCS's
373 // addFilterToSequence(...)
374 // signature
375 std::vector<std::array<unsigned int, 3>> cellIndices // not used either
376 ) {
377 if (_isRootRank) {
378 gettimeofday(&_tv.start, NULL);
379 }
380
381 // std::cout << "Entering synthetic MD scalar..." << std::endl;
382
383 const unsigned int size = inputScalars.size();
384 auto dx = coupling::indexing::IndexingService<3>::getInstance().getCouplingCellSize();
385 const tarch::la::Vector<3, double> couplingCellSize(dx);
386 const double mass = (_cfg.density) * couplingCellSize[0] * couplingCellSize[1] * couplingCellSize[2];
387
388 std::vector<double> syntheticMasses;
389 for (unsigned int i = 0; i < size; i++) {
390 syntheticMasses.push_back(mass);
391 }
392 // std::cout << "Generated masses!" << std::endl;
393
394 if (_isRootRank) {
395 gettimeofday(&_tv.end, NULL);
396 _tv.micro += (_tv.end.tv_sec - _tv.start.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start.tv_usec);
397 }
398
399 return syntheticMasses;
400 }},
401 new std::function<std::vector<std::array<double, 3>>(std::vector<std::array<double, 3>>, std::vector<std::array<unsigned int, 3>>)>{
402 // applyVector
403 [this](std::vector<std::array<double, 3>> inputVectors, // same as above
404 std::vector<std::array<unsigned int, 3>> cellIndices // same as above
405 ) {
406 if (_isRootRank) {
407 gettimeofday(&_tv.start, NULL);
408 }
409
410 // std::cout << "Entering synthetic MD vector." << std::endl;
411
412 const unsigned int size = inputVectors.size();
413 auto dx = coupling::indexing::IndexingService<3>::getInstance().getCouplingCellSize();
414 const tarch::la::Vector<3, double> couplingCellSize(dx);
415 const double mass = (_cfg.density) * couplingCellSize[0] * couplingCellSize[1] * couplingCellSize[2];
416
417 using coupling::indexing::IndexTrait;
419
420 const tarch::la::Vector<3, double> md2MacroDomainOffset = {
421 CellIndex<3, IndexTrait::local, IndexTrait::md2macro, IndexTrait::noGhost>::lowerBoundary.get()[0] * couplingCellSize[0],
422 CellIndex<3, IndexTrait::local, IndexTrait::md2macro, IndexTrait::noGhost>::lowerBoundary.get()[1] * couplingCellSize[1],
423 CellIndex<3, IndexTrait::local, IndexTrait::md2macro, IndexTrait::noGhost>::lowerBoundary.get()[2] * couplingCellSize[2],
424 };
425
426 std::normal_distribution<double> distribution(0.0, _cfg.noiseSigma);
427 std::vector<std::array<double, 3>> syntheticMomenta;
428 for (unsigned int i = 0; i < size; i++) {
429 // determine cell midpoint
430 CellIndex<3, IndexTrait::vector> globalIndex(
431 CellIndex<3, IndexTrait::local, IndexTrait::md2macro, IndexTrait::noGhost>{i}); // construct global CellIndex from buffer
432 // and convert it to vector
433 tarch::la::Vector<3, double> cellMidPoint(md2MacroDomainOffset - 0.5 * couplingCellSize);
434 for (unsigned int d = 0; d < 3; d++) {
435 cellMidPoint[d] = cellMidPoint[d] + ((double)globalIndex.get()[d]) * couplingCellSize[d];
436 }
437
438 // compute momentum
439 const tarch::la::Vector<3, double> noise(distribution(_generator), distribution(_generator), distribution(_generator));
440 const tarch::la::Vector<3, double> momentum(mass * ((*_couetteSolver).getVelocity(cellMidPoint) + noise));
441
442 // conversion from tarch::la::Vector to std::array
443 syntheticMomenta.push_back({momentum[0], momentum[1], momentum[2]});
444 }
445 // std::cout << "Generated momenta!" << std::endl;
446
447 if (_isRootRank) {
448 gettimeofday(&_tv.end, NULL);
449 _tv.micro += (_tv.end.tv_sec - _tv.start.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start.tv_usec);
450 }
451
452 return syntheticMomenta;
453 }},
454 0 // filterIndex
455 );
456 } catch (std::runtime_error& e) {
457 auto expectedError = std::string("ERROR: Could not find Filter Sequence named ").append(SYNTHETICMD_SEQUENCE);
458 if (expectedError.compare(e.what()) == 0) {
459 std::cout << "ERROR: Synthetic MD solver selected without providing "
460 "filter sequence '"
461 << SYNTHETICMD_SEQUENCE << "' in config." << std::endl;
462 exit(EXIT_FAILURE);
463 } else
464 throw e;
465 }
466 }
467
468 // allocate buffers for send/recv operations
469 allocateMacro2mdBuffer(*couetteSolverInterface);
470 allocateMd2macroBuffer(*couetteSolverInterface);
471
472 if (_cfg.initAdvanceCycles > 0 && _couetteSolver != NULL)
473 _couetteSolver->advance(_cfg.initAdvanceCycles * _simpleMDConfig.getSimulationConfiguration().getDt() *
474 _simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps());
475
476 // finish time measurement for initialisation
477 if (_isRootRank) {
478 gettimeofday(&_tv.end, NULL);
479 double runtime = (_tv.end.tv_sec - _tv.start.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start.tv_usec);
480 std::cout << "Initialization: " << (int)(runtime / 1000) << "ms" << std::endl;
481 }
482
483 if (_cfg.computeSNR) {
484 std::cout << "Output for every coupling cycle, for the cell 87 in recvBuffer:" << std::endl;
485 std::cout << "cycle number (after filter-init-cycles), vel_x macroscopic "
486 "solver, vel_x filter output"
487 << std::endl;
488 _sum_signal = 0;
489 _sum_noise = 0;
490 }
491
492 if (_isRootRank) {
493 gettimeofday(&_tv.start_total, NULL);
494 }
495 std::cout << "Finish CouetteScenario::initSolvers() " << std::endl;
496 }
497
501 void advanceMacro(int cycle) {
502 if (_couetteSolver != NULL) {
503 if (_isRootRank) {
504 gettimeofday(&_tv.start, NULL);
505 }
506
507 // run one time step for macroscopic couette solver
508 if (_cfg.wallInitCycles > 0 && cycle == _cfg.wallInitCycles) {
509 _couetteSolver->setWallVelocity(_cfg.wallVelocity);
510 // When using Synthetic MD,
511 }
512 if (_cfg.wallOscillations != 0) {
513 tarch::la::Vector<3, double> vel = cycle < _cfg.wallInitCycles ? _cfg.wallInitVelocity : _cfg.wallVelocity;
514 vel = vel * cos(2 * M_PI * _cfg.wallOscillations * cycle / _cfg.couplingCycles);
515 _couetteSolver->setWallVelocity(vel);
516 }
517 _couetteSolver->advance(_simpleMDConfig.getSimulationConfiguration().getDt() * _simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps());
518 if (_isRootRank) {
519 gettimeofday(&_tv.end, NULL);
520 _tv.macro += (_tv.end.tv_sec - _tv.start.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start.tv_usec);
521 // std::cout << "Finish _couetteSolver->advance " << std::endl;
522 }
523
524 // extract data from couette solver and send them to MD (can take any
525 // index-conversion object)
526 fillSendBuffer(_cfg.density, *_couetteSolver, _couplingBuffer.macro2MDBuffer);
527 }
528 if (_cfg.macro2Md) {
529#ifdef USE_COLLECTIVE_MPI
530 _multiMDCellService->bcastFromMacro2MD(_couplingBuffer.macro2MDBuffer);
531#else
532 _multiMDCellService->sendFromMacro2MD(_couplingBuffer.macro2MDBuffer);
533#endif
534 // std::cout << "Finish _multiMDCellService->sendFromMacro2MD " <<
535 // std::endl;
536 }
537 }
538
539 void varyMD(int cycle) {
540 // Non-dynamic case: Nothing to do.
542 return;
543
544 // modify number of instances only once every 10 cycles
545 if (cycle % 10 != 0)
546 return;
547
548 int addMDInstances = 0;
549
550 if (_rank == 0) {
551 tarch::la::Vector<3, double> vel(0, 0, 0);
552 double mass = 0;
553 for (auto pair : _couplingBuffer.md2macroBuffer) {
554 I01 idx;
556 std::tie(couplingCell, idx) = pair;
557 vel += couplingCell->getMacroscopicMomentum();
558 mass += couplingCell->getMacroscopicMass();
559 }
560 vel = vel / (double)_couplingBuffer.md2macroBuffer.size();
561 mass /= _couplingBuffer.md2macroBuffer.size();
562
563 double soundSpeed =
564 (1 / std::sqrt(3)) * (_mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[0] /
565 (_simpleMDConfig.getSimulationConfiguration().getDt() * _simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps()));
566 double cellVolume = _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[0] *
567 _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[1] *
568 _mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize()[2];
569
570 coupling::error::ErrorEstimation errorControl(vel[0], _cfg.temp, mass, _simpleMDConfig.getMoleculeConfiguration().getMass(), soundSpeed,
571 _multiMDService->getTotalNumberOfMDSimulations(), cellVolume);
572
573 double simtime = (double)cycle / _cfg.couplingCycles;
574 double targetError = _cfg.absVelErrEnd * simtime + _cfg.absVelErrStart * (1 - simtime);
575 errorControl.setAbsVelocityError(targetError);
576 double NoMD = errorControl.getCorrectorNumberOfSamples(coupling::error::ErrorEstimation::Velocity, coupling::error::ErrorEstimation::Absolute);
577
578 addMDInstances = NoMD - _multiMDService->getTotalNumberOfMDSimulations();
579 }
580
581#if (COUPLING_MD_PARALLEL == COUPLING_MD_YES)
582 MPI_Bcast(&addMDInstances, 1, MPI_INT, 0, _timeIntegrationService->getPintComm());
583#endif
584 if (addMDInstances < 0) {
585 if ((int)_multiMDMediator->getNumberOfActiveMDSimulations() + addMDInstances < _cfg.lowerBoundNumberMDSimulations) {
586 addMDInstances = (_cfg.lowerBoundNumberMDSimulations - (int)_multiMDMediator->getNumberOfActiveMDSimulations());
587 }
588 }
589 if (addMDInstances < 0) {
590 if (_rank == 0)
591 std::cout << "Removing " << -addMDInstances << " of " << _multiMDService->getTotalNumberOfMDSimulations() << " MD simulations" << std::endl;
592 _multiMDMediator->rmNMDSimulations(-addMDInstances);
593 } else if (addMDInstances > 0) {
594 if (_rank == 0)
595 std::cout << "Adding " << addMDInstances << " to " << _multiMDService->getTotalNumberOfMDSimulations() << " MD simulations" << std::endl;
596 _multiMDMediator->addNMDSimulations(addMDInstances);
597 }
598 }
599
603 void advanceMicro(int cycle) {
604 if (_isRootRank) {
605 gettimeofday(&_tv.start, NULL);
606 }
608 // run MD instances
609 _instanceHandling->simulateTimesteps(_simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps(), _mdStepCounter, *_multiMDCellService);
610 // plot macroscopic time step info in multi md service
611 _multiMDCellService->plotEveryMacroscopicTimestep(cycle);
612
613 _mdStepCounter += _simpleMDConfig.getSimulationConfiguration().getNumberOfTimesteps();
614
615 if (_isRootRank) {
616 gettimeofday(&_tv.end, NULL);
617 _tv.micro += (_tv.end.tv_sec - _tv.start.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start.tv_usec);
618 }
619
620 // send back data from MD instances and merge it
621 if (_cfg.md2Macro) {
622#ifdef USE_COLLECTIVE_MPI
623 _tv.filter += _multiMDCellService->reduceFromMD2Macro(_couplingBuffer.md2macroBuffer);
624#else
625 _tv.filter += _multiMDCellService->sendFromMD2Macro(_couplingBuffer.md2macroBuffer);
626#endif
627 // std::cout << "Finish _multiMDCellService->sendFromMD2Macro " <<
628 // std::endl;
629 }
630 }
631
633 if (_cfg.md2Macro) {
634 //_couplingBuffer does not get used here: Instead, the synthetic MD in the
635 // SYNTHETICMD_SEQUENCE generates values. To prevent segfaults, it has
636 // to be nonempty, though.
637#ifdef USE_COLLECTIVE_MPI
638 _tv.filter += _multiMDCellService->reduceFromMD2Macro(_couplingBuffer.md2macroBuffer);
639#else
640 _tv.filter += _multiMDCellService->sendFromMD2Macro(_couplingBuffer.md2macroBuffer);
641#endif
642 }
643 }
644 }
645
647 void computeSNR(int cycle) {
648 if (_cfg.computeSNR && cycle >= _cfg.filterInitCycles) {
649 std::cout << cycle - _cfg.filterInitCycles << ", ";
650 using namespace coupling::indexing;
651 const tarch::la::Vector<3, double> dx(IndexingService<3>::getInstance().getCouplingCellSize());
652 const double mass = _cfg.density * dx[0] * dx[1] * dx[2];
653 unsigned int i = 0;
654 for (auto pair : _couplingBuffer.md2macroBuffer) {
656 if (i == 87) {
657 I01 idx;
659 std::tie(couplingCell, idx) = pair;
660 auto midPoint = idx.getCellMidPoint();
661 double vx_macro = _couetteSolver->getVelocity(midPoint)[0];
662 double vx_filter = (1 / mass * couplingCell->getMacroscopicMomentum())[0];
663 _sum_noise += (vx_macro - vx_filter) * (vx_macro - vx_filter);
664 _sum_signal += vx_macro * vx_macro;
665 std::cout << vx_macro << ", " << vx_filter << std::endl;
666 }
667 i++;
668 }
669 }
670 }
671
675 void twoWayCoupling(int cycle) {
677 if (_cfg.twoWayCoupling) {
678#if (BUILD_WITH_OPENFOAM)
679 if ((_cfg.maSolverType == CouetteConfig::COUETTE_FOAM) && cycle == _cfg.filterInitCycles && _couetteSolver != NULL) {
680 static_cast<coupling::solvers::IcoFoamInterface*>(_couetteSolver)->setupMDBoundary();
681 }
682#endif
683 if ((_cfg.maSolverType == CouetteConfig::COUETTE_LB || _cfg.maSolverType == CouetteConfig::COUETTE_FD) && cycle >= _cfg.filterInitCycles) {
684 if (!_MDBoundarySetupDone){
686 ->setMDBoundary(_simpleMDConfig.getDomainConfiguration().getGlobalDomainOffset(), _simpleMDConfig.getDomainConfiguration().getGlobalDomainSize(),_mamicoConfig.getMomentumInsertionConfiguration().getInnerOverlap());
687 _MDBoundarySetupDone = true;
688 }
689 static_cast<coupling::solvers::LBCouetteSolver*>(_couetteSolver)->setMDBoundaryValues(_couplingBuffer.md2macroBuffer);
690 }
691#if (BUILD_WITH_OPENFOAM)
692 else if (_cfg.maSolverType == CouetteConfig::COUETTE_FOAM && cycle >= _cfg.filterInitCycles && _couetteSolver != NULL) {
693 static_cast<coupling::solvers::IcoFoamInterface*>(_couetteSolver)->setMDBoundaryValues(_couplingBuffer.md2macroBuffer);
694 }
695#endif
696 }
697 // write data to csv-compatible file for evaluation
698 write2CSV(_couplingBuffer.md2macroBuffer, cycle + 1);
699 }
700
703 void shutdown() {
704 if (_cfg.computeSNR) {
705 std::cout << "SNR = " << 10 * log10(_sum_signal / _sum_noise) << std::endl;
706 }
707
708 // finish time measurement for coupled simulation
709 if (_isRootRank) {
710 gettimeofday(&_tv.end, NULL);
711 double time_total = (_tv.end.tv_sec - _tv.start_total.tv_sec) * 1000000 + (_tv.end.tv_usec - _tv.start_total.tv_usec);
712 std::cout << "Finished all coupling cycles after " << time_total / 1000000 << " s" << std::endl;
713 if (_cfg.twsLoop)
714 std::cout << "TWS = " << _tws << std::endl;
715 std::cout << "Time percentages Micro, Macro, Filter, Other: " << std::endl;
716 std::cout << _tv.micro / time_total * 100 << ", " << _tv.macro / time_total * 100 << ", " << _tv.filter / time_total * 100 << ", "
717 << (1 - (_tv.micro + _tv.macro + _tv.filter) / time_total) * 100 << std::endl;
718 }
719
720 if (_instanceHandling != nullptr) {
721 delete _instanceHandling;
722 }
723
726
727 if (_multiMDService != NULL) {
728 delete _multiMDService;
729 _multiMDService = NULL;
730 }
731 if (couetteSolverInterface != NULL) {
732 delete couetteSolverInterface;
733 couetteSolverInterface = NULL;
734 }
735 if (_couetteSolver != NULL) {
736 delete _couetteSolver;
737 _couetteSolver = NULL;
738 }
739 if (_multiMDCellService != NULL) {
740 delete _multiMDCellService;
741 _multiMDCellService = NULL;
742 }
743 if (_multiMDMediator != nullptr) {
744 delete _multiMDMediator;
745 _multiMDMediator = nullptr;
746 }
747
748 std::cout << "Finish CouetteScenario::shutdown() " << std::endl;
749 }
750
752 tarch::la::Vector<3, unsigned int> getGlobalNumberCouplingCells(const simplemd::configurations::MolecularDynamicsConfiguration& simpleMDConfig,
753 const coupling::configurations::MaMiCoConfiguration<3>& mamicoConfig) const {
754 tarch::la::Vector<3, double> domainSize(simpleMDConfig.getDomainConfiguration().getGlobalDomainSize());
755 tarch::la::Vector<3, double> dx(mamicoConfig.getCouplingCellConfiguration().getCouplingCellSize());
756 tarch::la::Vector<3, unsigned int> globalNumberCouplingCells(0);
757 for (unsigned int d = 0; d < 3; d++) {
758 int buf = floor(domainSize[d] / dx[d] + 0.5);
759 globalNumberCouplingCells[d] = (unsigned int)buf;
760 }
761 return globalNumberCouplingCells;
762 }
763
768 for (auto idx : I08()) {
769 if (!I12::contains(idx)) {
770 if (tarch::utils::contains(msi.getSourceRanks(idx), (unsigned int)_rank)) {
772 _couplingBuffer.macro2MDBuffer << std::make_pair(couplingCell, idx);
773 if (couplingCell == nullptr)
774 throw std::runtime_error(std::string("ERROR CouetteScenario::allocateMacro2mdBuffer: couplingCell==NULL!"));
775 }
776 }
777 }
778 }
779
783 for (auto idx : I12()) {
784 if (tarch::utils::contains(msi.getTargetRanks(idx), (unsigned int)_rank)) {
786 _couplingBuffer.md2macroBuffer << std::make_pair(couplingCell, idx);
787 if (couplingCell == nullptr)
788 throw std::runtime_error(std::string("ERROR CouetteScenario::allocateMacro2mdBuffer: couplingCell==NULL!"));
789 }
790 }
791 }
792
797 template <class Container_T> void write2CSV(Container_T& md2macroBuffer, int couplingCycle) const {
798 if (md2macroBuffer.size() == 0)
799 return;
800 if (_cfg.csvEveryTimestep < 1 || couplingCycle % _cfg.csvEveryTimestep > 0)
801 return;
802 // form file name and open file
803 std::stringstream ss;
804 ss << "CouetteAvgMultiMDCells_" << _timeIntegrationService->getPintDomain() << "_" << _rank << "_" << couplingCycle << ".csv";
805 std::ofstream file(ss.str().c_str());
806 if (!file.is_open()) {
807 std::cout << "ERROR CouetteScenario::write2CSV(): Could not open file " << ss.str() << "!" << std::endl;
808 exit(EXIT_FAILURE);
809 }
810
811 // loop over md2macro cells; read macroscopic mass+momentum buffers and
812 // write cell index, mass and velocity to one line in the csv-file
813 file << "I01_x,I01_y,I01_z,vel_x,vel_y,vel_z,mass" << std::endl;
814 for (auto pair : md2macroBuffer) {
815 I01 idx;
817 std::tie(couplingCell, idx) = pair;
819 if (couplingCell->getMacroscopicMass() != 0.0) {
820 vel = (1.0 / couplingCell->getMacroscopicMass()) * vel;
821 }
822 file << idx << "," << vel[0] << "," << vel[1] << "," << vel[2] << "," << couplingCell->getMacroscopicMass() << std::endl;
823 }
824
825 // close file
826 file.close();
827 }
828
835 void fillSendBuffer(const double density, const coupling::solvers::AbstractCouetteSolver<3>& couetteSolver,
838 using namespace coupling::indexing;
839 const tarch::la::Vector<3, double> dx(IndexingService<3>::getInstance().getCouplingCellSize());
840 double mass = density * dx[0] * dx[1] * dx[2];
841 for (auto pair : macro2MDBuffer) {
842 I01 idx;
844 std::tie(couplingCell, idx) = pair;
845 auto midPoint = idx.getCellMidPoint();
846 if (_cfg.maSolverType == CouetteConfig::COUETTE_LB || _cfg.maSolverType == CouetteConfig::COUETTE_FD)
847 mass *= static_cast<const coupling::solvers::LBCouetteSolver*>(&couetteSolver)->getDensity(midPoint);
848 // compute momentum
849 tarch::la::Vector<3, double> momentum(mass * couetteSolver.getVelocity(midPoint));
850 couplingCell->setMicroscopicMass(mass);
851 couplingCell->setMicroscopicMomentum(momentum);
852 }
853 }
854
861 tarch::la::Vector<3, double> vel = _cfg.wallInitCycles > 0 ? _cfg.wallInitVelocity : _cfg.wallVelocity;
862 // analytical solver: is only active on rank 0
863 if (_cfg.maSolverType == CouetteConfig::COUETTE_ANALYTICAL) {
864 if (_rank == 0 || _cfg.miSolverType == CouetteConfig::SYNTHETIC) {
865 solver = new coupling::solvers::CouetteSolver<3>(_cfg.channelheight, vel[0], _cfg.kinVisc);
866 if (solver == NULL) {
867 std::cout << "ERROR CouetteScenario::getCouetteSolver(): Analytic solver==NULL!" << std::endl;
868 exit(EXIT_FAILURE);
869 }
870 }
871 }
872#if (BUILD_WITH_OPENFOAM)
873 else if (_cfg.maSolverType == CouetteConfig::COUETTE_FOAM) {
874 solver = new coupling::solvers::IcoFoamInterface(_rank, _cfg.plotEveryTimestep, _cfg.channelheight, _cfg.foam.directory, _cfg.foam.folder,
875 _cfg.foam.boundariesWithMD, _cfg.wallVelocity);
876 if (solver == NULL) {
877 std::cout << "ERROR CouetteScenario::getCouetteSolver(): IcoFoamInterface solver==NULL!" << std::endl;
878 exit(EXIT_FAILURE);
879 }
880 }
881#endif
882 // LB solver: active on lbNumberProcesses
883 else if (_cfg.maSolverType == CouetteConfig::COUETTE_LB) {
884 solver = new coupling::solvers::LBCouetteSolver(_cfg.channelheight, vel, _cfg.kinVisc, dx, dt, _cfg.plotEveryTimestep, "LBCouette",
885 _cfg.lbNumberProcesses, 1, this);
886 if (solver == NULL) {
887 std::cout << "ERROR CouetteScenario::getCouetteSolver(): LB solver==NULL!" << std::endl;
888 exit(EXIT_FAILURE);
889 }
890 } else if (_cfg.maSolverType == CouetteConfig::COUETTE_FD) {
891 solver = new coupling::solvers::FiniteDifferenceSolver(_cfg.channelheight, vel, _cfg.kinVisc, dx, dt, _cfg.plotEveryTimestep, "FDCouette",
892 _cfg.lbNumberProcesses, 1);
893 if (solver == NULL) {
894 std::cout << "ERROR CouetteScenario::getCouetteSolver(): FD solver==NULL!" << std::endl;
895 exit(EXIT_FAILURE);
896 }
897 } else {
898 std::cout << "ERROR CouetteScenario::getCouetteSolver(): Unknown solver type!" << std::endl;
899 exit(EXIT_FAILURE);
900 }
901 return solver;
902 }
903
913 tarch::la::Vector<3, double> mamicoMeshsize,
914 tarch::la::Vector<3, unsigned int> globalNumberCouplingCells,
915 unsigned int outerRegion) {
918 if (_cfg.maSolverType == CouetteConfig::COUETTE_ANALYTICAL) {
919 interface = new coupling::solvers::CouetteSolverInterface<3>(globalNumberCouplingCells, outerRegion);
920 } else if (_cfg.maSolverType == CouetteConfig::COUETTE_LB) {
921 // compute number of cells of MD offset; detect any mismatches!
922 tarch::la::Vector<3, unsigned int> offsetMDDomain(0);
923 for (unsigned int d = 0; d < 3; d++) {
924 if (mdOffset[d] < 0.0) {
925 std::cout << "ERROR CouetteScenario::getCouetteSolverInterface(...): mdOffset[" << d << "]<0.0!" << std::endl;
926 exit(EXIT_FAILURE);
927 }
928 offsetMDDomain[d] = floor(mdOffset[d] / mamicoMeshsize[d] + 0.5);
929 if (fabs((offsetMDDomain[d] * mamicoMeshsize[d] - mdOffset[d]) / mamicoMeshsize[d]) > 1.0e-8) {
930 std::cout << "ERROR CouetteScenario::getCouetteSolverInterface: MD offset and mesh size mismatch!" << std::endl;
931 exit(EXIT_FAILURE);
932 }
933 }
934 tarch::la::Vector<3, unsigned int> cells_per_process{
936 coupling::solvers::NumericalSolver::getAvgDomainSize(_cfg.channelheight, dx, _cfg.lbNumberProcesses, 1),
937 coupling::solvers::NumericalSolver::getAvgDomainSize(_cfg.channelheight, dx, _cfg.lbNumberProcesses, 2)}};
938 interface =
939 new coupling::solvers::LBCouetteSolverInterface(cells_per_process, _cfg.lbNumberProcesses, offsetMDDomain, globalNumberCouplingCells, outerRegion);
940 }
941#if (BUILD_WITH_OPENFOAM)
942 else if (_cfg.maSolverType == CouetteConfig::COUETTE_FOAM) {
943 interface = new coupling::solvers::CouetteSolverInterface<3>(globalNumberCouplingCells, outerRegion);
944 }
945#endif
946 else if (_cfg.maSolverType == CouetteConfig::COUETTE_FD) {
947 // compute number of cells of MD offset; detect any mismatches!
948 tarch::la::Vector<3, unsigned int> offsetMDDomain(0);
949 for (unsigned int d = 0; d < 3; d++) {
950 if (mdOffset[d] < 0.0) {
951 std::cout << "ERROR CouetteScenario::getCouetteSolverInterface(...): mdOffset[" << d << "]<0.0!" << std::endl;
952 exit(EXIT_FAILURE);
953 }
954 offsetMDDomain[d] = floor(mdOffset[d] / mamicoMeshsize[d] + 0.5);
955 if (fabs((offsetMDDomain[d] * mamicoMeshsize[d] - mdOffset[d]) / mamicoMeshsize[d]) > 1.0e-8) {
956 std::cout << "ERROR CouetteScenario::getCouetteSolverInterface: MD offset and mesh size mismatch!" << std::endl;
957 exit(EXIT_FAILURE);
958 }
959 }
960 tarch::la::Vector<3, unsigned int> cells_per_process{
962 coupling::solvers::NumericalSolver::getAvgDomainSize(_cfg.channelheight, dx, _cfg.lbNumberProcesses, 1),
963 coupling::solvers::NumericalSolver::getAvgDomainSize(_cfg.channelheight, dx, _cfg.lbNumberProcesses, 2)}};
964 interface =
965 new coupling::solvers::LBCouetteSolverInterface(cells_per_process, _cfg.lbNumberProcesses, offsetMDDomain, globalNumberCouplingCells, outerRegion);
966 }
967
968 if (interface == NULL) {
969 std::cout << "ERROR CouetteScenario::getCouetteSolverInterface(...), rank=" << _rank << ": interface==NULL!" << std::endl;
970 exit(EXIT_FAILURE);
971 }
972 return interface;
973 }
974
984
989 timeval start_total;
991 timeval start;
993 timeval end;
994 timeval output;
996 double micro;
998 double macro;
1000 double filter;
1001 };
1002
1008 int _tws;
1010 simplemd::configurations::MolecularDynamicsConfiguration _simpleMDConfig;
1016 unsigned int _mdStepCounter;
1026 std::vector<coupling::interface::MDSolverInterface<MY_LINKEDCELL, 3>*> _mdSolverInterface;
1029 std::default_random_engine _generator;
1037 bool _MDBoundarySetupDone;
1038};
1039
1040#endif // _COUPLING_SCENARIO_COUETTESCENARIO_H_
coupling::solvers::AbstractCouetteSolver< 3 > * getCouetteSolver(const double dx, const double dt)
Definition CouetteScenario.h:858
CouetteScenario()
simple constructor
Definition CouetteScenario.h:72
void allocateMd2macroBuffer(coupling::interface::MacroscopicSolverInterface< 3 > &msi)
Definition CouetteScenario.h:782
void computeSNR(int cycle)
used to compute signal-to-noise ratio, stores values in _sum_noise and _sum_signal
Definition CouetteScenario.h:647
void parseConfigurations()
reads the configuration from the xml file and calls parseCouetteScenarioConfiguration()
Definition CouetteScenario.h:172
TimingValues _tv
a instance of the timingValues
Definition CouetteScenario.h:1035
coupling::configurations::MaMiCoConfiguration< 3 > _mamicoConfig
the config data and information for MaMiCo
Definition CouetteScenario.h:1012
void fillSendBuffer(const double density, const coupling::solvers::AbstractCouetteSolver< 3 > &couetteSolver, coupling::datastructures::FlexibleCellContainer< 3 > &macro2MDBuffer) const
fills send buffer with data from macro/continuum solver
Definition CouetteScenario.h:835
void advanceMacro(int cycle)
advances the continuum solver and collects data to send to md (fillSendBuffer())
Definition CouetteScenario.h:501
void twsLoop()
Executes the entire test several times for a range of time-window-size parameters.
Definition CouetteScenario.h:161
void initSolvers()
initialises the macro and micro solver according to the setup from the xml file and pre-proccses them
Definition CouetteScenario.h:212
void allocateMacro2mdBuffer(coupling::interface::MacroscopicSolverInterface< 3 > &msi)
allocates the send buffer (with values for all coupling cells).
Definition CouetteScenario.h:767
CouplingBuffer _couplingBuffer
the current buffer for the coupling
Definition CouetteScenario.h:1024
int _tws
Definition CouetteScenario.h:1008
void equilibrateMicro() override
Definition CouetteScenario.h:128
void advanceMicro(int cycle)
advances the md solver for one coupling time step and collect the data for the coupling
Definition CouetteScenario.h:603
double _sum_signal
Definition CouetteScenario.h:1031
void init() override
initialises everthing necessary for the test
Definition CouetteScenario.h:90
unsigned int _mdStepCounter
the counter for the time steps, which are done within the md
Definition CouetteScenario.h:1016
double _sum_noise
Definition CouetteScenario.h:1033
tarch::utils::MultiMDService< 3 > * _multiMDService
Definition CouetteScenario.h:1020
void shutdown()
finalize the time measurement, and cleans up at the end of the simulation
Definition CouetteScenario.h:703
simplemd::configurations::MolecularDynamicsConfiguration _simpleMDConfig
the config data and information for SimpleMD
Definition CouetteScenario.h:1010
coupling::interface::MacroscopicSolverInterface< 3 > * getCouetteSolverInterface(const double dx, tarch::la::Vector< 3, double > mdOffset, tarch::la::Vector< 3, double > mamicoMeshsize, tarch::la::Vector< 3, unsigned int > globalNumberCouplingCells, unsigned int outerRegion)
Definition CouetteScenario.h:912
bool _isRootRank
if this is the world global root process
Definition CouetteScenario.h:1006
virtual ~CouetteScenario()
a dummy destructor
Definition CouetteScenario.h:74
void twoWayCoupling(int cycle)
sets up the boundaries in the macro solver for the coupling and applies the values from the md in the...
Definition CouetteScenario.h:675
void getRootRank()
initialises all MPI variables
Definition CouetteScenario.h:152
void run() override
runs the simulation
Definition CouetteScenario.h:78
void runOneCouplingCycle(int cycle) override
combines the functioniality necessary for a cycle of the coupled simulation
Definition CouetteScenario.h:107
int _rank
the rank of the current MPI process in the local time domain
Definition CouetteScenario.h:1004
std::default_random_engine _generator
Definition CouetteScenario.h:1029
coupling::configurations::CouetteConfig _cfg
the CouetteConfig for the current setup
Definition CouetteScenario.h:1014
tarch::la::Vector< 3, unsigned int > getGlobalNumberCouplingCells(const simplemd::configurations::MolecularDynamicsConfiguration &simpleMDConfig, const coupling::configurations::MaMiCoConfiguration< 3 > &mamicoConfig) const
Definition CouetteScenario.h:752
coupling::services::MultiMDCellService< MY_LINKEDCELL, 3 > * _multiMDCellService
Definition CouetteScenario.h:1022
std::vector< coupling::interface::MDSolverInterface< MY_LINKEDCELL, 3 > * > _mdSolverInterface
the interface to the md solver
Definition CouetteScenario.h:1026
coupling::solvers::AbstractCouetteSolver< 3 > * _couetteSolver
the current macro/continuum solver
Definition CouetteScenario.h:1018
void write2CSV(Container_T &md2macroBuffer, int couplingCycle) const
write coupling cells that have been received from MD to csv file
Definition CouetteScenario.h:797
Simulation slots are managed (i.e., added/removed) via this class. Works and interacts with the class...
Definition InstanceHandling.h:35
Class to handle interaction between MultiMDCellService and InstanceHandling This is currently mainly ...
Definition MultiMDMediator.h:25
parses all sub-tags for MaMiCo configuration.
Definition MaMiCoConfiguration.h:31
const coupling::configurations::CouplingCellConfiguration< dim > & getCouplingCellConfiguration() const
Definition MaMiCoConfiguration.h:68
defines the cell type with cell-averaged quantities only (no linked cells).
Definition CouplingCell.h:29
const tarch::la::Vector< dim, double > & getMacroscopicMomentum() const
Definition CouplingCell.h:64
void setMicroscopicMass(const double &mass)
Definition CouplingCell.h:42
const double & getMacroscopicMass() const
Definition CouplingCell.h:58
void setMicroscopicMomentum(const tarch::la::Vector< dim, double > &momentum)
Definition CouplingCell.h:48
provides access to coupling cells, which may belong to different indexing domains
Definition FlexibleCellContainer.h:30
@ Velocity
Definition ErrorEstimation.h:51
@ Absolute
Definition ErrorEstimation.h:61
Definition CellIndex.h:85
static bool contains(const coupling::indexing::BaseIndex< dim > &index)
Definition CellIndex.h:227
interface for the macroscopic, i.e. continuum solver
Definition MacroscopicSolverInterface.h:23
virtual std::vector< unsigned int > getSourceRanks(I01 idx)
Definition MacroscopicSolverInterface.h:67
virtual std::vector< unsigned int > getTargetRanks(I01 idx)
Definition MacroscopicSolverInterface.h:78
void setMDSolverInterface(coupling::interface::MDSolverInterface< LinkedCell, dim > *mdSolverInterface)
Definition MamicoInterfaceProvider.h:48
void setMacroscopicSolverInterface(coupling::interface::MacroscopicSolverInterface< dim > *macroscopicSolverInterface)
Definition MamicoInterfaceProvider.h:36
static MamicoInterfaceProvider & getInstance()
Definition MamicoInterfaceProvider.h:28
coupling::interface::MacroscopicSolverInterface< dim > * getMacroscopicSolverInterface()
Definition MamicoInterfaceProvider.h:43
void setCouplingCellService(coupling::services::CouplingCellService< dim > *couplingCellService)
Definition MamicoInterfaceProvider.h:58
Definition MultiMDCellService.h:29
interface for continuum/macro fluid solvers for the Couette scenario
Definition CouetteSolver.h:19
virtual tarch::la::Vector< dim, double > getVelocity(tarch::la::Vector< dim, double > pos) const =0
returns the current velocity at the given position
interface to couette solver
Definition CouetteSolverInterface.h:28
implements an analytic Couette flow solver.
Definition CouetteSolver.h:46
implements a simple one-dimensional finite-diffference solver for the Couette flow.
Definition FDCouetteSolver.h:20
Definition IcoFoamInterface.h:34
interface for the LBCouetteSolver
Definition LBCouetteSolverInterface.h:26
implements a three-dimensional Lattice-Boltzmann Couette flow solver.
Definition LBCouetteSolver.h:56
static int getAvgDomainSize(double channelheight, double dx, tarch::la::Vector< 3, unsigned int > processes, int d)
Definition NumericalSolver.h:225
static void parseConfiguration(const std::string filename, const std::string topleveltag, Configuration &config)
Definition ParseConfiguration.h:63
Definition Vector.h:24
Definition MultiMDService.h:30
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15
holds the buffers for the data transfer
Definition CouetteScenario.h:978
coupling::datastructures::FlexibleCellContainer< 3 > macro2MDBuffer
the buffer for data transfer from macro to md
Definition CouetteScenario.h:980
coupling::datastructures::FlexibleCellContainer< 3 > md2macroBuffer
the buffer for data transfer from md to macro
Definition CouetteScenario.h:982
holds all the variables for the time measurement of a simulation
Definition CouetteScenario.h:987
Configuration parameters for Couette flow scenario.
Definition CouetteConfiguration.h:25
int totalNumberMDSimulations
the number of md simulation instances in a multi-instance coupling, -1 = dynamic
Definition CouetteConfiguration.h:322
static CouetteConfig parseCouetteConfiguration(const std::string &filename)
creates CouetteConfig if all elements exist and can be read
Definition CouetteConfiguration.h:51
@ SIMPLEMD
the SimpleMD solver is used
Definition CouetteConfiguration.h:43
@ SYNTHETIC
the synthetic solver is used
Definition CouetteConfiguration.h:44
@ LS1
the LS1 solver is used
Definition CouetteConfiguration.h:45