Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfSpace.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of mdcore.
3 * Coypright (c) 2010 Pedro Gonnet (pedro.gonnet@durham.ac.uk)
4 * Coypright (c) 2017 Andy Somogyi (somogyie at indiana dot edu)
5 * Copyright (c) 2022-2024 T.J. Sego
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 ******************************************************************************/
21
26
27#ifndef _MDCORE_INCLUDE_TFSPACE_H_
28#define _MDCORE_INCLUDE_TFSPACE_H_
29#include <mdcore_config.h>
30#include "tfSpace_cell.h"
31
32#include <vector>
33
34
35#define space_partlist_incr 100
36
38#define space_maxtuples 4
39
41#define space_verlet_maxpairs 800
42
43/* some useful macros */
46#define space_cellid(s,i,j,k) ( ((i)*(s)->cdim[1] + (j)) * (s)->cdim[2] + (k) )
47#define celldims_cellid(cdim,i,j,k) ( ((i)*cdim[1] + (j)) * cdim[2] + (k) )
48
50#define space_pairind(i,j) ( space_maxtuples*(i) - (i)*((i)+1)/2 + (j) )
51
52
53namespace TissueForge {
54
55
56 /* some constants */
57 enum PeriodicFlags {
58 space_periodic_none = 0,
59 space_periodic_x = 1 << 0,
60 space_periodic_y = 1 << 1,
61 space_periodic_z = 1 << 2,
62 space_periodic_full = (1 << 0) | (1 << 1) | (1 << 2),
63 space_periodic_ghost_x = 1 << 3,
64 space_periodic_ghost_y = 1 << 4,
65 space_periodic_ghost_z = 1 << 5,
66 space_periodic_ghost_full = (1 << 3) | (1 << 4) | (1 << 5),
67 SPACE_FREESLIP_X = 1 << 6,
68 SPACE_FREESLIP_Y = 1 << 7,
69 SPACE_FREESLIP_Z = 1 << 8,
70 SPACE_FREESLIP_FULL = (1 << 6) | (1 << 7) | (1 << 8),
71 };
72
73
75 struct verlet_entry {
76
78 struct Particle *p;
79
81 struct Potential *pot;
82
84 signed char shift[3];
85
86 };
87
89 struct cellpair {
90
92 int i, j;
93
95 FPTYPE shift[3];
96
98 int size, count;
99 short int *pairs;
100 short int *nr_pairs;
101
103 struct cellpair *next;
104
105 };
106
108 struct celltuple {
109
112
114 int n;
115
118
119 /* Buffer value to keep the size at 64 bytes for space_maxtuples==4. */
120 int buff;
121
122 };
123
127 typedef struct space {
129 FPTYPE dim[3];
130
132 FPTYPE origin[3];
133
135 int cdim[3];
136
138 int span[3];
139
141 FPTYPE h[3], ih[3];
142
144 FPTYPE cutoff, cutoff2;
145
147 unsigned int period;
148
151
153 int *cid_real, *cid_ghost, *cid_marked;
154 int nr_real, nr_ghost, nr_marked;
155
158
160 int nr_tasks, tasks_size;
161
163 struct task *tasks;
164
166 pthread_mutex_t tasks_mutex;
167 pthread_cond_t tasks_avail;
168
171
174
176 int nr_swaps, nr_stalls;
177
180
183
186
188 int nr_parts, size_parts;
189
198 int nr_visible_large_parts;
199
202
204 FPTYPE maxdx;
205
207 FPTYPE epot, epot_nonbond, epot_bond, epot_angle, epot_dihedral, epot_exclusion;
208
211 FPTYPE *verlet_oldx, verlet_maxdx;
212 int *verlet_nrpairs;
213 int verlet_size, verlet_next;
214 pthread_mutex_t verlet_force_mutex;
215
218
221
224
227
230
232 int next_tuple, next_cell;
233
235 pthread_mutex_t cellpairs_mutex;
236
238 //lock_type cellpairs_spinlock;
239
241 pthread_cond_t cellpairs_avail;
242
244
245
246 /* associated functions */
247
265 CAPI_FUNC(HRESULT) space_init(
266 struct space *s,
267 const FPTYPE *origin,
268 const FPTYPE *dim,
269 FPTYPE *L,
270 FPTYPE cutoff,
271 const struct BoundaryConditions *bc
272 );
273
281 CAPI_FUNC(int) space_getsid(
282 struct space *s,
283 struct space_cell **ci,
284 struct space_cell **cj,
285 FPTYPE *shift
286 );
287
297 CAPI_FUNC(HRESULT) space_shuffle(struct space *s);
298
308 CAPI_FUNC(HRESULT) space_shuffle_local(struct space *s);
309
316 CAPI_FUNC(HRESULT) space_growparts(struct space *s, unsigned int size_incr);
317
338 struct space *s,
339 struct Particle *p,
340 FPTYPE *x,
341 struct Particle **result
342 );
343
344 CAPI_FUNC(HRESULT) space_addparts(
345 struct space *s,
346 int nr_parts,
347 struct Particle **parts,
348 FPTYPE **xparts
349 );
350
360 CAPI_FUNC(int) space_get_cellids_for_pos(struct space *s, FPTYPE *x, int *cellids);
361
371 CAPI_FUNC(HRESULT) space_del_particle(struct space *s, int pid);
372
373
378 CAPI_FUNC(HRESULT) space_update_style(struct space *s);
379
387 CAPI_FUNC(HRESULT) space_prepare_tasks(struct space *s);
388
397 CAPI_FUNC(HRESULT) space_prepare(struct space *s);
398
408 CAPI_FUNC(HRESULT) space_getpos(struct space *s, int id, FPTYPE *x);
409
418 CAPI_FUNC(HRESULT) space_setpos(struct space *s, int id, FPTYPE *x);
419
425 CAPI_FUNC(HRESULT) space_flush(struct space *s);
426
432 CAPI_FUNC(HRESULT) space_flush_ghosts(struct space *s);
433
446 CAPI_FUNC(struct task*) space_addtask(
447 struct space *s,
448 int type,
449 int subtype,
450 int flags,
451 int i,
452 int j
453 );
454
460 CAPI_FUNC(HRESULT) space_verlet_init(struct space *s, int list_global);
461
473 CAPI_FUNC(int) space_gettuple(struct space *s, struct celltuple **out, int wait);
474
484 CAPI_FUNC(int) space_getcell(struct space *s, struct space_cell **out);
485
498 CAPI_FUNC(int) space_verlet_force(struct space *s, FPTYPE *f, FPTYPE epot);
499
513 CAPI_FUNC(HRESULT) space_releasepair(struct space *s, int ci, int cj);
514
515};
516
517#endif // _MDCORE_INCLUDE_TFSPACE_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
HRESULT space_prepare(struct space *s)
Prepare the space before a time step.
int space_get_cellids_for_pos(struct space *s, FPTYPE *x, int *cellids)
HRESULT space_prepare_tasks(struct space *s)
Prepare the tasks before a time step.
int space_verlet_force(struct space *s, FPTYPE *f, FPTYPE epot)
Collect forces and potential energies.
struct task * space_addtask(struct space *s, int type, int subtype, int flags, int i, int j)
Add a task to the given space.
HRESULT space_addpart(struct space *s, struct Particle *p, FPTYPE *x, struct Particle **result)
Add a #part to a space at the given coordinates. The given particle p is only used for the attributes...
HRESULT space_shuffle(struct space *s)
Run through the cells of a space and make sure every particle is in its place.
HRESULT space_flush_ghosts(struct space *s)
Clear all particles from the ghost cells in this space.
HRESULT space_setpos(struct space *s, int id, FPTYPE *x)
Set the absolute position of a particle.
HRESULT space_releasepair(struct space *s, int ci, int cj)
Free the cells involved in the current pair.
HRESULT space_getpos(struct space *s, int id, FPTYPE *x)
Get the absolute position of a particle.
HRESULT space_init(struct space *s, const FPTYPE *origin, const FPTYPE *dim, FPTYPE *L, FPTYPE cutoff, const struct BoundaryConditions *bc)
Initialize the space with the given dimensions.
HRESULT space_update_style(struct space *s)
int space_getcell(struct space *s, struct space_cell **out)
Get the next unprocessed cell from the spaece.
HRESULT space_del_particle(struct space *s, int pid)
HRESULT space_verlet_init(struct space *s, int list_global)
Initialize the Verlet-list data structures.
HRESULT space_shuffle_local(struct space *s)
Run through the non-ghost cells of a space and make sure every particle is in its place.
HRESULT space_flush(struct space *s)
Clear all particles from this space.
struct TissueForge::space space
int space_gettuple(struct space *s, struct celltuple **out, int wait)
Get the next free celltuple from the space.
int space_getsid(struct space *s, struct space_cell **ci, struct space_cell **cj, FPTYPE *shift)
Get the sort-ID and flip the cells if necessary.
HRESULT space_growparts(struct space *s, unsigned int size_incr)
Grow the parts allocated to a space.
The BoundaryConditions class serves as a container for the six instances of the :class:BoundaryCondit...
Definition tfBoundaryConditions.h:117
Definition tfParticle.h:101
A Potential object is a compiled interpolation of a given function. The Universe applies potentials t...
Definition tfPotential.h:213
Definition tfSpace.h:89
FPTYPE shift[3]
Definition tfSpace.h:95
struct cellpair * next
Definition tfSpace.h:103
int i
Definition tfSpace.h:92
int size
Definition tfSpace.h:98
Definition tfSpace.h:108
int cellid[4]
Definition tfSpace.h:111
int pairid[4 *(4+1)/2]
Definition tfSpace.h:117
int n
Definition tfSpace.h:114
the space_cell structure
Definition tfSpace_cell.h:103
Definition tfSpace.h:127
pthread_mutex_t cellpairs_mutex
Definition tfSpace.h:235
FPTYPE dim[3]
Definition tfSpace.h:129
struct celltuple * tuples
Definition tfSpace.h:226
struct verlet_entry * verlet_list
Definition tfSpace.h:210
int span[3]
Definition tfSpace.h:138
int * cid_real
Definition tfSpace.h:153
int next_pair
Definition tfSpace.h:223
int nr_cells
Definition tfSpace.h:150
struct space_cell * cells
Definition tfSpace.h:157
char * cells_owner
Definition tfSpace.h:173
FPTYPE epot
Definition tfSpace.h:207
FPTYPE cutoff
Definition tfSpace.h:144
struct task * tasks
Definition tfSpace.h:163
char * cells_taboo
Definition tfSpace.h:170
FPTYPE origin[3]
Definition tfSpace.h:132
pthread_cond_t cellpairs_avail
Definition tfSpace.h:241
struct space_cell ** celllist
Definition tfSpace.h:185
FPTYPE maxdx
Definition tfSpace.h:204
pthread_mutex_t tasks_mutex
Definition tfSpace.h:166
int nr_parts
Definition tfSpace.h:188
unsigned int period
Definition tfSpace.h:147
struct cellpair * pairs
Definition tfSpace.h:220
int next_tuple
Definition tfSpace.h:232
FPTYPE h[3]
Definition tfSpace.h:141
int nr_visible_parts
Definition tfSpace.h:197
int nr_pairs
Definition tfSpace.h:217
int nr_tasks
Definition tfSpace.h:160
int nr_swaps
Definition tfSpace.h:176
int nr_tuples
Definition tfSpace.h:229
int verlet_rebuild
Definition tfSpace.h:201
struct Particle ** partlist
Definition tfSpace.h:179
int cdim[3]
Definition tfSpace.h:135
space_cell largeparts
Definition tfSpace.h:182
Definition tfTask.h:60
Definition tfSpace.h:75
struct Particle * p
Definition tfSpace.h:78
struct Potential * pot
Definition tfSpace.h:81
signed char shift[3]
Definition tfSpace.h:84
int32_t HRESULT
Definition tf_port.h:255
#define space_maxtuples
Definition tfSpace.h:38