Debian Codegraph @

packages/panzer/disc-fe/test/la_factory/UnitTest_GlobalIndexer.hpp

raw
1 // @HEADER
2 // *****************************************************************************
3 // Panzer: A partial differential equation assembly
4 // engine for strongly coupled complex multiphysics systems
5 //
6 // Copyright 2011 NTESS and the Panzer contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10
11 #ifndef __UnitTest_GlobalIndexer_hpp__
12 #define __UnitTest_GlobalIndexer_hpp__
13
14 #include <vector>
15 #include <string>
16
17 #include "Teuchos_RCP.hpp"
18
19 #include "Panzer_GlobalIndexer.hpp"
20
21 #ifdef HAVE_MPI
22 #include "Teuchos_DefaultMpiComm.hpp"
23 #include <mpi.h>
24 #else
25 #include "Teuchos_DefaultSerialComm.hpp"
26 #endif
27
28 #include "Kokkos_DynRankView.hpp"
29
30 namespace panzer {
31 namespace unit_test {
32
33 /** This a dummy global indexer used for testing. It has two fields
34 * "U" and "T"
35 * There is one element block called "block_0" with two elements. Each element
36 * resides on a different processor.
37 */
38 class GlobalIndexer : public virtual panzer::GlobalIndexer {
39 public:
40 GlobalIndexer(int rank,int procCount);
41
42 ~GlobalIndexer() {}
43
44 /** \brief Get the number used for access to this
45 * field
46 *
47 * Get the number used for access to this
48 * field. This is used as the input parameter
49 * to the other functions that provide access
50 * to the global unknowns.
51 *
52 * \param[in] str Human readable name of the field
53 *
54 * \returns A unique integer associated with the
55 * field if the field exisits. Otherwise
56 * a -1 is returned.
57 */
58 virtual int getFieldNum(const std::string & str) const;
59
60 virtual int getNumFields() const { return 2; }
61 virtual void getFieldOrder(std::vector<std::string> & order) const
62 { order.push_back("U"); order.push_back("T"); }
63
64 virtual const std::string & getFieldString(int field) const;
65
66 virtual Teuchos::RCP<Teuchos::Comm<int> > getComm() const
67 {
68 #ifdef HAVE_MPI
69 return Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(MPI_COMM_WORLD)));
70 #else
71 return Teuchos::rcp(Teuchos::SerialComm<int>());
72 #endif
73 }
74
75 /** What are the blockIds included in this connection manager?
76 */
77 virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const;
78
79 /** Is the specified field in the element block?
80 */
81 virtual bool fieldInBlock(const std::string & field, const std::string & block) const;
82
83 /** Get the local element IDs for a paricular element
84 * block.
85 *
86 * \param[in] blockId Block ID
87 *
88 * \returns Vector of local element IDs.
89 */
90 virtual const std::vector<panzer::LocalOrdinal> & getElementBlock(const std::string & blockId) const;
91
92 /** Get field numbers associated with a particular element block.
93 */
94 virtual const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
95
96 /** \brief Get the global IDs for a particular element. This function
97 * overwrites the <code>gids</code> variable.
98 */
99 virtual void getElementGIDs(panzer::LocalOrdinal localElmtId,std::vector<panzer::GlobalOrdinal> & gids,const std::string & blockId="") const;
100
101 virtual void getElementOrientation(panzer::LocalOrdinal /* localElmtId */, std::vector<double>& /* gidsOrientation */) const
102 { TEUCHOS_ASSERT(false); }
103
104 /** \brief Use the field pattern so that you can find a particular
105 * field in the GIDs array.
106 */
107 virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const;
108
109 /** \brief Use the field pattern so that you can find a particular
110 * field in the GIDs array. This version lets you specify the sub
111 * cell you are interested in and gets the closure. Meaning all the
112 * IDs of equal or lesser sub cell dimension that are contained within
113 * the specified sub cell. For instance for an edge, this function would
114 * return offsets for the edge and the nodes on that edge.
115 *
116 * \param[in] blockId
117 * \param[in] fieldNum
118 * \param[in] subcellDim
119 * \param[in] subcellId
120 */
121 // virtual const std::vector<int> &
122 virtual const std::pair<std::vector<int>,std::vector<int> > &
123 getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum,
124 int subcellDim,int subcellId) const;
125
126 /**
127 * \brief Get the set of indices owned by this processor.
128 *
129 * \param[out] indices A `vector` that will be filled with the indices
130 * owned by this processor.
131 *
132 * \throws `std::logic_error` If the processor rank is neither 0 nor 1.
133 */
134 virtual void getOwnedIndices(std::vector<panzer::GlobalOrdinal> & indices) const;
135
136 /**
137 * \brief Get the set of indices ghosted for this processor.
138 *
139 * \param[out] indices A `vector` that will be filled with the indices
140 * ghosted for this processor.
141 *
142 * \throws `std::logic_error` If the processor rank is neither 0 nor 1.
143 */
144 virtual void getGhostedIndices(std::vector<panzer::GlobalOrdinal> & indices) const;
145
146 /**
147 * \brief Get the set of owned and ghosted indices for this processor.
148 *
149 * \param[out] indices A `vector` that will be filled with the owned and
150 * ghosted indices for this processor.
151 *
152 * \throws `std::logic_error` If the processor rank is neither 0 nor 1.
153 */
154 virtual void getOwnedAndGhostedIndices(std::vector<panzer::GlobalOrdinal> & indices) const;
155
156 // Epetra specific functions. Will be deprecated.
157 void getElementGIDsAsInt(panzer::LocalOrdinal localElmtId,std::vector<int> & gids,const std::string & blockId="") const;
158 void getOwnedIndicesAsInt(std::vector<int> & indices) const;
159 void getGhostedIndicesAsInt(std::vector<int> & indices) const;
160 void getOwnedAndGhostedIndicesAsInt(std::vector<int> & indices) const;
161
162 /**
163 * \brief Get the number of indices owned by this processor.
164 *
165 * \returns The number of indices owned by this processor.
166 */
167 virtual int
168 getNumOwned() const;
169
170 /**
171 * \brief Get the number of indices ghosted for this processor.
172 *
173 * \returns The number of indices ghosted for this processor.
174 */
175 virtual int
176 getNumGhosted() const;
177
178 /**
179 * \brief Get the number of owned and ghosted indices for this processor.
180 *
181 * \returns The number of owned and ghosted indices for this processor.
182 */
183 virtual int
184 getNumOwnedAndGhosted() const;
185
186 /** Get a yes/no on ownership for each index in a vector
187 */
188 virtual void ownedIndices(const std::vector<panzer::GlobalOrdinal> & indices,std::vector<bool> & isOwned) const;
189
190 void getCoordinates(panzer::LocalOrdinal localElementId,Kokkos::DynRankView<double,PHX::Device> & points);
191
192 int getElementBlockGIDCount(const std::string &) const;
193 int getElementBlockGIDCount(const std::size_t &) const;
194
195 /** Not needed, so return null.
196 */
197 virtual Teuchos::RCP<const panzer::ConnManager> getConnManager() const
198 { return Teuchos::null; }
199
200 private:
201 int procRank_;
202 mutable Teuchos::RCP<std::vector<panzer::LocalOrdinal> > elements_; // local element IDs
203 mutable Teuchos::RCP<std::vector<int> > field0Offset_; // local element IDs
204 mutable Teuchos::RCP<std::vector<int> > field1Offset_; // local element IDs
205 };
206
207 /** This a dummy global indexer used for testing. It has two fields
208 * "U" and "T"
209 * There is only a single element degree of freedom.
210 * There is one element block called "block_0" with two elements. Each element
211 * resides on a different processor.
212 */
213 class GlobalIndexer_Element : public virtual panzer::GlobalIndexer {
214 public:
215 GlobalIndexer_Element(int rank,int procCount);
216
217 ~GlobalIndexer_Element() {}
218
219 /** \brief Get the number used for access to this
220 * field
221 *
222 * Get the number used for access to this
223 * field. This is used as the input parameter
224 * to the other functions that provide access
225 * to the global unknowns.
226 *
227 * \param[in] str Human readable name of the field
228 *
229 * \returns A unique integer associated with the
230 * field if the field exisits. Otherwise
231 * a -1 is returned.
232 */
233 virtual int getFieldNum(const std::string & str) const;
234
235 virtual int getNumFields() const { return 2; }
236 virtual void getFieldOrder(std::vector<std::string> & order) const
237 { order.push_back("U"); order.push_back("T"); }
238
239 virtual const std::string & getFieldString(int field) const;
240
241 virtual Teuchos::RCP<Teuchos::Comm<int> > getComm() const
242 {
243 #ifdef HAVE_MPI
244 return Teuchos::rcp(new Teuchos::MpiComm<int>(Teuchos::opaqueWrapper(MPI_COMM_WORLD)));
245 #else
246 return Teuchos::rcp(Teuchos::SerialComm<int>());
247 #endif
248 }
249
250 /** What are the blockIds included in this connection manager?
251 */
252 virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const;
253
254 /** Is the specified field in the element block?
255 */
256 virtual bool fieldInBlock(const std::string & field, const std::string & block) const;
257
258 /** Get the local element IDs for a paricular element
259 * block.
260 *
261 * \param[in] blockId Block ID
262 *
263 * \returns Vector of local element IDs.
264 */
265 virtual const std::vector<panzer::LocalOrdinal> & getElementBlock(const std::string & blockId) const;
266
267 /** Get field numbers associated with a particular element block.
268 */
269 virtual const std::vector<int> & getBlockFieldNumbers(const std::string & blockId) const;
270
271 /** \brief Get the global IDs for a particular element. This function
272 * overwrites the <code>gids</code> variable.
273 */
274 virtual void getElementGIDs(panzer::LocalOrdinal localElmtId,std::vector<panzer::GlobalOrdinal> & gids,const std::string & blockId="") const;
275
276 virtual void getElementOrientation(panzer::LocalOrdinal /* localElmtId */, std::vector<double>& /* gidsOrientation */) const
277 { TEUCHOS_ASSERT(false); }
278
279 /** \brief Use the field pattern so that you can find a particular
280 * field in the GIDs array.
281 */
282 virtual const std::vector<int> & getGIDFieldOffsets(const std::string & blockId,int fieldNum) const;
283
284 /** \brief Use the field pattern so that you can find a particular
285 * field in the GIDs array. This version lets you specify the sub
286 * cell you are interested in and gets the closure. Meaning all the
287 * IDs of equal or lesser sub cell dimension that are contained within
288 * the specified sub cell. For instance for an edge, this function would
289 * return offsets for the edge and the nodes on that edge.
290 *
291 * \param[in] blockId
292 * \param[in] fieldNum
293 * \param[in] subcellDim
294 * \param[in] subcellId
295 */
296 // virtual const std::vector<int> &
297 virtual const std::pair<std::vector<int>,std::vector<int> > &
298 getGIDFieldOffsets_closure(const std::string & blockId, int fieldNum,
299 int subcellDim,int subcellId) const;
300
301 /** Get set of indices owned by this processor
302 */
303 virtual void getOwnedIndices(std::vector<panzer::GlobalOrdinal> & indices) const;
304
305 /** Get set of indices owned and ghosted by this processor.
306 * This can be thought of as the ``ghosted'' indices.
307 */
308 virtual void getOwnedAndGhostedIndices(std::vector<panzer::GlobalOrdinal> & indices) const;
309
310 /** Get a yes/no on ownership for each index in a vector
311 */
312 virtual void ownedIndices(const std::vector<panzer::GlobalOrdinal> & indices,std::vector<bool> & isOwned) const;
313
314 void getCoordinates(panzer::LocalOrdinal localElementId,Kokkos::DynRankView<double,PHX::Device> & points);
315
316 int getElementBlockGIDCount(const std::string &) const;
317 int getElementBlockGIDCount(const std::size_t &) const;
318
319 /** Not needed, so return null.
320 */
321 virtual Teuchos::RCP<const panzer::ConnManager> getConnManager() const
322 { return Teuchos::null; }
323
324 private:
325 int procRank_;
326 mutable Teuchos::RCP<std::vector<panzer::LocalOrdinal> > elements_; // local element IDs
327 mutable Teuchos::RCP<std::vector<int> > field0Offset_; // local element IDs
328 mutable Teuchos::RCP<std::vector<int> > field1Offset_; // local element IDs
329 };
330
331 class BlockGlobalIndexer : public virtual panzer::GlobalIndexer {
332 public:
333 BlockGlobalIndexer(int blocks,int rank,int procCount);
334
335 ~BlockGlobalIndexer() {}
336
337 /** \brief Get the number used for access to this
338 * field
339 *
340 * Get the number used for access to this
341 * field. This is used as the input parameter
342 * to the other functions that provide access
343 * to the global unknowns.
344 *
345 * \param[in] str Human readable name of the field
346 *
347 * \returns A unique integer associated with the
348 * field if the field exisits. Otherwise
349 * a -1 is returned.
350 */
351 virtual int getFieldNum(const std::string& /* str */) const
352 { TEUCHOS_ASSERT(false); return -1; }
353
354 virtual int getNumFields() const { return 2; }
355 virtual void getFieldOrder(std::vector<std::string> & order) const
356 { order.push_back("U"); order.push_back("T"); }
357
358 virtual const std::string& getFieldString(int /* field */) const
359 { TEUCHOS_ASSERT(false); static std::string empty = "EMPTY"; return empty; }
360
361 virtual Teuchos::RCP<Teuchos::Comm<int> > getComm() const
362 { TEUCHOS_ASSERT(false); return Teuchos::null; }
363
364 /** What are the blockIds included in this connection manager?
365 */
366 virtual void getElementBlockIds(std::vector<std::string> & elementBlockIds) const;
367
368 /** Is the specified field in the element block?
369 */
370 virtual bool fieldInBlock(const std::string& /* field */, const std::string& /* block */) const
371 { TEUCHOS_ASSERT(false); return false; }
372
373 /** Get the local element IDs for a paricular element
374 * block.
375 *
376 * \param[in] blockId Block ID
377 *
378 * \returns Vector of local element IDs.
379 */
380 virtual const std::vector<panzer::LocalOrdinal> & getElementBlock(const std::string & blockId) const;
381
382 /** Get field numbers associated with a particular element block.
383 */
384 virtual const std::vector<int>& getBlockFieldNumbers(const std::string& /* blockId */) const
385 { static std::vector<int> data; TEUCHOS_ASSERT(false); return data; }
386
387 /** \brief Get the global IDs for a particular element. This function
388 * overwrites the <code>gids</code> variable.
389 */
390 virtual void getElementGIDs(panzer::LocalOrdinal /* localElmtId */, std::vector<std::pair<int, panzer::GlobalOrdinal>>& /* gids */, const std::string& /* blockId="" */) const
391 { TEUCHOS_ASSERT(false); }
392
393 virtual void getElementOrientation(panzer::LocalOrdinal /* localElmtId */, std::vector<double>& /* gidsOrientation */) const
394 { TEUCHOS_ASSERT(false); }
395
396 /** \brief Use the field pattern so that you can find a particular
397 * field in the GIDs array.
398 */
399 virtual const std::vector<int>& getGIDFieldOffsets(const std::string& /* blockId */, int /* fieldNum */) const
400 { TEUCHOS_ASSERT(false); }
401
402 /** \brief Use the field pattern so that you can find a particular
403 * field in the GIDs array. This version lets you specify the sub
404 * cell you are interested in and gets the closure. Meaning all the
405 * IDs of equal or lesser sub cell dimension that are contained within
406 * the specified sub cell. For instance for an edge, this function would
407 * return offsets for the edge and the nodes on that edge.
408 *
409 * \param[in] blockId
410 * \param[in] fieldNum
411 * \param[in] subcellDim
412 * \param[in] subcellId
413 */
414 // virtual const std::vector<int> &
415 virtual const std::pair<std::vector<int>,std::vector<int> > &
416 getGIDFieldOffsets_closure(const std::string& /* blockId */, int /* fieldNum */,
417 int /* subcellDim */, int /* subcellId */) const
418 { static std::pair<std::vector<int>,std::vector<int> > p; TEUCHOS_ASSERT(false); return p; }
419
420 /** Get set of indices owned by this processor
421 */
422 virtual void getOwnedIndices(std::vector<std::pair<int, panzer::GlobalOrdinal>>& /* indices */) const
423 { TEUCHOS_ASSERT(false); }
424
425 /** Get set of indices owned and ghosted by this processor.
426 * This can be thought of as the ``ghosted'' indices.
427 */
428 virtual void getOwnedAndGhostedIndices(std::vector<std::pair<int, panzer::GlobalOrdinal>>& /* indices */) const
429 { TEUCHOS_ASSERT(false); }
430
431 /** Get a yes/no on ownership for each index in a vector
432 */
433 virtual void ownedIndices(const std::vector<std::pair<int, panzer::GlobalOrdinal>>& /* indices */, std::vector<bool>& /* isOwned */) const
434 { TEUCHOS_ASSERT(false); }
435
436 void getCoordinates(panzer::LocalOrdinal /* localElementId */, Kokkos::DynRankView<double, PHX::Device>& /* points */)
437 { TEUCHOS_ASSERT(false); }
438
439 int getElementBlockGIDCount(const std::string &) const { TEUCHOS_ASSERT(false); }
440 int getElementBlockGIDCount(const std::size_t &) const { TEUCHOS_ASSERT(false); }
441
442 /** Not needed, so return null.
443 */
444 virtual Teuchos::RCP<const panzer::ConnManager> getConnManager() const
445 { return Teuchos::null; }
446
447 private:
448 int procRank_;
449 mutable Teuchos::RCP<std::vector<panzer::LocalOrdinal> > elements_; // local element IDs
450 mutable Teuchos::RCP<std::vector<int> > field0Offset_; // local element IDs
451 mutable Teuchos::RCP<std::vector<int> > field1Offset_; // local element IDs
452 };
453
454 } // end unit test
455 } // end panzer
456
457 #endif