-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitting_routines.cpp
executable file
·182 lines (136 loc) · 5.58 KB
/
splitting_routines.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
#include "splitting_routines.h"
//--------SHIFTS SEQUENCE TO LEFT FOR 2l/3-------------//
void shift_arr_l(double **s, int lx, int ly, double dx, int& position, int& position_cut, int& position_end, int& brojac, int& brojac_cut, int& brojac_end, double& path, double& path_cut, double& path_end)
{ int i,j;
for(j=0;j<ly;j++)
{
for(i=0;i<2*lx/3;i++)
s[i][j]=s[i+lx/3][j];
for(i=0;i<lx/3;i++)
s[i+2*lx/3][j]=0;
}
path = path + (lx/3-brojac)*dx;
brojac = 1;
position = lx/3;
path_cut = path_cut + (lx/3-brojac_cut)*dx;
brojac_cut = 1;
position_cut = lx/3;
path_end = path_end + (lx/3-brojac_end)*dx;
brojac_end = 1;
position_end = lx/3;
}
//---------Fourier transform-----------//
void fftw_line(double **sq, double *pos_line, const int& ly, const long int& j1)
{ fftw_plan p;
fftw_complex *izlaz;
int iy;
izlaz = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * ly); // def complex sequence
p = fftw_plan_dft_r2c_1d(ly,pos_line,izlaz,FFTW_ESTIMATE);
fftw_execute(p);
sq[0][j1]=sq[0][j1] + (pow(izlaz[0][0],2) + pow(izlaz[0][1],2));
for(iy=1;iy<ly/2;iy++)
sq[iy][j1]=sq[iy][j1] + (pow(izlaz[iy][0],2) + pow(izlaz[iy][1],2))/(ly);
fftw_destroy_plan(p);
fftw_free(izlaz);
}
void integrate_noise(double **s, const int& position, const int& ly, const double& dt, const double& sigma, const double& lambda, long int *inic)
{ double prev_value, new_value;
int inic_noise;
for(int iy=0;iy<ly;iy++)
{
inic_noise=position-50;
do inic_noise++;
while (s[inic_noise][iy]>0.5); // inic_noise, implements noise for values of rho<0.5
for(int ix=inic_noise;ix<position+250;ix++)
{
if(s[ix][iy]*lambda>1000)
s[ix][iy]=s[ix][iy]+sigma*sqrt(s[ix][iy]*dt)*gauss(0,1,inic);
else
if(s[ix][iy]*lambda>0.0001)
{ prev_value=s[ix][iy];
new_value=gamdev(poidev(lambda*s[ix][iy],inic),inic);
s[ix][iy]=new_value/lambda;
if(!isfinite(s[ix][iy]) || s[ix][iy]!=s[ix][iy])
{ s[ix][iy]=prev_value;
cout<< s[ix][iy] << " 2.deo p.!! " << prev_value << " " << ix << " " << iy << " "<< new_value << endl;
}
}
else s[ix][iy]=0;
}
}
}
void integrate_diffusion(double **s, double *firstx, double *lastx1, double *lastx2, const int& position, const int& lx, const int& ly, const double& dx, const double& dt, const double& D)
{ double last1, last2;
int ix,iy;
last1=s[0][0];
firstx[0]=1;
firstx[lx-1]=0;
last1=s[position-101][0];
for(ix=position-100;ix<position+252;ix++) //lx-1 position+50
{
last2=s[ix][0]; // FIRST WAVE, ON THE LEFT
firstx[ix]=s[ix][0];
lastx1[ix]=s[ix][0];
s[ix][0]=s[ix][0] + D*dt*(s[ix+1][0] + last1 + s[ix][1] + s[ix][ly-1] - 4*s[ix][0])/(dx*dx) + s[ix][0]*dt - s[ix][0]*s[ix][0]*dt; // Deterministic term b=1
last1=last2;
}
for(iy=1;iy<ly-1;iy++)
{
last1=1; last1=s[position-101][iy];
for(ix=position-100;ix<position+252;ix++) // WAVES INSIDE THE REGION
{
last2=s[ix][iy];
lastx2[ix]= s[ix][iy];
s[ix][iy] = s[ix][iy] + D*dt*(s[ix+1][iy] + last1 + lastx1[ix] + s[ix][iy+1] - 4*s[ix][iy])/(dx*dx) + s[ix][iy]*dt - s[ix][iy]*s[ix][iy]*dt; // Deterministic term b=1
last1=last2;
lastx1[ix]=lastx2[ix];
}
}
last1=1; last1=s[position-101][iy];
for(ix=position-100;ix<position+252;ix++) // LAST WAVE
{
last2=s[ix][ly-1];
s[ix][ly-1]=s[ix][ly-1] + D*dt*(s[ix+1][ly-1] + last1 + firstx[ix] + lastx1[ix] - 4*s[ix][ly-1])/(dx*dx) + s[ix][ly-1]*dt - s[ix][ly-1]*s[ix][ly-1]*dt; // Deterministic term b=1
last1=last2;
}
}
void check_wave_positions(double **s, int& position, int& position_cut, int& position_end, const double& N)
{
if(s[position][0]>0.5)
{do position=position+1; while (s[position][0]>0.5);} //locating the front
if(s[position_cut][0]>1/N)
{do position_cut=position_cut+1; while (s[position_cut][0]>1/N);} //locating the edge
if(s[position_end][0]>0)
{do position_end=position_end+1; while (s[position_end][0]>0);} //locating the edge
}
void calculate_positions(double **s, const int& lx, const int& ly, const long int& j1, double point, double **y_fce_t, double *pos, double *omega, int& brojac, double& path, const double& dx)
{
int iy, ix = brojac-1;
double h=0;
do ix++;
while(s[ix+lx/3][0]>point);
path = path + (ix-brojac)*dx;
pos[0] = (path*(s[ix+lx/3-1][0]-s[ix+lx/3][0])+s[ix+lx/3][0]-point)/(s[ix+lx/3-1][0]-s[ix+lx/3][0]);
y_fce_t[j1][0] = y_fce_t[j1][0] + pos[0];
brojac=ix;
// Positions of other waves:
for(iy=1;iy<ly;iy++)
{
ix = brojac;
if(s[ix+lx/3][iy]>point)
{ do ix++;
while(s[ix+lx/3][iy]>point);
} else
{
do ix--;
while(s[ix+lx/3][iy]<point); ix++;
}
pos[iy] = ((path+(ix-brojac)*dx)*(s[ix+lx/3-1][iy]-s[ix+lx/3][iy])+s[ix+lx/3][iy]-point)/(s[ix+lx/3-1][iy]-s[ix+lx/3][iy]);
y_fce_t[j1][iy] = y_fce_t[j1][iy] + pos[iy];
}
for(iy=0;iy<ly;iy++)
h = h + pos[iy];
h=h/ly;
for(iy=0;iy<ly;iy++)
omega[j1]=omega[j1]+(pos[iy]-h)*(pos[iy]-h)/ly;
}