> ## Documentation Index
> Fetch the complete documentation index at: https://developer.synopsys.com/llms.txt
> Use this file to discover all available pages before exploring further.

# IRockyTriangleScalarsModel Struct Reference

`#include <rocky_triangle_scalars.hpp>`

Inherits ScalarsModel\< rocky20::TriangleScalarsController >.

## Public Member Functions

| Type | Name |
| - | - |
| int | [find](#afc273a1e67e4995f848452fda3f71c31) (const char \*name) |
| int | [add](#a41b8986cbde7d37e0946a3a8a8361d19) (const char \*name, const char \*unit, bool output=true) |
| template\<class data\_type > int | [add\_accumulation\_scalar](#ac3e84af17e0dfaea602eab3a7a888b83) (const char \*name, const char \*unit, bool output=true) |
| void | [reset](#ae4f5d565ed2b3fa05b52f9274d542d69) (int scalar\_index) |
| void | [set\_dimension](#aa02d862be5d91a62af18a1b1320286e7) (int scalar\_index, double dimension\_factor) |
| void | [enable\_storage\_of\_exchanged\_heat](#a01f4979062e25a0fb10b874f9f1f81d9) () |
| void | [reset\_exchanged\_heat](#abe794fd133422249549fad8c56fee6eb) () |
| std::vector\< double > | [calculate\_sum\_over\_geometries](#acba5f06875d88bba1d66bd829c37fb52) (int scalar\_index) |
| void | [pull\_scalar\_from\_devices](#a60ee5f18541c3104a7a286d244a5f896) (int scalar\_index) |
| void | [push\_scalar\_to\_devices](#a1111ee6479b40ce1e086aec31c405e3e) (int scalar\_index) |

## Detailed Description

[`IRockyTriangleScalarsModel`](https://developer.synopsys.com/docs/rocky/rocky-solver-sdk/2025-r2/structIRockyTriangleScalarsModel) allows users to add new triangle scalars, find triangle scalars created in other modules or activate triangle scalars known to Rocky, during the setup phase of a module. Triangle scalars are special variables attached to boundary triangles, which are able to store values per triangle that are preserved between time iterations during a simulation.

## Member Function Documentation

### add()

```cpp theme={null}
int IRockyTriangleScalarsModel::add(
    const char * name,
    const char * unit,
    bool output = true
)
```

**This method creates a new scalar variable of type `double`**

for storing custom values during a simulation, preserving them between time iterations.

**Parameters**

| Name | Description |
| - | - |
| name | The name given to the scalar variable. The purpose of this name is twofold. First, it enables to find this scalar variable from other module, in order to share their values. Second, if the scalar variable can be displayed in a 3D window as a property, this name will identify it in the Rocky UI. |
| unit | A string specifying the unit in S.I. associated to the scalar variable. |
| output | Enables/disables the storage in disk at output times, for the visualization and post-processing of the scalar values. |

**Returns**

The index that will uniquely identify the scalar variable during the execution of the simulation.

### add\_accumulation\_scalar()

```cpp theme={null}
template<class data_type >
int IRockyTriangleScalarsModel::add_accumulation_scalar(
    const char * name,
    const char * unit,
    bool output = true
)
```

**This method creates a new scalar variable of type defined by template parameter**

`data_type` for storing custom values during a simulation, preserving them between time iterations. The scalar added with this method has a special behavior defined for pulling data from devices in multi-gpu simulations: It will accumulate those values in the host memory.

**Parameters**

| Name | Description |
| - | - |
| name | The name given to the scalar variable. The purpose of this name is twofold. First, it enables to find this scalar variable from other module, in order to share their values. Second, if the scalar variable can be displayed in a 3D window as a property, this name will identify it in the Rocky UI. |
| unit | A string specifying the unit in S.I. associated to the scalar variable. |
| output | Enables/disables the storage in disk at output times, for the visualization and post-processing of the scalar values. |

**Returns**

The index that will uniquely identify the scalar variable during the execution of the simulation.

### calculate\_sum\_over\_geometries()

```cpp theme={null}
std::vector< double > IRockyTriangleScalarsModel::calculate_sum_over_geometries(
    int scalar_index
)
```

**Returns**

A vector of the size of geometries in a project, in which every value is the sum of the triangle scalar values associated to the triangles belonging to a geometry. Those values are ordered in the vector according to the indices assigned to the geometries in a project. The sums are performed only if the triangle scalars are of type `double` or [`IRockyStatisticsAccumulator`](https://developer.synopsys.com/docs/rocky/rocky-solver-sdk/2025-r2/structIRockyStatisticsAccumulator).

### enable\_storage\_of\_exchanged\_heat()

```cpp theme={null}
void IRockyTriangleScalarsModel::enable_storage_of_exchanged_heat()
```

**This method activates an internal triangle scalar that accumulates the heat**

exchanged by geometry triangles with surrounding particles and/or SPH fluid elements during a simulation. The value of this scalar at each geometry triangle and at a given time will be equal to the sum of the heat received by the triangle from all particles and/or SPH elements that interacted with it since the last reset event, which is triggered by the [`IRockyTriangleScalarsModel::reset_exchanged_heat()`](#abe794fd133422249549fad8c56fee6eb) function.

### find()

```cpp theme={null}
int IRockyTriangleScalarsModel::find(const char * name)
```

**This method searches for a scalar variable already created by other modules,**

in order to allow access to its values, or store new values on it, during the execution of the simulation.

**Parameters**

| Name | Description |
| - | - |
| name | The name given to the scalar at the moment of its creation. |

**Returns**

The index that uniquely identifies the wanted scalar if it was actually found. It returns -1 otherwise.

### pull\_scalar\_from\_devices()

```cpp theme={null}
void IRockyTriangleScalarsModel::pull_scalar_from_devices(int scalar_index)
```

Copies the scalar values defined by scalar\_index from the device memory to the host memory (DRAM). When running a simulation in multi-GPU, the values of different devices will be accumulated (summed) in the scalar host memory. This method can only be called for scalars added with add\_accumulation\_scalar in multi-gpu simulations.

**Parameters**

| Name | Description |
| - | - |
| scalar\_index | the index of the scalar we want to copy. |

### push\_scalar\_to\_devices()

```cpp theme={null}
void IRockyTriangleScalarsModel::push_scalar_to_devices(int scalar_index)
```

Send the current scalar values defined by scalar\_index located in host memory (DRAM) to the devices memory.

**Parameters**

| Name | Description |
| - | - |
| scalar\_index | the index of the scalar we want to push to devices. |

### reset()

```cpp theme={null}
void IRockyTriangleScalarsModel::reset(int scalar_index)
```

**This method resets to zero all values stored in a scalar variable.**

**Parameters**

| Name | Description |
| - | - |
| scalar\_index | The index attributed to the scalar variable at the moment of its creation. |

### reset\_exchanged\_heat()

```cpp theme={null}
void IRockyTriangleScalarsModel::reset_exchanged_heat()
```

**This method resets an internal triangle scalar that accumulates the heat**

exchanged by geometry triangles with surrounding particles and/or SPH fluid elements. For example, this function may be called from within the `ROCKY_PLUGIN_BEGIN_ITERATION` hook. In that case, at the end of an iteration, a custom module can get the value of the total heat received by each triangle during the last timestep.

### set\_dimension()

```cpp theme={null}
void IRockyTriangleScalarsModel::set_dimension(
    int scalar_index,
    double dimension_factor
)
```

**The purpose of this method is to associate a dimensional factor**

to a scalar variable. This factor will be used to nondimensionalize their values. For instance, if the scalar represents a force, a force dimensional factor must be associated through this method. Dimensional factors for the fundamental magnitudes are provided by functions of a [`IRockyModel`](https://developer.synopsys.com/docs/rocky/rocky-solver-sdk/2025-r2/structIRockyModel) object.

**Parameters**

| Name | Description |
| - | - |
| scalar\_index | The index attributed to the scalar variable at the moment of its creation. |
| dimension\_factor | The appropriate dimensional factor for the scalar variable. |
