aboutsummaryrefslogtreecommitdiff
path: root/Tools/CodeGen/CactusBoundary.m
blob: 733abb921f037922ece94435f70decc160681965 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
(* $Id$ *)

(*  Copyright 2004 Sascha Husa, Ian Hinder, Christiane Lechner

    This file is part of Kranc.

    Kranc is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    Kranc is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Kranc; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*)

(* This file provides:

   - Source files
   - List of implementations to inherit
   - List of files to include
   - Aliased functions to use
   - Groups to schedule
   - Functions to schedule
   - Parameters to declare

    *)

BeginPackage["CactusBoundary`", {"CodeGen`", "Thorn`",
 "MapLookup`", "KrancGroups`", "Errors`", "Helpers`", "Kranc`", "MoL`",
 "Code`", "Object`"}];

GetInheritedImplementations::usage = "";
GetIncludeFiles::usage = "";
GetUsedFunctions::usage = "";
GetScheduledGroups::usage = "";
GetScheduledFunctions::usage = "";
GetParameters::usage = "";
GetSources::usage = "";
CactusBoundaryProcessCode;

Begin["`Private`"];


GetInheritedImplementations[] := {"Boundary"};

GetIncludeFiles[] := {"Boundary.h"};

GetUsedFunctions[] := 
{  
  {Name      -> "Boundary_SelectGroupForBC",
   Type      -> "CCTK_INT",
   ArgString -> "CCTK_POINTER_TO_CONST IN GH, CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, CCTK_STRING IN group_name, CCTK_STRING IN bc_name"},

  {Name      -> "Boundary_SelectVarForBC",
   Type      -> "CCTK_INT",
   ArgString -> "CCTK_POINTER_TO_CONST IN GH, CCTK_INT IN faces, CCTK_INT IN boundary_width, CCTK_INT IN table_handle, CCTK_STRING IN var_name, CCTK_STRING IN bc_name"}
};

boundariesName[thornName_] := thornName <> "_SelectBoundConds";
checkBoundariesName[thornName_] := thornName <> "_CheckBoundaries";

GetScheduledGroups[thornName_] :=
{
 {Name          -> "ApplyBCs",
  Language      -> "None", (* groups do not have a language *)
  SchedulePoint -> "as " <> thornName <> "_ApplyBCs in MoL_PostStep "
                   <> "after " <> boundariesName[thornName], 
  Comment       -> "Apply boundary conditions "
                   <> "controlled by thorn Boundary"
 }
};

GetScheduledFunctions[thornName_, declaredGroups_List, groups_List] :=
{
  {
    Name          -> boundariesName[thornName],
    SchedulePoint -> "in MoL_PostStep",
    SynchronizedGroups -> MoLEvolvedGroups[declaredGroups, groups],
    Language      -> "C",
    Options       -> "level", 
    Comment       -> "select boundary conditions"
  },

  {
    Name          -> checkBoundariesName[thornName],
    SchedulePoint -> "at BASEGRID",
    Options       -> "meta",
    Language      -> "C",
    Comment       -> "check boundaries treatment"
  }
};

createBoundTypeParam[groupOrGF_, def_] := {
                 Name          ->  ToString@groupOrGF <> "_bound",
                 Type          ->  "KEYWORD",
                 Default       ->  def,
                 Description   ->  "Boundary condition to implement",
                 Visibility    ->  "private",
                 AllowedValues ->  {
        {Value -> "flat",      Description -> "Flat boundary condition"},
        {Value -> "none",      Description -> "No boundary condition"},
        {Value -> "static",    Description -> "Boundaries held fixed"},
        {Value -> "radiative", Description -> "Radiation boundary condition"},
        {Value -> "scalar",    Description -> "Dirichlet boundary condition"},
        {Value -> "newrad",    Description -> "Improved radiative boundary condition"},
        {Value -> "skip",      Description -> "skip boundary condition code"}},
                 Steerable -> Always
};


createBoundSpeedParam[groupOrGF_] := {
                 Name          ->  ToString@groupOrGF <> "_bound_speed",
                 Type          ->  "CCTK_REAL",
                 Default       ->  1.0,
                 Description   ->  "characteristic speed at boundary",
                 Visibility    ->  "private",
                 AllowedValues ->  {{Value -> "0:*" ,
                      Description -> "outgoing characteristic speed > 0"}},
                 Steerable -> Always
};

createBoundLimitParam[groupOrGF_] := {
                 Name          ->  ToString@groupOrGF <> "_bound_limit",
                 Type          ->  "CCTK_REAL",
                 Default       ->  0.0,
                 Description   ->  "limit value for r -> infinity",
                 Visibility    ->  "private",
                 AllowedValues ->  {{Value -> "*:*" ,
                      Description -> "value of limit value is unrestricted"}},
                 Steerable -> Always
};

createBoundScalarParam[groupOrGF_] := {
                 Name          ->  ToString@groupOrGF <> "_bound_scalar",
                 Type          ->  "CCTK_REAL",
                 Default       ->  0.0,
                 Description   ->  "Dirichlet boundary value",
                 Visibility    ->  "private",
                 AllowedValues ->  {{Value -> "*:*" ,
                      Description -> "unrestricted"}},
                 Steerable -> Always
};

DefFn[
  GetParameters[declaredGroups_List, groups_List] :=
  Module[
    {evolvedGFs, evolvedGroups},
    evolvedGroups = MoLEvolvedGroups[declaredGroups, groups];
    evolvedGFs = variablesFromGroups[evolvedGroups, groups];

  Join[Map[createBoundTypeParam[#,"skip"] &, evolvedGFs],
       Map[createBoundTypeParam[#,"none"] &, Map[unqualifiedGroupName,evolvedGroups]],

       Map[createBoundSpeedParam, evolvedGFs],
       Map[createBoundSpeedParam, Map[unqualifiedGroupName,evolvedGroups]], 

       Map[createBoundLimitParam, evolvedGFs],
       Map[createBoundLimitParam, Map[unqualifiedGroupName,evolvedGroups]],

       Map[createBoundScalarParam, evolvedGFs],
       Map[createBoundScalarParam, Map[unqualifiedGroupName,evolvedGroups]]]]];
 

GetSources[declaredGroups_, groups_, implementation_, thornName_] :=
  Module[{boundarySpec, evolvedGFs},
    evolvedGroups = MoLEvolvedGroups[declaredGroups, groups];
    evolvedGFs = variablesFromGroups[evolvedGroups, groups];

    boundarySpec = 
    {
      Groups -> evolvedGroups,
      EvolvedGFs -> Map[qualifyGFName[#, groups, implementation] &, evolvedGFs],
      BaseImplementation -> implementation, 
      ThornName -> thornName,
      ThornImplementation -> implementation, 
      ExcisionGFs -> evolvedGFs
    };

    Return[{{Filename -> "Boundaries.cc", 
             Contents -> CreateMoLBoundariesSource[boundarySpec]}}]];

DefFn[
  CactusBoundaryProcessCode[cIn_Code, opts___] :=
  Module[
    {c = cIn},

    c = JoinObjectField[
      c, "Sources",
      CactusBoundary`GetSources[
        Sequence@@
        (GetObjectField[c,#]& /@
         {"DeclaredGroups", "Groups", "Implementation", "Name"})]];
    c]];

End[];
EndPackage[];