Memosa-FVM  0.2
testOneDConductionExactMC.cpp File Reference
#include <iostream>
#include <fstream>
#include <math.h>
#include <gsl/gsl_randist.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_statistics_double.h>
#include <gsl/gsl_histogram.h>
Include dependency graph for testOneDConductionExactMC.cpp:

Go to the source code of this file.

Macros

#define NCELLS   10
 
#define NTRIES   100000
 

Functions

int main ()
 

Macro Definition Documentation

#define NCELLS   10

Definition at line 15 of file testOneDConductionExactMC.cpp.

Referenced by main().

#define NTRIES   100000

Definition at line 16 of file testOneDConductionExactMC.cpp.

Referenced by main().

Function Documentation

int main ( )

Definition at line 17 of file testOneDConductionExactMC.cpp.

References NCELLS, NTRIES, and sqrt().

18 {
19  gsl_rng *r = gsl_rng_alloc(gsl_rng_taus);
20  gsl_rng_set(r,455465636);
21 
22  double sigma1=0.1;
23 
24  double **Tc = new double*[NCELLS];
25  double *xc = new double[NCELLS];
26  for(int c=0; c<NCELLS; c++)
27  Tc[c] = new double[NTRIES];
28 
29  double dx = 1.0/NCELLS;
30 
31  xc[0] = dx/2.0;
32  for(int c=1; c<NCELLS; c++)
33  xc[c] = xc[c-1] + dx;
34 
35  // increment inside the loop
36  for(int i=0; i<NTRIES; )
37  {
38  double e = (gsl_ran_ugaussian(r)*sigma1 +0.);
39  if (e<-1.0) continue;
40  double ln_term = log(1 + e);
41  for(int c=0; c<NCELLS; c++)
42  {
43  if (e == 0.0)
44  {
45  Tc[c][i] = xc[c];
46  }
47  else
48  {
49  Tc[c][i] = log(1+e*xc[c])/ln_term;
50  }
51  }
52  i++;
53  }
54 
55 
56  ofstream mean_file, sd_file;
57  mean_file.open("/tmp/mean-mc.dat");
58  sd_file.open("/tmp/sd-mc.dat");
59 
60  for(int c=0; c<NCELLS; c++)
61  {
62  double Tmean = gsl_stats_mean(Tc[c],1,NTRIES);
63  double Tvariance = gsl_stats_variance_m(Tc[c],1,NTRIES,Tmean);
64  mean_file << xc[c] << " " << Tmean << endl;
65  sd_file << xc[c] << " " << sqrt(Tvariance) << endl;
66  }
67  mean_file.close();
68  sd_file.close();
69  exit(0);
70 }
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
#define NCELLS
#define NTRIES