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

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



namespace CarpetTracker {

using namespace std;
  
  
  
  extern "C" {
    void
    CarpetTracker_SetPositions (CCTK_ARGUMENTS);
  }
  
  
  
  void
  SetParameter (char const * const dir, int const n, CCTK_REAL const pos)
  {
    ostringstream name_buf;
    name_buf << "position_" << dir << "_" << n + 1;
    string const name (name_buf.str());
    ostringstream pos_buf;
    pos_buf << pos;
    string const pos_str (pos_buf.str());
    int const ierr =
      CCTK_ParameterSet (name.c_str(), "CarpetRegrid2", pos_str.c_str());
    assert (not ierr);
  }
  
  
  
  void
  CarpetTracker_SetPositions (CCTK_ARGUMENTS)
  {
    DECLARE_CCTK_ARGUMENTS;
    DECLARE_CCTK_PARAMETERS;
    
    for (int n = 0; n < 3; ++ n) {
      int const sn = surface[n];
      if (sn >= 0) {
        assert (sn >= 0 and sn < nsurfaces);
        
        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]));
          }
          SetParameter ("x", n, sf_centroid_x[sn]);
          SetParameter ("y", n, sf_centroid_y[sn]);
          SetParameter ("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
    } // for
  }
  
} // namespace CarpetTracker