Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfBoundaryConditions.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of mdcore.
3 * Copyright (c) 2022-2024 T.J. Sego
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 ******************************************************************************/
19
24
25#ifndef _MDCORE_INCLUDE_TFBOUNDARYCONDITIONS_H_
26#define _MDCORE_INCLUDE_TFBOUNDARYCONDITIONS_H_
27
28#include <mdcore_config.h>
29#include <types/tf_types.h>
30#include <io/tf_io.h>
31
32#include <unordered_map>
33
34
35namespace TissueForge {
36
37
38 enum BoundaryConditionKind : unsigned int {
39 BOUNDARY_VELOCITY = 1 << 0,
40 BOUNDARY_PERIODIC = 1 << 1,
41 BOUNDARY_FREESLIP = 1 << 2,
42 BOUNDARY_POTENTIAL = 1 << 3,
43 BOUNDARY_NO_SLIP = 1 << 4, // really just velocity with zero velocity
44 BOUNDARY_RESETTING = 1 << 5, // reset the chemical cargo when particles cross boundaries.
45 BOUNDARY_ACTIVE = BOUNDARY_FREESLIP | BOUNDARY_VELOCITY | BOUNDARY_POTENTIAL
46 };
47
48 struct ParticleType;
49 struct Potential;
50
55 struct CAPI_EXPORT BoundaryCondition {
56 BoundaryConditionKind kind;
57
58 // id of this boundary, id's go from 0 to 6 (top, bottom, etc..)
59 int id;
60
64 FVector3 velocity;
65
73 FPTYPE restore;
74
78 const char* name;
79
83 FVector3 normal;
84
89
90 // many potentials act on the sum of both particle radii, so this
91 // paramter makes it looks like the wall has a sheet of particles of
92 // radius.
93 FPTYPE radius;
94
98 void set_potential(struct ParticleType *ptype, struct Potential *pot);
99
100 std::string kindStr() const;
101 std::string str(bool show_name) const;
102
103 unsigned init(const unsigned &kind);
104 unsigned init(const FVector3 &velocity, const FPTYPE *restore=NULL);
105 unsigned init(
106 const std::unordered_map<std::string, unsigned int> vals,
107 const std::unordered_map<std::string, FVector3> vels,
108 const std::unordered_map<std::string, FPTYPE> restores
109 );
110 };
111
117 struct CAPI_EXPORT BoundaryConditions {
118
123
128
133
138
143
148
149 // pointer to big array of potentials, 6 * max types.
150 // each boundary condition has a pointer that's an offset
151 // into this array, so allocate and free in single block.
152 // allocated in BoundaryConditions_Init.
153 struct Potential **potenntials;
154
158 static void boundedPosition(FVector3& position);
159
163 static FVector3 boundedPosition(const FVector3& position);
164
165 BoundaryConditions() {}
166 BoundaryConditions(int *cells);
167 BoundaryConditions(int *cells, const int &value);
169 int *cells,
170 const std::unordered_map<std::string, unsigned int> vals,
171 const std::unordered_map<std::string, FVector3> vels,
172 const std::unordered_map<std::string, FPTYPE> restores
173 );
174
181 void set_potential(struct ParticleType *ptype, struct Potential *pot);
182
186 uint32_t periodic;
187
188 static unsigned boundaryKindFromString(const std::string &s);
189 static unsigned boundaryKindFromStrings(const std::vector<std::string> &kinds);
190
191 std::string str();
192
198 std::string toString();
199
206 static BoundaryConditions *fromString(const std::string &str);
207
208 private:
209
210 HRESULT _initIni();
211 HRESULT _initFin(int *cells);
212
213 // processes directional initialization inputs
214 void _initDirections(const std::unordered_map<std::string, unsigned int> vals);
215
216 // processes sides initialization inputs
217 void _initSides(
218 const std::unordered_map<std::string, unsigned int> vals,
219 const std::unordered_map<std::string, FVector3> vels,
220 const std::unordered_map<std::string, FPTYPE> restores
221 );
222 };
223
224 struct CAPI_EXPORT BoundaryConditionsArgsContainer {
225 int *bcValue;
226 std::unordered_map<std::string, unsigned int> *bcVals;
227 std::unordered_map<std::string, FVector3> *bcVels;
228 std::unordered_map<std::string, FPTYPE> *bcRestores;
229
230 void setValueAll(const int &_bcValue);
231 void setValue(const std::string &name, const unsigned int &value);
232 void setVelocity(const std::string &name, const FVector3 &velocity);
233 void setRestore(const std::string &name, const FPTYPE restore);
234
235 BoundaryConditions *create(int *cells);
236
237 BoundaryConditionsArgsContainer(
238 int *_bcValue=NULL,
239 std::unordered_map<std::string, unsigned int> *_bcVals=NULL,
240 std::unordered_map<std::string, FVector3> *_bcVels=NULL,
241 std::unordered_map<std::string, FPTYPE> *_bcRestores=NULL
242 );
243
244 private:
245 void switchType(const bool &allSides);
246 };
247
253 struct Particle *p,
254 const int *delta,
255 const struct space_cell *source_cell,
256 const struct space_cell *dest_cell
257 );
258
259
260};
261
262#endif // _MDCORE_INCLUDE_TFBOUNDARYCONDITIONS_H_
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
void apply_boundary_particle_crossing(struct Particle *p, const int *delta, const struct space_cell *source_cell, const struct space_cell *dest_cell)
A condition on a boundary of the universe.
Definition tfBoundaryConditions.h:55
FPTYPE restore
restoring percent.
Definition tfBoundaryConditions.h:73
void set_potential(struct ParticleType *ptype, struct Potential *pot)
FVector3 normal
vector normal to the boundary
Definition tfBoundaryConditions.h:83
const char * name
name of the boundary
Definition tfBoundaryConditions.h:78
FVector3 velocity
the velocity on the boundary
Definition tfBoundaryConditions.h:64
struct Potential ** potenntials
Definition tfBoundaryConditions.h:88
The BoundaryConditions class serves as a container for the six instances of the :class:BoundaryCondit...
Definition tfBoundaryConditions.h:117
BoundaryCondition front
The front boundary.
Definition tfBoundaryConditions.h:142
static FVector3 boundedPosition(const FVector3 &position)
Enforce boundary conditions on a position.
std::string toString()
Get a JSON string representation.
static BoundaryConditions * fromString(const std::string &str)
Create from a JSON string representation.
BoundaryCondition top
The top boundary.
Definition tfBoundaryConditions.h:122
uint32_t periodic
Definition tfBoundaryConditions.h:186
static void boundedPosition(FVector3 &position)
Enforce boundary conditions on a position.
void set_potential(struct ParticleType *ptype, struct Potential *pot)
sets a potential for ALL boundary conditions and the given potential.
BoundaryCondition bottom
The bottom boundary.
Definition tfBoundaryConditions.h:127
BoundaryCondition back
The back boundary.
Definition tfBoundaryConditions.h:147
BoundaryCondition right
The right boundary.
Definition tfBoundaryConditions.h:137
BoundaryCondition left
The left boundary.
Definition tfBoundaryConditions.h:132
Definition tfParticle.h:101
Structure containing information on each particle type.
Definition tfParticle.h:768
A Potential object is a compiled interpolation of a given function. The Universe applies potentials t...
Definition tfPotential.h:213
the space_cell structure
Definition tfSpace_cell.h:103
int32_t HRESULT
Definition tf_port.h:255