    

 ## On this page

  

 

 # api\_device\_sph

 Last update: 16.07.2025 

<a id="l00001" name="l00001"></a> 1// (C) 2024 ANSYS, Inc. Unauthorized use, distribution, or duplication is prohibited.

<a id="l00002" name="l00002"></a> 2\#pragma once

<a id="l00003" name="l00003"></a> 3 

<a id="l00004" name="l00004"></a> 4\#include &lt;rocky20/api/rocky\_api\_sph\_functions.h&gt;

<a id="l00005" name="l00005"></a> 5\#include &lt;rocky20/api/rocky\_model\_api.hpp&gt;

<a id="l00006" name="l00006"></a> 6\#include &lt;rocky20/api/sph/rocky\_sph\_element\_api.hpp&gt;

<a id="l00007" name="l00007"></a> 7\#include &lt;rocky20/api/sph/rocky\_sph\_interaction\_api.hpp&gt;

<a id="l00008" name="l00008"></a> 8\#include &lt;rocky20/api/sph/rocky\_sph\_model\_api.hpp&gt;

<a id="l00009" name="l00009"></a> 9 

<a id="l00010" name="l00010"></a> 10namespace device {

<a id="l00011" name="l00011"></a> 11 

<a id="l00012" name="l00012"></a> 12template &lt;class Backend&gt;

<a id="l00013" name="l00013"></a> 13struct DefaultElementsOperator

<a id="l00014" name="l00014"></a> 14{

<a id="l00015" name="l00015"></a> 15 template &lt;typename Callable&gt;

<a id="l00016" name="l00016"></a> 16 __host__ __device__ void operator()(

<a id="l00017" name="l00017"></a> 17 Callable function_ptr,

<a id="l00018" name="l00018"></a> 18 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00019" name="l00019"></a> 19 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00020" name="l00020"></a> 20 [IRockySPHElementInteraction](structIRockySPHElementInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00021" name="l00021"></a> 21 void* udf_data)

<a id="l00022" name="l00022"></a> 22 {

<a id="l00023" name="l00023"></a> 23 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00024" name="l00024"></a> 24 }

<a id="l00025" name="l00025"></a> 25};

<a id="l00026" name="l00026"></a> 26 

<a id="l00027" name="l00027"></a> 27template &lt;class Backend&gt;

<a id="l00028" name="l00028"></a> 28struct DefaultTrianglesOperator

<a id="l00029" name="l00029"></a> 29{

<a id="l00030" name="l00030"></a> 30 template &lt;typename Callable&gt;

<a id="l00031" name="l00031"></a> 31 __host__ __device__ void operator()(

<a id="l00032" name="l00032"></a> 32 Callable function_ptr,

<a id="l00033" name="l00033"></a> 33 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00034" name="l00034"></a> 34 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00035" name="l00035"></a> 35 [IRockySPHTriangleInteraction](structIRockySPHTriangleInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00036" name="l00036"></a> 36 void* udf_data)

<a id="l00037" name="l00037"></a> 37 {

<a id="l00038" name="l00038"></a> 38 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00039" name="l00039"></a> 39 }

<a id="l00040" name="l00040"></a> 40};

<a id="l00041" name="l00041"></a> 41 

<a id="l00042" name="l00042"></a> 42template &lt;class Backend&gt;

<a id="l00043" name="l00043"></a> 43struct DefaultOperator

<a id="l00044" name="l00044"></a> 44{

<a id="l00045" name="l00045"></a> 45 template &lt;typename Callable&gt;

<a id="l00046" name="l00046"></a> 46 __host__ __device__ void operator()(

<a id="l00047" name="l00047"></a> 47 Callable function_ptr,

<a id="l00048" name="l00048"></a> 48 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00049" name="l00049"></a> 49 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00050" name="l00050"></a> 50 [IRockySPHElement](structIRockySPHElement.xhtml)&amp; sph_element_api,

<a id="l00051" name="l00051"></a> 51 void* udf_data)

<a id="l00052" name="l00052"></a> 52 {

<a id="l00053" name="l00053"></a> 53 function_ptr(device_model_api, sph_model, sph_element_api, udf_data);

<a id="l00054" name="l00054"></a> 54 }

<a id="l00055" name="l00055"></a> 55};

<a id="l00056" name="l00056"></a> 56 

<a id="l00057" name="l00057"></a> 57template &lt;class Backend&gt;

<a id="l00058" name="l00058"></a> 58struct HeatTransferElementsOperator

<a id="l00059" name="l00059"></a> 59{

<a id="l00060" name="l00060"></a> 60 template &lt;typename Callable&gt;

<a id="l00061" name="l00061"></a> 61 __host__ __device__ void operator()(

<a id="l00062" name="l00062"></a> 62 Callable function_ptr,

<a id="l00063" name="l00063"></a> 63 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00064" name="l00064"></a> 64 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00065" name="l00065"></a> 65 [IRockySPHElementInteraction](structIRockySPHElementInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00066" name="l00066"></a> 66 void* udf_data)

<a id="l00067" name="l00067"></a> 67 {

<a id="l00068" name="l00068"></a> 68 // Compute and add heat transfer

<a id="l00069" name="l00069"></a> 69 real_sph heat_transfer =

<a id="l00070" name="l00070"></a> 70 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00071" name="l00071"></a> 71 auto home_sph_element = sph_interaction_api.[get\_home\_element](structIRockySPHElementInteraction.xhtml#a7eb0236ba9b25b58b0ca258b1e79976b)();

<a id="l00072" name="l00072"></a> 72 auto near_sph_element = sph_interaction_api.[get\_near\_element](structIRockySPHElementInteraction.xhtml#a0e9d2687e1c8a66357730003f850fe26)();

<a id="l00073" name="l00073"></a> 73 home_sph_element.[get\_scalars](structIRockySPHElement.xhtml#a326bd60795936f9c4b77a9e000b1fa99)().[add\_heat\_transfer](structIRockySPHElementScalars.xhtml#ace6ee0291cca05f39eb04ba4c760afe0)(heat_transfer);

<a id="l00074" name="l00074"></a> 74 near_sph_element.get_scalars().add_heat_transfer(-heat_transfer);

<a id="l00075" name="l00075"></a> 75 

<a id="l00076" name="l00076"></a> 76 // Recording coupled heat transfer

<a id="l00077" name="l00077"></a> 77 if (home_sph_element.is_dem_coupled())

<a id="l00078" name="l00078"></a> 78 {

<a id="l00079" name="l00079"></a> 79 auto dem_particle = home_sph_element.get_linked_dem_particle(device_model_api);

<a id="l00080" name="l00080"></a> 80 auto dem_scalars = dem_particle.get_transfer_scalars();

<a id="l00081" name="l00081"></a> 81 dem_scalars.add_heat_transfer(heat_transfer);

<a id="l00082" name="l00082"></a> 82 }

<a id="l00083" name="l00083"></a> 83 

<a id="l00084" name="l00084"></a> 84 if (near_sph_element.is_dem_coupled())

<a id="l00085" name="l00085"></a> 85 {

<a id="l00086" name="l00086"></a> 86 auto dem_particle = near_sph_element.get_linked_dem_particle(device_model_api);

<a id="l00087" name="l00087"></a> 87 auto dem_scalars = dem_particle.get_transfer_scalars();

<a id="l00088" name="l00088"></a> 88 dem_scalars.add_heat_transfer(-heat_transfer);

<a id="l00089" name="l00089"></a> 89 }

<a id="l00090" name="l00090"></a> 90 }

<a id="l00091" name="l00091"></a> 91};

<a id="l00092" name="l00092"></a> 92 

<a id="l00093" name="l00093"></a> 93template &lt;class Backend&gt;

<a id="l00094" name="l00094"></a> 94struct HeatTransferTrianglesOperator

<a id="l00095" name="l00095"></a> 95{

<a id="l00096" name="l00096"></a> 96 template &lt;typename Callable&gt;

<a id="l00097" name="l00097"></a> 97 __host__ __device__ void operator()(

<a id="l00098" name="l00098"></a> 98 Callable function_ptr,

<a id="l00099" name="l00099"></a> 99 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00100" name="l00100"></a> 100 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00101" name="l00101"></a> 101 [IRockySPHTriangleInteraction](structIRockySPHTriangleInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00102" name="l00102"></a> 102 void* udf_data)

<a id="l00103" name="l00103"></a> 103 {

<a id="l00104" name="l00104"></a> 104 // Compute and add heat transfer

<a id="l00105" name="l00105"></a> 105 real_sph heat_transfer =

<a id="l00106" name="l00106"></a> 106 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00107" name="l00107"></a> 107 

<a id="l00108" name="l00108"></a> 108 // reduction factor for SPH elements with multiple triangle interactions

<a id="l00109" name="l00109"></a> 109 // (1 / number of simultaneous triangle interactions)

<a id="l00110" name="l00110"></a> 110 heat_transfer /= max(1.0f, sph_model._impl.device_model-&gt;bnd_force_coefficient[sph_interaction_api._impl-&gt;home_index]);

<a id="l00111" name="l00111"></a> 111 

<a id="l00112" name="l00112"></a> 112 sph_interaction_api.[get\_home\_element](structIRockySPHTriangleInteraction.xhtml#ae83d8750e222b2a46e6f901fd20b80d5)().[get\_scalars](structIRockySPHElement.xhtml#a326bd60795936f9c4b77a9e000b1fa99)().[add\_heat\_transfer](structIRockySPHElementScalars.xhtml#ace6ee0291cca05f39eb04ba4c760afe0)(heat_transfer);

<a id="l00113" name="l00113"></a> 113 

<a id="l00114" name="l00114"></a> 114 // Recording data for SPH Boundary Statistics

<a id="l00115" name="l00115"></a> 115 const auto&amp; data_recorder = sph_model._impl.device_model-&gt;boundary_data_recorder;

<a id="l00116" name="l00116"></a> 116 if (data_recorder

<a id="l00117" name="l00117"></a> 117 &amp;&amp; data_recorder-&gt;is_enabled(SPHBoundaryDataRecorder::tSPHTriangleHeatTransfer))

<a id="l00118" name="l00118"></a> 118 {

<a id="l00119" name="l00119"></a> 119 const int index =

<a id="l00120" name="l00120"></a> 120 data_recorder-&gt;get_scalar_index(SPHBoundaryDataRecorder::tSPHTriangleHeatTransfer);

<a id="l00121" name="l00121"></a> 121 auto triangle_scalars = sph_interaction_api.[get\_near\_triangle](structIRockySPHTriangleInteraction.xhtml#a469b4ac53234c9e707fee62725b0470a)().[get\_scalars](structIRockyGeometryTriangle.xhtml#a525086257224ba19ec3bbfec2522bdba)();

<a id="l00122" name="l00122"></a> 122 triangle_scalars.[add\_scalar](structIRockyTriangleScalars.xhtml#ab9721444212bd5fe4e3af03fe3a70294)(index, heat_transfer * device_model_api.[get\_timestep](structIRockyDeviceModel.xhtml#ab03adbadfc1d2a7a8f3a1f849be73d1a)());

<a id="l00123" name="l00123"></a> 123 }

<a id="l00124" name="l00124"></a> 124 

<a id="l00125" name="l00125"></a> 125 // Accumulation in a scalar used for heat coupling (positive when triangles receive heat)

<a id="l00126" name="l00126"></a> 126 auto* triangle_scalars = device_model_api._impl.model-&gt;triangle_scalars;

<a id="l00127" name="l00127"></a> 127 if (triangle_scalars &amp;&amp; triangle_scalars-&gt;is_heat_exchanged_enabled())

<a id="l00128" name="l00128"></a> 128 {

<a id="l00129" name="l00129"></a> 129 Backend::AtomicAdd(

<a id="l00130" name="l00130"></a> 130 &amp;triangle_scalars-&gt;get_heat_exchanged(sph_interaction_api._impl-&gt;near_index),

<a id="l00131" name="l00131"></a> 131 static\_cast&lt;double&gt;(-heat_transfer * device_model_api.[get\_timestep](structIRockyDeviceModel.xhtml#ab03adbadfc1d2a7a8f3a1f849be73d1a)()));

<a id="l00132" name="l00132"></a> 132 }

<a id="l00133" name="l00133"></a> 133 }

<a id="l00134" name="l00134"></a> 134};

<a id="l00135" name="l00135"></a> 135 

<a id="l00136" name="l00136"></a> 136template &lt;class Backend&gt;

<a id="l00137" name="l00137"></a> 137struct ForceElementInteractionOperator

<a id="l00138" name="l00138"></a> 138{

<a id="l00139" name="l00139"></a> 139 template &lt;typename Callable&gt;

<a id="l00140" name="l00140"></a> 140 __host__ __device__ void operator()(

<a id="l00141" name="l00141"></a> 141 Callable function_ptr,

<a id="l00142" name="l00142"></a> 142 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00143" name="l00143"></a> 143 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00144" name="l00144"></a> 144 [IRockySPHElementInteraction](structIRockySPHElementInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00145" name="l00145"></a> 145 void* udf_data)

<a id="l00146" name="l00146"></a> 146 {

<a id="l00147" name="l00147"></a> 147 // custom calculation of the element-to-element acceleration

<a id="l00148" name="l00148"></a> 148 const real_sph3 acceleration =

<a id="l00149" name="l00149"></a> 149 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00150" name="l00150"></a> 150 

<a id="l00151" name="l00151"></a> 151 sph_interaction_api.[add\_acceleration](structIRockySPHElementInteraction.xhtml#a713381036ee74bb8476435037c14124b)(acceleration);

<a id="l00152" name="l00152"></a> 152 }

<a id="l00153" name="l00153"></a> 153};

<a id="l00154" name="l00154"></a> 154 

<a id="l00155" name="l00155"></a> 155template &lt;class Backend&gt;

<a id="l00156" name="l00156"></a> 156struct ForceTriangleInteractionOperator

<a id="l00157" name="l00157"></a> 157{

<a id="l00158" name="l00158"></a> 158 template &lt;typename Callable&gt;

<a id="l00159" name="l00159"></a> 159 __host__ __device__ void operator()(

<a id="l00160" name="l00160"></a> 160 Callable function_ptr,

<a id="l00161" name="l00161"></a> 161 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00162" name="l00162"></a> 162 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00163" name="l00163"></a> 163 [IRockySPHTriangleInteraction](structIRockySPHTriangleInteraction.xhtml)&amp; sph_interaction_api,

<a id="l00164" name="l00164"></a> 164 void* udf_data)

<a id="l00165" name="l00165"></a> 165 {

<a id="l00166" name="l00166"></a> 166 // custom calculation of the element-to-triangle acceleration

<a id="l00167" name="l00167"></a> 167 const real_sph3 acceleration =

<a id="l00168" name="l00168"></a> 168 function_ptr(device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00169" name="l00169"></a> 169 

<a id="l00170" name="l00170"></a> 170 sph_interaction_api.[add\_acceleration](structIRockySPHTriangleInteraction.xhtml#a1578dfd6da083096eb169fe24913dd5b)(acceleration);

<a id="l00171" name="l00171"></a> 171 }

<a id="l00172" name="l00172"></a> 172};

<a id="l00173" name="l00173"></a> 173 

<a id="l00174" name="l00174"></a> 174template &lt;class Backend&gt;

<a id="l00175" name="l00175"></a> 175struct ForceElementOperator

<a id="l00176" name="l00176"></a> 176{

<a id="l00177" name="l00177"></a> 177 template &lt;typename Callable&gt;

<a id="l00178" name="l00178"></a> 178 __host__ __device__ void operator()(

<a id="l00179" name="l00179"></a> 179 Callable function_ptr,

<a id="l00180" name="l00180"></a> 180 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00181" name="l00181"></a> 181 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00182" name="l00182"></a> 182 [IRockySPHElement](structIRockySPHElement.xhtml)&amp; sph_element_api,

<a id="l00183" name="l00183"></a> 183 void* udf_data)

<a id="l00184" name="l00184"></a> 184 {

<a id="l00185" name="l00185"></a> 185 // custom calculation of the element acceleration (due to a body force)

<a id="l00186" name="l00186"></a> 186 const real_sph3 acceleration =

<a id="l00187" name="l00187"></a> 187 function_ptr(device_model_api, sph_model, sph_element_api, udf_data);

<a id="l00188" name="l00188"></a> 188 

<a id="l00189" name="l00189"></a> 189 sph_element_api.[add\_acceleration](structIRockySPHElement.xhtml#a2f90b3a2980c2fa73cd53e72ea277f76)(acceleration);

<a id="l00190" name="l00190"></a> 190 }

<a id="l00191" name="l00191"></a> 191};

<a id="l00192" name="l00192"></a> 192 

<a id="l00193" name="l00193"></a> 193template &lt;class Backend&gt;

<a id="l00194" name="l00194"></a> 194struct MolecularViscosityElementOperator

<a id="l00195" name="l00195"></a> 195{

<a id="l00196" name="l00196"></a> 196 template &lt;typename Callable&gt;

<a id="l00197" name="l00197"></a> 197 __host__ __device__ void operator()(

<a id="l00198" name="l00198"></a> 198 Callable function_ptr,

<a id="l00199" name="l00199"></a> 199 [IRockyDeviceModel](structIRockyDeviceModel.xhtml)&amp; device_model_api,

<a id="l00200" name="l00200"></a> 200 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)&amp; sph_model,

<a id="l00201" name="l00201"></a> 201 [IRockySPHElement](structIRockySPHElement.xhtml)&amp; sph_element_api,

<a id="l00202" name="l00202"></a> 202 void* udf_data)

<a id="l00203" name="l00203"></a> 203 {

<a id="l00204" name="l00204"></a> 204 // custom calculation of the element viscosity

<a id="l00205" name="l00205"></a> 205 const real_sph molecular_viscosity =

<a id="l00206" name="l00206"></a> 206 function_ptr(device_model_api, sph_model, sph_element_api, udf_data);

<a id="l00207" name="l00207"></a> 207 

<a id="l00208" name="l00208"></a> 208 sph_element_api.[set\_molecular\_viscosity](structIRockySPHElement.xhtml#abc6efc9b72adc7c3b487e760a2c53534)(molecular_viscosity);

<a id="l00209" name="l00209"></a> 209 }

<a id="l00210" name="l00210"></a> 210};

<a id="l00211" name="l00211"></a> 211 

<a id="l00212" name="l00212"></a> 212template &lt;class backend, typename Operator, typename Functor&gt;

<a id="l00213" name="l00213"></a> 213__host__ __device__ void launch_sph_particles_function(

<a id="l00214" name="l00214"></a> 214 SDeviceModel* device_data,

<a id="l00215" name="l00215"></a> 215 SPHDeviceModel* sph_device,

<a id="l00216" name="l00216"></a> 216 double current_time,

<a id="l00217" name="l00217"></a> 217 Functor function_ptr,

<a id="l00218" name="l00218"></a> 218 void* udf_data)

<a id="l00219" name="l00219"></a> 219{

<a id="l00220" name="l00220"></a> 220 [IRockyDeviceModel](structIRockyDeviceModel.xhtml) device_model_api;

<a id="l00221" name="l00221"></a> 221 device_model_api._impl.model = device_data;

<a id="l00222" name="l00222"></a> 222 device_model_api._impl.current_time = current_time;

<a id="l00223" name="l00223"></a> 223 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml) sph_model(device_data, sph_device-&gt;gen_sph, sph_device);

<a id="l00224" name="l00224"></a> 224 

<a id="l00225" name="l00225"></a> 225 int thread_start, thread_step, thread_stop;

<a id="l00226" name="l00226"></a> 226 backend::ThreadIteration(

<a id="l00227" name="l00227"></a> 227 thread_start, thread_step, thread_stop, sph_device-&gt;gen_sph-&gt;nprt_active);

<a id="l00228" name="l00228"></a> 228 for (int i = thread_start; i &lt; thread_stop; i += thread_step)

<a id="l00229" name="l00229"></a> 229 {

<a id="l00230" name="l00230"></a> 230 // Particle Interface

<a id="l00231" name="l00231"></a> 231 [IRockySPHElement](structIRockySPHElement.xhtml) sph_particle_api { RockySPHElement(sph_device, i), current_time };

<a id="l00232" name="l00232"></a> 232 if (sph_particle_api.is_enabled() &amp;&amp; !sph_particle_api._impl.is_ghost())

<a id="l00233" name="l00233"></a> 233 {

<a id="l00234" name="l00234"></a> 234 // Trigger user kernel

<a id="l00235" name="l00235"></a> 235 Operator caller{};

<a id="l00236" name="l00236"></a> 236 caller(function_ptr, device_model_api, sph_model, sph_particle_api, udf_data);

<a id="l00237" name="l00237"></a> 237 }

<a id="l00238" name="l00238"></a> 238 }

<a id="l00239" name="l00239"></a> 239}

<a id="l00240" name="l00240"></a> 240 

<a id="l00241" name="l00241"></a> 241template &lt;class Backend, typename Operator, typename Functor, class SPHNeighborsHandler&gt;

<a id="l00242" name="l00242"></a> 242__host__ __device__ void launch_sph_interactions_particles(

<a id="l00243" name="l00243"></a> 243 SDeviceModel* device_data,

<a id="l00244" name="l00244"></a> 244 SPHDeviceModel* sph_device,

<a id="l00245" name="l00245"></a> 245 double current_time,

<a id="l00246" name="l00246"></a> 246 Functor function_ptr,

<a id="l00247" name="l00247"></a> 247 void* udf_data,

<a id="l00248" name="l00248"></a> 248 SPHNeighborsHandler&amp; handler)

<a id="l00249" name="l00249"></a> 249{

<a id="l00250" name="l00250"></a> 250 [IRockyDeviceModel](structIRockyDeviceModel.xhtml) device_model_api;

<a id="l00251" name="l00251"></a> 251 device_model_api._impl.model = device_data;

<a id="l00252" name="l00252"></a> 252 device_model_api._impl.current_time = current_time;

<a id="l00253" name="l00253"></a> 253 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml) sph_model(device_data, sph_device-&gt;gen_sph, sph_device);

<a id="l00254" name="l00254"></a> 254 

<a id="l00255" name="l00255"></a> 255 RockySPHElementInteraction sph_interaction(device_data, sph_device, current_time);

<a id="l00256" name="l00256"></a> 256 [IRockySPHElementInteraction](structIRockySPHElementInteraction.xhtml) sph_interaction_api { &amp;sph_interaction };

<a id="l00257" name="l00257"></a> 257 

<a id="l00258" name="l00258"></a> 258 sph::iterator::IterateElements(handler, [&amp;](const auto&amp; search_element)

<a id="l00259" name="l00259"></a> 259 {

<a id="l00260" name="l00260"></a> 260 const int home_index = search_element.get_home_index();

<a id="l00261" name="l00261"></a> 261 // Home Interaction Interface

<a id="l00262" name="l00262"></a> 262 sph_interaction.reset_home_element(home_index);

<a id="l00263" name="l00263"></a> 263 

<a id="l00264" name="l00264"></a> 264 // Loop over number of active interactions

<a id="l00265" name="l00265"></a> 265 sph::iterator::IterateNeighbors(handler, [&amp;](const auto&amp; neighbor_element)

<a id="l00266" name="l00266"></a> 266 {

<a id="l00267" name="l00267"></a> 267 // Near Interaction Interface

<a id="l00268" name="l00268"></a> 268 sph_interaction.reset_near_element(

<a id="l00269" name="l00269"></a> 269 neighbor_element.get_near_index(), neighbor_element.get_periodic());

<a id="l00270" name="l00270"></a> 270 

<a id="l00271" name="l00271"></a> 271 // Trigger user kernel

<a id="l00272" name="l00272"></a> 272 Operator caller {};

<a id="l00273" name="l00273"></a> 273 caller(function_ptr, device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00274" name="l00274"></a> 274 });

<a id="l00275" name="l00275"></a> 275 });

<a id="l00276" name="l00276"></a> 276}

<a id="l00277" name="l00277"></a> 277 

<a id="l00278" name="l00278"></a> 278template &lt;class Backend, typename Operator, typename Functor&gt;

<a id="l00279" name="l00279"></a> 279__host__ __device__ void launch_sph_interactions_triangles(

<a id="l00280" name="l00280"></a> 280 SDeviceModel* device_data,

<a id="l00281" name="l00281"></a> 281 SPHDeviceModel* sph_device,

<a id="l00282" name="l00282"></a> 282 double current_time,

<a id="l00283" name="l00283"></a> 283 Functor function_ptr,

<a id="l00284" name="l00284"></a> 284 void* udf_data)

<a id="l00285" name="l00285"></a> 285{

<a id="l00286" name="l00286"></a> 286 [IRockyDeviceModel](structIRockyDeviceModel.xhtml) device_model_api;

<a id="l00287" name="l00287"></a> 287 device_model_api._impl.model = device_data;

<a id="l00288" name="l00288"></a> 288 device_model_api._impl.current_time = current_time;

<a id="l00289" name="l00289"></a> 289 [IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml) sph_model(device_data, sph_device-&gt;gen_sph, sph_device);

<a id="l00290" name="l00290"></a> 290 

<a id="l00291" name="l00291"></a> 291 RockySPHTriangleInteraction sph_interaction(device_data, sph_device, current_time);

<a id="l00292" name="l00292"></a> 292 [IRockySPHTriangleInteraction](structIRockySPHTriangleInteraction.xhtml) sph_interaction_api { &amp;sph_interaction };

<a id="l00293" name="l00293"></a> 293 

<a id="l00294" name="l00294"></a> 294 const auto&amp; periodic_domain = device_data-&gt;gen-&gt;periodic_domain;

<a id="l00295" name="l00295"></a> 295 

<a id="l00296" name="l00296"></a> 296 // loop only over element/triangle pairs with projection inside the triangle

<a id="l00297" name="l00297"></a> 297 int thread_start, thread_step, thread_stop;

<a id="l00298" name="l00298"></a> 298 Backend::ThreadIteration(thread_start, thread_step, thread_stop, sph_device-&gt;gen_sph-&gt;n_triangle_force_pairs);

<a id="l00299" name="l00299"></a> 299 for (int i = thread_start; i &lt; thread_stop; i += thread_step)

<a id="l00300" name="l00300"></a> 300 {

<a id="l00301" name="l00301"></a> 301 const int index = sph_device-&gt;triangle_force_pairs[i];

<a id="l00302" name="l00302"></a> 302 cuda_sph_contact* _sph_interaction = sph_device-&gt;cnt_sph_t + index;

<a id="l00303" name="l00303"></a> 303 PeriodicPosition cnt_per {};

<a id="l00304" name="l00304"></a> 304 if (periodic_domain.enabled())

<a id="l00305" name="l00305"></a> 305 cnt_per = sph_device-&gt;per_sph_cnt_t[index];

<a id="l00306" name="l00306"></a> 306 

<a id="l00307" name="l00307"></a> 307 // Interaction Interface

<a id="l00308" name="l00308"></a> 308 sph_interaction.reset_triangle_contact(_sph_interaction, cnt_per);

<a id="l00309" name="l00309"></a> 309 

<a id="l00310" name="l00310"></a> 310 // ROCKY-17943: For periodic cases, skipping interaction w/ triangles, such that

<a id="l00311" name="l00311"></a> 311 // the projected point is positioned outside periodic domain

<a id="l00312" name="l00312"></a> 312 if (periodic_domain.enabled()

<a id="l00313" name="l00313"></a> 313 &amp;&amp; periodic_domain.is_outside_cartesian_periodic_bounds(sph_interaction.inside_point))

<a id="l00314" name="l00314"></a> 314 {

<a id="l00315" name="l00315"></a> 315 continue;

<a id="l00316" name="l00316"></a> 316 }

<a id="l00317" name="l00317"></a> 317 

<a id="l00318" name="l00318"></a> 318 // Trigger user kernel

<a id="l00319" name="l00319"></a> 319 Operator caller {};

<a id="l00320" name="l00320"></a> 320 caller(function_ptr, device_model_api, sph_model, sph_interaction_api, udf_data);

<a id="l00321" name="l00321"></a> 321 }

<a id="l00322" name="l00322"></a> 322}

<a id="l00323" name="l00323"></a> 323 

<a id="l00324" name="l00324"></a> 324} // namespace device

[IRockyDeviceModel](structIRockyDeviceModel.xhtml)

**Definition** rocky_model_api.hpp:20



[IRockyDeviceModel::get\_timestep](structIRockyDeviceModel.xhtml#ab03adbadfc1d2a7a8f3a1f849be73d1a)

ROCKY_FUNCTIONS double get_timestep() const

**Definition** rocky_model_api.hpp:104



[IRockyGeometryTriangle::get\_scalars](structIRockyGeometryTriangle.xhtml#a525086257224ba19ec3bbfec2522bdba)

ROCKY_FUNCTIONS IRockyTriangleScalars get_scalars()



[IRockySPHDeviceModel](structIRockySPHDeviceModel.xhtml)

**Definition** rocky_sph_model_api.hpp:155



[IRockySPHElementInteraction](structIRockySPHElementInteraction.xhtml)

**Definition** rocky_sph_interaction_api.hpp:19



[IRockySPHElementInteraction::get\_near\_element](structIRockySPHElementInteraction.xhtml#a0e9d2687e1c8a66357730003f850fe26)

ROCKY_FUNCTIONS IRockySPHElement get_near_element() const

**Definition** rocky_sph_interaction_api.hpp:113



[IRockySPHElementInteraction::add\_acceleration](structIRockySPHElementInteraction.xhtml#a713381036ee74bb8476435037c14124b)

ROCKY_FUNCTIONS void add_acceleration(float3 acceleration)

**Definition** rocky_sph_interaction_api.hpp:123



[IRockySPHElementInteraction::get\_home\_element](structIRockySPHElementInteraction.xhtml#a7eb0236ba9b25b58b0ca258b1e79976b)

ROCKY_FUNCTIONS IRockySPHElement get_home_element() const

**Definition** rocky_sph_interaction_api.hpp:108



[IRockySPHElementScalars::add\_heat\_transfer](structIRockySPHElementScalars.xhtml#ace6ee0291cca05f39eb04ba4c760afe0)

ROCKY_FUNCTIONS void add_heat_transfer(const float value)

**Definition** rocky_sph_element_scalars.hpp:291



[IRockySPHElement](structIRockySPHElement.xhtml)

**Definition** rocky_sph_element_api.hpp:21



[IRockySPHElement::add\_acceleration](structIRockySPHElement.xhtml#a2f90b3a2980c2fa73cd53e72ea277f76)

ROCKY_FUNCTIONS void add_acceleration(const float3 &amp;acceleration)

**Definition** rocky_sph_element_api.hpp:69



[IRockySPHElement::get\_scalars](structIRockySPHElement.xhtml#a326bd60795936f9c4b77a9e000b1fa99)

ROCKY_FUNCTIONS IRockySPHElementScalars get_scalars()

**Definition** rocky_sph_element_api.hpp:260



[IRockySPHElement::set\_molecular\_viscosity](structIRockySPHElement.xhtml#abc6efc9b72adc7c3b487e760a2c53534)

ROCKY_FUNCTIONS void set_molecular_viscosity(const float molecular_viscosity)

**Definition** rocky_sph_element_api.hpp:284



[IRockySPHTriangleInteraction](structIRockySPHTriangleInteraction.xhtml)

**Definition** rocky_sph_interaction_api.hpp:138



[IRockySPHTriangleInteraction::add\_acceleration](structIRockySPHTriangleInteraction.xhtml#a1578dfd6da083096eb169fe24913dd5b)

ROCKY_FUNCTIONS void add_acceleration(float3 acceleration)

**Definition** rocky_sph_interaction_api.hpp:266



[IRockySPHTriangleInteraction::get\_near\_triangle](structIRockySPHTriangleInteraction.xhtml#a469b4ac53234c9e707fee62725b0470a)

ROCKY_FUNCTIONS IRockyGeometryTriangle get_near_triangle() const

**Definition** rocky_sph_interaction_api.hpp:279



[IRockySPHTriangleInteraction::get\_home\_element](structIRockySPHTriangleInteraction.xhtml#ae83d8750e222b2a46e6f901fd20b80d5)

ROCKY_FUNCTIONS IRockySPHElement get_home_element() const

**Definition** rocky_sph_interaction_api.hpp:256



[IRockyTriangleScalars::add\_scalar](structIRockyTriangleScalars.xhtml#ab9721444212bd5fe4e3af03fe3a70294)

ROCKY_FUNCTIONS void add_scalar(int scalar_index, double value) const