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