aboutsummaryrefslogtreecommitdiff
path: root/src/id_noise.c
blob: 99514356ff7e11536452d4c9d96e5627db72d972 (plain)
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
/*
  IDRandom

  Denis Pollney <pollney@aei.mpg.de>
  14 February 2002

  Put random data into the evolution variables for robust stability
  testing a-la-winicour.

  $Header$
*/

#include <stdlib.h>

#include "noise.h"

#include "cctk_Arguments.h"
#include "cctk_Parameters.h"

void
add_noise_to_group (int idx, const char* optstring, void* cctkGH)
{
  int i, j, k, ijk;
  CCTK_REAL* data;
  CCTK_REAL amplitude;
  CCTK_REAL offset;
  cGH* GH = cctkGH;
  int type;

  data = (CCTK_REAL*) CCTK_VarDataPtrI(GH, 0, idx);

  amplitude = *((CCTK_REAL*) CCTK_ParameterGet("amplitude", "Noise", &type))
    / RAND_MAX;
  offset = 0.5 * amplitude;

  for (k=1; k< GH->cctk_lsh[2]-1; ++k)
    {
      for (j=1; j< GH->cctk_lsh[1]-1; ++j)
	{
	  for (i=1; i< GH->cctk_lsh[0]-1; ++i)
	    {
	      ijk = CCTK_GFINDEX3D(GH, i, j, k);

	      data[ijk] += RAND_VAL;
      	    }
	}
    }
}


void
id_noise(CCTK_ARGUMENTS)
{
  DECLARE_CCTK_ARGUMENTS
  DECLARE_CCTK_PARAMETERS

  if (CCTK_TraverseString(id_vars, add_noise_to_group, cctkGH,
			  CCTK_GROUP_OR_VAR) < 0)
    {
      CCTK_WARN (1, "Failed to parse 'IDRandom::noisy_id_vars' parameter");
    }
}