Line data Source code
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_COUPLINGMDDEFINITIONS_H_
6 : #define _MOLECULARDYNAMICS_COUPLING_COUPLINGMDDEFINITIONS_H_
7 :
8 : #define COUPLING_MD_NO 0
9 : #define COUPLING_MD_YES 1
10 :
11 : #if defined(MDCoupledDebug)
12 : #define COUPLING_MD_DEBUG COUPLING_MD_YES
13 : #else
14 : #define COUPLING_MD_DEBUG COUPLING_MD_NO
15 : #endif
16 :
17 : #if defined(MDCoupledError)
18 : #define COUPLING_MD_ERROR COUPLING_MD_YES
19 : #else
20 : #define COUPLING_MD_ERROR COUPLING_MD_NO
21 : #endif
22 :
23 : #if defined(MDCoupledParallel)
24 : #define COUPLING_MD_PARALLEL COUPLING_MD_YES
25 : #else
26 : #define COUPLING_MD_PARALLEL COUPLING_MD_NO
27 : #endif
28 : // message tags for MPI parallelisation. For each CouplingCellService, we add
29 : // the ID of the cell service to the tags from below to yield a unique tag for
30 : // each operation. this currently supports a maximum of <10M instances of
31 : // CouplingCellService.
32 : #define TAG_FROM_MD2MACRO 100000
33 : #define TAG_FROM_MACRO2MD 500000
34 :
35 : #define IDXS coupling::indexing::IndexingService<dim>::getInstance()
36 :
37 : #include "tarch/la/Vector.h"
38 : #include "tarch/utils/OstreamOperators.h"
39 : #include <map>
40 : #include <set>
41 : #include <vector>
42 :
43 : namespace coupling {
44 : /** This is an enum for the macroscopic solver ID
45 : * @todo I have no idea what this is @someone */
46 : enum MacroscopicSolverID {
47 : PEANO_LATTICEBOLTZMANN_ID = 0, ///< test1
48 : TEST_LOCAL_MACROSCOPIC_SOLVER_ID = 1 ///< test2
49 : };
50 :
51 : // --------------------------- HELPER FUNCTIONS
52 : // ----------------------------------------
53 :
54 : /** @brief initialises the range for looping over Cartesian grid for general
55 : * case
56 : * @param vec the input vector to be generalised
57 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
58 : * or 3
59 : * @returns the given vector as 3d version */
60 36 : template <unsigned int dim> tarch::la::Vector<3, unsigned int> initRange(tarch::la::Vector<dim, unsigned int> vec) {
61 36 : tarch::la::Vector<3, unsigned int> range(1);
62 140 : for (unsigned int d = 0; d < dim; d++) {
63 104 : range[d] = vec[d];
64 : }
65 36 : return range;
66 : }
67 :
68 : /** @brief reduces three-dimensional vector to vector of size dim (assumes that
69 : * dim<= 3).
70 : * @param vec the input which will be reduced
71 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
72 : * or 3
73 : * @return the given 3d vector as a vector for the simulation dimension (dim)
74 : */
75 69132 : template <unsigned int dim> tarch::la::Vector<dim, unsigned int> initDimVector(tarch::la::Vector<3, unsigned int> vec) {
76 69132 : tarch::la::Vector<dim, unsigned int> smallVec;
77 276524 : for (unsigned int d = 0; d < dim; d++) {
78 207392 : smallVec[d] = vec[d];
79 : }
80 69132 : return smallVec;
81 : }
82 :
83 : /** @briefcomputes a vectorwise division factor for the conversion of linearised
84 : * to vector indices
85 : * @param numberCells the number of cells per direction in the spacial domain
86 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
87 : * or 3
88 : * @returns the division factor for the simulation */
89 796 : template <unsigned int dim> tarch::la::Vector<dim, unsigned int> initDivisionFactor(tarch::la::Vector<dim, unsigned int> numberCells) {
90 796 : tarch::la::Vector<dim, unsigned int> divFactor(1);
91 2372 : for (unsigned int d = 1; d < dim; d++) {
92 1576 : divFactor[d] = divFactor[d - 1] * (numberCells[d - 1]);
93 : }
94 796 : return divFactor;
95 : }
96 :
97 : /** This method is supposed to be only called with member divisionFactor
98 : * variables, cf. initDivisionFactor()-method.
99 : * @brief converts linearised cell index to a vector cell index using
100 : * predefined division factors.
101 : * @param cellIndex the index of the cell which shall be transformed
102 : * @param divisionFactor the division factor for the corresponding spacial
103 : * setup of the domain
104 : * @tparam dim refers to the spacial dimension of the simulation, can be 1, 2,
105 : * or 3
106 : * @returns the dimensionized index for a given cell */
107 : template <unsigned int dim>
108 1100 : tarch::la::Vector<dim, unsigned int> getVectorCellIndex(unsigned int cellIndex, const tarch::la::Vector<dim, unsigned int>& divisionFactor) {
109 1100 : tarch::la::Vector<dim, unsigned int> myVector(0);
110 : unsigned int help = cellIndex;
111 3244 : for (int d = dim - 1; d > 0; d--) {
112 2144 : myVector[d] = help / divisionFactor[d];
113 2144 : help = help - myVector[d] * divisionFactor[d];
114 : }
115 1100 : myVector[0] = help;
116 :
117 1100 : return myVector;
118 : }
119 :
120 : } // namespace coupling
121 : #endif // _MOLECULARDYNAMICS_COUPLING_COUPLINGMDDEFINITIONS_H_
|