mantaflow  0.10
A framework for fluid simulation
integrator.h
Go to the documentation of this file.
1 
2 /******************************************************************************
3  *
4  * MantaFlow fluid solver framework
5  * Copyright 2011 Tobias Pfaff, Nils Thuerey
6  *
7  * This program is free software, distributed under the terms of the
8  * GNU General Public License (GPL)
9  * http://www.gnu.org/licenses
10  *
11  * Helper functions for simple integration
12  *
13  ******************************************************************************/
14 
15 #ifndef _INTEGRATE_H
16 #define _INTEGRATE_H
17 
18 #include <vector>
19 #include "vectorbase.h"
20 #include "kernel.h"
21 
22 namespace Manta {
23 
24 enum IntegrationMode { IntEuler=0, IntRK2, IntRK4 };
25 
27 template<class VelKernel>
28 void integratePointSet(VelKernel& k, int mode) {
29  typedef typename VelKernel::type0 PosType;
30  PosType& x = k.getArg0();
31  const std::vector<Vec3>& u = k.getRet();
32  const int N = x.size();
33 
34  if (mode == IntEuler) {
35  for(int i=0; i<N; i++) x[i].pos += u[i];
36  }
37  else if (mode == IntRK2) {
38  PosType x0(x);
39 
40  for(int i=0; i<N; i++) x[i].pos = x0[i].pos + 0.5*u[i];
41 
42  k.run();
43  for(int i=0; i<N; i++) x[i].pos = x0[i].pos + u[i];
44  }
45  else if (mode == IntRK4) {
46  PosType x0(x);
47  std::vector<Vec3> uTotal(u);
48 
49  for(int i=0; i<N; i++) x[i].pos = x0[i].pos + 0.5*u[i];
50 
51  k.run();
52  for(int i=0; i<N; i++) {
53  x[i].pos = x0[i].pos + 0.5*u[i];
54  uTotal[i] += 2*u[i];
55  }
56 
57  k.run();
58  for(int i=0; i<N; i++) {
59  x[i].pos = x0[i].pos + u[i];
60  uTotal[i] += 2*u[i];
61  }
62 
63  k.run();
64  for(int i=0; i<N; i++) x[i].pos = x0[i].pos + (Real)(1./6.) * (uTotal[i] + u[i]);
65  }
66  else
67  errMsg("unknown integration type");
68 
69  //for(int i=0; i<N; i++) std::cout << x[i].pos.y-x[0].pos.y << std::endl;
70  //std::cout << "<><><>" << std::endl;
71 }
72 
73 
74 } // namespace
75 
76 #endif
77 
78 
Definition: commonkernels.h:22
void integratePointSet(VelKernel &k, int mode)
Integrate a particle set with a given velocity kernel.
Definition: integrator.h:28