XdmfDomain.cpp 17.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 : XdmfDomain.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.                                                 */
/*                                                                           */
/*****************************************************************************/
Kenneth Leiter's avatar
Kenneth Leiter committed
23 24

#include "XdmfDomain.hpp"
25
#include "XdmfCurvilinearGrid.hpp"
26
#include "XdmfGraph.hpp"
27
#include "XdmfGridCollection.hpp"
28 29 30
#include "XdmfRectilinearGrid.hpp"
#include "XdmfRegularGrid.hpp"
#include "XdmfUnstructuredGrid.hpp"
Kenneth Leiter's avatar
Kenneth Leiter committed
31

32 33 34 35 36 37
#ifdef XDMF_BUILD_DSM
  #include "XdmfDSMBuffer.hpp"
  #include "XdmfDSMDriver.hpp"
  #include "XdmfDSMDescription.hpp"
#endif

38 39 40 41 42 43 44 45
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfGridCollection,
                             GridCollection,
                             Name)
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfCurvilinearGrid,
                             CurvilinearGrid,
                             Name)
46 47 48 49
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfGraph,
                             Graph,
                             Name)
50 51 52 53 54 55 56 57 58 59 60 61
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfRectilinearGrid,
                             RectilinearGrid,
                             Name)
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfRegularGrid,
                             RegularGrid,
                             Name)
XDMF_CHILDREN_IMPLEMENTATION(XdmfDomain,
                             XdmfUnstructuredGrid,
                             UnstructuredGrid,
                             Name)
62

63
shared_ptr<XdmfDomain>
64
XdmfDomain::New()
65
{
66
  shared_ptr<XdmfDomain> p(new XdmfDomain());
67
  return p;
68 69
}

Kenneth Leiter's avatar
Kenneth Leiter committed
70 71 72 73
XdmfDomain::XdmfDomain()
{
}

74 75 76 77 78 79 80 81 82 83 84
XdmfDomain::XdmfDomain(XdmfDomain & refDomain) :
  XdmfItem(refDomain),
  mGridCollections(refDomain.mGridCollections),
  mGraphs(refDomain.mGraphs),
  mCurvilinearGrids(refDomain.mCurvilinearGrids),
  mRectilinearGrids(refDomain.mRectilinearGrids),
  mRegularGrids(refDomain.mRegularGrids),
  mUnstructuredGrids(refDomain.mUnstructuredGrids)
{
}

Kenneth Leiter's avatar
Kenneth Leiter committed
85 86 87 88
XdmfDomain::~XdmfDomain()
{
}

89
const std::string XdmfDomain::ItemTag = "Domain";
90

91 92
std::map<std::string, std::string>
XdmfDomain::getItemProperties() const
93
{
94 95
  std::map<std::string, std::string> domainProperties;
  return domainProperties;
96 97
}

98 99
std::string
XdmfDomain::getItemTag() const
100
{
101
  return ItemTag;
102 103
}

104 105
void
XdmfDomain::populateItem(const std::map<std::string, std::string> & itemProperties,
106
                         const std::vector<shared_ptr<XdmfItem> > & childItems,
107
                         const XdmfCoreReader * const reader)
108
{
109
  XdmfItem::populateItem(itemProperties, childItems, reader);
110
  for(std::vector<shared_ptr<XdmfItem> >::const_iterator iter =
111 112 113
        childItems.begin();
      iter != childItems.end();
      ++iter) {
114 115
    if(shared_ptr<XdmfGridCollection> gridCollection =
       shared_dynamic_cast<XdmfGridCollection>(*iter)) {
116 117
      this->insert(gridCollection);
    }
118
    else if(shared_ptr<XdmfCurvilinearGrid> curvilinear_grid =
119
            shared_dynamic_cast<XdmfCurvilinearGrid>(*iter)) {
120
      this->insert(curvilinear_grid);
121
    }
122 123 124 125
    else if(shared_ptr<XdmfGraph> graph =
            shared_dynamic_cast<XdmfGraph>(*iter)) {
      this->insert(graph);
    }
126
    else if(shared_ptr<XdmfRectilinearGrid> rect_grid =
127
            shared_dynamic_cast<XdmfRectilinearGrid>(*iter)) {
128
      this->insert(rect_grid);
129
    }
130
    else if(shared_ptr<XdmfRegularGrid> regular_grid =
131
            shared_dynamic_cast<XdmfRegularGrid>(*iter)) {
132
      this->insert(regular_grid);
133
    }
134
    else if(shared_ptr<XdmfUnstructuredGrid> unstructured_grid =
135
            shared_dynamic_cast<XdmfUnstructuredGrid>(*iter)) {
136
      this->insert(unstructured_grid);
137 138
    }
  }
139 140
}

141
void
142
XdmfDomain::traverse(const shared_ptr<XdmfBaseVisitor> visitor)
143
{
144 145 146 147 148 149 150 151 152 153 154 155 156 157
#ifdef XDMF_BUILD_DSM
  // Traverse Data Descriptions before anything
  XdmfDSMBuffer * dsmBuffer = (XdmfDSMBuffer *)xdmf_dsm_get_manager();

  if (dsmBuffer)
  {
    shared_ptr<XdmfDSMDescription> dsmDescription;
    dsmDescription = XdmfDSMDescription::New();
    dsmDescription->setPortDescription(dsmBuffer->GetComm()->GetDsmPortName());

    dsmDescription->accept(visitor);
  }
#endif

158
  XdmfItem::traverse(visitor);
159 160 161
  for (unsigned int i = 0; i < mGridCollections.size(); ++i)
  {
    mGridCollections[i]->accept(visitor);
162
  }
163 164 165
  for (unsigned int i = 0; i < mCurvilinearGrids.size(); ++i)
  {
    mCurvilinearGrids[i]->accept(visitor);
166
  }
167 168 169
  for (unsigned int i = 0; i < mGraphs.size(); ++i)
  {
    mGraphs[i]->accept(visitor);
170
  }
171 172 173
  for (unsigned int i = 0; i < mRectilinearGrids.size(); ++i)
  {
    mRectilinearGrids[i]->accept(visitor);
174
  }
175 176 177
  for (unsigned int i = 0; i < mRegularGrids.size(); ++i)
  {
    mRegularGrids[i]->accept(visitor);
178
  }
179 180 181 182 183 184 185 186 187 188
  for (unsigned int i = 0; i < mUnstructuredGrids.size(); ++i)
  {
    mUnstructuredGrids[i]->accept(visitor);
  }
}

// C Wrappers

XDMFDOMAIN * XdmfDomainNew()
{
189 190 191 192 193 194 195 196 197 198
  try
  {
    shared_ptr<XdmfDomain> generatedDomain = XdmfDomain::New();
    return (XDMFDOMAIN *)((void *)((XdmfItem *)(new XdmfDomain(*generatedDomain.get()))));
  }
  catch (...)
  {
    shared_ptr<XdmfDomain> generatedDomain = XdmfDomain::New();
    return (XDMFDOMAIN *)((void *)((XdmfItem *)(new XdmfDomain(*generatedDomain.get()))));
  }
199 200 201 202
}

XDMFGRIDCOLLECTION * XdmfDomainGetGridCollection(XDMFDOMAIN * domain, unsigned int index)
{
203 204 205
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(domainPointer->getGridCollection(index).get())));
206 207 208 209
}

XDMFGRIDCOLLECTION * XdmfDomainGetGridCollectionByName(XDMFDOMAIN * domain, char * Name)
{
210 211 212
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFGRIDCOLLECTION *)((void *)((XdmfItem *)(domainPointer->getGridCollection(Name).get())));
213 214 215 216
}

unsigned int XdmfDomainGetNumberGridCollections(XDMFDOMAIN * domain)
{
217 218 219
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberGridCollections();
220 221 222 223
}

void XdmfDomainInsertGridCollection(XDMFDOMAIN * domain, XDMFGRIDCOLLECTION * GridCollection, int passControl)
{
224 225 226 227 228 229 230 231
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfGridCollection>((XdmfGridCollection *)GridCollection));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfGridCollection>((XdmfGridCollection *)GridCollection, XdmfNullDeleter()));
  }
232
}
233 234 235

void XdmfDomainRemoveGridCollection(XDMFDOMAIN * domain, unsigned int index)
{
236 237 238
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeGridCollection(index);
239 240 241 242
}

void XdmfDomainRemoveGridCollectionByName(XDMFDOMAIN * domain, char * Name)
{
243 244 245
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeGridCollection(Name);
246 247 248 249
}

XDMFGRAPH * XdmfDomainGetGraph(XDMFDOMAIN * domain, unsigned int index)
{
250 251 252
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFGRAPH *)((void *)(domainPointer->getGraph(index).get()));
253 254 255 256
}

XDMFGRAPH * XdmfDomainGetGraphByName(XDMFDOMAIN * domain, char * Name)
{
257 258 259
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFGRAPH *)((void *)(domainPointer->getGraph(Name).get()));
260 261 262 263
}

unsigned int XdmfDomainGetNumberGraphs(XDMFDOMAIN * domain)
{
264 265 266
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberGraphs();
267 268 269 270
}

void XdmfDomainInsertGraph(XDMFDOMAIN * domain, XDMFGRAPH * Graph, int passControl)
{
271 272 273 274 275 276 277 278
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfGraph>((XdmfGraph *)Graph));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfGraph>((XdmfGraph *)Graph, XdmfNullDeleter()));
  }
279 280 281 282
}

void XdmfDomainRemoveGraph(XDMFDOMAIN * domain, unsigned int index)
{
283 284 285
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeGraph(index);
286 287 288 289
}

void XdmfDomainRemoveGraphByName(XDMFDOMAIN * domain, char * Name)
{
290 291 292
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeGraph(Name);
293 294 295 296
}

XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index)
{
297 298 299
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getCurvilinearGrid(index).get())));
300 301 302 303
}

XDMFCURVILINEARGRID * XdmfDomainGetCurvilinearGridByName(XDMFDOMAIN * domain, char * Name)
{
304 305 306
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFCURVILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getCurvilinearGrid(Name).get())));
307 308 309 310
}

unsigned int XdmfDomainGetNumberCurvilinearGrids(XDMFDOMAIN * domain)
{
311 312 313
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberCurvilinearGrids();
314 315 316 317
}

void XdmfDomainInsertCurvilinearGrid(XDMFDOMAIN * domain, XDMFCURVILINEARGRID * CurvilinearGrid, int passControl)
{
318 319 320 321 322 323 324 325
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfCurvilinearGrid>((XdmfCurvilinearGrid *)CurvilinearGrid));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfCurvilinearGrid>((XdmfCurvilinearGrid *)CurvilinearGrid, XdmfNullDeleter()));
  }
326 327 328 329
}

void XdmfDomainRemoveCurvilinearGrid(XDMFDOMAIN * domain, unsigned int index)
{
330 331 332
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeCurvilinearGrid(index);
333 334 335 336
}

void XdmfDomainRemoveCurvilinearGridByName(XDMFDOMAIN * domain, char * Name)
{
337 338 339
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeCurvilinearGrid(Name);
340 341 342 343
}

XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGrid(XDMFDOMAIN * domain, unsigned int index)
{
344 345 346
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getRectilinearGrid(index).get())));
347 348 349 350
}

XDMFRECTILINEARGRID * XdmfDomainGetRectilinearGridByName(XDMFDOMAIN * domain, char * Name)
{
351 352 353
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFRECTILINEARGRID *)((void *)((XdmfItem *)(domainPointer->getRectilinearGrid(Name).get())));
354 355 356 357
}

unsigned int XdmfDomainGetNumberRectilinearGrids(XDMFDOMAIN * domain)
{
358 359 360
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberRectilinearGrids();
361 362 363 364
}

void XdmfDomainInsertRectilinearGrid(XDMFDOMAIN * domain, XDMFRECTILINEARGRID * RectilinearGrid, int passControl)
{
365 366 367 368 369 370 371 372
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfRectilinearGrid>((XdmfRectilinearGrid *)RectilinearGrid));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfRectilinearGrid>((XdmfRectilinearGrid *)RectilinearGrid, XdmfNullDeleter()));
  }
373 374 375 376
}

void XdmfDomainRemoveRectilinearGrid(XDMFDOMAIN * domain, unsigned int index)
{
377 378 379
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeRectilinearGrid(index);
380 381 382 383
}

void XdmfDomainRemoveRectilinearGridByName(XDMFDOMAIN * domain, char * Name)
{
384 385 386
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeRectilinearGrid(Name);
387 388 389 390
}

XDMFREGULARGRID * XdmfDomainGetRegularGrid(XDMFDOMAIN * domain, unsigned int index)
{
391 392 393
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFREGULARGRID *)((void *)((XdmfItem *)(domainPointer->getRegularGrid(index).get())));
394 395 396 397
}

XDMFREGULARGRID * XdmfDomainGetRegularGridByName(XDMFDOMAIN * domain, char * Name)
{
398 399 400
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFREGULARGRID *)((void *)((XdmfItem *)(domainPointer->getRegularGrid(Name).get())));
401 402 403 404
}

unsigned int XdmfDomainGetNumberRegularGrids(XDMFDOMAIN * domain)
{
405 406 407
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberRegularGrids();
408 409 410 411
}

void XdmfDomainInsertRegularGrid(XDMFDOMAIN * domain, XDMFREGULARGRID * RegularGrid, int passControl)
{
412 413 414 415 416 417 418 419
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfRegularGrid>((XdmfRegularGrid *)RegularGrid));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfRegularGrid>((XdmfRegularGrid *)RegularGrid, XdmfNullDeleter()));
  }
420 421 422 423
}

void XdmfDomainRemoveRegularGrid(XDMFDOMAIN * domain, unsigned int index)
{
424 425 426
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeRegularGrid(index);
427 428 429 430
}

void XdmfDomainRemoveRegularGridByName(XDMFDOMAIN * domain, char * Name)
{
431 432 433
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeRegularGrid(Name);
434 435 436 437
}

XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index)
{
438 439 440
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(domainPointer->getUnstructuredGrid(index).get())));
441 442 443 444
}

XDMFUNSTRUCTUREDGRID * XdmfDomainGetUnstructuredGridByName(XDMFDOMAIN * domain, char * Name)
{
445 446 447
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return (XDMFUNSTRUCTUREDGRID *)((void *)((XdmfItem *)(domainPointer->getUnstructuredGrid(Name).get())));
448 449 450 451
}

unsigned int XdmfDomainGetNumberUnstructuredGrids(XDMFDOMAIN * domain)
{
452 453 454
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  return domainPointer->getNumberUnstructuredGrids();
455 456 457 458
}

void XdmfDomainInsertUnstructuredGrid(XDMFDOMAIN * domain, XDMFUNSTRUCTUREDGRID * UnstructuredGrid, int passControl)
{
459 460 461 462 463 464 465 466
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  if (passControl) {
    domainPointer->insert(shared_ptr<XdmfUnstructuredGrid>((XdmfUnstructuredGrid *)UnstructuredGrid));
  }
  else {
    domainPointer->insert(shared_ptr<XdmfUnstructuredGrid>((XdmfUnstructuredGrid *)UnstructuredGrid, XdmfNullDeleter()));
  }
467 468 469 470
}

void XdmfDomainRemoveUnstructuredGrid(XDMFDOMAIN * domain, unsigned int index)
{
471 472 473
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeUnstructuredGrid(index);
474 475 476 477
}

void XdmfDomainRemoveUnstructuredGridByName(XDMFDOMAIN * domain, char * Name)
{
478 479 480
  XdmfItem * classedPointer = (XdmfItem *)domain;
  XdmfDomain * domainPointer = dynamic_cast<XdmfDomain *>(classedPointer);
  domainPointer->removeUnstructuredGrid(Name);
481 482 483
}

XDMF_ITEM_C_CHILD_WRAPPER(XdmfDomain, XDMFDOMAIN)