gs2crmod 0.11.78 → 0.11.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/VERSION +1 -1
- data/ext/gs2crmod_ext.c +0 -399
- data/gs2crmod.gemspec +7 -5
- data/lib/gs2crmod/calculations.rb +4 -35
- data/lib/gs2crmod/graphs.rb +1 -1
- data/lib/gs2crmod/gs2.rb +0 -236
- data/lib/gs2crmod/gsl_data.rb +1305 -1304
- metadata +22 -40
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cc195134cfa0c19392d90285541c55e0c5fc9a74
|
4
|
+
data.tar.gz: 9c53414eb39130503a7f0a44dd3a8a3577153317
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4fb9ac64fd98cf403982bdbbcb5209fbaf40abfbc6ef89d668fb19752a8643065e28ed35f7ec0167ba225840f043a46d899ac21907dae9b414ad749607d376a5
|
7
|
+
data.tar.gz: 87357dd8be279c0e1330fba046e65b3622e1e23128bc01ad9ec30984376a45fe42e15be695c07007e61f4245643b80d7d7f52dc84873b1a352f299133a4a1d2f
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.11.
|
1
|
+
0.11.79
|
data/ext/gs2crmod_ext.c
CHANGED
@@ -348,404 +348,6 @@ VALUE gs2crmod_tensor_field_gsl_tensor(VALUE self, VALUE options)
|
|
348
348
|
return field_real_space;
|
349
349
|
}
|
350
350
|
|
351
|
-
inline int arr_index(int ix, int iy, int ith, int it, int *c_shape, int t_size)
|
352
|
-
{
|
353
|
-
return ix*c_shape[0]*c_shape[2]*t_size + iy*c_shape[0]*t_size + ith*t_size + it;
|
354
|
-
}
|
355
|
-
|
356
|
-
//Calculates normalized correlation function of 2 time series and stores result
|
357
|
-
void correlate_norm(double *A, double *B, double *C, int t_size)
|
358
|
-
{
|
359
|
-
//printf("%lf, %lf, %d\n", A[0], B[0], size);
|
360
|
-
|
361
|
-
int i, j, jmax;
|
362
|
-
double temp_sum, norm_a=0., norm_b=0.;
|
363
|
-
|
364
|
-
//printf("%lf, %lf, %lf, %d\n", A[0], B[0], C[0], t_size);
|
365
|
-
|
366
|
-
//Sum over appropriate terms to get vector of correlations as function of time delay
|
367
|
-
//Split into two loops instead of trying to be too smart with the indices.
|
368
|
-
for(i=0; i<=t_size; i++){
|
369
|
-
temp_sum=0;
|
370
|
-
for(j=0; j<=i; j++)
|
371
|
-
{
|
372
|
-
temp_sum += A[j] * B[t_size - i - 1 + j];
|
373
|
-
}
|
374
|
-
C[i] = temp_sum;
|
375
|
-
}
|
376
|
-
//Second half
|
377
|
-
for(i=t_size+1; i<2*t_size-1; i++){
|
378
|
-
jmax = 2*t_size - 2 - i;
|
379
|
-
temp_sum=0;
|
380
|
-
for(j=0; j<=2*t_size-2-i; j++){
|
381
|
-
temp_sum += A[t_size - jmax - 1 + j] * B[j];
|
382
|
-
}
|
383
|
-
C[i] = temp_sum;
|
384
|
-
}
|
385
|
-
|
386
|
-
// for(i=0; i<t_size; i++)
|
387
|
-
// printf("%lf, ", A[i]);
|
388
|
-
// printf("\n\n");
|
389
|
-
// for(i=0; i<2*t_size-1; i++)
|
390
|
-
// printf("%lf, ", C[i]);
|
391
|
-
// printf("\n\ntemp_sum=%lf, Cmax=%lf\n", temp_sum, C[50]);
|
392
|
-
|
393
|
-
//Normalize each array with its zero time delay correlation value
|
394
|
-
for(i=0; i<t_size; i++){
|
395
|
-
norm_a += A[i]*A[i];
|
396
|
-
norm_b += B[i]*B[i];
|
397
|
-
}
|
398
|
-
//Final answer written to C array
|
399
|
-
for(i=0; i<2*t_size-1; i++)
|
400
|
-
C[i] = C[i]/sqrt(norm_a * norm_b);
|
401
|
-
}
|
402
|
-
|
403
|
-
VALUE gs2crmod_tensor_field_correlation_gsl_tensor(VALUE self, VALUE options)
|
404
|
-
{
|
405
|
-
VALUE field_graphkit, shape, datakit, datakit_array;
|
406
|
-
VALUE x_narray, y_narray, z_narray, field_narray;
|
407
|
-
VALUE t_gsl_vector;
|
408
|
-
//Write some as floats to avoid flooring to wrong (lower) number later
|
409
|
-
float *lx_bin, *ly_bin, *lz_bin, *lt_bin;
|
410
|
-
float lxmin, lxmax, lymin, lymax, lzmin, lzmax, ltmin, ltmax, lx, ly, lz, *lt;
|
411
|
-
double *x, *y, *z, *t, *field, *coarray, *corr_norm;
|
412
|
-
int *c_shape, tot_size, ith, ix, iy, it, t_size, first=1;
|
413
|
-
int index, i2, i3, i4, tot_bins, *count;
|
414
|
-
long int i1;
|
415
|
-
|
416
|
-
printf("Starting correlation analysis\n");
|
417
|
-
|
418
|
-
/*Find time steps*/
|
419
|
-
/*self.gsl_vector('t')*/
|
420
|
-
//t_gsl_vector = RFCALL_11("gsl_vector", rb_str_new2("t"));
|
421
|
-
t_gsl_vector = rb_funcall(self, rb_intern("gsl_vector"), 2, rb_str_new2("t"), options);
|
422
|
-
t_size = NUM2INT(RFCALL_10_ON(t_gsl_vector, "size"));
|
423
|
-
t = ALLOC_N(double, t_size);
|
424
|
-
for(it=0; it<t_size; it++)
|
425
|
-
{
|
426
|
-
t[it] = NUM2DBL(CR_TELMT_R1(t_gsl_vector, it));
|
427
|
-
}
|
428
|
-
|
429
|
-
VALUE nbins_array=CR_HKS(options, "nbins_array");
|
430
|
-
int *nbins;
|
431
|
-
if(RTEST(nbins_array) && RTEST(rb_obj_is_kind_of(nbins_array, RGET_CLASS_TOP("Array")))){
|
432
|
-
CR_INT_ARY_R2C_STACK(nbins_array, nbins);
|
433
|
-
}
|
434
|
-
else
|
435
|
-
rb_raise(RGET_CLASS_TOP("TypeError"), "Please specify nbins_array as a 4D array");
|
436
|
-
|
437
|
-
//correlation_type = options[:correlation_type]
|
438
|
-
//Test which correlation type is to be calculated using ruby string comparison in a proc
|
439
|
-
VALUE test_proc = rb_eval_string("Proc.new {|options| case options[:correlation_type]; when 'perp'; 0; when 'par'; 1; when 'time'; 2; when 'full'; 3 ;else; raise 'Please specify correlation_type as a string (perp/par/time/full)'; end}");
|
440
|
-
int corr_type = FIX2INT(RFCALL_11_ON(test_proc, "call", options));
|
441
|
-
|
442
|
-
printf("Reading in data\n");
|
443
|
-
for(it=0; it<t_size; it++)
|
444
|
-
{
|
445
|
-
/*options[:t_index] = it+1*/
|
446
|
-
/*options.send("[]=", :t_index, it+1)*/
|
447
|
-
|
448
|
-
//rb_funcall(options, rb_intern("[]="), ID2SYM(rb_intern("t_index")), Qnil);
|
449
|
-
CR_HKS_SET(options, "t_index", INT2FIX(it));
|
450
|
-
|
451
|
-
field_graphkit = RFCALL_11("field_real_space_graphkit", options);
|
452
|
-
|
453
|
-
/*shape = rb_funcall(field_graphkit, rb_intern("shape"), 0);*/
|
454
|
-
datakit_array = RFCALL_10_ON(field_graphkit, "data");
|
455
|
-
datakit = CR_ELEMENT_ACCESS(datakit_array, INT2FIX(0));
|
456
|
-
|
457
|
-
/*Access data: datakit.x.data.narray*/
|
458
|
-
x_narray = RFCALL_10_ON(RFCALL_10_ON(RFCALL_10_ON(datakit, "x"), "data"), "narray");
|
459
|
-
y_narray = RFCALL_10_ON(RFCALL_10_ON(RFCALL_10_ON(datakit, "y"), "data"), "narray");
|
460
|
-
z_narray = RFCALL_10_ON(RFCALL_10_ON(RFCALL_10_ON(datakit, "z"), "data"), "narray");
|
461
|
-
field_narray = RFCALL_10_ON(RFCALL_10_ON(RFCALL_10_ON(datakit, "f"), "data"), "narray");
|
462
|
-
|
463
|
-
shape = RFCALL_10_ON(x_narray, "shape");
|
464
|
-
CR_INT_ARY_R2C_STACK(shape, c_shape);
|
465
|
-
|
466
|
-
if(first)
|
467
|
-
{
|
468
|
-
//ALLOC_N is used since it works correctly with ruby garbage collector
|
469
|
-
tot_size = c_shape[0]*c_shape[1]*c_shape[2]*t_size;
|
470
|
-
x = ALLOC_N(double, tot_size);
|
471
|
-
y = ALLOC_N(double, tot_size);
|
472
|
-
z = ALLOC_N(double, tot_size);
|
473
|
-
field = ALLOC_N(double, tot_size);
|
474
|
-
first=0;
|
475
|
-
}
|
476
|
-
|
477
|
-
|
478
|
-
/*Copy NArrays to C arrays*/
|
479
|
-
for(ith=0; ith<c_shape[0]; ith++)
|
480
|
-
for(ix=0; ix<c_shape[1]; ix++)
|
481
|
-
for(iy=0; iy<c_shape[2]; iy++)
|
482
|
-
{
|
483
|
-
index = arr_index(ix,iy,ith,it,c_shape,t_size);
|
484
|
-
x[index] = NUM2DBL(CR_TELMT_R3(x_narray, ith, ix, iy));
|
485
|
-
y[index] = NUM2DBL(CR_TELMT_R3(y_narray, ith, ix, iy));
|
486
|
-
z[index] = NUM2DBL(CR_TELMT_R3(z_narray, ith, ix, iy));
|
487
|
-
field[index] = NUM2DBL(CR_TELMT_R3(field_narray, ith, ix, iy));
|
488
|
-
}
|
489
|
-
}
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
printf("Interpolating\n");
|
494
|
-
/******************************
|
495
|
-
* GSL Interpolation of *
|
496
|
-
* field in time *
|
497
|
-
*****************************/
|
498
|
-
//Read t interp from options (default is 100)
|
499
|
-
int nt_reg;
|
500
|
-
if(RTEST(CR_HKS(options, "nt_reg")))
|
501
|
-
nt_reg = NUM2INT(CR_HKS(options, "nt_reg"));
|
502
|
-
else
|
503
|
-
nt_reg = 100;
|
504
|
-
int idx, ti;
|
505
|
-
double *x_reg, *y_reg, *z_reg, *t_reg, *field_reg, delta_t_reg, *y1;
|
506
|
-
tot_size = c_shape[0]*c_shape[1]*c_shape[2]*nt_reg;
|
507
|
-
delta_t_reg = (t[t_size-1]-t[0])/(nt_reg-1);
|
508
|
-
|
509
|
-
y1 = ALLOC_N(double, t_size);
|
510
|
-
x_reg = ALLOC_N(double, tot_size);
|
511
|
-
y_reg = ALLOC_N(double, tot_size);
|
512
|
-
z_reg = ALLOC_N(double, tot_size);
|
513
|
-
t_reg = ALLOC_N(double, nt_reg);
|
514
|
-
field_reg = ALLOC_N(double, tot_size);
|
515
|
-
|
516
|
-
for(i1=0; i1<c_shape[0]*c_shape[1]*c_shape[2]*t_size; i1+=t_size)
|
517
|
-
{
|
518
|
-
for (i2 = 0; i2 < t_size; i2++)
|
519
|
-
{
|
520
|
-
y1[i2] = field[i1+i2];
|
521
|
-
}
|
522
|
-
|
523
|
-
gsl_interp_accel *acc
|
524
|
-
= gsl_interp_accel_alloc ();
|
525
|
-
gsl_spline *spline
|
526
|
-
= gsl_spline_alloc (gsl_interp_cspline, t_size);
|
527
|
-
|
528
|
-
gsl_spline_init (spline, t, y1, t_size);
|
529
|
-
|
530
|
-
for (ti = 0; ti < nt_reg; ti++)
|
531
|
-
{
|
532
|
-
t_reg[ti] = t[0]+ti*delta_t_reg;
|
533
|
-
idx = floor((i1)/t_size)*nt_reg;
|
534
|
-
x_reg[idx+ti] = x[i1];
|
535
|
-
y_reg[idx+ti] = y[i1];
|
536
|
-
z_reg[idx+ti] = z[i1];
|
537
|
-
field_reg[idx+ti] = gsl_spline_eval (spline, t_reg[ti], acc);
|
538
|
-
}
|
539
|
-
gsl_spline_free (spline);
|
540
|
-
gsl_interp_accel_free (acc);
|
541
|
-
|
542
|
-
}
|
543
|
-
|
544
|
-
//Can now free the original pointers since redefined variables on a regular grid
|
545
|
-
free(x); x=0;
|
546
|
-
free(y); y=0;
|
547
|
-
free(z); z=0;
|
548
|
-
free(t); t=0;
|
549
|
-
|
550
|
-
/*printf("interpolated:\n");
|
551
|
-
for(i1=0; i1<c_shape[1]; i1++){
|
552
|
-
index = arr_index(i1,0,0,0,c_shape,nt_reg);
|
553
|
-
printf("%lf, ", x_reg[index]);
|
554
|
-
}*/
|
555
|
-
|
556
|
-
/**********************************************************************
|
557
|
-
* First need to know max and min lengths and times in each dimension *
|
558
|
-
* in order to define bins. These need to be specified before the loop*
|
559
|
-
* since the binning will be done at each step since there is too much*
|
560
|
-
* info to store. *
|
561
|
-
* ********************************************************************/
|
562
|
-
i3=0;
|
563
|
-
lxmin=0; lymin=0; lzmin=0;
|
564
|
-
for(i1=0; i1<tot_size; i1+=nt_reg){
|
565
|
-
//printf("%lf, %lf, %lf\n", x_reg[i1], y_reg[i1], z_reg[i1]);
|
566
|
-
for(i2=0; i2<tot_size; i2+=nt_reg)
|
567
|
-
{
|
568
|
-
lx = x_reg[i2] - x_reg[i1];
|
569
|
-
ly = y_reg[i2] - y_reg[i1];
|
570
|
-
lz = z_reg[i2] - z_reg[i1];
|
571
|
-
|
572
|
-
if(lx < lxmin)
|
573
|
-
lxmin = lx;
|
574
|
-
if(ly < lymin)
|
575
|
-
lymin = ly;
|
576
|
-
if(lz < lzmin)
|
577
|
-
lzmin = lz;
|
578
|
-
}
|
579
|
-
}
|
580
|
-
lxmax = -lxmin;
|
581
|
-
lymax = -lymin;
|
582
|
-
lzmax = -lzmin;
|
583
|
-
ltmin = t_reg[0] - t_reg[nt_reg-1];
|
584
|
-
ltmax = -ltmin;
|
585
|
-
//printf("\nMin/Max = %lf, %lf\n", lxmin, lxmax);
|
586
|
-
//printf("Min/Max = %lf, %lf\n", lymin, lymax);
|
587
|
-
//printf("Min/Max = %lf, %lf\n", lzmin, lzmax);
|
588
|
-
|
589
|
-
//printf("Bins\n");
|
590
|
-
//Initialize the bin arrays
|
591
|
-
tot_bins = nbins[0]*nbins[1]*nbins[2]*nbins[3];
|
592
|
-
lx_bin = ALLOC_N(double, nbins[0]);
|
593
|
-
ly_bin = ALLOC_N(double, nbins[1]);
|
594
|
-
lz_bin = ALLOC_N(double, nbins[2]);
|
595
|
-
lt_bin = ALLOC_N(double, nbins[3]);
|
596
|
-
|
597
|
-
for(i1=0; i1<nbins[0]; i1++){
|
598
|
-
lx_bin[i1] = lxmin + i1*(lxmax-lxmin)/(nbins[0]-1);
|
599
|
-
//printf("lx_bin = %f\n ", lx_bin[i1]);
|
600
|
-
}
|
601
|
-
for(i1=0; i1<nbins[1]; i1++){
|
602
|
-
ly_bin[i1] = lymin + i1*(lymax-lymin)/(nbins[1]-1);
|
603
|
-
//printf("ly_bin = %f\n", ly_bin[i1]);
|
604
|
-
}
|
605
|
-
for(i1=0; i1<nbins[2]; i1++){
|
606
|
-
lz_bin[i1] = lzmin + i1*(lzmax-lzmin)/(nbins[2]-1);
|
607
|
-
//printf("lz_bin = %f\n", lz_bin[i1]);
|
608
|
-
}
|
609
|
-
for(i1=0; i1<nbins[3]; i1++)
|
610
|
-
lt_bin[i1] = ltmin + i1*(ltmax-ltmin)/(nbins[3]-1);
|
611
|
-
|
612
|
-
//Now define and initialize the coarray and count arrays
|
613
|
-
coarray = ALLOC_N(double, tot_bins);
|
614
|
-
count = ALLOC_N(int, tot_bins);
|
615
|
-
corr_norm = ALLOC_N(double, (2*nt_reg-1)); //store correlate result before adding to coarray
|
616
|
-
lt = ALLOC_N(double, (2*nt_reg-1)); //Can calculate lt before loops
|
617
|
-
|
618
|
-
for(i1=0; i1<tot_bins; i1++){
|
619
|
-
coarray[i1] = 0.;
|
620
|
-
count[i1] = 0;
|
621
|
-
}
|
622
|
-
/******************************************************
|
623
|
-
* Start looping and calculating correlation function *
|
624
|
-
******************************************************/
|
625
|
-
//Can predefine the time separations
|
626
|
-
for(i1=0; i1<2*nt_reg-1; i1++){
|
627
|
-
if(i1<nt_reg)
|
628
|
-
lt[i1] = t_reg[i1] - t_reg[nt_reg-1];
|
629
|
-
else if(i1>nt_reg-1)
|
630
|
-
lt[i1] = t_reg[i1-nt_reg] - t_reg[0] + delta_t_reg;
|
631
|
-
}
|
632
|
-
|
633
|
-
/* Now test which correlation function is to be calculated since full 4D correlation
|
634
|
-
* is usually intractable. The type was read in at begininning and corr_type corresponds to:
|
635
|
-
*
|
636
|
-
* 0 : perpendicular only (lz = 0)
|
637
|
-
* 1 : parallel only (lx = ly = 0)
|
638
|
-
* 2 : time only (lx = lz = 0)
|
639
|
-
* 3 : full correlation (may take very long) (all separations != 0)
|
640
|
-
*/
|
641
|
-
float eps1 = 1e-5, eps2 = 1e5; //define very small and very large numbers to test against
|
642
|
-
float lx_test, ly_test, lz_test;
|
643
|
-
switch (corr_type){
|
644
|
-
case 0: //perp
|
645
|
-
lx_test = eps2;
|
646
|
-
ly_test = eps2;
|
647
|
-
lz_test = eps1;
|
648
|
-
break;
|
649
|
-
case 1: //par
|
650
|
-
lx_test = eps1;
|
651
|
-
ly_test = eps1;
|
652
|
-
lz_test = eps2;
|
653
|
-
break;
|
654
|
-
case 2: //time
|
655
|
-
lx_test = eps1;
|
656
|
-
ly_test = eps2;
|
657
|
-
lz_test = eps1;
|
658
|
-
break;
|
659
|
-
case 3: //full
|
660
|
-
lx_test = eps2;
|
661
|
-
ly_test = eps2;
|
662
|
-
lz_test = eps2;
|
663
|
-
break;
|
664
|
-
}
|
665
|
-
|
666
|
-
printf("Main calculation loop\n\n");
|
667
|
-
//Start main loop for correlation function calculation
|
668
|
-
for(i1=0; i1<tot_size; i1+=nt_reg){
|
669
|
-
printf("\33[2K\r"); //Clear line in terminal
|
670
|
-
printf("\33[1A"); //Go back one line in terminal
|
671
|
-
printf("Main loop iterator = %ld of %ld\n", i1/nt_reg, tot_size/nt_reg);
|
672
|
-
for(i2=i1; i2<tot_size; i2+=nt_reg)
|
673
|
-
{
|
674
|
-
//Calculate spatial and temporal separation
|
675
|
-
lx = x_reg[i2] - x_reg[i1];
|
676
|
-
ly = y_reg[i2] - y_reg[i1];
|
677
|
-
lz = z_reg[i2] - z_reg[i1];
|
678
|
-
|
679
|
-
if(lx<lx_test && ly<ly_test && lz<lz_test){
|
680
|
-
//Calculate correlation function:
|
681
|
-
//corr = correlate(field[i1], field[i2], answer, no of t pts)
|
682
|
-
correlate_norm(&field_reg[i1], &field_reg[i2], &corr_norm[0], nt_reg);
|
683
|
-
|
684
|
-
//Calculate appropriate bin (subtracting min ensures +ve idx)
|
685
|
-
ix = floor((lx - lxmin) / (lx_bin[1] - lx_bin[0]));
|
686
|
-
iy = floor((ly - lymin) / (ly_bin[1] - ly_bin[0]));
|
687
|
-
ith = floor((lz - lzmin) / (lz_bin[1] - lz_bin[0]));
|
688
|
-
//printf("(%lf, %lf, %lf, %lf)\n", lz, lzmin, lz_bin[1], lz_bin[0]);
|
689
|
-
//printf("indices: (%d, %d, %d)\n", ix, iy, ith);
|
690
|
-
|
691
|
-
//Loop over time calculate time bin and put into coarray
|
692
|
-
for(i3=0; i3<2*nt_reg-1; i3++){
|
693
|
-
it = floor((lt[i3] - ltmin) / (lt_bin[1] - lt_bin[0]));
|
694
|
-
coarray[ix*nbins[1]*nbins[2]*nbins[3] + iy*nbins[2]*nbins[3] + ith*nbins[3] + it] += corr_norm[i3];
|
695
|
-
count[ix*nbins[1]*nbins[2]*nbins[3] + iy*nbins[2]*nbins[3] + ith*nbins[3] + it] += 1;
|
696
|
-
}
|
697
|
-
|
698
|
-
/**************************
|
699
|
-
* Repeat for negative *
|
700
|
-
* lx, ly, lz, to avoid *
|
701
|
-
* recalculating corr_norm*
|
702
|
-
**************************/
|
703
|
-
|
704
|
-
lx = -lx; ly = -ly; lz = -lz;
|
705
|
-
|
706
|
-
//Calculate appropriate bin (subtracting min ensures +ve idx)
|
707
|
-
ix = floor((lx - lxmin) / (lx_bin[1] - lx_bin[0]));
|
708
|
-
iy = floor((ly - lymin) / (ly_bin[1] - ly_bin[0]));
|
709
|
-
ith = floor((lz - lzmin) / (lz_bin[1] - lz_bin[0]));
|
710
|
-
//printf("- = {%d, %d, %d}\n", ix, iy, ith);
|
711
|
-
|
712
|
-
//Loop over time calculate time bin and put into coarray
|
713
|
-
for(i3=0; i3<2*nt_reg-1; i3++){
|
714
|
-
it = floor((-lt[i3] - ltmin) / (lt_bin[1] - lt_bin[0]));
|
715
|
-
coarray[ix*nbins[1]*nbins[2]*nbins[3] + iy*nbins[2]*nbins[3] + ith*nbins[3] + it] += corr_norm[i3];
|
716
|
-
count[ix*nbins[1]*nbins[2]*nbins[3] + iy*nbins[2]*nbins[3] + ith*nbins[3] + it] += 1;
|
717
|
-
}
|
718
|
-
}
|
719
|
-
}
|
720
|
-
}
|
721
|
-
//End main loop
|
722
|
-
|
723
|
-
//Finally have to normalize coarray with count when count != 0
|
724
|
-
//printf("Normalization: \n");
|
725
|
-
for(i1=0; i1<tot_bins; i1++){
|
726
|
-
if(count[i1]>0){
|
727
|
-
coarray[i1] = coarray[i1]/count[i1];
|
728
|
-
}
|
729
|
-
}
|
730
|
-
//printf("Finish normalization: \n");
|
731
|
-
|
732
|
-
//Retun output to CR
|
733
|
-
VALUE cgsl_tensor, output_tensor;
|
734
|
-
cgsl_tensor = RGET_CLASS(cgsl, "Tensor");
|
735
|
-
//output_tensor = GSL::Tensor.alloc(nbins, ...)
|
736
|
-
output_tensor = rb_funcall(cgsl_tensor, rb_intern("alloc"), 4, INT2FIX(nbins[0]), INT2FIX(nbins[1]), INT2FIX(nbins[2]), INT2FIX(nbins[3]));
|
737
|
-
|
738
|
-
for(i1=0; i1<nbins[0]; i1++)
|
739
|
-
for(i2=0; i2<nbins[1]; i2++)
|
740
|
-
for(i3=0; i3<nbins[2]; i3++)
|
741
|
-
for(i4=0; i4<nbins[3]; i4++){
|
742
|
-
CR_TELMT_R4_SET(output_tensor, i1, i2, i3, i4, rb_float_new(coarray[i1*nbins[1]*nbins[2]*nbins[3] + i2*nbins[2]*nbins[3] + i3*nbins[3] + i4]));
|
743
|
-
}
|
744
|
-
|
745
|
-
printf("Finished correlation analysis\n");
|
746
|
-
return output_tensor;
|
747
|
-
}
|
748
|
-
|
749
351
|
void Init_gs2crmod_ext()
|
750
352
|
{
|
751
353
|
/*printf("HERE!!!");*/
|
@@ -769,7 +371,6 @@ void Init_gs2crmod_ext()
|
|
769
371
|
|
770
372
|
rb_define_method(ccode_runner_gs2_gsl_tensor_complexes, "field_gsl_tensor_complex_2", gs2crmod_tensor_complexes_field_gsl_tensor_complex_2, 1);
|
771
373
|
rb_define_method(ccode_runner_gs2_gsl_tensors, "field_real_space_gsl_tensor", gs2crmod_tensor_field_gsl_tensor, 1);
|
772
|
-
rb_define_method(ccode_runner_gs2_gsl_tensors, "field_correlation_gsl_tensor", gs2crmod_tensor_field_correlation_gsl_tensor, 1);
|
773
374
|
|
774
375
|
/*rb_define_method(ccode_runner_ext, "hello_world", code_runner_ext_hello_world, 0);*/
|
775
376
|
}
|
data/gs2crmod.gemspec
CHANGED
@@ -2,14 +2,17 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: gs2crmod 0.11.79 ruby lib
|
6
|
+
# stub: ext/extconf.rb
|
5
7
|
|
6
8
|
Gem::Specification.new do |s|
|
7
9
|
s.name = "gs2crmod"
|
8
|
-
s.version = "0.11.
|
10
|
+
s.version = "0.11.79"
|
9
11
|
|
10
12
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
13
|
+
s.require_paths = ["lib"]
|
11
14
|
s.authors = ["Edmund Highcock", "Ferdinand van Wyk"]
|
12
|
-
s.date = "2014-10-
|
15
|
+
s.date = "2014-10-17"
|
13
16
|
s.description = "GS2 is a gyrokinetic flux tube initial value turbulence code which can be used for fusion or astrophysical plasmas. CodeRunner is a framework for the automated running and analysis of large simulations. This module allows GS2 (and its sister code AstroGK) to harness the power of the CodeRunner framework."
|
14
17
|
s.email = "edmundhighcock@sourceforge.net"
|
15
18
|
s.extensions = ["ext/extconf.rb"]
|
@@ -75,13 +78,12 @@ Gem::Specification.new do |s|
|
|
75
78
|
]
|
76
79
|
s.homepage = "http://gs2crmod.sourceforge.net"
|
77
80
|
s.licenses = ["GSLv3"]
|
78
|
-
s.require_paths = ["lib"]
|
79
81
|
s.required_ruby_version = Gem::Requirement.new(">= 1.9.1")
|
80
|
-
s.rubygems_version = "
|
82
|
+
s.rubygems_version = "2.2.2"
|
81
83
|
s.summary = "Module to allow CodeRunner to run and analyse the GS2 and AstroGK codes."
|
82
84
|
|
83
85
|
if s.respond_to? :specification_version then
|
84
|
-
s.specification_version =
|
86
|
+
s.specification_version = 4
|
85
87
|
|
86
88
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
87
89
|
s.add_runtime_dependency(%q<coderunner>, [">= 0.14.15"])
|
@@ -668,42 +668,11 @@ alias :ctehfa :calculate_transient_es_heat_flux_amplifications
|
|
668
668
|
|
669
669
|
|
670
670
|
def calculate_transient_amplification(vector, options={})
|
671
|
-
|
672
|
-
|
673
|
-
#Implement data smoothing through a moving average procedure of 5 surrounding points.
|
674
|
-
#This is needed since we need to know the turning points and need calculate gradients
|
675
|
-
#to find the points where they change sign. In order to get the actual transient amplification
|
676
|
-
#use the original data at the points where the gradient of smoothed data changes sign.
|
677
|
-
|
678
|
-
vec_smooth = GSL::Vector.alloc(vector.size-2);
|
679
|
-
vec_smooth[0] = vector[0]
|
680
|
-
vec_smooth[1] = (vector[0] + vector[1] + vector[2])/3
|
681
|
-
for i in 2...vector.size-2
|
682
|
-
vec_smooth[i] = (vector[i-2] + vector[i-1] + vector[i] + vector[i+1] + vector[i+2])/5
|
683
|
-
end
|
684
|
-
|
685
|
-
#Calculate the gradient of the smoothed function
|
686
|
-
grad = GSL::Vector.alloc(vec_smooth.size-1);
|
687
|
-
for i in 0...vec_smooth.size-1
|
688
|
-
grad[i] = (vec_smooth[i+1] - vec_smooth[i])/(t[i+1]-t[i])
|
689
|
-
end
|
690
|
-
|
691
|
-
#Now find the first two points where the gradient changes sign
|
692
|
-
#If your data still oscillates too much this method will not work.
|
693
|
-
#You will have to change the order of the data smoothing scheme.
|
694
|
-
turning_points = Array.new
|
695
|
-
for i in 1...grad.size
|
696
|
-
if GSL::sign(grad[i]) != GSL::sign(grad[i-1])
|
697
|
-
turning_points.push(i+1)
|
698
|
-
end
|
699
|
-
end
|
700
|
-
|
701
|
-
#Now calculate amplification factor using original vector (assuming turning point is roughly the same)
|
702
|
-
#by dividing value at max by the value at the min
|
703
|
-
if turning_points.empty? or turning_points.size < 2
|
704
|
-
return 0
|
671
|
+
if @g_exb_start_timestep
|
672
|
+
return GSL::Sf::log(vector[@g_exb_start_timestep...-1].max / vector[@g_exb_start_timestep])/2
|
705
673
|
else
|
706
|
-
|
674
|
+
eputs "Warning: could not calculate transient amplification since g_exb_start_timestep was not used. Returning 0."
|
675
|
+
return 0
|
707
676
|
end
|
708
677
|
end
|
709
678
|
|
data/lib/gs2crmod/graphs.rb
CHANGED
@@ -317,7 +317,7 @@ module GraphKits
|
|
317
317
|
when :options
|
318
318
|
return [:mag, :norm, :z, :flip, :range, :kx_index, :ky_index, :kx, :ky, :strongest_non_zonal_mode]
|
319
319
|
when :plot, nil
|
320
|
-
eputs "Starting efn, this can take a while..."
|
320
|
+
#eputs "Starting efn, this can take a while..."
|
321
321
|
options[:imrc] ||= :real
|
322
322
|
ep options
|
323
323
|
options.convert_to_index(self, :ky)
|