Line data Source code
1 : /*
2 : * Copyright (c) 2012-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Andreas Vogel
4 : *
5 : * This file is part of UG4.
6 : *
7 : * UG4 is free software: you can redistribute it and/or modify it under the
8 : * terms of the GNU Lesser General Public License version 3 (as published by the
9 : * Free Software Foundation) with the following additional attribution
10 : * requirements (according to LGPL/GPL v3 §7):
11 : *
12 : * (1) The following notice must be displayed in the Appropriate Legal Notices
13 : * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 : *
15 : * (2) The following notice must be displayed at a prominent place in the
16 : * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 : *
18 : * (3) The following bibliography is recommended for citation and must be
19 : * preserved in all covered files:
20 : * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 : * parallel geometric multigrid solver on hierarchically distributed grids.
22 : * Computing and visualization in science 16, 4 (2013), 151-164"
23 : * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 : * flexible software system for simulating pde based models on high performance
25 : * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 : *
27 : * This program is distributed in the hope that it will be useful,
28 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 : * GNU Lesser General Public License for more details.
31 : */
32 :
33 : #ifndef __H__UG_BRIDGE__SUFFIX_TAG__
34 : #define __H__UG_BRIDGE__SUFFIX_TAG__
35 :
36 :
37 : namespace ug{
38 : namespace bridge{
39 :
40 : /// \addtogroup bridge
41 : /// \{
42 :
43 : ////////////////////////////////////////////////////////////////////////////////
44 : // Dimension - Suffix and Tag
45 : ////////////////////////////////////////////////////////////////////////////////
46 :
47 : /// returns the dim-suffix for a domain (e.g. "3d")
48 : template <int dim>
49 486 : std::string GetDimensionSuffix()
50 : {
51 : // the dimension suffix
52 486 : std::stringstream ss; ss << dim << "d";
53 486 : return ss.str();
54 486 : }
55 :
56 : /// returns the dim-tag for a domain (e.g. "dim=3d")
57 : template <int dim>
58 245 : std::string GetDimensionTag()
59 : {
60 735 : return std::string("dim=").append(GetDimensionSuffix<dim>()).append(";");
61 : }
62 :
63 : /// returns dim tag at runtime (e.g. "dim=3d")
64 0 : inline std::string GetDimensionTag(int dim)
65 : {
66 : // the dimension tag
67 0 : std::stringstream ss; ss << "dim=" << dim << "d;";
68 0 : return ss.str();
69 0 : }
70 :
71 : ////////////////////////////////////////////////////////////////////////////////
72 : // Domain - Suffix and Tag
73 : ////////////////////////////////////////////////////////////////////////////////
74 :
75 : /// returns the dim-suffix for a domain (e.g. "3d")
76 : template <typename TDomain>
77 46 : std::string GetDomainSuffix(){return GetDimensionSuffix<TDomain::dim>();}
78 :
79 : /// returns the dim-tag for a domain (e.g. "dim=3d")
80 : template <typename TDomain>
81 46 : std::string GetDomainTag() {return GetDimensionTag<TDomain::dim>();}
82 :
83 : ////////////////////////////////////////////////////////////////////////////////
84 : // Algebra - Suffix and Tag
85 : ////////////////////////////////////////////////////////////////////////////////
86 :
87 : /// returns the algebra-suffix (e.g. "CPU3", "CPUFlex")
88 : template<typename TAlgebraTypeType>
89 192 : inline std::string GetAlgebraSuffix(const TAlgebraTypeType& algType)
90 : {
91 : // the algebra suffix
92 192 : std::stringstream ss;
93 :
94 : // add type
95 192 : if(algType.type() == TAlgebraTypeType::CPU) ss << "CPU";
96 0 : else if(algType.type() == TAlgebraTypeType::GPU) ss << "GPU";
97 0 : else UG_THROW("Unknown algebra type.");
98 :
99 : // add blocktype
100 192 : if(algType.blocksize() == TAlgebraTypeType::VariableBlockSize) ss << "Variable";
101 192 : else ss << algType.blocksize();
102 :
103 192 : return ss.str();
104 192 : }
105 :
106 : /// returns the algebra-suffix (e.g. "CPU3", "CPUFlex")
107 : template <typename TAlgebra>
108 192 : std::string GetAlgebraSuffix()
109 : {
110 192 : return GetAlgebraSuffix(TAlgebra::get_type());
111 : }
112 :
113 : /// returns the algebra-suffix (e.g. "alg=CPU3", "alg=CPUVariable")
114 : template<typename TAlgebraTypeType>
115 192 : inline std::string GetAlgebraTag(const TAlgebraTypeType& algType)
116 : {
117 : // the algebra suffix
118 192 : std::stringstream ss; ss << "alg=";
119 :
120 : // add type
121 192 : if(algType.type() == TAlgebraTypeType::CPU) ss << "CPU";
122 0 : else if(algType.type() == TAlgebraTypeType::GPU) ss << "GPU";
123 0 : else UG_THROW("Unknown algebra type.");
124 :
125 : // add blocktype
126 192 : if(algType.blocksize() == TAlgebraTypeType::VariableBlockSize) ss << "Variable;";
127 192 : else ss << algType.blocksize() << ";";
128 :
129 192 : return ss.str();
130 192 : }
131 :
132 :
133 : /// returns the algebra-suffix (e.g. "alg=CPU3", "alg=CPUVariable")
134 : template <typename TAlgebra>
135 192 : std::string GetAlgebraTag()
136 : {
137 192 : return GetAlgebraTag(TAlgebra::get_type());
138 : }
139 :
140 : ////////////////////////////////////////////////////////////////////////////////
141 : // Dimension + Algebra - Suffix and Tag
142 : ////////////////////////////////////////////////////////////////////////////////
143 :
144 : /// returns the algebra-dim-suffix for a domain (e.g. "3dCPU1")
145 : template <int dim, typename TAlgebra>
146 126 : std::string GetDimensionAlgebraSuffix()
147 : {
148 126 : std::string dimAlgSuffix = GetDimensionSuffix<dim>();
149 126 : dimAlgSuffix.append(GetAlgebraSuffix<TAlgebra>());
150 126 : return dimAlgSuffix;
151 : }
152 :
153 : /// returns the dim-tag for a domain (e.g. "dim=3d;alg=CPU1;")
154 : template <int dim, typename TAlgebra>
155 126 : std::string GetDimensionAlgebraTag()
156 : {
157 126 : std::string dimAlgTag = GetDimensionTag<dim>();
158 126 : dimAlgTag.append(GetAlgebraTag<TAlgebra>());
159 126 : return dimAlgTag;
160 : }
161 : /// returns dim tag at runtime (e.g. "dim=3d;alg=CPU1;")
162 : template<typename TAlgebraTypeType>
163 : inline std::string GetDimensionAlgebraTag(int dim, const TAlgebraTypeType& algType)
164 : {
165 : std::string dimAlgTag = GetDimensionTag(dim);
166 : dimAlgTag.append(GetAlgebraTag(algType));
167 : return dimAlgTag;
168 : }
169 :
170 : ////////////////////////////////////////////////////////////////////////////////
171 : // Domain + Algebra - Suffix and Tag
172 : ////////////////////////////////////////////////////////////////////////////////
173 :
174 : /// returns the dim-suffix for a domain (e.g. "3dCPU1")
175 : template <typename TDomain, typename TAlgebra>
176 126 : std::string GetDomainAlgebraSuffix(){return GetDimensionAlgebraSuffix<TDomain::dim, TAlgebra>();}
177 :
178 : /// returns the dim-tag for a domain (e.g. "dim=3d;alg=CPU1;")
179 : template <typename TDomain, typename TAlgebra>
180 126 : std::string GetDomainAlgebraTag(){return GetDimensionAlgebraTag<TDomain::dim, TAlgebra>();}
181 :
182 : // end group bridge
183 : /// \}
184 :
185 : }// end bridge
186 : }// end ug
187 :
188 : #endif /* __H__UG_BRIDGE__SUFFIX_TAG__ */
|