avtSimV2FileFormat.C 84.2 KB
Newer Older
1 2
/*****************************************************************************
*
3
* Copyright (c) 2000 - 2014, Lawrence Livermore National Security, LLC
4
* Produced at the Lawrence Livermore National Laboratory
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 44
* 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.
*
*****************************************************************************/

// ************************************************************************* //
//                            avtSimV2FileFormat.C                           //
// ************************************************************************* //

#include <avtSimV2FileFormat.h>

45
#include <map>
46
#include <string>
47
#include <sstream>
48
#include <vector>
whitlocb's avatar
whitlocb committed
49
#include <snprintf.h>
50 51 52 53 54 55 56

#include <avtDatabaseMetaData.h>
#include <avtGhostData.h>
#include <avtIOInformation.h>
#include <avtMixedVariable.h>
#include <avtSimulationInformation.h>
#include <avtSimulationCommandSpecification.h>
whitlocb's avatar
whitlocb committed
57 58
#include <avtStructuredDomainBoundaries.h>
#include <avtStructuredDomainNesting.h>
59 60
#include <avtSpecies.h>
#include <avtVariableCache.h>
cyrush's avatar
cyrush committed
61
#include <avtPolyhedralSplit.h>
62 63 64 65 66 67 68

#include <Expression.h>
#include <DebugStream.h>
#include <InvalidFilesException.h>
#include <InvalidVariableException.h>

#include <visitstream.h>
cyrush's avatar
cyrush committed
69

70 71 72 73 74 75
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkFieldData.h>
#include <vtkFloatArray.h>
#include <vtkDoubleArray.h>
#include <vtkIdTypeArray.h>
76
#include <vtkIntArray.h>
77
#include <vtkLongArray.h>
78 79 80 81 82 83 84 85 86
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkVisItUtility.h>

using std::string;
using std::vector;
87
using std::ostringstream;
88 89 90 91 92 93

#ifdef PARALLEL
#include <mpi.h>
#include <avtParallel.h>
#endif

94
#ifndef MDSERVER
whitlocb's avatar
whitlocb committed
95 96 97
#include <VisItControlInterfaceRuntime.h>
#include <VisItDataInterfaceRuntime.h>

98 99 100 101 102 103 104 105 106 107 108 109
// MetaData
#include <simv2_CommandMetaData.h>
#include <simv2_CurveMetaData.h>
#include <simv2_ExpressionMetaData.h>
#include <simv2_MaterialMetaData.h>
#include <simv2_MeshMetaData.h>
#include <simv2_NameList.h>
#include <simv2_SimulationMetaData.h>
#include <simv2_SpeciesMetaData.h>
#include <simv2_VariableMetaData.h>

// Data
110
#include <simv2_CurveData.h>
111
#include <simv2_DomainBoundaries.h>
112
#include <simv2_DomainList.h>
113
#include <simv2_DomainNesting.h>
114
#include <simv2_MaterialData.h>
115
#include <simv2_SpeciesData.h>
116
#include <simv2_VariableData.h>
117 118
#include <simv2_TypeTraits.hxx>
#include <simv2_DeleteEventObserver.h>
119
#include <simv2_UnstructuredMesh.h>
120

whitlocb's avatar
whitlocb committed
121 122
vtkDataSet *SimV2_GetMesh_Curvilinear(visit_handle h);
vtkDataSet *SimV2_GetMesh_Rectilinear(visit_handle h);
cyrush's avatar
cyrush committed
123
vtkDataSet *SimV2_GetMesh_Unstructured(int, visit_handle h, avtPolyhedralSplit **);
whitlocb's avatar
whitlocb committed
124 125
vtkDataSet *SimV2_GetMesh_Point(visit_handle h);
vtkDataSet *SimV2_GetMesh_CSG(visit_handle h);
126 127

const char *AUXILIARY_DATA_POLYHEDRAL_SPLIT = "POLYHEDRAL_SPLIT";
128 129 130
#endif

// ****************************************************************************
131
//  Method: avtSimV2 constructor
132
//
133
//  Programmer: Brad Whitlock
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
//  Creation:   March 17, 2005
//
//  Modifications:
//
// ****************************************************************************

avtSimV2FileFormat::avtSimV2FileFormat(const char *filename)
    : avtSTMDFileFormat(&filename, 1)
{
#ifdef MDSERVER
    ifstream in(filename);

    simInfo.SetHost("");
    simInfo.SetPort(-1);
    simInfo.SetSecurityKey("");

    char buff[256];
    while (in >> buff)
    {
153
        if (strcmp(buff, "host")==0)
154 155 156 157
        {
            in >> buff;
            simInfo.SetHost(buff);
        }
158
        else if (strcmp(buff, "port")==0)
159 160 161 162 163
        {
            int port;
            in >> port;
            simInfo.SetPort(port);
        }
164
        else if (strcmp(buff, "key")==0)
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
        {
            in >> buff;
            simInfo.SetSecurityKey(buff);
        }
        else
        {
            in.get(); // assume one delimiter character

            char val[2048];
            in.getline(val, 2048);
            simInfo.GetOtherNames().push_back(buff);
            simInfo.GetOtherValues().push_back(val);
        }
    }

    in.close();

    if (simInfo.GetHost()=="")
    {
        EXCEPTION2(InvalidFilesException,filename,
                   "Did not find 'host' in the file.");
    }
    if (simInfo.GetSecurityKey()=="")
    {
        EXCEPTION2(InvalidFilesException,filename,
                   "Did not find 'key' in the file.");
    }
    if (simInfo.GetPort()==-1)
    {
        EXCEPTION2(InvalidFilesException,filename,
                   "Did not find 'port' in the file.");
    }
197 198
#else
    (void)filename;
199 200 201 202 203 204 205 206 207 208 209 210
#endif
}

// ****************************************************************************
//  Method: avtSimV2FileFormat::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.
//
211
//  Programmer: Brad Whitlock
212 213 214 215 216 217 218 219 220
//  Creation:   August 11, 2004
//
// ****************************************************************************

void
avtSimV2FileFormat::FreeUpResources(void)
{
}

whitlocb's avatar
whitlocb committed
221 222 223
// ****************************************************************************
// Method: avtSimV2FileFormat::ActivateTimestep
//
cyrush's avatar
cyrush committed
224
// Purpose:
whitlocb's avatar
whitlocb committed
225 226 227 228 229 230
//   Calls ActivateTimestep on all of the simulation processors.
//
// Programmer: Brad Whitlock
// Creation:   Mon Mar 16 16:51:20 PDT 2009
//
// Modifications:
cyrush's avatar
cyrush committed
231
//
whitlocb's avatar
whitlocb committed
232 233 234 235 236 237
// ****************************************************************************

void
avtSimV2FileFormat::ActivateTimestep()
{
#ifndef MDSERVER
238
    simv2_invoke_ActivateTimestep();
whitlocb's avatar
whitlocb committed
239 240 241
#endif
}

242 243 244 245
#ifndef MDSERVER
// ****************************************************************************
// Method: AddMeshMetaData
//
cyrush's avatar
cyrush committed
246
// Purpose:
247 248 249 250 251 252 253
//   Populates avtMeshMetaData using a handle to SimV2's MeshMetaData
//
// Arguments:
//   mHandle : A handle to a MeshMetaData object.
//
// Returns:    An initialized avtMeshMetaData object.
//
cyrush's avatar
cyrush committed
254
// Note:
255 256 257 258 259
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 11:11:27 PST 2010
//
// Modifications:
260
//   Brad Whitlock, Tue Jun  8 11:51:09 PDT 2010
cyrush's avatar
cyrush committed
261
//   I fixed an error where the wrong mesh metadata was used for domain
262 263
//   piece name.
//
264 265 266
//   Brad Whitlock, Thu Dec  2 14:41:13 PST 2010
//   I fixed a problem where a freed units string was being referenced.
//
267 268 269
//   Brad Whitlock, Wed Aug 17 12:20:43 PDT 2011
//   I added support for node/cell origin and spatial extents.
//
270 271 272
//   Brad Whitlock, Wed Aug  8 14:19:31 PDT 2012
//   Always assume that the number of groupIds is equal to the number of domains.
//
273 274 275
//   Kathleen Biagas, Wed Jul  2 15:20:32 MST 2014
//   Don't add group info unless there is at least 1 group.
//
276 277 278 279
// ****************************************************************************

void
AddMeshMetaData(avtDatabaseMetaData *md, visit_handle h)
whitlocb's avatar
whitlocb committed
280
{
281 282 283 284 285
    avtMeshMetaData *mesh = 0;

    // Get the mesh type
    int meshType = VISIT_MESHTYPE_UNKNOWN;
    if(simv2_MeshMetaData_getMeshType(h, &meshType) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
286
    {
287 288 289 290
        // Get the mesh name
        char *meshName = NULL;
        if(simv2_MeshMetaData_getName(h, &meshName) == VISIT_OKAY)
        {
291
            int tdim = 0, sdim = 0;
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
            if(simv2_MeshMetaData_getTopologicalDimension(h, &tdim)
               == VISIT_OKAY &&
               simv2_MeshMetaData_getSpatialDimension(h, &sdim)
               == VISIT_OKAY)
            {
                mesh = new avtMeshMetaData;
                mesh->name = meshName;
                mesh->topologicalDimension = tdim;
                mesh->spatialDimension = sdim;
                mesh->hasSpatialExtents = false;

                switch (meshType)
                {
                case VISIT_MESHTYPE_RECTILINEAR:
                    mesh->meshType = AVT_RECTILINEAR_MESH;
                    break;
                case VISIT_MESHTYPE_CURVILINEAR:
                    mesh->meshType = AVT_CURVILINEAR_MESH;
                    break;
                case VISIT_MESHTYPE_UNSTRUCTURED:
                    mesh->meshType = AVT_UNSTRUCTURED_MESH;
                    break;
                case VISIT_MESHTYPE_POINT:
                    mesh->meshType = AVT_POINT_MESH;
                    break;
                case VISIT_MESHTYPE_CSG:
                    mesh->meshType = AVT_CSG_MESH;
                    break;
                case VISIT_MESHTYPE_AMR:
                    mesh->meshType = AVT_AMR_MESH;
                    break;
                default:
                    delete mesh;
                    simv2_FreeObject(h);
                    EXCEPTION1(ImproperUseException,
                               "Invalid mesh type in MeshMetaData.");
                    break;
                }
            }

            free(meshName);
        }
whitlocb's avatar
whitlocb committed
334
    }
335 336 337 338 339 340 341 342 343 344

    if(mesh == 0)
        return;

    int nDomains = 1;
    if(simv2_MeshMetaData_getNumDomains(h, &nDomains) == VISIT_OKAY)
        mesh->numBlocks = nDomains;

    char *domainTitle = NULL;
    if(simv2_MeshMetaData_getDomainTitle(h, &domainTitle) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
345
    {
346
        mesh->blockTitle = std::string(domainTitle);
347
        free(domainTitle);
whitlocb's avatar
whitlocb committed
348
    }
349 350

    char *domainPieceName = NULL;
351
    if(simv2_MeshMetaData_getDomainPieceName(h, &domainPieceName) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
352
    {
353
        mesh->blockPieceName = std::string(domainPieceName);
354
        free(domainPieceName);
whitlocb's avatar
whitlocb committed
355
    }
356 357 358

    int nDomainNames = 0;
    if(simv2_MeshMetaData_getNumDomainName(h, &nDomainNames) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
359
    {
360 361 362 363 364 365 366 367 368 369 370 371 372
        for(int i = 0; i < nDomainNames; ++i)
        {
            char *name = NULL;
            if(simv2_MeshMetaData_getDomainName(h, i, &name) == VISIT_OKAY)
            {
                mesh->blockNames.push_back(name);
                free(name);
            }
            else
                mesh->blockNames.push_back("");
        }
    }

373
    int nGroups = 0;
374 375 376
    if(simv2_MeshMetaData_getNumGroups(h, &nGroups) == VISIT_OKAY)
        mesh->numGroups = nGroups;

377
    if (nGroups > 0)
378
    {
379 380 381 382 383 384
        char *groupTitle = NULL;
        if(simv2_MeshMetaData_getGroupTitle(h, &groupTitle) == VISIT_OKAY)
        {
            mesh->groupTitle = std::string(groupTitle);
            free(groupTitle);
        }
385

386 387 388 389 390 391
        char *groupPieceName = NULL;
        if(simv2_MeshMetaData_getGroupPieceName(h, &groupPieceName) == VISIT_OKAY)
        {
            mesh->groupPieceName = std::string(groupPieceName);
            free(groupPieceName);
        }
cyrush's avatar
cyrush committed
392

393 394 395 396 397 398 399 400
        int groupLen = mesh->numBlocks;
        mesh->groupIds.resize(groupLen);
        for (int g = 0; g<groupLen; g++)
        {
            int id = 0;
            simv2_MeshMetaData_getGroupId(h, g, &id);
            mesh->groupIds[g] = id;
        }
401 402 403 404 405 406
    }

    // Get axis labels
    char *xLabel = NULL, *yLabel = NULL, *zLabel = NULL;
    if(simv2_MeshMetaData_getXLabel(h, &xLabel) == VISIT_OKAY)
    {
407
        mesh->xLabel = std::string(xLabel);
408 409 410 411
        free(xLabel);
    }
    if(simv2_MeshMetaData_getYLabel(h, &yLabel) == VISIT_OKAY)
    {
412
        mesh->yLabel = std::string(yLabel);
413 414 415 416
        free(yLabel);
    }
    if(simv2_MeshMetaData_getZLabel(h, &zLabel) == VISIT_OKAY)
    {
417
        mesh->zLabel = std::string(zLabel);
418 419 420 421 422 423 424
        free(zLabel);
    }

    // Get axis units
    char *xUnits = NULL, *yUnits = NULL, *zUnits = NULL;
    if(simv2_MeshMetaData_getXUnits(h, &xUnits) == VISIT_OKAY)
    {
425
        mesh->xUnits = std::string(xUnits);
426 427 428 429
        free(xUnits);
    }
    if(simv2_MeshMetaData_getYUnits(h, &yUnits) == VISIT_OKAY)
    {
430
        mesh->yUnits = std::string(yUnits);
431 432 433 434
        free(yUnits);
    }
    if(simv2_MeshMetaData_getZUnits(h, &zUnits) == VISIT_OKAY)
    {
435
        mesh->zUnits = std::string(zUnits);
436
        free(zUnits);
whitlocb's avatar
whitlocb committed
437
    }
438

439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465
    // Get cell origin.
    int origin = 0;
    if(simv2_MeshMetaData_getCellOrigin(h, &origin) == VISIT_OKAY)
        mesh->cellOrigin = origin;

    // Get node origin.
    if(simv2_MeshMetaData_getNodeOrigin(h, &origin) == VISIT_OKAY)
        mesh->nodeOrigin = origin;

    // Get the spatial extents.
    int hasSE = 0;
    if(simv2_MeshMetaData_getHasSpatialExtents(h, &hasSE) == VISIT_OKAY)
    {
        double extents[6] = {0.,0.,0.,0.,0.,0.};
        if(hasSE > 0 &&
           simv2_MeshMetaData_getSpatialExtents(h, extents) == VISIT_OKAY)
        {
            mesh->hasSpatialExtents = true;
            mesh->minSpatialExtents[0] = extents[0];
            mesh->minSpatialExtents[1] = extents[2];
            mesh->minSpatialExtents[2] = extents[4];
            mesh->maxSpatialExtents[0] = extents[1];
            mesh->maxSpatialExtents[1] = extents[3];
            mesh->maxSpatialExtents[2] = extents[5];
        }
    }

466
    md->Add(mesh);
whitlocb's avatar
whitlocb committed
467
}
468

469 470 471
// ****************************************************************************
// Method: RestrictMaterialIndices
//
cyrush's avatar
cyrush committed
472
// Purpose:
473 474 475 476 477 478 479 480 481 482
//   Check the input variable metadata for its materialName to see if any of
//   the material names are present in the material for the variable's mesh.
//   If so, return a vector of the indices of the material names.
//
// Arguments:
//   h : the metadata handle.
//   mmd : The material metadata.
//
// Returns:    A vector of indices.
//
cyrush's avatar
cyrush committed
483
// Note:
484 485 486 487 488
//
// Programmer: Brad Whitlock
// Creation:   Wed Jul 18 14:55:04 PDT 2012
//
// Modifications:
cyrush's avatar
cyrush committed
489
//
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
// ****************************************************************************

intVector
RestrictMaterialIndices(visit_handle h, const avtMaterialMetaData *mmd)
{
    intVector restrictedMats;

    if(mmd != NULL)
    {
        int nmat = 0;
        if(simv2_VariableMetaData_getNumMaterialName(h, &nmat) == VISIT_OKAY)
        {
            for(int m = 0; m < nmat; ++m)
            {
                char *matname = NULL;
                if(simv2_VariableMetaData_getMaterialName(h, m, &matname) == VISIT_OKAY)
                {
                    // Find index of matname in mmd's material names.
                    for(size_t idx = 0; idx < mmd->materialNames.size(); ++idx)
                    {
                        if(mmd->materialNames[idx] == std::string(matname))
                        {
bonnell's avatar
bonnell committed
512
                            restrictedMats.push_back((int)idx);
513 514 515 516 517 518 519 520 521 522 523 524
                            break;
                        }
                    }
                    free(matname);
                }
            }
        }
    }

    return restrictedMats;
}

525
// ****************************************************************************
526
// Method: AddVariableMetaData
527
//
cyrush's avatar
cyrush committed
528
// Purpose:
529
//   Adds a variable metadata to the database metadata.
530
//
531
// Arguments:
532
//
cyrush's avatar
cyrush committed
533
// Returns:
534
//
cyrush's avatar
cyrush committed
535
// Note:
536 537 538
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 11:34:15 PST 2010
whitlocb's avatar
whitlocb committed
539
//
540
// Modifications:
whitlocb's avatar
whitlocb committed
541 542 543
//   Brad Whitlock, Thu Dec 15 14:51:15 PST 2011
//   Reenable array variables. Also add support for hideFromGUI attribute.
//
544 545 546
//   Brad Whitlock, Wed Jul 18 14:58:01 PDT 2012
//   Enable variables to be restricted to material subsets of the mesh.
//
547 548 549
// ****************************************************************************

void
550
AddVariableMetaData(avtDatabaseMetaData *md, visit_handle h)
cyrush's avatar
cyrush committed
551
{
552 553 554 555 556 557 558 559 560 561 562 563 564 565 566
    char *name = NULL, *meshName = NULL;
    if(simv2_VariableMetaData_getName(h, &name) == VISIT_OKAY)
    {
        if(simv2_VariableMetaData_getMeshName(h, &meshName) == VISIT_OKAY)
        {
            int type, cntr;
            if(simv2_VariableMetaData_getType(h, &type) == VISIT_OKAY &&
               simv2_VariableMetaData_getCentering(h, &cntr) == VISIT_OKAY)
            {
                char *u = NULL;
                bool hasUnits = false;
                std::string units;
                if(simv2_VariableMetaData_getUnits(h, &u) == VISIT_OKAY)
                {
                    units = u;
567
                    hasUnits = !units.empty();
568 569
                    free(u);
                }
570

571 572 573 574 575
                avtCentering centering;
                if(cntr == VISIT_VARCENTERING_NODE)
                    centering = AVT_NODECENT;
                else
                    centering = AVT_ZONECENT;
576

whitlocb's avatar
whitlocb committed
577 578 579 580 581
                int iHideFromGUI = 0;
                bool hideFromGUI = false;
                if(simv2_VariableMetaData_getHideFromGUI(h, &iHideFromGUI) ==  VISIT_OKAY)
                    hideFromGUI = iHideFromGUI > 0;

cyrush's avatar
cyrush committed
582
                // See if the mesh for this variable has a material so we can
583 584 585 586 587 588 589 590
                // potentially restrict this variable to certain material regions.
                const avtMaterialMetaData *mmd = NULL;
                TRY
                {
                    std::string matObjectName = md->MaterialOnMesh(meshName);
                    mmd = md->GetMaterial(matObjectName);
                }
                CATCHALL
cyrush's avatar
cyrush committed
591
                {
592 593 594
                }
                ENDTRY

595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
                // Create the appropriate metadata based on the variable type.
                if(type == VISIT_VARTYPE_SCALAR)
                {
                    int treatAsASCII = 0;
                    simv2_VariableMetaData_getTreatAsASCII(h, &treatAsASCII);

                    avtScalarMetaData *scalar = new avtScalarMetaData;
                    scalar->name = name;
                    scalar->originalName = name;
                    scalar->meshName = meshName;
                    scalar->centering = centering;
                    scalar->treatAsASCII = treatAsASCII != 0;
                    scalar->hasDataExtents = false;
                    scalar->units = units;
                    scalar->hasUnits = hasUnits;
whitlocb's avatar
whitlocb committed
610
                    scalar->hideFromGUI = hideFromGUI;
611
                    scalar->matRestricted = RestrictMaterialIndices(h, mmd);
whitlocb's avatar
whitlocb committed
612

613 614 615 616 617 618 619 620 621 622 623
                    md->Add(scalar);
                }
                else if(type == VISIT_VARTYPE_VECTOR)
                {
                    avtVectorMetaData *vector = new avtVectorMetaData;
                    vector->name = name;
                    vector->originalName = name;
                    vector->meshName = meshName;
                    vector->centering = centering;
                    vector->units = units;
                    vector->hasUnits = hasUnits;
whitlocb's avatar
whitlocb committed
624
                    vector->hideFromGUI = hideFromGUI;
625
                    vector->matRestricted = RestrictMaterialIndices(h, mmd);
626 627 628 629 630 631 632 633 634 635 636 637

                    md->Add(vector);
                }
                else if(type == VISIT_VARTYPE_TENSOR)
                {
                    avtTensorMetaData *tensor = new avtTensorMetaData;
                    tensor->name = name;
                    tensor->originalName = name;
                    tensor->meshName = meshName;
                    tensor->centering = centering;
                    tensor->units = units;
                    tensor->hasUnits = hasUnits;
whitlocb's avatar
whitlocb committed
638
                    tensor->hideFromGUI = hideFromGUI;
639
                    tensor->matRestricted = RestrictMaterialIndices(h, mmd);
640 641 642 643 644 645 646 647 648 649 650 651

                    md->Add(tensor);
                }
                else if(type == VISIT_VARTYPE_SYMMETRIC_TENSOR)
                {
                    avtSymmetricTensorMetaData *tensor = new avtSymmetricTensorMetaData;
                    tensor->name = name;
                    tensor->originalName = name;
                    tensor->meshName = meshName;
                    tensor->centering = centering;
                    tensor->units = units;
                    tensor->hasUnits = hasUnits;
whitlocb's avatar
whitlocb committed
652
                    tensor->hideFromGUI = hideFromGUI;
653
                    tensor->matRestricted = RestrictMaterialIndices(h, mmd);
654 655 656 657 658 659 660 661 662 663

                    md->Add(tensor);
                }
                else if(type == VISIT_VARTYPE_LABEL)
                {
                    avtLabelMetaData *label = new avtLabelMetaData;
                    label->name = name;
                    label->originalName = name;
                    label->meshName = meshName;
                    label->centering = centering;
whitlocb's avatar
whitlocb committed
664
                    label->hideFromGUI = hideFromGUI;
665
                    label->matRestricted = RestrictMaterialIndices(h, mmd);
666

667 668 669 670
                    md->Add(label);
                }
                else if(type == VISIT_VARTYPE_ARRAY)
                {
whitlocb's avatar
whitlocb committed
671 672 673
                    int nComponents = 1;
                    simv2_VariableMetaData_getNumComponents(h, &nComponents);

674 675 676 677
                    avtArrayMetaData *arr = new avtArrayMetaData;
                    arr->name = name;
                    arr->originalName = name;
                    arr->meshName = meshName;
whitlocb's avatar
whitlocb committed
678
                    arr->centering = centering;
679 680
                    arr->nVars = nComponents;
                    for(int c = 0; c < nComponents; ++c)
cyrush's avatar
cyrush committed
681
                    {
682 683 684 685 686 687
                        char compname[100];
                        sprintf(compname, "%d", c);
                        arr->compNames.push_back(compname);
                    }
                    arr->units = units;
                    arr->hasUnits = hasUnits;
whitlocb's avatar
whitlocb committed
688
                    arr->hideFromGUI = hideFromGUI;
689
                    arr->matRestricted = RestrictMaterialIndices(h, mmd);
690 691 692 693 694 695 696

                    md->Add(arr);
                }
            }
            free(meshName);
        }
        free(name);
697
    }
698
}
699

700 701 702
// ****************************************************************************
// Method: AddMaterialMetaData
//
cyrush's avatar
cyrush committed
703
// Purpose:
704 705 706 707
//   Add metadata for a material
//
// Arguments:
//
cyrush's avatar
cyrush committed
708
// Returns:
709
//
cyrush's avatar
cyrush committed
710
// Note:
711 712 713 714 715
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 12:13:56 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
716
//
717
// ****************************************************************************
718

719 720 721 722
void
AddMaterialMetaData(avtDatabaseMetaData *md, visit_handle h)
{
    char *name = NULL, *meshName = NULL;
723
    if(simv2_MaterialMetaData_getName(h, &name) == VISIT_OKAY)
724
    {
725
        if(simv2_MaterialMetaData_getMeshName(h, &meshName) == VISIT_OKAY)
726
        {
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751
            int nMat = 0;
            if(simv2_MaterialMetaData_getNumMaterialName(h, &nMat) == VISIT_OKAY)
            {
                avtMaterialMetaData *material = new avtMaterialMetaData;
                material->name = name;
                material->originalName = name;
                material->meshName = meshName;
                material->numMaterials = nMat;
                material->materialNames.clear();

                for (int m = 0; m < nMat; m++)
                {
                    char *matname = NULL;
                    if(simv2_MaterialMetaData_getMaterialName(h, m, &matname) == VISIT_OKAY)
                    {
                        material->materialNames.push_back(matname);
                        free(matname);
                    }
                    else
                        material->materialNames.push_back("");
                }

                md->Add(material);
            }
            free(meshName);
752
        }
753 754 755 756 757 758 759
        free(name);
    }
}

// ****************************************************************************
// Method: NameListToStringVector
//
cyrush's avatar
cyrush committed
760
// Purpose:
761 762 763 764
//   Converts a name list to a string vector.
//
// Arguments:
//
cyrush's avatar
cyrush committed
765
// Returns:
766
//
cyrush's avatar
cyrush committed
767
// Note:
768 769 770 771 772
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 13:06:44 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
773
//
774 775 776 777 778 779 780 781 782
// ****************************************************************************

void
NameListToStringVector(visit_handle h, stringVector &vec)
{
    int n;
    if(simv2_NameList_getNumName(h, &n) == VISIT_OKAY)
    {
        for(int i = 0; i < n; ++i)
whitlocb's avatar
whitlocb committed
783
        {
784 785 786 787 788 789
            char *name = NULL;
            if(simv2_NameList_getName(h, i, &name) == VISIT_OKAY)
            {
                vec.push_back(name);
                free(name);
            }
whitlocb's avatar
whitlocb committed
790
        }
791 792
    }
}
793

794 795 796
// ****************************************************************************
// Method: AddSpeciesMetaData
//
cyrush's avatar
cyrush committed
797
// Purpose:
798 799 800 801
//   Adds species metadata.
//
// Arguments:
//
cyrush's avatar
cyrush committed
802
// Returns:
803
//
cyrush's avatar
cyrush committed
804
// Note:
805 806 807 808 809
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 13:07:12 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
810
//
811 812 813 814 815 816 817 818 819
// ****************************************************************************

void
AddSpeciesMetaData(avtDatabaseMetaData *md, visit_handle h)
{
    char *name = NULL, *meshName = NULL, *matName = NULL;
    if(simv2_SpeciesMetaData_getName(h, &name) == VISIT_OKAY)
    {
        if(simv2_SpeciesMetaData_getMeshName(h, &meshName) == VISIT_OKAY)
820
        {
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835
            if(simv2_SpeciesMetaData_getMaterialName(h, &matName) == VISIT_OKAY)
            {
                int nSpecies = 0;
                if(simv2_SpeciesMetaData_getNumSpeciesName(h, &nSpecies) == VISIT_OKAY)
                {
                    vector<int>   numSpecies;
                    vector<vector<string> > speciesNames;
                    for(int i = 0; i < nSpecies; ++i)
                    {
                        visit_handle s;
                        if(simv2_SpeciesMetaData_getSpeciesName(h, i, &s) == VISIT_OKAY)
                        {
                            stringVector onelist;
                            NameListToStringVector(s, onelist);

836
                            numSpecies.push_back(static_cast<int>(onelist.size()));
837 838 839
                            speciesNames.push_back(onelist);
                        }
                    }
840 841

                    avtSpeciesMetaData *species = new avtSpeciesMetaData(name,
cyrush's avatar
cyrush committed
842
                        meshName, matName, static_cast<int>(numSpecies.size()), numSpecies,
843 844 845
                        speciesNames);

                    md->Add(species);
cyrush's avatar
cyrush committed
846
                }
847 848 849
                free(matName);
            }
            free(meshName);
850
        }
851
        free(name);
852
    }
853
}
854

855 856 857
// ****************************************************************************
// Method: AddCurveMetaData
//
cyrush's avatar
cyrush committed
858
// Purpose:
859 860 861 862
//   Adds curve metadata.
//
// Arguments:
//
cyrush's avatar
cyrush committed
863
// Returns:
864
//
cyrush's avatar
cyrush committed
865
// Note:
866 867 868 869 870
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 13:22:56 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
871
//
872
// ****************************************************************************
whitlocb's avatar
whitlocb committed
873

874 875 876 877 878 879 880 881 882 883
void
AddCurveMetaData(avtDatabaseMetaData *md, visit_handle h)
{
    char *name = NULL;
    if(simv2_CurveMetaData_getName(h, &name) == VISIT_OKAY)
    {
        avtCurveMetaData *curve = new avtCurveMetaData;
        curve->name = name;
        curve->originalName = name;
        free(name);
whitlocb's avatar
whitlocb committed
884

885
        // Get axis labels
886
        char *xLabel = NULL, *yLabel = NULL;
887
        if(simv2_CurveMetaData_getXLabel(h, &xLabel) == VISIT_OKAY)
888
        {
889 890
            curve->xLabel = xLabel;
            free(xLabel);
whitlocb's avatar
whitlocb committed
891
        }
892
        if(simv2_CurveMetaData_getYLabel(h, &yLabel) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
893
        {
894 895
            curve->yLabel = yLabel;
            free(yLabel);
896
        }
897 898

        // Get axis units
899
        char *xUnits = NULL, *yUnits = NULL;
900
        if(simv2_CurveMetaData_getXUnits(h, &xUnits) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
901
        {
902 903
            curve->xUnits = xUnits;
            free(xUnits);
whitlocb's avatar
whitlocb committed
904
        }
905
        if(simv2_CurveMetaData_getYUnits(h, &yUnits) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
906
        {
907 908
            curve->yUnits = yUnits;
            free(yUnits);
whitlocb's avatar
whitlocb committed
909 910
        }

911 912 913 914 915 916 917
        md->Add(curve);
    }
}

// ****************************************************************************
// Method: AddExpressionMetaData
//
cyrush's avatar
cyrush committed
918 919
// Purpose:
//
920 921 922
//
// Arguments:
//
cyrush's avatar
cyrush committed
923
// Returns:
924
//
cyrush's avatar
cyrush committed
925
// Note:
926 927 928 929 930
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 13:28:23 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
931
//
932 933 934
//   Burlen Loring, Mon Apr 28 14:54:13 PDT 2014
//   fixed leak, delete the expression after adding it.
//
935 936 937 938 939 940 941 942 943
// ****************************************************************************

void
AddExpressionMetaData(avtDatabaseMetaData *md, visit_handle h)
{
    char *name = NULL, *definition = NULL;
    if(simv2_ExpressionMetaData_getName(h, &name) == VISIT_OKAY)
    {
        if(simv2_ExpressionMetaData_getDefinition(h, &definition) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
944
        {
945 946
            int vartype;
            if(simv2_ExpressionMetaData_getType(h, &vartype) == VISIT_OKAY)
whitlocb's avatar
whitlocb committed
947
            {
948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968
                Expression *newexp = new Expression;
                newexp->SetName(name);
                newexp->SetDefinition(definition);
                if(vartype == VISIT_VARTYPE_MESH)
                    newexp->SetType(Expression::Mesh);
                else if(vartype == VISIT_VARTYPE_SCALAR)
                    newexp->SetType(Expression::ScalarMeshVar);
                else if(vartype == VISIT_VARTYPE_VECTOR)
                    newexp->SetType(Expression::VectorMeshVar);
                else if(vartype == VISIT_VARTYPE_TENSOR)
                    newexp->SetType(Expression::TensorMeshVar);
                else if(vartype == VISIT_VARTYPE_SYMMETRIC_TENSOR)
                    newexp->SetType(Expression::SymmetricTensorMeshVar);
                else if(vartype == VISIT_VARTYPE_MATERIAL)
                    newexp->SetType(Expression::Material);
                else if(vartype == VISIT_VARTYPE_MATSPECIES)
                    newexp->SetType(Expression::Species);
                else if(vartype == VISIT_VARTYPE_CURVE)
                    newexp->SetType(Expression::CurveMeshVar);
                else
                    newexp->SetType(Expression::Unknown);
969

970
                md->AddExpression(newexp);
971
                delete newexp;
972 973
            }
            free(definition);
whitlocb's avatar
whitlocb committed
974
        }
975 976 977 978 979 980 981
        free(name);
    }
}

// ****************************************************************************
// Method: CommandMetaDataToCommandSpec
//
cyrush's avatar
cyrush committed
982
// Purpose:
983 984 985 986
//   Populates avtSimulationCommandSpecification from CommandMetaData.
//
// Arguments:
//
cyrush's avatar
cyrush committed
987
// Returns:
988
//
cyrush's avatar
cyrush committed
989
// Note:
990 991 992 993 994
//
// Programmer: Brad Whitlock
// Creation:   Tue Mar  9 13:46:29 PST 2010
//
// Modifications:
cyrush's avatar
cyrush committed
995
//
996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008
// ****************************************************************************

void
CommandMetaDataToCommandSpec(visit_handle h, avtSimulationCommandSpecification &scs)
{
    char *name = NULL;
    if(simv2_CommandMetaData_getName(h, &name) == VISIT_OKAY)
    {
        scs.SetName(name);
        scs.SetArgumentType(avtSimulationCommandSpecification::CmdArgNone);
        free(name);
    }
}
whitlocb's avatar
whitlocb committed
1009
#endif
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021

// ****************************************************************************
//  Method: avtSimV2FileFormat::PopulateDatabaseMetaData
//
//  Purpose:
//      Fill the simulation metadata with the parameters from the file for
//      the mdserver.  Get the info from the simulation for the engine.
//
//  Programmer: Brad Whitlock
//  Creation:   Tue Mar  9 10:31:56 PST 2010
//
//  Modifications:
1022 1023
//    Mark C. Miller, Tue Oct 19 20:23:57 PDT 2010
//    Added test of debug level before calling MD's Print() method.
1024 1025 1026 1027
//
//    Brad Whitlock, Fri Aug 10 10:38:20 PDT 2012
//    I moved CalculateBoundaries into the simv2 runtime.
//
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044
// ****************************************************************************

void
avtSimV2FileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
    md->SetIsSimulation(true);
#ifdef MDSERVER
    md->SetSimInfo(simInfo);
#else
    const char *mName = "avtSimV2FileFormat::PopulateDatabaseMetaData: ";

    visit_handle h = simv2_invoke_GetMetaData();
    if(h == VISIT_INVALID_HANDLE)
        return;

    int simMode, currentCycle;
    double currentTime;
cyrush's avatar
cyrush committed
1045
    if(simv2_SimulationMetaData_getData(h, simMode, currentCycle,
1046 1047 1048 1049 1050
        currentTime) == VISIT_ERROR)
    {
        debug4 << mName << "Can't get data from simulation metadata" << endl;
        simv2_FreeObject(h);
        return;
1051 1052
    }

1053 1054 1055 1056
    md->SetCycle(timestep, currentCycle);
    md->SetTime(timestep, currentTime);

    switch(simMode)
1057
    {
1058 1059 1060 1061 1062 1063 1064 1065 1066
    case VISIT_SIMMODE_UNKNOWN:
        md->GetSimInfo().SetMode(avtSimulationInformation::Unknown);
        break;
    case VISIT_SIMMODE_RUNNING:
        md->GetSimInfo().SetMode(avtSimulationInformation::Running);
        break;
    case VISIT_SIMMODE_STOPPED:
        md->GetSimInfo().SetMode(avtSimulationInformation::Stopped);
        break;
1067
    }
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078

    //
    // Add the meshes.
    //
    int numMeshes = 0;
    simv2_SimulationMetaData_getNumMeshes(h, numMeshes);
    for(int m = 0; m < numMeshes; m++)
    {
        visit_handle mHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getMesh(h, m, mHandle) == VISIT_OKAY)
            AddMeshMetaData(md, mHandle);
1079 1080
    }

1081
    //
1082
    // Add the Curves
cyrush's avatar
cyrush committed
1083
    //
1084 1085 1086
    int numCurves = 0;
    simv2_SimulationMetaData_getNumCurves(h, numCurves);
    for (int i=0; i < numCurves; i++)
1087
    {
1088 1089 1090
        visit_handle iHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getCurve(h, i, iHandle) == VISIT_OKAY)
            AddCurveMetaData(md, iHandle);
1091
    }
1092 1093
    for(int i = 0; i < md->GetNumCurves(); ++i)
        curveMeshes.insert(md->GetCurve(i)->name);
1094

1095 1096
    //
    // Add the materials
cyrush's avatar
cyrush committed
1097
    //
1098 1099 1100 1101 1102 1103 1104
    int numMaterials = 0;
    simv2_SimulationMetaData_getNumMaterials(h, numMaterials);
    for (int i=0; i < numMaterials; i++)
    {
        visit_handle iHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getMaterial(h, i, iHandle) == VISIT_OKAY)
            AddMaterialMetaData(md, iHandle);
1105 1106
    }

1107 1108
    //
    // Add the Species
cyrush's avatar
cyrush committed
1109
    //
1110 1111 1112 1113 1114 1115 1116 1117
    int numSpecies = 0;
    simv2_SimulationMetaData_getNumSpecies(h, numSpecies);
    for (int i=0; i < numSpecies; i++)
    {
        visit_handle iHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getSpecies(h, i, iHandle) == VISIT_OKAY)
            AddSpeciesMetaData(md, iHandle);
    }
cyrush's avatar
cyrush committed
1118

1119
    //
1120 1121 1122 1123 1124
    // Add the variables
    //
    int numVariables = 0;
    simv2_SimulationMetaData_getNumVariables(h, numVariables);
    for (int s=0; s < numVariables; s++)
1125
    {
1126 1127 1128
        visit_handle vHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getVariable(h, s, vHandle) == VISIT_OKAY)
            AddVariableMetaData(md, vHandle);
1129
    }
1130 1131

    //
1132
    // Add the Expressions
cyrush's avatar
cyrush committed
1133
    //
1134 1135 1136 1137 1138 1139 1140 1141 1142
    int numExpressions = 0;
    simv2_SimulationMetaData_getNumExpressions(h, numExpressions);
    for (int i=0; i < numExpressions; i++)
    {
        visit_handle iHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getExpression(h, i, iHandle) == VISIT_OKAY)
            AddExpressionMetaData(md, iHandle);
    }

1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
    //
    // Add simulation commands.
    //
    int numCommands = 0;
    simv2_SimulationMetaData_getNumGenericCommands(h, numCommands);
    for (int i=0; i < numCommands; i++)
    {
        visit_handle cHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getGenericCommand(h, i, cHandle) == VISIT_OKAY)
        {
            avtSimulationCommandSpecification spec;
            CommandMetaDataToCommandSpec(cHandle, spec);
            md->GetSimInfo().AddGenericCommands(spec);
        }
    }

    simv2_SimulationMetaData_getNumCustomCommands(h, numCommands);
    for (int i=0; i < numCommands; i++)
    {
        visit_handle cHandle = VISIT_INVALID_HANDLE;
        if(simv2_SimulationMetaData_getCustomCommand(h, i, cHandle) == VISIT_OKAY)
        {
            avtSimulationCommandSpecification spec;
            CommandMetaDataToCommandSpec(cHandle, spec);
            md->GetSimInfo().AddCustomCommands(spec);
        }
    }
whitlocb's avatar
whitlocb committed
1170 1171 1172

    // Get domain boundary information
    int numMultiblock = 0;
1173
    for (int m=0; m < md->GetNumMeshes(); m++)
whitlocb's avatar
whitlocb committed
1174
    {
1175
        if(md->GetMesh(m)->numBlocks > 1)
whitlocb's avatar
whitlocb committed
1176 1177 1178 1179
            numMultiblock++;
    }
    if(numMultiblock > 0)
    {
1180
        for (int i=0; i < md->GetNumMeshes(); i++)
whitlocb's avatar
whitlocb committed
1181
        {
1182
            if(md->GetMesh(i)->numBlocks > 1)
whitlocb's avatar
whitlocb committed
1183
            {
1184 1185
                debug4 << mName << "Getting domain boundaries for mesh: " << md->GetMesh(i)->name << endl;
                visit_handle boundaries = simv2_invoke_GetDomainBoundaries(md->GetMesh(i)->name.c_str());
whitlocb's avatar
whitlocb committed
1186 1187 1188 1189
                if(boundaries != VISIT_INVALID_HANDLE)
                {
                    // Cache the domain boundary information
                    avtStructuredDomainBoundaries *sdb = (avtStructuredDomainBoundaries *)
1190
                        simv2_DomainBoundaries_avt(boundaries);
whitlocb's avatar
whitlocb committed
1191 1192 1193
                    if(sdb != NULL)
                    {
                        void_ref_ptr vr = void_ref_ptr(sdb,avtStructuredDomainBoundaries::Destruct);
1194
                        const char *cache_meshname = (numMultiblock > 1) ? md->GetMesh(i)->name.c_str() : "any_mesh";
whitlocb's avatar
whitlocb committed
1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205
                        debug4 << mName << "Caching domain boundaries for mesh:" << cache_meshname << endl;
                        cache->CacheVoidRef(cache_meshname,
                                AUXILIARY_DATA_DOMAIN_BOUNDARY_INFORMATION,
                                timestep, -1, vr);
                    }
                    else
                    {
                        debug4 << mName << "Could not obtain domain boundaries from returned "
                                           "simulation object."
                               << endl;
                    }
1206
                    simv2_DomainBoundaries_free(boundaries);
whitlocb's avatar
whitlocb committed
1207 1208 1209 1210 1211
                }
                else
                {
                    debug4 << mName << "The simulation did not return a valid "
                                       "domain boundaries object for mesh "
1212
                           << md->GetMesh(i)->name << endl;
whitlocb's avatar
whitlocb committed
1213 1214 1215 1216 1217 1218 1219
                }
            }
        }
    }

    // Get domain nesting information
    int numAMR = 0;
1220
    for (int m=0; m < md->GetNumMeshes(); m++)
whitlocb's avatar
whitlocb committed
1221
    {
1222
        if(md->GetMesh(m)->meshType == AVT_AMR_MESH)
whitlocb's avatar
whitlocb committed
1223 1224 1225 1226
            numAMR++;
    }
    if(numAMR > 0)
    {
1227
        for (int i=0; i < md->GetNumMeshes(); i++)
whitlocb's avatar
whitlocb committed
1228
        {
1229
            if(md->GetMesh(i)->meshType == AVT_AMR_MESH)
whitlocb's avatar
whitlocb committed
1230
            {
1231 1232
                debug4 << mName << "Getting domain nesting for mesh: " << md->GetMesh(i)->name << endl;
                visit_handle nesting = simv2_invoke_GetDomainNesting(md->GetMesh(i)->name.c_str());
whitlocb's avatar
whitlocb committed
1233 1234 1235
                if(nesting != VISIT_INVALID_HANDLE)
                {
                    avtStructuredDomainNesting *sdn = (avtStructuredDomainNesting *)
1236
                        simv2_DomainNesting_avt(nesting);
whitlocb's avatar
whitlocb committed
1237 1238 1239
                    if(sdn != NULL)
                    {
                        void_ref_ptr vr = void_ref_ptr(sdn, avtStructuredDomainNesting::Destruct);
1240
                        const char *cache_meshname = (numAMR > 1) ? md->GetMesh(i)->name.c_str() : "any_mesh";
whitlocb's avatar
whitlocb committed
1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
                        debug4 << mName << "Caching domain nesting for mesh:" << cache_meshname << endl;
                        cache->CacheVoidRef(cache_meshname,
                                            AUXILIARY_DATA_DOMAIN_NESTING_INFORMATION,
                                            timestep, -1, vr);
                    }
                    else
                    {
                        debug4 << mName << "Could not obtain domain nesting from returned "
                                           "simulation object."
                               << endl;
                    }
1252
                    simv2_DomainNesting_free(nesting);
whitlocb's avatar
whitlocb committed
1253 1254 1255 1256 1257
                }
                else
                {
                    debug4 << mName << "The simulation did not return a valid "
                                       "domain nesting object for mesh "
1258
                           << md->GetMesh(i)->name << endl;
whitlocb's avatar
whitlocb committed
1259 1260 1261 1262 1263
                }
            }
        }
    }

1264
    if (DebugStream::Level4())
1265 1266
    {
        debug4 << mName << "Returning meta data:" << endl;
1267
        md->Print(DebugStream::Stream4());
1268
    }
1269
    simv2_SimulationMetaData_free(h);
1270 1271 1272
#endif
}

1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336
#ifndef MDSERVER
// ****************************************************************************
// Method: PackageGlobalIdArray
//
// Purpose:
//   Package the global cells/nodes as a VTK int array.
//
// Arguments:
//   global : The data array.
//   name   : Then name of the data array we're making.
//
// Returns:    A VTK int array with the global cell/node ids.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Fri Jun 13 10:53:32 PDT 2014
//
// Modifications:
//
// ****************************************************************************

static vtkIntArray *
PackageGlobalIdArray(visit_handle global, const char *name)
{
    vtkIntArray *arr = NULL;
    // Get the global cell id information
    int owner, dataType, nComps, nTuples = 0;
    void *data = 0;
    if(simv2_VariableData_getData(global, owner, dataType, nComps, nTuples, data))
    {
        arr = vtkIntArray::New();
        arr->SetName(name);
        arr->SetNumberOfTuples(nTuples);
        if(dataType == VISIT_DATATYPE_INT)
            memcpy(arr->GetVoidPointer(0), data, sizeof(int) * nTuples);
        else
        {
            int *iptr = (int *)arr->GetVoidPointer(0);
            const long *lptr = (const long *)data;
            for(int i = 0; i < nTuples; ++i)
                iptr[i] = lptr[i];
        }
    }
    return arr;
}

// ****************************************************************************
// Method: CreateUnstructuredMeshGlobalCellIds
//
// Purpose:
//   Creates global cell ids for unstructured mesh.
//
// Arguments:
//   h : The handle to the unstructured mesh.
//
// Returns:    A pointer to the VTK data array containing the ids.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Fri Jun 13 10:47:37 PDT 2014
//
// Modifications:
1337 1338
//    Kathleen Biagas, Tue Jun 24 10:25:03 MST 2014
//    Check for valid handle before packaging.
1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
//
// ****************************************************************************

static vtkIntArray *
CreateUnstructuredMeshGlobalCellIds(visit_handle h)
{
    vtkIntArray *retval = NULL;
    visit_handle globalCells = VISIT_INVALID_HANDLE;
    if(simv2_UnstructuredMesh_getGlobalCellIds(h, &globalCells) == VISIT_OKAY)
    {
1349 1350
        if (globalCells != VISIT_INVALID_HANDLE)
            retval = PackageGlobalIdArray(globalCells, "avtGlobalZoneIds");
1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371
    }
    return retval;
}

// ****************************************************************************
// Method: CreateUnstructuredMeshGlobalNodeIds
//
// Purpose:
//   Creates global node ids for unstructured mesh.
//
// Arguments:
//   h : The handle to the unstructured mesh.
//
// Returns:    A pointer to the VTK data array containing the ids.
//
// Note:       
//
// Programmer: Brad Whitlock
// Creation:   Fri Jun 13 10:47:37 PDT 2014
//
// Modifications:
1372 1373
//    Kathleen Biagas, Tue Jun 24 10:25:03 MST 2014
//    Check for valid handle before packaging.
1374 1375 1376 1377 1378 1379 1380 1381 1382 1383
//
// ****************************************************************************

static vtkIntArray *
CreateUnstructuredMeshGlobalNodeIds(visit_handle h)
{
    vtkIntArray *retval = NULL;
    visit_handle globalNodes = VISIT_INVALID_HANDLE;
    if(simv2_UnstructuredMesh_getGlobalNodeIds(h, &globalNodes) == VISIT_OKAY)
    {
1384 1385
        if (globalNodes != VISIT_INVALID_HANDLE)
            retval = PackageGlobalIdArray(globalNodes, "avtGlobalNodeIds");
1386 1387 1388 1389 1390
    }
    return retval;
}
#endif

1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408
// ****************************************************************************
//  Method: avtSimV2FileFormat::GetMesh
//
//  Purpose:
//      For the mdserver, do nothing.
//      For the engine, return a C-api mesh converted to a vtkDataSet.
//
//  Arguments:
//      domain      The index of the domain.  If there are NDomains, this
//                  value is guaranteed to be between 0 and NDomains-1,
//                  regardless of block origin.
//      meshname    The name of the mesh of interest.  This can be ignored if
//                  there is only one mesh.
//
//  Programmer: Brad Whitlock
//  Creation:   Thu Feb  5 11:50:58 PST 2009
//
//  Modifications:
1409 1410
//    Brad Whitlock, Fri Jun 13 10:56:13 PDT 2014
//    I added global nodes/cell support.
1411
//
1412 1413 1414
//    Kathleen Biagas, Fri Jul 25 09:13:45 MST 2014
//    Set a new mesh meta data flag when polyhdral zones are split.
//
1415 1416 1417 1418 1419 1420
// ****************************************************************************

vtkDataSet *
avtSimV2FileFormat::GetMesh(int domain, const char *meshname)
{
#ifdef MDSERVER
1421
    (void)meshname;
1422 1423 1424 1425 1426 1427 1428 1429
    return NULL;
#else

    if (curveMeshes.count(meshname))
    {
        return GetCurve(meshname);
    }

whitlocb's avatar
whitlocb committed
1430
    visit_handle h = simv2_invoke_GetMesh(domain, meshname);
1431

whitlocb's avatar
whitlocb committed
1432
    // If the mesh could not be created then return.
whitlocb's avatar
whitlocb committed
1433
    if(h == VISIT_INVALID_HANDLE)
whitlocb's avatar
whitlocb committed
1434
        return NULL;
1435 1436

    vtkDataSet *ds = 0;
cyrush's avatar
cyrush committed
1437
    avtPolyhedralSplit *phSplit = 0;
1438 1439
    TRY
    {
whitlocb's avatar
whitlocb committed
1440 1441
        int objType = simv2_ObjectType(h);
        switch (objType)
1442
        {
whitlocb's avatar
whitlocb committed
1443 1444
        case VISIT_CURVILINEAR_MESH:
            ds = SimV2_GetMesh_Curvilinear(h);
1445
            break;
whitlocb's avatar
whitlocb committed
1446 1447
        case VISIT_RECTILINEAR_MESH:
            ds = SimV2_GetMesh_Rectilinear(h);
1448
            break;
whitlocb's avatar
whitlocb committed
1449
        case VISIT_UNSTRUCTURED_MESH:
1450 1451 1452 1453 1454 1455 1456
        {
            ds = SimV2_GetMesh_Unstructured(domain, h, &phSplit);

            // Cache the polyhedral split object in case we need it for
            // variables later.
            if(phSplit != 0)
            {
cyrush's avatar
cyrush committed
1457
                void_ref_ptr vr = void_ref_ptr(phSplit, avtPolyhedralSplit::Destruct);
1458 1459 1460 1461
                debug4 << "Caching polyhedral split for mesh:" << meshname << endl;
                cache->CacheVoidRef(meshname,
                                    AUXILIARY_DATA_POLYHEDRAL_SPLIT,
                                    timestep, domain, vr);
1462
                metadata->SetZonesWereSplit(meshname, true);
1463
            }
1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
            else
            {
                // Try and add the global ids if we have not split the mesh.

                vtkIntArray *globalCellIds = CreateUnstructuredMeshGlobalCellIds(h);
                if(globalCellIds != NULL)
                {
                    void_ref_ptr vr = void_ref_ptr(globalCellIds, avtVariableCache::DestructVTKObject);
                    cache->CacheVoidRef(meshname, AUXILIARY_DATA_GLOBAL_ZONE_IDS, timestep,
                                        domain, vr);
                }

                vtkIntArray *globalNodeIds = CreateUnstructuredMeshGlobalNodeIds(h);
                if(globalNodeIds != NULL)
                {
                    void_ref_ptr vr = void_ref_ptr(globalNodeIds, avtVariableCache::DestructVTKObject);
                    cache->CacheVoidRef(meshname, AUXILIARY_DATA_GLOBAL_NODE_IDS, timestep,
                                        domain, vr);
                }
            }
1484
        }
1485
            break;
whitlocb's avatar
whitlocb committed
1486 1487
        case VISIT_POINT_MESH:
            ds = SimV2_GetMesh_Point(h);
1488
            break;
whitlocb's avatar
whitlocb committed
1489 1490
        case VISIT_CSG_MESH:
            ds = SimV2_GetMesh_CSG(h);
1491
            break;
cyrush's avatar
cyrush committed
1492
        default:
1493
            EXCEPTION1(ImproperUseException,
whitlocb's avatar
whitlocb committed
1494 1495
                "The simulation returned a handle that does not correspond "
                "to a mesh.\n");
1496 1497 1498
            break;
        }
    }
1499
    CATCH(VisItException)
1500
    {
1501
        delete phSplit;
whitlocb's avatar
whitlocb committed
1502
        simv2_FreeObject(h);
1503 1504 1505 1506
        RETHROW;
    }
    ENDTRY

whitlocb's avatar
whitlocb committed
1507
    simv2_FreeObject(h);
1508 1509 1510 1511 1512

    return ds;
#endif
}

whitlocb's avatar
whitlocb committed
1513 1514
#ifndef MDSERVER
// ****************************************************************************
1515
// Method: StoreVariableData
whitlocb's avatar
whitlocb committed
1516
//
cyrush's avatar
cyrush committed
1517
// Purpose:
1518
//   Store memory into the new vtkDataArray, taking 2-tuple to 3-tuple conversion
whitlocb's avatar
whitlocb committed
1519 1520 1521 1522 1523 1524 1525
//   into account.
//
// Arguments:
//   array       : The destination vtkDataArray.
//   src         : The source data array.
//   nComponents : The number of components in the data.
//   nTuples     : The numebr of tuples in the data.
1526
//   owner       : The owner of the array.
whitlocb's avatar
whitlocb committed
1527 1528 1529 1530 1531
//
// Programmer: Brad Whitlock
// Creation:   Fri Feb 27 11:12:21 PST 2009
//
// Modifications: