OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
Graph_api.cpp
Go to the documentation of this file.
1//Copyright> OpenRadioss
2//Copyright> Copyright (C) 1986-2025 Altair Engineering Inc.
3//Copyright>
4//Copyright> This program is free software: you can redistribute it and/or modify
5//Copyright> it under the terms of the GNU Affero General Public License as published by
6//Copyright> the Free Software Foundation, either version 3 of the License, or
7//Copyright> (at your option) any later version.
8//Copyright>
9//Copyright> This program is distributed in the hope that it will be useful,
10//Copyright> but WITHOUT ANY WARRANTY; without even the implied warranty of
11//Copyright> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12//Copyright> GNU Affero General Public License for more details.
13//Copyright>
14//Copyright> You should have received a copy of the GNU Affero General Public License
15//Copyright> along with this program. If not, see <https://www.gnu.org/licenses/>.
16//Copyright>
17//Copyright>
18//Copyright> Commercial Alternative: Altair Radioss Software
19//Copyright>
20//Copyright> As an alternative to this open-source version, Altair also offers Altair Radioss
21//Copyright> software under a commercial license. Contact Altair to discuss further if the
22//Copyright> commercial version may interest you: https://www.altair.com/radioss/.
23#include "Graph.hpp"
24
25#define _FCALL
26
27using namespace std;
28
29// Interface
30
31extern "C"
32{
33 void graph_build_path_(const int* , const int* , const int* , int* , Graph**);
34 void graph_get_sizes_(Graph**, int*);
35 void graph_get_path_(Graph**, int*);
37 void graph_build_cycles_(Graph**, int*);
38 void graph_get_nb_adj_(Graph**, int*);
39 void graph_get_adj_(Graph**, int*);
40 void _FCALL GRAPH_BUILD_PATH(const int* npts, const int* nconnect, const int* connection,
41 int* nb_connected_comp, Graph** graph_ptr)
42 {
43 graph_build_path_(npts, nconnect, connection, nb_connected_comp, graph_ptr);
44 }
45 void _FCALL GRAPH_GET_SIZES(Graph** graph_ptr, int* sizes)
46 {
47 graph_get_sizes_(graph_ptr, sizes);
48 }
49 void _FCALL GRAPH_GET_PATH(Graph** graph_ptr, int* path)
50 {
51 graph_get_path_(graph_ptr, path);
52 }
53 void _FCALL GRAPH_GET_NB_ADJ(Graph** graph_ptr, int* nb_adj)
54 {
55 graph_get_nb_adj_(graph_ptr, nb_adj);
56 }
57 void _FCALL GRAPH_GET_ADJ(Graph** graph_ptr, int* adj)
58 {
59 graph_get_adj_(graph_ptr, adj);
60 }
61 void _FCALL GRAPH_FREE_MEMORY(Graph** graph_ptr)
62 {
63 graph_free_memory_(graph_ptr);
64 }
65 void _FCALL GRAPH_BUILD_CYCLES(Graph** graph_ptr, int* cycles)
66 {
67 graph_build_cycles_(graph_ptr, cycles);
68 }
69}
70
71// Build Path
72
73void graph_build_path_(const int* npts, const int* nconnect, const int* connection,
74 int* nb_connected_comp, Graph** graph_ptr)
75{
76 vector<int> connect_list;
77 connect_list.reserve((*nconnect) * 2);
78 for (int i(0) ; i < *nconnect ; ++i) {
79 connect_list.push_back(connection[2 * i]);
80 connect_list.push_back(connection[2 * i + 1]);
81 }
82 *graph_ptr = new Graph (*npts, *nconnect, connect_list);
83 (*graph_ptr)->build_path();
84 *nb_connected_comp = (*graph_ptr)->getNbConnectedComponents();
85 vector<vector<int>> path = (*graph_ptr)->getPath();
86}
87
88// Get sizes
89
90void graph_get_sizes_(Graph** graph_ptr, int* sizes) {
91 for (int i(0) ; i < (*graph_ptr)->getNbConnectedComponents() ; ++i) {
92 sizes[i] = (*graph_ptr)->getPath()[i].size();
93 }
94}
95
96// Get path
97
98void graph_get_path_(Graph** graph_ptr, int* path) {
99 int i = 0;
100 for (int iconnect(0) ; iconnect < (*graph_ptr)->getNbConnectedComponents() ; ++iconnect) {
101 for (int ipt(0) ; ipt < (*graph_ptr)->getPath()[iconnect].size() ; ++ipt) {
102 path[i] = (*graph_ptr)->getPath()[iconnect][ipt];
103 i++;
104 }
105 }
106}
107
108// free meomory
109
110void graph_free_memory_(Graph** graph_ptr) {
111 delete(*graph_ptr);
112 *graph_ptr = nullptr;
113}
114
115// build cycles
116
117void graph_build_cycles_(Graph** graph_ptr, int* cycles) {
118 vector<bool> res((*graph_ptr)->build_cycle());
119
120 const int& nb_comp = (*graph_ptr)->getNbConnectedComponents();
121
122 for (int iconnect(0) ; iconnect < nb_comp ; iconnect++) {
123 cycles[iconnect] = res[iconnect] ? 1 : 0;
124 }
125}
126
127// get adjacence list size by elem
128
129void graph_get_nb_adj_(Graph** graph_ptr, int* nb_adj) {
130 for (int i(0) ; i < (*graph_ptr)->getAdjList().size() ; ++i) {
131 nb_adj[i] = (*graph_ptr)->getAdjList().at(i).size();
132 }
133}
134
135// get adjacence list
136
137void graph_get_adj_(Graph** graph_ptr, int* adj) {
138 int cpt = 0;
139 for (int i(0) ; i < (*graph_ptr)->getAdjList().size() ; ++i) {
140 for (int j(0) ; j < (*graph_ptr)->getAdjList().at(i).size() ; ++j) {
141 adj[cpt] = (*graph_ptr)->getAdjList().at(i).at(j);
142 cpt++;
143 }
144 }
145}
146
void graph_get_path_(Graph **, int *)
Definition Graph_api.cpp:98
void graph_build_cycles_(Graph **, int *)
void _FCALL GRAPH_BUILD_CYCLES(Graph **graph_ptr, int *cycles)
Definition Graph_api.cpp:65
void _FCALL GRAPH_BUILD_PATH(const int *npts, const int *nconnect, const int *connection, int *nb_connected_comp, Graph **graph_ptr)
Definition Graph_api.cpp:40
void graph_build_path_(const int *, const int *, const int *, int *, Graph **)
Definition Graph_api.cpp:73
void _FCALL GRAPH_GET_PATH(Graph **graph_ptr, int *path)
Definition Graph_api.cpp:49
void graph_free_memory_(Graph **)
void _FCALL GRAPH_GET_NB_ADJ(Graph **graph_ptr, int *nb_adj)
Definition Graph_api.cpp:53
void _FCALL GRAPH_GET_ADJ(Graph **graph_ptr, int *adj)
Definition Graph_api.cpp:57
void _FCALL GRAPH_FREE_MEMORY(Graph **graph_ptr)
Definition Graph_api.cpp:61
void graph_get_sizes_(Graph **, int *)
Definition Graph_api.cpp:90
void _FCALL GRAPH_GET_SIZES(Graph **graph_ptr, int *sizes)
Definition Graph_api.cpp:45
void graph_get_adj_(Graph **, int *)
void graph_get_nb_adj_(Graph **, int *)
#define _FCALL