Skip to content

Commit 767b60f

Browse files
authored
Merge pull request #154 from AetherModel/run_in_1d
Code can run in 1D (alt)
2 parents 2eb163b + 650bf81 commit 767b60f

File tree

14 files changed

+241
-39
lines changed

14 files changed

+241
-39
lines changed

include/aether.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#ifndef INCLUDE_AETHER_H_
55
#define INCLUDE_AETHER_H_
66

7+
const float aether_version = 0.6;
8+
79
/// The armadillo library is to allow the use of 3d cubes and other
810
/// array types, with array math built in. This eliminates loops!
911
#include <armadillo>

include/grid.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,14 @@ class Grid {
172172

173173
int64_t get_nGCs();
174174

175+
bool get_HasXdim();
176+
bool get_HasYdim();
177+
bool get_HasZdim();
178+
bool get_Is0D();
179+
bool get_Is1Dx();
180+
bool get_Is1Dy();
181+
bool get_Is1Dz();
182+
175183
void fill_grid(Planets planet);
176184
void correct_xy_grid(Planets planet);
177185
void calc_sza(Planets planet, Times time);
@@ -311,6 +319,19 @@ class Grid {
311319
int64_t nY, nLats;
312320
int64_t nZ, nAlts;
313321

322+
// These logicals define the dimensionality of the grid:
323+
bool Is0D = false;
324+
bool Is1Dx = false;
325+
bool Is1Dy = false;
326+
bool Is1Dz = false;
327+
bool Is2Dxy = false;
328+
bool Is2Dxz = false;
329+
bool Is2Dyz = false;
330+
bool Is3D = false;
331+
bool HasXdim = true;
332+
bool HasYdim = true;
333+
bool HasZdim = true;
334+
314335
int nGCs; // number of ghostcells
315336

316337
// interpolation members

include/output.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class OutputContainer {
119119
**/
120120
void set_version(float in_version);
121121

122+
/**********************************************************************
123+
\brief set the number of ghost cells in Aether
124+
\param in_nGCs the number of ghostcells in the grid
125+
**/
126+
void set_nGhostCells(int in_nGCs);
127+
122128
/**********************************************************************
123129
\brief write a file with the information in the container
124130
**/
@@ -191,9 +197,13 @@ class OutputContainer {
191197

192198
/// The time of the data
193199
std::vector<int> itime;
200+
194201
/// The version of the code / data / whatever:
195202
float version;
196203

204+
/// The number of Ghost Cells:
205+
int nGCs;
206+
197207
/// The frequency of the output for this particular container:
198208
float dt_output;
199209

share/run/UA/inputs/defaults.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969
"LatRange" : [-90.0, 90.0],
7070
"nLatsPerBlock" : 18,
7171
"LonRange" : [0.0, 360.0],
72-
"nLonsPerBlock" : 36,
73-
"nAlts" : 50,
72+
"nLonsPerBlock" : 20,
73+
"nAlts" : 40,
7474
"MinAlt" : 100.0,
7575
"dAltkm" : 5.0,
7676
"dAltScale" : 0.25,
@@ -82,11 +82,15 @@
8282
"LatRange" : [-90.0, 90.0],
8383
"nLatsPerBlock" : 18,
8484
"LonRange" : [0.0, 360.0],
85-
"nLonsPerBlock" : 36,
86-
"nAlts" : 200,
85+
"nLonsPerBlock" : 22,
86+
"nAlts" : 50,
8787
"MinAlt" : 80.0,
8888
"MinApex" : 120.0,
89-
"MaxAlt" : 5000.0},
89+
"MaxAlt" : 5000.0,
90+
"dAltkm" : 5.0,
91+
"dAltScale" : 0.25,
92+
"IsUniformAlt" : true,
93+
"AltFile" : ""},
9094

9195
"Oblate" : {
9296
"isOblate" : false,

src/containers_io.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,14 @@ void OutputContainer::set_version(float in_version) {
162162
version = in_version;
163163
}
164164

165+
// -----------------------------------------------------------------------------
166+
// Set the number of ghostcells.
167+
// -----------------------------------------------------------------------------
168+
169+
void OutputContainer::set_nGhostCells(int in_nGCs) {
170+
nGCs = in_nGCs;
171+
}
172+
165173
// -----------------------------------------------------------------------------
166174
// Clears the elements vector within the output container
167175
// -----------------------------------------------------------------------------
@@ -176,6 +184,7 @@ void OutputContainer::clear_variables() {
176184

177185
OutputContainer::OutputContainer() {
178186
// Set default output type to netCDF
187+
nGCs = 0;
179188
#ifdef NETCDF
180189
output_type = netcdf_type;
181190
#else
@@ -236,6 +245,7 @@ void OutputContainer::display() {
236245
std::cout << " nX : " << elements[0].value.n_rows << "\n";
237246
std::cout << " nY : " << elements[0].value.n_cols << "\n";
238247
std::cout << " nZ : " << elements[0].value.n_slices << "\n";
248+
std::cout << " nGCs : " << nGCs << "\n";
239249
int64_t nVars = elements.size();
240250
std::cout << " Number of Variables : " << nVars << "\n";
241251

@@ -281,6 +291,7 @@ bool OutputContainer::write_container_header() {
281291
{"nX", nX},
282292
{"nY", nY},
283293
{"nZ", nZ},
294+
{"nGCs", nGCs},
284295
{"nLons", nX},
285296
{"nLats", nY},
286297
{"nAlts", nZ},
@@ -327,6 +338,7 @@ bool OutputContainer::read_container_binary() {
327338
int64_t iY, nY = header["nY"];
328339
int64_t iZ, nZ = header["nZ"];
329340
int64_t iTotalSize = nX * nY * nZ;
341+
nGCs = header["nGCs"];
330342

331343
float *variable_array = new float[iTotalSize];
332344
arma_cube value_scgc;

src/exchange_messages.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,10 @@ bool exchange_one_var(Grid &grid,
896896
arma_cube &var_to_pass,
897897
bool doReverseSignAcrossPole) {
898898

899+
// This function is only needed if we do interpolation, which only happens in
900+
// the horizontal directions
901+
if (!grid.get_HasXdim() & !grid.get_HasYdim()) return true;
902+
899903
std::string function = "exchange_one_var";
900904
static int iFunction = -1;
901905
report.enter(function, iFunction);
@@ -1192,6 +1196,10 @@ arma_cube interpolate_ghostcells(arma_cube varIn, Grid &grid) {
11921196

11931197
bool find_ghostcell_interpolation_coefs(Grid &grid) {
11941198

1199+
// This function is only needed if we do interpolation, which only happens in
1200+
// the horizontal directions
1201+
if (!grid.get_HasXdim() & !grid.get_HasYdim()) return true;
1202+
11951203
std::string function = "find_ghostcell_interpolation_coefs";
11961204
static int iFunction = -1;
11971205
report.enter(function, iFunction);

src/grid.cpp

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,28 @@ Grid::Grid(std::string gridtype) {
2323
nZ = grid_input.nZ + nGCs * 2;
2424
nAlts = nZ;
2525

26+
// No set all of the logicals to make the flow a bit easier:
27+
28+
if (grid_input.nX == 1 &
29+
grid_input.nY == 1 &
30+
grid_input.nZ == 1)
31+
Is0D = true;
32+
else {
33+
if (grid_input.nY == 1 & grid_input.nZ == 1) Is1Dx = true;
34+
if (grid_input.nX == 1 & grid_input.nZ == 1) Is1Dy = true;
35+
if (grid_input.nX == 1 & grid_input.nY == 1) Is1Dz = true;
36+
if (!Is1Dx & !Is1Dy & !Is1Dz) {
37+
if (grid_input.nX == 1) Is2Dyz = true;
38+
if (grid_input.nY == 1) Is2Dxz = true;
39+
if (grid_input.nZ == 1) Is2Dxy = true;
40+
if (!Is2Dyz & !Is2Dxz & !Is2Dxy) Is3D = true;
41+
}
42+
}
43+
44+
if (grid_input.nX == 1) HasXdim = false;
45+
if (grid_input.nY == 1) HasYdim = false;
46+
if (grid_input.nZ == 1) HasZdim = false;
47+
2648
if (mklower(grid_input.shape) == "sphere")
2749
iGridShape_ = iSphere_;
2850
if (mklower(grid_input.shape) == "cubesphere")
@@ -192,8 +214,9 @@ bool Grid::write_restart(std::string dir) {
192214
try {
193215
OutputContainer RestartContainer;
194216
RestartContainer.set_directory(dir);
195-
RestartContainer.set_version(0.1);
217+
RestartContainer.set_version(aether_version);
196218
RestartContainer.set_time(0.0);
219+
RestartContainer.set_nGhostCells(nGCs);
197220

198221
// Output Cell Centers
199222
RestartContainer.set_filename("grid_" + cGrid);
@@ -280,7 +303,7 @@ bool Grid::read_restart(std::string dir) {
280303
try {
281304
OutputContainer RestartContainer;
282305
RestartContainer.set_directory(dir);
283-
RestartContainer.set_version(0.1);
306+
RestartContainer.set_version(aether_version);
284307
// Cell Centers:
285308
RestartContainer.set_filename("grid_" + cGrid);
286309
RestartContainer.read();
@@ -402,6 +425,38 @@ int64_t Grid::get_nPointsInGrid() {
402425
return nPoints;
403426
}
404427

428+
// --------------------------------------------------------------------------
429+
// Get some grid definition things
430+
// --------------------------------------------------------------------------
431+
432+
bool Grid::get_HasXdim() {
433+
return HasXdim;
434+
}
435+
436+
bool Grid::get_HasYdim() {
437+
return HasYdim;
438+
}
439+
440+
bool Grid::get_HasZdim() {
441+
return HasZdim;
442+
}
443+
444+
bool Grid::get_Is0D() {
445+
return Is0D;
446+
}
447+
448+
bool Grid::get_Is1Dx() {
449+
return Is1Dx;
450+
}
451+
452+
bool Grid::get_Is1Dy() {
453+
return Is1Dy;
454+
}
455+
456+
bool Grid::get_Is1Dz() {
457+
return Is1Dz;
458+
}
459+
405460
// --------------------------------------------------------------------------
406461
// Get a bunch of sizes within the grid
407462
// --------------------------------------------------------------------------

src/init_geo_grid.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,10 @@ void Grid::create_sphere_grid(Quadtree quadtree) {
650650
precision_t lon0 = lower_left_norm(0) * cPI;
651651
arma_vec lon1d(nLons);
652652

653+
// if we are not doing anything in the lon direction, then set dlon to
654+
// something reasonable:
655+
if (!HasXdim) dlon = 1.0 * cDtoR;
656+
653657
// Longitudes:
654658
// - Make a 1d vector
655659
// - copy it into the 3d cube
@@ -665,6 +669,10 @@ void Grid::create_sphere_grid(Quadtree quadtree) {
665669
precision_t lat0 = lower_left_norm(1) * cPI;
666670
arma_vec lat1d(nLats);
667671

672+
// if we are not doing anything in the lat direction, then set dlat to
673+
// something reasonable:
674+
if (!HasYdim) dlat = 1.0 * cDtoR;
675+
668676
// Latitudes:
669677
// - Make a 1d vector
670678
// - copy it into the 3d cube
@@ -947,11 +955,11 @@ bool Grid::init_geo_grid(Quadtree quadtree,
947955

948956
if (iGridShape_ == iCubesphere_) {
949957
report.print(0, "Creating Cubesphere Grid");
950-
create_cubesphere_connection(quadtree);
958+
if (!Is0D & !Is1Dz) create_cubesphere_connection(quadtree);
951959
IsCubeSphereGrid = true;
952960
} else {
953961
report.print(0, "Creating Spherical Grid");
954-
create_sphere_connection(quadtree);
962+
if (!Is0D & !Is1Dz) create_sphere_connection(quadtree);
955963
IsCubeSphereGrid = false;
956964
}
957965

src/ions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ bool Ions::restart_file(std::string dir, bool DoRead) {
303303
if (DoRead)
304304
RestartContainer.read();
305305
else {
306-
RestartContainer.set_version(0.1);
306+
RestartContainer.set_version(aether_version);
307307
RestartContainer.set_time(0.0);
308308
}
309309

src/neutrals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ bool Neutrals::restart_file(std::string dir, bool DoRead) {
359359
if (DoRead)
360360
RestartContainer.read();
361361
else {
362-
RestartContainer.set_version(0.1);
362+
RestartContainer.set_version(aether_version);
363363
RestartContainer.set_time(0.0);
364364
}
365365

0 commit comments

Comments
 (0)