aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/Restrict.cc
blob: c200a22b3934f80a45adc48d868acbf63e1d24d1 (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
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
#include <assert.h>
#include <math.h>
#include <stdlib.h>

#include "cctk.h"
#include "cctk_Parameters.h"

#include "ggf.hh"
#include "gh.hh"

#include "carpet.hh"

extern "C" {
  static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/Carpet/Carpet/src/Restrict.cc,v 1.23 2004/01/25 14:57:27 schnetter Exp $";
  CCTK_FILEVERSION(Carpet_Carpet_Restrict_cc);
}



namespace Carpet {
  
  using namespace std;
  
  
  
  void Restrict (const cGH* cgh)
  {
    DECLARE_CCTK_PARAMETERS;
    
    assert (is_level_mode());
    
    if (suppress_restriction) {
      Checkpoint ("Restriction suppressed");
      return;
    }
    
    Checkpoint ("Restrict");
    
    // Restrict
    if (reflevel < reflevels-1) {
      for (comm_state<dim> state; !state.done(); state.step()) {
        for (int group=0; group<CCTK_NumGroups(); ++group) {
          if (CCTK_GroupTypeI(group) == CCTK_GF) {
            if (CCTK_QueryGroupStorageI(cgh, group)) {
              if (groupdata[group].transport_operator != op_none) {
                
                const int tl = 0;
                
                for (int m=0; m<maps; ++m) {
                  assert (m<(int)arrdata[group].size());
                  
                  // use background time here (which may not be
                  // modified by the user)
                  const CCTK_REAL time = vtt[m]->time (tl, reflevel, mglevel);
                  
                  const CCTK_REAL time1 = vtt[m]->time (0, reflevel, mglevel);
                  const CCTK_REAL time2 = (cgh->cctk_time - cctk_initial_time) / cgh->cctk_delta_time;
                  assert (fabs(time1 - time2) / (fabs(time1) + fabs(time2) + fabs(cgh->cctk_delta_time)) < 1e-12);
                  
                  for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
                    assert (var<(int)arrdata[group][m].data.size());
                    for (int c=0; c<vhh[m]->components(reflevel); ++c) {
                      arrdata[group][m].data[var]->ref_restrict
                        (state, tl, reflevel, c, mglevel, time);
                    }
                  }
                }
                
              } else {
                if (state.thestate==state_recv) {
                  char * const groupname = CCTK_GroupName(group);
                  Checkpoint ("(no restricting for group %s)", groupname);
                  free (groupname);
                }
              } // if ! do_transfer
            } // if group has storage
          } // if grouptype == CCTK_GF
        } // loop over groups
      } // for state
    } // if not finest refinement level
    
    
    
    // Sync
    if (reflevel < reflevels-1) {
      for (comm_state<dim> state; !state.done(); state.step()) {
        for (int group=0; group<CCTK_NumGroups(); ++group) {
          if (CCTK_GroupTypeI(group) == CCTK_GF) {
            if (CCTK_QueryGroupStorageI(cgh, group)) {
              if (groupdata[group].transport_operator != op_none) {
                
                const int tl = 0;
                
                for (int m=0; m<maps; ++m) {
                  assert (m<(int)arrdata[group].size());
                  for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
                    assert (var<(int)arrdata[group][m].data.size());
                    for (int c=0; c<vhh[m]->components(reflevel); ++c) {
                      arrdata[group][m].data[var]->sync
                        (state, tl, reflevel, c, mglevel);
                    }
                  }
                }
                
              } // if do_transfer
            } // if group has storage
          } // if grouptype == CCTK_GF
        } // loop over groups
      } // for state
    } // if not finest refinement level
    
  }
  
} // namespace Carpet