aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetSlab/src/Get.cc
blob: a6d30312242d6371937545f9384d4e0d44cc5a03 (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
#include <cassert>

#include "cctk.h"

#include "carpet.hh"

#include "mapping.hh"
#include "slab.hh"
#include "Get.hh"



namespace CarpetSlab {
  
  using namespace Carpet;
  
  
  
  CCTK_INT
  CarpetSlab_Get (CCTK_POINTER_TO_CONST const cctkGH_,
                  CCTK_INT const mapping_handle,
                  CCTK_INT const proc,
                  CCTK_INT const vindex,
                  CCTK_INT const timelevel,
                  CCTK_INT const hdatatype,
                  CCTK_POINTER const hdata)
  {
    cGH const * const cctkGH = (cGH const *) cctkGH_;
    
    // Check arguments
    assert (cctkGH);
    assert (mapping_handle>=0);
    assert (proc==-1 || proc>=0 && proc<CCTK_nProcs(cctkGH));
    assert (vindex>=0 && vindex<CCTK_NumVars());
    assert (timelevel>=0);
    assert (hdatatype>=0);
    assert (hdata);
    
    // Get mapping
    const mapping * const mp = RetrieveMapping (mapping_handle);
    assert (mp);
    
    // Calculate total size
    size_t size = 1;
    for (size_t d=0; d<(size_t)mp->hdim; ++d) {
      size *= mp->length[d];
    }
    
    // Get type size
    size_t const sz = CCTK_VarTypeSize (hdatatype);
    assert (sz>0);
    
    // Forward call
    FillSlab (cctkGH, proc, vindex, timelevel,
              mp->hdim,
              &mp->origin[0], &mp->dirs[0], &mp->stride[0], &mp->length[0],
              hdata);
    
    return 0;
  }
  
  
  
  CCTK_INT
  CarpetSlab_GetList (CCTK_POINTER_TO_CONST const cctkGH_,
                      CCTK_INT const mapping_handle,
                      CCTK_INT const num_arrays,
                      CCTK_INT const * const procs,
                      CCTK_INT const * const vindices,
                      CCTK_INT const * const timelevels,
                      CCTK_INT const * const hdatatypes,
                      CCTK_POINTER const * const hdata,
                      CCTK_INT * const retvals)
  {
    cGH const * const cctkGH = (cGH const *) cctkGH_;
    
    // Check arguments
    assert (cctkGH);
    assert (mapping_handle>=0);
    assert (num_arrays>=0);
    assert (procs);
    assert (vindices);
    assert (timelevels);
    assert (hdatatypes);
    assert (hdata);
    assert (retvals);
    
    // Remember whether there were errors
    bool everyting_okay = true;
    
    // Loop over all slabs
    for (int n=0; n<num_arrays; ++n) {
      // Forward call
      retvals[n] = CarpetSlab_Get (cctkGH, mapping_handle, procs[n],
                                   vindices[n], timelevels[n], hdatatypes[n],
                                   hdata[n]);
      everyting_okay = everyting_okay && retvals[n];
    }
    
    return everyting_okay ? 0 : -1;
  }
  
  
  
} // namespace CarpetSlab