UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
c_loops.hh
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2// Modified version of Voro++'s source file
3
4// Voro++, a 3D cell-based Voronoi library
5//
6// Author : Chris H. Rycroft (LBL / UC Berkeley)
7// Email : chr@alum.mit.edu
8// Date : August 30th 2011
9
13#ifndef VOROPP_C_LOOPS_HH
14#define VOROPP_C_LOOPS_HH
15
17
18#include <cstddef>
19
20#include "config.hh"
21
22namespace voro {
23
31
45 public:
47 int *o;
50 int *op;
53 int size;
63 delete [] o;
64 }
70 inline void add(int ijk,int q) {
71 if(op==o+size) add_ordering_memory();
72 *(op++)=ijk;*(op++)=q;
73 }
74 private:
75 void add_ordering_memory();
76};
77
86 public:
88 const int nx;
90 const int ny;
92 const int nz;
96 const int nxy;
99 const int nxyz;
102 const int ps;
105 double **p;
108 int **id;
111 int *co;
114 int i;
117 int j;
120 int k;
123 int ijk;
126 int q;
130 template<class c_class>
131 c_loop_base(c_class &con) : nx(con.nx), ny(con.ny), nz(con.nz),
132 nxy(con.nxy), nxyz(con.nxyz), ps(con.ps),
133 p(con.p), id(con.id), co(con.co) {}
137 inline void pos(double &x,double &y,double &z) {
138 double *pp=p[ijk]+ps*q;
139 x=*(pp++);y=*(pp++);z=*pp;
140 }
148 inline void pos(int &pid,double &x,double &y,double &z,double &r) {
149 pid=id[ijk][q];
150 double *pp=p[ijk]+ps*q;
151 x=*(pp++);y=*(pp++);z=*pp;
152 r=ps==3?default_radius:*(++pp);
153 }
156 inline double x() {return p[ijk][ps*q];}
159 inline double y() {return p[ijk][ps*q+1];}
162 inline double z() {return p[ijk][ps*q+2];}
165 inline int pid() {return id[ijk][q];}
166};
167
172class c_loop_all : public c_loop_base {
173 public:
177 template<class c_class>
182 inline bool start() {
183 i=j=k=ijk=q=0;
184 while(co[ijk]==0) if(!next_block()) return false;
185 return true;
186 }
190 inline bool inc() {
191 q++;
192 if(q>=co[ijk]) {
193 q=0;
194 do {
195 if(!next_block()) return false;
196 } while(co[ijk]==0);
197 }
198 return true;
199 }
200 private:
205 inline bool next_block() {
206 ijk++;
207 i++;
208 if(i==nx) {
209 i=0;j++;
210 if(j==ny) {
211 j=0;k++;
212 if(ijk==nxyz) return false;
213 }
214 }
215 return true;
216 }
217};
218
223 public:
227 template<class c_class>
232 inline bool start() {
233 ijk = ijk_start;
234 checkSlow(ijk >= 0 && ijk < nxyz);
235 k = ijk / nxy;
236 int ijkt = ijk - nxy * k;
237 j = ijkt / nx;
238 i = ijkt - j * nx;
239 q=0;
240 while(co[ijk]==0) if(!next_block()) return false;
241 return true;
242 }
244 {
245 ijk_start = ijk_start_in;
246 ijk_stop = ijk_stop_in;
247
248 check(ijk_start >= 0 && ijk_start < nxyz && ijk_stop >= 0 && ijk_stop <= nxyz);
249 checkSlow(ijk_start < ijk_stop);
250 }
254 inline bool inc() {
255 q++;
256 if(q>=co[ijk]) {
257 q=0;
258 do {
259 if(!next_block()) return false;
260 } while(co[ijk]==0);
261 }
262 return true;
263 }
264 private:
265 int ijk_start = 0, ijk_stop = 0;
266
271 inline bool next_block() {
272 ijk++;
273 if (ijk >= ijk_stop) return false;
274 i++;
275 if(i==nx) {
276 i=0;j++;
277 if(j==ny) {
278 j=0;k++;
279 }
280 }
281 return true;
282 }
283};
284
292 public:
300 template<class c_class>
301 c_loop_subset(c_class &con) : c_loop_base(con), ax(con.ax), ay(con.ay), az(con.az),
302 sx(con.bx-ax), sy(con.by-ay), sz(con.bz-az), xsp(con.xsp), ysp(con.ysp), zsp(con.zsp),
303 xperiodic(con.xperiodic), yperiodic(con.yperiodic), zperiodic(con.zperiodic) {}
304 void setup_sphere(double vx,double vy,double vz,double r,bool bounds_test=true);
305 void setup_box(double xmin,double xmax,double ymin,double ymax,double zmin,double zmax,bool bounds_test=true);
306 void setup_intbox(int ai_,int bi_,int aj_,int bj_,int ak_,int bk_);
307 bool start();
311 inline bool inc() {
312 do {
313 q++;
314 while(q>=co[ijk]) {q=0;if(!next_block()) return false;}
315 } while(mode!=no_check&&out_of_bounds());
316 return true;
317 }
318 private:
319 const double ax,ay,az,sx,sy,sz,xsp,ysp,zsp;
320 double px,py,pz,apx,apy,apz;
321 double v0,v1,v2,v3,v4,v5;
322 int ai,bi,aj,bj,ak,bk;
323 int ci,cj,ck,di,dj,dk,inc1,inc2;
324 const bool xperiodic,yperiodic,zperiodic;
325 inline int step_mod(int a,int b) const {return a>=0?a%b:b-1-(b-1-a)%b;}
326 inline int step_div(int a,int b) const {return a>=0?a/b:-1+(a+1)/b;}
327 inline int step_int(double a) const {return a<0?int(a)-1:int(a);}
328 void setup_common();
329 bool next_block();
330 bool out_of_bounds();
331};
332
341class c_loop_order : public c_loop_base {
342 public:
346 int *cp;
348 int *op;
354 template<class c_class>
356 : c_loop_base(con), vo(vo_), nx(con.nx), nxy(con.nxy) {}
360 inline bool start() {
361 cp=vo.o;op=vo.op;
362 if(cp!=op) {
363 ijk=*(cp++);decode();
364 q=*(cp++);
365 return true;
366 } else return false;
367 }
371 inline bool inc() {
372 if(cp==op) return false;
373 ijk=*(cp++);decode();
374 q=*(cp++);
375 return true;
376 }
377 private:
379 const int nx;
381 const int nxy;
384 inline void decode() {
385 k=ijk/nxy;
386 int ijkt=ijk-nxy*k;
387 j=ijkt/nx;
388 i=ijkt-j*nx;
389 }
390};
391
399 public:
403 template<class c_class>
404 c_loop_all_periodic(c_class &con) : c_loop_base(con), ey(con.ey), ez(con.ez), wy(con.wy), wz(con.wz),
405 ijk0(nx*(ey+con.oy*ez)), inc2(2*nx*con.ey+1) {}
409 inline bool start() {
410 i=0;
411 j=ey;
412 k=ez;
413 ijk=ijk0;
414 q=0;
415 while(co[ijk]==0) if(!next_block()) return false;
416 return true;
417 }
421 inline bool inc() {
422 q++;
423 if(q>=co[ijk]) {
424 q=0;
425 do {
426 if(!next_block()) return false;
427 } while(co[ijk]==0);
428 }
429 return true;
430 }
431 private:
434 int ey;
437 int ez;
440 int wy;
443 int wz;
446 int ijk0;
449 int inc2;
454 inline bool next_block() {
455 i++;
456 if(i==nx) {
457 i=0;j++;
458 if(j==wy) {
459 j=ey;k++;
460 if(k==wz) return false;
461 ijk+=inc2;
462 } else ijk++;
463 } else ijk++;
464 return true;
465 }
466};
467
477 public:
481 int *cp;
483 int *op;
489 template<class c_class>
491 : c_loop_base(con), vo(vo_), nx(con.nx), oxy(con.nx*con.oy) {}
495 inline bool start() {
496 cp=vo.o;op=vo.op;
497 if(cp!=op) {
498 ijk=*(cp++);decode();
499 q=*(cp++);
500 return true;
501 } else return false;
502 }
506 inline bool inc() {
507 if(cp==op) return false;
508 ijk=*(cp++);decode();
509 q=*(cp++);
510 return true;
511 }
512 private:
514 const int nx;
516 const int oxy;
519 inline void decode() {
520 k=ijk/oxy;
521 int ijkt=ijk-oxy*k;
522 j=ijkt/nx;
523 i=ijkt-j*nx;
524 }
525};
526
527}
528
529#endif
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
A class for looping over all particles in a container_periodic or container_periodic_poly class.
Definition c_loops.hh:398
c_loop_all_periodic(c_class &con)
Definition c_loops.hh:404
bool start()
Definition c_loops.hh:409
bool inc()
Definition c_loops.hh:421
Class for looping over all of the particles in a container.
Definition c_loops.hh:172
c_loop_all(c_class &con)
Definition c_loops.hh:178
bool inc()
Definition c_loops.hh:190
bool start()
Definition c_loops.hh:182
Base class for looping over particles in a container.
Definition c_loops.hh:85
int * co
Definition c_loops.hh:111
const int nx
Definition c_loops.hh:88
double ** p
Definition c_loops.hh:105
int q
Definition c_loops.hh:126
double y()
Definition c_loops.hh:159
void pos(int &pid, double &x, double &y, double &z, double &r)
Definition c_loops.hh:148
int ijk
Definition c_loops.hh:123
const int nxyz
Definition c_loops.hh:99
double x()
Definition c_loops.hh:156
int pid()
Definition c_loops.hh:165
const int nz
Definition c_loops.hh:92
const int ps
Definition c_loops.hh:102
int ** id
Definition c_loops.hh:108
const int nxy
Definition c_loops.hh:96
int j
Definition c_loops.hh:117
int k
Definition c_loops.hh:120
const int ny
Definition c_loops.hh:90
void pos(double &x, double &y, double &z)
Definition c_loops.hh:137
c_loop_base(c_class &con)
Definition c_loops.hh:131
double z()
Definition c_loops.hh:162
int i
Definition c_loops.hh:114
Class for looping over the particles in a range of blocks within a container.
Definition c_loops.hh:222
bool inc()
Definition c_loops.hh:254
c_loop_block_range(c_class &con)
Definition c_loops.hh:228
bool start()
Definition c_loops.hh:232
void setup_range(int ijk_start_in, int ijk_stop_in)
Definition c_loops.hh:243
Class for looping over all of the particles specified in a pre-assembled particle_order class,...
Definition c_loops.hh:476
int * cp
Definition c_loops.hh:481
bool start()
Definition c_loops.hh:495
particle_order & vo
Definition c_loops.hh:479
int * op
Definition c_loops.hh:483
c_loop_order_periodic(c_class &con, particle_order &vo_)
Definition c_loops.hh:490
bool inc()
Definition c_loops.hh:506
Class for looping over all of the particles specified in a pre-assembled particle_order class.
Definition c_loops.hh:341
c_loop_order(c_class &con, particle_order &vo_)
Definition c_loops.hh:355
bool start()
Definition c_loops.hh:360
particle_order & vo
Definition c_loops.hh:344
int * op
Definition c_loops.hh:348
int * cp
Definition c_loops.hh:346
bool inc()
Definition c_loops.hh:371
Class for looping over a subset of particles in a container.
Definition c_loops.hh:291
void setup_box(double xmin, double xmax, double ymin, double ymax, double zmin, double zmax, bool bounds_test=true)
Definition c_loops.cc:101
bool start()
Definition c_loops.cc:82
void setup_sphere(double vx, double vy, double vz, double r, bool bounds_test=true)
Definition c_loops.cc:27
void setup_intbox(int ai_, int bi_, int aj_, int bj_, int ak_, int bk_)
Definition c_loops.cc:47
c_loop_subset(c_class &con)
Definition c_loops.hh:301
c_loop_subset_mode mode
Definition c_loops.hh:296
bool inc()
Definition c_loops.hh:311
A class for storing ordering information when particles are added to a container.
Definition c_loops.hh:44
particle_order(int init_size=init_ordering_size)
Definition c_loops.hh:58
int * op
Definition c_loops.hh:50
int size
Definition c_loops.hh:53
void add(int ijk, int q)
Definition c_loops.hh:70
~particle_order()
Definition c_loops.hh:62
int * o
Definition c_loops.hh:47
Master configuration file for setting various compile-time options.
int
Definition TestServer.py:515
Definition c_loops.cc:15
const int init_ordering_size
Definition config.hh:38
c_loop_subset_mode
Definition c_loops.hh:26
@ no_check
Definition c_loops.hh:29
@ sphere
Definition c_loops.hh:27
@ box
Definition c_loops.hh:28
const double default_radius
Definition config.hh:97