Cartesian.hpp 130 KB
Newer Older
gsell's avatar
gsell committed
1 2 3 4
// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
5 6
 *
 * This program was prepared by PSI.
gsell's avatar
gsell committed
7 8 9 10 11 12 13 14 15 16 17 18 19
 * All rights in the program are reserved by PSI.
 * Neither PSI nor the author(s)
 * makes any warranty, express or implied, or assumes any liability or
 * responsibility for the use of this software
 *
 * Visit www.amas.web.psi for more details
 *
 ***************************************************************************/

// -*- C++ -*-
/***************************************************************************
 *
 * The IPPL Framework
20
 *
gsell's avatar
gsell committed
21 22 23 24 25 26 27 28 29 30
 *
 * Visit http://people.web.psi.ch/adelmann/ for more details
 *
 ***************************************************************************/

// Cartesian.cpp
// Implementations for Cartesian mesh class (nonuniform spacings)

// include files
#include "Utility/PAssert.h"
31
#include "Utility/IpplException.h"
gsell's avatar
gsell committed
32 33 34 35 36 37 38 39 40 41 42 43
#include "Utility/IpplInfo.h"
#include "Field/BareField.h"
#include "Field/BrickExpression.h"
#include "Field/LField.h"
#include "Field/Field.h"
#include "Field/Assign.h"
#include "Field/AssignDefs.h"

//-----------------------------------------------------------------------------
// Setup chores common to all constructors:
//-----------------------------------------------------------------------------
template <unsigned Dim, class MFLOAT>
44
void
gsell's avatar
gsell committed
45 46 47 48 49 50 51 52 53 54 55 56 57
Cartesian<Dim,MFLOAT>::
setup()
{
  hasSpacingFields = false;
}

//-----------------------------------------------------------------------------
// Constructors from NDIndex object:
//-----------------------------------------------------------------------------
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const NDIndex<Dim>& ndi)
{
58
  unsigned int d,i;
gsell's avatar
gsell committed
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
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
    origin(d) = ndi[d].first();     // Default origin at ndi[d].first()
    // default mesh spacing from stride()
    for (i=0; i < gridSizes[d]-1; i++) {
      (meshSpacing[d])[i] = ndi[d].stride();
      (meshPosition[d])[i] = MFLOAT(i);
    }
    (meshPosition[d])[gridSizes[d]-1] = MFLOAT(gridSizes[d]-1);
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const NDIndex<Dim>& ndi, MFLOAT** const delX)
{
  unsigned int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
    origin(d) = ndi[d].first();     // Default origin at ndi[d].first()
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const NDIndex<Dim>& ndi, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig)
{
  int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const NDIndex<Dim>& ndi, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
//-----------------------------------------------------------------------------
// Constructors from Index objects:
//-----------------------------------------------------------------------------

//===========1D============
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first()
138
  unsigned int i;
gsell's avatar
gsell committed
139 140 141 142 143 144
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
kraus's avatar
kraus committed
145
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
146 147 148 149 150 151 152 153 154 155 156 157 158 159
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, MFLOAT** const delX)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first()
kraus's avatar
kraus committed
160
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  setup();
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
kraus's avatar
kraus committed
176
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
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 204 205 206 207 208 209
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  setup();
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//===========2D============
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first(),J.first()
  origin(1) = J.first();
210
  unsigned int i;
gsell's avatar
gsell committed
211 212 213 214 215 216 217 218 219 220 221
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
  for (i=0; i < gridSizes[1]-1; i++) {
    (meshSpacing[1])[i] = J.stride();
    (meshPosition[1])[i] = MFLOAT(i);
  }
  (meshPosition[1])[gridSizes[1]-1] = MFLOAT(gridSizes[1]-1);
kraus's avatar
kraus committed
222
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, MFLOAT** const delX)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first(),J.first()
  origin(1) = J.first();
kraus's avatar
kraus committed
239
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
kraus's avatar
kraus committed
256
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, MFLOAT** const delX,
          const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//===========3D============
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, const Index& K)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  // Setup chores, such as array allocations
290
  setup();
gsell's avatar
gsell committed
291 292 293
  origin(0) = I.first();    // Default origin at I.first(),J.first(),K.first()
  origin(1) = J.first();
  origin(2) = K.first();
294
  unsigned int i;
gsell's avatar
gsell committed
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
  for (i=0; i < gridSizes[1]-1; i++) {
    (meshSpacing[1])[i] = J.stride();
    (meshPosition[1])[i] = MFLOAT(i);
  }
  (meshPosition[1])[gridSizes[1]-1] = MFLOAT(gridSizes[1]-1);
  for (i=0; i < gridSizes[2]-1; i++) {
    (meshSpacing[2])[i] = K.stride();
    (meshPosition[2])[i] = MFLOAT(i);
  }
  (meshPosition[2])[gridSizes[2]-1] = MFLOAT(gridSizes[2]-1);

kraus's avatar
kraus committed
312
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, const Index& K,
          MFLOAT** const delX)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();    // Default origin at I.first(),J.first(),K.first()
  origin(1) = J.first();
  origin(2) = K.first();
kraus's avatar
kraus committed
332
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, const Index& K,
          MFLOAT** const delX, const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
kraus's avatar
kraus committed
350
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
Cartesian<Dim,MFLOAT>::
Cartesian(const Index& I, const Index& J, const Index& K,
          MFLOAT** const delX, const Vektor<MFLOAT,Dim>& orig,
          MeshBC_E* const mbc)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//-----------------------------------------------------------------------------
// initialize using NDIndex object:
//-----------------------------------------------------------------------------
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const NDIndex<Dim>& ndi)
{
384
  unsigned int d,i;
gsell's avatar
gsell committed
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
    origin(d) = ndi[d].first();     // Default origin at ndi[d].first()
    // default mesh spacing from stride()
    for (i=0; i < gridSizes[d]-1; i++) {
      (meshSpacing[d])[i] = ndi[d].stride();
      (meshPosition[d])[i] = MFLOAT(i);
    }
    (meshPosition[d])[gridSizes[d]-1] = MFLOAT(gridSizes[d]-1);
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const NDIndex<Dim>& ndi, MFLOAT** const delX)
{
  unsigned int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
    origin(d) = ndi[d].first();     // Default origin at ndi[d].first()
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const NDIndex<Dim>& ndi, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig)
{
  int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  for (d=0; d<Dim; d++) {
    MeshBC[2*d]   = Reflective;     // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective;     // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const NDIndex<Dim>& ndi, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  int d;
  for (d=0; d<Dim; d++)
    gridSizes[d] = ndi[d].length(); // Number of vertices along this dimension.
  setup();                          // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
//-----------------------------------------------------------------------------
// initialize using Index objects:
//-----------------------------------------------------------------------------

//===========1D============
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first()
468
  unsigned int i;
gsell's avatar
gsell committed
469 470 471 472 473 474
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
kraus's avatar
kraus committed
475
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, MFLOAT** const delX)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first()
kraus's avatar
kraus committed
491
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  setup();
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
kraus's avatar
kraus committed
508
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  PInsist(Dim==1,"Number of Index arguments does not match mesh dimension!!");
  setup();
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//===========2D============
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first(),J.first()
  origin(1) = J.first();
544
  unsigned int i;
gsell's avatar
gsell committed
545 546 547 548 549 550 551 552 553 554 555
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
  for (i=0; i < gridSizes[1]-1; i++) {
    (meshSpacing[1])[i] = J.stride();
    (meshPosition[1])[i] = MFLOAT(i);
  }
  (meshPosition[1])[gridSizes[1]-1] = MFLOAT(gridSizes[1]-1);
kraus's avatar
kraus committed
556
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, MFLOAT** const delX)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();      // Default origin at I.first(),J.first()
  origin(1) = J.first();
kraus's avatar
kraus committed
574
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
kraus's avatar
kraus committed
592
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, MFLOAT** const delX,
           const Vektor<MFLOAT,Dim>& orig, MeshBC_E* const mbc)
{
  PInsist(Dim==2,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//===========3D============
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, const Index& K)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  // Setup chores, such as array allocations
628
  setup();
gsell's avatar
gsell committed
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
  origin(0) = I.first();    // Default origin at I.first(),J.first(),K.first()
  origin(1) = J.first();
  origin(2) = K.first();
  int i;
  // Default mesh spacing from stride()
  for (i=0; i < gridSizes[0]-1; i++) {
    (meshSpacing[0])[i] = I.stride();
    (meshPosition[0])[i] = MFLOAT(i);
  }
  (meshPosition[0])[gridSizes[0]-1] = MFLOAT(gridSizes[0]-1);
  for (i=0; i < gridSizes[1]-1; i++) {
    (meshSpacing[1])[i] = J.stride();
    (meshPosition[1])[i] = MFLOAT(i);
  }
  (meshPosition[1])[gridSizes[1]-1] = MFLOAT(gridSizes[1]-1);
  for (i=0; i < gridSizes[2]-1; i++) {
    (meshSpacing[2])[i] = K.stride();
    (meshPosition[2])[i] = MFLOAT(i);
  }
  (meshPosition[2])[gridSizes[2]-1] = MFLOAT(gridSizes[2]-1);

kraus's avatar
kraus committed
650
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, const Index& K,
           MFLOAT** const delX)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  origin(0) = I.first();    // Default origin at I.first(),J.first(),K.first()
  origin(1) = J.first();
  origin(2) = K.first();
kraus's avatar
kraus committed
671
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify mesh spacings and origin:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, const Index& K,
           MFLOAT** const delX, const Vektor<MFLOAT,Dim>& orig)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
kraus's avatar
kraus committed
690
  for (unsigned int d=0; d<Dim; d++) {
gsell's avatar
gsell committed
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728
    MeshBC[2*d]   = Reflective; // Default mesh: reflective boundary conds
    MeshBC[2*d+1] = Reflective; // Default mesh: reflective boundary conds
  }
  set_origin(orig);           // Set origin.
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}
// Also specify a MeshBC_E array for mesh boundary conditions:
template <unsigned Dim, class MFLOAT>
void
Cartesian<Dim,MFLOAT>::
initialize(const Index& I, const Index& J, const Index& K,
           MFLOAT** const delX, const Vektor<MFLOAT,Dim>& orig,
           MeshBC_E* const mbc)
{
  PInsist(Dim==3,"Number of Index arguments does not match mesh dimension!!");
  gridSizes[0] = I.length();  // Number of vertices along this dimension.
  gridSizes[1] = J.length();  // Number of vertices along this dimension.
  gridSizes[2] = K.length();  // Number of vertices along this dimension.
  setup();                    // Setup chores, such as array allocations
  set_origin(orig);           // Set origin.
  set_MeshBC(mbc);            // Set up mesh boundary conditions
  set_meshSpacing(delX);      // Set mesh spacings and compute cell volume
  set_Dvc();                  // Set derivative coefficients from spacings.
}

//-----------------------------------------------------------------------------
// Set/accessor functions for member data:
//-----------------------------------------------------------------------------
// Set the origin of mesh vertex positions:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
set_origin(const Vektor<MFLOAT,Dim>& o)
{
  origin = o;
  for (unsigned d=0; d<Dim; ++d) {
    (meshPosition[d])[0] = o(d);
    for (unsigned vert=1; vert<gridSizes[d]; ++vert) {
729
      (meshPosition[d])[vert] = (meshPosition[d])[vert-1] +
gsell's avatar
gsell committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
                                (meshSpacing[d])[vert-1];
    }
  }
  // Apply the current state of the mesh BC to add guards to meshPosition map:
  for (unsigned face=0; face < 2*Dim; ++face) updateMeshSpacingGuards(face);
  this->notifyOfChange();
}
// Get the origin of mesh vertex positions:
template<unsigned Dim, class MFLOAT>
Vektor<MFLOAT,Dim> Cartesian<Dim,MFLOAT>::
get_origin() const
{
  return origin;
}

// Set the spacings of mesh vertex positions:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
set_meshSpacing(MFLOAT** const del)
{
  unsigned d, cell, face;

  for (d=0;d<Dim;++d) {
    (meshPosition[d])[0] = origin(d);
    for (cell=0; cell < gridSizes[d]-1; cell++) {
      (meshSpacing[d])[cell] = del[d][cell];
      (meshPosition[d])[cell+1] = (meshPosition[d])[cell] + del[d][cell];
    }
  }
  // Apply the current state of the mesh BC to add guards to meshSpacings map:
  for (face=0; face < 2*Dim; ++face) updateMeshSpacingGuards(face);
  // if spacing fields allocated, we must update values
  if (hasSpacingFields) storeSpacingFields();
  this->notifyOfChange();
}

// Set only the derivative constants, using pre-set spacings:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
set_Dvc()
{
  unsigned d;
  MFLOAT coef = 1.0;
  for (d=1;d<Dim;++d) coef *= 0.5;

  for (d=0;d<Dim;++d) {
    MFLOAT dvc = coef;
    for (unsigned b=0; b<(1<<Dim); ++b) {
      int s = ( b&(1<<d) ) ? 1 : -1;
      Dvc[b](d) = s*dvc;
    }
  }
}

// Get the spacings of mesh vertex positions along specified direction:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
get_meshSpacing(unsigned d, MFLOAT* spacings) const
{
789
  PAssert_LT(d, Dim);
790
  for (unsigned int cell=0; cell < gridSizes[d]-1; cell++)
gsell's avatar
gsell committed
791 792 793 794 795 796 797
    spacings[cell] = (*(meshSpacing[d].find(cell))).second;
  return;
}
//leak template<unsigned Dim, class MFLOAT>
//leak MFLOAT* Cartesian<Dim,MFLOAT>::
//leak get_meshSpacing(unsigned d) const
//leak {
798
//leak   PAssert_LT(d, Dim);
gsell's avatar
gsell committed
799
//leak   MFLOAT* theMeshSpacing = new MFLOAT[gridSizes[d]-1];
800
//leak   for (int cell=0; cell < gridSizes[d]-1; cell++)
gsell's avatar
gsell committed
801 802 803 804 805 806
//leak     theMeshSpacing[cell] = (*(meshSpacing[d].find(cell))).second;
//leak   return theMeshSpacing;
//leak }

///////////////////////////////////////////////////////////////////////////////

807
// Applicative templates for Mesh BC PETE_apply() functions, used
gsell's avatar
gsell committed
808 809 810 811 812 813 814 815
// by BrickExpression in storeSpacingFields()

// Periodic:
template<class T>
struct OpMeshPeriodic
{
};
template<class T>
816
inline void PETE_apply(OpMeshPeriodic<T> /*e*/, T& a, T b) { a = b; }
gsell's avatar
gsell committed
817 818 819 820 821 822 823 824 825

// Reflective/None:
template<class T>
struct OpMeshExtrapolate
{
  OpMeshExtrapolate(T& o, T& s) : Offset(o), Slope(s) {}
  T Offset, Slope;
};
// template<class T>
826
// inline void apply(OpMeshExtrapolate<T> e, T& a, T b)
gsell's avatar
gsell committed
827
template<class T>
828 829
inline void PETE_apply(OpMeshExtrapolate<T> e, T& a, T b)
{
gsell's avatar
gsell committed
830 831 832 833 834 835 836 837 838 839 840 841 842 843
  a = b*e.Slope+e.Offset;
}

///////////////////////////////////////////////////////////////////////////////

// Create BareField's of vertex and cell spacings
// Special prototypes taking no args or FieldLayout ctor args:
// No-arg case:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields()
{
  // Set up default FieldLayout parameters:
  e_dim_tag et[Dim];
kraus's avatar
kraus committed
844
  for (unsigned int d=0; d<Dim; d++) et[d] = PARALLEL;
gsell's avatar
gsell committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883
  storeSpacingFields(et, -1);
}
// 1D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1, int vnodes)
{
  e_dim_tag et[1];
  et[0] = p1;
  storeSpacingFields(et, vnodes);
}
// 2D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1, e_dim_tag p2, int vnodes)
{
  e_dim_tag et[2];
  et[0] = p1;
  et[1] = p2;
  storeSpacingFields(et, vnodes);
}
// 3D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1, e_dim_tag p2, e_dim_tag p3, int vnodes)
{
  e_dim_tag et[3];
  et[0] = p1;
  et[1] = p2;
  et[2] = p3;
  storeSpacingFields(et, vnodes);
}


// The general storeSpacingfields() function; others invoke this internally:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag* et, int vnodes)
{
884
  unsigned int d;
gsell's avatar
gsell committed
885 886 887 888 889 890 891 892 893 894
  int currentLocation[Dim];
  NDIndex<Dim> cells, verts;
  for (d=0; d<Dim; d++) {
    cells[d] = Index(gridSizes[d]-1);
    verts[d] = Index(gridSizes[d]);
  }
  if (!hasSpacingFields) {
    // allocate layouts and spacing fields
    FlCell = new FieldLayout<Dim>(cells, et, vnodes);
    // Note: enough guard cells only for existing Div(), etc. implementations:
895
    VertSpacings =
gsell's avatar
gsell committed
896 897 898
      new BareField<Vektor<MFLOAT,Dim>,Dim>(*FlCell,GuardCellSizes<Dim>(1));
    FlVert = new FieldLayout<Dim>(verts, et, vnodes);
    // Note: enough guard cells only for existing Div(), etc. implementations:
899
    CellSpacings =
gsell's avatar
gsell committed
900 901 902 903 904 905 906 907 908 909
      new BareField<Vektor<MFLOAT,Dim>,Dim>(*FlVert,GuardCellSizes<Dim>(1));
  }
  // VERTEX-VERTEX SPACINGS:
  BareField<Vektor<MFLOAT,Dim>,Dim>& vertSpacings = *VertSpacings;
  Vektor<MFLOAT,Dim> vertexSpacing;
  vertSpacings.Uncompress(); // Must do this prior to assign via iterator
  typename BareField<Vektor<MFLOAT,Dim>,Dim>::iterator cfi,
    cfi_end = vertSpacings.end();
  for (cfi = vertSpacings.begin(); cfi != cfi_end; ++cfi) {
    cfi.GetCurrentLocation(currentLocation);
910
    for (d=0; d<Dim; d++)
gsell's avatar
gsell committed
911 912 913 914 915 916 917 918 919 920 921
      vertexSpacing(d) = (*(meshSpacing[d].find(currentLocation[d]))).second;
    *cfi = vertexSpacing;
  }
  // CELL-CELL SPACINGS:
  BareField<Vektor<MFLOAT,Dim>,Dim>& cellSpacings = *CellSpacings;
  Vektor<MFLOAT,Dim> cellSpacing;
  cellSpacings.Uncompress(); // Must do this prior to assign via iterator
  typename BareField<Vektor<MFLOAT,Dim>,Dim>::iterator vfi,
    vfi_end = cellSpacings.end();
  for (vfi = cellSpacings.begin(); vfi != vfi_end; ++vfi) {
    vfi.GetCurrentLocation(currentLocation);
922
    for (d=0; d<Dim; d++)
gsell's avatar
gsell committed
923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944
      cellSpacing(d) = 0.5 * ((meshSpacing[d])[currentLocation[d]] +
                              (meshSpacing[d])[currentLocation[d]-1]);
    *vfi = cellSpacing;
  }
  //-------------------------------------------------
  // Now the hard part, filling in the guard cells:
  //-------------------------------------------------
  // The easy part of the hard part is filling so that all the internal
  // guard layers are right:
  cellSpacings.fillGuardCells();
  vertSpacings.fillGuardCells();
  // The hard part of the hard part is filling the external guard layers,
  // using the mesh BC to figure out how:
  // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  // Temporaries used in loop over faces
  Vektor<MFLOAT,Dim> v0,v1; v0 = 0.0; v1 = 1.0; // Used for Reflective mesh BC
  typedef Vektor<MFLOAT,Dim> T;          // Used multipple places in loop below
  typename BareField<T,Dim>::iterator_if cfill_i; // Iterator used below
  typename BareField<T,Dim>::iterator_if vfill_i; // Iterator used below
  int coffset, voffset; // Pointer offsets used with LField::iterator below
  MeshBC_E bct;         // Scalar value of mesh BC used for each face in loop
  // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
945
  for (unsigned int face=0; face < 2*Dim; face++) {
gsell's avatar
gsell committed
946 947 948 949 950 951
    // NDIndex's spanning elements and guard elements:
    NDIndex<Dim> cSlab = AddGuardCells(verts,cellSpacings.getGuardCellSizes());
    NDIndex<Dim> vSlab = AddGuardCells(cells,vertSpacings.getGuardCellSizes());
    // Shrink it down to be the guards along the active face:
    d = face/2;
    // The following bitwise AND logical test returns true if face is odd
952 953
    // (meaning the "high" or "right" face in the numbering convention) and
    // returns false if face is even (meaning the "low" or "left" face in
gsell's avatar
gsell committed
954 955
    // the numbering convention):
    if ( face & 1 ) {
956
      cSlab[d] = Index(verts[d].max() + 1,
957
                       verts[d].max() + cellSpacings.rightGuard(d));
958
      vSlab[d] = Index(cells[d].max() + 1,
959
                       cells[d].max() + vertSpacings.rightGuard(d));
gsell's avatar
gsell committed
960
    } else {
961
      cSlab[d] = Index(verts[d].min() - cellSpacings.leftGuard(d),
962
                       verts[d].min() - 1);
963
      vSlab[d] = Index(cells[d].min() - vertSpacings.leftGuard(d),
964
                       cells[d].min() - 1);
gsell's avatar
gsell committed
965 966 967 968 969 970
    }
    // Compute pointer offsets used with LField::iterator below:
    switch (MeshBC[face]) {
    case Periodic:
      bct = Periodic;
      if ( face & 1 ) {
971 972
        coffset = -verts[d].length();
        voffset = -cells[d].length();
gsell's avatar
gsell committed
973
      } else {
974 975
        coffset = verts[d].length();
        voffset = cells[d].length();
976
      }
gsell's avatar
gsell committed
977 978 979 980
      break;
    case Reflective:
      bct = Reflective;
      if ( face & 1 ) {
981 982
        coffset = 2*verts[d].max() + 1;
        voffset = 2*cells[d].max() + 1 - 1;
gsell's avatar
gsell committed
983
      } else {
984 985
        coffset = 2*verts[d].min() - 1;
        voffset = 2*cells[d].min() - 1 + 1;
986
      }
gsell's avatar
gsell committed
987 988 989 990
      break;
    case NoBC:
      bct = NoBC;
      if ( face & 1 ) {
991 992
        coffset = 2*verts[d].max() + 1;
        voffset = 2*cells[d].max() + 1 - 1;
gsell's avatar
gsell committed
993
      } else {
994 995
        coffset = 2*verts[d].min() - 1;
        voffset = 2*cells[d].min() - 1 + 1;
996
      }
gsell's avatar
gsell committed
997 998
      break;
    default:
999
        throw IpplException("Cartesian::storeSpacingFields", "unknown MeshBC type");
gsell's avatar
gsell committed
1000 1001 1002 1003
    }

    // Loop over all the LField's in the BareField's:
    // +++++++++++++++cellSpacings++++++++++++++
1004
    for (cfill_i=cellSpacings.begin_if();
1005
         cfill_i!=cellSpacings.end_if(); ++cfill_i)
gsell's avatar
gsell committed
1006
      {
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
        // Cache some things we will use often below.
        // Pointer to the data for the current LField (right????):
        LField<T,Dim> &fill = *(*cfill_i).second;
        // NDIndex spanning all elements in the LField, including the guards:
        const NDIndex<Dim> &fill_alloc = fill.getAllocated();
        // If the previously-created boundary guard-layer NDIndex "cSlab"
        // contains any of the elements in this LField (they will be guard
        // elements if it does), assign the values into them here by applying
        // the boundary condition:
        if ( cSlab.touches( fill_alloc ) )
          {
            // Find what it touches in this LField.
            NDIndex<Dim> dest = cSlab.intersect( fill_alloc );

            // For exrapolation boundary conditions, the boundary guard-layer
            // elements are typically copied from interior values; the "src"
            // NDIndex specifies the interior elements to be copied into the
            // "dest" boundary guard-layer elements (possibly after some
            // mathematical operations like multipplying by minus 1 later):
            NDIndex<Dim> src = dest; // Create dest equal to src
            // Now calculate the interior elements; the coffset variable
            // computed above makes this right for "low" or "high" face cases:
            src[d] = coffset - src[d];

            // TJW: Why is there another loop over LField's here??????????
            // Loop over the ones that src touches.
            typename BareField<T,Dim>::iterator_if from_i;
            for (from_i=cellSpacings.begin_if();
                 from_i!=cellSpacings.end_if(); ++from_i)
              {
                // Cache a few things.
                LField<T,Dim> &from = *(*from_i).second;
                const NDIndex<Dim> &from_owned = from.getOwned();
                const NDIndex<Dim> &from_alloc = from.getAllocated();
                // If src touches this LField...
                if ( src.touches( from_owned ) )
                  {
                    NDIndex<Dim> from_it = src.intersect( from_alloc );
                    NDIndex<Dim> cfill_it = dest.plugBase( from_it );
                    // Build iterators for the copy...
                    typedef typename LField<T,Dim>::iterator LFI;
                    LFI lhs = fill.begin(cfill_it);
                    LFI rhs = from.begin(from_it);
                    // And do the assignment.
                    if (bct == Periodic) {
                      BrickExpression<Dim,LFI,LFI,OpMeshPeriodic<T> >
                        (lhs,rhs,OpMeshPeriodic<T>()).apply();
                    } else {
                      if (bct == Reflective) {
                        BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                          (lhs,rhs,OpMeshExtrapolate<T>(v0,v1)).apply();
                      } else {
                        if (bct == NoBC) {
                          BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                            (lhs,rhs,OpMeshExtrapolate<T>(v0,v0)).apply();
                        }
                      }
                    }
                  }
              }
          }
gsell's avatar
gsell committed
1068 1069
      }
    // +++++++++++++++vertSpacings++++++++++++++
1070
    for (vfill_i=vertSpacings.begin_if();
1071
         vfill_i!=vertSpacings.end_if(); ++vfill_i)
gsell's avatar
gsell committed
1072
      {
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
        // Cache some things we will use often below.
        // Pointer to the data for the current LField (right????):
        LField<T,Dim> &fill = *(*vfill_i).second;
        // NDIndex spanning all elements in the LField, including the guards:
        const NDIndex<Dim> &fill_alloc = fill.getAllocated();
        // If the previously-created boundary guard-layer NDIndex "cSlab"
        // contains any of the elements in this LField (they will be guard
        // elements if it does), assign the values into them here by applying
        // the boundary condition:
        if ( vSlab.touches( fill_alloc ) )
          {
            // Find what it touches in this LField.
            NDIndex<Dim> dest = vSlab.intersect( fill_alloc );

            // For exrapolation boundary conditions, the boundary guard-layer
            // elements are typically copied from interior values; the "src"
            // NDIndex specifies the interior elements to be copied into the
            // "dest" boundary guard-layer elements (possibly after some
            // mathematical operations like multipplying by minus 1 later):
            NDIndex<Dim> src = dest; // Create dest equal to src
            // Now calculate the interior elements; the voffset variable
            // computed above makes this right for "low" or "high" face cases:
            src[d] = voffset - src[d];

            // TJW: Why is there another loop over LField's here??????????
            // Loop over the ones that src touches.
            typename BareField<T,Dim>::iterator_if from_i;
            for (from_i=vertSpacings.begin_if();
                 from_i!=vertSpacings.end_if(); ++from_i)
              {
                // Cache a few things.
                LField<T,Dim> &from = *(*from_i).second;
                const NDIndex<Dim> &from_owned = from.getOwned();
                const NDIndex<Dim> &from_alloc = from.getAllocated();
                // If src touches this LField...
                if ( src.touches( from_owned ) )
                  {
                    NDIndex<Dim> from_it = src.intersect( from_alloc );
                    NDIndex<Dim> vfill_it = dest.plugBase( from_it );
                    // Build iterators for the copy...
                    typedef typename LField<T,Dim>::iterator LFI;
                    LFI lhs = fill.begin(vfill_it);
                    LFI rhs = from.begin(from_it);
                    // And do the assignment.
                    if (bct == Periodic) {
                      BrickExpression<Dim,LFI,LFI,OpMeshPeriodic<T> >
                        (lhs,rhs,OpMeshPeriodic<T>()).apply();
                    } else {
                      if (bct == Reflective) {
                        BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                          (lhs,rhs,OpMeshExtrapolate<T>(v0,v1)).apply();
                      } else {
                        if (bct == NoBC) {
                          BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                            (lhs,rhs,OpMeshExtrapolate<T>(v0,v0)).apply();
                        }
                      }
                    }
                  }
              }
          }
gsell's avatar
gsell committed
1134
      }
1135

gsell's avatar
gsell committed
1136
  }
1137

gsell's avatar
gsell committed
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
  hasSpacingFields = true; // Flag this as having been done to this object.
}


// These specify both the total number of vnodes and the numbers of vnodes
// along each dimension for the partitioning of the index space. Obviously
// this restricts the number of vnodes to be a product of the numbers along
// each dimension (the constructor implementation checks this): Special
// cases for 1-3 dimensions, ala FieldLayout ctors (see FieldLayout.h for
// more relevant comments, including definition of recurse):

// 1D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1,
1153 1154 1155
                        unsigned vnodes1,
                        bool recurse,
                        int vnodes) {
gsell's avatar
gsell committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
  e_dim_tag et[1];
  et[0] = p1;
  unsigned vnodesPerDirection[Dim];
  vnodesPerDirection[0] = vnodes1;
  storeSpacingFields(et, vnodesPerDirection, recurse, vnodes);
}
// 2D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1, e_dim_tag p2,
1166 1167
                        unsigned vnodes1, unsigned vnodes2,
                        bool recurse,int vnodes) {
gsell's avatar
gsell committed
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
  e_dim_tag et[2];
  et[0] = p1;
  et[1] = p2;
  unsigned vnodesPerDirection[Dim];
  vnodesPerDirection[0] = vnodes1;
  vnodesPerDirection[1] = vnodes2;
  storeSpacingFields(et, vnodesPerDirection, recurse, vnodes);
}
// 3D
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
storeSpacingFields(e_dim_tag p1, e_dim_tag p2, e_dim_tag p3,
1180 1181
                   unsigned vnodes1, unsigned vnodes2, unsigned vnodes3,
                   bool recurse, int vnodes) {
gsell's avatar
gsell committed
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198
  e_dim_tag et[3];
  et[0] = p1;
  et[1] = p2;
  et[2] = p3;
  unsigned vnodesPerDirection[Dim];
  vnodesPerDirection[0] = vnodes1;
  vnodesPerDirection[1] = vnodes2;
  vnodesPerDirection[2] = vnodes3;
  storeSpacingFields(et, vnodesPerDirection, recurse, vnodes);
}

// TJW: Note: should clean up here eventually, and put redundant code from
// this and the other general storeSpacingFields() implementation into one
// function. Need to check this in quickly for Blanca right now --12/8/98
// The general storeSpacingfields() function; others invoke this internally:
template<unsigned Dim, class MFLOAT>
void Cartesian<Dim,MFLOAT>::
1199
storeSpacingFields(e_dim_tag *p,
1200 1201 1202
                   unsigned* vnodesPerDirection,
                   bool recurse, int vnodes) {
  unsigned int d;
gsell's avatar
gsell committed
1203 1204 1205 1206 1207 1208 1209 1210
  int currentLocation[Dim];
  NDIndex<Dim> cells, verts;
  for (d=0; d<Dim; d++) {
    cells[d] = Index(gridSizes[d]-1);
    verts[d] = Index(gridSizes[d]);
  }
  if (!hasSpacingFields) {
    // allocate layouts and spacing fields
1211
    FlCell =
gsell's avatar
gsell committed
1212 1213
      new FieldLayout<Dim>(cells, p, vnodesPerDirection, recurse, vnodes);
    // Note: enough guard cells only for existing Div(), etc. implementations:
1214
    VertSpacings =
gsell's avatar
gsell committed
1215
      new BareField<Vektor<MFLOAT,Dim>,Dim>(*FlCell,GuardCellSizes<Dim>(1));
1216
    FlVert =
gsell's avatar
gsell committed
1217 1218
      new FieldLayout<Dim>(verts, p, vnodesPerDirection, recurse, vnodes);
    // Note: enough guard cells only for existing Div(), etc. implementations:
1219
    CellSpacings =
gsell's avatar
gsell committed
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
      new BareField<Vektor<MFLOAT,Dim>,Dim>(*FlVert,GuardCellSizes<Dim>(1));
  }
  // VERTEX-VERTEX SPACINGS:
  BareField<Vektor<MFLOAT,Dim>,Dim>& vertSpacings = *VertSpacings;
  Vektor<MFLOAT,Dim> vertexSpacing;
  vertSpacings.Uncompress(); // Must do this prior to assign via iterator
  typename BareField<Vektor<MFLOAT,Dim>,Dim>::iterator cfi,
    cfi_end = vertSpacings.end();
  for (cfi = vertSpacings.begin(); cfi != cfi_end; ++cfi) {
    cfi.GetCurrentLocation(currentLocation);
1230
    for (d=0; d<Dim; d++)
gsell's avatar
gsell committed
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241
      vertexSpacing(d) = (*(meshSpacing[d].find(currentLocation[d]))).second;
    *cfi = vertexSpacing;
  }
  // CELL-CELL SPACINGS:
  BareField<Vektor<MFLOAT,Dim>,Dim>& cellSpacings = *CellSpacings;
  Vektor<MFLOAT,Dim> cellSpacing;
  cellSpacings.Uncompress(); // Must do this prior to assign via iterator
  typename BareField<Vektor<MFLOAT,Dim>,Dim>::iterator vfi,
    vfi_end = cellSpacings.end();
  for (vfi = cellSpacings.begin(); vfi != vfi_end; ++vfi) {
    vfi.GetCurrentLocation(currentLocation);
1242
    for (d=0; d<Dim; d++)
gsell's avatar
gsell committed
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258
      cellSpacing(d) = 0.5 * ((meshSpacing[d])[currentLocation[d]] +
                              (meshSpacing[d])[currentLocation[d]-1]);
    *vfi = cellSpacing;
  }
  //-------------------------------------------------
  // Now the hard part, filling in the guard cells:
  //-------------------------------------------------
  // The easy part of the hard part is filling so that all the internal
  // guard layers are right:
  cellSpacings.fillGuardCells();
  vertSpacings.fillGuardCells();
  // The hard part of the hard part is filling the external guard layers,
  // using the mesh BC to figure out how:
  // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  // Temporaries used in loop over faces
  Vektor<MFLOAT,Dim> v0,v1; v0 = 0.0; v1 = 1.0; // Used for Reflective mesh BC
1259
  unsigned int face;
gsell's avatar
gsell committed
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
  typedef Vektor<MFLOAT,Dim> T;          // Used multipple places in loop below
  typename BareField<T,Dim>::iterator_if cfill_i; // Iterator used below
  typename BareField<T,Dim>::iterator_if vfill_i; // Iterator used below
  int coffset, voffset; // Pointer offsets used with LField::iterator below
  MeshBC_E bct;         // Scalar value of mesh BC used for each face in loop
  // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  for (face=0; face < 2*Dim; face++) {
    // NDIndex's spanning elements and guard elements:
    NDIndex<Dim> cSlab = AddGuardCells(verts,cellSpacings.getGuardCellSizes());
    NDIndex<Dim> vSlab = AddGuardCells(cells,vertSpacings.getGuardCellSizes());
    // Shrink it down to be the guards along the active face:
    d = face/2;
    // The following bitwise AND logical test returns true if face is odd
1273 1274
    // (meaning the "high" or "right" face in the numbering convention) and
    // returns false if face is even (meaning the "low" or "left" face in
gsell's avatar
gsell committed
1275 1276
    // the numbering convention):
    if ( face & 1 ) {
1277
      cSlab[d] = Index(verts[d].max() + 1,
1278
                       verts[d].max() + cellSpacings.rightGuard(d));
1279
      vSlab[d] = Index(cells[d].max() + 1,
1280
                       cells[d].max() + vertSpacings.rightGuard(d));
gsell's avatar
gsell committed
1281
    } else {
1282
      cSlab[d] = Index(verts[d].min() - cellSpacings.leftGuard(d),
1283
                       verts[d].min() - 1);
1284
      vSlab[d] = Index(cells[d].min() - vertSpacings.leftGuard(d),
1285
                       cells[d].min() - 1);
gsell's avatar
gsell committed
1286 1287 1288 1289 1290 1291
    }
    // Compute pointer offsets used with LField::iterator below:
    switch (MeshBC[face]) {
    case Periodic:
      bct = Periodic;
      if ( face & 1 ) {
1292 1293
        coffset = -verts[d].length();
        voffset = -cells[d].length();
gsell's avatar
gsell committed
1294
      } else {
1295 1296
        coffset = verts[d].length();
        voffset = cells[d].length();
1297
      }
gsell's avatar
gsell committed
1298 1299 1300 1301
      break;
    case Reflective:
      bct = Reflective;
      if ( face & 1 ) {
1302 1303
        coffset = 2*verts[d].max() + 1;
        voffset = 2*cells[d].max() + 1 - 1;
gsell's avatar
gsell committed
1304
      } else {
1305 1306
        coffset = 2*verts[d].min() - 1;
        voffset = 2*cells[d].min() - 1 + 1;
1307
      }
gsell's avatar
gsell committed
1308 1309 1310 1311
      break;
    case NoBC:
      bct = NoBC;
      if ( face & 1 ) {
1312 1313
        coffset = 2*verts[d].max() + 1;
        voffset = 2*cells[d].max() + 1 - 1;
gsell's avatar
gsell committed
1314
      } else {
1315 1316
        coffset = 2*verts[d].min() - 1;
        voffset = 2*cells[d].min() - 1 + 1;
1317
      }
gsell's avatar
gsell committed
1318 1319 1320 1321 1322 1323 1324 1325
      break;
    default:
      ERRORMSG("Cartesian::storeSpacingFields(): unknown MeshBC type" << endl);
      break;
    }

    // Loop over all the LField's in the BareField's:
    // +++++++++++++++cellSpacings++++++++++++++
1326
    for (cfill_i=cellSpacings.begin_if();
1327
         cfill_i!=cellSpacings.end_if(); ++cfill_i)
gsell's avatar
gsell committed
1328
      {
1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389
        // Cache some things we will use often below.
        // Pointer to the data for the current LField (right????):
        LField<T,Dim> &fill = *(*cfill_i).second;
        // NDIndex spanning all elements in the LField, including the guards:
        const NDIndex<Dim> &fill_alloc = fill.getAllocated();
        // If the previously-created boundary guard-layer NDIndex "cSlab"
        // contains any of the elements in this LField (they will be guard
        // elements if it does), assign the values into them here by applying
        // the boundary condition:
        if ( cSlab.touches( fill_alloc ) )
          {
            // Find what it touches in this LField.
            NDIndex<Dim> dest = cSlab.intersect( fill_alloc );

            // For exrapolation boundary conditions, the boundary guard-layer
            // elements are typically copied from interior values; the "src"
            // NDIndex specifies the interior elements to be copied into the
            // "dest" boundary guard-layer elements (possibly after some
            // mathematical operations like multipplying by minus 1 later):
            NDIndex<Dim> src = dest; // Create dest equal to src
            // Now calculate the interior elements; the coffset variable
            // computed above makes this right for "low" or "high" face cases:
            src[d] = coffset - src[d];

            // TJW: Why is there another loop over LField's here??????????
            // Loop over the ones that src touches.
            typename BareField<T,Dim>::iterator_if from_i;
            for (from_i=cellSpacings.begin_if();
                 from_i!=cellSpacings.end_if(); ++from_i)
              {
                // Cache a few things.
                LField<T,Dim> &from = *(*from_i).second;
                const NDIndex<Dim> &from_owned = from.getOwned();
                const NDIndex<Dim> &from_alloc = from.getAllocated();
                // If src touches this LField...
                if ( src.touches( from_owned ) )
                  {
                    NDIndex<Dim> from_it = src.intersect( from_alloc );
                    NDIndex<Dim> cfill_it = dest.plugBase( from_it );
                    // Build iterators for the copy...
                    typedef typename LField<T,Dim>::iterator LFI;
                    LFI lhs = fill.begin(cfill_it);
                    LFI rhs = from.begin(from_it);
                    // And do the assignment.
                    if (bct == Periodic) {
                      BrickExpression<Dim,LFI,LFI,OpMeshPeriodic<T> >
                        (lhs,rhs,OpMeshPeriodic<T>()).apply();
                    } else {
                      if (bct == Reflective) {
                        BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                          (lhs,rhs,OpMeshExtrapolate<T>(v0,v1)).apply();
                      } else {
                        if (bct == NoBC) {
                          BrickExpression<Dim,LFI,LFI,OpMeshExtrapolate<T> >
                            (lhs,rhs,OpMeshExtrapolate<T>(v0,v0)).apply();
                        }
                      }
                    }
                  }
              }
          }
gsell's avatar
gsell committed
1390 1391
      }
    // +++++++++++++++vertSpacings++++++++++++++
1392
    for (vfill_i=vertSpacings.begin_if();
1393
         vfill_i!=vertSpacings.end_if(); ++vfill_i)
gsell's avatar
gsell committed
1394
      {
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429