avtM3DC1FileFormat.C 72.2 KB
Newer Older
1 2
/*****************************************************************************
*
brugger's avatar
 
brugger committed
3
* Copyright (c) 2000 - 2011, Lawrence Livermore National Security, LLC
4
* Produced at the Lawrence Livermore National Laboratory
brugger's avatar
 
brugger committed
5
* LLNL-CODE-442911
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
* All rights reserved.
*
* This file is  part of VisIt. For  details, see https://visit.llnl.gov/.  The
* full copyright notice is contained in the file COPYRIGHT located at the root
* of the VisIt distribution or at http://www.llnl.gov/visit/copyright.html.
*
* Redistribution  and  use  in  source  and  binary  forms,  with  or  without
* modification, are permitted provided that the following conditions are met:
*
*  - Redistributions of  source code must  retain the above  copyright notice,
*    this list of conditions and the disclaimer below.
*  - Redistributions in binary form must reproduce the above copyright notice,
*    this  list of  conditions  and  the  disclaimer (as noted below)  in  the
*    documentation and/or other materials provided with the distribution.
*  - Neither the name of  the LLNS/LLNL nor the names of  its contributors may
*    be used to endorse or promote products derived from this software without
*    specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT  HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR  IMPLIED WARRANTIES, INCLUDING,  BUT NOT  LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND  FITNESS FOR A PARTICULAR  PURPOSE
* ARE  DISCLAIMED. IN  NO EVENT  SHALL LAWRENCE  LIVERMORE NATIONAL  SECURITY,
* LLC, THE  U.S.  DEPARTMENT OF  ENERGY  OR  CONTRIBUTORS BE  LIABLE  FOR  ANY
* DIRECT,  INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,  OR   CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT  LIMITED TO, PROCUREMENT OF  SUBSTITUTE GOODS OR
* SERVICES; LOSS OF  USE, DATA, OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER
* CAUSED  AND  ON  ANY  THEORY  OF  LIABILITY,  WHETHER  IN  CONTRACT,  STRICT
* LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)  ARISING IN ANY  WAY
* OUT OF THE  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*
*****************************************************************************/

// ************************************************************************* //
//                            avtM3DC1FileFormat.C                           //
// ************************************************************************* //

#include <avtM3DC1FileFormat.h>
allens's avatar
allens committed
44
#include <avtM3DC1Field.h>
45 46 47 48 49 50 51 52

#include <string>

#include <vtkIntArray.h>
#include <vtkFloatArray.h>
#include <vtkDoubleArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkTriangle.h>
allens's avatar
allens committed
53
#include <vtkWedge.h>
54 55 56 57

#include <avtDatabaseMetaData.h>

#include <DBOptionsAttributes.h>
allens's avatar
allens committed
58 59
#include <avtLogicalSelection.h>
//#include <avtSpatialBoxSelection.h>
60 61
#include <Expression.h>

62 63
#include <avtCallback.h>
#include <NonCompliantException.h>
64
#include <InvalidFilesException.h>
allens's avatar
allens committed
65
#include <InvalidVariableException.h>
66 67
#include <DebugStream.h>

68 69
#include <visit-hdf5.h>

70 71 72

using namespace std;

allens's avatar
allens committed
73 74 75 76 77
#define ELEMENT_SIZE_2D 7
#define SCALAR_SIZE_2D 20

#define ELEMENT_SIZE_3D 9
#define SCALAR_SIZE_3D 80
78 79 80 81 82 83 84 85 86 87 88 89 90 91


// ****************************************************************************
//  Method: avtM3DC1FileFormat constructor
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

avtM3DC1FileFormat::avtM3DC1FileFormat(const char *filename,
                                       DBOptionsAttributes *readOpts)
  : avtMTSDFileFormat(&filename, 1),
    m_filename(filename),
allens's avatar
allens committed
92
    m_refinement(2), m_dataLocation(AVT_NODECENT),
allens's avatar
allens committed
93
    processDataSelections(false), haveReadWholeData(true)
94 95 96
{
    if (readOpts != NULL) {
      for (int i=0; i<readOpts->GetNumberOfOptions(); ++i) {
allens's avatar
allens committed
97
        if (readOpts->GetName(i) == "Mesh refinement")
allens's avatar
allens committed
98 99
          m_refinement = readOpts->GetEnum("Mesh refinement");
        else if (readOpts->GetName(i) == "Linear mesh data location") 
100
        {
allens's avatar
allens committed
101
          int dataLocation = readOpts->GetEnum("Linear mesh data location");
102 103 104 105 106 107
          
          if( dataLocation == 0 )
            m_dataLocation = AVT_NODECENT;
          else if( dataLocation == 1 )
            m_dataLocation = AVT_ZONECENT;
        }
allens's avatar
allens committed
108 109 110
        else if (readOpts->GetName(i) == "Process Data Selections in the Reader")
          processDataSelections =
            readOpts->GetBool("Process Data Selections in the Reader");
111 112 113
      }
    }

allens's avatar
allens committed
114 115
    if( m_refinement < 0 )      m_refinement = 0;
    else if( m_refinement > 5 ) m_refinement = 5;
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

    LoadFile();
}


// ****************************************************************************
//  Method: avtEMSTDFileFormat::GetNTimesteps
//
//  Purpose:
//      Tells the rest of the code how many timesteps there are in this file.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

int
avtM3DC1FileFormat::GetNTimesteps(void)
{
allens's avatar
allens committed
135
    return m_times.size();
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
}


// ****************************************************************************
//  Method: avtM3DC1FileFormat::FreeUpResources
//
//  Purpose:
//      When VisIt is done focusing on a particular timestep, it asks that
//      timestep to free up any resources (memory, file descriptors) that
//      it has associated with it.  This method is the mechanism for doing
//      that.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

void
avtM3DC1FileFormat::FreeUpResources(void)
{
    H5Fclose( m_fileID );
}


allens's avatar
allens committed
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 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 290 291
// ****************************************************************************
//  Method: avtVsFileFormat::CanCacheVariable
//
//  Purpose:
//      To truly exercise the VS file format, we can't have VisIt caching
//      chunks of mesh and variables above the plugin.
//      
//  Programmer: Mark C. Miller 
//  Creation:   September 20, 2004 
//
// ****************************************************************************

bool
avtM3DC1FileFormat::CanCacheVariable(const char *var)
{
    // If processing the selections turn caching off.
    return !processDataSelections;

//    return haveReadWholeData;
}


// ****************************************************************************
//  Method: avtVsFileFormat::RegisterDataSelections
//
//  Purpose:
//      The Vs format can exploit some data selections so get them. 
//      
//  Programmer: Allen Sanderson
//  Creation:   March 4, 2011
//
// ****************************************************************************

void
avtM3DC1FileFormat::RegisterDataSelections(const std::vector<avtDataSelection_p> &sels,
                                        std::vector<bool> *selectionsApplied)
{
  selList     = sels;
  selsApplied = selectionsApplied;
}


// ****************************************************************************
//  Method: avtVsFileFormat::ProcessDataSelections
//
//  Purpose:
//      The Vs format can exploit some data selections so process them. 
//      
//  Programmer: Allen Sanderson
//  Creation:   March 4, 2011
//
// ****************************************************************************

bool
avtM3DC1FileFormat::ProcessDataSelections(int *mins, int *maxs, int *strides)
{
    bool retval = false;

    if( !processDataSelections )
      return retval;

    avtLogicalSelection composedSel;

    for (int i = 0; i < selList.size(); i++)
    {
        if (std::string(selList[i]->GetType()) == "Logical Data Selection")
        {
            avtLogicalSelection *sel = (avtLogicalSelection *) *(selList[i]);

            // overrwrite method-scope arrays with the new indexing
            composedSel.Compose(*sel);
            (*selsApplied)[i] = true;
            retval = true;
        }

        // Cannot handle avtSpatialBoxSelection without knowing the mesh.

//         else if (std::string(selList[i]->GetType()) == "Spatial Box Data Selection")
//         {
//             avtSpatialBoxSelection *sel =
//               (avtSpatialBoxSelection *) *(Sellist[i]);

//             double dmins[3], dmaxs[3];
//             sel->GetMins(dmins);
//             sel->GetMaxs(dmaxs);
//             avtSpatialBoxSelection::InclusionMode imode =
//                 sel->GetInclusionMode();

//             // we won't handle clipping of zones here
//             if ((imode != avtSpatialBoxSelection::Whole) &&
//                 (imode != avtSpatialBoxSelection::Partial))
//             {
//                 (*selsApplied)[i] = false;
//                 continue;
//             }

//             int imins[3], imaxs[3];
//             for (int j = 0; j < 3; j++)
//             {
//                 int imin = (int) dmins[j];
//                 if (((double) imin < dmins[j]) &&
//                     (imode == avtSpatialBoxSelection::Whole))
//                     imin++;
                
//                 int imax = (int) dmaxs[j];
//                 if (((double) imax < dmaxs[j]) &&
//                     (imode == avtSpatialBoxSelection::Partial))
//                     imax++;

//                 imins[j] = imin;
//                 imaxs[j] = imax;
//             }

//             avtLogicalSelection newSel;
//             newSel.SetStarts(imins);
//             newSel.SetStops(imaxs);

//             composedSel.Compose(newSel);
//             (*selsApplied)[i] = true;
//             retval = true;
//         }
        else
        {
            // indicate we won't handle this selection
            (*selsApplied)[i] = false;
        }
    }

    composedSel.GetStarts(mins);
    composedSel.GetStops(maxs);
    composedSel.GetStrides(strides);

292
    // If the user is a dumb ass and selects a dimension lower than
allens's avatar
allens committed
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
    // the actual dimension the min, max, and stride will be zero. So
    // fix it to be the full bounds and a stride of 1.
    for (int i = 0; i < 3; i++)
    {
      if( strides[i] == 0 )
      {
        mins[i] = 0;
        maxs[i] = -1;
        strides[i] = 1;
      }
    }

    return retval;
}


309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
// ****************************************************************************
//  Method: avtM3DC1FileFormat::PopulateDatabaseMetaData
//
//  Purpose:
//      This database meta-data object is like a table of contents for the
//      file.  By populating it, you are telling the rest of VisIt what
//      information it can request from you.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

void
avtM3DC1FileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md,
                                             int timeState)
{
    avtMeshMetaData *mmd;
allens's avatar
allens committed
327
    avtMeshType meshType = AVT_UNSTRUCTURED_MESH;
328
    int nblocks = 1;
329 330 331 332 333 334
    int block_origin = 0;
    int cell_origin = 0;
    int group_origin = 0;
    int spatial_dimension = 3;
    int topological_dimension = 3;
    double *extents = NULL;
allens's avatar
allens committed
335
    int bounds[3] = {nelms, 0, 0};
336 337 338

    char level[4];

allens's avatar
allens committed
339
    if( m_refinement != 0 )
340
    {
allens's avatar
allens committed
341 342
      sprintf( level, "_%d", m_refinement );
    }
343
    else
344
      level[0] = '\0';
345 346 347


    // Original meshes for the user to see.
allens's avatar
allens committed
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
    mmd = new avtMeshMetaData("equilibrium/mesh",
                              nblocks, block_origin,
                              cell_origin, group_origin,
                              spatial_dimension, topological_dimension,
                              meshType);

    mmd->SetBounds( bounds );
    mmd->SetNumberCells( nelms );
    md->Add(mmd);

    mmd = new avtMeshMetaData("mesh",
                              nblocks, block_origin,
                              cell_origin, group_origin,
                              spatial_dimension, topological_dimension,
                              meshType);

    mmd->SetBounds( bounds );
    mmd->SetNumberCells( nelms );
    md->Add(mmd);

368 369 370 371 372 373 374 375 376 377 378 379
    // Populate the scalar field vars that will be interpolate onto a
    // refined mesh.
    for ( int i = 0; i < m_fieldVarNames.size(); ++i )
    {
      string varname = "equilibrium/" + m_fieldVarNames[i];
      string meshname = string("equilibrium/mesh") + string(level);
      AddScalarVarToMetaData( md, varname, meshname, m_dataLocation );

      meshname = string("mesh") + string(level);
      AddScalarVarToMetaData( md, m_fieldVarNames[i], meshname, m_dataLocation );
    }

380 381 382 383 384 385 386 387 388 389 390
    // For now the mesh is the same mesh as the original mesh because
    // of needing it for the integration.
    AddVectorVarToMetaData( md, "B_C1_Elements",
                            string("mesh"),
                            AVT_ZONECENT, 3);
    
    // Interpolated on to a mesh for visualization only.
    AddVectorVarToMetaData( md, "B_Interpolated",
                            string("mesh") + string(level),
                            m_dataLocation, 3 );
    
391
    // Hidden refined meshes for working with the interpolated data
allens's avatar
allens committed
392
    if( m_refinement )
393
    {
allens's avatar
allens committed
394 395
      int nLevels = m_refinement + 1;

allens's avatar
allens committed
396
      nblocks = nelms * nLevels * nLevels;
397 398 399 400 401

      mmd =
        new avtMeshMetaData(string("equilibrium/mesh") + string(level),
                            nblocks, block_origin,
                            cell_origin, group_origin,
allens's avatar
allens committed
402
                            spatial_dimension, topological_dimension, meshType);
403 404 405 406 407 408 409 410
      mmd->hideFromGUI = true;
      md->Add(mmd);


      mmd =
        new avtMeshMetaData(string("mesh") + string(level),
                            nblocks, block_origin,
                            cell_origin, group_origin,
allens's avatar
allens committed
411
                            spatial_dimension, topological_dimension, meshType);
412 413 414 415 416 417 418 419 420 421
      mmd->hideFromGUI = true;
      md->Add(mmd);
    }

    nblocks = nelms;    

    // Hidden meshes for working with the elements directly
    mmd =
      new avtMeshMetaData("hidden/equilibrium/mesh",
                          nblocks, block_origin, cell_origin, group_origin,
allens's avatar
allens committed
422
                          spatial_dimension, topological_dimension, meshType);
423 424 425 426 427 428
    mmd->hideFromGUI = true;
    md->Add(mmd);

    mmd =
      new avtMeshMetaData("hidden/mesh",
                          nblocks, block_origin, cell_origin, group_origin,
allens's avatar
allens committed
429
                          spatial_dimension, topological_dimension, meshType);
430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
    mmd->hideFromGUI = true;
    md->Add(mmd);


    // Hidden scalar header vars.
    for ( int i = 0; i < m_scalarVarNames.size(); ++i )
    {
      avtScalarMetaData *smd =
        new avtScalarMetaData("hidden/" + m_scalarVarNames[i],
                              "hidden/equilibrium/mesh", AVT_ZONECENT);

      smd->hideFromGUI = true;
      md->Add(smd);
    }

    // Add the elements so we have access to them for the interpolation
    avtVectorMetaData *amd =
      new avtVectorMetaData("hidden/equilibrium/elements",
                           "hidden/equilibrium/mesh",
allens's avatar
allens committed
449
                           AVT_ZONECENT, element_size);
450 451 452 453 454

    amd->hideFromGUI = true;
    md->Add(amd);

    amd = new avtVectorMetaData("hidden/elements", "hidden/mesh",
allens's avatar
allens committed
455
                               AVT_ZONECENT, element_size);
456 457 458 459 460 461 462 463 464

    amd->hideFromGUI = true;
    md->Add(amd);

    // Hidden array field vars so we have access to them for the interpolation
    for ( int i = 0; i < m_fieldVarNames.size(); ++i )
    {
      string varname = "hidden/equilibrium/" + m_fieldVarNames[i];
      amd = new avtVectorMetaData(varname, "hidden/equilibrium/mesh",
allens's avatar
allens committed
465
                                 AVT_ZONECENT, scalar_size);
466 467 468 469 470 471

      amd->hideFromGUI = true;
      md->Add(amd);

      varname = "hidden/" + m_fieldVarNames[i];
      amd = new avtVectorMetaData(varname, "hidden/mesh",
allens's avatar
allens committed
472
                                 AVT_ZONECENT, scalar_size);
473 474 475 476

      amd->hideFromGUI = true;
      md->Add(amd);
    }
allens's avatar
allens committed
477 478 479 480 481 482

    md->SetCyclesAreAccurate(true);
    md->SetCycles( m_cycles );

    md->SetTimesAreAccurate(true);
    md->SetTimes( m_times );
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
}


// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetElements
//
//  Purpose:
//      Gets the elements assoicated for the C1 mesh.
//
//  Arguments:
//      timestate   The index of the timestate.  If GetNTimesteps returned
//                  'N' time steps, this is guaranteed to be between 0 and N-1.
//      meshname    The name of the mesh of interest.  This can be ignored if
//                  there is only one mesh.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

float *
avtM3DC1FileFormat::GetElements(int timestate, const char *meshname)
{
  char meshStr[64];

  // Parse the mesh naem into the hdf5 group name.
  if( strncmp(meshname, "equilibrium/mesh", 16 ) == 0 )
  {
    sprintf( meshStr, "/equilibrium/mesh" );
  } else if( strncmp(meshname, "mesh", 4 ) == 0 ) {
    sprintf( meshStr, "/time_%03d/mesh", timestate );
  } else
515 516
    EXCEPTION2( NonCompliantException, "M3DC1 Element Name Lookup",
                "Element '" + string(meshStr) + "' was not found." );
517 518 519 520

  // Open the group.
  hid_t meshId = H5Gopen( m_fileID, meshStr, H5P_DEFAULT);
  if ( meshId < 0 )
521 522
    EXCEPTION2( NonCompliantException, "M3DC1 Group Open",
                "Group '" + string(meshStr) + "' was not found." );
523 524 525 526
  
  // Read in the mesh information.
  int nElements;
  if ( ! ReadAttribute( meshId, "nelms", &nElements ) )
527 528
    EXCEPTION2( NonCompliantException, "M3DC1 Attribute Reader",
                "Attribute 'nelms' was not found or was the wrong type." );
529 530
  
  if( nElements != nelms )
531 532
    EXCEPTION2( NonCompliantException, "M3DC1 Element Check",
                "Time step 'nelms' does not match equilibrium 'nelms'" );
533 534 535 536 537
 
  // Open the dataset and space info for the elements.  
  hid_t datasetId = H5Dopen(meshId, "elements", H5P_DEFAULT);
  hid_t spaceId = H5Dget_space(datasetId);
  size_t rank = H5Sget_simple_extent_ndims(spaceId);
538 539
  std::vector<hsize_t> sdim(rank);
  H5Sget_simple_extent_dims(spaceId, &sdim[0], NULL);
540 541

  // Sanity check.  
allens's avatar
allens committed
542
  if( rank != 2 || sdim[0] != nelms || sdim[1] != element_size )
543
  {
544 545
      EXCEPTION2( NonCompliantException, "M3DC1 Element Check",
                  "The number of elements or the element size does not match" );          
546 547 548 549 550
  }

  // Memory for the elements.  
  float *elements = new float[sdim[0]*sdim[1]];
  if( elements == 0 )
551 552
    EXCEPTION2( NonCompliantException, "M3DC1 Memory Allocation",
                "CAN NOT ALLOCATE MEMORY" );
553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572

  // Read in the elements.
  H5Dread( datasetId,
           H5T_NATIVE_FLOAT, H5S_ALL, spaceId, H5P_DEFAULT, elements );

  H5Dclose(spaceId);
  H5Dclose(datasetId);
  H5Gclose( meshId );

  return elements;
}

// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetMeshPoints
//
//  Purpose: Gets the mesh points associated with this file.  The mesh
//      is returned as vtkPoints.
//
//  Arguments:
//      elements        The original C1 elements 
allens's avatar
allens committed
573
//      refinement      The amount of mesh refinement.
574 575 576 577 578 579 580 581
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

vtkPoints *
avtM3DC1FileFormat::GetMeshPoints(float *elements,
allens's avatar
allens committed
582
                                  int refinement)
583
{
allens's avatar
allens committed
584 585 586
  // Inital number of triangles before refinement.
  int npts = nelms * nvertices;
  int ncoords = nvertices * 3;
587 588 589

  // VTK structure for holding the mesh points. 
  vtkPoints *vtkPts = vtkPoints::New();
allens's avatar
allens committed
590
  vtkPts->SetNumberOfPoints( npts );
591 592
  float *pts = (float *) vtkPts->GetVoidPointer(0);

allens's avatar
allens committed
593 594 595 596 597 598 599
  float phi = 0;

  // Pointer for fast indexing through the elements.
  float *element = elements;

//   for( int i=0; i<nelms/2; ++i )
//     element += element_size;
600

allens's avatar
allens committed
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618
  for( int i=0; i<nelms; ++i )
  {
    // The element values from Jardin, JCP 200:133 (2004)
    float a     = element[0];
    float b     = element[1];
    float c     = element[2];
    float theta = element[3];
    float x     = element[4];
    float z     = element[5];

    // The seventh value (call it "e") specifies which edges of the
    // element lie on the domain boundary.  The first edge is the
    // edge between the first and second nodes, the second edge
    // joins nodes 2 and 3, and the third edge joins nodes 3 and 1.
    // If edge n lies on the domain boundary, than the nth bit of e
    // is set.  For example, e=0 means no edges are on the domain
    // boundary, e=5 means the first and third edges are on the
    // domain boundary.
619
    //unsigned int e = element[6];
allens's avatar
allens committed
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635

    if( element_dimension == 3 )
      phi = element[8];

    // The three points in the phi plane that define the triangle mesh element.
    pts[0] = x;
    pts[1] = phi;
    pts[2] = z;

    pts[3] = x + (a+b)*cos(theta);
    pts[4] = phi;
    pts[5] = z + (a+b)*sin(theta);
    
    pts[6] = x + b*cos(theta) - c*sin(theta);
    pts[7] = phi;
    pts[8] = z + b*sin(theta) + c*cos(theta);
636

allens's avatar
allens committed
637 638 639
    // The three points in the phi+d plane that define the second part of
    // the wedge element.
    if( element_dimension == 3 )
640
    {
allens's avatar
allens committed
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
      float d = element[7];

      pts[ 9] = x;
      pts[10] = phi + d;
      pts[11] = z;

      pts[12] = x + (a+b)*cos(theta);
      pts[13] = phi + d;
      pts[14] = z + (a+b)*sin(theta);
    
      pts[15] = x + b*cos(theta) - c*sin(theta);
      pts[16] = phi + d;
      pts[17] = z + b*sin(theta) + c*cos(theta);
    }

    // Increment for fast indexing.
    element += element_size;
    pts += ncoords;
  } 
allens's avatar
allens committed
660 661 662 663

  // Now do any needed refinement. Currently the flag is 0-4. The user
  // sees 1-5. With 1 being no refinement aka linear.
  if( refinement )
664
  {
allens's avatar
allens committed
665 666
    int nLevels = refinement + 1;

667 668 669 670 671
    // Pointer to the current mesh.
    float *pts = (float *) vtkPts->GetVoidPointer(0);

    // VTK structure for holding the refined mesh points. 
    vtkPoints *rf_vtkPts = vtkPoints::New();
allens's avatar
allens committed
672 673 674 675 676

    rf_vtkPts->SetNumberOfPoints( npts *
                                  (int) pow( (float) nLevels,
                                             (float) element_dimension) );

677 678
    float *rf_pts = (float *) rf_vtkPts->GetVoidPointer(0);

allens's avatar
allens committed
679
    if( element_dimension == 2 )
680
    {
allens's avatar
allens committed
681
      for( int i=0; i<npts; i+=nvertices )
682
      {
allens's avatar
allens committed
683 684 685 686
        // Refine the triangle based on barrycentric coordinates.
        float *A = &(pts[0]);
        float *B = &(pts[3]);
        float *C = &(pts[6]);
allens's avatar
allens committed
687

allens's avatar
allens committed
688
        for( int j=0; j<nLevels; ++j )
allens's avatar
allens committed
689
        {
allens's avatar
allens committed
690 691
          float a  = (float)  j      / (float) nLevels;
          float a1 = (float) (j + 1) / (float) nLevels;
allens's avatar
allens committed
692

allens's avatar
allens committed
693 694 695 696
          for( int k=0; k<nLevels-j; ++k )
          {
            float b   = (float) (nLevels-j-k)   / (float) nLevels;
            float b_1 = (float) (nLevels-j-k-1) / (float) nLevels;
allens's avatar
allens committed
697

allens's avatar
allens committed
698 699
            float c  = (float)  k    / (float) nLevels;
            float c1 = (float) (k+1) / (float) nLevels;
allens's avatar
allens committed
700

allens's avatar
allens committed
701 702 703
            rf_pts[0] = a * A[0] + b * B[0] + c * C[0];
            rf_pts[1] = a * A[1] + b * B[1] + c * C[1];
            rf_pts[2] = a * A[2] + b * B[2] + c * C[2];
allens's avatar
allens committed
704

allens's avatar
allens committed
705 706 707
            rf_pts[3] = a * A[0] + b_1 * B[0] + c1 * C[0];
            rf_pts[4] = a * A[1] + b_1 * B[1] + c1 * C[1];
            rf_pts[5] = a * A[2] + b_1 * B[2] + c1 * C[2];
allens's avatar
allens committed
708

allens's avatar
allens committed
709 710 711
            rf_pts[6] = a1 * A[0] + b_1 * B[0] + c * C[0];
            rf_pts[7] = a1 * A[1] + b_1 * B[1] + c * C[1];
            rf_pts[8] = a1 * A[2] + b_1 * B[2] + c * C[2];
allens's avatar
allens committed
712

allens's avatar
allens committed
713
            rf_pts += ncoords;
allens's avatar
allens committed
714

allens's avatar
allens committed
715 716 717 718 719 720 721
            if( k )
            {
              float c_1 = (float) (k-1) / (float) nLevels;

              rf_pts[0] = a * A[0] + b * B[0] + c * C[0];
              rf_pts[1] = a * A[1] + b * B[1] + c * C[1];
              rf_pts[2] = a * A[2] + b * B[2] + c * C[2];
allens's avatar
allens committed
722
            
allens's avatar
allens committed
723 724 725
              rf_pts[3] = a1 * A[0] + b_1 * B[0] + c * C[0];
              rf_pts[4] = a1 * A[1] + b_1 * B[1] + c * C[1];
              rf_pts[5] = a1 * A[2] + b_1 * B[2] + c * C[2];
allens's avatar
allens committed
726
            
allens's avatar
allens committed
727 728 729
              rf_pts[6] = a1 * A[0] + b * B[0] + c_1 * C[0];
              rf_pts[7] = a1 * A[1] + b * B[1] + c_1 * C[1];
              rf_pts[8] = a1 * A[2] + b * B[2] + c_1 * C[2];
allens's avatar
allens committed
730
            
allens's avatar
allens committed
731 732
              rf_pts += ncoords;
            }
allens's avatar
allens committed
733 734 735
          }
        }

allens's avatar
allens committed
736
        pts += ncoords;
737
      }
allens's avatar
allens committed
738 739 740 741 742 743 744 745 746 747 748 749 750 751
    }

    else //if( element_dimension == 3 )
    {
      for( int i=0; i<npts; i+=nvertices )
      {
        // Refine the triangle based on barrycentric coordinates.
        float *A = &(pts[0]);
        float *B = &(pts[3]);
        float *C = &(pts[6]);

        float *D = &(pts[9]);
        float *E = &(pts[12]);
        float *F = &(pts[15]);
752

allens's avatar
allens committed
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 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855
        for( int j=0; j<nLevels; ++j )
        {
          float a  = (float)  j      / (float) nLevels;
          float a1 = (float) (j + 1) / (float) nLevels;
          
          for( int k=0; k<nLevels-j; ++k )
          {
            float b   = (float) (nLevels-j-k)   / (float) nLevels;
            float b_1 = (float) (nLevels-j-k-1) / (float) nLevels;
            
            float c  = (float)  k    / (float) nLevels;
            float c1 = (float) (k+1) / (float) nLevels;

            double left_pts[9], right_pts[9];

            left_pts[0] = a * A[0] + b * B[0] + c * C[0];
            left_pts[1] = a * A[1] + b * B[1] + c * C[1];
            left_pts[2] = a * A[2] + b * B[2] + c * C[2];

            left_pts[3] = a * A[0] + b_1 * B[0] + c1 * C[0];
            left_pts[4] = a * A[1] + b_1 * B[1] + c1 * C[1];
            left_pts[5] = a * A[2] + b_1 * B[2] + c1 * C[2];

            left_pts[6] = a1 * A[0] + b_1 * B[0] + c * C[0];
            left_pts[7] = a1 * A[1] + b_1 * B[1] + c * C[1];
            left_pts[8] = a1 * A[2] + b_1 * B[2] + c * C[2];


            right_pts[0] = a * D[0] + b * E[0] + c * F[0];
            right_pts[1] = a * D[1] + b * E[1] + c * F[1];
            right_pts[2] = a * D[2] + b * E[2] + c * F[2];

            right_pts[3] = a * D[0] + b_1 * E[0] + c1 * F[0];
            right_pts[4] = a * D[1] + b_1 * E[1] + c1 * F[1];
            right_pts[5] = a * D[2] + b_1 * E[2] + c1 * F[2];

            right_pts[6] = a1 * D[0] + b_1 * E[0] + c * F[0];
            right_pts[7] = a1 * D[1] + b_1 * E[1] + c * F[1];
            right_pts[8] = a1 * D[2] + b_1 * E[2] + c * F[2];

            for( int l=0; l<nLevels; ++l )
            {
              for( int ii=0; ii<9; ++ii )
                rf_pts[ii] = left_pts[ii] + (double) l *
                  (right_pts[ii] - left_pts[ii]) / (double) nLevels;

              rf_pts += ncoords/2;

              for( int ii=0; ii<9; ++ii )
                rf_pts[ii] = left_pts[ii] + (double) (l+1) *
                  (right_pts[ii] - left_pts[ii]) / (double) nLevels;

              rf_pts += ncoords/2;
            }

            if( k )
            {
              float c_1 = (float) (k-1) / (float) nLevels;

              left_pts[0] = a * A[0] + b * B[0] + c * C[0];
              left_pts[1] = a * A[1] + b * B[1] + c * C[1];
              left_pts[2] = a * A[2] + b * B[2] + c * C[2];
              
              left_pts[3] = a1 * A[0] + b_1 * B[0] + c * C[0];
              left_pts[4] = a1 * A[1] + b_1 * B[1] + c * C[1];
              left_pts[5] = a1 * A[2] + b_1 * B[2] + c * C[2];
              
              left_pts[6] = a1 * A[0] + b * B[0] + c_1 * C[0];
              left_pts[7] = a1 * A[1] + b * B[1] + c_1 * C[1];
              left_pts[8] = a1 * A[2] + b * B[2] + c_1 * C[2];
              
              right_pts[0] = a * D[0] + b * E[0] + c * F[0];
              right_pts[1] = a * D[1] + b * E[1] + c * F[1];
              right_pts[2] = a * D[2] + b * E[2] + c * F[2];
              
              right_pts[3] = a1 * D[0] + b_1 * E[0] + c * F[0];
              right_pts[4] = a1 * D[1] + b_1 * E[1] + c * F[1];
              right_pts[5] = a1 * D[2] + b_1 * E[2] + c * F[2];
              
              right_pts[6] = a1 * D[0] + b * E[0] + c_1 * F[0];
              right_pts[7] = a1 * D[1] + b * E[1] + c_1 * F[1];
              right_pts[8] = a1 * D[2] + b * E[2] + c_1 * F[2];

              for( int l=0; l<nLevels; ++l )
              {
                for( int ii=0; ii<9; ++ii )
                  rf_pts[ii] = left_pts[ii] + (double) l *
                    (right_pts[ii] - left_pts[ii]) / (double) nLevels;
                
                rf_pts += ncoords/2;
                
                for( int ii=0; ii<9; ++ii )
                  rf_pts[ii] = left_pts[ii] + (double) (l+1) *
                    (right_pts[ii] - left_pts[ii]) / (double) nLevels;
                
                rf_pts += ncoords/2;
              }
            }
          }
        }

        pts += ncoords;
      }
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 884 885 886 887 888 889 890 891 892 893 894
    }

    // Delete the old points.
    vtkPts->Delete();

    // Update the pointers to the new mesh
    vtkPts = rf_vtkPts;
  }

  return vtkPts;  
}



// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetMesh
//
//  Purpose:
//      Gets the mesh associated with this file.  The mesh is returned as a
//      derived type of vtkDataSet (ie vtkRectilinearGrid, vtkStructuredGrid,
//      vtkUnstructuredGrid, etc).
//
//  Arguments:
//      timestate   The index of the timestate.  If GetNTimesteps returned
//                  'N' time steps, this is guaranteed to be between 0 and N-1.
//      meshname    The name of the mesh of interest.  This can be ignored if
//                  there is only one mesh.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

vtkDataSet *
avtM3DC1FileFormat::GetMesh(int timestate, const char *meshname)
{
  const char *meshnamePtr = meshname;  
  char meshStr[64];

allens's avatar
allens committed
895 896 897
  bool haveDataSelections;
  int mins[3], maxs[3], strides[3];
  
898 899 900 901 902
  // If hidden only one poloidal plane as the mesh will be used for
  // interpolation. There should also be no refinement.
  if( strncmp(meshname, "hidden/", 7 ) == 0 )
  {
    meshnamePtr = &(meshname[7]);
allens's avatar
allens committed
903 904

    mins[0] = 0;
905
    maxs[0] = nelms-1;
allens's avatar
allens committed
906 907 908
    strides[0] = 1;
      
    haveReadWholeData = true;
909 910 911 912
  }
  else
  {
    meshnamePtr = meshname;
allens's avatar
allens committed
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928

    // Adjust for the data selections which are NODAL.
    if( haveDataSelections = ProcessDataSelections(mins, maxs, strides) )
    {
      debug5
        << "Have a logical cell selection for mesh  " << meshname << "  "
        << "(" << mins[0] << "," << maxs[0] << " stride " << strides[0] << ") "
        //      << "(" << mins[1] << "," << maxs[1] << " stride " << strides[1] << ") "
        //      << "(" << mins[2] << "," << maxs[2] << " stride " << strides[2] << ") "
        << std::endl;
      
      haveReadWholeData = false;
    }
    else
    {
      mins[0] = 0;
929
      maxs[0] = nelms-1;
allens's avatar
allens committed
930 931 932 933
      strides[0] = 1;
      
      haveReadWholeData = true;
    }
934 935
  }
  
allens's avatar
allens committed
936 937
  // Parse the mesh variable name to get the true mesh name and the
  // refiement level in the meshnamePtr.
938 939 940 941 942 943 944 945 946 947
  if( strncmp(meshnamePtr, "equilibrium/mesh", 16 ) == 0 )
  {
    meshnamePtr = &(meshnamePtr[16]);
    sprintf( meshStr, "equilibrium/mesh" );    
  }
  else if( strncmp(meshnamePtr, "mesh", 4 ) == 0 ) {
    meshnamePtr = &(meshnamePtr[4]);
    sprintf( meshStr, "mesh" );    
  }
  else
948 949
    EXCEPTION2( NonCompliantException, "M3DC1 Mesh Name",
                "Can not find '" + string(meshnamePtr) );
950 951

  // Parse the mesh variable name to get the refinement level.
allens's avatar
allens committed
952
  int refinement;
953

allens's avatar
allens committed
954 955
  if( strlen(meshnamePtr) && atoi(&(meshnamePtr[1])) == m_refinement )
      refinement = m_refinement;
956
  else
allens's avatar
allens committed
957
    refinement = 0;
958 959 960 961

  // Get the C1 elements.
  float* elements = GetElements(timestate, meshStr);

962
  // Create a VTK grid for the mesh.
963 964
  vtkUnstructuredGrid *grid = vtkUnstructuredGrid::New();

allens's avatar
allens committed
965
  // Now get the points on the mesh based on the refinement level.
allens's avatar
allens committed
966
  vtkPoints *vtkPts = GetMeshPoints( elements, refinement );
967 968 969 970 971 972 973 974 975 976

  // Add the points to the VTK grid.
  int npts = vtkPts->GetNumberOfPoints();
  grid->SetPoints( vtkPts );

  delete [] elements;

  // Add in the VTK cells. The connectivity is the same for all
  // triangles because each triangle is defined by three points that
  // are not unique. 
977

978 979
  grid->Allocate((maxs[0]-mins[0])/strides[0]+1);

allens's avatar
allens committed
980
  if( element_dimension == 2 )
981
  {
allens's avatar
allens committed
982
    vtkTriangle *tri = vtkTriangle::New();
983 984

    for( int i=mins[0]; i<=maxs[0]; i+=strides[0] )
allens's avatar
allens committed
985
    {
986 987 988 989
      unsigned int index = i * nvertices;
      tri->GetPointIds()->SetId( 0, index   );
      tri->GetPointIds()->SetId( 1, index+1 );
      tri->GetPointIds()->SetId( 2, index+2 );
allens's avatar
allens committed
990 991 992
      
      grid->InsertNextCell( tri->GetCellType(), tri->GetPointIds() );
    }
993
    
allens's avatar
allens committed
994 995 996 997 998
    tri->Delete();
  }
  else //if( element_dimension == 3 )
  {
    vtkWedge *wedge = vtkWedge::New();
allens's avatar
allens committed
999

allens's avatar
allens committed
1000
    for( int i=mins[0]; i<=maxs[0]; i+=strides[0] )
allens's avatar
allens committed
1001
    {
allens's avatar
allens committed
1002 1003 1004 1005 1006 1007 1008
      unsigned int index = i * nvertices;
      wedge->GetPointIds()->SetId( 0, index   );
      wedge->GetPointIds()->SetId( 1, index+1 );
      wedge->GetPointIds()->SetId( 2, index+2 );
      wedge->GetPointIds()->SetId( 3, index+3 );
      wedge->GetPointIds()->SetId( 4, index+4 );
      wedge->GetPointIds()->SetId( 5, index+5 );
allens's avatar
allens committed
1009

allens's avatar
allens committed
1010 1011 1012 1013
      grid->InsertNextCell( wedge->GetCellType(), wedge->GetPointIds() );
    }
    
    wedge->Delete();
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
  }

  return grid;
}


// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetHeaderVar
//
//  Purpose:
//      Gets a scalar variable associated with this file.  Although VTK has
//      support for many different types, the best bet is vtkFloatArray, since
//      that is supported everywhere through VisIt.
//
//  Arguments:
//      timestate  The index of the timestate.  If GetNTimesteps returned
//                 'N' time steps, this is guaranteed to be between 0 and N-1.
//      varname    The name of the variable requested.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

vtkDataArray *
avtM3DC1FileFormat::GetHeaderVar(int timestate, const char *varname)
{
  // Get the header variable

  // Header variables are at the top level group.
  hid_t rootID = H5Gopen( m_fileID, "/", H5P_DEFAULT);
  if ( rootID < 0 )
1046 1047
    EXCEPTION2( NonCompliantException, "M3DC1 Group Open",
                "The root group '/' was not found" );
1048 1049 1050

  // Everything is converted to floats by visit so might as well do it
  // here and save the copying time and memory.
1051
  string variable(&(varname[7]));
1052 1053
  float value;

allens's avatar
allens committed
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
  // Read in 3D flag and nplanes an an int
  if( variable == "nplanes" )
  {
    int intVal;
    // 2D or 3D elements?
    if ( ReadAttribute( rootID, "3d", &intVal ) && intVal == 1 )
    {
      // Read in nplanes
      if ( ! ReadAttribute( rootID, "nplanes", &intVal ) )
      {
        EXCEPTION1( InvalidVariableException, "M3DC1 Attribute Reader - 'nplanes' was not found or was the wrong type." );
      }
      else
        value = intVal;
    }  
    else
    {
      value = 1;
    }  
  }

1075
  // Read in linear flag and ntor an an int
1076 1077 1078
  else if( variable == "eqsubtract" ||
           variable == "linear" ||
           variable == "ntor"   )
1079 1080
  {
      int intVal;
1081 1082 1083 1084 1085
      if ( ! ReadAttribute( rootID, variable.c_str(), &intVal ) )
      {
        EXCEPTION2( NonCompliantException, "M3DC1 Attribute Reader",
                    "Attribute '" + variable + "' was not found or was the wrong type." );
      }
1086 1087 1088 1089 1090
      else
        value = intVal;
  }
    
  // Read in bzero and rzero as a double
1091
  else if( variable == "bzero" || variable == "rzero" )
1092 1093
  {
      double dblVal;
1094 1095 1096 1097 1098
      if ( ! ReadAttribute( rootID, variable.c_str(), &dblVal ) )
      {
        EXCEPTION2( NonCompliantException, "M3DC1 Attribute Reader",
                    "Attribute '" + variable + "' was not found or was the wrong type." );
      }
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 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
      else
        value = dblVal;
  }

  vtkFloatArray *var = vtkFloatArray::New();

  // Set the number of components before setting the number of tuples
  // for proper memory allocation.
  var->SetNumberOfComponents( 1 );
  var->SetNumberOfTuples( nelms );
    
  float* varPtr = (float *) var->GetVoidPointer(0);
    
  for( int i=0; i<nelms; ++i)
    *varPtr++ = value;
    
  H5Gclose( rootID );
    
  return var;
}


// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetFieldVar
//
//  Purpose:
//      Gets a field variable associated with this file.  Although VTK has
//      support for many different types, the best bet is vtkFloatArray, since
//      that is supported everywhere through VisIt.
//
//  Arguments:
//      timestate  The index of the timestate.  If GetNTimesteps returned
//                 'N' time steps, this is guaranteed to be between 0 and N-1.
//      varname    The name of the variable requested.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

vtkDataArray *
avtM3DC1FileFormat::GetFieldVar(int timestate, const char *varname)
{
  char groupStr[64];
  char varStr[64];

  int nComponents;

  // Parse the field variable name to get the HDF5 group and dataset
  // name.
  if( strncmp(varname, "equilibrium", 11 ) == 0 )
  {
    if( strcmp(&(varname[11]), "elements" ) == 0 ) {
allens's avatar
allens committed
1152
      nComponents = element_size;;
1153 1154
      sprintf( groupStr, "/equilibrium/mesh" );
    } else {
allens's avatar
allens committed
1155
      nComponents = scalar_size;;
1156 1157 1158 1159 1160 1161 1162
      sprintf( groupStr, "/equilibrium/fields" );
    }

    strcpy( varStr, &(varname[12]) );

  } else {
    if( strcmp(varname, "elements" ) == 0 ) {
allens's avatar
allens committed
1163
      nComponents = element_size;;
1164 1165
      sprintf( groupStr, "/time_%03d/mesh", timestate );
    } else {
allens's avatar
allens committed
1166
      nComponents = scalar_size;;
1167 1168 1169 1170 1171 1172 1173 1174 1175
      sprintf( groupStr, "/time_%03d/fields", timestate );
    }

    strcpy( varStr, varname );
  }

  // Open the group.
  hid_t groupID = H5Gopen( m_fileID, groupStr, H5P_DEFAULT);
  if ( groupID < 0 )
1176 1177
    EXCEPTION2( NonCompliantException, "M3DC1 Group Open",
                "Group '" + string(groupStr) + "' was not found" );
1178 1179 1180 1181

  // Open the field dataset
  hid_t datasetId = H5Dopen(groupID, varStr, H5P_DEFAULT);
  if ( datasetId < 0 )
1182 1183
    EXCEPTION2( NonCompliantException, "M3DC1 Dataset Open",
                "Dataset '" + string(varStr) + "' was not found" );
1184 1185 1186 1187
  
  // Read in the dataset information.
  hid_t spaceId = H5Dget_space(datasetId);
  size_t rank = H5Sget_simple_extent_ndims(spaceId);
1188 1189
  std::vector<hsize_t> sdim(rank);
  H5Sget_simple_extent_dims(spaceId, &sdim[0], NULL);
1190 1191
  
  if( rank != 2 || sdim[0] != nelms || sdim[1] != nComponents )
1192 1193 1194 1195
    EXCEPTION2( NonCompliantException, "M3DC1 Element Check",
                "Dataset '" +
                string(groupStr) + string("/") + string(varStr) +
                "' the number of elements or the component size does not match" );
1196

allens's avatar
allens committed
1197 1198 1199 1200 1201 1202 1203 1204 1205
  // Create the VTK structure to hole the field variable.
  vtkFloatArray *var = vtkFloatArray::New();

  // Set the number of components before setting the number of tuples
  // for proper memory allocation.
  var->SetNumberOfComponents( sdim[1] );
  var->SetNumberOfTuples( sdim[0] );


1206
  // Normally an array would be created but instead use the VTK memory
1207 1208 1209 1210 1211 1212
  // directly - this usage works because the vtk and hdf5 memory
  // layout are the same.

//   float *vals = new float[sdim[0]*sdim[1]];
//   if( H5Dread( datasetId,
//             H5T_NATIVE_FLOAT, H5S_ALL, spaceId, H5P_DEFAULT, vals ) < 0 )
allens's avatar
allens committed
1213 1214 1215
//     EXCEPTION2( NonCompliantException, "M3DC1 Dataset Read",
//              "Dataset '" + string(groupStr) + string("/") + string(varStr) +
//              "' can not be read" );
1216

allens's avatar
allens committed
1217 1218 1219 1220
//  var->SetNumberOfValues( sdim[0]*sdim[1] );
//  var->SetArray( vals, sdim[0]*sdim[1], 0, // ); delete[]( void *) );
//  delete [] vals;
  
1221 1222 1223 1224 1225 1226 1227

  // Pointer to the vtk memory.
  float* values = (float*) var->GetVoidPointer(0);
  
  // Read the data directly into the vtk memory - this call assume
  // that the hdfd5 and vtk memory layout are the same.
  if( H5Dread( datasetId,
allens's avatar
allens committed
1228
              H5T_NATIVE_FLOAT, H5S_ALL, spaceId, H5P_DEFAULT, values ) < 0 )
1229 1230 1231
    EXCEPTION2( NonCompliantException, "M3DC1 Dataset Read",
                "Dataset '" + string(groupStr) + string("/") + string(varStr) +
                "' can not be read" );
allens's avatar
allens committed
1232 1233 1234 1235 1236 1237 1238 1239 1240

  int ncomponents = sdim[1];

//   std::cerr << "READ " << varname << std::endl;
//     for( int j=0; j<ncomponents; ++j )
//       std::cerr << values[0*ncomponents+j]  << "  ";
//     std::cerr << std::endl;
//     std::cerr << std::endl;

1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287
  H5Dclose(spaceId);
  H5Dclose(datasetId);
  H5Gclose( groupID );
  
  return var;
}


// ****************************************************************************
//  Method: avtM3DC1FileFormat::GetVar
//
//  Purpose:
//      Gets a scalar variable associated with this file.  Although VTK has
//      support for many different types, the best bet is vtkFloatArray, since
//      that is supported everywhere through VisIt.
//
//  Arguments:
//      timestate  The index of the timestate.  If GetNTimesteps returned
//                 'N' time steps, this is guaranteed to be between 0 and N-1.
//      varname    The name of the variable requested.
//
//  Programmer: allen -- generated by xml2avt
//  Creation:   Fri Dec 4 15:04:15 PST 2009
//
// ****************************************************************************

vtkDataArray *
avtM3DC1FileFormat::GetVar(int timestate, const char *varname)
{
  // Hidden scalar variables are read from the header and put on the
  // C1 mesh.
  if( strncmp(varname, "hidden/", 7) == 0 )
  {
    char varStr[64];
    strcpy( varStr, &(varname[7]) );

    if( strncmp(varStr, "header", 6) == 0 )
      return GetHeaderVar( timestate, varStr);
    else
      return 0;
  }
    
  // First get the elements for this variable so that the variable can
  // be interpolated onto the linear mesh.
  float* elements;
  if( strncmp(varname, "equilibrium", 11 ) == 0 )
    elements = GetElements(timestate, "equilibrium/mesh");
allens's avatar
allens committed
1288
  else
1289 1290 1291 1292
    elements = GetElements(timestate, "mesh");

  // Create a temporary mesh for getting the correct field variable
  // values on the linear mesh.
allens's avatar
allens committed
1293
  vtkPoints *vtkPts = GetMeshPoints( elements, m_refinement );
1294 1295 1296 1297 1298
  float* pts = (float *) vtkPts->GetVoidPointer(0);
  int npts = vtkPts->GetNumberOfPoints();

  // Get the M3D C1 field so the variables can be interpolated on the
  // linear mesh.
allens's avatar
allens committed
1299
  avtM3DC1Field m3dField(elements, nelms, element_dimension, nplanes);
1300 1301 1302 1303 1304

  // Get the field variable to be interpolated on the linear mesh.
  vtkDataArray* vtkVar = GetFieldVar( timestate, varname );
  float* values = (float*) vtkVar->GetVoidPointer