Skip to main content

Rocky Solver SDK 2024 R2

rocky_scalars

Last update: 17.07.2025
1#pragma once
2
3// Includes ========================================================================================
4#include <rocky20/model/rocky_model.h>
5#include <rocky20/sph/sph_data.h>
6#include <rocky20/api/device/api_backend.hpp>
7#include <rocky20/api/rocky_statistics_data.hpp>
8
16template <class _scalars>
17struct ScalarsModel
18{
29 int find(const char* name);
30
50 int add(const char* _name, const char* _unit, bool output = true);
51
52 template<class _data_type>
53 int add(const char* _name, const char* _unit, bool output)
54 {
55 return this->_impl.template add_scalars<_data_type>(
56 _name, _unit, rocky20::ScalarsInfo::cotNone, output);
57 }
71 int add_statistics_adder(const char* _name, const char* _unit);
72
83 [[deprecated("IRockyStatisticsCounter is no longer needed for statistics")]]
84 int add_statistics_counter(const char* _name);
85
99 int add_statistics_accumulator(const char* _name, const char* _unit);
100
107 void reset(int scalar_index);
108
123 void set_dimension(int scalar_index, double dimension_factor);
124
134 template<class _data_type = double>
135 _data_type* get_scalars_array(int scalar_index)
136 {
137 return this->_impl.template get_scalars<_data_type>(scalar_index);
138 }
139
140 ScalarsModel(_scalars& scalars, const std::vector< int >& device_ids);
141
142 _scalars& _impl;
143 const std::vector< int >& device_ids;
144
145};
146
157template <class _scalars>
158struct EntityScalars
159{
160
161 typedef typename _scalars::KnownTypes KnownTypes;
162
163 _scalars& _impl;
164 int element_index;
165
166 ROCKY_FUNCTIONS
167 EntityScalars(_scalars& scalars, int _element_index) : _impl(scalars), element_index(_element_index)
168 {
169 }
170
171 template <class _data_type = double>
172 ROCKY_FUNCTIONS
173 _data_type& get_known_scalar(KnownTypes scalars_type)
174 {
175 return this->_impl._scalars::template get_known_scalar<_data_type>(
176 scalars_type, this->element_index);
177 }
178
179 template <class _data_type = double>
180 ROCKY_FUNCTIONS
181 _data_type get_known_scalar(KnownTypes scalars_type) const
182 {
183 return this->_impl._scalars::template get_known_scalar<_data_type>(
184 scalars_type, this->element_index);
185 }
186
187 template <class _data_type = double>
188 ROCKY_FUNCTIONS
189 void add_known_scalar(KnownTypes scalars_type, _data_type value)
190 {
191 backend::atomic_add(
192 &this->_impl._scalars::template get_known_scalar<_data_type>(
193 scalars_type, this->element_index),
194 value);
195 }
196
206 template <class _data_type = double>
207 ROCKY_FUNCTIONS
208 _data_type get_scalar(int scalar_index) const
209 {
210 return this->_impl._scalars::template get_scalar<_data_type>(scalar_index, this->element_index);
211 }
212
213 ROCKY_FUNCTIONS
214 IRockyStatisticsAdder get_statistics_adder(int scalar_index) const
215 {
216 return this->_impl._scalars::template get_scalar<IRockyStatisticsAdder>(scalar_index, this->element_index);
217 }
218
219 ROCKY_FUNCTIONS
220 IRockyStatisticsAccumulator get_statistics_accumulator(int scalar_index) const
221 {
222 return this->_impl._scalars::template get_scalar<IRockyStatisticsAccumulator>(scalar_index, this->element_index);
223 }
224
225 [[deprecated("IRockyStatisticsCounter is no longer needed for statistics")]]
226 ROCKY_FUNCTIONS
227 IRockyStatisticsCounter get_statistics_counter(int scalar_index) const
228 {
229 return this->_impl._scalars::template get_scalar<IRockyStatisticsCounter>(scalar_index, this->element_index);
230 }
231
241 template <class _data_type = double>
242 ROCKY_FUNCTIONS
243 void set_scalar(int scalars_index, _data_type value) const
244 {
245 this->_impl._scalars::template get_scalar<_data_type>(
246 scalars_index, this->element_index) = value;
247 }
248
258 template <class _data_type = double>
259 ROCKY_FUNCTIONS
260 void add_scalar(int scalar_index, _data_type value) const
261 {
262 backend::atomic_add(
263 &this->_impl._scalars::template get_scalar<_data_type>(scalar_index, this->element_index),
264 value
265 );
266 }
267
279 template <class _data_type = double>
280 ROCKY_FUNCTIONS
281 void max_scalar(int scalar_index, _data_type value) const
282 {
283 backend::atomic_max(
284 &this->_impl._scalars::template get_scalar<_data_type>(scalar_index, this->element_index),
285 value
286 );
287 }
288
289 [[deprecated("IRockyStatisticsCounter is no longer needed for statistics")]]
290 ROCKY_FUNCTIONS
291 void add_value_to_statistics_adder(int scalar_index, double value, double count)
292 {
293 rocky20::AAdder& adder = this->_impl._scalars::template
294 get_scalar<rocky20::AAdder>(scalar_index, this->element_index);
295#ifdef __CUDA_ARCH__
296 adder.add_value<CudaBackend>(value);
297#else
298 adder.add_value<OMPBackend>(value);
299#endif
300 }
301
302 ROCKY_FUNCTIONS
303 void add_value_to_statistics_adder(int scalar_index, double value)
304 {
305 rocky20::AAdder& adder = this->_impl._scalars::template
306 get_scalar<rocky20::AAdder>(scalar_index, this->element_index);
307#ifdef __CUDA_ARCH__
308 adder.add_value<CudaBackend>(value);
309#else
310 adder.add_value<OMPBackend>(value);
311#endif
312 }
313
317 ROCKY_FUNCTIONS
318 void add_value_to_statistics_accumulator(int scalar_index, double value)
319 {
320 rocky20::AAccumulator& accumulator = this->_impl._scalars::template
321 get_scalar<rocky20::AAccumulator>(scalar_index, this->element_index);
322#ifdef __CUDA_ARCH__
323 accumulator.add_value<CudaBackend>(value);
324#else
325 accumulator.add_value<OMPBackend>(value);
326#endif
327 }
328
329 [[deprecated("IRockyStatisticsCounter is no longer needed for statistics")]]
330 ROCKY_FUNCTIONS
331 void increment_statistics_counter(int scalar_index)
332 {
333 int& counter =
334 this->_impl._scalars::template get_scalar<int>(scalar_index, this->element_index);
335 backend::atomic_add(&counter, 1);
336 }
337
338 [[deprecated("IRockyStatisticsCounter is no longer needed for statistics")]]
339 ROCKY_FUNCTIONS
340 double get_statistics_count(int scalar_index) const
341 {
342 return this->_impl._scalars::template get_scalar<int>(scalar_index, this->element_index);
343 }
344};
345
Definition rocky_statistics_data.hpp:181
Definition rocky_statistics_data.hpp:21

Connect with Ansys