OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
cpp_reorder_elements.cpp File Reference
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <set>
#include <unordered_map>
#include <algorithm>
#include <map>
#include <deque>
#include <list>

Go to the source code of this file.

Data Structures

struct  ElementPartition
class  NodeMapping
class  Adjacency

Macros

#define _FCALL

Typedefs

typedef vector< int > Vint
typedef vector< NodeMappingVorder

Functions

bool is_permutation (const Vint &v)
void splitPerDomain (int nel, int nodesPerElt, size_t nspmd, int *domain, int lda, int offset, int *elt2Nodes, Vorder &nodes, ElementPartition &elts)
void cpp_reorder_elements (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
void CPP_REORDER_ELEMENTS_ (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
void CPP_REORDER_ELEMENTS__ (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
void _FCALL CPP_REORDER_ELEMENTS (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
void cpp_reorder_elements_ (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
void cpp_reorder_elements__ (int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)

Macro Definition Documentation

◆ _FCALL

#define _FCALL

Definition at line 40 of file cpp_reorder_elements.cpp.

Typedef Documentation

◆ Vint

typedef vector<int> Vint

Definition at line 42 of file cpp_reorder_elements.cpp.

◆ Vorder

typedef vector<NodeMapping> Vorder

Definition at line 82 of file cpp_reorder_elements.cpp.

Function Documentation

◆ CPP_REORDER_ELEMENTS()

void _FCALL CPP_REORDER_ELEMENTS ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 408 of file cpp_reorder_elements.cpp.

409 {
410 cpp_reorder_elements(NEL, NSPMD, NODES_PER_ELT, OFFSET, LDA, domain, elt2Nodes, permutation);
411 }
void cpp_reorder_elements(int *NEL, int *NSPMD, int *NODES_PER_ELT, int *OFFSET, int *LDA, int *domain, int *elt2Nodes, int *permutation)
#define LDA

◆ cpp_reorder_elements()

void cpp_reorder_elements ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 318 of file cpp_reorder_elements.cpp.

319 {
320 const int nel = *NEL; // number of elements
321 const size_t nspmd = (size_t)*NSPMD; // number of subdomains
322 const int nodesPerElt = *NODES_PER_ELT; // number of nodes per element
323 const int offset = *OFFSET; // padding size of array elt2Nodes (see cgrtails.F)
324 const int lda = *LDA; // leading dimension of elt2Nodes array
325 // elt2Nodes is a 2D array of size nel x nodesPerElt such as elt2Nodes[i*lda + j + offset] is the global id of the jth node of the ith element
326
327 Vorder nodesMapping(nspmd);
328 ElementPartition eltsParition;
329 vector<Adjacency> adjacencies(nspmd);
330 vector<vector<Vint>> node2Elts(nspmd);
331 vector<Vint> elt2LocalNodes(nspmd);
332
333 splitPerDomain(nel, nodesPerElt, nspmd, domain, lda, offset, elt2Nodes, nodesMapping, eltsParition);
334
335 for (size_t p = 0; p < nspmd; p++)
336 {
337 const int nb_local_elts = eltsParition.globalId[p].size();
338 const int nb_local_nodes = nodesMapping[p].size();
339 node2Elts[p].resize(nb_local_nodes);
340 adjacencies[p].setNbVertices(nb_local_elts);
341 adjacencies[p].reserve(30); // estimation of the maximum number of neighbor per element
342 elt2LocalNodes[p].resize(nb_local_elts * nodesPerElt);
343 }
344
345 // Fill node2Elts[domain][local_node_id] = set of local element id
346 // Fill elt2LocalNodes[domain][position in connectivity] = local_node_id
347 for (int i = 0; i < nel; i++)
348 {
349 const int p = domain[i];
350 // local id of the element
351 const int e = eltsParition.localId[i];
352 for (int j = 0; j < nodesPerElt; j++)
353 {
354 // local id of the neighbouring node
355 const int local_node_id = nodesMapping[p].getCompactId(elt2Nodes[i * lda + j + offset]);
356 elt2LocalNodes[p][nodesPerElt * e + j] = local_node_id;
357 node2Elts[p][local_node_id].push_back(e);
358 }
359 }
360
361 // Fill Adjacency
362 for(size_t p = 0; p < nspmd; p++) //for each domain
363 {
364 const size_t nel_local = eltsParition.globalId[p].size();
365 Vint last(nel_local, -1);
366 for(size_t e1 = 0 ; e1 < nel_local ; e1++) //for each element e1
367 {
368 for(size_t j = 0 ; j < nodesPerElt ; j++) //for each node n of e1
369 {
370 const int n = elt2LocalNodes[p][nodesPerElt * e1 + j];
371 for(auto & e2 : node2Elts[p][n]) //for each element e2 connected to n
372 {
373 if(last[e2] != e1)
374 {
375 last[e2] = e1;
376 adjacencies[p].addEdge(e1, e2);
377 }
378 }
379 }
380 }
381 }
382
383 // for each domain, compute the local permutation (index)
384 // and fill the global permutation
385 int start = 0;
386 for (size_t p = 0; p < nspmd; ++p)
387 {
388 Vint index = adjacencies[p].CuthillMckee();
389 //adjacencies[p].printStats(index);
390 for (size_t i = 0; i < index.size(); ++i)
391 {
392 // permutation["new"] = "old"
393 permutation[(size_t)(start + index[i])] = 1 + eltsParition.globalId[p][i];
394 }
395 start += index.size();
396 }
397 };
void splitPerDomain(int nel, int nodesPerElt, size_t nspmd, int *domain, int lda, int offset, int *elt2Nodes, Vorder &nodes, ElementPartition &elts)
vector< int > Vint
vector< NodeMapping > Vorder
integer, dimension(:), allocatable offset
Definition rad2r.F:53
type(reorder_struct_) permutation
Definition reorder_mod.F:54
static int nspmd
Definition rad2rad_c.c:126
n

◆ CPP_REORDER_ELEMENTS_()

void CPP_REORDER_ELEMENTS_ ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 400 of file cpp_reorder_elements.cpp.

401 {
402 cpp_reorder_elements(NEL, NSPMD, NODES_PER_ELT, OFFSET, LDA, domain, elt2Nodes, permutation);
403 }

◆ cpp_reorder_elements_()

void cpp_reorder_elements_ ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 412 of file cpp_reorder_elements.cpp.

413 {
414 cpp_reorder_elements(NEL, NSPMD, NODES_PER_ELT, OFFSET, LDA, domain, elt2Nodes, permutation);
415 }

◆ CPP_REORDER_ELEMENTS__()

void CPP_REORDER_ELEMENTS__ ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 404 of file cpp_reorder_elements.cpp.

405 {
406 cpp_reorder_elements(NEL, NSPMD, NODES_PER_ELT, OFFSET, LDA, domain, elt2Nodes, permutation);
407 }

◆ cpp_reorder_elements__()

void cpp_reorder_elements__ ( int * NEL,
int * NSPMD,
int * NODES_PER_ELT,
int * OFFSET,
int * LDA,
int * domain,
int * elt2Nodes,
int * permutation )

Definition at line 416 of file cpp_reorder_elements.cpp.

417 {
418 cpp_reorder_elements(NEL, NSPMD, NODES_PER_ELT, OFFSET, LDA, domain, elt2Nodes, permutation);
419 }

◆ is_permutation()

bool is_permutation ( const Vint & v)

Definition at line 280 of file cpp_reorder_elements.cpp.

281{
282 Vint r(v.size(), 0);
283 for (const auto &i : v)
284 {
285 if (i < 0 || ((size_t)i) > v.size())
286 {
287 return false;
288 }
289 r[i] = 1;
290 }
291 size_t sum = 0;
292 for (auto &n : r)
293 {
294 sum += n;
295 }
296 return sum == v.size();
297}

◆ splitPerDomain()

void splitPerDomain ( int nel,
int nodesPerElt,
size_t nspmd,
int * domain,
int lda,
int offset,
int * elt2Nodes,
Vorder & nodes,
ElementPartition & elts )

Definition at line 298 of file cpp_reorder_elements.cpp.

300{ // Distribute the elements according to domain[i = 0:nspmd-1]
301 // defines local-to-domain ids of elements and nodes
302 elts.globalId = vector<Vint>(nspmd);
303 elts.localId = Vint(nel, -1);
304 for (int i = 0; i < nel; i++)
305 {
306 const int p = domain[i];
307 elts.localId[i] = elts.globalId[p].size();
308 elts.globalId[p].push_back(i);
309 for (int j = 0; j < nodesPerElt; j++)
310 {
311 nodes[p].addGlobalId(elt2Nodes[i * lda + j + offset]);
312 }
313 }
314}