-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflameSolver.cpp
executable file
·1914 lines (1583 loc) · 51.1 KB
/
flameSolver.cpp
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "flameSolver.h"
#include "scalarFunction.h"
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
FlameSolver::FlameSolver()
: U(0, 0, Stride1X(1 ,1))
, T(0, 0, Stride1X(1 ,1))
, Y(0, 0, 0, StrideXX(1 ,1))
, jCorrSolver(jCorrSystem)
, strainfunc(NULL)
, rateMultiplierFunction(NULL)
, stateWriter(NULL)
, timeseriesWriter(NULL)
, heatLossFunction(NULL)
, tbbTaskSched(tbb::task_scheduler_init::deferred)
, vzInterp(new BilinearInterpolator)
, vrInterp(new BilinearInterpolator)
, TInterp(new BilinearInterpolator)
{
}
FlameSolver::~FlameSolver()
{
delete strainfunc;
delete rateMultiplierFunction;
}
void FlameSolver::setOptions(const ConfigOptions& _options)
{
SplitSolver::setOptions(_options);
tStart = options.tStart;
tEnd = options.tEnd;
gas.setOptions(_options);
grid.setOptions(_options);
}
void FlameSolver::initialize(void)
{
tbbTaskSched.initialize (options.nThreads);
delete strainfunc;
strainfunc = newScalarFunction(options.strainFunctionType, options);
delete rateMultiplierFunction;
if (options.rateMultiplierFunctionType != "") {
rateMultiplierFunction = newScalarFunction(options.rateMultiplierFunctionType,
options);
} else {
rateMultiplierFunction = NULL;
}
flamePosIntegralError = 0;
terminationCondition = 1e10;
// Cantera initialization
gas.initialize();
nSpec = gas.nSpec;
nVars = nSpec + 2;
W.resize(nSpec);
gas.getMolecularWeights(W);
// Get Initial Conditions
loadProfile();
grid.setSize(x.size());
convectionSystem.setGas(gas);
convectionSystem.setLeftBC(Tleft, Yleft);
convectionSystem.setTolerances(options);
for (size_t k=0; k<nVars; k++) {
DiffusionSystem* term = new DiffusionSystem();
TridiagonalIntegrator* integrator = new TridiagonalIntegrator(*term);
integrator->resize(nPoints);
diffusionTerms.push_back(term);
diffusionSolvers.push_back(integrator);
}
if (options.wallFlux) {
diffusionTerms[kEnergy].yInf = options.Tinf;
diffusionTerms[kEnergy].wallConst = options.Kwall;
}
resizeAuxiliary();
ddtConv.setZero();
ddtDiff.setZero();
ddtProd.setZero();
//logFile.write(format("Hi moj 4444444444444444444444444444444444444444444444444"));
updateChemicalProperties();
calculateQdot();
t = tStart;
tOutput = t;
tRegrid = t + options.regridTimeInterval;
tProfile = t + options.profileTimeInterval;
nTotal = 0;
nRegrid = 0;
nOutput = 0;
nProfile = 0;
nTerminate = 0;
nCurrentState = 0;
grid.updateValues();
resizeAuxiliary();
tFlamePrev = t;
tNow = t;
totalTimer.start();
}
void FlameSolver::setupStep()
{
setupTimer.start();
// Debug sanity check
#ifndef NDEBUG
bool error = false;
for (size_t j=0; j<nPoints; j++) {
if (T(j) < 295 || T(j) > 3000) {
logFile.write(format(
"WARNING: Unexpected Temperature: T = %f at j = %i") % T(j) % j);
error = true;
}
}
if (error) {
writeStateFile("err_setupStep", true, false);
}
#endif
// Reset boundary conditions to prevent numerical drift
if (grid.leftBC == BoundaryCondition::FixedValue) {
T(0) = Tleft;
Y.col(0) = Yleft;
}
if (grid.rightBC == BoundaryCondition::FixedValue) {
T(jj) = Tright;
Y.col(jj) = Yright;
}
// logFile.write(format("Hi moj 3333333333333333333333333333333333333333333333333333"));
updateChemicalProperties();
updateBC();
if (options.xFlameControl) {
update_xStag(t, true); // calculate the value of rVzero
}
// edit shode
convectionSystem.set_rVzero(rVzero);
setupTimer.stop();
// Set up solvers for split integration
updateCrossTerms();
}
void FlameSolver::prepareIntegrators()
{
splitTimer.resume();
// Diffusion terms
if (!options.quasi2d) {
// Diffusion solvers: Energy and momentum
diffusionTerms[kMomentum].B = rho.inverse();
diffusionTerms[kEnergy].B = (rho * cp).inverse();
diffusionTerms[kMomentum].D = mu;
diffusionTerms[kEnergy].D = lambda;
// Diffusion solvers: Species
for (size_t k=0; k<nSpec; k++) {
diffusionTerms[kSpecies+k].B =rho.inverse();
diffusionTerms[kSpecies+k].D = rhoD.row(k);
}
} else {
// Diffusion solvers: Energy and momentum
diffusionTerms[kMomentum].B.setZero(nPoints);
diffusionTerms[kEnergy].B.setZero(nPoints);
diffusionTerms[kMomentum].D.setZero(nPoints);
diffusionTerms[kEnergy].D.setZero(nPoints);
// Diffusion solvers: Species
for (size_t k=0; k<nSpec; k++) {
DiffusionSystem& sys = diffusionTerms[kSpecies+k];
sys.D = rhoD.row(k);
for (size_t j = 0; j <= jj; j++) {
sys.B[j] = 1 / (rho[j] * vzInterp->get(x[j], tNow));
}
}
}
setDiffusionSolverState(tNow);
for (size_t i=0; i<nVars; i++) {
diffusionTerms[i].splitConst = splitConstDiff.row(i);
}
// Production terms
setProductionSolverState(tNow);
for (size_t j=0; j<nPoints; j++) {
sourceTerms[j].splitConst = splitConstProd.col(j);
}
// Convection terms
setConvectionSolverState(tNow);
// edit shode 1 2 3
dmatrix ddt = ddtConv*0.0 + ddtDiff*0.0 + ddtProd*0.0;
if (options.splittingMethod == "balanced") {
ddt += ddtCross;
}
dvec tmp = (W.inverse().matrix().transpose() * ddt.bottomRows(nSpec).matrix()).array();
drhodt = - rho * (ddt.row(kEnergy).transpose() / T + tmp * Wmx);
assert(mathUtils::notnan(drhodt));
// edit shode 4 7 5
//convectionSystem.setDensityDerivative(drhodt);
convectionSystem.setSplitConstants(splitConstConv);
//convectionSystem.updateContinuityBoundaryCondition(qDot, options.continuityBC);
//
splitTimer.stop();
}
int FlameSolver::finishStep()
{
logFile.verboseWrite("done!");
// *** End of Strang-split integration step ***
correctMassFractions();
t = tNow + dt;
tNow += dt;
nOutput++;
nRegrid++;
nProfile++;
nTerminate++;
nCurrentState++;
if (debugParameters::debugTimesteps) {
int nSteps = convectionSystem.getNumSteps();
logFile.write(format("t = %8.6f (dt = %9.3e) [C: %i]") % t % dt % nSteps);
}
setupTimer.resume();
if (t + 0.5 * dt > tOutput || nOutput >= options.outputStepInterval) {
calculateQdot();
timeVector.push_back(t);
heatReleaseRate.push_back(getHeatReleaseRate());
saveTimeSeriesData("out", false);
tOutput = t + options.outputTimeInterval;
nOutput = 0;
}
// Periodic check for terminating the integration (based on steady heat
// release rate, etc.) Quit now to skip grid adaptation on the last step
if (t >= tEnd) {
return 1;
} else if (nTerminate >= options.terminateStepInterval) {
nTerminate = 0;
if (checkTerminationCondition()) {
return 1;
}
}
//**--------------------------------------- Main Part Of Code -----------------------------------------------
if (init_flag==1)
{
INIT_AllParameters();
//TM();
init_flag=0;
}
int k,j,kk;
// logFile.write(format("Hi moj 111111111111111111111111111111111111111111111111111111"));
updateChemicalProperties();
DiffusionVelocityCalculator();
ofstream poof ("Size_TripleMap.txt");
for ( int k= 0; k< sizedatacounter; k++)
{
poof<< sizedata(k) << "\n" ;
}
poof.close();
// logFile.write(format("Hi moj, the counter number in the loop for solving flame is : %i ") %Check_flag );
// PREMIXADV should be located here ------- PREMIX ADVANCEMENT IN TIME
// PREMIXADV FUNCTION -----------------------------------------------------------------------------------
PREMIXADV();
logFile.write(format("Hi moj, the NTS_PE is : %i ") %NTS_PE);
logFile.write(format("Hi moj, the simulation number is : %i ") %Check_flag);
if ((Check_flag%NTS_PE)==0)
{
TM();
sizedata(sizedatacounter)=L;
sizedatacounter=sizedatacounter+1;
}
/*if (Check_flag%200==0)
{
velocityCalculator();
//CFUEL();
}*/
VolumeExpansion();
FlamePositionCorrection();
Check_flag=Check_flag+1;
/* if (Check_flag%NTSPSIM==0 && NSIM_counter<=NSIM)
{
check_velocity=XMDOT*(8.3144627*T(nPoints-1))/(P*Wmx(nPoints-1));
if( check_velocity > 2.4 || check_velocity <= 0.0 )
{
init_flag=1;
error_flag=error_flag+1;
}
else
{
Print_flag = 1;
NSIM_counter=NSIM_counter+1;
}
}
*/
// Save the current integral and profile data in files that are
// automatically overwritten, and save the time-series data (out.h5)
if (nCurrentState >= options.currentStateStepInterval) {
calculateQdot();
nCurrentState = 0;
saveTimeSeriesData("out", true);
writeStateFile("profNow");
}
// *** Save flame profiles
if (t + 0.5 * dt > tProfile || nProfile >= options.profileStepInterval) {
if (options.outputProfiles) {
writeStateFile();
}
tProfile = t + options.profileTimeInterval;
nProfile = 0;
}
setupTimer.stop();
setupTimer.stop();
if (nTotal % 10 == 0) {
printPerformanceStats();
}
nTotal++;
return 0;
}
void FlameSolver::FlamePositionCorrection()
{
double Tavg,targetTemperature,targetPosition,difference1,difference;
int j,k;
/*Tavg= (T(0)+T(nPoints))/2;
difference=2000;
difference1=1800;
for(j=0; j<nPoints; j++)
{
difference1= T(j)-Tavg;
if ( difference1<difference)
{
difference=difference1;
targetPosition=j;
}
}
targetTemperature=T(targetPosition);*/
if (t<=0.003)
{
unitmovement= flamevelocity*dt;
}
else if ( t>0.003 && t<= 0.015)
{
unitmovement= 2.2*flamevelocity*dt;
}
else if ( t>0.015 && t<= 0.04)
{
unitmovement= 1.7*flamevelocity*dt;
}
movement=movement+unitmovement;
movecount=DX/unitmovement;
/*logFile.write(format("Hi moj, the move count is : %d ") %movecount);
logFile.write(format("Hi moj, the movement is : %d ") %(12300*unitmovement));
logFile.write(format("Hi moj, the DX is : %d ") %(100*DX));*/
if ((Check_flag%movecount) == 0)
{
for(j=0;j<nPoints;j++)
{
T_transient(j)=T(j);
for(k=0;k<nSpec;k++)
{
Y_transient(k,j)=Y(k,j);
}
}
for(j=0;j<nPoints-1;j++)
{
T(j+1)=T_transient(j);
for(k=0;k<nSpec;k++)
{
Y(k,j+1)=Y_transient(k,j);
}
}
moveflag=moveflag+1;
}
// logFile.write(format("Hi moj, the moveflag is : %d ") %moveflag);
}
void FlameSolver::VolumeExpansion()
{
int j,k,DCFlag,i,low_count,h,jj;
double SumDCV=0,low,slop;
assert(mathUtils::notnan(Y_old));
for(j=0;j<nPoints;j++)
{
rho_old[j]=rho[j];
}
updateChemicalProperties();
position[0]=0;
for(j=1;j<nPoints-1;j++)
{
DCvolume[j]=rho_old[j]/rho[j];
if (DCvolume[j]*DX+position[j-1] < DX*(nPoints-1))
{
position[j]=DCvolume[j]*DX+position[j-1];
}
else
{
position[j]=DX*nPoints;
}
}
position[nPoints-1]=(nPoints-1)*DX;
for (j=0;j<nPoints;j++)
{
T_old[j]=T(j);
for ( k=0;k<nSpec;k++)
{
Y_old(k,j)=Y(k,j);
}
}
for(j=0;j<nPoints;j++)
{
uniformGrid[j]=j*DX;
}
// i is counter of new cell
i=1;
for (j=2;j<nPoints-2;j++)
{
Find2NearPoints(j);
//logFile.write(format("Hi moj, target1 : %i T1 : %d X1 : %d target2 : %i T2 : %d X2: %d also j : %i") %target1 %T_old[target1] %position[target1] %target2 %T_old[target2] %position[target2] %j);
//logFile.write(format("----------------------- ") );
//linear interpolation;
slop= (T_old[target2]-T_old[target1])/(position[target2]-position[target1]);
//logFile.write(format("Hi moj, the slop is : %d ") %slop);
T(j)= T_old(target1)+(uniformGrid[j]-position[target1])*(slop);
for( k=0;k<nSpec;k++)
{
slop= (Y_old(k,target2)-Y_old(k,target1))/(position[target2]-position[target1]);
Y(k,j)=Y_old(k,target1)+(uniformGrid[j]-position[target1])*(slop);
}
}
}
void FlameSolver::Find2NearPoints(int local)
{
int j;
double temporary,tposition;
double diftemp[nPoints];
double local_position[nPoints];
for (j=0; j<nPoints;j++)
{
local_position[j]=position[j];
}
tposition= local * DX;
for (j=0; j<nPoints;j++)
{
diftemp[j]=abs(local_position[j]-tposition);
}
temporary= 2*nPoints*DX;
target1=0;
for(j=1;j<nPoints;j++)
{
if(local_position[j]< tposition)
{
if (temporary>diftemp[j])
{
temporary= diftemp[j];
target1=j;
}
}
}
local_position[target1]=2*nPoints*DX;
diftemp[target1]=abs(local_position[target1]-tposition);
temporary= 2*nPoints*DX;
target2=0;
for(j=1;j<nPoints;j++)
{
if(local_position[j]> tposition)
{
if (temporary>diftemp[j])
{
temporary= diftemp[j];
target2=j;
}
}
}
}
void FlameSolver::XRecord()
{
int profile,j;
profile=Print_counter;
string profileString=std::to_string(profile);
string pref="result/prof00";
string suf=".txt";
string filename1= profileString+suf;
string filename= pref+filename1;
ofstream prof (filename);
prof<< "Temperature profile at time : " << "\t" << t << "\n" ;
for ( j= 0; j< nPoints; j++)
{
prof<< T(j) << "\n" ;
}
prof.close();
}
void FlameSolver::ReadParameters(Config& config)
{
ifstream fin("config.txt");
string line;
while (getline(fin, line)) {
istringstream sin(line.substr(line.find("=") + 1));
//if (line.find("endtime") != -1)
// sin >> config.endtime;
//else if (line.find("timestep") != -1)
// sin >> config.timestep;
if (line.find("Re_t") != -1)
sin >> config.Re_t;
else if (line.find("dom") != -1)
sin >> config.dom;
else if (line.find("pressure") != -1)
sin >> config.pressure;
//else if (line.find("u") != -1)
// sin >> config.velocity;
//else if (line.find("T") != -1)
// sin >> config.Th; // GET_RHO_U
else if (line.find("kinematic_viscosity") != -1)
sin >> config.kinematic_viscosity;
else if (line.find("GFAC") != -1)
sin >> config.GFAC;
else if (line.find("FAL") != -1)
sin >> config.FAL;
else if (line.find("Intlength") != -1)
sin >> config.Intlength;
else if (line.find("Sl") != -1)
sin >> config.Sl;
else if (line.find("Clambda") != -1)
sin >> config.Clambda;
else if (line.find("Neta") != -1)
sin >> config.Neta;
}
}
void FlameSolver::DiffusionVelocityCalculator()
{
int j,k;
double SUM,VC,Yavg;
double Yp[nSpec][nPoints];
double XMF[nSpec][nPoints];
double XMFP[nSpec][nPoints];
assert(mathUtils::notnan(dVel));
for(j=0;j<nPoints;j++)
{
for(k=0;k<nSpec;k++)
{
XMF[k][j] = Y(k,j)*(Wmx(j)/W(k));
}
}
for(j=0;j<nPoints-1;j++)
{
for(k=0;k<nSpec;k++)
{
XMFP[k][j] = XMF[k][j+1];
}
}
for(k=0;k<nSpec;k++)
{
XMFP[k][nPoints-1] = XMF[k][nPoints-1];
}
for(j=0; j<nPoints; j++)
{
for(k=0;k<nSpec;k++)
{
dVel(k,j) = - Dkm(k,j)*(W(k)/Wmx(j))*(XMFP[k][j]-XMF[k][j])/DX;
}
SUM = 0.0;
for(k=0;k<nSpec;k++)
{
SUM = SUM + dVel(k,j);
}
VC = - SUM;
for(k=0;k<nSpec;k++)
{
Yavg=(Y(k,j)+Y(k,j+1))/2.0;
if (j<nPoints-1)
{
dVel(k,j) = dVel(k,j) + Yavg*VC;
}
else
{
dVel(k,j)=dVel(k,j) + Y(k,j)*VC;
}
}
}
/*if(t==2e-9){
ofstream proof ("diff_velocity.txt");
for ( k= 0; k< nPoints; k++)
{
proof<< dVel(9,k) << "\n" ;
}
proof.close();}*/
}
void FlameSolver::INIT_AllParameters()
{
Config config;
ReadParameters(config);
double Temperature,U_velocity,density;
//dt=config.timestep;
//NTS = config.endtime/dt;
DOM = config.dom;
NC= nPoints;
NCM1=NC-1;
NCP1=nPoints+1;
DX=DOM/NCM1;
//XMDT = dt/DX;
GFAC=config.GFAC;
NFL=config.FAL;
flamevelocity= (config.Sl);
//NSIM =config.NofRperR ;
//NTSPSIM=config.NSPE ;
NTS_COUNT = 0;
//Temperature= config.Th;
//U_velocity= config.velocity;
P =config.pressure;
//density = P*Wmx(nPoints-1)/(8.3144627*Temperature);
//XMDOT = rho(0)*U_velocity;
//logFile.write(format("Hi moj1, the XMDOT is : %d ") %XMDOT);
//XNU = config.kinematic_viscosity;
XLint = config.Intlength;
C_lambda = config.Clambda ;
Rate=0;
for (int j=0;j<nPoints;j++)
{
XNU=(mu(j)/rho(j));
Re=2.16*0.01*XLint/XNU;
XLk = (config.Neta)*XLint/pow(Re,0.75);
XNU=(10000)*(mu(j)/rho(j));
Rate =Rate+DOM*100*(54.0/5.0)*( XNU*Re/(C_lambda*pow(XLint,3)) )*( pow((XLint/XLk),(5/3)) - 1)/( 1 - pow((XLk/XLint),(4/3)) );
}
Rate=Rate/nPoints;
logFile.write(format("Hi moj, the kinematic viscosity is : %d ") %XNU);
logFile.write(format("Hi moj, the dynamic is : %d ") %mu(5));
logFile.write(format("Hi moj, the rho is : %d ") %rho(5));
//Re = config.Re_t;
//XLk = (config.Neta)*XLint/pow(Re,0.75);
//XNU=config.kinematic_viscosity;
//Rate = DOM*100*(54.0/5.0)*( XNU*Re / (C_lambda*pow(XLint,3)) )*( pow((XLint/XLk),(5/3)) - 1)/( 1 - pow((XLk/XLint),(4/3)) );
logFile.write(format("Hi moj, the Rate is : %d ") %Rate);
logFile.write(format("Hi moj, the dt is : %d ") %dt);
NTS_PE = (1.0/Rate)/dt+1;
PDFA = pow(XLint,(5.0/3.0)) * pow(XLk,(-5.0/3.0)) / ( pow((XLint/XLk),(5.0/3.0)) -1.0 );
PDFB = -pow(XLint,(5.0/3.0))/( pow((XLint/XLk),(5.0/3.0)) -1.0 );
TAU = XLk*XLk/XNU;
if( (1.0/Rate)/dt < 1.0 )
{
MTS = int(Rate*dt)+1;
}
else
{
MTS = 1;
}
}
void FlameSolver::velocityCalculator()
{
int j;
for (j=0;j<nPoints;j++)
{
U_velocity(j)=XMDOT/rho(j);
}
ofstream proof ("velocity.txt");
for ( j= 0; j< nPoints; j++)
{
proof<< U_velocity(j) << "\n" ;
}
proof.close();
}
void FlameSolver::Random_Number()
{
random=double(rand())/RAND_MAX;
}
void FlameSolver::eddyLength()
{
// generate a random number between 0 and 1
Random_Number();
int NSize;
// make sure eddy is Greater than 6 cells long
NSize = int(pow((random-PDFA)/PDFB,(-3.0/5.0))/(DX*100));
while (NSize<5)
{
Random_Number();
NSize = int(pow((random-PDFA)/PDFB,(-3.0/5.0))/(DX*100));
//logFile.write(format("hi moj, the size value NSize=%i random=%d") % NSize % random);
}
// make sure eddy size is divisible by 3
if((NSize%3)==0)
{
L=NSize;
}
else if ((NSize%3)==1)
{
L=NSize-1;
}
else if ((NSize%3)==2)
{
L=NSize+1;
}
/*if(t==2e-9){
ofstream proof ("diff_velocity.txt");
for ( k= 0; k< nPoints; k++)
{
proof<< dVel(9,k) << "\n" ;
}
proof.close();}*/
}
void FlameSolver::BTriplet(double var[])
{
// Permute Cells M through M+L-1 of the array S
// as prescribrd by the discrete triplet map , where L is an integer multiple by 3.
int Lo,k,j;
Lo=int(L/3);
double X[L];
// first part of mapping
for(j=1;j<=Lo;j++)
{
k=M+3*(j-1);
X[j]=var[k]; //gather the cells going to the 1st image
}
// second part of mapping
for (j=1;j<=Lo;j++)
{
k=M+L+1-(3*j); // minus sign because second image is flipped
X[j+Lo]=var[k]; // gather the cells going to 2nd image
}
// third part of mapping
for (j=1;j<=Lo;j++)
{
k=M+(3*j)-1;
X[j+Lo+Lo]=var[k];// gather the cells going to the 3rd image
}
for(j=1;j<=L;j++)
{
k=M+j-1;
var[k]=X[j];
}
}
void FlameSolver::TM()
{
// MTS shows number of triplet map require in each realization
// first of all call a random number
double Temp[nPoints];
double y_x[nPoints];
int j,k;
// first of all call a random number
Random_Number();
// m determine the starting point of triplet map
M=int(random*nPoints);
// this loop check the starting point of triplet map
while(M<(NCP1/4))
{
Random_Number();
M=int(random*nPoints);
}
// calculate the eddy length
eddyLength();
// check eddy size does not exceed domain
if((L+M)>nPoints)
{
M=nPoints-L;
}
while((L+M)>nPoints || M<(NCP1/4))
{
Random_Number();
M=int(random*nPoints);
eddyLength();
}
for(j=0;j<nPoints;j++)
{
Temp[j]=T(j);
}
BTriplet(Temp);
for(j=0;j<nPoints;j++)
{
T(j)=Temp[j];
}
for(k=0;k<=nSpec;k++)
{
for(j=0;j<nPoints;j++)
{
y_x[j]=Y(k,j);
}
BTriplet(y_x);
for(j=0;j<nPoints;j++)
{
Y(k,j)=y_x[j];
}
}
}
void FlameSolver::CFUEL()
{
// NFL set based on chemistry, you should find the CH4 location in Y matrix
int NSTAB;
double velocity,RHO2;
velocity=U_velocity(0);
logFile.write(format("*******************************************************************"));
logFile.write(format("*******************************************************************"));
logFile.write(format("hi moj, the size value velocity : %d") %velocity);
logFile.write(format("*******************************************************************"));
logFile.write(format("*******************************************************************"));
RHO2=rho(0);
logFile.write(format("hi moj, the size value RHO2 : %d") %RHO2);
NSTAB = int(2*NCP1/5);
logFile.write(format("hi moj, the size value NSTAB : %d") %NSTAB);
double A=0.8*Y(NFL,0);
logFile.write(format("hi moj, the size value A : %d") %A);
logFile.write(format("hi moj, the size value Y(NFL,NSTAB) : %d") %Y(NFL,NSTAB));
XMDOT = RHO2*velocity;
logFile.write(format("hi moj, the size value XMDOT : %d") %XMDOT);
// MILD CORRECTION
if(Y(NFL,NSTAB)< A && velocity<0.3)
{
velocity= velocity + 0.00001;
logFile.write(format("hi moj 1"));
}
else if(Y(NFL,NSTAB+1)> A && velocity> 0.15)
{
logFile.write(format("hi moj 2"));
velocity = velocity - 0.00001;
}
// AGRESSIVE CORRECTION
if( Y(NFL,NSTAB-2) <= A && velocity < 0.3)
{