aboutsummaryrefslogtreecommitdiff
path: root/Carpet/CarpetTracker/src/SetPositions.cc
blob: 9569aaadf519cdf4cc301dff47410f5d3db2cef0 (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
#include <cassert>
#include <sstream>
#include <string>

#include "cctk.h"
#include "cctk_Arguments.h"
#include "cctk_Parameters.h"
#include "cctk_Functions.h"



namespace CarpetTracker {

using namespace std;
  
  
  
  // Maximum number of tracked surfaces
  int const num_surfaces = 10;
  
  
  
  extern "C" {
    void
    CarpetTracker_SetPositions (CCTK_ARGUMENTS);
  }
  
  
  
  void
  CarpetTracker_SetPositions (CCTK_ARGUMENTS)
  {
    DECLARE_CCTK_ARGUMENTS;
    DECLARE_CCTK_PARAMETERS;
    
    static int cctk_iteration_done = -1;
    
    if (cctk_iteration == cctk_iteration_done) return;
    cctk_iteration_done = cctk_iteration;
    
    for (int n = 0; n < num_surfaces; ++ n) {
      int const sn = sf_IdFromName(surface[n], surface_name[n]);
      if (sn >= 0) {
        assert (sn >= 0 and sn < nsurfaces);
        
        if (sf_active[sn]) {
          if (sf_valid[sn] > 0) {
            
            if (verbose) {
              CCTK_VInfo (CCTK_THORNSTRING,
                          "Setting position of refined region #%d from surface #%d to (%g,%g,%g)",
                          n + 1, sn,
                          static_cast <double> (sf_centroid_x[sn]),
                          static_cast <double> (sf_centroid_y[sn]),
                          static_cast <double> (sf_centroid_z[sn]));
            }
            
            // Activate region
            active[n] = 1;
            
            // Set position in CarpetRegrid2
            position_x[n] = sf_centroid_x[sn];
            position_y[n] = sf_centroid_y[sn];
            position_z[n] = sf_centroid_z[sn];
            
          } else {
            
            if (verbose) {
              CCTK_VInfo (CCTK_THORNSTRING,
                          "No position information available for refined region #%d from surface #%d",
                          n + 1, sn);
            }
            
          } // if not valid
          
        } else {
          
          if (verbose) {
            CCTK_VInfo (CCTK_THORNSTRING,
                        "Refined region #%d (depending on surface #%d) is inactive",
                        n + 1, sn);
          }
          
          // Deactivate region
          active[n] = 0;
          
        } // if not active
        
      } // if sn > 0
    } // for n
  }
  
} // namespace CarpetTracker