GemaCoreLib
The GeMA Core library
Loading...
Searching...
No Matches
gmMeshUtils.h
1/************************************************************************
2**
3** Copyright (C) 2014 by Carlos Augusto Teixera Mendes
4** All rights reserved.
5**
6** This file is part of the "GeMA" software. It's use should respect
7** the terms in the license agreement that can be found together
8** with this source code.
9** It is provided AS IS, with NO WARRANTY OF ANY KIND,
10** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
11** A PARTICULAR PURPOSE.
12**
13************************************************************************/
14
24#ifndef _GEMA_MESH_UTILS_H_
25#define _GEMA_MESH_UTILS_H_
26
27#include "gmPCR.h"
28#include "gmCellMesh.h"
29
30#include <assert.h>
31
100namespace GmMeshUtils
101{
111
116 inline int geomNodeToModel(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
117 {
118 Q_UNUSED(semantic);
119 return pcr->localOrderToOriginalGeomNode(nodeId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
120 }
121
128 inline int nodeToModel(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
129 {
130 Q_UNUSED(semantic);
131 return pcr->localOrderToOriginalNode(nodeId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
132 }
133
140 inline int nodeToModel_Ghs_Gn(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
141 {
142 Q_UNUSED(semantic);
143 if(GmMesh::isGhostNode(nodeId))
145 else
146 return pcr->localOrderToOriginalGeomNode(nodeId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
147 }
148
155 inline int nodeToModel_Gl_Gn(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
156 {
157 Q_UNUSED(semantic);
158 if(nodeId >= pcr->mesh()->numNodes())
159 return -(pcr->localOrderToOriginalGhostNodeHighClear(nodeId - pcr->mesh()->numNodes()) + 1);
160 else
161 return pcr->localOrderToOriginalGeomNode(nodeId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
162 }
163
169 inline int nodeToModel_Ghs_Ghs(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
170 {
171 Q_UNUSED(semantic);
172 return pcr->localOrderToOriginalNode(nodeId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
173 }
174
179 inline int cellToModel(int cellId, const GmPCR* pcr, TranslationSemantics semantic)
180 {
181 Q_UNUSED(semantic);
182 return pcr->localOrderToOriginalCell(cellId) + 1; // If unknow, returned -1 value will be converted to 0, as expected!!
183 }
184
186 inline int cellToModel(const GmCell* c, TranslationSemantics semantic)
187 {
188 Q_UNUSED(semantic);
189 return cellToModel(c->cellId(), c->mesh()->pcrObject(), semantic);
190 }
191
201 inline int checkedNodeFromModel(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
202 {
203 Q_UNUSED(semantic);
204 if(nodeId >= 0) // Common node or linear ghost node. Using >= ensures that a 0 (invalid) value will be flagged correctly
205 {
206 nodeId--; // -1 to adjust from 1-based to 0-based
207 if(nodeId < 0 || nodeId >= pcr->mesh()->totalNumGlobalNodes())
208 return -2;
209 return pcr->originalToLocalOrderNode(nodeId); // Returns -1 if out of the partition
210 }
211 else // Ghost node represented with the high bit set (and so, a negative number)
212 {
213 nodeId = GmMesh::clearGhostFlag(nodeId) - 1;
214 if(nodeId >= pcr->mesh()->numGlobalGhostNodes())
215 return -2;
216 return GmMesh::setGhostFlag(pcr->originalToLocalOrderGhostNodeHighClear(nodeId)); // Returns -1 if out of the partition
217 }
218 }
219
225 inline int checkedGeomNodeFromModel(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
226 {
227 Q_UNUSED(semantic);
228 nodeId--; // -1 to adjust from 1-based to 0-based
229 if(nodeId < 0 || nodeId >= pcr->mesh()->numGlobalNodes())
230 return -2;
231 return pcr->originalToLocalOrderGeomNode(nodeId); // Returns -1 if out of the partition
232 }
233
234 // The SR version for checkedGeomNodeFromModel(). See comments on the namespace definition
235 inline int checkedGeomNodeFromModelSR(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
236 {
237 Q_UNUSED(semantic);
238 nodeId--; // -1 to adjust from 1-based to 0-based
239 if(nodeId < 0 || nodeId >= pcr->mesh()->numGlobalNodes())
240 return -2;
241 return pcr->originalToLocalOrderGeomNodeSR(nodeId); // Returns -1 if out of the partition
242 }
243
252 inline int checkedNodeFromModel_Gn_Ghs(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
253 {
254 Q_UNUSED(semantic);
255 if(nodeId >= 0) // Common node. Using >= ensures that a 0 (invalid) value will be flagged correctly
256 return checkedGeomNodeFromModel(nodeId, pcr, semantic);
257 else // Ghost node represented by a negative number
258 {
259 nodeId = (-nodeId) - 1;
260 if(nodeId >= pcr->mesh()->numGlobalGhostNodes())
261 return -2;
262 return GmMesh::setGhostFlag(pcr->originalToLocalOrderGhostNodeHighClear(nodeId)); // Returns -1 if out of the partition
263 }
264 }
265
266 // The SR version for checkedNodeFromModel_Gn_Ghs(). See comments on the namespace definition
267 inline int checkedNodeFromModel_Gn_GhsSR(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
268 {
269 Q_UNUSED(semantic);
270 if(nodeId >= 0) // Common node. Using >= ensures that a 0 (invalid) value will be flagged correctly
271 return checkedGeomNodeFromModelSR(nodeId, pcr, semantic);
272 else // Ghost node represented by a negative number
273 {
274 nodeId = (-nodeId) - 1;
275 if(nodeId >= pcr->mesh()->numGlobalGhostNodes())
276 return -2;
277 return GmMesh::setGhostFlag(pcr->originalToLocalOrderGhostNodeHighClearSR(nodeId)); // Returns -1 if out of the partition
278 }
279 }
280
286 inline int checkedNodeFromModel_Gn_Gl(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
287 {
288 if(nodeId >= 0) // Common node. Using >= ensures that a 0 (invalid) value will be flagged correctly
289 return checkedGeomNodeFromModel(nodeId, pcr, semantic);
290 else // Ghost node represented by a negative number
291 {
292 nodeId = (-nodeId) - 1;
293 if(nodeId >= pcr->mesh()->numGlobalGhostNodes())
294 return -2;
295 int tnode = pcr->originalToLocalOrderGhostNodeHighClear(nodeId);
296 return tnode == -1 ? -1 : tnode + pcr->mesh()->numNodes();
297 }
298 }
299
308 inline int checkedNodeFromModel_Ghs_Ghs(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
309 {
310 if(nodeId >= 0) // Common node. Using >= ensures that a 0 (invalid) value will be flagged correctly
311 return checkedGeomNodeFromModel(nodeId, pcr, semantic);
312 else // Ghost node represented with the high bit set (and so, a negative number)
313 {
314 nodeId = GmMesh::clearGhostFlag(nodeId) - 1;
315 if(nodeId >= pcr->mesh()->numGlobalGhostNodes())
316 return -2;
317 return GmMesh::setGhostFlag(pcr->originalToLocalOrderGhostNodeHighClear(nodeId)); // Returns -1 if out of the partition
318 }
319 }
320
326 inline int checkedGhostNodeFromModel_Ghc_Ghc(int nodeId, const GmPCR* pcr, TranslationSemantics semantic)
327 {
328 Q_UNUSED(semantic);
329 nodeId--; // -1 to adjust from 1-based to 0-based
330 if(nodeId < 0 || nodeId >= pcr->mesh()->numGlobalGhostNodes())
331 return -2;
332 return pcr->originalToLocalOrderGhostNodeHighClear(nodeId); // Returns -1 if out of the partition
333 }
334
339 inline int checkedCellFromModel(int cellId, const GmPCR* pcr, TranslationSemantics semantic)
340 {
341 Q_UNUSED(semantic);
342 assert(dynamic_cast<GmCellMesh*>(pcr->mesh()));
343 cellId--; // -1 to adjust from 1-based to 0-based
344 if(cellId < 0 || cellId >= ((GmCellMesh*)pcr->mesh())->numGlobalCells())
345 return -2;
346 return pcr->originalToLocalOrderCell(cellId); // Returns -1 if out of the partition
347 }
348
349 // The SR version for checkedCellFromModel(). See comments on the namespace definition
350 inline int checkedCellFromModelSR(int cellId, const GmPCR* pcr, TranslationSemantics semantic)
351 {
352 Q_UNUSED(semantic);
353 assert(dynamic_cast<GmCellMesh*>(pcr->mesh()));
354 cellId--; // -1 to adjust from 1-based to 0-based
355 if(cellId < 0 || cellId >= ((GmCellMesh*)pcr->mesh())->numGlobalCells())
356 return -2;
357 return pcr->originalToLocalOrderCellSR(cellId); // Returns -1 if out of the partition / remote halo cell
358 }
359}
360
361#endif
362
Base interface for mesh cells.
Definition gmCell.h:88
virtual GmCellMesh * mesh() const =0
Returns the "father" mesh for this cell.
virtual int cellId() const =0
Returns a number identifying the cell. It should be possible to use this id as an index to GmCellMesh...
Base interface class for CellMesh type plugins.
Definition gmCellMesh.h:40
virtual int numNodes() const =0
Returns the number of nodes in the mesh.
static bool isGhostNode(int nodeIndex)
Returns true if the given index is a ghost node index, false if not.
Definition gmMesh.h:136
virtual GmPCR * pcrObject() const =0
Returns the PCR(Partition - Color - Renumber) object associated with this mesh. Should NEVER return N...
static int clearGhostFlag(int nodeIndex)
Returns the given index with the ghost node bit cleared.
Definition gmMesh.h:142
static int setGhostFlag(int nodeIndex)
Returns the given index with the ghost node bit set.
Definition gmMesh.h:139
int totalNumGlobalNodes() const
Returns the total number of nodes in the mesh, including normal nodes & ghost nodes.
Definition gmMesh.h:122
virtual int numGlobalGhostNodes() const
When working with partitioned meshes, returns the number of ghost nodes in the global mesh,...
Definition gmMesh.h:119
virtual int numGlobalNodes() const
When working with partitioned meshes, returns the number of nodes in the global mesh,...
Definition gmMesh.h:116
Base interface class for Partition-Color-Renumber object plugins.
Definition gmPCR.h:54
virtual int originalToLocalOrderCell(int originalCellId) const =0
Translates an original(model) cell id into the local, ordered, cell id used by the mesh....
virtual int originalToLocalOrderCellSR(int originalCellId) const =0
SR version for originalToLocalOrderCell(). Returns -1 if skipRemote() is true and the cell is a remot...
virtual int originalToLocalOrderGhostNodeHighClearSR(int originalNodeId) const =0
SR version for originalToLocalOrderGhostNodeHighClear(). Returns -1 if skipRemote() is true and the n...
virtual int originalToLocalOrderNode(int originalNodeId) const =0
Translates an original (model) node id into the local, ordered, node id used by the mesh....
virtual int localOrderToOriginalGeomNode(int nodeId) const =0
An specialization of localOrderToOriginalNode, accepting ONLY geometric nodes (between 0 and num node...
virtual int originalToLocalOrderGhostNodeHighClear(int originalNodeId) const =0
An specialization of originalToLocalOrderNode, accepting ONLY ghost nodes with the high bit CLEARED (...
virtual GmMesh * mesh() const =0
Returns the mesh that this PCR object is tied to.
virtual int originalToLocalOrderGeomNode(int originalNodeId) const =0
An specialization of originalToLocalOrderNode, accepting ONLY geometric nodes (between 0 and num node...
virtual int localOrderToOriginalGhostNodeHighClear(int nodeId) const =0
An specialization of localOrderToOriginalNode, accepting ONLY ghost nodes with the high bit CLEARED (...
virtual int localOrderToOriginalNode(int nodeId) const =0
Translates a local, ordered, node id used by the mesh into the original (model) node id....
virtual int localOrderToOriginalCell(int cellId) const =0
Translates a local, ordered, cell id used by the mesh into the original(model) cell id When working w...
virtual int originalToLocalOrderGeomNodeSR(int originalNodeId) const =0
SR version for originalToLocalOrderGeomNode(). Returns -1 if skipRemote() is true and the node is a r...
Declaration of the GmCellMesh interface class.
Implementation of the GmPCR class.
Groups utility routines for translating node and cell indices to / from our internal representation a...
Definition gmMeshUtils.h:101
int checkedGeomNodeFromModel(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided geometry node id (no ghost nodes allowed), checks the input data and converts i...
Definition gmMeshUtils.h:225
TranslationSemantics
An enumeration to declare the semantics of the operation that made the index translation call....
Definition gmMeshUtils.h:106
@ IO
Method called from a model loading / saving function.
Definition gmMeshUtils.h:109
@ API
Method called from the Lua binding.
Definition gmMeshUtils.h:107
@ REPORT
Method called from a report function or an error message.
Definition gmMeshUtils.h:108
int checkedNodeFromModel_Gn_Ghs(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided node id where ghost nodes are represented as negative values,...
Definition gmMeshUtils.h:252
int checkedNodeFromModel_Ghs_Ghs(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided node id where ghost nodes are represented with the high bit set,...
Definition gmMeshUtils.h:308
int checkedGhostNodeFromModel_Ghc_Ghc(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided ghost node id (no geometry nodes allowed), with the high bit CLEARED (a value b...
Definition gmMeshUtils.h:326
int checkedNodeFromModel(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided node id that is either a geometry node, a ghost node WITH the high bit set or a...
Definition gmMeshUtils.h:201
int nodeToModel_Gl_Gn(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal node number that is either a geometry node or a ghost node in linear representation...
Definition gmMeshUtils.h:155
int nodeToModel_Ghs_Gn(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal node number that is either a geometry node or a ghost node WITH the high bit set,...
Definition gmMeshUtils.h:140
int checkedNodeFromModel_Gn_Gl(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided node id where ghost nodes are represented as negative values,...
Definition gmMeshUtils.h:286
int nodeToModel(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal node number that is either a geometry node, a ghost node WITH the high bit set or a...
Definition gmMeshUtils.h:128
int checkedCellFromModel(int cellId, const GmPCR *pcr, TranslationSemantics semantic)
Given a user provided cell id, checks the input data and converts it to the internal cell representat...
Definition gmMeshUtils.h:339
int cellToModel(int cellId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal cell number, converts that index to a Model index. If the internal cell does NOT ha...
Definition gmMeshUtils.h:179
int geomNodeToModel(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal geometry node number, converts that index to a Model index. If the internal node do...
Definition gmMeshUtils.h:116
int nodeToModel_Ghs_Ghs(int nodeId, const GmPCR *pcr, TranslationSemantics semantic)
Given an internal node number that is either a geometry node or a ghost node WITH the high bit set,...
Definition gmMeshUtils.h:169