Adding visit plugin

This commit is contained in:
Mark Berrill
2014-07-16 16:49:09 -04:00
parent eecce3f1b5
commit a95cf05b11
11 changed files with 1290 additions and 0 deletions

12
visit/LBM.xml Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<Plugin name="LBM" type="database" label="LBM" version="1.0" mdspecificcode="true" dbtype="MTMD">
<FilePatterns>
*.LBM
</FilePatterns>
<CXXFLAGS>
</CXXFLAGS>
<LDFLAGS>
</LDFLAGS>
<LIBS>
</LIBS>
</Plugin>

View File

@@ -0,0 +1,92 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
#include <LBMPluginInfo.h>
#include <avtLBMFileFormat.h>
#include <avtMTMDFileFormatInterface.h>
#include <avtGenericDatabase.h>
// ****************************************************************************
// Method: LBMCommonPluginInfo::GetDatabaseType
//
// Purpose:
// Returns the type of a LBM database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
DatabaseType
LBMCommonPluginInfo::GetDatabaseType()
{
return DB_TYPE_MTMD;
}
// ****************************************************************************
// Method: LBMCommonPluginInfo::SetupDatabase
//
// Purpose:
// Sets up a LBM database.
//
// Arguments:
// list A list of file names.
// nList The number of timesteps in list.
// nBlocks The number of blocks in the list.
//
// Returns: A LBM database from list.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
avtDatabase *
LBMCommonPluginInfo::SetupDatabase(const char *const *list,
int nList, int nBlock)
{
// ignore any nBlocks past 1
int nTimestepGroups = nList / nBlock;
avtMTMDFileFormat **ffl = new avtMTMDFileFormat*[nTimestepGroups];
for (int i = 0 ; i < nTimestepGroups ; i++)
{
ffl[i] = new avtLBMFileFormat(list[i*nBlock]);
}
avtMTMDFileFormatInterface *inter
= new avtMTMDFileFormatInterface(ffl, nTimestepGroups);
return new avtGenericDatabase(inter);
}

View File

@@ -0,0 +1,73 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
#include <LBMPluginInfo.h>
// ****************************************************************************
// Function: GetEngineInfo
//
// Purpose:
// Return a new EnginePluginInfo for the LBM database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
extern "C" DBP_EXPORT EngineDatabasePluginInfo* LBM_GetEngineInfo()
{
return new LBMEnginePluginInfo;
}
// ****************************************************************************
// Method: LBMEnginePluginInfo::GetWriter
//
// Purpose:
// Sets up a LBM writer.
//
// Returns: A LBM writer.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
avtDatabaseWriter *
LBMEnginePluginInfo::GetWriter(void)
{
return NULL;
}

View File

@@ -0,0 +1,60 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
#include <LBMPluginInfo.h>
// ****************************************************************************
// Function: GetMDServerInfo
//
// Purpose:
// Return a new MDServerPluginInfo for the LBM database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
extern "C" DBP_EXPORT MDServerDatabasePluginInfo* LBM_GetMDServerInfo()
{
return new LBMMDServerPluginInfo;
}
// this makes compilers happy... remove if we ever have functions here
void LBMMDServerPluginInfo::dummy()
{
}

206
visit/LBMPluginInfo.C Normal file
View File

@@ -0,0 +1,206 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// File: LBMPluginInfo.C
// ************************************************************************* //
#include <LBMPluginInfo.h>
#include <visit-config.h>
VISIT_PLUGIN_VERSION(LBM,DBP_EXPORT)
// ****************************************************************************
// Function: GetGeneralInfo
//
// Purpose:
// Return a new GeneralPluginInfo for the LBM database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
extern "C" DBP_EXPORT GeneralDatabasePluginInfo* LBM_GetGeneralInfo()
{
return new LBMGeneralPluginInfo;
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::GetName
//
// Purpose:
// Return the name of the database plugin.
//
// Returns: A pointer to the name of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
LBMGeneralPluginInfo::GetName() const
{
return "LBM";
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::GetVersion
//
// Purpose:
// Return the version of the database plugin.
//
// Returns: A pointer to the version of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
LBMGeneralPluginInfo::GetVersion() const
{
return "1.0";
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::GetID
//
// Purpose:
// Return the id of the database plugin.
//
// Returns: A pointer to the id of the database plugin.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
const char *
LBMGeneralPluginInfo::GetID() const
{
return "LBM_1.0";
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::EnabledByDefault
//
// Purpose:
// Return true if this plugin should be enabled by default; false otherwise.
//
// Returns: true/false
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
LBMGeneralPluginInfo::EnabledByDefault() const
{
return true;
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::HasWriter
//
// Purpose:
// Return true if this plugin has a database writer.
//
// Returns: true/false
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
LBMGeneralPluginInfo::HasWriter() const
{
return false;
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::GetDefaultFilePatterns
//
// Purpose:
// Returns the default patterns for a LBM database.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
std::vector<std::string>
LBMGeneralPluginInfo::GetDefaultFilePatterns() const
{
std::vector<std::string> defaultPatterns;
defaultPatterns.push_back("*.LBM");
return defaultPatterns;
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::AreDefaultFilePatternsStrict
//
// Purpose:
// Returns if the file patterns for a LBM database are
// intended to be interpreted strictly by default.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
LBMGeneralPluginInfo::AreDefaultFilePatternsStrict() const
{
return false;
}
// ****************************************************************************
// Method: LBMGeneralPluginInfo::OpensWholeDirectory
//
// Purpose:
// Returns if the LBM plugin opens a whole directory name
// instead of a single file.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// ****************************************************************************
bool
LBMGeneralPluginInfo::OpensWholeDirectory() const
{
return false;
}

100
visit/LBMPluginInfo.h Normal file
View File

@@ -0,0 +1,100 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
// ****************************************************************************
// LBMPluginInfo.h
// ****************************************************************************
#ifndef LBM_PLUGIN_INFO_H
#define LBM_PLUGIN_INFO_H
#include <DatabasePluginInfo.h>
#include <database_plugin_exports.h>
class avtDatabase;
class avtDatabaseWriter;
// ****************************************************************************
// Class: LBMDatabasePluginInfo
//
// Purpose:
// Classes that provide all the information about the LBM plugin.
// Portions are separated into pieces relevant to the appropriate
// components of VisIt.
//
// Programmer: generated by xml2info
// Creation: omitted
//
// Modifications:
//
// ****************************************************************************
class LBMGeneralPluginInfo : public virtual GeneralDatabasePluginInfo
{
public:
virtual const char *GetName() const;
virtual const char *GetVersion() const;
virtual const char *GetID() const;
virtual bool EnabledByDefault() const;
virtual bool HasWriter() const;
virtual std::vector<std::string> GetDefaultFilePatterns() const;
virtual bool AreDefaultFilePatternsStrict() const;
virtual bool OpensWholeDirectory() const;
};
class LBMCommonPluginInfo : public virtual CommonDatabasePluginInfo, public virtual LBMGeneralPluginInfo
{
public:
virtual DatabaseType GetDatabaseType();
virtual avtDatabase *SetupDatabase(const char * const *list,
int nList, int nBlock);
};
class LBMMDServerPluginInfo : public virtual MDServerDatabasePluginInfo, public virtual LBMCommonPluginInfo
{
public:
// this makes compilers happy... remove if we ever have functions here
virtual void dummy();
};
class LBMEnginePluginInfo : public virtual EngineDatabasePluginInfo, public virtual LBMCommonPluginInfo
{
public:
virtual avtDatabaseWriter *GetWriter(void);
};
#endif

578
visit/avtLBMFileFormat.C Normal file
View File

@@ -0,0 +1,578 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtLBMFileFormat.C //
// ************************************************************************* //
#include <avtLBMFileFormat.h>
#include <DebugStream.h>
#include <string>
// vtk headers
#include <vtkFloatArray.h>
#include <vtkRectilinearGrid.h>
#include <vtkStructuredGrid.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPointSet.h>
#include <vtkCellType.h>
#include <vtkPolyData.h>
#include <vtkCellArray.h>
#include <avtDatabaseMetaData.h>
#include <DBOptionsAttributes.h>
#include <Expression.h>
#include <InvalidVariableException.h>
#if defined(WIN32) || defined(_WIN32) || defined(WIN64) || defined(_WIN64)
#define USE_WINDOWS
#elif defined(__APPLE__)
#define USE_MAC
#else
#define USE_LINUX
#endif
#ifdef USE_WINDOWS
#include <windows.h>
#include <stdio.h>
#define TIME_TYPE LARGE_INTEGER
#define get_time(x) QueryPerformanceCounter(x)
#define get_frequency(f) QueryPerformanceFrequency(f)
#define get_diff(start,end,f) \
static_cast<double>(end.QuadPart-start.QuadPart)/static_cast<double>(f.QuadPart)
#elif defined(USE_LINUX) || defined(USE_MAX)
#include <sys/time.h>
#define TIME_TYPE timeval
#define get_time(x) gettimeofday(x,NULL);
#define get_frequency(f) (*f=timeval())
#define get_diff(start,end,f) 1e-6*static_cast<double>( \
0xF4240*(static_cast<int64_t>(end.tv_sec)-static_cast<int64_t>(start.tv_sec)) + \
(static_cast<int64_t>(end.tv_usec)-static_cast<int64_t>(start.tv_usec)) )
#else
#error Unknown OS
#endif
// ****************************************************************************
// Method: avtLBMFileFormat constructor
//
// Programmer: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
avtLBMFileFormat::avtLBMFileFormat(const char *filename)
: avtMTMDFileFormat(filename)
{
DebugStream::Stream1() << "avtLBMFileFormat::avtLBMFileFormat: " << filename << std::endl;
// Get the path to the input file
std::string file(filename);
size_t k1 = file.rfind(47);
size_t k2 = file.rfind(92);
if ( k1==std::string::npos ) { k1=0; }
if ( k2==std::string::npos ) { k2=0; }
path = file.substr(0,std::max(k1,k2));
// Load the summary file
DebugStream::Stream1() << "Loading " << filename << std::endl;
FILE *fid= fopen(filename,"r");
if ( fid==NULL ) {
DebugStream::Stream1() << "Error opening file" << std::endl;
return;
}
char buf[1000];
while (fgets(buf,sizeof(buf),fid) != NULL) {
std::string line(buf);
line.resize(line.size()-1);
if ( line.empty() )
continue;
timesteps.push_back(line);
}
fclose(fid);
// For each time step, get the list of meshes and files
meshlist.resize(timesteps.size());
for (size_t i=0; i<timesteps.size(); i++) {
std::string filename2 = path + "/" + timesteps[i] + "/LBM.summary";
FILE *fid= fopen(filename2.c_str(),"r");
if ( fid==NULL ) {
DebugStream::Stream1() << "Error opening timestep: " << filename << std::endl;
return;
}
char buf[1000];
while (fgets(buf,sizeof(buf),fid) != NULL) {
std::string file(buf);
file.resize(file.size()-1);
if ( file.empty() )
continue;
size_t k = file.rfind('.');
std::string meshname = file.substr(0,k);
if ( meshlist[i][meshname].meshname.empty() ) {
meshlist[i][meshname].meshname = meshname;
if ( meshname=="ns-tris" || meshname=="ws-tris" || meshname=="wn-tris" ) {
meshlist[i][meshname].type = AVT_SURFACE_MESH;
} else if ( meshname=="wns-crv" ) {
meshlist[i][meshname].type = AVT_POINT_MESH;
} else {
DebugStream::Stream1() << "Warning: unknown mesh type for mesh: " << meshname << std::endl;
}
}
meshlist[i][meshname].files.push_back(file);
}
fclose(fid);
}
}
// ****************************************************************************
// Method: avtEMSTDFileFormat::GetNTimesteps
//
// Purpose:
// Tells the rest of the code how many timesteps there are in this file.
//
// Programmer: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
int
avtLBMFileFormat::GetNTimesteps(void)
{
DebugStream::Stream1() << "avtLBMFileFormat::GetNTimesteps" << std::endl;
return static_cast<int>(timesteps.size());
}
// ****************************************************************************
// Method: avtLBMFileFormat::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: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
void
avtLBMFileFormat::FreeUpResources(void)
{
DebugStream::Stream1() << "avtLBMFileFormat::FreeUpResources" << std::endl;
std::map<std::string,vtkObjectBase*>::iterator it;
for ( it=meshcache.begin(); it!=meshcache.end(); ++it ) {
DebugStream::Stream2() << " deleting: " << it->first << std::endl;
vtkObjectBase* obj = it->second;
it->second = NULL;
if ( obj!=NULL )
obj->Delete();
}
meshcache.clear();
DebugStream::Stream2() << " finished" << std::endl;
}
// ****************************************************************************
// Method: avtLBMFileFormat::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: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
void
avtLBMFileFormat::PopulateDatabaseMetaData(avtDatabaseMetaData *md, int timeState)
{
DebugStream::Stream1() << "avtLBMFileFormat::PopulateDatabaseMetaData: " << timeState << std::endl;
// Add the mesh domains to the meta data
std::map<std::string,meshdata>::iterator it;
for (it=meshlist[timeState].begin(); it!=meshlist[timeState].end(); ++it) {
std::sort(it->second.files.begin(),it->second.files.end());
std::string meshname = it->first;
avtMeshType type = it->second.type;
avtMeshMetaData *mmd = new avtMeshMetaData;
mmd->name = meshname;
mmd->meshType = it->second.type;
mmd->spatialDimension = 3;
mmd->topologicalDimension = -1;
if ( mmd->meshType==AVT_SURFACE_MESH )
mmd->topologicalDimension = 2;
mmd->numBlocks = it->second.files.size();
mmd->blockNames = std::vector<std::string>(it->second.files.size());
for(size_t i=0; i<it->second.files.size(); i++) {
char tmp[100];
sprintf(tmp,"%s.%5i",meshname.c_str(),(int)i);
mmd->blockNames[i] = std::string(tmp);
}
md->Add(mmd);
// Add expressions for the coordinates
const char *xyz[3] = {"x","y","z"};
for(int i=0; i<3; ++i) {
Expression expr;
char expdef[100], expname[100];
sprintf(expdef,"coord(<%s>)[%i]",meshname.c_str(),i);
sprintf(expname,"%s-%s",meshname.c_str(),xyz[i]);
expr.SetName(expname);
expr.SetDefinition(expdef);
expr.SetType(Expression::ScalarMeshVar);
md->AddExpression(&expr);
}
}
//
// CODE TO ADD A SCALAR VARIABLE
//
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
// string varname = ...
//
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
// avtCentering cent = AVT_NODECENT;
//
//
// Here's the call that tells the meta-data object that we have a var:
//
// AddScalarVarToMetaData(md, varname, mesh_for_this_var, cent);
//
//
// CODE TO ADD A VECTOR VARIABLE
//
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
// string varname = ...
// int vector_dim = 2;
//
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
// avtCentering cent = AVT_NODECENT;
//
//
// Here's the call that tells the meta-data object that we have a var:
//
// AddVectorVarToMetaData(md, varname, mesh_for_this_var, cent,vector_dim);
//
//
// CODE TO ADD A TENSOR VARIABLE
//
// string mesh_for_this_var = meshname; // ??? -- could be multiple meshes
// string varname = ...
// int tensor_dim = 9;
//
// AVT_NODECENT, AVT_ZONECENT, AVT_UNKNOWN_CENT
// avtCentering cent = AVT_NODECENT;
//
//
// Here's the call that tells the meta-data object that we have a var:
//
// AddTensorVarToMetaData(md, varname, mesh_for_this_var, cent,tensor_dim);
//
//
// CODE TO ADD A MATERIAL
//
// string mesh_for_mat = meshname; // ??? -- could be multiple meshes
// string matname = ...
// int nmats = ...;
// vector<string> mnames;
// for (int i = 0 ; i < nmats ; i++)
// {
// char str[32];
// sprintf(str, "mat%d", i);
// -- or --
// strcpy(str, "Aluminum");
// mnames.push_back(str);
// }
//
// Here's the call that tells the meta-data object that we have a mat:
//
// AddMaterialToMetaData(md, matname, mesh_for_mat, nmats, mnames);
//
//
// Here's the way to add expressions:
//Expression momentum_expr;
//momentum_expr.SetName("momentum");
//momentum_expr.SetDefinition("{u, v}");
//momentum_expr.SetType(Expression::VectorMeshVar);
//md->AddExpression(&momentum_expr);
//Expression KineticEnergy_expr;
//KineticEnergy_expr.SetName("KineticEnergy");
//KineticEnergy_expr.SetDefinition("0.5*(momentum*momentum)/(rho*rho)");
//KineticEnergy_expr.SetType(Expression::ScalarMeshVar);
//md->AddExpression(&KineticEnergy_expr);
//
}
// ****************************************************************************
// Method: avtLBMFileFormat::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.
// 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: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
vtkDataSet *
avtLBMFileFormat::GetMesh(int timestate, int domain, const char *meshname)
{
TIME_TYPE start, stop, freq;
get_frequency(&freq);
get_time(&start);
// Get the filename
DebugStream::Stream1() << "avtLBMFileFormat::GetMesh: ";
std::string filename = path + "/" + timesteps[timestate] + "/" +
meshlist[timestate][std::string(meshname)].files[domain];
avtMeshType type = meshlist[timestate][std::string(meshname)].type;
DebugStream::Stream1() << filename << std::endl;
// Check if we have a cached copy of the mesh
char cache_name[1000];
sprintf(cache_name,"%i-%i-%s",timestate,domain,meshname);
if ( meshcache.find(cache_name)!=meshcache.end() )
return dynamic_cast<vtkDataSet*>(meshcache.find(cache_name)->second);
// Read the raw data
FILE *fid = fopen(filename.c_str(),"rb");
if ( fid==NULL ) {
DebugStream::Stream1() << " Error opening file" << std::endl;
return NULL;
}
fseek( fid, 0, SEEK_END );
size_t bytes = ftell(fid);
size_t N_max = bytes/sizeof(double)+1000;
double *data = new double[N_max];
fseek( fid, 0, SEEK_SET );
size_t count = fread(data,sizeof(double),N_max,fid);
fclose(fid);
if ( count%3 ) {
DebugStream::Stream1() << " Error reading data: " << count << std::endl;
delete [] data;
return NULL;
}
if ( count==0 ) {
DebugStream::Stream2() << " No points read" << std::endl;
delete [] data;
return NULL;
}
// Create the points in vtk
DebugStream::Stream2() << " Creating vtkFloatArray" << std::endl;
vtkFloatArray *coords = vtkFloatArray::New();
coords->SetNumberOfComponents(3);
coords->SetNumberOfTuples(count/3);
for (size_t i=0; i<count/3; i++)
coords->SetTuple3(i,data[3*i+0],data[3*i+1],data[3*i+2]);
delete [] data;
DebugStream::Stream2() << " Creating vtkPoints" << std::endl;
vtkPoints *points = vtkPoints::New(VTK_FLOAT);
points->SetData(coords);
points->ComputeBounds();
// Create the mesh
DebugStream::Stream2() << " Creating mesh" << std::endl;
vtkPolyData *mesh = vtkPolyData::New();
mesh->SetPoints(points);
if ( type==AVT_SURFACE_MESH ) {
size_t N_tri = count/9;
mesh->Allocate(N_tri);
for (size_t i=0; i<N_tri; i++) {
vtkIdType ids[3] = {3*i+0,3*i+1,3*i+2};
mesh->InsertNextCell(VTK_TRIANGLE,3,ids);
}
} else if ( type==AVT_POINT_MESH ) {
size_t N_tri = count/3;
mesh->Allocate(N_tri);
for (size_t i=0; i<N_tri; i++) {
vtkIdType ids[1] = {i};
mesh->InsertNextCell(VTK_VERTEX,1,ids);
}
} else {
DebugStream::Stream1() << " Unknown mesh type" << std::endl;
points->Delete();
coords->Delete();
return NULL;
}
mesh->BuildCells();
mesh->ComputeBounds();
DebugStream::Stream2() << " mesh created:" << std::endl;
DebugStream::Stream2() << " " << mesh->GetNumberOfCells() << std::endl;
DebugStream::Stream2() << " " << mesh->GetNumberOfCells() << std::endl;
mesh->PrintSelf(DebugStream::Stream2(),vtkIndent(6));
points->Delete();
coords->Delete();
// Cache the mesh and return
// meshcache[cache_name] = mesh;
get_time(&stop);
DebugStream::Stream2() << " Time required: " << get_diff(start,stop,freq) << std::endl;
return mesh;
}
// ****************************************************************************
// Method: avtLBMFileFormat::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.
// 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: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
vtkDataArray *
avtLBMFileFormat::GetVar(int timestate, int domain, const char *varname)
{
DebugStream::Stream1() << "avtLBMFileFormat::GetVar" << std::endl;
EXCEPTION1(InvalidVariableException, varname);
return NULL;
//
// If you have a file format where variables don't apply (for example a
// strictly polygonal format like the STL (Stereo Lithography) format,
// then uncomment the code below.
//
// EXCEPTION1(InvalidVariableException, varname);
//
//
// If you do have a scalar variable, here is some code that may be helpful.
//
// int ntuples = XXX; // this is the number of entries in the variable.
// vtkFloatArray *rv = vtkFloatArray::New();
// rv->SetNumberOfTuples(ntuples);
// for (int i = 0 ; i < ntuples ; i++)
// {
// rv->SetTuple1(i, VAL); // you must determine value for ith entry.
// }
//
// return rv;
//
}
// ****************************************************************************
// Method: avtLBMFileFormat::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:
// timestate The index of the timestate. If GetNTimesteps returned
// 'N' time steps, this is guaranteed to be between 0 and N-1.
// 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: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
vtkDataArray *
avtLBMFileFormat::GetVectorVar(int timestate, int domain,const char *varname)
{
DebugStream::Stream1() << "avtLBMFileFormat::GetVectorVar" << std::endl;
EXCEPTION1(InvalidVariableException, varname);
return NULL;
//
// If you have a file format where variables don't apply (for example a
// strictly polygonal format like the STL (Stereo Lithography) format,
// then uncomment the code below.
//
// EXCEPTION1(InvalidVariableException, varname);
//
//
// If you do have a vector variable, here is some code that may be helpful.
//
// int ncomps = YYY; // This is the rank of the vector - typically 2 or 3.
// int ntuples = XXX; // this is the number of entries in the variable.
// vtkFloatArray *rv = vtkFloatArray::New();
// int ucomps = (ncomps == 2 ? 3 : ncomps);
// rv->SetNumberOfComponents(ucomps);
// rv->SetNumberOfTuples(ntuples);
// float *one_entry = new float[ucomps];
// for (int i = 0 ; i < ntuples ; i++)
// {
// int j;
// for (j = 0 ; j < ncomps ; j++)
// one_entry[j] = ...
// for (j = ncomps ; j < ucomps ; j++)
// one_entry[j] = 0.;
// rv->SetTuple(i, one_entry);
// }
//
// delete [] one_entry;
// return rv;
//
}

114
visit/avtLBMFileFormat.h Normal file
View File

@@ -0,0 +1,114 @@
/*****************************************************************************
*
* Copyright (c) 2000 - 2013, Lawrence Livermore National Security, LLC
* Produced at the Lawrence Livermore National Laboratory
* LLNL-CODE-442911
* 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.
*
*****************************************************************************/
// ************************************************************************* //
// avtLBMFileFormat.h //
// ************************************************************************* //
#ifndef AVT_LBM_FILE_FORMAT_H
#define AVT_LBM_FILE_FORMAT_H
#include <vtkObjectBase.h>
#include <avtMTMDFileFormat.h>
#include <vector>
#include <map>
// ****************************************************************************
// Class: avtLBMFileFormat
//
// Purpose:
// Reads in LBM files as a plugin to VisIt.
//
// Programmer: mbt -- generated by xml2avt
// Creation: Wed Jul 9 10:59:08 PDT 2014
//
// ****************************************************************************
class avtLBMFileFormat : public avtMTMDFileFormat
{
public:
avtLBMFileFormat(const char *);
virtual ~avtLBMFileFormat() {;};
//
// This is used to return unconvention data -- ranging from material
// information to information about block connectivity.
//
// virtual void *GetAuxiliaryData(const char *var, int timestep,
// int domain, const char *type, void *args,
// DestructorFunction &);
//
//
// If you know the times and cycle numbers, overload this function.
// Otherwise, VisIt will make up some reasonable ones for you.
//
// virtual void GetCycles(std::vector<int> &);
// virtual void GetTimes(std::vector<double> &);
//
virtual int GetNTimesteps(void);
virtual const char *GetType(void) { return "LBM"; };
virtual void FreeUpResources(void);
virtual vtkDataSet *GetMesh(int, int, const char *);
virtual vtkDataArray *GetVar(int, int, const char *);
virtual vtkDataArray *GetVectorVar(int, int, const char *);
protected:
// DATA MEMBERS
virtual void PopulateDatabaseMetaData(avtDatabaseMetaData *, int);
std::string path;
std::vector<std::string> timesteps;
struct meshdata {
std::string meshname;
avtMeshType type;
std::vector<std::string> files;
};
std::vector<std::map<std::string,meshdata> > meshlist;
std::map<std::string,vtkObjectBase*> meshcache;
};
#endif