1 2 3 4 5 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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 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 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 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 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 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 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 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938
|
/*****************************************************************************
*
* Copyright (c) 2000 - 2010, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-400124
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtOVERFLOWFileFormat.C //
// ************************************************************************* //
#include <avtOVERFLOWFileFormat.h>
#include <string>
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkUnsignedCharArray.h>
#include <vtkPointData.h>
#include <avtDatabaseMetaData.h>
#include <avtDatabase.h>
#include <avtGhostData.h>
#include <Expression.h>
#include <InvalidVariableException.h>
#include <InvalidFilesException.h>
#include <visit-config.h>
#include <snprintf.h>
using std::string;
using std::map;
//#define SWAP_4_assumeinteger(x) ( ((x) << 24) | (((x) << 8) & 0x00ff0000) | (((x) >> 8) & 0x0000ff00) | ((x) >> 24) )
#define SWAP_4(x) {unsigned char *_v = (unsigned char*)&x; unsigned char t; t=_v[0];_v[0]=_v[3];_v[3]=t; t=_v[1];_v[1]=_v[2];_v[2]=t; }
// ****************************************************************************
// Method: avtOVERFLOW constructor
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
avtOVERFLOWFileFormat::avtOVERFLOWFileFormat(const char *filename)
: avtSTMDFileFormat(&filename, 1)
{
origfilename = filename;
ndomains = 0;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::InitializeFile
//
// Purpose:
// Create grid/solution file names, read the headers from the
// respective files, and determine endianness
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
// Jeremy Meredith, Wed Aug 11 13:56:47 PDT 2004
// Allow naming convention to have a single grid file for all cycles.
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::InitializeFile()
{
// This is a hack to create a grid and solution file
// name, no matter which one was given. We just force
// the first character of the filename to an x or a q
// and see if that gives us good files.
//
// Find the last slash -- indicates the first character of the filename
//
int lastslash;
for (lastslash=origfilename.size()-2; lastslash>0; lastslash--)
{
if (origfilename[lastslash]=='/')
break;
}
//
// Now change the first character after it to an x/q
//
string gridfilename(origfilename);
string solfilename(origfilename);
gridfilename[lastslash+1] = 'x';
solfilename[lastslash+1] = 'q';
//
// Try to open the files
//
gridin.open(gridfilename.c_str());
if (!gridin)
{
// Okay, that didn't work. But it might simply be the case that
// there was only one grid file for all cycles; remove the cycle
// number from the grid file name and try again. This is assumed
// to be all digits in the file name itself.
string gridfilename_withnumbers = gridfilename;
gridfilename = "";
for (int i=0; i<gridfilename_withnumbers.length(); i++)
{
if (i <= lastslash ||
gridfilename_withnumbers[i] < '0' ||
gridfilename_withnumbers[i] > '9')
{
gridfilename += gridfilename_withnumbers[i];
}
}
gridin.open(gridfilename.c_str());
if (!gridin)
{
gridin.close();
EXCEPTION1(InvalidFilesException, gridfilename.c_str());
}
}
solin.open(solfilename.c_str());
if (!solin)
{
gridin.close();
solin.close();
EXCEPTION1(InvalidFilesException, solfilename.c_str());
}
//
// Determine endianness of the file:
//
// We are assuming a FORTRAN unformatted file, which means that
// the first integer in the file is a record length. we are also
// assuming multi-grid, which means that the first record will be
// an integer containing the number of blocks. This means that we
// should get a 4from the first four byte integer no matter what.
//
int testvar;
gridin.read((char*)&testvar, 4);
if (testvar == 4)
{
swap_endian = false;
}
else
{
SWAP_4(testvar);
if (testvar == 4)
{
swap_endian = true;
}
else
{
gridin.close();
solin.close();
EXCEPTION1(InvalidFilesException, gridfilename.c_str());
}
}
// return to the beginning of the file
gridin.seekg(0, ios::beg);
//
// Read the grid and solution headers
//
ReadGridHeader();
ReadSolHeader();
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::ReadGridHeader
//
// Purpose:
// Read the header from the grid file. It contains
// sizes of each domain. Keep track of where the header
// ended in the file.
//
// Arguments:
//
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
// Brad Whitlock, Wed Aug 11 17:49:12 PST 2004
// Made it compile on Windows.
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::ReadGridHeader()
{
// The first record is the number of domains
char *ndomsbuffer = read_fortran_record(gridin);
char *ptr = ndomsbuffer;
ndomains = parse_int(ptr);
delete[] ndomsbuffer;
// The next one contains ndomains triplets of nx,ny,nz sizes
char *dimsbuffer = read_fortran_record(gridin);
ptr = dimsbuffer;
nx = new int[ndomains];
ny = new int[ndomains];
nz = new int[ndomains];
for (int i=0; i<ndomains; i++)
{
nx[i] = parse_int(ptr);
ny[i] = parse_int(ptr);
nz[i] = parse_int(ptr);
}
delete[] dimsbuffer;
//
// Keep track of the start position of the real data so we can
// seke directly to it later.
//
start_of_coords = gridin.tellg();
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::ReadSolHeader
//
// Purpose:
// Read the header from the solution file. It contains
// some information redundant with the grid file (like domain
// sizes), but other information like number of mesh variables
// and number of species. Also, read the global variables
// from the first domain's record. Keep track of where the
// header ended in the file.
//
// Arguments:
// none
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
// Brad Whitlock, Wed Aug 11 17:49:12 PST 2004
// Made it compile on Windows.
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::ReadSolHeader()
{
// The first record is the number of domains, just
// like the grid file.
char *ndomsbuffer = read_fortran_record(solin);
delete[] ndomsbuffer;
// Then we've got all the dims, just like the grid file,
// except that after all the dims come NQ and NQC, which we need.
char *dimsbuffer = read_fortran_record(solin);
char *ptr = dimsbuffer;
int i;
for (i=0; i<ndomains; i++)
{
ptr += 12;
}
nq = parse_int(ptr);
nqc = parse_int(ptr);
// When we retrieve the global variables, it expects at least
// two RGAS values, even if NQC is less than two. Don't know why.
nspec = (2 > nqc) ? 2 : nqc;
delete[] dimsbuffer;
//
// Keep track of the start position of the real data so we can
// seek directly to it later.
//
start_of_data = solin.tellg();
//
// Read global variables
//
char *varbuff = read_fortran_record(solin);
char *varbuffptr = varbuff;
varmap["FSMACH"] = parse_float(varbuffptr);
varmap["ALPHA"] = parse_float(varbuffptr);
varmap["REY"] = parse_float(varbuffptr);
varmap["TIME"] = parse_float(varbuffptr);
varmap["GAMINF"] = parse_float(varbuffptr);
varmap["BETA"] = parse_float(varbuffptr);
varmap["TINF"] = parse_float(varbuffptr);
varmap["IGAM"] = parse_float(varbuffptr);
varmap["HTINF"] = parse_float(varbuffptr);
varmap["HT1"] = parse_float(varbuffptr);
varmap["HT2"] = parse_float(varbuffptr);
for (i=0; i<nspec; i++)
{
char rgas[1024];
SNPRINTF(rgas, 1024, "RGAS%d", i+1);
varmap[rgas] = parse_float(varbuffptr);
}
varmap["FSMACH"] = parse_float(varbuffptr);
varmap["TVREF"] = parse_float(varbuffptr);
varmap["DTVREF"] = parse_float(varbuffptr);
delete[] varbuff;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::ReadCoords
//
// Purpose:
// Read the coordinate (x,y,z) and IBLANK data for a single domain.
//
// Arguments:
// domain the domain number (zero-origin) (i)
// x,y,z,ib the output arrays (o)
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::ReadCoords(int domain,
float *&x, float *&y, float *&z, int *&ib)
{
//
// Go to the beginning of the coordinate data, and skip over
// domains one at a time until you reach the right one. This
// could have also been done with a direct numerical calculation
// but this was just as easy, and the seeking seemed fast enough.
//
int record_size;
gridin.seekg(start_of_coords, ios::beg);
for (int i=0; i<domain; i++)
{
record_size = read_int(gridin);
gridin.seekg(record_size + 4, ios::cur);
}
//
// Allocate array space
//
int npts = nx[domain]*ny[domain]*nz[domain];
x = new float[npts];
y = new float[npts];
z = new float[npts];
ib = new int[npts];
//
// Read the raw buffers
//
record_size = read_int(gridin);
gridin.read((char*)x, 4*npts);
gridin.read((char*)y, 4*npts);
gridin.read((char*)z, 4*npts);
gridin.read((char*)ib, 4*npts);
//
// Swap endianness if necessary
//
if (swap_endian)
{
for (int i=0; i<npts; i++)
{
SWAP_4(x[i]);
SWAP_4(y[i]);
SWAP_4(z[i]);
SWAP_4(ib[i]);
}
}
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::ReadCoords
//
// Purpose:
// Read the coordinate (x,y,z) and IBLANK data for a single domain.
//
// Arguments:
// domain the domain number (zero-origin) (i)
// var the index of the variable (zero-origin) (i)
// vals the output array (o)
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::ReadVariable(int domain, int var, float *&vals)
{
//
// Go to the beginning of the coordinate data, and skip over
// domains one at a time until you reach the right one. This
// could have also been done with a direct numerical calculation
// but this was just as easy, and the seeking seemed fast enough.
//
// This is a little different from ReadCoords because the
// solution file has two records per domain -- the global variables
// and the mesh variables.
int record_size;
solin.seekg(start_of_data, ios::beg);
for (int i=0; i<domain; i++)
{
record_size = read_int(solin);
solin.seekg(record_size + 4, ios::cur);
record_size = read_int(solin);
solin.seekg(record_size + 4, ios::cur);
}
//
// And skip over the globals for this domain
//
record_size = read_int(solin);
solin.seekg(record_size + 4, ios::cur);
//
// Allocate array space
//
int npts = nx[domain]*ny[domain]*nz[domain];
vals = new float[npts];
//
// Skip over the other variables, since var is an index
//
solin.seekg(var*npts*4, ios::cur);
//
// Read the raw data
//
record_size = read_int(solin);
solin.read((char*)vals, 4*npts);
//
// Swap endianness if necessary
//
if (swap_endian)
{
for (int i=0; i<npts; i++)
{
SWAP_4(vals[i]);
}
}
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::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: meredith -- generated by xml2avt
// Creation: Tue Jul 20 13:00:41 PST 2004
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::FreeUpResources(void)
{
gridin.close();
solin.close();
delete[] nx;
delete[] ny;
delete[] nz;
//
// ndomains is our key to know when we closed the files
//
ndomains = 0;
nx = ny = nz = NULL;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::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: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
// Brad Whitlock, Wed Aug 11 17:56:42 PST 2004
// Made it build on Windows.
//
// Hank Childs, Tue Aug 31 12:46:29 PDT 2004
// Remove variable "gn" which was accidentally left over from testing.
//
// ****************************************************************************
void
avtOVERFLOWFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md)
{
//
// We are using ndomains as a flag to indicate if we have read
// the file.
//
if (!ndomains)
{
InitializeFile();
}
//
// Create the mesh metadata
//
avtMeshMetaData *mesh = new avtMeshMetaData;
mesh->name = "mesh";
mesh->meshType = AVT_CURVILINEAR_MESH;
mesh->numBlocks = ndomains;
mesh->blockOrigin = 1;
mesh->cellOrigin = 1;
mesh->spatialDimension = 3;
mesh->topologicalDimension = 3;
mesh->blockTitle = "Zones";
mesh->blockPieceName = "Zone";
mesh->hasSpatialExtents = false;
md->Add(mesh);
//
// Add our variable names
//
for (int i=0; i<nq; i++)
{
char name[1024];
SNPRINTF(name, 1024, "Q%d", i+1);
AddScalarVarToMetaData(md, name, "mesh", AVT_NODECENT);
}
//
// The "global" variables work well as expressions with no type
//
for (std::map<string,float>::iterator it=varmap.begin(); it!=varmap.end(); it++)
{
Expression exp;
exp.SetName(it->first);
char def[1024];
sprintf(def, "%f", it->second);
exp.SetDefinition(def);
exp.SetType(Expression::Unknown);
md->AddExpression(&exp);
}
//
// And don't forget we got TIME for this file!
//
md->SetTime(timestep, varmap["TIME"]);
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::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:
// 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: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
//
// Hank Childs, Fri Aug 27 17:16:05 PDT 2004
// Rename ghost data arrays.
//
// ****************************************************************************
vtkDataSet *
avtOVERFLOWFileFormat::GetMesh(int domain, const char *meshname)
{
float *x, *y, *z;
int *ib;
ReadCoords(domain, x,y,z,ib);
//
// Create the VTK objects and connect them up.
//
vtkStructuredGrid *sgrid = vtkStructuredGrid::New();
vtkPoints *points = vtkPoints::New();
sgrid->SetPoints(points);
points->Delete();
//
// Tell the grid what its dimensions are and populate the points array.
//
int dims[3];
dims[0] = nx[domain];
dims[1] = ny[domain];
dims[2] = nz[domain];
sgrid->SetDimensions(dims);
//
// Populate the coordinates and ghost node levels.
//
int npts = nx[domain]*ny[domain]*nz[domain];
points->SetNumberOfPoints(npts);
float *pts = (float *) points->GetVoidPointer(0);
vtkUnsignedCharArray *gn = vtkUnsignedCharArray::New();
gn->SetName("avtGhostNodes");
gn->SetNumberOfTuples(npts);
sgrid->GetPointData()->AddArray(gn);
gn->Delete();
unsigned char *gn_raw = gn->GetPointer(0);
for (int i=0; i<npts; i++)
{
*pts++ = x[i];
*pts++ = y[i];
*pts++ = z[i];
// From the document at:
// http://www.nas.nasa.gov/FAST/RND-93-010.walatka-clucas/htmldocs/chp5.file_io.html
// concerning IBLANKing:
// This indicates that the grid file has integer
// IBLANKing. IBLANKing is used to blank out regions of the
// grid geometry that should not be plotted and to indicate
// the zone interfaces for use in calculating particle
// traces. A single integer IBLANK value for each grid point
// describes the treatment of the grid and solution at that
// point. The file format for IBLANKed grids is included in
// the File Format section starting on page 112XREF. The
// solution and function files which match IBLANKed grids are
// unchanged. Acceptable IBLANK values and their descriptions
// are listed below.
// IBLANK = 1: Grid points requiring no special treatment
// (that is, those not at a boundary where IBLANKing is being
// used) are assigned a positive IBLANK value. The convention
// is to use the value 1.
// IBLANK = 0: The point is turned off. When multiple grids
// overlap (for example, a wing and a fuselage) the
// meaningless data points of one grid which lie inside a
// solid body of another grid should be turned off; the grid
// point is not drawn and the solution data is never used. If
// IBLANK is anything but zero, the data at that point are
// assumed valid.
// IBLANK = -n: Continue into grid n. In simulations involving
// multiple grid zones or a periodic grid, IBLANKing may be
// used at grid interfaces to indicate a continuation of
// physical space. Without IBLANKing, particle traces will
// stop when they reach the edge of a grid. Assigning IBLANK =
// -n (negative n) at the boundary allows a trace calculation
// to continue from the current grid, m, into grid
// n. Likewise, the grid points in grid n along the interface
// with grid m should be assigned IBLANK values of -m. In the
// case of a single periodic mesh or a c-mesh, the trace will
// continue back into the current grid m, if IBLANK = -m is
// assigned at all common boundaries.
// Now, you might think that this means that anything with an
// IBLANK value of "0" would get a nonzero ghost level, and
// anything with an IBLANK value of "1" would get a zero ghost
// level, but you might not be sure what to do with the negative
// IBLANK values, though the first choice would be to have them
// take a nonzero ghost level.
// For some reason the first assumption is wrong -- turning a
// zero IBLANK value seemed to remove more geometry than I wanted.
// Given that, I am only having those nodes with negative IBLANK
// values take a nonzero ghost node value, but leaving the zero
// IBLANKs as zero ghost node values. I am also making use of the
// new "2" ghost node value, as these should be treated slightly
// differently from our other usage of ghost nodes.
*gn_raw = 0;
if (ib[i] < 0)
avtGhostData::AddGhostNodeType(*gn_raw,
NODE_NOT_APPLICABLE_TO_PROBLEM);
gn_raw++;
}
delete[] x;
delete[] y;
delete[] z;
delete[] ib;
return sgrid;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::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:
// 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.
// varname The name of the variable requested.
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
vtkDataArray *
avtOVERFLOWFileFormat::GetVar(int domain, const char *varname)
{
// We assume variables are named Q# or Q## (etc.)
if (strlen(varname) < 2)
{
EXCEPTION1(InvalidVariableException, varname);
}
int varindex = atoi(&varname[1]) - 1;
if (varindex < 0 || varindex >= nq)
{
EXCEPTION1(InvalidVariableException, varname);
}
// Actually read it from the solution file, using this index
float *vals;
ReadVariable(domain, varindex, vals);
int npts = nx[domain]*ny[domain]*nz[domain];
// Put it in a VTK array
vtkFloatArray *rv = vtkFloatArray::New();
rv->SetNumberOfTuples(npts);
for (int i = 0 ; i < npts ; i++)
{
rv->SetTuple1(i, vals[i]);
}
delete[] vals;
return rv;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::GetVectorVar
//
// Purpose:
// Gets a vector 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:
// 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.
// varname The name of the variable requested.
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
vtkDataArray *
avtOVERFLOWFileFormat::GetVectorVar(int domain, const char *varname)
{
// No vector variables yet
return NULL;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::read_int
//
// Purpose:
// Read an integer from the file, swapping byte order if necessary.
//
// Arguments:
// in the input stream
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
int avtOVERFLOWFileFormat::read_int(ifstream &in)
{
int v;
in.read((char*)&v, 4);
if (swap_endian)
SWAP_4(v);
return v;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::read_fortran_record
//
// Purpose:
// Read the header, body, and footer from a file record.
// Allocate the buffer space for the body.
// Confirm that the footer matched the header (sanity check).
//
// Arguments:
// in the input stream
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// Modifications:
// Brad Whitlock, Wed Aug 11 17:52:07 PST 2004
// I removed the const from the return pointer since the output is
// usually deleted with the delete[] operator.
//
// ****************************************************************************
char *avtOVERFLOWFileFormat::read_fortran_record(ifstream &in)
{
int len = read_int(in);
char *buffer = new char[len];
in.read(buffer, len);
int testlen;
testlen = read_int(in);
if (testlen != len)
{
EXCEPTION1(VisItException, "Internal error reading "
"FORTRAN unformatted record");
}
return buffer;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::parse_int
//
// Purpose:
// Read a single 32-bit integer from a buffer,
// incrementing the buffer pointer approriately.
// Swaps byte order if necessary.
//
// Arguments:
// buff the current buffer position
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
int avtOVERFLOWFileFormat::parse_int(char *&buff)
{
int v = *((int*)(buff));
buff += 4;
if (swap_endian)
SWAP_4(v);
return v;
}
// ****************************************************************************
// Method: avtOVERFLOWFileFormat::parse_float
//
// Purpose:
// Read a single precision floating point number from a buffer,
// incrementing the buffer pointer approriately.
// Swaps byte order if necessary.
//
// Arguments:
// buff the current buffer position
//
// Programmer: Jeremy Meredith
// Creation: July 21, 2004
//
// ****************************************************************************
float avtOVERFLOWFileFormat::parse_float(char *&buff)
{
float v = *((float*)(buff));
buff += 4;
if (swap_endian)
SWAP_4(v);
return v;
}
|