XdmfRectilinearGrid.cpp 23.6 KB
Newer Older
Kenneth Leiter's avatar
Kenneth Leiter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*****************************************************************************/
/*                                    XDMF                                   */
/*                       eXtensible Data Model and Format                    */
/*                                                                           */
/*  Id : XdmfRectilinearGrid.cpp                                             */
/*                                                                           */
/*  Author:                                                                  */
/*     Kenneth Leiter                                                        */
/*     kenneth.leiter@arl.army.mil                                           */
/*     US Army Research Laboratory                                           */
/*     Aberdeen Proving Ground, MD                                           */
/*                                                                           */
/*     Copyright @ 2011 US Army Research Laboratory                          */
/*     All Rights Reserved                                                   */
/*     See Copyright.txt for details                                         */
/*                                                                           */
/*     This software is distributed WITHOUT ANY WARRANTY; without            */
/*     even the implied warranty of MERCHANTABILITY or FITNESS               */
/*     FOR A PARTICULAR PURPOSE.  See the above copyright notice             */
/*     for more information.                                                 */
/*                                                                           */
/*****************************************************************************/
23 24 25 26 27

#include <cmath>
#include "XdmfArray.hpp"
#include "XdmfGeometry.hpp"
#include "XdmfGeometryType.hpp"
28
#include "XdmfRectilinearGrid.hpp"
29 30
#include "XdmfTopology.hpp"
#include "XdmfTopologyType.hpp"
31
#include "XdmfError.hpp"
32 33 34 35

/**
 * PIMPL
 */
36
class XdmfRectilinearGrid::XdmfRectilinearGridImpl : public XdmfGridImpl {
37 38 39

public:

40 41 42 43 44
  class XdmfGeometryRectilinear : public XdmfGeometry
  {

  public:

45
    static shared_ptr<XdmfGeometryRectilinear>
46 47
    New(XdmfRectilinearGrid * const rectilinearGrid)
    {
48
      shared_ptr<XdmfGeometryRectilinear>
49 50 51 52 53 54 55
        p(new XdmfGeometryRectilinear(rectilinearGrid));
      return p;
    }

    unsigned int
    getNumberPoints() const
    {
56
      const shared_ptr<const XdmfArray> dimensions =
57 58 59 60 61 62 63 64 65 66 67
        mRectilinearGrid->getDimensions();
      if(dimensions->getSize() == 0) {
        return 0;
      }
      unsigned int toReturn = 1;
      for(unsigned int i=0; i<dimensions->getSize(); ++i) {
        toReturn *= dimensions->getValue<unsigned int>(i);
      }
      return toReturn;
    }

68 69 70 71 72
    bool isInitialized() const
    {
      return true;
    }

73
    void
74
    traverse(const shared_ptr<XdmfBaseVisitor> visitor)
75
    {
76
      const std::vector<shared_ptr<XdmfArray> > & coordinates =
77
        mRectilinearGrid->getCoordinates();
78 79 80
      for (unsigned int i = 0; i < coordinates.size(); ++i)
      {
        coordinates[i]->accept(visitor);
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
      }
    }

  private:

    XdmfGeometryRectilinear(XdmfRectilinearGrid * const rectilinearGrid) :
      mRectilinearGrid(rectilinearGrid)
    {
      this->setType(XdmfGeometryTypeRectilinear::New(mRectilinearGrid));
    }

    const XdmfRectilinearGrid * const mRectilinearGrid;
  };

  class XdmfGeometryTypeRectilinear : public XdmfGeometryType
  {

  public:

100
    static shared_ptr<const XdmfGeometryTypeRectilinear>
101 102
    New(const XdmfRectilinearGrid * const rectilinearGrid)
    {
103
      shared_ptr<const XdmfGeometryTypeRectilinear>
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
        p(new XdmfGeometryTypeRectilinear(rectilinearGrid));
      return p;
    }

    unsigned int
    getDimensions() const
    {
      return mRectilinearGrid->getDimensions()->getSize();
    }

    void
    getProperties(std::map<std::string, std::string> & collectedProperties) const
    {
      const unsigned int dimensions = this->getDimensions();
      if(dimensions == 3) {
        collectedProperties["Type"] = "VXVYVZ";
      }
      else if(dimensions == 2) {
        collectedProperties["Type"] = "VXVY";
      }
      else {
125
        collectedProperties["Type"] = "VECTORED";
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
      }
    }

  private:

    XdmfGeometryTypeRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
      XdmfGeometryType("", 0),
      mRectilinearGrid(rectilinearGrid)
    {
    }

    const XdmfRectilinearGrid * const mRectilinearGrid;

  };

  class XdmfTopologyRectilinear : public XdmfTopology
  {

  public:

146
    static shared_ptr<XdmfTopologyRectilinear>
147 148
    New(const XdmfRectilinearGrid * const rectilinearGrid)
    {
149
      shared_ptr<XdmfTopologyRectilinear>
150 151 152 153
        p(new XdmfTopologyRectilinear(rectilinearGrid));
      return p;
    }

154 155 156 157 158
    bool isInitialized() const
    {
      return true;
    }

159 160 161
    unsigned int
    getNumberElements() const
    {
162
      const shared_ptr<const XdmfArray> dimensions = 
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
        mRectilinearGrid->getDimensions();
      if(dimensions->getSize() == 0) {
        return 0;
      }
      unsigned int toReturn = 1;
      for(unsigned int i=0; i<dimensions->getSize(); ++i) {
        toReturn *= (dimensions->getValue<unsigned int>(i) - 1);
      }
      return toReturn;
    }

  private:

    XdmfTopologyRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
      mRectilinearGrid(rectilinearGrid)
    {
      this->setType(XdmfTopologyTypeRectilinear::New(rectilinearGrid));
    }

    const XdmfRectilinearGrid * const mRectilinearGrid;
  };

  class XdmfTopologyTypeRectilinear : public XdmfTopologyType
  {

  public:

190
    static shared_ptr<const XdmfTopologyTypeRectilinear>
191 192
    New(const XdmfRectilinearGrid * const rectilinearGrid)
    {
193
      shared_ptr<const XdmfTopologyTypeRectilinear>
194 195 196 197
        p(new XdmfTopologyTypeRectilinear(rectilinearGrid));
      return p;
    }

198 199 200
    unsigned int
    getEdgesPerElement() const
    {
201
      return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 1);
202 203 204 205 206
    }

    unsigned int
    getFacesPerElement() const
    {
207
      return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 2);
208 209
    }

210 211 212
    unsigned int
    getNodesPerElement() const
    {
213
      return calculateHypercubeNumElements(mRectilinearGrid->getDimensions()->getSize(), 0);
214 215 216 217 218
    }

    void
    getProperties(std::map<std::string, std::string> & collectedProperties) const
    {
219
      shared_ptr<const XdmfArray> dimensions = 
220 221 222 223 224 225 226 227
        mRectilinearGrid->getDimensions();
      if(dimensions->getSize() == 3) {
        collectedProperties["Type"] = "3DRectMesh";
      }
      else if(dimensions->getSize() == 2) {
        collectedProperties["Type"] = "2DRectMesh";
      }
      else {
228
        collectedProperties["Type"] = "RectMesh";
229 230 231 232 233 234 235
      }
      collectedProperties["Dimensions"] = dimensions->getValuesString();
    }

  private:

    XdmfTopologyTypeRectilinear(const XdmfRectilinearGrid * const rectilinearGrid) :
236 237 238 239 240 241 242
      XdmfTopologyType(0,
                       0,
                       std::vector<shared_ptr<const XdmfTopologyType> >(),
                       0,
                       "foo",
                       XdmfTopologyType::Structured,
                       0x1101),
243 244 245 246 247 248 249 250
      mRectilinearGrid(rectilinearGrid)
    {
    }

    const XdmfRectilinearGrid * const mRectilinearGrid;

  };

251
  XdmfRectilinearGridImpl(const std::vector<shared_ptr<XdmfArray> > & coordinates) :
252 253
    mCoordinates(coordinates.begin(), coordinates.end())
  {
254
    mGridType = "Rectilinear";
255
  }
256

257 258 259 260
  XdmfGridImpl * duplicate()
  {
    return new XdmfRectilinearGridImpl(mCoordinates);
  }
261

262
  std::vector<shared_ptr<XdmfArray> > mCoordinates;
263 264
};

265 266 267
shared_ptr<XdmfRectilinearGrid>
XdmfRectilinearGrid::New(const shared_ptr<XdmfArray> xCoordinates,
                         const shared_ptr<XdmfArray> yCoordinates)
268
{
269
  std::vector<shared_ptr<XdmfArray> > axesCoordinates;
270 271 272
  axesCoordinates.resize(2);
  axesCoordinates[0] = xCoordinates;
  axesCoordinates[1] = yCoordinates;
273
  shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
274
  return p;
275 276
}

277 278 279 280
shared_ptr<XdmfRectilinearGrid>
XdmfRectilinearGrid::New(const shared_ptr<XdmfArray> xCoordinates,
                         const shared_ptr<XdmfArray> yCoordinates,
                         const shared_ptr<XdmfArray> zCoordinates)
281
{
282
  std::vector<shared_ptr<XdmfArray> > axesCoordinates;
283 284 285 286
  axesCoordinates.resize(3);
  axesCoordinates[0] = xCoordinates;
  axesCoordinates[1] = yCoordinates;
  axesCoordinates[2] = zCoordinates;
287
  shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
288
  return p;
289 290
}

291 292
shared_ptr<XdmfRectilinearGrid>
XdmfRectilinearGrid::New(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates)
293
{
294
  shared_ptr<XdmfRectilinearGrid> p(new XdmfRectilinearGrid(axesCoordinates));
295
  return p;
296 297
}

298
XdmfRectilinearGrid::XdmfRectilinearGrid(const std::vector<shared_ptr<XdmfArray> > & axesCoordinates) :
299
  XdmfGrid(XdmfRectilinearGridImpl::XdmfGeometryRectilinear::New(this),
300
           XdmfRectilinearGridImpl::XdmfTopologyRectilinear::New(this))
301
{
302 303 304
  mImpl = new XdmfRectilinearGridImpl(axesCoordinates);
}

305 306 307 308 309 310 311
XdmfRectilinearGrid::XdmfRectilinearGrid(XdmfRectilinearGrid & refGrid):
  XdmfGrid(refGrid)
{
  mTopology = XdmfRectilinearGridImpl::XdmfTopologyRectilinear::New(this);
  mGeometry = XdmfRectilinearGridImpl::XdmfGeometryRectilinear::New(this);
}

312
XdmfRectilinearGrid::~XdmfRectilinearGrid()
313
{
314 315 316 317
  if (mImpl) {
    delete mImpl;
  }
  mImpl = NULL;
318 319
}

320
const std::string XdmfRectilinearGrid::ItemTag = "Grid";
321

322 323 324 325 326 327 328 329 330 331 332
void
XdmfRectilinearGrid::copyGrid(shared_ptr<XdmfGrid> sourceGrid)
{
  XdmfGrid::copyGrid(sourceGrid);
  if (shared_ptr<XdmfRectilinearGrid> classedGrid = shared_dynamic_cast<XdmfRectilinearGrid>(sourceGrid))
  {
    // Copy stucture from read grid to this grid
    this->setCoordinates(classedGrid->getCoordinates());
  }
}

333
shared_ptr<XdmfArray>
334
XdmfRectilinearGrid::getCoordinates(const unsigned int axisIndex)
335
{
336 337 338
  return boost::const_pointer_cast<XdmfArray>
    (static_cast<const XdmfRectilinearGrid &>
     (*this).getCoordinates(axisIndex));
339 340
}

341
shared_ptr<const XdmfArray>
342
XdmfRectilinearGrid::getCoordinates(const unsigned int axisIndex) const
343
{
344 345
  if(axisIndex < ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size()) {
    return ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates[axisIndex];
346
  }
347
  return shared_ptr<XdmfArray>();
348 349
}

350
std::vector<shared_ptr<XdmfArray> >
351
XdmfRectilinearGrid::getCoordinates()
352
{
353
  return static_cast<const XdmfRectilinearGrid &>(*this).getCoordinates();
354 355
}

356
const std::vector<shared_ptr<XdmfArray> >
357
XdmfRectilinearGrid::getCoordinates() const
358
{
359
  return ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates;
360 361
}

362
shared_ptr<XdmfArray>
363
XdmfRectilinearGrid::getDimensions()
364
{
365
  return boost::const_pointer_cast<XdmfArray>
366
    (static_cast<const XdmfRectilinearGrid &>(*this).getDimensions());
367 368
}

369
shared_ptr<const XdmfArray>
370
XdmfRectilinearGrid::getDimensions() const
371
{
372
  shared_ptr<XdmfArray> dimensions = XdmfArray::New();
373 374
  std::vector<shared_ptr<XdmfArray> > heldCoordinates =
    ((XdmfRectilinearGridImpl*)mImpl)->mCoordinates;
375
  dimensions->reserve(heldCoordinates.size());
376 377 378
  for (unsigned int i = 0; i < heldCoordinates.size(); ++i)
  {
    dimensions->pushBack(heldCoordinates[i]->getSize());
379 380
  }
  return dimensions;
381 382
}

383 384
void
XdmfRectilinearGrid::populateItem(const std::map<std::string, std::string> & itemProperties,
385
                                  const std::vector<shared_ptr<XdmfItem> > & childItems,
386
                                  const XdmfCoreReader * const reader)
387
{
388 389
  XdmfGrid::populateItem(itemProperties, childItems, reader);

390
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
391 392 393
        childItems.begin();
      iter != childItems.end();
      ++iter) {
394 395
    if(shared_ptr<XdmfRectilinearGrid> rectilinearGrid =
       shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
396 397 398 399 400 401
      if(rectilinearGrid->getGeometry()->getType()->getDimensions() > 0) {
        this->setCoordinates(rectilinearGrid->getCoordinates());
        break;
      }
    }
  }
402 403
}

404 405 406 407 408 409 410 411 412 413
void
XdmfRectilinearGrid::read()
{
  if (mGridController)
  {
    if (shared_ptr<XdmfRectilinearGrid> grid = shared_dynamic_cast<XdmfRectilinearGrid>(mGridController->read()))
    { 
      // Copy stucture from read grid to this grid
      copyGrid(grid);
    }
414
    else if (shared_dynamic_cast<XdmfGrid>(mGridController->read()))
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    {
      XdmfError::message(XdmfError::FATAL, "Error: Grid Type Mismatch");
    }
    else
    {
      XdmfError::message(XdmfError::FATAL, "Error: Invalid Grid Reference");
    }
  }
}

void
XdmfRectilinearGrid::release()
{
  XdmfGrid::release();
  ((XdmfRectilinearGridImpl*)mImpl)->mCoordinates.clear();
}

432 433
void
XdmfRectilinearGrid::setCoordinates(const unsigned int axisIndex,
434
                                    const shared_ptr<XdmfArray> axisCoordinates)
435
{
436 437
  if(((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size() <= axisIndex) {
    ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.reserve(axisIndex + 1);
438
    unsigned int numArraysToInsert =
439
      axisIndex - ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.size() + 1;
440
    for(unsigned int i=0; i<numArraysToInsert; ++i) {
441
      ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates.push_back(XdmfArray::New());
442 443
    }
  }
444
  ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates[axisIndex] = axisCoordinates;
445
  this->setIsChanged(true);
446 447
}

448
void
449
XdmfRectilinearGrid::setCoordinates(const std::vector<shared_ptr<XdmfArray> > axesCoordinates)
450
{
451
  ((XdmfRectilinearGridImpl *)mImpl)->mCoordinates = axesCoordinates;
452 453 454 455 456 457 458
  this->setIsChanged(true);
}

// C Wrappers

XDMFRECTILINEARGRID * XdmfRectilinearGridNew(XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl)
{
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485
  try
  {
    std::vector<shared_ptr<XdmfArray> > holderVector;
    for (unsigned int i = 0; i < numCoordinates; ++i) {
      if (passControl) {
        holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
      }
      else {
        holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
      }
    }
    shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(holderVector);
    return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
  }
  catch (...)
  {
    std::vector<shared_ptr<XdmfArray> > holderVector;
    for (unsigned int i = 0; i < numCoordinates; ++i) {
      if (passControl) {
        holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
      }
      else {
        holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
      }
    }
    shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(holderVector);
    return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
486 487 488 489 490
  }
}

XDMFRECTILINEARGRID * XdmfRectilinearGridNew2D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, int passControl)
{
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
  try
  {
    if (passControl) {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
    else {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
  }
  catch (...)
  {
    if (passControl) {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
    else {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
  }
517 518 519 520
}

XDMFRECTILINEARGRID * XdmfRectilinearGridNew3D(XDMFARRAY * xCoordinates, XDMFARRAY * yCoordinates, XDMFARRAY * zCoordinates, int passControl)
{
521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550
  try
  {
    if (passControl) {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)zCoordinates));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
    else {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)zCoordinates, XdmfNullDeleter()));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
  }
  catch (...)
  {
    if (passControl) {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)zCoordinates));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
    else {
      shared_ptr<XdmfRectilinearGrid> generatedGrid = XdmfRectilinearGrid::New(shared_ptr<XdmfArray>((XdmfArray *)xCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)yCoordinates, XdmfNullDeleter()),
                                                                               shared_ptr<XdmfArray>((XdmfArray *)zCoordinates, XdmfNullDeleter()));
      return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(new XdmfRectilinearGrid(*generatedGrid.get()))));
    }
  }
551 552 553 554 555
}

XDMFARRAY * XdmfRectilinearGridGetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int axisIndex, int * status)
{
  XDMF_ERROR_WRAP_START(status)
556 557 558
  XdmfItem * classedPointer = (XdmfItem *)grid;
  XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
  return (XDMFARRAY *)((void *)(gridPointer->getCoordinates(axisIndex).get()));
559 560 561 562 563 564 565
  XDMF_ERROR_WRAP_END(status)
  return NULL;
}

XDMFARRAY ** XdmfRectilinearGridGetCoordinates(XDMFRECTILINEARGRID * grid, int * status)
{
  XDMF_ERROR_WRAP_START(status)
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
  try
  {
    XDMFARRAY ** returnPointer;
    XdmfItem * classedPointer = (XdmfItem *)grid;
    XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
    std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
    returnPointer = new XDMFARRAY *[heldCoordinates.size()]();
    for (unsigned int i = 0; i < heldCoordinates.size(); ++i) {
      XDMFARRAY * insertArray = (XDMFARRAY *)((void *)(new XdmfArray(*(heldCoordinates[i].get()))));
      returnPointer[i] = insertArray;
    }
    return returnPointer;
  }
  catch (...)
  {
    XDMFARRAY ** returnPointer;
    XdmfItem * classedPointer = (XdmfItem *)grid;
    XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
    std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
    returnPointer = new XDMFARRAY *[heldCoordinates.size()]();
    for (unsigned int i = 0; i < heldCoordinates.size(); ++i) {
      XDMFARRAY * insertArray = (XDMFARRAY *)((void *)(new XdmfArray(*(heldCoordinates[i].get()))));
      returnPointer[i] = insertArray;
    }
    return returnPointer;
591 592 593
  }
  XDMF_ERROR_WRAP_END(status)
  return NULL;
594
}
595 596 597 598

int XdmfRectilinearGridGetNumberCoordinates(XDMFRECTILINEARGRID * grid, int * status)
{
  XDMF_ERROR_WRAP_START(status)
599 600 601 602
  XdmfItem * classedPointer = (XdmfItem *)grid;
  XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
  std::vector<shared_ptr<XdmfArray> > heldCoordinates = gridPointer->getCoordinates();
  return heldCoordinates.size();
603 604 605 606 607 608 609
  XDMF_ERROR_WRAP_END(status)
  return 0;
}

XDMFARRAY * XdmfRectilinearGridGetDimensions(XDMFRECTILINEARGRID * grid, int * status)
{
  XDMF_ERROR_WRAP_START(status)
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
  try
  {
    XdmfArray * copyArray;
    shared_ptr<XdmfArray> returnDimensions;
    XdmfItem * classedPointer = (XdmfItem *)grid;
    XdmfGrid * classedGrid = dynamic_cast<XdmfGrid *>(classedPointer);
    XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedGrid);
    XDMFARRAY * returnArray;
    returnDimensions = gridPointer->getDimensions();
    copyArray = new XdmfArray(*(returnDimensions.get()));
    void * copyVoid = (void *)copyArray;
    returnArray = (XDMFARRAY *) copyVoid;
    returnDimensions.reset();
    return returnArray;
  }
  catch (...)
  {
    XdmfArray * copyArray;
    shared_ptr<XdmfArray> returnDimensions;
    XdmfItem * classedPointer = (XdmfItem *)grid;
    XdmfGrid * classedGrid = dynamic_cast<XdmfGrid *>(classedPointer);
    XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedGrid);
    XDMFARRAY * returnArray;
    returnDimensions = gridPointer->getDimensions();
    copyArray = new XdmfArray(*(returnDimensions.get()));
    void * copyVoid = (void *)copyArray;
    returnArray = (XDMFARRAY *) copyVoid;
    returnDimensions.reset();
    return returnArray;
  }
640 641 642 643 644 645 646
  XDMF_ERROR_WRAP_END(status)
  return NULL;
}

void XdmfRectilinearGridSetCoordinates(XDMFRECTILINEARGRID * grid, XDMFARRAY ** axesCoordinates, unsigned int numCoordinates, int passControl, int * status)
{
  XDMF_ERROR_WRAP_START(status)
647 648
  XdmfItem * classedPointer = (XdmfItem *)grid;
  XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
649 650
  std::vector<shared_ptr<XdmfArray> > holderVector;
  for (unsigned int i = 0; i < numCoordinates; ++i) {
651 652 653 654 655 656
    if (passControl) {
      holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i]));
    }
    else {
      holderVector.push_back(shared_ptr<XdmfArray>((XdmfArray *)axesCoordinates[i], XdmfNullDeleter()));
    }
657
  }
658
  gridPointer->setCoordinates(holderVector);
659 660 661 662 663 664
  XDMF_ERROR_WRAP_END(status)
}

void XdmfRectilinearGridSetCoordinatesByIndex(XDMFRECTILINEARGRID * grid, unsigned int index, XDMFARRAY * coordinates, int passControl, int * status)
{
  XDMF_ERROR_WRAP_START(status)
665 666 667 668 669 670 671 672
  XdmfItem * classedPointer = (XdmfItem *)grid;
  XdmfRectilinearGrid * gridPointer = dynamic_cast<XdmfRectilinearGrid *>(classedPointer);
  if (passControl) {
    gridPointer->setCoordinates(index, shared_ptr<XdmfArray>((XdmfArray *)coordinates));
  }
  else {
    gridPointer->setCoordinates(index, shared_ptr<XdmfArray>((XdmfArray *)coordinates, XdmfNullDeleter()));
  }
673 674 675 676 677
  XDMF_ERROR_WRAP_END(status)
}

XDMF_ITEM_C_CHILD_WRAPPER(XdmfRectilinearGrid, XDMFRECTILINEARGRID)
XDMF_GRID_C_CHILD_WRAPPER(XdmfRectilinearGrid, XDMFRECTILINEARGRID)