├── vcenter.txt ├── ucenter.txt ├── README.md ├── LICENSE ├── vorticity.txt ├── v.txt ├── u.txt ├── psi.txt └── SIMPLE.cpp /vcenter.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of1000 0.121466 0.192548 0.212668 0.202628 0.178893 0.143297 0.0941322 0.029639 -0.0512457 -0.138982 -0.224914 -0.279187 -0.265233 -0.166214 -0.0494959 0 -------------------------------------------------------------------------------- /ucenter.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of1000 -0.00391551 -0.0462378 -0.106636 -0.170132 -0.224735 -0.256323 -0.251887 -0.201171 -0.118649 -0.0293076 0.0582875 0.136556 0.229639 0.368472 0.61604 1 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SIMPLE_Solver 2 | # Version 1.0 3 | 4 | This folder contains the self written C++ code for solving lid driven flow, further features, and cases will be added over time 5 | Although files of plots generated are not attached currently, the solution files generated are available 6 | The post processing may then be carried out in MATLAB or Python 7 | Future update would include an IPython notebook containing plots and contours 8 | 9 | Please stay tuned for updates 10 | 11 | 12 | Developer:Shyam Sundar Sankaran 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 ShyamSS-95 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vorticity.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of100 2 | 0.127282 0.216355 0.41564 0.543017 0.607257 0.575693 0.437828 0.19275 -0.0659989 -0.218221 -0.279756 -0.219798 -0.122758 -0.067682 -0.0279294 -0.00982429 3 | 0.296084 0.0758493 0.22335 0.354382 0.424564 0.471883 0.512809 0.580977 0.686439 0.661172 0.303662 -0.0479405 -0.0652183 -0.0244326 -0.0223417 -0.0194816 4 | 0.60737 0.0503444 0.0099287 0.131827 0.231101 0.337893 0.489983 0.705165 0.955646 1.20353 1.14494 0.512745 0.00303964 -0.01929 -0.0130494 -0.0340635 5 | 0.952204 0.134116 -0.141383 -0.107725 -0.000657938 0.137562 0.324546 0.56186 0.884314 1.26015 1.57598 1.36978 0.500816 -0.022675 -0.0197151 -0.0253686 6 | 1.28866 0.281208 -0.212078 -0.322325 -0.288268 -0.190758 -0.0261522 0.203353 0.519347 0.960971 1.46751 1.80215 1.37828 0.374855 -0.0338344 -0.00742394 7 | 1.57392 0.468813 -0.216218 -0.48773 -0.581906 -0.614751 -0.552313 -0.370523 -0.101361 0.334674 0.957197 1.63418 1.93068 1.23011 0.242887 0.0405889 8 | 1.78076 0.681305 -0.161109 -0.588247 -0.819755 -1.00546 -1.14608 -1.13516 -0.93139 -0.575229 0.0725789 0.982556 1.86551 1.97841 0.958561 0.225494 9 | 1.88908 0.90392 -0.0417982 -0.615356 -0.95791 -1.26746 -1.58664 -1.85765 -1.90182 -1.66411 -1.12195 -0.120149 1.2187 2.23704 1.84302 0.629731 10 | 1.89973 1.10377 0.149288 -0.555325 -0.99103 -1.36474 -1.77553 -2.21082 -2.59913 -2.73491 -2.4538 -1.58055 -0.000695775 1.88554 2.61442 1.37467 11 | 1.83841 1.24333 0.390781 -0.388423 -0.924303 -1.32643 -1.7455 -2.21277 -2.72706 -3.22686 -3.5333 -3.15686 -1.70651 0.818887 3.05514 2.52796 12 | 1.75549 1.31959 0.626859 -0.144594 -0.746349 -1.20781 -1.60273 -2.02888 -2.46991 -2.91709 -3.60739 -4.2717 -3.62531 -1.00243 2.85522 3.98998 13 | 1.76365 1.27124 0.807235 0.114748 -0.554385 -1.08072 -1.49416 -1.83423 -2.21981 -2.62428 -2.91364 -3.89867 -5.03239 -3.44421 1.65535 5.65213 14 | 1.86154 1.04744 0.731849 0.0746387 -0.613109 -1.14536 -1.55757 -1.9056 -2.18484 -2.56749 -2.90889 -2.98394 -4.51435 -5.72655 -0.984478 7.04398 15 | 2.24487 0.276433 -0.537165 -1.0734 -1.50577 -1.90152 -2.23382 -2.51189 -2.76459 -2.94575 -3.28482 -3.42118 -3.50913 -5.97799 -5.07063 7.66588 16 | 1.03359 -3.02439 -4.26326 -4.38205 -4.32398 -4.25865 -4.21519 -4.18296 -4.15115 -4.15053 -4.13222 -4.39635 -4.27148 -5.18038 -8.8141 4.21999 17 | -14.6516 -13.7778 -11.7693 -10.3323 -9.15494 -8.13633 -7.24799 -6.5145 -5.9848 -5.65292 -5.61241 -5.78236 -6.57367 -7.10366 -11.7354 -12.0415 18 | -------------------------------------------------------------------------------- /v.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of100 2 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | 0 0.00795513 0.00556705 0.00450018 0.002394 -0.000485165 -0.00436678 -0.00813137 -0.0109506 -0.00804044 0.00143669 0.00419449 0.00231068 0.00187052 0.00113157 0.000614018 0 4 | 0 0.0264604 0.0236229 0.017482 0.0105283 0.000495453 -0.0114843 -0.0240213 -0.032098 -0.0293615 -0.0111568 0.00891801 0.00970704 0.00530988 0.0037664 0.00183162 0 5 | 0 0.0485107 0.0516957 0.0402185 0.0260791 0.00847085 -0.0124926 -0.0337282 -0.0505656 -0.0562455 -0.0434529 -0.0105425 0.0138905 0.0103692 0.00506028 0.00273255 0 6 | 0 0.071013 0.0844754 0.072083 0.0519695 0.0271524 -0.00181679 -0.0324049 -0.0612328 -0.0806664 -0.0815118 -0.0566248 -0.0116074 0.0117918 0.00549708 0.00188289 0 7 | 0 0.091543 0.11826 0.10958 0.0875101 0.0584286 0.0222462 -0.018464 -0.0596314 -0.0965906 -0.117924 -0.11127 -0.0709844 -0.0157885 0.00376858 -0.000683018 0 8 | 0 0.107898 0.149662 0.148401 0.128355 0.0986461 0.0592485 0.00978134 -0.044349 -0.0986635 -0.144415 -0.165176 -0.144321 -0.0818892 -0.0192221 -0.00395569 0 9 | 0 0.118124 0.175548 0.183934 0.168622 0.14112 0.102547 0.0510228 -0.0139926 -0.083806 -0.153593 -0.206598 -0.219019 -0.169912 -0.0780516 -0.0159472 0 10 | 0 0.121466 0.192548 0.212668 0.202628 0.178893 0.143297 0.0941322 0.029639 -0.0512457 -0.138982 -0.224914 -0.279187 -0.265233 -0.166214 -0.0494959 0 11 | 0 0.118676 0.198997 0.230695 0.227619 0.206123 0.174079 0.129297 0.0697508 -0.00498861 -0.100777 -0.209081 -0.309077 -0.348739 -0.273247 -0.109328 0 12 | 0 0.112168 0.195215 0.236747 0.23965 0.221445 0.190427 0.14998 0.0974163 0.029724 -0.0477513 -0.158255 -0.292298 -0.398519 -0.381531 -0.194419 0 13 | 0 0.105943 0.185238 0.228968 0.238217 0.221712 0.19189 0.153702 0.108363 0.0519475 -0.017627 -0.0911795 -0.22353 -0.389144 -0.466455 -0.298043 0 14 | 0 0.107779 0.170537 0.211961 0.218972 0.203286 0.176063 0.142326 0.103013 0.0597574 0.00188341 -0.0629631 -0.129636 -0.304842 -0.489922 -0.408213 0 15 | 0 0.120632 0.16422 0.177881 0.175812 0.16252 0.141063 0.114712 0.0849809 0.0501389 0.0141175 -0.0427959 -0.0910669 -0.161934 -0.414818 -0.495463 0 16 | 0 0.148872 0.138081 0.117695 0.109345 0.100297 0.0877015 0.0718133 0.0529407 0.0327811 0.00748066 -0.0156352 -0.0641236 -0.0819748 -0.194121 -0.511154 0 17 | 0 0.0842723 0.0546161 0.04126 0.0351945 0.0323252 0.0284682 0.0231963 0.0173749 0.0099101 0.00336729 -0.00737808 -0.0139895 -0.0420785 -0.0191346 -0.247404 0 18 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 | -------------------------------------------------------------------------------- /u.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of100 2 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | 0 -0.00795513 -0.0214773 -0.0315445 -0.0384387 -0.0403476 -0.0354956 -0.0229975 -0.00391551 0.0150755 0.0216793 0.0160481 0.0095429 0.0053617 0.00235961 0.000614018 0 4 | 0 -0.0105501 -0.033589 -0.0545595 -0.0687814 -0.0759875 -0.0747025 -0.0641932 -0.0462378 -0.0227604 0.00455052 0.0180517 0.012437 0.00578252 0.00271042 0.000603582 0 5 | 0 -0.0115002 -0.0385844 -0.0684234 -0.0924888 -0.108809 -0.117061 -0.116855 -0.106636 -0.0847616 -0.0528924 -0.014637 0.00625473 0.00366644 0.000385321 0.00029735 0 6 | 0 -0.011002 -0.0391997 -0.074005 -0.107694 -0.135946 -0.157052 -0.169257 -0.170132 -0.156918 -0.126307 -0.0804217 -0.0297333 -0.00306964 -0.00164785 -0.00114701 0 7 | 0 -0.00952807 -0.0356452 -0.072122 -0.11147 -0.150035 -0.184269 -0.210068 -0.224735 -0.223626 -0.2019 -0.156727 -0.0933932 -0.0330995 -0.00521246 -0.00141889 0 8 | 0 -0.0068272 -0.0284671 -0.062213 -0.10253 -0.145027 -0.188013 -0.227462 -0.256323 -0.270642 -0.263804 -0.22858 -0.164672 -0.085528 -0.0243236 -0.00185379 0 9 | 0 -0.00339894 -0.0178714 -0.0455444 -0.081027 -0.121271 -0.164058 -0.20915 -0.251887 -0.282782 -0.295299 -0.279924 -0.227713 -0.144136 -0.0584889 -0.0101377 0 10 | 0 5.71365e-05 -0.00581214 -0.0238729 -0.0511307 -0.0826656 -0.1184 -0.157167 -0.201171 -0.246468 -0.281123 -0.292793 -0.266519 -0.194606 -0.0967704 -0.023411 0 11 | 0 0.00273311 0.00494371 -0.00147166 -0.0172317 -0.0379177 -0.0601959 -0.0873762 -0.118649 -0.159722 -0.209529 -0.251898 -0.264115 -0.222631 -0.129927 -0.036421 0 12 | 0 0.00377517 0.0118543 0.0159996 0.0136772 0.00701025 -0.00238146 -0.0122322 -0.0293076 -0.050613 -0.088544 -0.150027 -0.205416 -0.213899 -0.148539 -0.0486698 0 13 | 0 0.00244961 0.010573 0.0241848 0.0357191 0.0435518 0.0512135 0.0558798 0.0582875 0.0464232 0.0320064 -0.00370994 -0.0841641 -0.153823 -0.143634 -0.0549546 0 14 | 0 -0.00428547 0.000455765 0.0185514 0.0432696 0.0731087 0.0997006 0.122238 0.136556 0.14596 0.133057 0.121046 0.0793898 -0.0291477 -0.100172 -0.0552146 0 15 | 0 -0.00856751 -0.0198449 0.00245565 0.0549767 0.109063 0.158236 0.198311 0.229639 0.247885 0.258173 0.237782 0.220702 0.147761 0.000773817 -0.0320361 0 16 | 0 -0.0196727 -0.0104963 0.0535281 0.127659 0.202263 0.268675 0.32486 0.368472 0.399624 0.413331 0.413198 0.376174 0.342212 0.188542 0.0163455 0 17 | 0 0.0842723 0.223161 0.319037 0.395491 0.463011 0.523804 0.575469 0.61604 0.643325 0.656602 0.652592 0.631224 0.575156 0.513943 0.247404 0 18 | 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 19 | -------------------------------------------------------------------------------- /psi.txt: -------------------------------------------------------------------------------- 1 | The value we are printing are for16X16grid, for a reynolds number of100 2 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 | 0 -0.000248598 -0.000671166 -0.000985767 -0.00120121 -0.00126086 -0.00110924 -0.000718671 -0.00012236 0.00047111 0.000677477 0.000501502 0.000298216 0.000167553 7.37377e-05 1.91881e-05 0 4 | 0 -0.000826887 -0.00239199 -0.00367652 -0.00455184 -0.00489633 -0.00455293 -0.00344338 -0.00168965 0.000230959 0.00149716 0.00156712 0.000985089 0.00051581 0.000232176 5.72381e-05 0 5 | 0 -0.00151596 -0.00464741 -0.00751973 -0.00959153 -0.0106712 -0.0105455 -0.00910114 -0.00646695 -0.0031291 -1.35264e-05 0.00167383 0.00156921 0.00081109 0.000328918 8.53922e-05 0 6 | 0 -0.00221916 -0.00707817 -0.0119706 -0.0158473 -0.0183198 -0.0191116 -0.0180421 -0.0151159 -0.0106816 -0.00561352 -0.00129675 0.000835501 0.00082974 0.000289464 5.88402e-05 0 7 | 0 -0.00286072 -0.00941707 -0.0165371 -0.0226962 -0.0272567 -0.0297778 -0.029896 -0.0274555 -0.0225736 -0.01587 -0.00870766 -0.0030122 -0.000300544 7.50794e-05 -2.13443e-05 0 8 | 0 -0.00337182 -0.0114206 -0.0207351 -0.0293837 -0.0364775 -0.0414117 -0.0435688 -0.0424886 -0.0380195 -0.0304233 -0.0207485 -0.0110767 -0.00400765 -0.000847922 -0.000123615 0 9 | 0 -0.00369139 -0.0128687 -0.0241025 -0.0351198 -0.0447993 -0.0524139 -0.057213 -0.0583702 -0.055314 -0.0478952 -0.0366393 -0.0233387 -0.0111847 -0.00343581 -0.00049835 0 10 | 0 -0.00379582 -0.0136088 -0.0262718 -0.0392498 -0.0511723 -0.0612407 -0.0686604 -0.0725282 -0.071853 -0.0659084 -0.0545366 -0.0387835 -0.0217704 -0.00828767 -0.00154675 0 11 | 0 -0.00370863 -0.0136359 -0.0270638 -0.0413861 -0.0549405 -0.0668219 -0.0763024 -0.0825226 -0.0845464 -0.0812413 -0.0715582 -0.0553658 -0.034809 -0.015372 -0.0034165 0 12 | 0 -0.00350524 -0.013111 -0.0266098 -0.0414972 -0.0559064 -0.0687774 -0.0794151 -0.0871463 -0.0911194 -0.0905561 -0.0841184 -0.0700386 -0.0484506 -0.024074 -0.00607559 0 13 | 0 -0.00331072 -0.0124101 -0.025354 -0.0399535 -0.0543263 -0.0672514 -0.0780511 -0.0862407 -0.0912503 -0.0923229 -0.0889227 -0.079088 -0.0599419 -0.0332044 -0.00931385 0 14 | 0 -0.00336809 -0.0120655 -0.0240185 -0.0374851 -0.0506807 -0.0625353 -0.072485 -0.0801518 -0.0852384 -0.0871646 -0.0852559 -0.0792372 -0.0656597 -0.0408233 -0.0127566 0 15 | 0 -0.00376974 -0.0126714 -0.023362 -0.0344149 -0.0449878 -0.0544748 -0.0624678 -0.0687082 -0.0729307 -0.0749387 -0.0740425 -0.0698593 -0.061953 -0.0439295 -0.0154832 0 16 | 0 -0.00465225 -0.0136195 -0.0216125 -0.0287076 -0.0352589 -0.0411339 -0.0461187 -0.0500173 -0.0526961 -0.0539542 -0.0536994 -0.0512069 -0.0466414 -0.0380134 -0.0159736 0 17 | 0 -0.00263351 -0.00697377 -0.0099699 -0.0123591 -0.0144691 -0.0163689 -0.0179834 -0.0192513 -0.0201039 -0.0205188 -0.0203935 -0.0197258 -0.0179736 -0.0160607 -0.00773138 0 18 | 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 | -------------------------------------------------------------------------------- /SIMPLE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | //solver version 1.0 9 | //For the sake of simplicity, the variables will be declared as global so all functions may access it 10 | //In future updates, to improve the efficiency they functions will be passed by reference to subfunctions 11 | //Future updates to improve the solver efficiency and capabilites 12 | 13 | double u[90601],v[90601],p[90000]; 14 | //velocities and pressure 15 | 16 | double psix[90601],psiy[90601],psi[90601]; 17 | //for stream function calculation 18 | 19 | double vorticity[90000]; 20 | //stores vorticity values 21 | 22 | double uav[90000],vav[90000]; 23 | //stores averages 24 | 25 | double dudx[90000],dudy[90000],dvdx[90000],dvdy[90000]; 26 | //gradients 27 | 28 | double m[90000],pc[90000]; 29 | //mass and pressure corrections 30 | 31 | double dudt,dvdt,dx,dy,dt; 32 | //parameters for solution and time gradients 33 | 34 | double rho,nu,con; 35 | //constants 36 | 37 | double resmax,psimax; 38 | //max values 39 | 40 | int n,k; 41 | //grid count 42 | 43 | int n1,n2,n3,n4,n5; 44 | //used for nodal connectivity 45 | 46 | //max capacity of 90000 elements for the grid 47 | //dynamic memory allocation to be added 48 | 49 | void intro() 50 | { 51 | 52 | cout<<"================================================="<resmax) 126 | resmax=m[i]; 127 | } 128 | } 129 | 130 | void massbal()//this function performs mass balance for mass balance cells 131 | { 132 | int i; 133 | for(i=0;i<(k*k);i++) 134 | { 135 | if(i((k*(k-1))-1)&&(i%k)==0) 146 | pc[i]=0.8*pc[i]+0.05*(pc[i+1]+pc[i]+pc[i]+pc[i-k]); 147 | else if(i>((k*(k-1))-1)&&(i%k)==(k-1)) 148 | pc[i]=0.8*pc[i]+0.05*(pc[i]+pc[i-1]+pc[i]+pc[i-k]); 149 | else if(i>((k*(k-1))-1)) 150 | pc[i]=0.8*pc[i]+0.05*(pc[i+1]+pc[i-1]+pc[i]+pc[i-k]); 151 | else 152 | pc[i]=0.8*pc[i]+0.05*(pc[i+1]+pc[i-1]+pc[i+k]+pc[i-k]); 153 | //the above section of code attempts to stabilize the solution obtained, as we are using an approximate solver 154 | p[i]=p[i]+pc[i]; 155 | } 156 | } 157 | 158 | void correction()//this function performs the velocity correction for each of the nodes 159 | { 160 | int i; 161 | for(i=0;i<((k-1)*(k-1));i++) 162 | { 163 | nodcon(i,(k-1)); 164 | u[n5]=u[n5]-((dt/rho)*((pc[n2]+pc[n3]-pc[n1]-pc[n4])/(2*dx))); 165 | v[n5]=v[n5]-((dt/rho)*((pc[n4]+pc[n3]-pc[n1]-pc[n2])/(2*dy))); 166 | } 167 | } 168 | 169 | void mombal()//this function performs momentum balance to the momentum balance cells 170 | { 171 | //here we apply that (storage of momentum)+(mass efflux)=(forces due to shear and normal pressures) 172 | int i; 173 | for(i=0;i<((k-1)*(k-1));i++) 174 | { 175 | nodcon(i,(k-1)); 176 | double mn,ms,me,mw,un,us,ue,uw,vn,vs,ve,vw,xnormalf,xshearf,xmflux,ynormalf,yshearf,ymflux; 177 | mn=0.5*rho*(vav[n3]+vav[n4])*dx; 178 | ms=0.5*rho*(vav[n1]+vav[n2])*dx; 179 | me=0.5*rho*(uav[n2]+uav[n3])*dy; 180 | mw=0.5*rho*(uav[n1]+uav[n4])*dy; 181 | un=0.5*(uav[n3]+uav[n4]); 182 | us=0.5*(uav[n1]+uav[n2]); 183 | ue=0.5*(uav[n2]+uav[n3]); 184 | uw=0.5*(uav[n1]+uav[n4]); 185 | vn=0.5*(vav[n3]+vav[n4]); 186 | vs=0.5*(vav[n1]+vav[n2]); 187 | ve=0.5*(vav[n2]+vav[n3]); 188 | vw=0.5*(vav[n1]+vav[n4]); 189 | //the following section applies upwinding 190 | if((double)(1/(k*nu))>2)// this condition ensures that upwinding would be implemented only when the cell reynolds number is greater than two 191 | { 192 | if(uw>0) 193 | { 194 | uw=0.5*uw+0.5*u[n5-1]; 195 | vw=0.5*vw+0.5*v[n5-1]; 196 | } 197 | else 198 | { 199 | uw=0.5*uw+0.5*u[n5]; 200 | vw=0.5*vw+0.5*v[n5]; 201 | } 202 | if(ue>0){ 203 | ue=0.5*ue+0.5*u[n5]; 204 | ve=0.5*ve+0.5*v[n5]; 205 | } 206 | else 207 | { 208 | ue=0.5*ue+0.5*u[n5+1]; 209 | ve=0.5*ve+0.5*v[n5+1]; 210 | } 211 | if(vn>0) 212 | { 213 | vn=0.5*vn+0.5*v[n5]; 214 | un=0.5*un+0.5*u[n5]; 215 | } 216 | else 217 | { 218 | vn=0.5*vn+0.5*v[n5+n]; 219 | un=0.5*un+0.5*u[n5+n]; 220 | } 221 | if(vs>0) 222 | { 223 | vs=0.5*vs+0.5*v[n5-n]; 224 | us=0.5*us+0.5*u[n5-n]; 225 | } 226 | else 227 | { 228 | vs=0.5*vs+0.5*v[n5]; 229 | us=0.5*us+0.5*u[n5]; 230 | } 231 | } 232 | xmflux=(mn*un-ms*us+me*ue-mw*uw); 233 | ymflux=(mn*vn-ms*vs+me*ve-mw*vw); 234 | xnormalf=(0.5*(p[n1]+p[n4]-p[n3]-p[n2])+nu*(dudx[n2]+dudx[n3]-dudx[n1]-dudx[n4]))*dy; 235 | ynormalf=(0.5*(p[n1]+p[n2]-p[n3]-p[n4])+nu*(dvdx[n3]+dvdx[n4]-dvdx[n1]-dvdx[n2]))*dx; 236 | xshearf=0.5*nu*dx*(dudy[n3]+dudy[n4]+dvdx[n3]+dvdx[n4]-dudy[n1]-dudy[n2]-dvdx[n1]-dvdx[n2]); 237 | yshearf=0.5*nu*dy*(dudy[n2]+dudy[n3]+dvdx[n2]+dvdx[n3]-dudy[n1]-dudy[n4]-dvdx[n1]-dvdx[n4]); 238 | dudt=(xnormalf+xshearf-xmflux)/(rho*dx*dy); 239 | dvdt=(ynormalf+yshearf-ymflux)/(rho*dx*dy); 240 | u[n5]=u[n5]+(dudt*dt); 241 | v[n5]=v[n5]+(dvdt*dt); 242 | } 243 | } 244 | 245 | void psical()//this funtion calculates psi for each of the grid points 246 | { 247 | int i,j; 248 | for(j=1;jpsimax) 261 | psimax=psi[i]; 262 | } 263 | } 264 | 265 | void stability()//this function assigns the value for dt, looking at general stability criterion and correction constant 266 | { 267 | double trial1,trial2; 268 | trial1=(double)(dx); 269 | trial2=(double)(0.5*dx*dx*rho/nu); 270 | if(trial1>k; 282 | n=(k+1); 283 | initialize(); 284 | double side; 285 | cout<<"\nEnter the value of size of square cavity concerned\n"; 286 | cin>>side; 287 | dx=dy=(double)(side/k);//the size for each element of the grid which will be used for solving 288 | cout<<"\nEnter values of Reynold's number which will be used in the program\n"; 289 | rho=1;//since we want to solve using reynolds number, we are taking the value of density as 290 | //unity, so that the value of visocity may be assigned as the reciprocal of entered reynolds number 291 | double rey; 292 | cin>>rey; 293 | nu=(double)(1/rey); 294 | stability(); 295 | int i; 296 | long int loopcounter;//as name suggests, this variable will hold the number of outer iterations 297 | printf("\nThe value of dt obtained is %f\n",dt); 298 | getchar(); 299 | getchar(); 300 | loopcounter=0; 301 | while(1) 302 | { 303 | if(loopcounter%500==0) 304 | { 305 | cout<<"=========================================================================="<10000) 329 | { 330 | if(loopcounter%10000==0) 331 | { 332 | if((int)((10000000)*(old-psimax))==0)//we are checking if the value of psi has stabilized to check for convergence 333 | loopcounter=1000000; 334 | else 335 | old=psimax; 336 | }} 337 | if(loopcounter>=1000000) 338 | break; 339 | } 340 | psical(); 341 | ofstream myfile; 342 | myfile.open("psi.txt"); 343 | myfile<<"The value we are printing are for"<