aboutsummaryrefslogtreecommitdiff
path: root/Carpet/Carpet/src/Comm.cc
blob: c66dd6915a6ba2cf1898061af0b9c20590a02b22 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include <assert.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/Comm.cc,v 1.29 2004/05/21 18:16:23 schnetter Exp $";
  CCTK_FILEVERSION(Carpet_Carpet_Comm_cc);
}



namespace Carpet {
  
  using namespace std;
  
  
  
  int SyncGroup (const cGH* cgh, const char* groupname)
  {
    DECLARE_CCTK_PARAMETERS;
    
    const int group = CCTK_GroupIndex(groupname);
    assert (group>=0 && group<CCTK_NumGroups());
    assert (group<(int)arrdata.size());
    
    Checkpoint ("SyncGroup \"%s\" time=%g", groupname, (double)cgh->cctk_time);
    
    const int grouptype = CCTK_GroupTypeI(group);
    
    if (grouptype == CCTK_GF) {
      if (reflevel == -1) {
        CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
                    "Cannot synchronise in global mode "
                    "(Tried to synchronise group \"%s\")",
                    groupname);
      }
      if (map != -1 && component == -1) {
        if (maps == 1) {
          CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                      "Synchronising group \"%s\" in singlemap mode",
                      groupname);
        } else {
          CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
                      "Cannot synchronise in singlemap mode "
                      "(Tried to synchronise group \"%s\")",
                      groupname);
        }
      }
      if (component != -1) {
        if (maps == 1 && vhh.at(map)->local_components(reflevel) == 1) {
          CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
                      "Synchronising group \"%s\" in local mode",
                      groupname);
        } else {
          CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING,
                      "Cannot synchronise in local mode "
                      "(Tried to synchronise group \"%s\")",
                      groupname);
        }
      }
    }
    
    if (! CCTK_QueryGroupStorageI(cgh, group)) {
      CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
		  "Cannot synchronise group \"%s\" because it has no storage",
		  groupname);
      return -1;
    }
    
    if (CCTK_NumVarsInGroupI(group) == 0) return 0;
    
    const int n0 = CCTK_FirstVarIndexI(group);
    assert (n0>=0);
    const int num_tl = CCTK_NumTimeLevelsFromVarI(n0);
    assert (num_tl>0);
    const int tl = 0;
    
    // Prolongate the boundaries
    if (do_prolongate) {
      switch (grouptype) {
        
      case CCTK_GF:
        assert (reflevel>=0 && reflevel<reflevels);
        if (reflevel > 0) {
          
          // use the current time here (which may be modified by the
          // user)
          const CCTK_REAL time
            = (cgh->cctk_time - cctk_initial_time) / delta_time;
          
          for (comm_state<dim> state; !state.done(); state.step()) {
            for (int m=0; m<(int)arrdata.at(group).size(); ++m) {
              for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
                for (int c=0; c<vhh.at(m)->components(reflevel); ++c) {
                  arrdata.at(group).at(m).data.at(var)->ref_bnd_prolongate
                    (state, tl, reflevel, c, mglevel, time);
                }
              }
            }
          } // for state
        } // if reflevel>0
        break;
        
      case CCTK_SCALAR:
      case CCTK_ARRAY:
        // do nothing
        break;
        
      default:
        assert (0);
      } // switch grouptype
    } // if do_prolongate
    
    // Sync
    for (comm_state<dim> state; !state.done(); state.step()) {
      switch (CCTK_GroupTypeI(group)) {
        
      case CCTK_GF:
        for (int m=0; m<(int)arrdata.at(group).size(); ++m) {
          for (int var=0; var<CCTK_NumVarsInGroupI(group); ++var) {
            for (int c=0; c<vhh.at(m)->components(reflevel); ++c) {
              arrdata.at(group).at(m).data.at(var)->sync
                (state, tl, reflevel, c, mglevel);
            }
          }
        }
        break;
        
      case CCTK_SCALAR:
      case CCTK_ARRAY:
        for (int var=0; var<(int)arrdata.at(group).at(0).data.size(); ++var) {
          arrdata.at(group).at(0).data.at(var)->sync (state, 0, 0, 0, 0);
        }
        break;
        
      default:
        assert (0);
      } // switch grouptype
    } // for state
    
    return 0;
  }
  
  
  
  int EnableGroupComm (const cGH* cgh, const char* groupname)
  {
    // Communication is always enabled
    return 0;
  }
  
  int DisableGroupComm (const cGH* cgh, const char* groupname)
  {
    // Communication is always enabled
    return -1;
  }
  
} // namespace Carpet