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

ptsplugins.cpp « plugin « preprocessed « mantaflow « extern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7b2aedb694ee270941b207dafe6f69e370b80443 (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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502


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

// ----------------------------------------------------------------------------
//
// MantaFlow fluid solver framework
// Copyright 2018 Kiwon Um, Nils Thuerey
//
// This program is free software, distributed under the terms of the
// GNU General Public License (GPL)
// http://www.gnu.org/licenses
//
// Particle system helper
//
// ----------------------------------------------------------------------------

#include "particle.h"

namespace Manta {

struct KnAddForcePvel : public KernelBase {
  KnAddForcePvel(ParticleDataImpl<Vec3> &v,
                 const Vec3 &da,
                 const ParticleDataImpl<int> *ptype,
                 const int exclude)
      : KernelBase(v.size()), v(v), da(da), ptype(ptype), exclude(exclude)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx,
                 ParticleDataImpl<Vec3> &v,
                 const Vec3 &da,
                 const ParticleDataImpl<int> *ptype,
                 const int exclude) const
  {
    if (ptype && ((*ptype)[idx] & exclude))
      return;
    v[idx] += da;
  }
  inline ParticleDataImpl<Vec3> &getArg0()
  {
    return v;
  }
  typedef ParticleDataImpl<Vec3> type0;
  inline const Vec3 &getArg1()
  {
    return da;
  }
  typedef Vec3 type1;
  inline const ParticleDataImpl<int> *getArg2()
  {
    return ptype;
  }
  typedef ParticleDataImpl<int> type2;
  inline const int &getArg3()
  {
    return exclude;
  }
  typedef int type3;
  void runMessage()
  {
    debMsg("Executing kernel KnAddForcePvel ", 3);
    debMsg("Kernel range"
               << " size " << size << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r) const
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, v, da, ptype, exclude);
  }
  void run()
  {
    tbb::parallel_for(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  ParticleDataImpl<Vec3> &v;
  const Vec3 &da;
  const ParticleDataImpl<int> *ptype;
  const int exclude;
};
//! add force to vec3 particle data; a: acceleration

void addForcePvel(ParticleDataImpl<Vec3> &vel,
                  const Vec3 &a,
                  const Real dt,
                  const ParticleDataImpl<int> *ptype,
                  const int exclude)
{
  KnAddForcePvel(vel, a * dt, ptype, exclude);
}
static PyObject *_W_0(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
  try {
    PbArgs _args(_linargs, _kwds);
    FluidSolver *parent = _args.obtainParent();
    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
    pbPreparePlugin(parent, "addForcePvel", !noTiming);
    PyObject *_retval = nullptr;
    {
      ArgLocker _lock;
      ParticleDataImpl<Vec3> &vel = *_args.getPtr<ParticleDataImpl<Vec3>>("vel", 0, &_lock);
      const Vec3 &a = _args.get<Vec3>("a", 1, &_lock);
      const Real dt = _args.get<Real>("dt", 2, &_lock);
      const ParticleDataImpl<int> *ptype = _args.getPtr<ParticleDataImpl<int>>("ptype", 3, &_lock);
      const int exclude = _args.get<int>("exclude", 4, &_lock);
      _retval = getPyNone();
      addForcePvel(vel, a, dt, ptype, exclude);
      _args.check();
    }
    pbFinalizePlugin(parent, "addForcePvel", !noTiming);
    return _retval;
  }
  catch (std::exception &e) {
    pbSetError("addForcePvel", e.what());
    return 0;
  }
}
static const Pb::Register _RP_addForcePvel("", "addForcePvel", _W_0);
extern "C" {
void PbRegister_addForcePvel()
{
  KEEP_UNUSED(_RP_addForcePvel);
}
}

struct KnUpdateVelocityFromDeltaPos : public KernelBase {
  KnUpdateVelocityFromDeltaPos(const BasicParticleSystem &p,
                               ParticleDataImpl<Vec3> &v,
                               const ParticleDataImpl<Vec3> &x_prev,
                               const Real over_dt,
                               const ParticleDataImpl<int> *ptype,
                               const int exclude)
      : KernelBase(p.size()),
        p(p),
        v(v),
        x_prev(x_prev),
        over_dt(over_dt),
        ptype(ptype),
        exclude(exclude)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx,
                 const BasicParticleSystem &p,
                 ParticleDataImpl<Vec3> &v,
                 const ParticleDataImpl<Vec3> &x_prev,
                 const Real over_dt,
                 const ParticleDataImpl<int> *ptype,
                 const int exclude) const
  {
    if (ptype && ((*ptype)[idx] & exclude))
      return;
    v[idx] = (p[idx].pos - x_prev[idx]) * over_dt;
  }
  inline const BasicParticleSystem &getArg0()
  {
    return p;
  }
  typedef BasicParticleSystem type0;
  inline ParticleDataImpl<Vec3> &getArg1()
  {
    return v;
  }
  typedef ParticleDataImpl<Vec3> type1;
  inline const ParticleDataImpl<Vec3> &getArg2()
  {
    return x_prev;
  }
  typedef ParticleDataImpl<Vec3> type2;
  inline const Real &getArg3()
  {
    return over_dt;
  }
  typedef Real type3;
  inline const ParticleDataImpl<int> *getArg4()
  {
    return ptype;
  }
  typedef ParticleDataImpl<int> type4;
  inline const int &getArg5()
  {
    return exclude;
  }
  typedef int type5;
  void runMessage()
  {
    debMsg("Executing kernel KnUpdateVelocityFromDeltaPos ", 3);
    debMsg("Kernel range"
               << " size " << size << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r) const
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, p, v, x_prev, over_dt, ptype, exclude);
  }
  void run()
  {
    tbb::parallel_for(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  const BasicParticleSystem &p;
  ParticleDataImpl<Vec3> &v;
  const ParticleDataImpl<Vec3> &x_prev;
  const Real over_dt;
  const ParticleDataImpl<int> *ptype;
  const int exclude;
};
//! retrieve velocity from position change

void updateVelocityFromDeltaPos(const BasicParticleSystem &parts,
                                ParticleDataImpl<Vec3> &vel,
                                const ParticleDataImpl<Vec3> &x_prev,
                                const Real dt,
                                const ParticleDataImpl<int> *ptype,
                                const int exclude)
{
  KnUpdateVelocityFromDeltaPos(parts, vel, x_prev, 1.0 / dt, ptype, exclude);
}
static PyObject *_W_1(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
  try {
    PbArgs _args(_linargs, _kwds);
    FluidSolver *parent = _args.obtainParent();
    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
    pbPreparePlugin(parent, "updateVelocityFromDeltaPos", !noTiming);
    PyObject *_retval = nullptr;
    {
      ArgLocker _lock;
      const BasicParticleSystem &parts = *_args.getPtr<BasicParticleSystem>("parts", 0, &_lock);
      ParticleDataImpl<Vec3> &vel = *_args.getPtr<ParticleDataImpl<Vec3>>("vel", 1, &_lock);
      const ParticleDataImpl<Vec3> &x_prev = *_args.getPtr<ParticleDataImpl<Vec3>>(
          "x_prev", 2, &_lock);
      const Real dt = _args.get<Real>("dt", 3, &_lock);
      const ParticleDataImpl<int> *ptype = _args.getPtr<ParticleDataImpl<int>>("ptype", 4, &_lock);
      const int exclude = _args.get<int>("exclude", 5, &_lock);
      _retval = getPyNone();
      updateVelocityFromDeltaPos(parts, vel, x_prev, dt, ptype, exclude);
      _args.check();
    }
    pbFinalizePlugin(parent, "updateVelocityFromDeltaPos", !noTiming);
    return _retval;
  }
  catch (std::exception &e) {
    pbSetError("updateVelocityFromDeltaPos", e.what());
    return 0;
  }
}
static const Pb::Register _RP_updateVelocityFromDeltaPos("", "updateVelocityFromDeltaPos", _W_1);
extern "C" {
void PbRegister_updateVelocityFromDeltaPos()
{
  KEEP_UNUSED(_RP_updateVelocityFromDeltaPos);
}
}

struct KnStepEuler : public KernelBase {
  KnStepEuler(BasicParticleSystem &p,
              const ParticleDataImpl<Vec3> &v,
              const Real dt,
              const ParticleDataImpl<int> *ptype,
              const int exclude)
      : KernelBase(p.size()), p(p), v(v), dt(dt), ptype(ptype), exclude(exclude)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx,
                 BasicParticleSystem &p,
                 const ParticleDataImpl<Vec3> &v,
                 const Real dt,
                 const ParticleDataImpl<int> *ptype,
                 const int exclude) const
  {
    if (ptype && ((*ptype)[idx] & exclude))
      return;
    p[idx].pos += v[idx] * dt;
  }
  inline BasicParticleSystem &getArg0()
  {
    return p;
  }
  typedef BasicParticleSystem type0;
  inline const ParticleDataImpl<Vec3> &getArg1()
  {
    return v;
  }
  typedef ParticleDataImpl<Vec3> type1;
  inline const Real &getArg2()
  {
    return dt;
  }
  typedef Real type2;
  inline const ParticleDataImpl<int> *getArg3()
  {
    return ptype;
  }
  typedef ParticleDataImpl<int> type3;
  inline const int &getArg4()
  {
    return exclude;
  }
  typedef int type4;
  void runMessage()
  {
    debMsg("Executing kernel KnStepEuler ", 3);
    debMsg("Kernel range"
               << " size " << size << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r) const
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, p, v, dt, ptype, exclude);
  }
  void run()
  {
    tbb::parallel_for(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  BasicParticleSystem &p;
  const ParticleDataImpl<Vec3> &v;
  const Real dt;
  const ParticleDataImpl<int> *ptype;
  const int exclude;
};
//! simple foward Euler integration for particle system

void eulerStep(BasicParticleSystem &parts,
               const ParticleDataImpl<Vec3> &vel,
               const ParticleDataImpl<int> *ptype,
               const int exclude)
{
  KnStepEuler(parts, vel, parts.getParent()->getDt(), ptype, exclude);
}
static PyObject *_W_2(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
  try {
    PbArgs _args(_linargs, _kwds);
    FluidSolver *parent = _args.obtainParent();
    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
    pbPreparePlugin(parent, "eulerStep", !noTiming);
    PyObject *_retval = nullptr;
    {
      ArgLocker _lock;
      BasicParticleSystem &parts = *_args.getPtr<BasicParticleSystem>("parts", 0, &_lock);
      const ParticleDataImpl<Vec3> &vel = *_args.getPtr<ParticleDataImpl<Vec3>>("vel", 1, &_lock);
      const ParticleDataImpl<int> *ptype = _args.getPtr<ParticleDataImpl<int>>("ptype", 2, &_lock);
      const int exclude = _args.get<int>("exclude", 3, &_lock);
      _retval = getPyNone();
      eulerStep(parts, vel, ptype, exclude);
      _args.check();
    }
    pbFinalizePlugin(parent, "eulerStep", !noTiming);
    return _retval;
  }
  catch (std::exception &e) {
    pbSetError("eulerStep", e.what());
    return 0;
  }
}
static const Pb::Register _RP_eulerStep("", "eulerStep", _W_2);
extern "C" {
void PbRegister_eulerStep()
{
  KEEP_UNUSED(_RP_eulerStep);
}
}

struct KnSetPartType : public KernelBase {
  KnSetPartType(ParticleDataImpl<int> &ptype,
                const BasicParticleSystem &part,
                const int mark,
                const int stype,
                const FlagGrid &flags,
                const int cflag)
      : KernelBase(ptype.size()),
        ptype(ptype),
        part(part),
        mark(mark),
        stype(stype),
        flags(flags),
        cflag(cflag)
  {
    runMessage();
    run();
  }
  inline void op(IndexInt idx,
                 ParticleDataImpl<int> &ptype,
                 const BasicParticleSystem &part,
                 const int mark,
                 const int stype,
                 const FlagGrid &flags,
                 const int cflag) const
  {
    if (flags.isInBounds(part.getPos(idx), 0) && (flags.getAt(part.getPos(idx)) & cflag) &&
        (ptype[idx] & stype))
      ptype[idx] = mark;
  }
  inline ParticleDataImpl<int> &getArg0()
  {
    return ptype;
  }
  typedef ParticleDataImpl<int> type0;
  inline const BasicParticleSystem &getArg1()
  {
    return part;
  }
  typedef BasicParticleSystem type1;
  inline const int &getArg2()
  {
    return mark;
  }
  typedef int type2;
  inline const int &getArg3()
  {
    return stype;
  }
  typedef int type3;
  inline const FlagGrid &getArg4()
  {
    return flags;
  }
  typedef FlagGrid type4;
  inline const int &getArg5()
  {
    return cflag;
  }
  typedef int type5;
  void runMessage()
  {
    debMsg("Executing kernel KnSetPartType ", 3);
    debMsg("Kernel range"
               << " size " << size << " ",
           4);
  };
  void operator()(const tbb::blocked_range<IndexInt> &__r) const
  {
    for (IndexInt idx = __r.begin(); idx != (IndexInt)__r.end(); idx++)
      op(idx, ptype, part, mark, stype, flags, cflag);
  }
  void run()
  {
    tbb::parallel_for(tbb::blocked_range<IndexInt>(0, size), *this);
  }
  ParticleDataImpl<int> &ptype;
  const BasicParticleSystem &part;
  const int mark;
  const int stype;
  const FlagGrid &flags;
  const int cflag;
};
//! if particle is stype and in cflag cell, set ptype as mark

void setPartType(const BasicParticleSystem &parts,
                 ParticleDataImpl<int> &ptype,
                 const int mark,
                 const int stype,
                 const FlagGrid &flags,
                 const int cflag)
{
  KnSetPartType(ptype, parts, mark, stype, flags, cflag);
}
static PyObject *_W_3(PyObject *_self, PyObject *_linargs, PyObject *_kwds)
{
  try {
    PbArgs _args(_linargs, _kwds);
    FluidSolver *parent = _args.obtainParent();
    bool noTiming = _args.getOpt<bool>("notiming", -1, 0);
    pbPreparePlugin(parent, "setPartType", !noTiming);
    PyObject *_retval = nullptr;
    {
      ArgLocker _lock;
      const BasicParticleSystem &parts = *_args.getPtr<BasicParticleSystem>("parts", 0, &_lock);
      ParticleDataImpl<int> &ptype = *_args.getPtr<ParticleDataImpl<int>>("ptype", 1, &_lock);
      const int mark = _args.get<int>("mark", 2, &_lock);
      const int stype = _args.get<int>("stype", 3, &_lock);
      const FlagGrid &flags = *_args.getPtr<FlagGrid>("flags", 4, &_lock);
      const int cflag = _args.get<int>("cflag", 5, &_lock);
      _retval = getPyNone();
      setPartType(parts, ptype, mark, stype, flags, cflag);
      _args.check();
    }
    pbFinalizePlugin(parent, "setPartType", !noTiming);
    return _retval;
  }
  catch (std::exception &e) {
    pbSetError("setPartType", e.what());
    return 0;
  }
}
static const Pb::Register _RP_setPartType("", "setPartType", _W_3);
extern "C" {
void PbRegister_setPartType()
{
  KEEP_UNUSED(_RP_setPartType);
}
}

}  // namespace Manta