OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
ghost_shells.cpp File Reference
#include <iostream>
#include <vector>
#include <algorithm>

Go to the source code of this file.

Typedefs

using Ghosts = std::vector<std::vector<int>>

Functions

bool is_shell_ghost_on_proc (int shell_index, int process_id, int *shells, int *mask, int nspmd, int max_node_id)
Ghostscpp_build_ghosts (int *shells, int nb_shells, int *mask, int nspmd, int numnod)
int * cpp_get_shells_list (void *c, int pc, int *n)
int cpp_get_shells_list_size (void *c, int pc)
void cpp_copy_shells_list (void *c, int pc, int *shells, int n)
void cpp_destroy_ghosts (void *c)

Typedef Documentation

◆ Ghosts

using Ghosts = std::vector<std::vector<int>>

Definition at line 28 of file ghost_shells.cpp.

Function Documentation

◆ cpp_build_ghosts()

Ghosts * cpp_build_ghosts ( int * shells,
int nb_shells,
int * mask,
int nspmd,
int numnod )

Definition at line 60 of file ghost_shells.cpp.

66 {
67 if (!shells || !mask || nb_shells < 0 || nspmd <= 0 || numnod <= 0)
68 {
69 return nullptr;
70 }
71
72 auto *ghost_data = new Ghosts(nspmd);
73 const int max_node_id = numnod;
74
75 // Build ghost shell lists for each process
76 for (int shell_idx = 0; shell_idx < nb_shells; ++shell_idx)
77 {
78 for (int process_idx = 0; process_idx < nspmd; ++process_idx)
79 {
80 if (is_shell_ghost_on_proc(shell_idx, process_idx, shells, mask, nspmd, max_node_id))
81 {
82 (*ghost_data)[process_idx].push_back(shell_idx + 1); // Convert to 1-based for Fortran
83 }
84 }
85 }
86
87 // Remove duplicates from each process's shell list
88 if (nb_shells > 0)
89 {
90 for (int process_idx = 0; process_idx < nspmd; ++process_idx)
91 {
92 auto &shell_list = (*ghost_data)[process_idx];
93 std::sort(shell_list.begin(), shell_list.end());
94 auto new_end = std::unique(shell_list.begin(), shell_list.end());
95 shell_list.erase(new_end, shell_list.end());
96 }
97 }
98
99 return ghost_data;
100 }
bool is_shell_ghost_on_proc(int shell_index, int process_id, int *shells, int *mask, int nspmd, int max_node_id)
std::vector< std::vector< int > > Ghosts
static int nspmd
Definition rad2rad_c.c:126

◆ cpp_copy_shells_list()

void cpp_copy_shells_list ( void * c,
int pc,
int * shells,
int n )

Definition at line 146 of file ghost_shells.cpp.

147 {
148 if (!c || !shells)
149 {
150 return;
151 }
152
153 auto *ghost_data = static_cast<Ghosts *>(c);
154 const int process_idx = pc - 1; // Fortran to C index conversion
155
156 // Check bounds
157 if (process_idx < 0 || process_idx >= static_cast<int>(ghost_data->size()))
158 {
159 return;
160 }
161
162 // Copy the shells list to the output array
163 const auto &shell_list = (*ghost_data)[process_idx];
164 std::copy(shell_list.begin(), shell_list.end(), shells);
165 }

◆ cpp_destroy_ghosts()

void cpp_destroy_ghosts ( void * c)

Definition at line 167 of file ghost_shells.cpp.

168 {
169 if (!c)
170 {
171 return;
172 }
173
174 auto *ghost_data = static_cast<Ghosts *>(c);
175 delete ghost_data;
176 }

◆ cpp_get_shells_list()

int * cpp_get_shells_list ( void * c,
int pc,
int * n )

Definition at line 102 of file ghost_shells.cpp.

103 {
104 if (!c || !n)
105 {
106 if (n)
107 *n = 0;
108 return nullptr;
109 }
110
111 auto *ghost_data = static_cast<Ghosts *>(c);
112 const int process_idx = pc - 1; // Fortran to C index conversion
113
114 // Check bounds
115 if (process_idx < 0 || process_idx >= static_cast<int>(ghost_data->size()))
116 {
117 *n = 0;
118 return nullptr;
119 }
120
121 auto &shell_list = (*ghost_data)[process_idx];
122 *n = static_cast<int>(shell_list.size());
123
124 return *n == 0 ? nullptr : shell_list.data();
125 }
n

◆ cpp_get_shells_list_size()

int cpp_get_shells_list_size ( void * c,
int pc )

Definition at line 127 of file ghost_shells.cpp.

128 {
129 if (!c)
130 {
131 return 0;
132 }
133
134 auto *ghost_data = static_cast<Ghosts *>(c);
135 const int process_idx = pc - 1; // Fortran to C index conversion
136
137 // Check bounds
138 if (process_idx < 0 || process_idx >= static_cast<int>(ghost_data->size()))
139 {
140 return 0;
141 }
142
143 return static_cast<int>((*ghost_data)[process_idx].size());
144 }

◆ is_shell_ghost_on_proc()

bool is_shell_ghost_on_proc ( int shell_index,
int process_id,
int * shells,
int * mask,
int nspmd,
int max_node_id )

Definition at line 30 of file ghost_shells.cpp.

37{
38 // A shell should be included if at least one of its nodes has mask == 1
39 constexpr int nodes_per_shell = 4;
40
41 for (int j = 0; j < nodes_per_shell; ++j)
42 {
43 const int node_id = shells[shell_index * nodes_per_shell + j];
44 if (node_id > 0 && node_id <= max_node_id)
45 {
46 // For a Fortran array mask(nspmd,numnodes)
47 // Access mask(p,node_id) as mask[(node_id-1)*nspmd + (p)]
48 const int mask_index = (node_id - 1) * nspmd + process_id;
49 if (mask[mask_index] == 1)
50 {
51 return true; // Found at least one node with mask == 1
52 }
53 }
54 }
55 return false; // No nodes have mask == 1
56}