afbe53949188a08db9c775857e997583ed945346
[blender.git] / intern / elbeem / intern / solver_control.h
1 /** \file elbeem/intern/solver_control.h
2  *  \ingroup elbeem
3  */
4 /******************************************************************************
5  *
6  * El'Beem - the visual lattice boltzmann freesurface simulator
7  * All code distributed as part of El'Beem is covered by the version 2 of the 
8  * GNU General Public License. See the file COPYING for details.
9  * Copyright 2003-2006 Nils Thuerey
10  *
11  * testing extensions
12  *
13  *****************************************************************************/
14
15
16 #ifndef LBM_TESTCLASS_H
17 #define LBM_TESTCLASS_H
18
19 //class IsoSurface;
20 class ParticleObject;
21 class ControlParticles;
22 class ControlForces;
23
24 //#define NUMGRIDS 2
25 //#define MAXNUMSWS 10
26
27 // farfield modes
28 #define FARF_3DONLY -1
29 #define FARF_BOTH    0
30 #define FARF_SWEONLY 1
31 // dont reuse 3d vars/init
32 #define FARF_SEPSWE  2
33
34 // relaxation macros for solver_relax.h
35
36 // WARNING has to match controlparts.h
37 #define CPF_ENTRIES     12
38 #define CPF_FORCE       0
39 #define CPF_VELWEIGHT   3
40 #define CPF_VELOCITY    4
41 #define CPF_FORCEWEIGHT 7
42 #define CPF_MINCPDIST   8
43 #define CPF_MINCPDIR    9
44
45 #include "controlparticles.h"
46
47 #include "ntl_geometrymodel.h"
48                          
49 // get force entry, set=0 is unused anyway
50 #define LBMGET_FORCE(lev, i,j,k)  mpControl->mCpForces[lev][ (LBMGI(lev,i,j,k,0)) ]
51
52 // debug mods off...
53 // same as in src/solver_relax.h!
54 #define __PRECOLLIDE_MODS(rho,ux,uy,uz, grav) \
55         ux += (grav)[0]; \
56         uy += (grav)[1]; \
57         uz += (grav)[2]; 
58
59 //void testMaxdmod(int i, int j,int k, LbmFloat &ux,LbmFloat &uy,LbmFloat &uz,ControlForces &ff);
60 #if LBMDIM==3
61 #define MAXDGRAV \
62                         if(myforce->forceMaxd[0]*ux+myforce->forceMaxd[1]*uy<LBM_EPSILON) { \
63                                 ux = v2w*myforce->forceVel[0]+ v2wi*ux;  \
64                                 uy = v2w*myforce->forceVel[1]+ v2wi*uy; }  \
65                         /* movement inverse to g? */ \
66                         if((uz>LBM_EPSILON)&&(uz>myforce->forceVel[2])) { \
67                                 uz = v2w*myforce->forceVel[2]+ v2wi*uz; } 
68 #else // LBMDIM==3
69 #define MAXDGRAV \
70                         if(myforce->forceMaxd[0]*ux<LBM_EPSILON) { \
71                                 ux = v2w*myforce->forceVel[0]+ v2wi*ux; } \
72                         /* movement inverse to g? */ \
73                         if((uy>LBM_EPSILON)&&(uy>myforce->forceVel[1])) { \
74                                 uy = v2w*myforce->forceVel[1]+ v2wi*uy; } 
75 #endif // LBMDIM==3
76
77 // debug modifications of collide vars (testing)
78 // requires: lev,i,j,k
79 #define PRECOLLIDE_MODS(rho,ux,uy,uz, grav) \
80         LbmFloat attforce = 1.; \
81         if(this->mTForceStrength>0.) { \
82                 ControlForces* myforce = &LBMGET_FORCE(lev,i,j,k); \
83                 const LbmFloat vf = myforce->weightAtt;\
84                 const LbmFloat vw = myforce->weightVel;\
85                 if(vf!=0.) { attforce = MAX(0., 1.-vf);  /* TODO FIXME? use ABS(vf) for repulsion force? */ \
86                         ux += myforce->forceAtt[0]; \
87                         uy += myforce->forceAtt[1]; \
88                         uz += myforce->forceAtt[2]; \
89                         \
90                 } else if(( myforce->maxDistance>0.) && ( myforce->maxDistance<CPF_MAXDINIT)) {\
91                         const LbmFloat v2w = mpControl->mCons[0]->mCparts->getInfluenceMaxdist() * \
92                                 (myforce->maxDistance-mpControl->mCons[0]->mCparts->getRadiusMinMaxd()) / (mpControl->mCons[0]->mCparts->getRadiusMaxd()-mpControl->mCons[0]->mCparts->getRadiusMinMaxd()); \
93                         const LbmFloat v2wi = 1.-v2w; \
94                         if(v2w>0.){ MAXDGRAV; \
95                                 /* errMsg("ERRMDTT","at "<<PRINT_IJK<<" maxd="<<myforce->maxDistance<<", newu"<<PRINT_VEC(ux,uy,uz)<<", org"<<PRINT_VEC(oux,ouy,ouz)<<", fv"<<myforce->forceVel<<" " );  */ \
96                         }\
97                 } \
98                 if(vw>0.) { \
99                         const LbmFloat vwi = 1.-vw;\
100                         const LbmFloat vwd = mpControl->mDiffVelCon;\
101                         ux += vw*(myforce->forceVel[0]-myforce->compAv[0] + vwd*(myforce->compAv[0]-ux) ); \
102                         uy += vw*(myforce->forceVel[1]-myforce->compAv[1] + vwd*(myforce->compAv[1]-uy) ); \
103                         uz += vw*(myforce->forceVel[2]-myforce->compAv[2] + vwd*(myforce->compAv[2]-uz) ); \
104                         /*  TODO test!? modify smooth vel by influence of force for each lbm step, to account for force update only each N steps */ \
105                         myforce->compAv = (myforce->forceVel*vw+ myforce->compAv*vwi); \
106                 } \
107         } \
108         ux += (grav)[0]*attforce; \
109         uy += (grav)[1]*attforce; \
110         uz += (grav)[2]*attforce; \
111         /* end PRECOLLIDE_MODS */
112
113 #define TEST_IF_CHECK \
114                 if((!iffilled)&&(LBMGET_FORCE(lev,i,j,k).weightAtt!=0.)) { \
115                         errMsg("TESTIFFILL"," at "<<PRINT_IJK<<" "<<mass<<" "<<rho); \
116                         iffilled = true; \
117                         if(mass<rho*1.0) mass = rho*1.0; myfrac = 1.0; \
118                 }
119
120
121 // a single set of control particles and params
122 class LbmControlSet {
123         public:
124                 LbmControlSet();
125                 ~LbmControlSet();
126                 void initCparts();
127
128                 // control particles
129                 ControlParticles *mCparts; 
130                 // control particle overall motion (for easier manual generation)
131                 ControlParticles *mCpmotion;
132                 // cp data file
133                 string mContrPartFile;
134                 string mCpmotionFile;
135                 // cp debug displau
136                 LbmFloat mDebugCpscale, mDebugVelScale, mDebugCompavScale, mDebugAttScale, mDebugMaxdScale, mDebugAvgVelScale;
137
138                 // params
139                 AnimChannel<float> mcForceAtt;
140                 AnimChannel<float> mcForceVel;
141                 AnimChannel<float> mcForceMaxd;
142
143                 AnimChannel<float> mcRadiusAtt;
144                 AnimChannel<float> mcRadiusVel;
145                 AnimChannel<float> mcRadiusMind;
146                 AnimChannel<float> mcRadiusMaxd;
147
148                 AnimChannel<ntlVec3f> mcCpScale;
149                 AnimChannel<ntlVec3f> mcCpOffset;
150 };
151                 
152
153
154 // main control data storage
155 class LbmControlData 
156 {
157         public:
158                 LbmControlData();
159                 virtual ~LbmControlData();
160
161                 // control data
162
163                 // contorl params
164                 void parseControldataAttrList(AttributeList *attr);
165
166                 // control strength, set for solver interface
167                 LbmFloat mSetForceStrength;
168                 // cp vars
169                 std::vector<LbmControlSet*> mCons;
170                 // update interval
171                 int mCpUpdateInterval;
172                 // output
173                 string mCpOutfile;
174                 // control particle precomputed influence
175                 std::vector< std::vector<ControlForces> > mCpForces;
176                 std::vector<ControlForces> mCpKernel;
177                 std::vector<ControlForces> mMdKernel;
178                 // activate differential velcon
179                 LbmFloat mDiffVelCon;
180
181                 // cp debug displau
182                 LbmFloat mDebugCpscale, mDebugVelScale, mDebugCompavScale, mDebugAttScale, mDebugMaxdScale, mDebugAvgVelScale;
183 };
184
185 #endif // LBM_TESTCLASS_H