Tissue Forge C++ 0.2.1
Interactive, particle-based physics, chemistry and biology modeling and simulation environment
Loading...
Searching...
No Matches
tfUniverse.h
Go to the documentation of this file.
1/*******************************************************************************
2 * This file is part of Tissue Forge.
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 _SOURCE_TFUNIVERSE_H_
26#define _SOURCE_TFUNIVERSE_H_
27
28#include "TissueForge_private.h"
29#ifdef TF_FPTYPE_SINGLE
30#include <mdcore_single.h>
31#else
32#include <mdcore_double.h>
33#endif
34#include "io/tf_io.h"
35#include <unordered_map>
36#include "event/tfEventList.h"
37
38
39namespace TissueForge {
40
41
54 struct CAPI_EXPORT Universe {
55
56 enum Flags {
57 RUNNING = 1 << 0,
58
59 SHOW_PERF_STATS = 1 << 1,
60
61 // in ipython message loop, monitor console
62 IPYTHON_MSGLOOP = 1 << 2,
63
64 // standard polling message loop
65 POLLING_MSGLOOP = 1 << 3,
66 };
67
73 static FVector3 dim();
74
80 static FloatP_t volume();
81
82 bool isRunning = false;
83
85
86 // name of the model / script, usually picked up from command line;
87 std::string name;
88
92 static std::string getName();
93
104 static FMatrix3 *virial(FVector3 *origin=NULL, FloatP_t *radius=NULL, std::vector<ParticleType*> *types=NULL);
105
107 static FVector3 getCenter();
108
117 static HRESULT step(const FloatP_t &until=0, const FloatP_t &dt=0);
118
123 static HRESULT stop();
124
130 static HRESULT start();
131
132 static HRESULT reset();
133
134 static Universe* get();
135
140
144 static std::vector<int32_t> particleIds();
145
150 static void resetSpecies();
151
157 static std::vector<std::vector<std::vector<ParticleList> > > grid(iVector3 shape);
158
162 static std::vector<BondHandle> bonds();
163
167 static std::vector<AngleHandle> angles();
168
172 static std::vector<DihedralHandle> dihedrals();
173
183 static FloatP_t getTemperature();
184
188 static FloatP_t getTime();
189
193 static FloatP_t getDt();
194 static event::EventList *getEventList();
195
198
202 static FloatP_t getKineticEnergy();
203
207 static int getNumTypes();
208
212 static FloatP_t getCutoff();
213
217 static unsigned int getNumFluxSteps();
218 };
219
242
243 struct CAPI_EXPORT UniverseConfig {
245 FVector3 dim;
246
249
251 FloatP_t cutoff;
252 uint32_t flags;
253 uint32_t maxTypes;
254
256 FloatP_t dt;
257
260 FloatP_t temp;
261 int nParticles;
262
265
267 unsigned int nr_fluxsteps;
268
270 EngineIntegrator integrator;
271
272 // pointer to boundary conditions ctor data
273 // these objects are parsed initializing the engine.
274 BoundaryConditionsArgsContainer *boundaryConditionsPtr;
275
276 FloatP_t max_distance;
277
278 // bitmask of timers to show in performance counter output.
279 uint32_t timers_mask;
280
281 long timer_output_period;
282
283 UniverseConfig();
284
285 // just set the object, borow a pointer to python handle
286 void setBoundaryConditions(BoundaryConditionsArgsContainer *_bcArgs) {
287 boundaryConditionsPtr = _bcArgs;
288 }
289
291 if(boundaryConditionsPtr) {
292 delete boundaryConditionsPtr;
293 boundaryConditionsPtr = 0;
294 }
295 }
296 };
297
298
308 CAPI_FUNC(HRESULT) Universe_Step(FloatP_t until, FloatP_t dt);
309
313 CAPI_FUNC(int) Universe_Flag(Universe::Flags flag);
314
318 CAPI_FUNC(HRESULT) Universe_SetFlag(Universe::Flags flag, int value);
319
320
321
325 extern CAPI_EXPORT Universe _Universe;
326
331 CAPI_FUNC(Universe*) getUniverse();
332
333
334 namespace io {
335
336 template <>
337 HRESULT toFile(const Universe &dataElement, const MetaData &metaData, IOElement &fileElement);
338
339 template <>
340 HRESULT fromFile(const IOElement &fileElement, const MetaData &metaData, Universe *dataElement);
341
342 }
343
344};
345
346#endif // _SOURCE_TFUNIVERSE_H_
Tissue Forge I/O.
Definition tfThreeDFAngleMeshGenerator.h:28
HRESULT toFile(const T &dataElement, const MetaData &metaData, IOElement &fileElement)
Convert an object to an intermediate I/O object.
HRESULT fromFile(const IOElement &fileElement, const MetaData &metaData, T *dataElement)
Instantiate an object from an intermediate I/O object.
Native Tissue Forge type definitions.
Definition tfMatrix.h:33
Include Python header, disable linking to pythonX_d.lib on Windows in debug mode.
Definition tfAngleConfig.h:26
Universe _Universe
HRESULT Universe_Step(FloatP_t until, FloatP_t dt)
int Universe_Flag(Universe::Flags flag)
Universe * getUniverse()
HRESULT Universe_SetFlag(Universe::Flags flag, int value)
Definition tfBoundaryConditions.h:224
The BoundaryConditions class serves as a container for the six instances of the :class:BoundaryCondit...
Definition tfBoundaryConditions.h:117
A special list with convenience methods for working with sets of particles.
Definition tfParticleList.h:52
Initialize an engine with the given data.
Definition tfUniverse.h:243
long start_step
Definition tfUniverse.h:259
FVector3 dim
Definition tfUniverse.h:245
int threads
Definition tfUniverse.h:264
unsigned int nr_fluxsteps
Definition tfUniverse.h:267
FloatP_t cutoff
Definition tfUniverse.h:251
iVector3 spaceGridSize
Definition tfUniverse.h:248
EngineIntegrator integrator
Definition tfUniverse.h:270
FloatP_t dt
Definition tfUniverse.h:256
The universe is a top level singleton object, and is automatically initialized when the simulator loa...
Definition tfUniverse.h:54
static FVector3 dim()
Gets the dimensions of the universe.
static std::vector< AngleHandle > angles()
Get all angles in the universe.
static FloatP_t getKineticEnergy()
Get the current system kinetic energy.
static FMatrix3 * virial(FVector3 *origin=NULL, FloatP_t *radius=NULL, std::vector< ParticleType * > *types=NULL)
Computes the virial tensor for the either the entire simulation domain, or a specific local virial te...
static unsigned int getNumFluxSteps()
Get the number of flux steps per simulation step.
static std::vector< int32_t > particleIds()
Gets all particles in the universe.
static HRESULT stop()
Stops the universe time evolution. This essentially freezes the universe, everything remains the same...
static void resetSpecies()
Reset all species in all particles.
static HRESULT start()
Starts the universe time evolution, and advanced the universe forward by timesteps in dt....
static std::vector< DihedralHandle > dihedrals()
Get all dihedrals in the universe.
static HRESULT step(const FloatP_t &until=0, const FloatP_t &dt=0)
Performs a single time step dt of the universe if no arguments are given. Optionally runs until until...
static FloatP_t getTime()
Get the current time.
static FloatP_t volume()
Gets the volume of the universe.
static std::vector< BondHandle > bonds()
Get all bonds in the universe.
static FVector3 getCenter()
static FloatP_t getTemperature()
Get the universe temperature.
static std::string getName()
Get the name of the model / script.
static FloatP_t getCutoff()
Get the global interaction cutoff distance.
static int getNumTypes()
Get the current number of registered particle types.
static ParticleList particles()
Gets all particles in the universe.
static BoundaryConditions * getBoundaryConditions()
static std::vector< std::vector< std::vector< ParticleList > > > grid(iVector3 shape)
Gets a three-dimesional array of particle lists, of all the particles in the system.
static FloatP_t getDt()
Get the period of a time step.
Definition tfEventList.h:36
int32_t HRESULT
Definition tf_port.h:255