source: issm/trunk-jpl/src/m/contrib/gravity/vfsa.cpp@ 18435

Last change on this file since 18435 was 18435, checked in by abuzzi, 11 years ago

MODIF: generation of the new matrix

File size: 16.0 KB
Line 
1#include <iostream>
2#include <cmath>
3#include <fstream>
4#include <string>
5#include <cstdio>
6#include <cstdlib>
7#include <time.h>
8#include <cassert>
9#include <gsl/gsl_multifit.h>
10
11using namespace std;
12
13class Matrix{/*{{{*/
14 private:
15 int M; /*Number of lines */
16 int N; /*Number if Columns */
17 double *values;
18 public:
19 Matrix(int m_in,int n_in){/*{{{*/
20 this->M = m_in;
21 this->N = n_in;
22 this->values = new double[M*N];
23 }/*}}}*/
24 ~Matrix(){/*{{{*/
25 delete [] this->values;
26 }/*}}}*/
27 void Echo(void){/*{{{*/
28 for(int i=0;i<M;i++){
29 for(int j=0;j<N;j++){
30 cout << " " << this->values[i*N+j];
31 }
32 cout << endl;
33 }
34 }/*}}}*/
35 void SetValue(int i,int j,double value){/*{{{*/
36 this->values[i*N+j] = value;
37 }/*}}}*/
38 double GetValue(int i,int j){/*{{{*/
39 return this->values[i*N+j];
40 }/*}}}*/
41 void GetSize(int* pM,int* pN){/*{{{*/
42 *pM = this->M;
43 *pN = this->N;
44 }/*}}}*/
45 double* GetPointer(void){/*{{{*/
46 return this->values;
47 }/*}}}*/
48 void MatrixSum(Matrix* A,Matrix* B){/*{{{*/
49 /*Check that sizes are compatible*/
50 int M_B,N_B,M_A,N_A;
51 B->GetSize(&M_B,&N_B);
52 A->GetSize(&M_A,&N_A);
53 assert(this->M==M_B && this->N==N_B);
54 assert(this->M==M_A && this->N==N_A);
55 for(int i=0;i<this->M;i++){
56 for(int j=0;j<this->N;j++){
57 this->SetValue(i,j,A->GetValue(i,j) + B->GetValue(i,j));
58 }
59 }
60 }/*}}}*/
61 void MatrixDiff(Matrix* A,Matrix* B){/*{{{*/
62 /*Check that sizes are compatible*/
63 int M_B,N_B,M_A,N_A;
64 B->GetSize(&M_B,&N_B);
65 A->GetSize(&M_A,&N_A);
66 assert(this->M==M_B && this->N==N_B);
67 assert(this->M==M_A && this->N==N_A);
68 for(int i=0;i<this->M;i++){
69 for(int j=0;j<this->N;j++){
70 this->SetValue(i,j,A->GetValue(i,j) - B->GetValue(i,j));
71 }
72 }
73 }/*}}}*/
74 void MatrixAbs(Matrix* A){/*{{{*/
75 for(int i=0;i<this->M;i++){
76 for(int j=0;j<this->N;j++){
77 this->SetValue(i,j,fabs(A->GetValue(i,j)));
78 }
79 }
80 }/*}}}*/
81 void MatrixEqual(Matrix* A){/*{{{*/
82 for(int i=0;i<this->M;i++){
83 for(int j=0;j<this->N;j++){
84 this->SetValue(i,j,A->GetValue(i,j));
85 }
86 }
87 }/*}}}*/
88 double MatrixInternSum(){/*{{{*/
89 double sum=0;
90 for(int i=0;i<this->M;i++){
91 for(int j=0;j<this->N;j++){
92 sum+=this->GetValue(i,j);
93 }
94 }
95 return sum;
96 }/*}}}*/
97 void ExtractLine(Matrix* A,int i){/*{{{*/
98 /* Check that the size of A is compatible */
99 int M_A,N_A;
100 A->GetSize(&M_A,&N_A);
101 assert(M_A==1 && this->N==N_A);
102 for(int j=0;j<this->N;j++){
103 A->SetValue(0,j,this->GetValue(i,j));
104 }
105 }/*}}}*/
106 void ExtractColumn(Matrix* A,int j){/*{{{*/
107 /* Check that the size of A is compatible */
108 int M_A,N_A;
109 A->GetSize(&M_A,&N_A);
110 assert(N_A==1 && this->M==M_A);
111 for(int i=0;i<this->M;i++){
112 A->SetValue(i,0,this->GetValue(i,j));
113 }
114 }/*}}}*/
115 void AddNumber(double a){/*{{{*/
116 for(int i=0;i<this->M;i++){
117 for(int j=0;j<this->N;j++){
118 this->SetValue(i,j,this->GetValue(i,j) + a);
119 }
120 }
121 }/*}}}*/
122};/*}}}*/
123
124/*Local prototypes{{{*/
125void makep(Matrix *Pobs,int nx,int ny, int dx, int dy);
126void vec2grid(Matrix *V,Matrix *V1,Matrix *V2,int nx, int ny);
127void msplit( Matrix *m, Matrix *m1,Matrix *m2,double dlevel);
128void plouff(Matrix *g,Matrix *Pobs,Matrix *Pp,Matrix * mesh,Matrix *rho,int dx,int dy, int dn,int m,int n,int l);
129void vec2gridsimple(Matrix *V,Matrix *V1,int nx, int ny);
130void reshape(Matrix* V,Matrix* V1,int nx,int ny);
131double misfit(Matrix* m0,Matrix* evalid,Matrix* gobs,int dlevel,Matrix* Pobs,Matrix* xobs,Matrix* yobs,Matrix* Pp,Matrix* rho1, Matrix* rho2,int dx,int dy,int dn,int nx,int ny, int mx,int my);
132void GSLsquarefit(Matrix** pX,Matrix* A,Matrix* B);
133double signe(double a);
134void filtergrav(Matrix* A,Matrix* Ain,double ctr,double sd,int mx,int my);
135/*}}}*/
136
137int main(){/*{{{*/
138
139 /* Seed the random number generator {{{*/
140 srand (time(NULL)); /*}}}*/
141 /* Define the variables {{{*/
142
143 int dx = 500; /* prism dimension in x-direction */
144 int dy = 500; /* prism dimension in y-direction */
145 int mx = 39; /* number of prisms in x-direction */
146 int my = 60; /* number of prisms in y-direction */
147 int nx = 39; /* number of data points in x-direction */
148 int ny = 60; /* number of data points in y-direction */
149 int dn = 15000; /* distance for neighbouting prisms for gravity calculation */
150 double ptval = 100.; /* max. amount to perturb model */
151 double ptval2 = 100.;
152
153 Matrix *Pobs=new Matrix(nx*ny,2); /* data positions */
154 makep(Pobs,nx,ny,dx,dy);
155// Pobs->Echo();
156
157
158 Matrix *Pp=new Matrix(mx*my,2); /* data positions */
159 makep(Pp,mx,my,dx,dy);
160// Pp->Echo();
161
162 double rhoi = 890; /* ice density */
163 double rhow = 1030; /* water density */
164// double rhos = 2013; /* sediment density */
165 double rhoc = 2670; /* bedrock density */
166
167 Matrix *Rho = new Matrix(1,2);
168 Rho->SetValue(0,0,rhoi);
169 Rho->SetValue(0,1,rhow);
170 Matrix *rho1 = new Matrix(1,3);
171 rho1->SetValue(0,0,rhoi);
172 rho1->SetValue(0,1,rhow);
173 rho1->SetValue(0,2,rhoc);
174 Matrix *rho2 = new Matrix(1,2);
175 rho2->SetValue(0,0,rhoi-rhoc);
176 rho2->SetValue(0,1,rhow-rhoc);
177
178 double ctr=1; /* parameter for filtering */
179 double sd=0.1;
180
181 Matrix *xobs= new Matrix(ny,nx);
182 Matrix *yobs= new Matrix(ny,nx);
183
184 vec2grid(Pobs,xobs,yobs,nx,ny);
185// xobs->Echo();
186// yobs->Echo();
187
188 double dlevel= 860; /* mean level of data acquisition */
189
190 double mmax = 1000; /* max value for layer interfaces */
191 double mmax2 = 1000;
192 double mmax3 = 1000;
193
194 /* control parameter for temperature schedule */
195
196 double ca=0.9; /* for acceptance */
197 double cm=0.5; /* for model perturbation */
198 /*}}}*/
199 /* load the data {{{*/
200
201 /* Observed gravity anomaly */
202
203 ifstream file1("store_fa500_36s.txt");
204 Matrix * gobs= new Matrix(nx*ny,1);
205 double inputnumber;
206 for(int i=0;i<ny*nx; i++){
207 file1 >> inputnumber;
208 gobs->SetValue(i,0, inputnumber*1e-5);
209 }
210 file1.close();
211// gobs->Echo();
212
213 /* load data about the ice thickness */
214
215 ifstream file2("store_flag_icethick500.txt");
216 Matrix * icethick= new Matrix(mx*my,1);
217 for(int s=0;s<mx*my; s++){
218 file2 >> inputnumber;
219 icethick->SetValue(s,0,inputnumber);
220 }
221 file2.close();
222// icethick->Echo();
223
224 /* load the batimethry data */
225
226 ifstream file3("store_flag_bathy500.txt");
227 Matrix * bathy= new Matrix(mx*my,1);
228 for(int s=0;s<mx*my; s++){
229 file3 >> inputnumber;
230 bathy->SetValue(s,0,inputnumber);
231 }
232 file3.close();
233// bathy->Echo();
234
235 /* id of grid to evaluate misfit */
236
237
238 ifstream file4("store_flag_eval500.txt");
239 Matrix * evalid= new Matrix(mx*my,1);
240 for(int s=0;s<mx*my; s++){
241 file4 >> inputnumber;
242 evalid->SetValue(s,0,inputnumber);
243 }
244 file4.close();
245// evalid->Echo();
246
247 /* initial guess of the model */
248
249 ifstream file5("m0_140114b.txt");
250 Matrix * mesh_ini= new Matrix(mx*my,3);
251 for(int s=0;s<mx*my; s++){
252 for(int j=0;j<3;j++){
253 file5 >> inputnumber;
254 mesh_ini->SetValue(s,j,inputnumber);
255 }
256 }
257 file5.close();
258// mesh_ini->Echo();
259 /*}}}*/
260 double q=0;
261 q=misfit(mesh_ini,evalid,gobs,dlevel,Pobs,xobs,yobs,Pp,rho1,rho2,dx,dy,dn,nx,ny,mx,my);
262 cout<< q;
263/* Matrix* G=new Matrix(4,3);
264 Matrix* df=new Matrix(4,1);
265 Matrix* o=new Matrix(4,1);
266 for(int i= 0;i<4;i++){
267 for(int j=0;j<3;j++){
268 if(j==2){G->SetValue(i,j,1);}
269 else{G->SetValue(i,j,i+j);}
270 }
271 df->SetValue(i,0,i*1e-3);
272 }
273 G->SetValue(0,0,1);
274 G->SetValue(0,1,2);
275
276 Matrix* M = NULL;
277 GSLsquarefit(&M,G,df);
278 for(int i= 0;i<4;i++){
279 o->SetValue(i,0,G->GetValue(i,0)*M->GetValue(0,0)+G->GetValue(i,1)*M->GetValue(1,0)+G->GetValue(i,2)*M->GetValue(2,0));}
280
281 G->Echo();
282 df->Echo();
283 M->Echo();
284 o->Echo();*/
285double a;
286a=signe(-9);
287cout<<a;
288 return 0;
289}/*}}}*/
290
291void GSLsquarefit(Matrix** pX,Matrix* A,Matrix* B){/*{{{*/
292
293 /*GSL Matrices and vectors: */
294 int M,N;
295 double chisq;
296
297 /*Get system size*/
298 A->GetSize(&M,&N);
299
300 /*Initialize gsl matrices and vectors: */
301 gsl_matrix* a = gsl_matrix_alloc(M,N);
302 for(int i=0;i<M;i++){
303 for(int j=0;j<N;j++){
304 gsl_matrix_set (a,i,j,A->GetValue(i,j));
305 }
306 }
307 gsl_vector* b = gsl_vector_alloc(M);
308 for(int i=0;i<M;i++){
309 gsl_vector_set(b,i,B->GetValue(i,0));
310 }
311
312 gsl_vector* x = gsl_vector_alloc(N);
313 gsl_matrix* cov = gsl_matrix_alloc(N,N);
314
315 /*Least square fit: */
316 gsl_multifit_linear_workspace* work = gsl_multifit_linear_alloc(M,N);
317 gsl_multifit_linear (a, b, x, cov, &chisq, work);
318 gsl_multifit_linear_free (work);
319
320 /*Clean up and assign output pointer*/
321 Matrix* X = new Matrix(N,1);
322 for(int j=0;j<N;j++){
323 X->SetValue(j,0,gsl_vector_get(x,j));
324 }
325 *pX = X;
326
327 gsl_matrix_free(a);
328 gsl_vector_free(b);
329 gsl_matrix_free(cov);
330
331}/*}}}*/
332void makep(Matrix *Pobs,int nx,int ny, int dx, int dy){/*{{{*/
333 for(int i=0;i<ny;i++){
334 for(int j=0;j<nx;j++){
335 Pobs->SetValue(j+nx*i,0,j*dx);
336 Pobs->SetValue(j+nx*i,1,i*dy);
337 }
338 }
339}/*}}}*/
340void vec2grid(Matrix *V,Matrix *V1,Matrix *V2,int nx, int ny){/*{{{*/
341 for(int i=0;i<ny;i++){
342 for (int j=0;j<nx;j++){
343 V1->SetValue(i,j, V->GetValue(j+nx*i,0));
344 V2->SetValue(i,j, V->GetValue(j+nx*i,1));
345 }
346 }
347}/*}}}*/
348void msplit( Matrix *m, Matrix *m1,Matrix *m2,double dlevel){/*{{{*/
349 int sizem1,sizem2;
350 m->GetSize(&sizem1,&sizem2);
351 for(int i=0;i<sizem1;i++){
352 for(int j=0;j<sizem2+1;j++){
353 if(j<sizem2){
354 m1->SetValue(i,j,1e-10*(sizem2+1-j));
355 m2->SetValue(i,j,m->GetValue(i,j));
356 if(m->GetValue(i,j)<0){
357 m1->SetValue(i,j,m->GetValue(i,j));
358 m2->SetValue(i,j,i*1e-10);
359 }
360 }
361 else{
362 m1->SetValue(i,j,1e-10);
363 }
364 }
365 }
366 m1->AddNumber(dlevel);
367 m2->AddNumber(dlevel);
368}/*}}}*/
369void plouff(Matrix *g,Matrix *Pobs,Matrix *Pp,Matrix * mesh,Matrix *rho,int dx,int dy, int dn,int m,int n,int l){/*{{{*/
370 double gg=6.673e-11;
371 int si,sj,id,s;
372 double R,Q,P;
373 Matrix *xp= new Matrix(1,2);
374 Matrix *yp= new Matrix(1,2);
375 Matrix *xpp= new Matrix(1,2);
376 Matrix *ypp= new Matrix(1,2);
377 Matrix *U= new Matrix(l,4);
378 Matrix *U1=new Matrix(1,4);
379 Matrix *U2=new Matrix(1,4);
380 Matrix *gl= new Matrix(1,l-1);
381 bool test=true;
382 for(int c=0;c<n;c++){
383 g->SetValue(c,0,0);
384 for(int a=0;a<m;a++){
385 test=true;
386 xp->SetValue(0,0,Pp->GetValue(a,0)-Pobs->GetValue(c,0));
387 xp->SetValue(0,1,Pp->GetValue(a,0)-Pobs->GetValue(c,0)+dx);
388 if(xp->GetValue(0,0)<0 && xp->GetValue(0,0)<xp->GetValue(0,1) && xp->GetValue(0,0)*xp->GetValue(0,1)>=0){
389 xpp->SetValue(0,0,xp->GetValue(0,1));
390 xpp->SetValue(0,1,xp->GetValue(0,0));
391 xp->MatrixAbs(xpp);
392 }
393 yp->SetValue(0,0,Pp->GetValue(a,1)-Pobs->GetValue(c,1));
394 yp->SetValue(0,1,Pp->GetValue(a,1)-Pobs->GetValue(c,1)+dy);
395 if(yp->GetValue(0,0)<0 && yp->GetValue(0,0)<yp->GetValue(0,1) && yp->GetValue(0,0)*yp->GetValue(0,1)>=0){
396 ypp->SetValue(0,0,yp->GetValue(0,1));
397 ypp->SetValue(0,1,yp->GetValue(0,0));
398 yp->MatrixAbs(ypp);
399 }
400 P=sqrt(xp->GetValue(0,0)*xp->GetValue(0,0)+yp->GetValue(0,0)*yp->GetValue(0,0));
401 if(P>dn){
402 test=false;
403 for(int i=0;i<l-1;i++){
404 gl->SetValue(0,i,0);
405 }
406 }
407 if(test==true){
408 si=1;
409 sj=1;
410 id=0;
411 for(int i=0;i<2;i++){
412 si*=-1;
413 for(int j=0;j<2;j++){
414 si*=-1;
415 s=si*sj;
416 for(int k=0;k<l;k++){
417 R=sqrt(xp->GetValue(0,i)*xp->GetValue(0,i)+yp->GetValue(0,j)*yp->GetValue(0,j)+mesh->GetValue(a,k)*mesh->GetValue(a,k));
418 Q=atan(xp->GetValue(0,i)*yp->GetValue(0,j)/(mesh->GetValue(a,k)*R));
419 U->SetValue(k,id,s*(mesh->GetValue(a,k)*Q-xp->GetValue(0,i)*log(R+yp->GetValue(0,j))-yp->GetValue(0,j)*log(R+xp->GetValue(0,i))));
420 }
421 id++;
422 }
423 }
424 for(int b=0;b<l-1;b++){
425 U->ExtractLine(U1,b);
426 U->ExtractLine(U2,b+1);
427 gl->SetValue(0,b,rho->GetValue(0,b)*(U1->MatrixInternSum()*(-1)+U2->MatrixInternSum()));
428 }
429 }
430 g->SetValue(c,0,g->GetValue(c,0)+gg*gl->MatrixInternSum());
431 }
432 }
433 delete xp;
434 delete yp;
435 delete xpp;
436 delete ypp;
437 delete gl;
438 delete U;
439 delete U1;
440 delete U2;
441 }/*}}}*/
442void vec2gridsimple(Matrix *V,Matrix *V1,int nx, int ny){/*{{{*/
443 for(int i=0;i<ny;i++){
444 for (int j=0;j<nx;j++){
445 V1->SetValue(i,j, V->GetValue(j+nx*i,0));
446 }
447 }
448}/*}}}*/
449void reshape(Matrix* V,Matrix* V1,int nx,int ny){/*{{{*/
450 for (int i=0;i<ny;i++){
451 for(int j=0;j<nx;j++){
452 V1->SetValue(j+nx*i,0,V->GetValue(i,j));
453 }
454 }
455}/*}}}*/
456double misfit(Matrix* m0,Matrix* evalid,Matrix* gobs,int dlevel,Matrix* Pobs,Matrix* xobs,Matrix* yobs,Matrix* Pp,Matrix* rho1, Matrix* rho2,int dx,int dy,int dn,int nx,int ny, int mx,int my){/*{{{*/
457 Matrix* m1=new Matrix(mx*my,4);
458 Matrix* m2=new Matrix(mx*my,3);
459 Matrix* g1=new Matrix(nx*ny,1);
460 Matrix* g2=new Matrix(nx*ny,1);
461 Matrix* g=new Matrix(nx*ny,1);
462 Matrix* gcalgr=new Matrix(ny,nx);
463 Matrix* gcalvec=new Matrix(mx*my,1);
464 Matrix* df=new Matrix(mx*my,1);
465 Matrix* G=new Matrix(mx*my,3);
466 double a=0;
467 double b=0;
468 double e=0;
469 msplit(m0,m1,m2,dlevel);
470 plouff(g1,Pobs,Pp,m1,rho1,dx,dy,dn,mx*my,nx*ny,4);
471 plouff(g2,Pobs,Pp,m2,rho2,dx,dy,dn,mx*my,nx*ny,3);
472 g->MatrixSum(g1,g2);
473 vec2gridsimple(g,gcalgr,nx,ny);
474 reshape(gcalgr,gcalvec,mx,my);
475 for (int i=0;i<mx*my;i++){
476 df->SetValue(i,0,evalid->GetValue(i,0)*(gobs->GetValue(i,0)-gcalvec->GetValue(i,0)));
477 G->SetValue(i,0,evalid->GetValue(i,0)*Pobs->GetValue(i,0));
478 G->SetValue(i,1,evalid->GetValue(i,0)*Pobs->GetValue(i,1));
479 G->SetValue(i,2,evalid->GetValue(i,0));
480 }
481 Matrix* M = NULL;
482 GSLsquarefit(&M,G,df);
483
484 for (int i=0;i<my;i++){
485 for(int j=0;j<mx;j++){
486 gcalgr->SetValue(i,j,gcalgr->GetValue(i,j)+xobs->GetValue(i,j)*M->GetValue(0,0)+yobs->GetValue(i,j)*M->GetValue(1,0)+M->GetValue(2,0));
487 }
488 }
489 reshape(gcalgr,g,mx,my);
490 for (int i=0;i<mx*my;i++){
491 a=a+fabs(evalid->GetValue(i,0)*(gobs->GetValue(i,0)-g->GetValue(i,0)));
492 b=b+fabs(evalid->GetValue(i,0)*(gobs->GetValue(i,0)+g->GetValue(i,0)));
493 }
494 e=2*a/(a+b);
495 return e;
496}/*}}}*/
497void newmodelgen(Matrix* m0,Matrix* m1,Matrix* bathy,Matrix* icethick,int mx,int my,double T,double ptval,double mmax,double mmax2,double ctr,double sd){/*{{{*/
498 Matrix* m1gr=new Matrix(my,mx);
499 Matrix* m1grsm=new Matrix(my,mx);
500 Matrix* m1col=new Matrix(mx*my,1);
501 double u=0;
502 double y=0;
503 m1->MatrixEqual(m0);
504 for (int i=0;i<mx*my;i++){
505 if(icethick->GetValue(i,0)==0){
506 u=double (rand())/ double(RAND_MAX);
507 y=signe(u-0.5)*T*(pow(1+1/T,fabs(2*u-1))-1);
508 m1->SetValue(i,1,m0->GetValue(i,1)+y*ptval);
509 if(m1->GetValue(i,1)<=m1->GetValue(i,0)){
510 m1->SetValue(i,1,m1->GetValue(i,0)+1e-10);
511 }
512 if(m1->GetValue(i,1)>=m1->GetValue(i,0)+mmax){
513 m1->SetValue(i,1,m1->GetValue(i,0)+mmax);
514 }
515 }
516 }
517 m1->ExtractColumn(m1col,1);
518 vec2gridsimple(m1col,m1gr,mx,my);
519 filtergrav(m1grsm,m1gr,ctr,sd,mx,my);
520 reshape(m1grsm,m1col,mx,my);
521 for (int i=0;i<mx*my;i++){
522 if(icethick->GetValue(i,0)==0){
523 m1->SetValue(i,1,m1col->GetValue(i,0));
524 }
525 else{
526 m1->SetValue(i,1,m0->GetValue(i,1));
527 }
528 if(m1->GetValue(i,1)<=m1->GetValue(i,0)){
529 m1->SetValue(i,1,m1->GetValue(i,0)+1e-10);
530 }
531 }
532
533 for (int i=0;i<mx*my;i++){
534 if(bathy->GetValue(i,0)==0){
535 u=double (rand())/ double(RAND_MAX);
536 y=signe(u-0.5)*T*(pow(1+1/T,fabs(2*u-1))-1);
537 m1->SetValue(i,2,m0->GetValue(i,2)+y*ptval);
538 if(m1->GetValue(i,2)<=m1->GetValue(i,1)){
539 m1->SetValue(i,2,m1->GetValue(i,1)+1e-10);
540 }
541 if(m1->GetValue(i,2)>=m1->GetValue(i,1)+mmax2){
542 m1->SetValue(i,2,m1->GetValue(i,1)+mmax2);
543 }
544 }
545 }
546 m1->ExtractColumn(m1col,2);
547 vec2gridsimple(m1col,m1gr,mx,my);
548 filtergrav(m1grsm,m1gr,ctr,sd,mx,my);
549 reshape(m1grsm,m1col,mx,my);
550 for (int i=0;i<mx*my;i++){
551 if(bathy->GetValue(i,0)==0){
552 m1->SetValue(i,2,m1col->GetValue(i,0));
553 }
554 else{
555 m1->SetValue(i,2,m0->GetValue(i,2));
556 }
557 if(m1->GetValue(i,2)<=m1->GetValue(i,1)){
558 m1->SetValue(i,2,m1->GetValue(i,1)+1e-10);
559 }
560 }
561 delete m1gr;
562 delete m1grsm;
563 delete m1col;
564}/*}}}*/
565double signe(double a){/*{{{*/
566 if(a<0){return -1;}
567 else{return 1;}
568}/*}}}*/
569void filtergrav(Matrix* A,Matrix* Ain,double ctr,double sd,int mx,int my){/*{{{*/
570 for (int i=1;i<my-1;i++){
571 for(int j=1;j<mx-1;j++){
572 A->SetValue(i,j,(ctr*Ain->GetValue(i,j)+sd*(Ain->GetValue(i-1,j)+Ain->GetValue(i+1,j)+Ain->GetValue(i,j-1)+Ain->GetValue(i,j+1)))/(ctr+4*sd));
573 }
574 }
575}/*}}}*/
Note: See TracBrowser for help on using the repository browser.