Welcome to mirror list, hosted at ThFree Co, Russian Federation.

fluidsolver.h « preprocessed « mantaflow « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6770f8b7b05b772cc9bfe5f83ffdd5bb3e9fb1c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396


// DO NOT EDIT !
// This file is generated using the MantaFlow preprocessor (prep generate).

/******************************************************************************
 *
 * MantaFlow fluid solver framework
 * Copyright 2011 Tobias Pfaff, Nils Thuerey
 *
 * This program is free software, distributed under the terms of the
 * Apache License, Version 2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Main class for the fluid solver
 *
 ******************************************************************************/

#ifndef _FLUIDSOLVER_H
#define _FLUIDSOLVER_H

#include "manta.h"
#include "vectorbase.h"
#include "vector4d.h"
#include <vector>
#include <map>

namespace Manta {

//! Encodes grid size, timstep etc.

class FluidSolver : public PbClass {
 public:
  FluidSolver(Vec3i gridSize, int dim = 3, int fourthDim = -1);
  static int _W_0(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    PbClass *obj = Pb::objFromPy(_self);
    if (obj)
      delete obj;
    try {
      PbArgs _args(_linargs, _kwds);
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(0, "FluidSolver::FluidSolver", !noTiming);
      {
        ArgLocker _lock;
        Vec3i gridSize = _args.get<Vec3i>("gridSize", 0, &_lock);
        int dim = _args.getOpt<int>("dim", 1, 3, &_lock);
        int fourthDim = _args.getOpt<int>("fourthDim", 2, -1, &_lock);
        obj = new FluidSolver(gridSize, dim, fourthDim);
        obj->registerObject(_self, &_args);
        _args.check();
      }
      pbFinalizePlugin(obj->getParent(), "FluidSolver::FluidSolver", !noTiming);
      return 0;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::FluidSolver", e.what());
      return -1;
    }
  }

  virtual ~FluidSolver();

  // accessors
  Vec3i getGridSize()
  {
    return mGridSize;
  }
  static PyObject *_W_1(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    try {
      PbArgs _args(_linargs, _kwds);
      FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(_self));
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(pbo->getParent(), "FluidSolver::getGridSize", !noTiming);
      PyObject *_retval = nullptr;
      {
        ArgLocker _lock;
        pbo->_args.copy(_args);
        _retval = toPy(pbo->getGridSize());
        pbo->_args.check();
      }
      pbFinalizePlugin(pbo->getParent(), "FluidSolver::getGridSize", !noTiming);
      return _retval;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::getGridSize", e.what());
      return 0;
    }
  }

  inline Real getDt() const
  {
    return mDt;
  }
  inline Real getDx() const
  {
    return 1.0 / mGridSize.max();
  }
  inline Real getTime() const
  {
    return mTimeTotal;
  }

  //! Check dimensionality
  inline bool is2D() const
  {
    return mDim == 2;
  }
  //! Check dimensionality (3d or above)
  inline bool is3D() const
  {
    return mDim == 3;
  }

  void printMemInfo();
  static PyObject *_W_2(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    try {
      PbArgs _args(_linargs, _kwds);
      FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(_self));
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(pbo->getParent(), "FluidSolver::printMemInfo", !noTiming);
      PyObject *_retval = nullptr;
      {
        ArgLocker _lock;
        pbo->_args.copy(_args);
        _retval = getPyNone();
        pbo->printMemInfo();
        pbo->_args.check();
      }
      pbFinalizePlugin(pbo->getParent(), "FluidSolver::printMemInfo", !noTiming);
      return _retval;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::printMemInfo", e.what());
      return 0;
    }
  }

  //! Advance the solver one timestep, update GUI if present
  void step();
  static PyObject *_W_3(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    try {
      PbArgs _args(_linargs, _kwds);
      FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(_self));
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(pbo->getParent(), "FluidSolver::step", !noTiming);
      PyObject *_retval = nullptr;
      {
        ArgLocker _lock;
        pbo->_args.copy(_args);
        _retval = getPyNone();
        pbo->step();
        pbo->_args.check();
      }
      pbFinalizePlugin(pbo->getParent(), "FluidSolver::step", !noTiming);
      return _retval;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::step", e.what());
      return 0;
    }
  }

  //! Update the timestep size based on given maximal velocity magnitude
  void adaptTimestep(Real maxVel);
  static PyObject *_W_4(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    try {
      PbArgs _args(_linargs, _kwds);
      FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(_self));
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(pbo->getParent(), "FluidSolver::adaptTimestep", !noTiming);
      PyObject *_retval = nullptr;
      {
        ArgLocker _lock;
        Real maxVel = _args.get<Real>("maxVel", 0, &_lock);
        pbo->_args.copy(_args);
        _retval = getPyNone();
        pbo->adaptTimestep(maxVel);
        pbo->_args.check();
      }
      pbFinalizePlugin(pbo->getParent(), "FluidSolver::adaptTimestep", !noTiming);
      return _retval;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::adaptTimestep", e.what());
      return 0;
    }
  }

  //! create a object with the solver as its parent
  PbClass *create(PbType type, PbTypeVec T = PbTypeVec(), const std::string &name = "");
  static PyObject *_W_5(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
  {
    try {
      PbArgs _args(_linargs, _kwds);
      FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(_self));
      bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
      pbPreparePlugin(pbo->getParent(), "FluidSolver::create", !noTiming);
      PyObject *_retval = nullptr;
      {
        ArgLocker _lock;
        PbType type = _args.get<PbType>("type", 0, &_lock);
        PbTypeVec T = _args.getOpt<PbTypeVec>("T", 1, PbTypeVec(), &_lock);
        const std::string &name = _args.getOpt<std::string>("name", 2, "", &_lock);
        pbo->_args.copy(_args);
        _retval = toPy(pbo->create(type, T, name));
        pbo->_args.check();
      }
      pbFinalizePlugin(pbo->getParent(), "FluidSolver::create", !noTiming);
      return _retval;
    }
    catch (std::exception &e) {
      pbSetError("FluidSolver::create", e.what());
      return 0;
    }
  }

  // temp grid and plugin functions: you shouldn't call this manually
  template<class T> T *getGridPointer();
  template<class T> void freeGridPointer(T *ptr);

  //! expose animation time to python
  Real mDt;
  static PyObject *_GET_mDt(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mDt);
  }
  static int _SET_mDt(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mDt = fromPy<Real>(val);
    return 0;
  }

  Real mTimeTotal;
  static PyObject *_GET_mTimeTotal(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mTimeTotal);
  }
  static int _SET_mTimeTotal(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mTimeTotal = fromPy<Real>(val);
    return 0;
  }

  int mFrame;
  static PyObject *_GET_mFrame(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mFrame);
  }
  static int _SET_mFrame(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mFrame = fromPy<int>(val);
    return 0;
  }

  //! parameters for adaptive time stepping
  Real mCflCond;
  static PyObject *_GET_mCflCond(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mCflCond);
  }
  static int _SET_mCflCond(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mCflCond = fromPy<Real>(val);
    return 0;
  }

  Real mDtMin;
  static PyObject *_GET_mDtMin(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mDtMin);
  }
  static int _SET_mDtMin(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mDtMin = fromPy<Real>(val);
    return 0;
  }

  Real mDtMax;
  static PyObject *_GET_mDtMax(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mDtMax);
  }
  static int _SET_mDtMax(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mDtMax = fromPy<Real>(val);
    return 0;
  }

  Real mFrameLength;
  static PyObject *_GET_mFrameLength(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mFrameLength);
  }
  static int _SET_mFrameLength(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mFrameLength = fromPy<Real>(val);
    return 0;
  }

  //! Per frame duration. Blender needs access in order to restore value in new solver object
  Real mTimePerFrame;
  static PyObject *_GET_mTimePerFrame(PyObject *self, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    return toPy(pbo->mTimePerFrame);
  }
  static int _SET_mTimePerFrame(PyObject *self, PyObject *val, void *cl)
  {
    FluidSolver *pbo = dynamic_cast<FluidSolver *>(Pb::objFromPy(self));
    pbo->mTimePerFrame = fromPy<Real>(val);
    return 0;
  }

 protected:
  Vec3i mGridSize;
  const int mDim;
  bool mLockDt;

  //! subclass for managing grid memory
  //! stored as a stack to allow fast allocation
  template<class T> struct GridStorage {
    GridStorage() : used(0)
    {
    }
    T *get(Vec3i size);
    void free();
    void release(T *ptr);

    std::vector<T *> grids;
    int used;
  };

  //! memory for regular (3d) grids
  GridStorage<int> mGridsInt;
  GridStorage<Real> mGridsReal;
  GridStorage<Vec3> mGridsVec;

  //! 4d data section, only required for simulations working with space-time data

 public:
  //! 4D enabled? note, there's intentionally no "is4D" function, there are only 3D solvers that
  //! also support 4D of a certain size
  inline bool supports4D() const
  {
    return mFourthDim > 0;
  }
  //! fourth dimension size
  inline int getFourthDim() const
  {
    return mFourthDim;
  }
  //! 4d data allocation
  template<class T> T *getGrid4dPointer();
  template<class T> void freeGrid4dPointer(T *ptr);

 protected:
  //! 4d size. Note - 4d is not treated like going from 2d to 3d! 4D grids are a separate data
  //! type. Normally all grids are forced to have the same size. In contrast, a solver can create
  //! and work with 3D as well as 4D grids, when fourth-dim is >0.
  int mFourthDim;

  //! 4d grid storage
  GridStorage<Vec4> mGridsVec4;
  GridStorage<int> mGrids4dInt;
  GridStorage<Real> mGrids4dReal;
  GridStorage<Vec3> mGrids4dVec;
  GridStorage<Vec4> mGrids4dVec4;

 public:
  PbArgs _args;
}
#define _C_FluidSolver
;

}  // namespace Manta

#endif