Nektar++
Loading...
Searching...
No Matches
ModeIndexDataWarehouseDef.hpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: ModeIndexDataWarehouseDef.hpp
4//
5// For more information, please see: http://www.nektar.info
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description:
32//
33///////////////////////////////////////////////////////////////////////////////
34
35#pragma once
36
38
39#if defined(_MSC_VER)
40#undef max
41#undef min
42#endif
43
45{
46
47template <typename MemSpace>
49 const ModeIndexKey &modeIndexKey)
50{
52
53 const auto shapeType = modeIndexKey.m_shapeType;
54
55 switch (shapeType)
56 {
57 case Tri:
58 case NodalTri:
59 {
60 const auto mode = modeIndexKey.m_mode;
61 const auto nm0 = modeIndexKey.m_nm0;
62 const auto nm1 = modeIndexKey.m_nm1;
63 const auto nm01 = GetNumberOfCoefficients(shapeType, nm0, nm1);
64
65 auto index = MemoryRegion<value_type>(nm01);
66 auto ptr =
67 index.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
68 for (unsigned int p = 0, mode_pq = 0; p < nm0; p++)
69 {
70 for (unsigned int q = 0; q < nm1 - p; q++, mode_pq++)
71 {
72 if (mode == 0)
73 {
74 ptr[mode_pq] = p;
75 }
76 else if (mode == 1)
77 {
78 ptr[mode_pq] = q;
79 }
80 else
81 {
82 NEKERROR(ErrorUtil::efatal, "invalid data requested.");
83 }
84 }
85 }
86
87 return index;
88 }
89 break;
90 case Tet:
91 case NodalTet:
92 {
93 const auto mode = modeIndexKey.m_mode;
94 const auto nm0 = modeIndexKey.m_nm0;
95 const auto nm1 = modeIndexKey.m_nm1;
96 const auto nm2 = modeIndexKey.m_nm2;
97 const auto nmTot =
98 GetNumberOfCoefficients(shapeType, nm0, nm1, nm2);
99 const unsigned int nm01 = (2u * nm1 - nm0 + 1u) * nm0 / 2u;
100 if (mode == 0 || mode == 3)
101 {
102 auto index = MemoryRegion<value_type>(nm01);
103 auto ptr =
104 index.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
105 for (unsigned int p = 0, mode_pq = 0; p < nm0; p++)
106 {
107 for (unsigned int q = 0; q < nm1 - p; q++, mode_pq++)
108 {
109 if (mode == 0)
110 {
111 ptr[mode_pq] = p;
112 }
113 else if (mode == 3)
114 {
115 ptr[mode_pq] = q;
116 }
117 }
118 }
119
120 return index;
121 }
122 else if (mode == 1 || mode == 2)
123 {
124 auto index = MemoryRegion<value_type>(nmTot);
125 auto ptr =
126 index.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
127 for (unsigned int p = 0, mode_pq = 0, mode_pqr = 0; p < nm0;
128 p++)
129 {
130 for (unsigned int q = 0; q < nm1 - p; q++, mode_pq++)
131 {
132 for (unsigned int r = 0; r < nm2 - p - q;
133 r++, mode_pqr++)
134 {
135 if (mode == 1)
136 {
137 ptr[mode_pqr] = p;
138 }
139 else if (mode == 2)
140 {
141 ptr[mode_pqr] = q;
142 }
143 }
144 }
145 }
146
147 return index;
148 }
149 else
150 {
151 NEKERROR(ErrorUtil::efatal, "invalid data requested.");
152 return MemoryRegion<value_type>(0);
153 }
154 }
155 break;
156 case Prism:
157 case NodalPrism:
158 {
159 const auto mode = modeIndexKey.m_mode;
160 const auto nm0 = modeIndexKey.m_nm0;
161 const auto nm1 = modeIndexKey.m_nm1;
162 const auto nm2 = modeIndexKey.m_nm2;
163 const auto nmTot =
164 GetNumberOfCoefficients(shapeType, nm0, nm1, nm2);
165
166 auto index = MemoryRegion<value_type>(nmTot);
167 auto ptr =
168 index.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
169 for (unsigned int p = 0, mode_pqr = 0; p < nm0; p++)
170 {
171 for (unsigned int q = 0u; q < nm1; q++)
172 {
173 for (unsigned int r = 0u; r < nm2 - p; r++, mode_pqr++)
174 {
175 if (mode == 0)
176 {
177 ptr[mode_pqr] = p;
178 }
179 else if (mode == 1)
180 {
181 ptr[mode_pqr] = q;
182 }
183 else if (mode == 2)
184 {
185 ptr[mode_pqr] = r;
186 }
187 else
188 {
190 "invalid data requested.");
191 }
192 }
193 }
194 }
195
196 return index;
197 }
198 break;
199 case Pyr:
200 case NodalPyr:
201 {
202 const auto mode = modeIndexKey.m_mode;
203 const auto nm0 = modeIndexKey.m_nm0;
204 const auto nm1 = modeIndexKey.m_nm1;
205 const auto nm2 = modeIndexKey.m_nm2;
206 const auto nmTot =
207 GetNumberOfCoefficients(shapeType, nm0, nm1, nm2);
208
209 auto index = MemoryRegion<value_type>(nmTot);
210 auto ptr =
211 index.template GetPtr<NektarSpaces::HostSpace, WriteOnly>();
212 for (unsigned int p = 0, mode_pqr = 0; p < nm0; p++)
213 {
214 for (unsigned int q = 0u; q < nm1; q++)
215 {
216 for (unsigned int r = 0; r < nm2 - std::max(p, q);
217 r++, mode_pqr++)
218 {
219 if (mode == 0)
220 {
221 ptr[mode_pqr] = p;
222 }
223 else if (mode == 1)
224 {
225 ptr[mode_pqr] = q;
226 }
227 else
228 {
230 "invalid data requested.");
231 }
232 }
233 }
234 }
235
236 return index;
237 }
238 break;
239 default:
240 NEKERROR(ErrorUtil::efatal, "invalid data requested.");
241 return MemoryRegion<value_type>(0);
242 break;
243 }
244}
245
246} // namespace Nektar::LibUtilities
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
A MemoryRegion represents a memory region.
MemoryRegion< value_type > Create(const ModeIndexKey &modeIndexKey)
constexpr int GetNumberOfCoefficients(ShapeType shape, std::vector< unsigned int > &modes, int offset=0)