OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_interface_tools.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#define _FCALL
24#include <list>
25#include <vector>
26#include <algorithm>
27#include <cmath>
28#include <deque>
29#include <fstream>
30#include <iostream>
31#include <limits>
32#include <cfloat>
33
34#ifndef NDEBUG
35#define NDEBUG
36#endif
37#include <assert.h>
38
39// to be consistent with Fortran
40// But template would be better design
41#ifndef MYREAL4
42#define MY_REAL double
43#else
44#define MY_REAL float
45#endif
46
48{
49 MY_REAL vx = 0,vy = 0,vz = 0;
50};
51
53{
54 if(a.vx != b.vx) return (a.vx > b.vx);
55 if(a.vy != b.vy) return (a.vy > b.vy);
56 return (a.vz > b.vz);
57}
58
60{
61 return (a.vx == b.vx && a.vy == b.vy && a.vz == b.vz);
62}
63
64// =============================================================================
65// find the global velocity of a set of nodes
66// The global velocity is computed at the most frequent velocity among the nodes
67// In :
68// v - vector of nodal velocity
69// out::
70// v1,v2,v3 - directional velocities
71// freq - frequency of the velocity
72// =============================================================================
73void globalVelocity(std::vector<Velocity> & v, MY_REAL &v1, MY_REAL &v2, MY_REAL &v3, int & freq)
74{
75 std::sort(v.begin(),v.end(),compareVel);
76 Velocity most_frequent_velocity;
77 Velocity current_velocity;
78 size_t max_frequency = 0;
79 size_t current_frequency = 0;
80
81 most_frequent_velocity.vx = FLT_MAX;
82 most_frequent_velocity.vy = FLT_MAX;
83 most_frequent_velocity.vz = FLT_MAX;
84 current_velocity.vx = FLT_MAX;
85 current_velocity.vy = FLT_MAX;
86 current_velocity.vz = FLT_MAX;
87
88 for(auto it = v.begin() ; it != v.end(); it++)
89 {
90 if(areVelEqual(current_velocity,*it))
91 {
92 current_frequency ++;
93 }else
94 { // new velocity
95 if(max_frequency < current_frequency)
96 { // save old velocity if it is the most frequent so far
97 max_frequency = current_frequency;
98 most_frequent_velocity.vx = current_velocity.vx;
99 most_frequent_velocity.vy = current_velocity.vy;
100 most_frequent_velocity.vz = current_velocity.vz;
101 }
102 current_frequency = 1;
103 current_velocity.vx = (*it).vx;
104 current_velocity.vy = (*it).vy;
105 current_velocity.vz = (*it).vz;
106 }
107 }
108
109 if(max_frequency < current_frequency)
110 { // save old velocity if it is the most frequent so far
111 max_frequency = current_frequency;
112 most_frequent_velocity.vx = current_velocity.vx;
113 most_frequent_velocity.vy = current_velocity.vy;
114 most_frequent_velocity.vz = current_velocity.vz;
115 }
116 v1 = most_frequent_velocity.vx;
117 v2 = most_frequent_velocity.vy;
118 v3 = most_frequent_velocity.vz;
119 freq = max_frequency;
120}
121
122extern "C" {
123void c_compute_velocity_(MY_REAL *v, int * numnod, int *idx, int *size_idx, MY_REAL * v1, int * freq)
124{
125 std::vector<Velocity> vel;
126 vel.resize(*size_idx);
127 for(size_t i = 0; i < (size_t) *size_idx ; i++)
128 {
129 const int index_in_v = idx[i]-1;
130 assert(index_in_v >= 0);
131 assert(index_in_v < *numnod);
132 vel[i].vx = v[3*index_in_v];
133 vel[i].vy = v[3*index_in_v+1];
134 vel[i].vz = v[3*index_in_v+2];
135
136 }
137 int f = 0;
138 MY_REAL vx,vy,vz;
139 globalVelocity(vel,vx,vy,vz,f);
140 v1[0] = vx;
141 v1[1] = vy;
142 v1[2] = vz;
143 *freq = f;
144}
145void _FCALL C_COMPUTE_VELOCITY(MY_REAL *v, int * numnod, int *idx, int *size_idx, MY_REAL * v1, int * freq)
146{
147 c_compute_velocity_(v, numnod, idx, size_idx, v1, freq);
148}
149}
150
void _FCALL C_COMPUTE_VELOCITY(MY_REAL *v, int *numnod, int *idx, int *size_idx, MY_REAL *v1, int *freq)
bool compareVel(Velocity a, Velocity b)
bool areVelEqual(Velocity &a, Velocity &b)
void c_compute_velocity_(MY_REAL *v, int *numnod, int *idx, int *size_idx, MY_REAL *v1, int *freq)
#define MY_REAL
void globalVelocity(std::vector< Velocity > &v, MY_REAL &v1, MY_REAL &v2, MY_REAL &v3, int &freq)
#define _FCALL