    

 ## On this page

  

 

 # api\_cuda\_contacts

 Last update: 17.07.2025 

<a id="l00001" name="l00001"></a> 1\#pragma once

<a id="l00002" name="l00002"></a> 2 

<a id="l00003" name="l00003"></a> 3\#include &lt;rocky20/api/device/api\_device\_contacts.hpp&gt;

<a id="l00004" name="l00004"></a> 4\#include &lt;rocky20/api/device/api\_cuda.hpp&gt;

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

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

<a id="l00007" name="l00007"></a> 7 

<a id="l00008" name="l00008"></a> 8namespace rocky::cuda

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

<a id="l00010" name="l00010"></a> 10 

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

<a id="l00012" name="l00012"></a> 12// Contacts Loop

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

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

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

<a id="l00016" name="l00016"></a> 16__global__ void execute_frictional_contacts_function(

<a id="l00017" name="l00017"></a> 17 SDeviceModel *device_data,

<a id="l00018" name="l00018"></a> 18 cu_real time_curr,

<a id="l00019" name="l00019"></a> 19 Callable particle_contact_f_ptr,

<a id="l00020" name="l00020"></a> 20 Callable triangle_contact_f_ptr,

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

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

<a id="l00023" name="l00023"></a> 23{

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

<a id="l00025" name="l00025"></a> 25 device::execute_contacts_function&lt;CudaBackend&gt;(

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

<a id="l00027" name="l00027"></a> 27 time_curr,

<a id="l00028" name="l00028"></a> 28 device_data-&gt;ind_cnt_p_fr,

<a id="l00029" name="l00029"></a> 29 device_data-&gt;n_contacts-&gt;particle_fr,

<a id="l00030" name="l00030"></a> 30 true,

<a id="l00031" name="l00031"></a> 31 particle_contact_f_ptr,

<a id="l00032" name="l00032"></a> 32 udf_device_data);

<a id="l00033" name="l00033"></a> 33 

<a id="l00034" name="l00034"></a> 34 // Triangles

<a id="l00035" name="l00035"></a> 35 device::execute_contacts_function&lt;CudaBackend&gt;(

<a id="l00036" name="l00036"></a> 36 device_data,

<a id="l00037" name="l00037"></a> 37 time_curr,

<a id="l00038" name="l00038"></a> 38 device_data-&gt;ind_cnt_t_fr,

<a id="l00039" name="l00039"></a> 39 device_data-&gt;n_contacts-&gt;triangle_fr,

<a id="l00040" name="l00040"></a> 40 false,

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

<a id="l00042" name="l00042"></a> 42 udf_device_data);

<a id="l00043" name="l00043"></a> 43}

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

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

<a id="l00046" name="l00046"></a> 46__global__ void execute_finished_contacts_function(

<a id="l00047" name="l00047"></a> 47 SDeviceModel* device_data,

<a id="l00048" name="l00048"></a> 48 cu_real time_curr,

<a id="l00049" name="l00049"></a> 49 Callable particle_contact_f_ptr,

<a id="l00050" name="l00050"></a> 50 Callable triangle_contact_f_ptr,

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

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

<a id="l00053" name="l00053"></a> 53{

<a id="l00054" name="l00054"></a> 54 // particles -&gt; particles

<a id="l00055" name="l00055"></a> 55 device::execute_finished_contacts_function&lt;CudaBackend&gt;(

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

<a id="l00057" name="l00057"></a> 57 time_curr,

<a id="l00058" name="l00058"></a> 58 device_data-&gt;gen-&gt;ncont_p,

<a id="l00059" name="l00059"></a> 59 true,

<a id="l00060" name="l00060"></a> 60 particle_contact_f_ptr, udf_device_data

<a id="l00061" name="l00061"></a> 61 );

<a id="l00062" name="l00062"></a> 62 

<a id="l00063" name="l00063"></a> 63 // particles -&gt; triangles

<a id="l00064" name="l00064"></a> 64 device::execute_finished_contacts_function&lt;CudaBackend&gt;(

<a id="l00065" name="l00065"></a> 65 device_data,

<a id="l00066" name="l00066"></a> 66 time_curr,

<a id="l00067" name="l00067"></a> 67 device_data-&gt;gen-&gt;ncont_t,

<a id="l00068" name="l00068"></a> 68 false,

<a id="l00069" name="l00069"></a> 69 triangle_contact_f_ptr, udf_device_data

<a id="l00070" name="l00070"></a> 70 );

<a id="l00071" name="l00071"></a> 71}

<a id="l00072" name="l00072"></a> 72 

<a id="l00073" name="l00073"></a> 73template &lt;typename Callable&gt;

<a id="l00074" name="l00074"></a> 74__global__ void execute_active_contacts_function(

<a id="l00075" name="l00075"></a> 75 SDeviceModel* device_data,

<a id="l00076" name="l00076"></a> 76 cu_real time_curr,

<a id="l00077" name="l00077"></a> 77 Callable particle_contact_f_ptr,

<a id="l00078" name="l00078"></a> 78 Callable triangle_contact_f_ptr,

<a id="l00079" name="l00079"></a> 79 void* udf_device_data

<a id="l00080" name="l00080"></a> 80)

<a id="l00081" name="l00081"></a> 81{

<a id="l00082" name="l00082"></a> 82 // particles -&gt; particles

<a id="l00083" name="l00083"></a> 83 device::execute_active_contacts_function&lt;CudaBackend&gt;(

<a id="l00084" name="l00084"></a> 84 device_data,

<a id="l00085" name="l00085"></a> 85 time_curr,

<a id="l00086" name="l00086"></a> 86 device_data-&gt;gen-&gt;ncont_p,

<a id="l00087" name="l00087"></a> 87 true,

<a id="l00088" name="l00088"></a> 88 particle_contact_f_ptr,

<a id="l00089" name="l00089"></a> 89 udf_device_data);

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

<a id="l00091" name="l00091"></a> 91 // particles -&gt; triangles

<a id="l00092" name="l00092"></a> 92 device::execute_active_contacts_function&lt;CudaBackend&gt;(

<a id="l00093" name="l00093"></a> 93 device_data,

<a id="l00094" name="l00094"></a> 94 time_curr,

<a id="l00095" name="l00095"></a> 95 device_data-&gt;gen-&gt;ncont_t,

<a id="l00096" name="l00096"></a> 96 false,

<a id="l00097" name="l00097"></a> 97 triangle_contact_f_ptr,

<a id="l00098" name="l00098"></a> 98 udf_device_data);

<a id="l00099" name="l00099"></a> 99}

<a id="l00100" name="l00100"></a> 100 

<a id="l00101" name="l00101"></a> 101template &lt;typename Callable&gt;

<a id="l00102" name="l00102"></a> 102void dispatch_frictional_contacts_kernel(

<a id="l00103" name="l00103"></a> 103 [IRockyModel](structIRockyModel.xhtml) &amp;model,

<a id="l00104" name="l00104"></a> 104 Callable h_particle_contact_f_ptr,

<a id="l00105" name="l00105"></a> 105 Callable h_triangle_contact_f_ptr,

<a id="l00106" name="l00106"></a> 106 void **udf_devices_data

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

<a id="l00108" name="l00108"></a> 108{

<a id="l00109" name="l00109"></a> 109 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00110" name="l00110"></a> 110 return;

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

<a id="l00112" name="l00112"></a> 112 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

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

<a id="l00114" name="l00114"></a> 114 void *udf_device_data = udf_devices_data[i];

<a id="l00115" name="l00115"></a> 115 SDeviceModel *device_data = model.get_device_data(i);

<a id="l00116" name="l00116"></a> 116 

<a id="l00117" name="l00117"></a> 117 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00118" name="l00118"></a> 118 rocky::cuda::execute_frictional_contacts_function&lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt;(

<a id="l00119" name="l00119"></a> 119 device_data,

<a id="l00120" name="l00120"></a> 120 model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00121" name="l00121"></a> 121 h_particle_contact_f_ptr,

<a id="l00122" name="l00122"></a> 122 h_triangle_contact_f_ptr,

<a id="l00123" name="l00123"></a> 123 udf_device_data);

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

<a id="l00125" name="l00125"></a> 125 

<a id="l00126" name="l00126"></a> 126 //Sync all GPUs

<a id="l00127" name="l00127"></a> 127 sync_devices(model);

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

<a id="l00129" name="l00129"></a> 129 

<a id="l00130" name="l00130"></a> 130// frictional and adhesive contacts just finished

<a id="l00131" name="l00131"></a> 131template &lt;typename Callable&gt;

<a id="l00132" name="l00132"></a> 132void dispatch_finished_contacts_kernel(

<a id="l00133" name="l00133"></a> 133 [IRockyModel](structIRockyModel.xhtml)&amp; model,

<a id="l00134" name="l00134"></a> 134 Callable h_particle_contact_f_ptr,

<a id="l00135" name="l00135"></a> 135 Callable h_triangle_contact_f_ptr,

<a id="l00136" name="l00136"></a> 136 void** udf_devices_data

<a id="l00137" name="l00137"></a> 137)

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

<a id="l00139" name="l00139"></a> 139 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00140" name="l00140"></a> 140 return;

<a id="l00141" name="l00141"></a> 141 

<a id="l00142" name="l00142"></a> 142 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00143" name="l00143"></a> 143 {

<a id="l00144" name="l00144"></a> 144 void* udf_device_data = udf_devices_data[i];

<a id="l00145" name="l00145"></a> 145 SDeviceModel* device_data = model.get_device_data(i);

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

<a id="l00147" name="l00147"></a> 147 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00148" name="l00148"></a> 148 rocky::cuda::execute_finished_contacts_function &lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt; (

<a id="l00149" name="l00149"></a> 149 device_data, model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00150" name="l00150"></a> 150 h_particle_contact_f_ptr, h_triangle_contact_f_ptr,

<a id="l00151" name="l00151"></a> 151 udf_device_data

<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> 155 sync_devices(model);

<a id="l00156" name="l00156"></a> 156}

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

<a id="l00158" name="l00158"></a> 158// frictional and adhesive contacts still active

<a id="l00159" name="l00159"></a> 159template &lt;typename Callable&gt;

<a id="l00160" name="l00160"></a> 160void dispatch_active_contacts_kernel(

<a id="l00161" name="l00161"></a> 161 [IRockyModel](structIRockyModel.xhtml)&amp; model,

<a id="l00162" name="l00162"></a> 162 Callable h_particle_contact_f_ptr,

<a id="l00163" name="l00163"></a> 163 Callable h_triangle_contact_f_ptr,

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

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

<a id="l00166" name="l00166"></a> 166 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00167" name="l00167"></a> 167 return;

<a id="l00168" name="l00168"></a> 168 

<a id="l00169" name="l00169"></a> 169 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00170" name="l00170"></a> 170 {

<a id="l00171" name="l00171"></a> 171 void* udf_device_data = udf_devices_data[i];

<a id="l00172" name="l00172"></a> 172 SDeviceModel* device_data = model.get_device_data(i);

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

<a id="l00174" name="l00174"></a> 174 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00175" name="l00175"></a> 175 rocky::cuda::execute_active_contacts_function&lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt;(

<a id="l00176" name="l00176"></a> 176 device_data,

<a id="l00177" name="l00177"></a> 177 model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00178" name="l00178"></a> 178 h_particle_contact_f_ptr,

<a id="l00179" name="l00179"></a> 179 h_triangle_contact_f_ptr,

<a id="l00180" name="l00180"></a> 180 udf_device_data);

<a id="l00181" name="l00181"></a> 181 }

<a id="l00182" name="l00182"></a> 182 

<a id="l00183" name="l00183"></a> 183 sync_devices(model);

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

<a id="l00185" name="l00185"></a> 185 

<a id="l00186" name="l00186"></a> 186// Adhesive ----------------------------------------------------------------------------------------

<a id="l00187" name="l00187"></a> 187 

<a id="l00188" name="l00188"></a> 188template &lt;typename Callable&gt;

<a id="l00189" name="l00189"></a> 189__global__ void execute_adhesive_contacts_function(

<a id="l00190" name="l00190"></a> 190 SDeviceModel *device_data,

<a id="l00191" name="l00191"></a> 191 cu_real time_curr,

<a id="l00192" name="l00192"></a> 192 Callable particle_contact_f_ptr,

<a id="l00193" name="l00193"></a> 193 Callable triangle_contact_f_ptr,

<a id="l00194" name="l00194"></a> 194 void *udf_device_data

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

<a id="l00196" name="l00196"></a> 196{

<a id="l00197" name="l00197"></a> 197 // Particles

<a id="l00198" name="l00198"></a> 198 if (device_data-&gt;n_contacts-&gt;particle_ad &gt; 0)

<a id="l00199" name="l00199"></a> 199 {

<a id="l00200" name="l00200"></a> 200 device::execute_contacts_function&lt;CudaBackend&gt;(

<a id="l00201" name="l00201"></a> 201 device_data,

<a id="l00202" name="l00202"></a> 202 time_curr,

<a id="l00203" name="l00203"></a> 203 device_data-&gt;ind_cnt_p_ad,

<a id="l00204" name="l00204"></a> 204 device_data-&gt;n_contacts-&gt;particle_ad,

<a id="l00205" name="l00205"></a> 205 true,

<a id="l00206" name="l00206"></a> 206 particle_contact_f_ptr,

<a id="l00207" name="l00207"></a> 207 udf_device_data);

<a id="l00208" name="l00208"></a> 208 }

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

<a id="l00210" name="l00210"></a> 210 // Triangles

<a id="l00211" name="l00211"></a> 211 if (device_data-&gt;n_contacts-&gt;triangle_ad &gt; 0)

<a id="l00212" name="l00212"></a> 212 {

<a id="l00213" name="l00213"></a> 213 device::execute_contacts_function&lt;CudaBackend&gt;(

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

<a id="l00215" name="l00215"></a> 215 time_curr,

<a id="l00216" name="l00216"></a> 216 device_data-&gt;ind_cnt_t_ad,

<a id="l00217" name="l00217"></a> 217 device_data-&gt;n_contacts-&gt;triangle_ad,

<a id="l00218" name="l00218"></a> 218 false,

<a id="l00219" name="l00219"></a> 219 triangle_contact_f_ptr,

<a id="l00220" name="l00220"></a> 220 udf_device_data);

<a id="l00221" name="l00221"></a> 221 }

<a id="l00222" name="l00222"></a> 222}

<a id="l00223" name="l00223"></a> 223 

<a id="l00224" name="l00224"></a> 224template &lt;typename Callable&gt;

<a id="l00225" name="l00225"></a> 225void dispatch_adhesive_contacts_kernel(

<a id="l00226" name="l00226"></a> 226 [IRockyModel](structIRockyModel.xhtml) &amp;model,

<a id="l00227" name="l00227"></a> 227 Callable h_particle_contact_f_ptr,

<a id="l00228" name="l00228"></a> 228 Callable h_triangle_contact_f_ptr,

<a id="l00229" name="l00229"></a> 229 void **udf_devices_data

<a id="l00230" name="l00230"></a> 230)

<a id="l00231" name="l00231"></a> 231{

<a id="l00232" name="l00232"></a> 232 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00233" name="l00233"></a> 233 return;

<a id="l00234" name="l00234"></a> 234 

<a id="l00235" name="l00235"></a> 235 for (int i = 0; i&lt;model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00236" name="l00236"></a> 236 {

<a id="l00237" name="l00237"></a> 237 void *udf_device_data = udf_devices_data[i];

<a id="l00238" name="l00238"></a> 238 SDeviceModel *device_data = model.get_device_data(i);

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

<a id="l00240" name="l00240"></a> 240 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00241" name="l00241"></a> 241 rocky::cuda::execute_adhesive_contacts_function&lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt;(

<a id="l00242" name="l00242"></a> 242 device_data,

<a id="l00243" name="l00243"></a> 243 model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00244" name="l00244"></a> 244 h_particle_contact_f_ptr,

<a id="l00245" name="l00245"></a> 245 h_triangle_contact_f_ptr,

<a id="l00246" name="l00246"></a> 246 udf_device_data);

<a id="l00247" name="l00247"></a> 247 }

<a id="l00248" name="l00248"></a> 248 

<a id="l00249" name="l00249"></a> 249 //Sync all GPUs

<a id="l00250" name="l00250"></a> 250 sync_devices(model);

<a id="l00251" name="l00251"></a> 251 

<a id="l00252" name="l00252"></a> 252}

<a id="l00253" name="l00253"></a> 253 

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

<a id="l00255" name="l00255"></a> 255// All Contacts Loop

<a id="l00256" name="l00256"></a> 256// =================================================================================================

<a id="l00257" name="l00257"></a> 257template &lt;typename Callable&gt;

<a id="l00258" name="l00258"></a> 258__global__ void execute_all_contacts_function(

<a id="l00259" name="l00259"></a> 259 SDeviceModel *device_data,

<a id="l00260" name="l00260"></a> 260 cu_real time_curr,

<a id="l00261" name="l00261"></a> 261 Callable particle_contact_f_ptr,

<a id="l00262" name="l00262"></a> 262 Callable triangle_contact_f_ptr,

<a id="l00263" name="l00263"></a> 263 void *udf_device_data

<a id="l00264" name="l00264"></a> 264)

<a id="l00265" name="l00265"></a> 265{

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

<a id="l00267" name="l00267"></a> 267 device::execute_all_contacts_function&lt;CudaBackend&gt;(

<a id="l00268" name="l00268"></a> 268 device_data,

<a id="l00269" name="l00269"></a> 269 time_curr,

<a id="l00270" name="l00270"></a> 270 device_data-&gt;gen-&gt;ncont_p,

<a id="l00271" name="l00271"></a> 271 true,

<a id="l00272" name="l00272"></a> 272 particle_contact_f_ptr,

<a id="l00273" name="l00273"></a> 273 udf_device_data);

<a id="l00274" name="l00274"></a> 274 

<a id="l00275" name="l00275"></a> 275 // Triangles

<a id="l00276" name="l00276"></a> 276 device::execute_all_contacts_function&lt;CudaBackend&gt;(

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

<a id="l00278" name="l00278"></a> 278 time_curr,

<a id="l00279" name="l00279"></a> 279 device_data-&gt;gen-&gt;ncont_t,

<a id="l00280" name="l00280"></a> 280 false,

<a id="l00281" name="l00281"></a> 281 triangle_contact_f_ptr,

<a id="l00282" name="l00282"></a> 282 udf_device_data);

<a id="l00283" name="l00283"></a> 283}

<a id="l00284" name="l00284"></a> 284 

<a id="l00285" name="l00285"></a> 285template &lt;typename Callable&gt;

<a id="l00286" name="l00286"></a> 286void dispatch_all_contacts_kernel(

<a id="l00287" name="l00287"></a> 287 [IRockyModel](structIRockyModel.xhtml) &amp;model,

<a id="l00288" name="l00288"></a> 288 Callable h_particle_contact_f_ptr,

<a id="l00289" name="l00289"></a> 289 Callable h_triangle_contact_f_ptr,

<a id="l00290" name="l00290"></a> 290 void **udf_device_data

<a id="l00291" name="l00291"></a> 291)

<a id="l00292" name="l00292"></a> 292{

<a id="l00293" name="l00293"></a> 293 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00294" name="l00294"></a> 294 return;

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

<a id="l00296" name="l00296"></a> 296 for (int i = 0; i&lt;model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00297" name="l00297"></a> 297 {

<a id="l00298" name="l00298"></a> 298 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00299" name="l00299"></a> 299 rocky::cuda::execute_all_contacts_function&lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt;(

<a id="l00300" name="l00300"></a> 300 model.get_device_data(i),

<a id="l00301" name="l00301"></a> 301 model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00302" name="l00302"></a> 302 h_particle_contact_f_ptr,

<a id="l00303" name="l00303"></a> 303 h_triangle_contact_f_ptr,

<a id="l00304" name="l00304"></a> 304 udf_device_data[i]);

<a id="l00305" name="l00305"></a> 305 }

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

<a id="l00307" name="l00307"></a> 307 //Sync all GPUs

<a id="l00308" name="l00308"></a> 308 sync_devices(model);

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

<a id="l00310" name="l00310"></a> 310 

<a id="l00311" name="l00311"></a> 311// =================================================================================================

<a id="l00312" name="l00312"></a> 312// Contact forces

<a id="l00313" name="l00313"></a> 313// =================================================================================================

<a id="l00314" name="l00314"></a> 314template &lt;typename CallableCollection&gt;

<a id="l00315" name="l00315"></a> 315__global__ void execute_frictional_particle_contact_forces_function(

<a id="l00316" name="l00316"></a> 316 SDeviceModel* device_data,

<a id="l00317" name="l00317"></a> 317 cu_real time_curr,

<a id="l00318" name="l00318"></a> 318 const CallableCollection functions,

<a id="l00319" name="l00319"></a> 319 void* udf_device_data)

<a id="l00320" name="l00320"></a> 320{

<a id="l00321" name="l00321"></a> 321 device::api_compute_particle_contact_frictional_forces&lt;CudaBackend&gt;(

<a id="l00322" name="l00322"></a> 322 device_data, time_curr, functions, udf_device_data);

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

<a id="l00324" name="l00324"></a> 324 

<a id="l00325" name="l00325"></a> 325template &lt;typename CallableCollection&gt;

<a id="l00326" name="l00326"></a> 326__global__ void execute_frictional_triangle_contact_forces_function(

<a id="l00327" name="l00327"></a> 327 SDeviceModel* device_data,

<a id="l00328" name="l00328"></a> 328 cu_real time_curr,

<a id="l00329" name="l00329"></a> 329 const CallableCollection functions,

<a id="l00330" name="l00330"></a> 330 void* udf_device_data)

<a id="l00331" name="l00331"></a> 331{

<a id="l00332" name="l00332"></a> 332 device::api_compute_triangle_contact_frictional_forces&lt;CudaBackend&gt;(

<a id="l00333" name="l00333"></a> 333 device_data, time_curr, functions, udf_device_data);

<a id="l00334" name="l00334"></a> 334}

<a id="l00335" name="l00335"></a> 335 

<a id="l00336" name="l00336"></a> 336 

<a id="l00337" name="l00337"></a> 337template &lt;typename CallableCollection&gt;

<a id="l00338" name="l00338"></a> 338void dispatch_frictional_contact_forces_kernel(

<a id="l00339" name="l00339"></a> 339 [IRockyModel](structIRockyModel.xhtml)&amp; model, const CallableCollection&amp; function_ptrs, void** udf_devices_data)

<a id="l00340" name="l00340"></a> 340{

<a id="l00341" name="l00341"></a> 341 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00342" name="l00342"></a> 342 return;

<a id="l00343" name="l00343"></a> 343 

<a id="l00344" name="l00344"></a> 344 auto&amp; solver_model = *model._impl;

<a id="l00345" name="l00345"></a> 345 

<a id="l00346" name="l00346"></a> 346 solver_model.n_contacts.reset();

<a id="l00347" name="l00347"></a> 347 std::vector&lt;SNumberContacts&gt; n_contacts(model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)());

<a id="l00348" name="l00348"></a> 348 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00349" name="l00349"></a> 349 {

<a id="l00350" name="l00350"></a> 350 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i));

<a id="l00351" name="l00351"></a> 351 CUDA_COPY_D2H(n_contacts.data() + i, solver_model.GetDeviceModel(i).n_contacts, 1);

<a id="l00352" name="l00352"></a> 352 solver_model.n_contacts.join(n_contacts[i]);

<a id="l00353" name="l00353"></a> 353 }

<a id="l00354" name="l00354"></a> 354 

<a id="l00355" name="l00355"></a> 355 void* udf_device_data = nullptr;

<a id="l00356" name="l00356"></a> 356 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00357" name="l00357"></a> 357 {

<a id="l00358" name="l00358"></a> 358 if (udf_devices_data) udf_device_data = udf_devices_data[i];

<a id="l00359" name="l00359"></a> 359 SDeviceModel* device_data = model.get_device_data(i);

<a id="l00360" name="l00360"></a> 360 

<a id="l00361" name="l00361"></a> 361 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i))

<a id="l00362" name="l00362"></a> 362 auto [blocks, threads] = CudaBackend::get_launch_params(n_contacts[i].particle_fr);

<a id="l00363" name="l00363"></a> 363 rocky::cuda::execute_frictional_particle_contact_forces_function&lt;&lt;&lt;blocks, threads&gt;&gt;&gt;(

<a id="l00364" name="l00364"></a> 364 device_data, model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(), function_ptrs, udf_device_data);

<a id="l00365" name="l00365"></a> 365 }

<a id="l00366" name="l00366"></a> 366 

<a id="l00367" name="l00367"></a> 367 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00368" name="l00368"></a> 368 {

<a id="l00369" name="l00369"></a> 369 if (udf_devices_data) udf_device_data = udf_devices_data[i];

<a id="l00370" name="l00370"></a> 370 SDeviceModel* device_data = model.get_device_data(i);

<a id="l00371" name="l00371"></a> 371 

<a id="l00372" name="l00372"></a> 372 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i))

<a id="l00373" name="l00373"></a> 373 auto [blocks, threads] = CudaBackend::get_launch_params(n_contacts[i].triangle_fr);

<a id="l00374" name="l00374"></a> 374 rocky::cuda::execute_frictional_triangle_contact_forces_function &lt;&lt;&lt;blocks, threads&gt;&gt;&gt; (

<a id="l00375" name="l00375"></a> 375 device_data, model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(), function_ptrs, udf_device_data);

<a id="l00376" name="l00376"></a> 376 }

<a id="l00377" name="l00377"></a> 377 

<a id="l00378" name="l00378"></a> 378 sync_devices(model);

<a id="l00379" name="l00379"></a> 379}

<a id="l00380" name="l00380"></a> 380 

<a id="l00381" name="l00381"></a> 381template &lt;typename Callable&gt;

<a id="l00382" name="l00382"></a> 382__global__ void execute_adhesive_contact_forces_function(

<a id="l00383" name="l00383"></a> 383 SDeviceModel *device_data,

<a id="l00384" name="l00384"></a> 384 cu_real time_curr,

<a id="l00385" name="l00385"></a> 385 Callable particle_contact_f_ptr,

<a id="l00386" name="l00386"></a> 386 Callable triangle_contact_f_ptr,

<a id="l00387" name="l00387"></a> 387 void *udf_device_data

<a id="l00388" name="l00388"></a> 388)

<a id="l00389" name="l00389"></a> 389{

<a id="l00390" name="l00390"></a> 390 // Particles

<a id="l00391" name="l00391"></a> 391 device::api_compute_particle_contact_adhesive_forces&lt;CudaBackend&gt;(

<a id="l00392" name="l00392"></a> 392 device_data, time_curr,

<a id="l00393" name="l00393"></a> 393 particle_contact_f_ptr, udf_device_data

<a id="l00394" name="l00394"></a> 394 );

<a id="l00395" name="l00395"></a> 395 

<a id="l00396" name="l00396"></a> 396 // Triangles

<a id="l00397" name="l00397"></a> 397 device::api_compute_triangle_contact_adhesive_forces&lt;CudaBackend&gt;(

<a id="l00398" name="l00398"></a> 398 device_data, time_curr,

<a id="l00399" name="l00399"></a> 399 triangle_contact_f_ptr, udf_device_data

<a id="l00400" name="l00400"></a> 400 );

<a id="l00401" name="l00401"></a> 401}

<a id="l00402" name="l00402"></a> 402 

<a id="l00403" name="l00403"></a> 403template &lt;typename Callable&gt;

<a id="l00404" name="l00404"></a> 404void dispatch_adhesive_contact_forces_kernel(

<a id="l00405" name="l00405"></a> 405 [IRockyModel](structIRockyModel.xhtml) &amp;model,

<a id="l00406" name="l00406"></a> 406 Callable h_particle_contact_f_ptr,

<a id="l00407" name="l00407"></a> 407 Callable h_triangle_contact_f_ptr,

<a id="l00408" name="l00408"></a> 408 void **udf_devices_data

<a id="l00409" name="l00409"></a> 409)

<a id="l00410" name="l00410"></a> 410{

<a id="l00411" name="l00411"></a> 411 if (model.[get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)() &lt;= 0)

<a id="l00412" name="l00412"></a> 412 return;

<a id="l00413" name="l00413"></a> 413 

<a id="l00414" name="l00414"></a> 414 std::vector&lt;SNumberContacts&gt; n_contacts(model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)());

<a id="l00415" name="l00415"></a> 415 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00416" name="l00416"></a> 416 {

<a id="l00417" name="l00417"></a> 417 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i))

<a id="l00418" name="l00418"></a> 418 CUDA_COPY_D2H(n_contacts.data() + i, model._impl-&gt;GetDeviceModel(i).n_contacts, 1)

<a id="l00419" name="l00419"></a> 419 }

<a id="l00420" name="l00420"></a> 420 

<a id="l00421" name="l00421"></a> 421 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00422" name="l00422"></a> 422 {

<a id="l00423" name="l00423"></a> 423 void *udf_device_data = udf_devices_data[i];

<a id="l00424" name="l00424"></a> 424 SDeviceModel *device_data = model.get_device_data(i);

<a id="l00425" name="l00425"></a> 425 

<a id="l00426" name="l00426"></a> 426 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i))

<a id="l00427" name="l00427"></a> 427 auto [blocks, threads] = CudaBackend::get_launch_params(

<a id="l00428" name="l00428"></a> 428 std::max(n_contacts[i].particle_ad, n_contacts[i].triangle_ad));

<a id="l00429" name="l00429"></a> 429 rocky::cuda::execute_adhesive_contact_forces_function&lt;&lt;&lt;blocks, threads&gt;&gt;&gt;(

<a id="l00430" name="l00430"></a> 430 device_data,

<a id="l00431" name="l00431"></a> 431 model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(),

<a id="l00432" name="l00432"></a> 432 h_particle_contact_f_ptr,

<a id="l00433" name="l00433"></a> 433 h_triangle_contact_f_ptr,

<a id="l00434" name="l00434"></a> 434 udf_device_data);

<a id="l00435" name="l00435"></a> 435 }

<a id="l00436" name="l00436"></a> 436 

<a id="l00437" name="l00437"></a> 437 //Sync all GPUs

<a id="l00438" name="l00438"></a> 438 sync_devices(model);

<a id="l00439" name="l00439"></a> 439}

<a id="l00440" name="l00440"></a> 440 

<a id="l00441" name="l00441"></a> 441// Boundary wear on particle-triangle contacts ----------------------------------------------------

<a id="l00442" name="l00442"></a> 442 

<a id="l00443" name="l00443"></a> 443template &lt;typename Callable&gt;

<a id="l00444" name="l00444"></a> 444__global__ void execute_boundaries_wear_function_kernel(

<a id="l00445" name="l00445"></a> 445 SDeviceModel* device_data,

<a id="l00446" name="l00446"></a> 446 Callable triangle_wear_f_ptr,

<a id="l00447" name="l00447"></a> 447 void* udf_device_data,

<a id="l00448" name="l00448"></a> 448 cu_real time_curr)

<a id="l00449" name="l00449"></a> 449{

<a id="l00450" name="l00450"></a> 450 device::api_compute_boundaries_wear&lt;CudaBackend&gt;(

<a id="l00451" name="l00451"></a> 451 device_data, time_curr, triangle_wear_f_ptr, udf_device_data);

<a id="l00452" name="l00452"></a> 452}

<a id="l00453" name="l00453"></a> 453 

<a id="l00454" name="l00454"></a> 454template &lt;typename Callable&gt;

<a id="l00455" name="l00455"></a> 455void dispatch_boundaries_wear_kernel(

<a id="l00456" name="l00456"></a> 456 [IRockyModel](structIRockyModel.xhtml)&amp; model,

<a id="l00457" name="l00457"></a> 457 Callable triangle_wear_f_ptr,

<a id="l00458" name="l00458"></a> 458 void** udf_devices_data

<a id="l00459" name="l00459"></a> 459)

<a id="l00460" name="l00460"></a> 460{

<a id="l00461" name="l00461"></a> 461 for (int i = 0; i &lt; model.[get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)(); i++)

<a id="l00462" name="l00462"></a> 462 {

<a id="l00463" name="l00463"></a> 463 void* udf_device_data = udf_devices_data[i];

<a id="l00464" name="l00464"></a> 464 SDeviceModel* device_data = model.get_device_data(i);

<a id="l00465" name="l00465"></a> 465 

<a id="l00466" name="l00466"></a> 466 CUDA_SET_DEVICE(model.[get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)(i))

<a id="l00467" name="l00467"></a> 467 rocky::cuda::execute_boundaries_wear_function_kernel&lt;&lt;&lt;CD_NBLOCKS, CD_NTHREADS&gt;&gt;&gt;(

<a id="l00468" name="l00468"></a> 468 device_data,

<a id="l00469" name="l00469"></a> 469 triangle_wear_f_ptr,

<a id="l00470" name="l00470"></a> 470 udf_device_data,

<a id="l00471" name="l00471"></a> 471 model._impl-&gt;iteration.current_time);

<a id="l00472" name="l00472"></a> 472 }

<a id="l00473" name="l00473"></a> 473 

<a id="l00474" name="l00474"></a> 474 sync_devices(model);

<a id="l00475" name="l00475"></a> 475}

<a id="l00476" name="l00476"></a> 476 

<a id="l00477" name="l00477"></a> 477} // namespace rocky::cuda

[IRockyModel](structIRockyModel.xhtml)

**Definition** rocky_api.h:60



[IRockyModel::get\_number\_of\_devices](structIRockyModel.xhtml#a1fd1011aa809fe64647e9cacf1956a11)

int get_number_of_devices() const

**Definition** rocky_api.cpp:159



[IRockyModel::get\_number\_of\_active\_particles](structIRockyModel.xhtml#a38a15145f4f2bb47b79ab785f50d8277)

int get_number_of_active_particles() const

**Definition** rocky_api.cpp:139



[IRockyModel::get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)

double get_current_time() const

**Definition** rocky_api.cpp:129



[IRockyModel::get\_device\_id](structIRockyModel.xhtml#ae8f8865c809a31988291f9180d7cda2b)

int get_device_id(int device_index) const

**Definition** rocky_api.cpp:164