OpenRadioss 2025.1.11
OpenRadioss project
Loading...
Searching...
No Matches
c_interface_tools.cpp File Reference
#include <list>
#include <vector>
#include <algorithm>
#include <cmath>
#include <deque>
#include <fstream>
#include <iostream>
#include <limits>
#include <cfloat>
#include <assert.h>

Go to the source code of this file.

Data Structures

struct  Velocity

Macros

#define _FCALL
#define NDEBUG
#define MY_REAL   double

Functions

bool compareVel (Velocity a, Velocity b)
bool areVelEqual (Velocity &a, Velocity &b)
void globalVelocity (std::vector< Velocity > &v, MY_REAL &v1, MY_REAL &v2, MY_REAL &v3, int &freq)
void c_compute_velocity_ (MY_REAL *v, int *numnod, int *idx, int *size_idx, MY_REAL *v1, int *freq)
void _FCALL C_COMPUTE_VELOCITY (MY_REAL *v, int *numnod, int *idx, int *size_idx, MY_REAL *v1, int *freq)

Macro Definition Documentation

◆ _FCALL

#define _FCALL

Definition at line 23 of file c_interface_tools.cpp.

◆ MY_REAL

#define MY_REAL   double

Definition at line 42 of file c_interface_tools.cpp.

◆ NDEBUG

#define NDEBUG

Definition at line 35 of file c_interface_tools.cpp.

Function Documentation

◆ areVelEqual()

bool areVelEqual ( Velocity & a,
Velocity & b )

Definition at line 59 of file c_interface_tools.cpp.

60{
61 return (a.vx == b.vx && a.vy == b.vy && a.vz == b.vz);
62}

◆ C_COMPUTE_VELOCITY()

void _FCALL C_COMPUTE_VELOCITY ( MY_REAL * v,
int * numnod,
int * idx,
int * size_idx,
MY_REAL * v1,
int * freq )

Definition at line 145 of file c_interface_tools.cpp.

146{
147 c_compute_velocity_(v, numnod, idx, size_idx, v1, freq);
148}
void c_compute_velocity_(MY_REAL *v, int *numnod, int *idx, int *size_idx, MY_REAL *v1, int *freq)

◆ c_compute_velocity_()

void c_compute_velocity_ ( MY_REAL * v,
int * numnod,
int * idx,
int * size_idx,
MY_REAL * v1,
int * freq )

Definition at line 123 of file c_interface_tools.cpp.

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}
#define MY_REAL
void globalVelocity(std::vector< Velocity > &v, MY_REAL &v1, MY_REAL &v2, MY_REAL &v3, int &freq)

◆ compareVel()

bool compareVel ( Velocity a,
Velocity b )

Definition at line 52 of file c_interface_tools.cpp.

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}

◆ globalVelocity()

void globalVelocity ( std::vector< Velocity > & v,
MY_REAL & v1,
MY_REAL & v2,
MY_REAL & v3,
int & freq )

Definition at line 73 of file c_interface_tools.cpp.

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}
bool compareVel(Velocity a, Velocity b)
bool areVelEqual(Velocity &a, Velocity &b)