    

 ## On this page

  

 

 # api\_omp\_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// Includes ---------------------------------------------------------------------------------------

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

<a id="l00006" name="l00006"></a> 6 

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

<a id="l00008" name="l00008"></a> 8\#include &lt;rocky20/device/omp\_backend.hpp&gt;

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

<a id="l00010" name="l00010"></a> 10namespace rocky::omp {

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

<a id="l00012" name="l00012"></a> 12// Dispatchers ------------------------------------------------------------------------------------

<a id="l00013" name="l00013"></a> 13template &lt;typename Operator = device::DefaultOperator&lt;OMPBackend&gt;, typename Functor&gt;

<a id="l00014" name="l00014"></a> 14inline void dispatch_sph_elements_kernel(

<a id="l00015" name="l00015"></a> 15 [IRockyModel](structIRockyModel.xhtml)&amp; model, Functor&amp; omp_dispatch_particle_f, void* udf_data)

<a id="l00016" name="l00016"></a> 16{

<a id="l00017" name="l00017"></a> 17 SPHModel* sph_model = &amp;(*model._impl-&gt;sph_model);

<a id="l00018" name="l00018"></a> 18 SPHDeviceModel* sph_device = model._impl-&gt;sph_model-&gt;get_device_data(0);

<a id="l00019" name="l00019"></a> 19 SDeviceModel* device_data = model.get_device_data(0);

<a id="l00020" name="l00020"></a> 20 

<a id="l00021" name="l00021"></a> 21 if (sph_model-&gt;gen_sph.nprt_active &lt;= 0)

<a id="l00022" name="l00022"></a> 22 return;

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

<a id="l00024" name="l00024"></a> 24\#ifndef GPU\_KERNEL\_COMPILING\_STAGE

<a id="l00025" name="l00025"></a> 25 #pragma omp parallel num\_threads(model.get\_number\_of\_processes())

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

<a id="l00027" name="l00027"></a> 27 device::launch_sph_particles_function&lt;OMPBackend, Operator&gt;(

<a id="l00028" name="l00028"></a> 28 device_data, sph_device, model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)(), omp_dispatch_particle_f, udf_data);

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

<a id="l00030" name="l00030"></a> 30\#endif

<a id="l00031" name="l00031"></a> 31}

<a id="l00032" name="l00032"></a> 32 

<a id="l00033" name="l00033"></a> 33template &lt;typename Operator = device::DefaultElementsOperator&lt;OMPBackend&gt;, typename Functor&gt;

<a id="l00034" name="l00034"></a> 34inline void dispatch_sph_interactions_elements_kernel(

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

<a id="l00036" name="l00036"></a> 36 Functor&amp; sph_particle_interaction_f,

<a id="l00037" name="l00037"></a> 37 void* udf_data,

<a id="l00038" name="l00038"></a> 38 IterationType it_type = itAll)

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

<a id="l00040" name="l00040"></a> 40 cuda_host&amp; solver_model = *model._impl;

<a id="l00041" name="l00041"></a> 41 SPHModel* sph_model = &amp;(*model._impl-&gt;sph_model);

<a id="l00042" name="l00042"></a> 42 float current_time = model.[get\_current\_time](structIRockyModel.xhtml#a93ef35ae1eb9cf50ca77ab2070a769ab)();

<a id="l00043" name="l00043"></a> 43 if (sph_model-&gt;gen_sph.nprt_active &lt;= 0)

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

<a id="l00045" name="l00045"></a> 45 

<a id="l00046" name="l00046"></a> 46\#ifndef GPU\_KERNEL\_COMPILING\_STAGE

<a id="l00047" name="l00047"></a> 47 #pragma omp parallel num\_threads(model.get\_number\_of\_processes())

<a id="l00048" name="l00048"></a> 48 {

<a id="l00049" name="l00049"></a> 49 // SPH -&gt; SPH

<a id="l00050" name="l00050"></a> 50 if (sph_model-&gt;gen_sph.use_particles_neighbors_list)

<a id="l00051" name="l00051"></a> 51 {

<a id="l00052" name="l00052"></a> 52 if (solver_model.gen.periodic_domain.enabled())

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

<a id="l00054" name="l00054"></a> 54 SPHExplicitHandler&lt;OMPBackend, true&gt; handler { solver_model.GetDeviceData(0),

<a id="l00055" name="l00055"></a> 55 sph_model-&gt;get_device_data(0),

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

<a id="l00057" name="l00057"></a> 57 it_type };

<a id="l00058" name="l00058"></a> 58 device::launch_sph_interactions_particles&lt;

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

<a id="l00060" name="l00060"></a> 60 Operator,

<a id="l00061" name="l00061"></a> 61 decltype(sph_particle_interaction_f)&gt;(

<a id="l00062" name="l00062"></a> 62 solver_model.GetDeviceData(0),

<a id="l00063" name="l00063"></a> 63 sph_model-&gt;get_device_data(0),

<a id="l00064" name="l00064"></a> 64 current_time,

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

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

<a id="l00067" name="l00067"></a> 67 handler);

<a id="l00068" name="l00068"></a> 68 }

<a id="l00069" name="l00069"></a> 69 else

<a id="l00070" name="l00070"></a> 70 {

<a id="l00071" name="l00071"></a> 71 SPHExplicitHandler&lt;OMPBackend, false&gt; handler { solver_model.GetDeviceData(0),

<a id="l00072" name="l00072"></a> 72 sph_model-&gt;get_device_data(0),

<a id="l00073" name="l00073"></a> 73 current_time,

<a id="l00074" name="l00074"></a> 74 it_type };

<a id="l00075" name="l00075"></a> 75 device::launch_sph_interactions_particles&lt;

<a id="l00076" name="l00076"></a> 76 OMPBackend,

<a id="l00077" name="l00077"></a> 77 Operator,

<a id="l00078" name="l00078"></a> 78 decltype(sph_particle_interaction_f)&gt;(

<a id="l00079" name="l00079"></a> 79 solver_model.GetDeviceData(0),

<a id="l00080" name="l00080"></a> 80 sph_model-&gt;get_device_data(0),

<a id="l00081" name="l00081"></a> 81 current_time,

<a id="l00082" name="l00082"></a> 82 sph_particle_interaction_f,

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

<a id="l00084" name="l00084"></a> 84 handler);

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

<a id="l00086" name="l00086"></a> 86 }

<a id="l00087" name="l00087"></a> 87 else

<a id="l00088" name="l00088"></a> 88 {

<a id="l00089" name="l00089"></a> 89 if (solver_model.gen.nprt_active &gt; 0)

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

<a id="l00091" name="l00091"></a> 91 if (solver_model.gen.periodic_domain.enabled())

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

<a id="l00093" name="l00093"></a> 93 SPHApplyHandler&lt;OMPBackend, true, true&gt; handler { solver_model.GetDeviceData(0),

<a id="l00094" name="l00094"></a> 94 sph_model-&gt;get_device_data(0),

<a id="l00095" name="l00095"></a> 95 current_time,

<a id="l00096" name="l00096"></a> 96 it_type };

<a id="l00097" name="l00097"></a> 97 device::launch_sph_interactions_particles&lt;

<a id="l00098" name="l00098"></a> 98 OMPBackend,

<a id="l00099" name="l00099"></a> 99 Operator,

<a id="l00100" name="l00100"></a> 100 decltype(sph_particle_interaction_f)&gt;(

<a id="l00101" name="l00101"></a> 101 solver_model.GetDeviceData(0),

<a id="l00102" name="l00102"></a> 102 sph_model-&gt;get_device_data(0),

<a id="l00103" name="l00103"></a> 103 current_time,

<a id="l00104" name="l00104"></a> 104 sph_particle_interaction_f,

<a id="l00105" name="l00105"></a> 105 udf_data,

<a id="l00106" name="l00106"></a> 106 handler);

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

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

<a id="l00109" name="l00109"></a> 109 {

<a id="l00110" name="l00110"></a> 110 SPHApplyHandler&lt;OMPBackend, true, false&gt; handler {

<a id="l00111" name="l00111"></a> 111 solver_model.GetDeviceData(0),

<a id="l00112" name="l00112"></a> 112 sph_model-&gt;get_device_data(0),

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

<a id="l00114" name="l00114"></a> 114 it_type

<a id="l00115" name="l00115"></a> 115 };

<a id="l00116" name="l00116"></a> 116 device::launch_sph_interactions_particles&lt;

<a id="l00117" name="l00117"></a> 117 OMPBackend,

<a id="l00118" name="l00118"></a> 118 Operator,

<a id="l00119" name="l00119"></a> 119 decltype(sph_particle_interaction_f)&gt;(

<a id="l00120" name="l00120"></a> 120 solver_model.GetDeviceData(0),

<a id="l00121" name="l00121"></a> 121 sph_model-&gt;get_device_data(0),

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

<a id="l00123" name="l00123"></a> 123 sph_particle_interaction_f,

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

<a id="l00125" name="l00125"></a> 125 handler);

<a id="l00126" name="l00126"></a> 126 }

<a id="l00127" name="l00127"></a> 127 }

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

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

<a id="l00130" name="l00130"></a> 130 if (solver_model.gen.periodic_domain.enabled())

<a id="l00131" name="l00131"></a> 131 {

<a id="l00132" name="l00132"></a> 132 SPHApplyHandler&lt;OMPBackend, false, true&gt; handler {

<a id="l00133" name="l00133"></a> 133 solver_model.GetDeviceData(0),

<a id="l00134" name="l00134"></a> 134 sph_model-&gt;get_device_data(0),

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

<a id="l00136" name="l00136"></a> 136 it_type

<a id="l00137" name="l00137"></a> 137 };

<a id="l00138" name="l00138"></a> 138 device::launch_sph_interactions_particles&lt;

<a id="l00139" name="l00139"></a> 139 OMPBackend,

<a id="l00140" name="l00140"></a> 140 Operator,

<a id="l00141" name="l00141"></a> 141 decltype(sph_particle_interaction_f)&gt;(

<a id="l00142" name="l00142"></a> 142 solver_model.GetDeviceData(0),

<a id="l00143" name="l00143"></a> 143 sph_model-&gt;get_device_data(0),

<a id="l00144" name="l00144"></a> 144 current_time,

<a id="l00145" name="l00145"></a> 145 sph_particle_interaction_f,

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

<a id="l00147" name="l00147"></a> 147 handler);

<a id="l00148" name="l00148"></a> 148 }

<a id="l00149" name="l00149"></a> 149 else

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

<a id="l00151" name="l00151"></a> 151 SPHApplyHandler&lt;OMPBackend, false, false&gt; handler {

<a id="l00152" name="l00152"></a> 152 solver_model.GetDeviceData(0),

<a id="l00153" name="l00153"></a> 153 sph_model-&gt;get_device_data(0),

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

<a id="l00155" name="l00155"></a> 155 it_type

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

<a id="l00157" name="l00157"></a> 157 device::launch_sph_interactions_particles&lt;

<a id="l00158" name="l00158"></a> 158 OMPBackend,

<a id="l00159" name="l00159"></a> 159 Operator,

<a id="l00160" name="l00160"></a> 160 decltype(sph_particle_interaction_f)&gt;(

<a id="l00161" name="l00161"></a> 161 solver_model.GetDeviceData(0),

<a id="l00162" name="l00162"></a> 162 sph_model-&gt;get_device_data(0),

<a id="l00163" name="l00163"></a> 163 current_time,

<a id="l00164" name="l00164"></a> 164 sph_particle_interaction_f,

<a id="l00165" name="l00165"></a> 165 udf_data,

<a id="l00166" name="l00166"></a> 166 handler);

<a id="l00167" name="l00167"></a> 167 }

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

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

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

<a id="l00171" name="l00171"></a> 171\#endif

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

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

<a id="l00174" name="l00174"></a> 174template &lt;typename Operator = device::DefaultTrianglesOperator&lt;OMPBackend&gt;, typename Functor&gt;

<a id="l00175" name="l00175"></a> 175inline void dispatch_sph_interactions_triangles_kernel(

<a id="l00176" name="l00176"></a> 176 [IRockyModel](structIRockyModel.xhtml)&amp; model, Functor&amp; sph_triangle_interaction_f, void* udf_data)

<a id="l00177" name="l00177"></a> 177{

<a id="l00178" name="l00178"></a> 178 SPHModel* sph_model = &amp;(*model._impl-&gt;sph_model);

<a id="l00179" name="l00179"></a> 179 SPHDeviceModel* sph_device = model._impl-&gt;sph_model-&gt;get_device_data(0);

<a id="l00180" name="l00180"></a> 180 SDeviceModel* device_data = model.get_device_data(0);

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

<a id="l00182" name="l00182"></a> 182 if (sph_model-&gt;gen_sph.nprt_active &lt;= 0)

<a id="l00183" name="l00183"></a> 183 return;

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

<a id="l00185" name="l00185"></a> 185\#ifndef GPU\_KERNEL\_COMPILING\_STAGE

<a id="l00186" name="l00186"></a> 186 #pragma omp parallel num\_threads(model.get\_number\_of\_processes())

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

<a id="l00188" name="l00188"></a> 188 // SPH -&gt; triangles

<a id="l00189" name="l00189"></a> 189 device::launch_sph_interactions_triangles&lt;OMPBackend, Operator&gt;(

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

<a id="l00191" name="l00191"></a> 191 sph_device,

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

<a id="l00193" name="l00193"></a> 193 sph_triangle_interaction_f,

<a id="l00194" name="l00194"></a> 194 udf_data);

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

<a id="l00196" name="l00196"></a> 196\#endif

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

<a id="l00198" name="l00198"></a> 198 

<a id="l00199" name="l00199"></a> 199} // namespace rocky::omp

[IRockyModel](structIRockyModel.xhtml)

**Definition** rocky_api.h:58



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

double get_current_time() const

**Definition** rocky_api.cpp:143