Skip to content

Commit cc719ce

Browse files
committed
Added time_step_multiplicator for integrate_particles() function in PARTICLES extension, fixed bug in write_file() template functions
1 parent 1f95c0a commit cc719ce

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/kernel.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ string opencl_c_container() { return R( // ########################## begin of O
19221922
)+"#endif"+R( // FORCE_FIELD
19231923

19241924
)+"#ifdef PARTICLES"+R(
1925-
)+R(kernel void integrate_particles)+"("+R(global float* particles, const global float* u // ) {
1925+
)+R(kernel void integrate_particles)+"("+R(global float* particles, const global float* u, const float time_step_multiplicator // ) {
19261926
)+"#ifdef FORCE_FIELD"+R(
19271927
, volatile global float* F, const float fx, const float fy, const float fz
19281928
)+"#endif"+R( // FORCE_FIELD
@@ -1937,7 +1937,7 @@ string opencl_c_container() { return R( // ########################## begin of O
19371937
spread_force(F, p0, Fn); // do force spreading
19381938
}
19391939
)+"#endif"+R( // FORCE_FIELD
1940-
const float3 un = interpolate_u(mirror_position(p0), u); // trilinear interpolation of velocity at point p
1940+
const float3 un = interpolate_u(mirror_position(p0), u)*time_step_multiplicator; // trilinear interpolation of velocity at point p
19411941
const float3 p = mirror_position(p0+un); // advect particles
19421942
particles[ n] = p.x;
19431943
particles[ def_particles_N+(ulong)n] = p.y;

src/lbm.cpp

+10-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ void LBM_Domain::allocate(Device& device) {
102102

103103
#ifdef PARTICLES
104104
particles = Memory<float>(device, (ulong)particles_N, 3u);
105-
kernel_integrate_particles = Kernel(device, (ulong)particles_N, "integrate_particles", particles, u);
105+
kernel_integrate_particles = Kernel(device, (ulong)particles_N, "integrate_particles", particles, u, 1.0f);
106106
#ifdef FORCE_FIELD
107107
kernel_integrate_particles.add_parameters(F, fx, fy, fz);
108108
#endif // FORCE_FIELD
@@ -150,17 +150,17 @@ void LBM_Domain::enqueue_update_moving_boundaries() { // mark/unmark nodes next
150150
}
151151
#endif // MOVING_BOUNDARIES
152152
#ifdef PARTICLES
153-
void LBM_Domain::enqueue_integrate_particles() { // intgegrate particles forward in time and couple particles to fluid
153+
void LBM_Domain::enqueue_integrate_particles(const uint time_step_multiplicator) { // intgegrate particles forward in time and couple particles to fluid
154154
#ifdef FORCE_FIELD
155155
if(particles_rho!=1.0f) kernel_reset_force_field.enqueue_run(); // only reset force field if particles have buoyancy and apply forces on fluid
156-
kernel_integrate_particles.set_parameters(3u, fx, fy, fz);
156+
kernel_integrate_particles.set_parameters(4u, fx, fy, fz);
157157
#endif // FORCE_FIELD
158-
kernel_integrate_particles.enqueue_run();
158+
kernel_integrate_particles.set_parameters(2u, (float)time_step_multiplicator).enqueue_run();
159159
}
160160
#endif // PARTICLES
161161

162-
void LBM_Domain::increment_time_step() {
163-
t++; // increment time step
162+
void LBM_Domain::increment_time_step(const uint steps) {
163+
t += (ulong)steps; // increment time step
164164
#ifdef UPDATE_FIELDS
165165
t_last_update_fields = t;
166166
#endif // UPDATE_FIELDS
@@ -830,18 +830,18 @@ void LBM::update_moving_boundaries() { // mark/unmark nodes next to TYPE_S nodes
830830
#endif // MOVING_BOUNDARIES
831831

832832
#if defined(PARTICLES)&&!defined(FORCE_FIELD)
833-
void LBM::integrate_particles(const ulong steps) { // intgegrate passive tracer particles forward in time in stationary flow field
833+
void LBM::integrate_particles(const ulong steps, const uint time_step_multiplicator) { // intgegrate passive tracer particles forward in time in stationary flow field
834834
info.append(steps, get_t());
835835
Clock clock;
836-
for(ulong i=1ull; i<=steps; i++) {
836+
for(ulong i=1ull; i<=steps; i+=(ulong)time_step_multiplicator) {
837837
#if defined(INTERACTIVE_GRAPHICS)||defined(INTERACTIVE_GRAPHICS_ASCII)
838838
while(!key_P&&running) sleep(0.016);
839839
if(!running) break;
840840
#endif // INTERACTIVE_GRAPHICS_ASCII || INTERACTIVE_GRAPHICS
841841
clock.start();
842-
for(uint d=0u; d<get_D(); d++) lbm[d]->enqueue_integrate_particles();
842+
for(uint d=0u; d<get_D(); d++) lbm[d]->enqueue_integrate_particles(time_step_multiplicator);
843843
for(uint d=0u; d<get_D(); d++) lbm[d]->finish_queue();
844-
for(uint d=0u; d<get_D(); d++) lbm[d]->increment_time_step();
844+
for(uint d=0u; d<get_D(); d++) lbm[d]->increment_time_step(time_step_multiplicator);
845845
info.update(clock.stop());
846846
}
847847
}

src/lbm.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class LBM_Domain {
9999
void enqueue_update_moving_boundaries(); // mark/unmark nodes next to TYPE_S nodes with velocity!=0 with TYPE_MS
100100
#endif // MOVING_BOUNDARIES
101101
#ifdef PARTICLES
102-
void enqueue_integrate_particles(); // intgegrates particles forward in time and couples particles to fluid
102+
void enqueue_integrate_particles(const uint time_step_multiplicator=1u); // intgegrates particles forward in time and couples particles to fluid
103103
#endif // PARTICLES
104104

105-
void increment_time_step(); // increment time step
105+
void increment_time_step(const uint steps=1u); // increment time step
106106
void reset_time_step(); // reset time step
107107
void finish_queue();
108108

@@ -387,7 +387,7 @@ class LBM {
387387
void update_moving_boundaries(); // mark/unmark nodes next to TYPE_S nodes with velocity!=0 with TYPE_MS
388388
#endif // MOVING_BOUNDARIES
389389
#if defined(PARTICLES)&&!defined(FORCE_FIELD)
390-
void integrate_particles(const ulong steps=max_ulong); // intgegrate passive tracer particles forward in time in stationary flow field
390+
void integrate_particles(const ulong steps=max_ulong, const uint time_step_multiplicator=1u); // intgegrate passive tracer particles forward in time in stationary flow field
391391
#endif // PARTICLES&&!FORCE_FIELD
392392

393393
uint get_Nx() const { return Nx; } // get (global) lattice dimensions in x-direction

src/utilities.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3927,13 +3927,13 @@ inline void write_line(const string& filename, const string& content="") {
39273927
file.write(s.c_str(), s.length());
39283928
file.close();
39293929
}
3930-
template<typename T> inline void write_file(const string& filename, const uint n, const T* y, const string& header="") {
3930+
template<typename T> inline void write_file(const string& filename, const string& header, const uint n, const T* y) {
39313931
string s = header;
39323932
if(length(s)>0u && !ends_with(s, "\n")) s += "\n";
39333933
for(uint i=0u; i<n; i++) s += to_string(i)+"\t"+to_string(y[i])+"\n";
39343934
write_file(filename, s);
39353935
}
3936-
template<typename T, typename U> inline void write_file(const string& filename, const uint n, const T* x, const U* y, const string& header="") {
3936+
template<typename T, typename U> inline void write_file(const string& filename, const string& header, const uint n, const T* x, const U* y) {
39373937
string s = header;
39383938
if(length(s)>0u && !ends_with(s, "\n")) s += "\n";
39393939
for(uint i=0u; i<n; i++) s += to_string(x[i])+"\t"+to_string(y[i])+"\n";

0 commit comments

Comments
 (0)