MaMiCo 1.2
Loading...
Searching...
No Matches
MomentumInsertionConfiguration.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_CONFIGURATIONS_MOMENTUMINSERTIONCONFIGURATION_H_
6#define _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_MOMENTUMINSERTIONCONFIGURATION_H_
7
8#include "coupling/AdditiveMomentumInsertion.h"
9#include "coupling/NieVelocityImposition.h"
10#include "coupling/NoMomentumInsertion.h"
11#include "coupling/SetGivenVelocity4MomentumInsertion.h"
12#include "coupling/VelocityGradientRelaxation.h"
13#include "tarch/configuration/Configuration.h"
14#include "tarch/configuration/ParseConfiguration.h"
15#include "tarch/la/Vector.h"
16#include <iostream>
17
18namespace coupling {
19namespace configurations {
20template <unsigned int dim> class MomentumInsertionConfiguration;
21}
22} // namespace coupling
23
25class NieTest;
26
32public:
33 // for testing: give access to variables; will only be used in the read-sense
34 friend class ::NieTest;
35
47
49 MomentumInsertionConfiguration() : _insertionType(ADDITIVE_MOMENTUM_INSERTION), _isValid(true) {}
50
53
58 std::string value;
60 if (value == "additive-momentum-insertion") {
61 _insertionType = ADDITIVE_MOMENTUM_INSERTION;
62 } else if (value == "direct-velocity-insertion") {
63 _insertionType = DIRECT_VELOCITY_INSERTION;
64 } else if (value == "velocity-gradient-relaxation") {
65 _insertionType = VELOCITY_GRADIENT_RELAXATION;
66 } else if (value == "none") {
67 _insertionType = NO_INSERTION;
68 } else if (value == "velocity-gradient-relaxation-top-only") {
70 } else if (value == "nie-velocity-imposition") {
71 _insertionType = NIE_VELOCITY_IMPOSITION;
72 } else {
73 std::cout << "ERROR coupling::MomentumInsertionConfiguration: Wrong "
74 "insertion type!"
75 << std::endl;
76 _isValid = false;
77 exit(EXIT_FAILURE);
78 }
79
80 if (_insertionType == VELOCITY_GRADIENT_RELAXATION) {
81 tarch::configuration::ParseConfiguration::readDoubleMandatory(_velocityRelaxationFactor, node, "velocity-relaxation-factor");
82 if ((_velocityRelaxationFactor <= 0.0) || (_velocityRelaxationFactor > 1.0)) {
83 std::cout << "ERROR coupling::MomentumInsertionConfiguration: "
84 "velocity-relaxation-factor="
85 << _velocityRelaxationFactor << "!";
86 std::cout << " It must be in the range (0.0,1.0]!" << std::endl;
87 _isValid = false;
88 exit(EXIT_FAILURE);
89 }
90 } else if (_insertionType == VELOCITY_GRADIENT_RELAXATION_TOPONLY) {
91 tarch::configuration::ParseConfiguration::readDoubleMandatory(_velocityRelaxationFactor, node, "velocity-relaxation-factor");
92 if ((_velocityRelaxationFactor <= 0.0) || (_velocityRelaxationFactor > 1.0)) {
93 std::cout << "ERROR coupling::MomentumInsertionConfiguration: "
94 "velocity-relaxation-factor="
95 << _velocityRelaxationFactor << "!";
96 std::cout << " It must be in the range (0.0,1.0]!" << std::endl;
97 _isValid = false;
98 exit(EXIT_FAILURE);
99 }
100 } else if (_insertionType == NIE_VELOCITY_IMPOSITION) {
101 int buf;
102 tarch::configuration::ParseConfiguration::readIntMandatory(buf, node, "innermost-overlap-layer");
103 if (buf <= 0) {
104 std::cout << "ERROR coupling::MomentumInsertionConfiguration: "
105 "innermost-overlap-layer="
106 << buf << "!" << std::endl;
107 _isValid = false;
108 exit(EXIT_FAILURE);
109 }
110 _innerOverlap = (unsigned int)buf;
111 tarch::configuration::ParseConfiguration::readIntMandatory(buf, node, "outermost-overlap-layer");
112 if (((unsigned int)buf > _innerOverlap) || (buf <= 0)) {
113 std::cout << "ERROR coupling::MomentumInsertionConfiguration: "
114 "outermost-overlap-layer="
115 << buf << "!" << std::endl;
116 _isValid = false;
117 exit(EXIT_FAILURE);
118 }
119 _outerOverlap = (unsigned int)buf;
120 const std::string boundaries[6] = {"west", "east", "south", "north", "bottom", "top"}; // TODO change to +-xyz
121 for (unsigned int d = 0; d < 2 * dim; d++) {
122 _impositionEnabled[d] = true;
123 tarch::configuration::ParseConfiguration::readBoolOptional(_impositionEnabled[d], node, boundaries[d]);
124 }
125 }
126 }
127
131 std::string getTag() const { return "momentum-insertion"; }
132
141 bool isValid() const { return _isValid; }
142
146 const MomentumInsertionType& getMomentumInsertionType() const { return _insertionType; }
147
151 unsigned int getInnerOverlap() const { return _innerOverlap; }
152
161 template <class LinkedCell>
165 unsigned int numberMDTimestepsPerCouplingCycle) const {
166 if (_insertionType == ADDITIVE_MOMENTUM_INSERTION) {
167 return new coupling::AdditiveMomentumInsertion<LinkedCell, dim>(mdSolverInterface, numberMDTimestepsPerCouplingCycle);
168 } else if (_insertionType == DIRECT_VELOCITY_INSERTION) {
170 } else if (_insertionType == VELOCITY_GRADIENT_RELAXATION) {
171 return new coupling::VelocityGradientRelaxation<LinkedCell, dim>(_velocityRelaxationFactor, mdSolverInterface, couplingCells);
172 } else if (_insertionType == NO_INSERTION) {
173 return new coupling::NoMomentumInsertion<LinkedCell, dim>(mdSolverInterface);
174 } else if (_insertionType == VELOCITY_GRADIENT_RELAXATION_TOPONLY) {
175 return new coupling::VelocityGradientRelaxationTopOnly<LinkedCell, dim>(_velocityRelaxationFactor, mdSolverInterface, couplingCells);
176 } else if (_insertionType == NIE_VELOCITY_IMPOSITION) {
177 return new coupling::NieVelocityImposition<LinkedCell, dim>(mdSolverInterface, _outerOverlap, _innerOverlap, _impositionEnabled);
178 }
179 return NULL;
180 }
181
182protected:
183 MomentumInsertionConfiguration(MomentumInsertionType insertionType) : _insertionType(insertionType), _isValid(true) {}
184
185private:
186 MomentumInsertionType _insertionType;
187 double _velocityRelaxationFactor; // required by velocity relaxation schemes
188 unsigned int _innerOverlap; // innermost layer of overlap cells (required by
189 // nie velocity imposition)
190 unsigned int _outerOverlap; // outermost layer of overlap cells (required by
191 // nie velocity imposition)
192 tarch::la::Vector<2 * dim, bool> _impositionEnabled; // true in each component, if one of the 2*dim
193 // boundaries allows for velocity imposition (currently only used for nie)
194 bool _isValid;
195};
196
197#endif // _MOLECULARDYNAMICS_COUPLING_CONFIGURATIONS_MOMENTUMINSERTIONCONFIGURATION_H_
used to manipulate the momentum/velocity of the molecules contained in a coupling cell.
Definition AdditiveMomentumInsertion.h:30
used to manipulate the momentum/ velocity of the molecules contained in a coupling cell.
Definition MomentumInsertion.h:23
Velocity imposition scheme following the respective paper by Nie et al., J. Fluid....
Definition NieVelocityImposition.h:25
dummy class. Empty momentum insertion mechanism. Doesn't change anything.
Definition NoMomentumInsertion.h:21
Definition SetGivenVelocity4MomentumInsertion.h:25
carries out velocity relaxation (similar to the SetMomentumMapping procedure).
Definition VelocityGradientRelaxation.h:110
carries out velocity relaxation (similar to the SetMomentumMapping procedure).
Definition VelocityGradientRelaxation.h:37
momentum insertion configuration. friend class: NieTest
Definition MomentumInsertionConfiguration.h:31
virtual ~MomentumInsertionConfiguration()
Definition MomentumInsertionConfiguration.h:52
bool isValid() const
Definition MomentumInsertionConfiguration.h:141
void parseSubtag(tinyxml2::XMLElement *node)
Definition MomentumInsertionConfiguration.h:57
std::string getTag() const
Definition MomentumInsertionConfiguration.h:131
unsigned int getInnerOverlap() const
Definition MomentumInsertionConfiguration.h:151
MomentumInsertionConfiguration()
Definition MomentumInsertionConfiguration.h:49
coupling::MomentumInsertion< LinkedCell, dim > * interpreteConfiguration(coupling::interface::MDSolverInterface< LinkedCell, dim > *const mdSolverInterface, const coupling::datastructures::CouplingCellWithLinkedCells< LinkedCell, dim > *const couplingCells, unsigned int numberMDTimestepsPerCouplingCycle) const
Definition MomentumInsertionConfiguration.h:163
MomentumInsertionType
Definition MomentumInsertionConfiguration.h:39
@ VELOCITY_GRADIENT_RELAXATION_TOPONLY
Definition MomentumInsertionConfiguration.h:44
@ NIE_VELOCITY_IMPOSITION
Definition MomentumInsertionConfiguration.h:45
@ NO_INSERTION
Definition MomentumInsertionConfiguration.h:43
@ VELOCITY_GRADIENT_RELAXATION
Definition MomentumInsertionConfiguration.h:42
@ ADDITIVE_MOMENTUM_INSERTION
Definition MomentumInsertionConfiguration.h:40
@ DIRECT_VELOCITY_INSERTION
Definition MomentumInsertionConfiguration.h:41
const MomentumInsertionType & getMomentumInsertionType() const
Definition MomentumInsertionConfiguration.h:146
defines the cell type with cell-averaged quantities. Derived from the class coupling::datastructures:...
Definition CouplingCellWithLinkedCells.h:26
interface to the MD simulation
Definition MDSolverInterface.h:25
Definition Configuration.h:22
static void readStringMandatory(std::string &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:201
static void readIntMandatory(int &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:115
static void readDoubleMandatory(double &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:79
static void readBoolOptional(bool &storage, tinyxml2::XMLElement *node, std::string tag)
Definition ParseConfiguration.h:177
Definition Vector.h:25
Definition tinyxml2.h:1124
everything necessary for coupling operations, is defined in here
Definition AdditiveMomentumInsertion.h:15