Creation of OpenFOAM-dev repository 15/04/2008

This commit is contained in:
OpenFOAM-admin
2008-04-15 18:56:58 +01:00
commit 3170c7c0c9
9896 changed files with 4016171 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#!/bin/sh
set -x
if [ "$ParaView_VERSION" = "3" -a "$ParaView_DIR" -a -r $ParaView_DIR ] ; then
wmake libso vtkPV3Foam
(cd PV3FoamReader; mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1; cd Make/$WM_OPTIONS; cmake ../..; make)
fi

View File

@ -0,0 +1,54 @@
# create a plugin that adds a reader to the ParaView GUI
# it is added in the file dialog when doing opens/saves.
# The qrc file is processed by Qt's resource compiler (rcc)
# the qrc file must have a resource prefix of "/ParaViewResources"
# and ParaView will read anything contained under that prefix
# the pqReader.xml file contains xml defining readers with their
# file extensions and descriptions.
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
LINK_DIRECTORIES(
$ENV{FOAM_LIBBIN}
)
INCLUDE_DIRECTORIES(
$ENV{FOAM_SRC}/OpenFOAM/lnInclude
$ENV{FOAM_SRC}/finiteVolume/lnInclude
${PROJECT_SOURCE_DIR}/../vtkPV3Foam
)
ADD_DEFINITIONS(
-D$ENV{WM_PRECISION_OPTION}
)
# Set output library destination to plugin folder
SET(
LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH}
CACHE INTERNAL
"Single output directory for building all libraries."
)
# Build the server-side plugin
ADD_PARAVIEW_PLUGIN(
PV3FoamReader_SM "1.0"
SERVER_MANAGER_XML PV3FoamReader_SM.xml
SERVER_MANAGER_SOURCES vtkPV3FoamReader.cxx
)
# Build the client-side plugin
ADD_PARAVIEW_PLUGIN(
PV3FoamReader
"1.0"
GUI_RESOURCES PV3FoamReader.qrc
)
TARGET_LINK_LIBRARIES(
PV3FoamReader_SM
OpenFOAM
finiteVolume
vtkPV3Foam
)

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/ParaViewResources" >
<file>PV3FoamReader.xml</file>
</qresource>
</RCC>

View File

@ -0,0 +1,6 @@
<ParaViewReaders>
<Reader name="PV3FoamReader"
extensions="foam OpenFOAM"
file_description="OpenFOAM Files">
</Reader>
</ParaViewReaders>

View File

@ -0,0 +1,238 @@
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy
name="PV3FoamReader"
class="vtkPV3FoamReader">
<!-- File name - compulsory -->
<StringVectorProperty
name="FileName"
command="SetFileName"
number_of_elements="1">
<FileListDomain
name="files"/>
</StringVectorProperty>
<!-- Time info sent to animation controls (top of window) -->
<DoubleVectorProperty
name="TimestepValues"
information_only="1">
<TimeStepsInformationHelper/>
<Documentation>
Available timestep values.
</Documentation>
</DoubleVectorProperty>
<DoubleVectorProperty
name="TimeRange"
information_only="1">
<TimeRangeInformationHelper/>
</DoubleVectorProperty>
<!-- Update GUI check box -->
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
number_of_elements="1"
default_values="0">
<BooleanDomain
name="bool"/>
</IntVectorProperty>
<!-- Cache mesh check box -->
<IntVectorProperty
name="CacheMesh"
command="SetCacheMesh"
number_of_elements="1"
default_values="1">
<BooleanDomain
name="bool"/>
</IntVectorProperty>
<!-- Include sets check box -->
<IntVectorProperty
name="IncludeSets"
command="SetIncludeSets"
number_of_elements="1"
default_values="0">
<BooleanDomain
name="bool"/>
</IntVectorProperty>
<!-- Show patch names check box -->
<IntVectorProperty
name="ShowPatchNames"
command="SetShowPatchNames"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool"/>
</IntVectorProperty>
<!-- Time step edit box -->
<IntVectorProperty
name="TimeStepRangeInfo"
command="GetTimeStepRange"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStep"
command="SetTimeStep"
number_of_elements="1"
animateable="1"
default_values="0"
information_property="TimestepValues">
<IntRangeDomain
name="range">
<RequiredProperties>
<Property name="TimeStepRangeInfo"
function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>
<!-- Time step limits boxes -->
<!-- <IntVectorProperty
name="TimeStepLimitsInfo"
command="GetTimeStepLimits"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepLimits"
command="SetTimeStepLimits"
number_of_elements="2"
default_values="2 5" >
<IntRangeDomain
name="range">
<RequiredProperties>
<Property name="TimeStepLimitsInfo"
function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>-->
<!-- Available times array -->
<StringVectorProperty
name="TimeArrayInfo"
information_only="1">
<ArraySelectionInformationHelper
attribute_name="Time"/>
</StringVectorProperty>
<StringVectorProperty
name="TimeStatus"
command="SetTimeArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="TimeArrayInfo">
<ArraySelectionDomain
name="array_list">
<RequiredProperties>
<Property name="TimeArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available regions array -->
<StringVectorProperty
name="RegionArrayInfo"
information_only="1">
<ArraySelectionInformationHelper
attribute_name="Region"/>
</StringVectorProperty>
<StringVectorProperty
name="RegionStatus"
command="SetRegionArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="RegionArrayInfo">
<ArraySelectionDomain
name="array_list">
<RequiredProperties>
<Property name="RegionArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available volFields array -->
<StringVectorProperty
name="VolFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper
attribute_name="VolField"/>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldStatus"
command="SetVolFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="VolFieldArrayInfo">
<ArraySelectionDomain
name="array_list">
<RequiredProperties>
<Property name="VolFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available pointFields array -->
<StringVectorProperty
name="PointFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper
attribute_name="PointField"/>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldStatus"
command="SetPointFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PointFieldArrayInfo">
<ArraySelectionDomain
name="array_list">
<RequiredProperties>
<Property name="PointFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available Lagrangian fields array -->
<StringVectorProperty
name="LagrangianFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper
attribute_name="LagrangianField"/>
</StringVectorProperty>
<StringVectorProperty
name="LagrangianFieldStatus"
command="SetLagrangianFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="LagrangianFieldArrayInfo">
<ArraySelectionDomain
name="array_list">
<RequiredProperties>
<Property name="LagrangianFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,600 @@
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3FoamReader.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPV3FoamReader.h"
#include "pqApplicationCore.h"
#include "pqRenderView.h"
#include "pqServerManagerModel.h"
// VTK includes
#include "vtkCallbackCommand.h"
#include "vtkCellArray.h"
#include "vtkCellData.h"
#include "vtkDataArraySelection.h"
#include "vtkDirectory.h"
#include "vtkDoubleArray.h"
#include "vtkErrorCode.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkIntArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkPoints.h"
#include "vtkRenderer.h"
#include "vtkSMRenderViewProxy.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
#include "vtkUnstructuredGrid.h"
#include "vtkUnstructuredGridAlgorithm.h"
// Foam includes
#include "vtkPV3Foam.H"
vtkCxxRevisionMacro(vtkPV3FoamReader, "$Revision: 1.2$");
vtkStandardNewMacro(vtkPV3FoamReader);
vtkPV3FoamReader::vtkPV3FoamReader()
{
vtkDebugMacro(<<"Constructor");
SetNumberOfInputPorts(0);
FileName = NULL;
foamData_ = NULL;
CacheMesh = 0;
UpdateGUI = 1;
UpdateGUIOld = 1;
TimeStep = 0;
TimeStepRange[0] = 0;
TimeStepRange[1] = 0;
ShowPatchNames = 0;
TimeSelection = vtkDataArraySelection::New();
PointFieldSelection = vtkDataArraySelection::New();
RegionSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New();
LagrangianFieldSelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
SelectionObserver = vtkCallbackCommand::New();
SelectionObserver->SetCallback
(
&vtkPV3FoamReader::SelectionModifiedCallback
);
SelectionObserver->SetClientData(this);
TimeSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
RegionSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
VolFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
PointFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
LagrangianFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
}
vtkPV3FoamReader::~vtkPV3FoamReader()
{
vtkDebugMacro(<<"Deconstructor");
if (foamData_)
{
delete foamData_;
}
if (FileName)
{
delete [] FileName;
}
TimeSelection->RemoveObserver(this->SelectionObserver);
RegionSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
TimeSelection->Delete();
RegionSelection->Delete();
VolFieldSelection->Delete();
PointFieldSelection->Delete();
}
// Do everything except set the output info
int vtkPV3FoamReader::RequestInformation
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"Request Information");
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
if (!foamData_)
{
vtkDebugMacro("RequestInformation: creating foamData_");
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
foamData_ = new Foam::vtkPV3Foam(FileName, this, output);
foamData_->UpdateInformation();
}
else
{
vtkDebugMacro("RequestInformation: updating information");
foamData_->UpdateInformation();
}
double* timeSteps = foamData_->timeSteps();
outputVector->GetInformationObject(0)->Set
(
vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
timeSteps,
foamData_->numberOfTimeSteps()
);
delete timeSteps;
return 1;
}
// Set the output info
int vtkPV3FoamReader::RequestData
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestData");
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
if
(
(UpdateGUIOld == GetUpdateGUI())
|| (output->GetNumberOfDataSets(0) == 0)
)
{
foamData_->Update(output);
if (ShowPatchNames == 1)
{
addPatchNamesToView();
}
else
{
removePatchNamesFromView();
}
}
UpdateGUIOld = GetUpdateGUI();
return 1;
}
void vtkPV3FoamReader::addPatchNamesToView()
{
pqApplicationCore* appCore = pqApplicationCore::instance();
// Server manager model for querying items in the server manager
pqServerManagerModel* smModel = appCore->getServerManagerModel();
// Get all the pqRenderView instances
QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>();
for (int viewI=0; viewI<renderViews.size(); viewI++)
{
foamData_->addPatchNames
(
renderViews[viewI]->getRenderViewProxy()->GetRenderer()
);
}
}
void vtkPV3FoamReader::removePatchNamesFromView()
{
pqApplicationCore* appCore = pqApplicationCore::instance();
// Server manager model for querying items in the server manager
pqServerManagerModel* smModel = appCore->getServerManagerModel();
// Get all the pqRenderView instances
QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>();
for (int viewI=0; viewI<renderViews.size(); viewI++)
{
foamData_->removePatchNames
(
renderViews[viewI]->getRenderViewProxy()->GetRenderer()
);
}
}
void vtkPV3FoamReader::PrintSelf
(
ostream& os,
vtkIndent indent
)
{
vtkDebugMacro(<<"PrintSelf");
this->Superclass::PrintSelf(os,indent);
os<< indent << "File name: "
<< (this->FileName ? this->FileName : "(none)") << "\n";
os<< indent << "Number of meshes: " << foamData_->numberOfMeshes() << "\n";
os<< indent << "Number of nodes: " << foamData_->numberOfPoints() << "\n";
os<< indent << "Number of cells: " << foamData_->numberOfCells() << "\n";
os<< indent << "Number of time steps: " << foamData_->numberOfTimeSteps()
<< endl;
os<< indent << "Time step range: "
<< this->TimeStepRange[0] << " - " << this->TimeStepRange[1]
<< endl;
os<< indent << "Time step: " << this->TimeStep << endl;
return;
}
vtkDataArraySelection* vtkPV3FoamReader::GetTimeSelection()
{
vtkDebugMacro(<<"GetTimeSelection");
return TimeSelection;
}
int vtkPV3FoamReader::GetNumberOfTimeArrays()
{
vtkDebugMacro(<<"GetNumberOf TimeArrays");
return TimeSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetTimeArrayName
(
int index
)
{
vtkDebugMacro(<<"GetTimeArrayName");
return TimeSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetTimeArrayStatus
(
const char* name
)
{
vtkDebugMacro(<<"GetTimeArrayStatus");
return TimeSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetTimeArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetTimeArrayStatus");
if (status)
{
TimeSelection->EnableArray(name);
}
else
{
TimeSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkPV3FoamReader::GetRegionSelection()
{
vtkDebugMacro(<<"GetRegionSelection");
return RegionSelection;
}
int vtkPV3FoamReader::GetNumberOfRegionArrays()
{
vtkDebugMacro(<<"GetNumberOfRegionArrays");
return RegionSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetRegionArrayName
(
int index
)
{
vtkDebugMacro(<<"GetRegionArrayName");
return RegionSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetRegionArrayStatus
(
const char* name
)
{
vtkDebugMacro(<<"GetRegionArrayStatus");
return RegionSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetRegionArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetRegionArrayStatus");
if(status)
{
RegionSelection->EnableArray(name);
}
else
{
RegionSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkPV3FoamReader::GetVolFieldSelection()
{
vtkDebugMacro(<<"GetVolFieldSelection");
return VolFieldSelection;
}
int vtkPV3FoamReader::GetNumberOfVolFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfVolFieldArrays");
return VolFieldSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetVolFieldArrayName
(
int index
)
{
vtkDebugMacro(<<"GetVolFieldArrayName");
return VolFieldSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetVolFieldArrayStatus
(
const char* name
)
{
vtkDebugMacro(<<"GetVolFieldArrayStatus");
return VolFieldSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetVolFieldArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetVolFieldArrayStatus");
if (status)
{
VolFieldSelection->EnableArray(name);
}
else
{
VolFieldSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkPV3FoamReader::GetPointFieldSelection()
{
vtkDebugMacro(<<"GetPointFieldSelection");
return PointFieldSelection;
}
int vtkPV3FoamReader::GetNumberOfPointFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfPointFieldArrays");
return PointFieldSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetPointFieldArrayName
(
int index
)
{
vtkDebugMacro(<<"GetPointFieldArrayName");
return PointFieldSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetPointFieldArrayStatus
(
const char* name
)
{
vtkDebugMacro(<<"GetPointFieldArrayStatus");
return PointFieldSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetPointFieldArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetPointFieldArrayStatus");
if (status)
{
PointFieldSelection->EnableArray(name);
}
else
{
PointFieldSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkPV3FoamReader::GetLagrangianFieldSelection()
{
vtkDebugMacro(<<"GetLagrangianFieldSelection");
return LagrangianFieldSelection;
}
int vtkPV3FoamReader::GetNumberOfLagrangianFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays");
return LagrangianFieldSelection->GetNumberOfArrays();
}
const char* vtkPV3FoamReader::GetLagrangianFieldArrayName
(
int index
)
{
vtkDebugMacro(<<"GetLagrangianFieldArrayName");
return LagrangianFieldSelection->GetArrayName(index);
}
int vtkPV3FoamReader::GetLagrangianFieldArrayStatus
(
const char* name
)
{
vtkDebugMacro(<<"GetLagrangianFieldArrayStatus");
return LagrangianFieldSelection->ArrayIsEnabled(name);
}
void vtkPV3FoamReader::SetLagrangianFieldArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetLagrangianFieldArrayStatus");
if (status)
{
LagrangianFieldSelection->EnableArray(name);
}
else
{
LagrangianFieldSelection->DisableArray(name);
}
}
void vtkPV3FoamReader::SelectionModifiedCallback
(
vtkObject*,
unsigned long,
void* clientdata,
void*
)
{
static_cast<vtkPV3FoamReader*>(clientdata)->SelectionModified();
}
void vtkPV3FoamReader::SelectionModified()
{
vtkDebugMacro(<<"SelectionModified");
Modified();
}

View File

@ -0,0 +1,195 @@
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3FoamReader.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPV3FoamReader - reads a dataset in OpenFOAM format
// .SECTION Description
// vtkPV3FoamReader creates an multiblock dataset. It reads a controlDict
// file, mesh information, and time dependent data. The controlDict file
// contains timestep information. The polyMesh folders contain mesh information
// The time folders contain transient data for the cells Each folder can
// contain any number of data files.
#ifndef __vtkPV3FoamReader_h
#define __vtkPV3FoamReader_h
#include "vtkMultiBlockDataSetAlgorithm.h"
// Foam forward declarations
namespace Foam
{
class vtkPV3Foam;
}
// VTK forward declarations
class vtkUnstructuredGrid;
class vtkPoints;
class vtkIntArray;
class vtkFloatArray;
class vtkDoubleArray;
class vtkDataArraySelection;
class vtkCallbackCommand;
class VTK_IO_EXPORT vtkPV3FoamReader : public vtkMultiBlockDataSetAlgorithm
{
public:
static vtkPV3FoamReader* New();
vtkTypeRevisionMacro
(
vtkPV3FoamReader,
vtkMultiBlockDataSetAlgorithm
);
void PrintSelf
(
ostream& os,
vtkIndent indent
);
// Description:
// Set/Get the filename.
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
// GUI update control
vtkSetMacro(UpdateGUI, int);
vtkGetMacro(UpdateGUI, int);
// FOAM mesh caching control
vtkSetMacro(CacheMesh, int);
vtkGetMacro(CacheMesh, int);
// FOAM read sets control
vtkSetMacro(IncludeSets, int);
vtkGetMacro(IncludeSets, int);
// FOAM patch names control
vtkSetMacro(ShowPatchNames, int);
vtkGetMacro(ShowPatchNames, int);
// Time-step slider control
vtkSetMacro(TimeStep, int);
vtkGetMacro(TimeStep, int);
vtkSetVector2Macro(TimeStepRange, int);
vtkGetVector2Macro(TimeStepRange, int);
// Time selection list control
vtkDataArraySelection* GetTimeSelection();
int GetNumberOfTimeArrays();
const char* GetTimeArrayName(int index);
int GetTimeArrayStatus(const char* name);
void SetTimeArrayStatus(const char* name, int status);
// Region selection list control
vtkDataArraySelection* GetRegionSelection();
int GetNumberOfRegionArrays();
const char* GetRegionArrayName(int index);
int GetRegionArrayStatus(const char* name);
void SetRegionArrayStatus(const char* name, int status);
// volField selection list control
vtkDataArraySelection* GetVolFieldSelection();
int GetNumberOfVolFieldArrays();
const char* GetVolFieldArrayName(int index);
int GetVolFieldArrayStatus(const char* name);
void SetVolFieldArrayStatus(const char* name, int status);
// pointField selection list control
vtkDataArraySelection* GetPointFieldSelection();
int GetNumberOfPointFieldArrays();
const char* GetPointFieldArrayName(int index);
int GetPointFieldArrayStatus(const char* name);
void SetPointFieldArrayStatus(const char* name, int status);
// lagrangianField selection list control
vtkDataArraySelection* GetLagrangianFieldSelection();
int GetNumberOfLagrangianFieldArrays();
const char* GetLagrangianFieldArrayName(int index);
int GetLagrangianFieldArrayStatus(const char* name);
void SetLagrangianFieldArrayStatus(const char* name, int status);
// Callback registered with the SelectionObserver
// for all the selection lists
static void SelectionModifiedCallback
(
vtkObject* caller,
unsigned long eid,
void* clientdata,
void* calldata
);
void SelectionModified();
protected:
vtkPV3FoamReader();
~vtkPV3FoamReader();
char* FileName;
virtual int RequestData
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
virtual int RequestInformation
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
// The observer to modify this object when the array selections
// are modified
vtkCallbackCommand* SelectionObserver;
private:
vtkPV3FoamReader(const vtkPV3FoamReader&); // Not implemented.
void operator=(const vtkPV3FoamReader&); // Not implemented.
//- Add patch names to the view
void addPatchNamesToView();
//- Remove patch names from the view
void removePatchNamesFromView();
int CacheMesh;
int IncludeSets;
int ShowPatchNames;
int UpdateGUI;
int UpdateGUIOld;
int TimeStep;
int TimeStepRange[2];
vtkDataArraySelection* TimeSelection;
vtkDataArraySelection* RegionSelection;
vtkDataArraySelection* VolFieldSelection;
vtkDataArraySelection* PointFieldSelection;
vtkDataArraySelection* LagrangianFieldSelection;
//BTX
Foam::vtkPV3Foam* foamData_;
//ETX
};
#endif

View File

@ -0,0 +1,11 @@
vtkPV3Foam.C
vtkPV3FoamAddVolumeMesh.C
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamUpdate.C
vtkPV3FoamUpdateInformation.C
vtkPV3FoamConvertMesh.C
LIB = $(FOAM_LIBBIN)/libvtkPV3Foam

View File

@ -0,0 +1,17 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(ParaView_DIR)/VTK \
-I$(ParaView_INST_DIR) \
-I$(ParaView_INST_DIR)/VTK \
-I$(ParaView_INST_DIR)/VTK/Common \
-I$(ParaView_INST_DIR)/VTK/Filtering \
-I$(ParaView_INST_DIR)/VTK/Rendering \
-I../PV3FoamReader
LIB_LIBS = \
-lfiniteVolume \
-llagrangian \
-lmeshTools \
$(GLIBS)

View File

@ -0,0 +1,16 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(ParaView_DIR) \
-I$(ParaView_DIR)/VTK \
-I$(ParaView_DIR)/VTK/Common \
-I$(ParaView_DIR)/VTK/Filtering \
-I$(ParaView_DIR)/VTK/Rendering \
-I../PV3FoamReader
LIB_LIBS = \
-lfiniteVolume \
-llagrangian \
-lmeshTools \
$(GLIBS)

View File

@ -0,0 +1,736 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "argList.H"
#include "Time.H"
#include "IOobjectList.H"
#include "fvMesh.H"
#include "vtkPV3FoamReader.h"
#include "patchZones.H"
// VTK includes
#include "vtkCharArray.h"
#include "vtkDataArraySelection.h"
#include "vtkFieldData.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::vtkPV3Foam, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
#include "vtkPV3FoamAddFields.H"
#include "vtkPV3FoamUpdateInformationFields.H"
void Foam::vtkPV3Foam::resetCounters()
{
// Reset data size counts
lagrangianDataSize_ = 0;
patchDataSize_ = 0;
cellSetDataSize_ = 0;
faceSetDataSize_ = 0;
pointSetDataSize_ = 0;
// Reset region ids
idRegionVolume_ = -1;
idRegionLagrangian_ = -1;
idRegionPatches_ = -1;
idRegionCellSets_ = -1;
idRegionFaceSets_ = -1;
idRegionPointSets_ = -1;
}
void Foam::vtkPV3Foam::SetName
(
vtkUnstructuredGrid* vtkMesh,
const char* name
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::setName" << endl;
}
vtkCharArray* nmArray = vtkCharArray::New();
nmArray->SetName("Name");
size_t len = strlen(name);
nmArray->SetNumberOfTuples(static_cast<vtkIdType>(len) + 1);
char* copy = nmArray->GetPointer(0);
memcpy(copy, name, len);
copy[len] = '\0';
vtkMesh->GetFieldData()->AddArray(nmArray);
nmArray->Delete();
}
void Foam::vtkPV3Foam::setSelectedTime
(
Time& runTime,
vtkPV3FoamReader* reader
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::setSelectedTime" << endl;
}
// Get times list
instantList times = runTime.times();
int timeIndex = min(max(reader->GetTimeStep() + 1, 0), times.size() - 1);
// If this is the first call timeIndex will be 0 ("constant")
// so reset to the first time step if one exists and deselect every
// element of the selection array
if (timeIndex == 0)
{
timeIndex = min(1, times.size() - 1);
reader->GetTimeSelection()->DisableAllArrays();
}
label selectedTimeIndex = -1;
const label nSelectedTimes =
reader->GetTimeSelection()->GetNumberOfArrays();
// Choose latest time
for (label i=nSelectedTimes - 1; i>=0; i--)
{
if (reader->GetTimeSelection()->GetArraySetting(i))
{
word timeName = string::validate<word>
(
reader->GetTimeSelection()->GetArrayName(i)
);
forAll(times, j)
{
if (times[j].name() == timeName)
{
selectedTimeIndex = j;
break;
}
}
break;
}
}
if (selectedTimeIndex != -1)
{
timeIndex = min(selectedTimeIndex, times.size() - 1);
}
if (debug)
{
Info<< "Selecting time " << times[timeIndex].name() << endl;
}
runTime.setTime(times[timeIndex], timeIndex);
times = runTime.times();
// set time step slider range
reader->SetTimeStepRange(0, max(times.size() - 2, 0));
reader->SetTimeStep(timeIndex); // TODO - does nothing???
// reset the time steps ...
reader->GetTimeSelection()->RemoveAllArrays();
forAll (times, timeI)
{
reader->GetTimeSelection()->AddArray(times[timeI].name().c_str());
}
// Disable all the time selections (which are all selected by default) ...
reader->GetTimeSelection()->DisableAllArrays();
// But maintain the selection made previously
if (selectedTimeIndex != -1 && selectedTimeIndex < times.size())
{
reader->GetTimeSelection()->EnableArray
(times[selectedTimeIndex].name().c_str());
}
}
void Foam::vtkPV3Foam::updateSelectedRegions()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateSelectedRegions" << endl;
}
const label nRegions = reader_->GetRegionSelection()->GetNumberOfArrays();
selectedRegions_.setSize(nRegions);
selectedRegionDatasetIds_.setSize(nRegions);
// Read the selected patches and add to the region list
for (int i=0; i<nRegions; i++)
{
selectedRegions_[i] = reader_->GetRegionSelection()
->GetArraySetting(i);
selectedRegionDatasetIds_[i] = -1;
if (debug)
{
Info<< "region" << i << " selected = " << selectedRegions_[i]
<< endl;
}
}
}
Foam::wordList Foam::vtkPV3Foam::getSelectedArrayEntries
(
vtkDataArraySelection* arraySelection
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::getSelectedArrayEntries" << endl;
}
const label nArrays = arraySelection->GetNumberOfArrays();
wordList selections(nArrays);
label j = 0;
for (label i=0; i<nArrays; i++)
{
if (arraySelection->GetArraySetting(i))
{
selections[j] = arraySelection->GetArrayName(i);
if (debug)
{
Info<< "Active array: " << selections[j] << " index: " << j
<< endl;
}
j++;
}
}
// Fill non-selected arrays with 'default' value
for (label k=j; k<nArrays; k++)
{
selections[k] = "undefinedArrayEntry";
}
return selections;
}
void Foam::vtkPV3Foam::setSelectedArrayEntries
(
vtkDataArraySelection* arraySelection,
const wordList& selectedEntries
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::setSelectedArrayEntries" << endl;
}
const label nEntries = arraySelection->GetNumberOfArrays();
// Reset all current entries to 'not selected'
arraySelection->DisableAllArrays();
// Loop through entries, setting values from selectedEntries
forAll (selectedEntries, entryI)
{
if (debug)
{
Info<< "selectedEntries[entryI] = " << selectedEntries[entryI]
<< endl;
}
for (label i=0; i<nEntries; i++)
{
const word arrayName = string::validate<word>
(
arraySelection->GetArrayName(i)
);
if (arrayName == selectedEntries[entryI])
{
if (debug)
{
Info<< "enabling array: " << arrayName << " Index = " << i
<< endl;
}
arraySelection->EnableArray
(
arrayName.c_str()
);
break;
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkPV3Foam::vtkPV3Foam
(
const char* const FileName,
vtkPV3FoamReader* reader,
vtkMultiBlockDataSet* output
)
:
reader_(reader),
argsPtr_(NULL),
dbPtr_(NULL),
meshPtr_(NULL),
patchTextActorsPtrs_(0),
nMesh_(0)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::vtkPV3Foam" << endl;
}
// Set paths
fileName fullCasePath(fileName(FileName).path());
if (!dir(fullCasePath))
{
return;
}
char* argvStrings[3];
argvStrings[0] = new char[12];
strcpy(argvStrings[0], "/vtkPV3Foam");
argvStrings[1] = new char[6];
strcpy(argvStrings[1], "-case");
argvStrings[2] = new char[fullCasePath.size() + 1];
strcpy(argvStrings[2], fullCasePath.c_str());
int argc = 3;
char** argv = &argvStrings[0];
argsPtr_.reset(new argList(argc, argv));
for (int i=0; i<argc; i++)
{
delete[] argvStrings[i];
}
// Create time object
dbPtr_.reset
(
new Time
(
Time::controlDictName,
argsPtr_().rootPath(),
argsPtr_().caseName()
)
);
dbPtr_().functionObjects().off();
resetCounters();
// Set initial cloud name
// TODO - TEMPORARY MEASURE UNTIL CAN PROCESS MULTIPLE CLOUDS
cloudName_ = "";
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkPV3Foam::~vtkPV3Foam()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::~vtkPV3Foam" << endl;
}
if (meshPtr_)
{
delete meshPtr_;
meshPtr_ = NULL;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::UpdateInformation()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::UpdateInformation" << nl
<< "TimeStep = " << reader_->GetTimeStep() << endl;
}
resetCounters();
const wordList selectedArrayEntries = getSelectedArrayEntries
(
reader_->GetRegionSelection()
);
// Clear current region list/array
reader_->GetRegionSelection()->RemoveAllArrays();
// Set current time
setSelectedTime(dbPtr_(), reader_);
// Update region array
updateInformationInternalMesh();
updateInformationLagrangian();
updateInformationPatches();
if (reader_->GetIncludeSets())
{
updateInformationSets();
}
// Update region selection with the data just read in
setSelectedArrayEntries
(
reader_->GetRegionSelection(),
selectedArrayEntries
);
// Update volField array
updateInformationFields<fvPatchField, volMesh>
(
reader_->GetVolFieldSelection()
);
// Update pointField array
updateInformationFields<pointPatchField, pointMesh>
(
reader_->GetPointFieldSelection()
);
// Update lagrangian field array
updateInformationLagrangianFields();
}
void Foam::vtkPV3Foam::Update
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::Update" << endl;
}
// Set up region selection(s)
updateSelectedRegions();
// Update the Foam mesh
updateFoamMesh();
// Convert meshes
convertMeshVolume(output);
convertMeshLagrangian(output);
convertMeshPatches(output);
if (reader_->GetIncludeSets())
{
convertMeshCellSet(output);
convertMeshFaceSet(output);
convertMeshPointSet(output);
}
// Update fields
updateVolFields(output);
updatePointFields(output);
updateLagrangianFields(output);
if (debug)
{
Info<< "Number of data sets after update" << nl
<< " VOLUME = " << output->GetNumberOfDataSets(VOLUME) << nl
<< " LAGRANGIAN = " << output->GetNumberOfDataSets(LAGRANGIAN)
<< nl << " CELLSET = " << output->GetNumberOfDataSets(CELLSET)
<< nl << " FACESET = " << output->GetNumberOfDataSets(FACESET)
<< nl << " POINTSET = " << output->GetNumberOfDataSets(POINTSET)
<< endl;
}
}
double* Foam::vtkPV3Foam::timeSteps()
{
if (dbPtr_.valid())
{
const instantList foamTimes =
dbPtr_().findTimes(dbPtr_().path().path());
double* ts = new double[foamTimes.size()];
for (int i = 0; i < foamTimes.size(); i++)
{
ts[i] = foamTimes[i].value();
if (debug)
{
Info<< "found time = " << ts[i] << endl;
}
}
return ts;
}
else
{
return NULL;
}
}
void Foam::vtkPV3Foam::addPatchNames(vtkRenderer* renderer)
{
if (debug)
{
Info<< "addPatchNames()" << endl;
}
// Remove any patch names previously added to the renderer
removePatchNames(renderer);
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& pbMesh = mesh.boundaryMesh();
// Find the total number of zones
// Each zone will take the patch name
// Number of zones per patch
labelList nZones(pbMesh.size(), 0);
// Per global zone number the average face centre position
DynamicList<point> zoneCentre(pbMesh.size());
if (debug)
{
Info<< "determining patch zones" << endl;
}
// Loop through all patches to determine zones, and centre of each zone
forAll(pbMesh, patchI)
{
const polyPatch& pp = pbMesh[patchI];
// Only include the patch if it is selected
if (reader_->GetRegionArrayStatus(pp.name().c_str()) == 1)
{
const labelListList& edgeFaces = pp.edgeFaces();
const vectorField& n = pp.faceNormals();
boolList featEdge(pp.nEdges(), false);
forAll(edgeFaces, edgeI)
{
const labelList& eFaces = edgeFaces[edgeI];
if (eFaces.size() != 2)
{
featEdge[edgeI] = true;
}
else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
{
featEdge[edgeI] = true;
}
}
// Do topological analysis of patch. Determine disconnected regions
patchZones pZones(pp, featEdge);
nZones[patchI] = pZones.nZones();
labelList zoneNFaces(pZones.nZones(), 0);
// Save start of information for current patch
label patchStart = zoneCentre.size();
// Create storage for additional zone centres
forAll(zoneNFaces, zoneI)
{
zoneCentre.append(vector::zero);
}
// Do averaging per individual zone
forAll(pp, faceI)
{
label zoneI = pZones[faceI];
zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points());
zoneNFaces[zoneI]++;
}
for (label i=0; i<nZones[patchI]; i++)
{
zoneCentre[patchStart + i] /= zoneNFaces[i];
}
}
}
zoneCentre.shrink();
if (debug)
{
Info<< "patch zone centres = " << zoneCentre << endl;
Info<< "zones per patch = " << nZones << endl;
}
// Set the size of the patch labels to max number of zones
patchTextActorsPtrs_.setSize(zoneCentre.size());
if (debug)
{
Info<< "constructing patch labels" << endl;
}
label globalZoneI = 0;
forAll(pbMesh, patchI)
{
const polyPatch& pp = pbMesh[patchI];
if (reader_->GetRegionArrayStatus(pp.name().c_str()) == 1)
{
for (label i=0; i<nZones[patchI]; i++)
{
if (debug)
{
Info<< "patch name = " << pp.name() << endl;
Info<< "anchor = " << zoneCentre[globalZoneI] << endl;
Info<< "globalZoneI = " << globalZoneI << endl;
}
vtkTextActor* txt = vtkTextActor::New();
txt->SetInput(pp.name().c_str());
// Set text properties
vtkTextProperty* tprop = txt->GetTextProperty();
tprop->SetFontFamilyToArial();
tprop->BoldOff();
tprop->ShadowOff();
tprop->SetLineSpacing(1.0);
tprop->SetFontSize(20);
tprop->SetColor(1.0, 0.0, 0.0);
tprop->SetJustificationToCentered();
// Set text to use 3-D world co-ordinates
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
txt->GetPositionCoordinate()->SetValue
(
zoneCentre[globalZoneI].x(),
zoneCentre[globalZoneI].y(),
zoneCentre[globalZoneI].z()
);
// Add text to each renderer
renderer->AddViewProp(txt);
// Maintain a list of text labels added so that they can be
// removed later
patchTextActorsPtrs_[globalZoneI] = txt;
globalZoneI++;
}
}
}
// Resize the patch names list to the actual number of patch names added
patchTextActorsPtrs_.setSize(globalZoneI);
}
void Foam::vtkPV3Foam::removePatchNames(vtkRenderer* renderer)
{
if (debug)
{
Info<< "removePatchNames()" << endl;
}
forAll(patchTextActorsPtrs_, patchI)
{
renderer->RemoveViewProp(patchTextActorsPtrs_[patchI]);
}
patchTextActorsPtrs_.setSize(0);
}
int Foam::vtkPV3Foam::numberOfTimeSteps()
{
if (dbPtr_.valid())
{
return dbPtr_().times().size();
}
else
{
return 0;
}
}
int Foam::vtkPV3Foam::numberOfPoints()
{
if (meshPtr_)
{
return meshPtr_->nPoints();
}
else
{
return 0;
}
}
int Foam::vtkPV3Foam::numberOfCells()
{
if (meshPtr_)
{
return meshPtr_->nCells();
}
{
return 0;
}
}
int Foam::vtkPV3Foam::numberOfMeshes() const
{
return nMesh_;
}
// ************************************************************************* //

View File

@ -0,0 +1,534 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::vtkPV3Foam
Description
SourceFiles
interpolatePointToCell.C
interpolatePointToCell.H
vtkPV3Foam.C
vtkPV3Foam.H
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddFields.H
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamAddVolumeMesh.C
vtkPV3FoamConvertLagrangianFields.H
vtkPV3FoamConvertMesh.C
vtkPV3FoamConvertPatchFaceField.H
vtkPV3FoamConvertPatchPointField.H
vtkPV3FoamConvertPointFields.H
vtkPV3FoamConvertVolFields.H
vtkPV3FoamInsertNextPoint.H
vtkPV3FoamUpdate.C
vtkPV3FoamUpdateInformation.C
vtkPV3FoamUpdateInformationFields.H
// Needed by VTK?
vtkDataArrayTemplateImplicit.txx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3Foam_H
#define vtkPV3Foam_H
#include "className.H"
#include "fileName.H"
#include "volPointInterpolation.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
class vtkMultiBlockDataSet;
class vtkPoints;
class vtkPV3FoamReader;
class vtkRenderer;
class vtkTextActor;
class vtkUnstructuredGrid;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Foam class forward declarations
class argList;
class Time;
class fvMesh;
class IOobjectList;
class polyPatch;
class faceSet;
class pointSet;
class WordList;
template<class Type>
class IOField;
template<class Type>
class List;
/*---------------------------------------------------------------------------*\
Class vtkPV3Foam Declaration
\*---------------------------------------------------------------------------*/
class vtkPV3Foam
{
// Private data
//BTX
//- Indices for datasets in vtkMultiBlockDataSet
enum
{
VOLUME = 0, // internal mesh AND patches
LAGRANGIAN = 1,
CELLSET = 2,
FACESET = 3,
POINTSET = 4
};
//ETX
//- Indices of (first instance of) various regions
int idRegionVolume_;
int idRegionLagrangian_;
int idRegionPatches_;
int idRegionCellSets_;
int idRegionFaceSets_;
int idRegionPointSets_;
//- Access to the controlling vtkPV3FoamReader
vtkPV3FoamReader* reader_;
//- Selected regions
// [0] = internal mesh, then lagrangian, patches, and sets
boolList selectedRegions_;
//- Selected regions indices in each respective block
labelList selectedRegionDatasetIds_;
//- Foam argument handler
autoPtr<argList> argsPtr_;
//- Path to root and case
fileName rootPath_;
fileName casePath_;
//- Foam time control
autoPtr<Time> dbPtr_;
//- Foam mesh
fvMesh* meshPtr_;
//- Labels of cell-centres used as additional points when decomposing
// polyhedra
labelList addPointCellLabels_;
//- Label of original cell the decomposed cells are split from
// - internal mesh
labelList superCells_;
//- Label of original cell the decomposed cells are split from
// - cell set meshes
List<labelList> superCellSetCells_;
//- List of patch names
List<vtkTextActor*> patchTextActorsPtrs_;
// Dataset sizes
//- Number of meshes
// TODO - for info only - only set up to process ONE mesh
int nMesh_;
//- Lagrangian data size (i.e. 0 or 1)
int lagrangianDataSize_;
//- Cloud name to be processed
// TODO - currently only set up to process ONE cloud
word cloudName_;
//- Patch data size, 0 to n
int patchDataSize_;
//- Cell set data size, 0 to n
int cellSetDataSize_;
//- Face set data size, 0 to n
int faceSetDataSize_;
//- Point set data size, 0 to n
int pointSetDataSize_;
// Private Member Functions
//- Reset data counters
void resetCounters();
//- Find and set the selected time from all the methods of selection
static void setSelectedTime
(
Time& runTime,
vtkPV3FoamReader* reader
);
// Update information helper functions
//- Update the regions selected in the GUI
void updateSelectedRegions();
//- Internal mesh info
void updateInformationInternalMesh();
//- Lagrangian info
void updateInformationLagrangian();
//- Patch info
void updateInformationPatches();
//- Set info
void updateInformationSets();
//- Field info
template<template<class> class patchType, class meshType>
void updateInformationFields
(
vtkDataArraySelection *fieldSelection
);
//- Lagrangian field info
void updateInformationLagrangianFields();
// Update helper functions
//- Foam mesh
void updateFoamMesh();
//- Volume fields
void updateVolFields(vtkMultiBlockDataSet* output);
//- Point fields
void updatePointFields(vtkMultiBlockDataSet* output);
//- Lagrangian fields
void updateLagrangianFields(vtkMultiBlockDataSet* output);
// Mesh conversion functions
//- Volume mesh
void convertMeshVolume(vtkMultiBlockDataSet* output);
//- Lagrangian mesh
void convertMeshLagrangian(vtkMultiBlockDataSet* output);
//- Patch meshes
void convertMeshPatches(vtkMultiBlockDataSet* output);
//- Cell set meshes
void convertMeshCellSet(vtkMultiBlockDataSet* output);
//- Face set meshes
void convertMeshFaceSet(vtkMultiBlockDataSet* output);
//- Point set meshes
void convertMeshPointSet(vtkMultiBlockDataSet* output);
// Add mesh functions
//- Add internal mesh/cell set meshes
void addVolumeMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh,
labelList& superCells
);
//- Add Lagrangian mesh
void addLagrangianMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh
);
//- Add patch mesh
void addPatchMesh
(
const polyPatch& p,
vtkUnstructuredGrid* vtkMesh
);
//- Add cell set mesh
void addCellSetMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh
);
//- Add face set mesh
void addFaceSetMesh
(
const fvMesh& mesh,
const faceSet& fSet,
vtkUnstructuredGrid* vtkMesh
);
//- Add point mesh
void addPointSetMesh
(
const fvMesh& mesh,
const pointSet& pSet,
vtkUnstructuredGrid* vtkMesh
);
//- Add the fields in the selected time directory to the selection
// lists
template<class GeoField>
void addFields
(
vtkDataArraySelection* fieldSelection,
const IOobjectList& objects
);
// Convert Foam fields
//- Volume fields - all types
template<class Type>
void convertVolFields
(
const fvMesh& mesh,
const volPointInterpolation& pInterp,
const IOobjectList& objects,
vtkDataArraySelection* fieldSelection,
vtkMultiBlockDataSet* output
);
//- Volume field - all types except scalar
template<class Type>
void convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output
);
//- Patch field
template<class Type>
void convertPatchFaceField
(
const word& name,
const Field<Type>& tf,
const label regioni,
vtkMultiBlockDataSet* output
);
//- Lagrangian fields - all types
template<class Type>
void convertLagrangianFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection,
vtkMultiBlockDataSet* output
);
//- Lagrangian field - all types except scalar
template<class Type>
void convertLagrangianField
(
const IOField<Type>& tf,
vtkMultiBlockDataSet* output
);
//- Point fields - all types
template<class Type>
void convertPointFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection,
vtkMultiBlockDataSet* output
);
//- Point fields - all types except scalar
template<class Type>
void convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output
);
//- Patch point field - all types except scalar
template<class Type>
void convertPatchPointField
(
const word& name,
const Field<Type>& tf,
const label regioni,
vtkMultiBlockDataSet* output
);
// GUI selection helper functions
//- Store selection(s)
wordList getSelectedArrayEntries
(
vtkDataArraySelection* arraySelection
);
//- Set selection(s)
void setSelectedArrayEntries
(
vtkDataArraySelection* arraySelection,
const wordList& selectedEntries
);
//- Set the name VTK objects
void SetName(vtkUnstructuredGrid* vtkMesh, const char* name);
//- Disallow default bitwise copy construct
vtkPV3Foam(const vtkPV3Foam&);
//- Disallow default bitwise assignment
void operator=(const vtkPV3Foam&);
public:
//- Static data members
ClassName("vtkPV3Foam");
// Constructors
//- Construct from components
vtkPV3Foam
(
const char* const FileName,
vtkPV3FoamReader* reader,
vtkMultiBlockDataSet* output
);
//- Destructor
~vtkPV3Foam();
// Member Functions
void UpdateInformation();
void Update(vtkMultiBlockDataSet* output);
double* timeSteps();
//- Add patch names to the display
void addPatchNames(vtkRenderer* renderer);
//- Remove patch names from the display
void removePatchNames(vtkRenderer* renderer);
// Access
int numberOfTimeSteps();
int numberOfCells();
int numberOfPoints();
int numberOfMeshes() const;
};
// * * * * * * * * * * * * * Template Specialisations * * * * * * * * * * * //
template<>
void vtkPV3Foam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output
);
template<>
void vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<scalar>& sf,
const label regioni,
vtkMultiBlockDataSet* output
);
template<>
void vtkPV3Foam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>& psf,
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output
);
template<>
void vtkPV3Foam::convertPatchPointField
(
const word& name,
const Field<scalar>& sf,
const label regioni,
vtkMultiBlockDataSet* output
);
template<>
void vtkPV3Foam::convertLagrangianField
(
const IOField<scalar>& sf,
vtkMultiBlockDataSet* output
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,104 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "faceSet.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolygon.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addFaceSetMesh
(
const fvMesh& mesh,
const faceSet& fSet,
vtkUnstructuredGrid* vtkMesh
)
{
if (debug)
{
Info<< "entered add face set internal mesh" << endl;
}
SetName(vtkMesh, "faceSetMesh");
// Construct primitivePatch of faces in fSet.
const faceList& faces = mesh.faces();
faceList setFaces(fSet.size());
label setFaceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
setFaces[setFaceI++] = faces[iter.key()];
}
primitiveFacePatch fp(setFaces, mesh.points());
// Add face points
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(fp.size());
forAll(fp.localPoints(), i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, fp.localPoints()[i]);
}
// Add faces as polygons
vtkMesh->Allocate(fp.size());
forAll(fp.localFaces(), faceI)
{
const face& f = fp.localFaces()[faceI];
vtkIdType nodeIds[f.size()];
for (int j=0; j<f.size(); j++)
{
nodeIds[j] = f[j];
}
vtkMesh->InsertNextCell
(
VTK_POLYGON,
f.size(),
nodeIds
);
}
vtkMesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,58 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamAddFields_H
#define vtkPV3FoamAddFields_H
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::vtkPV3Foam::addFields
(
vtkDataArraySelection *fieldSelection,
const IOobjectList& objects
)
{
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
forAllConstIter(IOobjectList, fieldObjects, iter)
{
fieldSelection->AddArray(iter()->name().c_str());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,94 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "Cloud.H"
#include "fvMesh.H"
#include "passiveParticle.H"
#include "vtkPV3FoamInsertNextPoint.H"
#include "IOobjectList.H"
// Foam includes
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addLagrangianMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh
)
{
if (debug)
{
Info<< "entered add Lagrangian mesh" << endl;
}
SetName(vtkMesh, "LagrangianMesh");
fileNameList cloudDirs
(
readDir(mesh.time().timePath()/"lagrangian", fileName::DIRECTORY)
);
bool foundCloud = false;
forAll(cloudDirs, i)
{
IOobjectList sprayObjs
(
mesh,
mesh.time().timeName(),
"lagrangian"/cloudDirs[i]
);
IOobject* positionsPtr = sprayObjs.lookup("positions");
if (positionsPtr && !foundCloud)
{
foundCloud = true;
Cloud<passiveParticle> parcels(mesh, cloudDirs[i], false);
vtkPoints* vtkpoints = vtkPoints::New();
vtkpoints->Allocate(parcels.size());
forAllConstIter(Cloud<passiveParticle>, parcels, elmnt)
{
vtkPV3FoamInsertNextPoint(vtkpoints, elmnt().position());
}
vtkMesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,131 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "polyPatch.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPatchMesh
(
const polyPatch& p,
vtkUnstructuredGrid *vtkPatch
)
{
if (debug)
{
Info<< "Adding patch: " << p.name() << endl;
}
SetName(vtkPatch, p.name().c_str());
if (debug)
{
Info<< "converting points" << endl;
}
const Foam::pointField& points = p.localPoints();
// Convert Foam mesh vertices to VTK
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(points.size());
forAll(points, i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
}
if (debug)
{
Info<< "converting faces" << endl;
}
const faceList& faces = p.localFaces();
vtkPatch->Allocate(faces.size());
forAll(faces, facei)
{
const face& f = faces[facei];
vtkIdType nodeIds[f.size()];
if (f.size() == 3)
{
for (int j=0; j<3; j++)
{
nodeIds[j] = f[j];
}
vtkPatch->InsertNextCell
(
VTK_TRIANGLE,
3,
nodeIds
);
}
else if (f.size() == 4)
{
for (int j=0; j<4; j++)
{
nodeIds[j] = f[j];
}
vtkPatch->InsertNextCell
(
VTK_QUAD,
4,
nodeIds
);
}
else
{
for (int j=0; j<f.size(); j++)
{
nodeIds[j] = f[j];
}
vtkPatch->InsertNextCell
(
VTK_POLYGON,
f.size(),
nodeIds
);
}
}
vtkPatch->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,68 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "pointSet.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPointSetMesh
(
const fvMesh& mesh,
const pointSet& pSet,
vtkUnstructuredGrid* vtkMesh
)
{
if (debug)
{
Info<< "entered add point set mesh" << endl;
}
SetName(vtkMesh, "pointSetMesh");
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(mesh.nPoints());
forAllConstIter(pointSet, pSet, iter)
{
vtkPV3FoamInsertNextPoint(vtkpoints, mesh.points()[iter.key()]);
}
vtkMesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,362 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamAddVolumeMesh_H
#define vtkPV3FoamAddVolumeMesh_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "vtkPV3Foam.H"
// Foam includes
#include "fvMesh.H"
#include "cellModeller.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addVolumeMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh,
labelList& superCells
)
{
if (debug)
{
Info<< "entered add volume mesh" << endl;
}
SetName(vtkMesh, "internalMesh");
// Number of additional points needed by the decomposition of polyhedra
label nAddPoints = 0;
// Number of additional cells generated by the decomposition of polyhedra
label nAddCells = 0;
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
const cellModel& hex = *(cellModeller::lookup("hex"));
// Scan for cells which need to be decomposed and count additional points
// and cells
if (debug)
{
Info<< "building cell-shapes" << endl;
}
const cellShapeList& cellShapes = mesh.cellShapes();
if (debug)
{
Info<< "scanning" << endl;
}
forAll(cellShapes, cellI)
{
const cellModel& model = cellShapes[cellI].model();
if
(
model != hex
&& model != wedge
&& model != prism
&& model != pyr
&& model != tet
&& model != tetWedge
)
{
const cell& cFaces = mesh.cells()[cellI];
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
label nFacePoints = f.size();
label nQuads = (nFacePoints - 2)/2;
label nTris = (nFacePoints - 2)%2;
nAddCells += nQuads + nTris;
}
nAddCells--;
nAddPoints++;
}
}
// Set size of additional point addressing array
// (from added point to original cell)
addPointCellLabels_.setSize(nAddPoints);
// Set size of additional cells mapping array
// (from added cell to original cell)
if (debug)
{
Info<<"mesh.nCells() = " << mesh.nCells() << nl
<<"mesh.nPoints() = " << mesh.nPoints() << nl
<<"nAddCells = " << nAddCells << nl
<<"nAddPoints = " << nAddPoints << endl;
}
superCells.setSize(mesh.nCells() + nAddCells);
if (debug)
{
Info<< "converting points" << endl;
}
// Convert Foam mesh vertices to VTK
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(mesh.nPoints() + nAddPoints);
const Foam::pointField& points = mesh.points();
forAll(points, i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
}
if (debug)
{
Info<< "converting cells" << endl;
}
vtkMesh->Allocate(mesh.nCells() + nAddCells);
// Set counters for additional points and additional cells
label api = 0, aci = 0;
// Create storage for points - needed for mapping from Foam to VTK
// data types - max 'order' = hex = 8 points
vtkIdType nodeIds[8];
forAll(cellShapes, celli)
{
const cellShape& cellShape = cellShapes[celli];
const cellModel& cellModel = cellShape.model();
superCells[aci++] = celli;
if (cellModel == tet)
{
for (int j = 0; j < 4; j++)
{
nodeIds[j] = cellShape[j];
}
vtkMesh->InsertNextCell
(
VTK_TETRA,
4,
nodeIds
);
}
else if (cellModel == pyr)
{
for (int j = 0; j < 5; j++)
{
nodeIds[j] = cellShape[j];
}
vtkMesh->InsertNextCell
(
VTK_PYRAMID,
5,
nodeIds
);
}
else if (cellModel == prism)
{
for (int j = 0; j < 6; j++)
{
nodeIds[j] = cellShape[j];
}
vtkMesh->InsertNextCell
(
VTK_WEDGE,
6,
nodeIds
);
}
else if (cellModel == tetWedge)
{
// Treat as squeezed prism
nodeIds[0] = cellShape[0];
nodeIds[1] = cellShape[2];
nodeIds[2] = cellShape[1];
nodeIds[3] = cellShape[3];
nodeIds[4] = cellShape[4];
nodeIds[5] = cellShape[4];
vtkMesh->InsertNextCell
(
VTK_WEDGE,
6,
nodeIds
);
}
else if (cellModel == wedge)
{
// Treat as squeezed hex
nodeIds[0] = cellShape[0];
nodeIds[1] = cellShape[1];
nodeIds[2] = cellShape[2];
nodeIds[3] = cellShape[2];
nodeIds[4] = cellShape[3];
nodeIds[5] = cellShape[4];
nodeIds[6] = cellShape[5];
nodeIds[7] = cellShape[6];
vtkMesh->InsertNextCell
(
VTK_HEXAHEDRON,
8,
nodeIds
);
}
else if (cellModel == hex)
{
for (int j = 0; j < 8; j++)
{
nodeIds[j] = cellShape[j];
}
vtkMesh->InsertNextCell
(
VTK_HEXAHEDRON,
8,
nodeIds
);
}
else
{
// Polyhedral cell. Decompose into tets + prisms.
// Mapping from additional point to cell
addPointCellLabels_[api] = celli;
// Insert the new vertex from the cell-centre
label newVertexLabel = mesh.nPoints() + api;
vtkPV3FoamInsertNextPoint(vtkpoints, mesh.C()[celli]);
// Whether to insert cell in place of original or not.
bool substituteCell = true;
const labelList& cFaces = mesh.cells()[celli];
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
label nFacePoints = f.size();
label nQuads = (nFacePoints - 2)/2;
label nTris = (nFacePoints - 2)%2;
label qpi = 0;
for (label quadi=0; quadi<nQuads; quadi++)
{
label thisCellI = -1;
if (substituteCell)
{
thisCellI = celli;
substituteCell = false;
}
else
{
thisCellI = mesh.nCells() + aci;
superCells[aci++] = celli;
}
nodeIds[0] = f[0];
nodeIds[1] = f[qpi + 1];
nodeIds[2] = f[qpi + 2];
nodeIds[3] = f[qpi + 3];
nodeIds[4] = newVertexLabel;
vtkMesh->InsertNextCell
(
VTK_PYRAMID,
5,
nodeIds
);
qpi += 2;
}
if (nTris)
{
label thisCellI = -1;
if (substituteCell)
{
thisCellI = celli;
substituteCell = false;
}
else
{
thisCellI = mesh.nCells() + aci;
superCells[aci++] = celli;
}
nodeIds[0] = f[0];
nodeIds[1] = f[qpi + 1];
nodeIds[2] = f[qpi + 2];
nodeIds[3] = newVertexLabel;
vtkMesh->InsertNextCell
(
VTK_TETRA,
4,
nodeIds
);
}
}
api++;
}
}
vtkMesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,182 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertLagrangianFields_H
#define vtkPV3FoamConvertLagrangianFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertLagrangianFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection* fieldSelection,
vtkMultiBlockDataSet* output
)
{
if (!lagrangianDataSize_)
{
return;
}
if (!selectedRegions_[LAGRANGIAN])
{
return;
}
IOobjectList fieldObjects
(
objects.lookupClass
(
IOField<Type>::typeName
)
);
label nSelectedFields = fieldSelection->GetNumberOfArrays();
for (label i=0; i<nSelectedFields; i++)
{
if (fieldSelection->GetArraySetting(i))
{
const word fieldName = fieldSelection->GetArrayName(i);
if (fieldObjects.found(fieldName))
{
if (debug)
{
Info<< "converting Foam Lagrangian field: " << fieldName
<< endl;
}
IOField<Type> iotf
(
IOobject
(
fieldName,
mesh.time().timeName(),
"lagrangian"/cloudName_,
mesh,
IOobject::MUST_READ
)
);
convertLagrangianField(iotf, output);
}
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertLagrangianField
(
const IOField<Type>& tf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* lagrangianMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(LAGRANGIAN, 0)
);
vtkFloatArray *pointTypes = vtkFloatArray::New();
pointTypes->SetNumberOfTuples(tf.size());
pointTypes->SetNumberOfComponents(Type::nComponents);
pointTypes->Allocate(Type::nComponents*tf.size());
pointTypes->SetName(tf.name().c_str());
if (debug)
{
Info<< "converting Lagrangian <Type>Field: " << tf.name() << nl
<< "tf.size() = " << tf.size() << nl
<< "nComps = " << Type::nComponents << endl;
}
float vec[Type::nComponents];
forAll(tf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = tf[i][d];
}
pointTypes->InsertTuple(i, vec);
}
lagrangianMesh->GetPointData()->AddArray(pointTypes);
pointTypes->Delete();
}
template<>
void Foam::vtkPV3Foam::convertLagrangianField
(
const IOField<scalar>& sf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* lagrangianMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(LAGRANGIAN, 0)
);
vtkFloatArray *pointScalars = vtkFloatArray::New();
pointScalars->SetNumberOfTuples(sf.size());
pointScalars->SetNumberOfComponents(1);
pointScalars->Allocate(sf.size());
pointScalars->SetName(sf.name().c_str());
if (debug)
{
Info<< "converting Lagrangian scalarField: " << sf.name() << nl
<< "sf.size() = " << sf.size() << nl
<< "nComps = 1" << endl;
}
for (int i=0; i<sf.size(); i++)
{
pointScalars->InsertComponent(i, 0, sf[i]);
}
lagrangianMesh->GetPointData()->AddArray(pointScalars);
if (!lagrangianMesh->GetPointData()->GetScalars())
{
lagrangianMesh->GetPointData()->SetScalars(pointScalars);
}
pointScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,309 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "cellSet.H"
#include "faceSet.H"
#include "fvMeshSubset.H"
#include "pointSet.H"
#include "vtkPV3FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::convertMeshVolume
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshVolume" << endl;
}
// Create the internal mesh and add as DataSet(VOLUME, 0)
if (selectedRegions_[VOLUME])
{
if (debug)
{
Info<< "Creating VTK internal mesh" << endl;
}
const fvMesh& mesh = *meshPtr_;
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
SetName(ugrid, "internalMesh");
addVolumeMesh(mesh, ugrid, superCells_);
output->SetDataSet(VOLUME, 0, ugrid);
selectedRegionDatasetIds_[VOLUME] = 0;
ugrid->Delete();
}
}
void Foam::vtkPV3Foam::convertMeshLagrangian
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
}
// Create the Lagrangian mesh and add as DataSet(LAGRANGIAN, 0)
if (lagrangianDataSize_)
{
if (selectedRegions_[LAGRANGIAN])
{
if (debug)
{
Info<< "Creating VTK Lagrangian mesh" << endl;
}
const fvMesh& mesh = *meshPtr_;
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
addLagrangianMesh(mesh, ugrid);
output->SetDataSet(LAGRANGIAN, 0, ugrid);
selectedRegionDatasetIds_[LAGRANGIAN] = 0;
ugrid->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshPatches
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshPatches" << endl;
}
// Convert patches
if (patchDataSize_)
{
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& patches = mesh.boundaryMesh();
const label regionStartId = idRegionPatches_;
const label regionEndId = idRegionPatches_ + patchDataSize_ - 1;
// Create the patches and add as DataSet(VOLUME, ...)
for (int i=regionStartId; i<=regionEndId; i++)
{
if (selectedRegions_[i])
{
const word regionName = reader_->GetRegionSelection()
->GetArrayName(i);
if (debug)
{
Info<< "Creating VTK mesh for patch: " << regionName
<< " region index: " << i << endl;
}
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
const label patchId = mesh.boundaryMesh()
.findPatchID(regionName);
addPatchMesh(patches[patchId], ugrid);
const label nextId = output->GetNumberOfDataSets(VOLUME);
output->SetDataSet(VOLUME, nextId, ugrid);
selectedRegionDatasetIds_[i] = nextId;
ugrid->Delete();
}
}
}
}
void Foam::vtkPV3Foam::convertMeshCellSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshCellSet" << endl;
}
// Create the cell sets and add as DataSet(CELLSET, 0..n)
if (cellSetDataSize_)
{
const fvMesh& mesh = *meshPtr_;
const label regionStartId = idRegionCellSets_;
const label regionEndId = regionStartId + cellSetDataSize_ - 1;
for (int i=regionStartId; i<=regionEndId; i++)
{
if (selectedRegions_[i])
{
const word cSetName = reader_->GetRegionSelection()
->GetArrayName(i);
if (debug)
{
Info<< "Creating VTK mesh for cellSet: " << cSetName
<< " region index: " << i << endl;
}
const cellSet cSet(mesh, cSetName);
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(cSet);
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
SetName(ugrid, cSetName.c_str());
const label nextId = output->GetNumberOfDataSets(CELLSET);
addVolumeMesh
(
subsetter.subMesh(),
ugrid,
superCellSetCells_[nextId]
);
output->SetDataSet(CELLSET, nextId, ugrid);
selectedRegionDatasetIds_[i] = nextId;
ugrid->Delete();
}
}
}
}
void Foam::vtkPV3Foam::convertMeshFaceSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshFaceSet" << endl;
}
// Create the face sets and add as DataSet(FACESET, 0..n)
if (faceSetDataSize_)
{
const fvMesh& mesh = *meshPtr_;
const label regionStartId = idRegionFaceSets_;
const label regionEndId = regionStartId + faceSetDataSize_ - 1;
for (int i=regionStartId; i<=regionEndId ; i++)
{
if (selectedRegions_[i])
{
const word fSetName = reader_->GetRegionSelection()
->GetArrayName(i);
if (debug)
{
Info<< "Creating VTK mesh for faceSet: " << fSetName
<< " region index: " << i << endl;
}
const faceSet fSet(mesh, fSetName);
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
SetName(ugrid, fSetName.c_str());
addFaceSetMesh
(
mesh,
fSet,
ugrid
);
const label nextId = output->GetNumberOfDataSets(FACESET);
output->SetDataSet(FACESET, nextId, ugrid);
selectedRegionDatasetIds_[i] = nextId;
ugrid->Delete();
}
}
}
}
void Foam::vtkPV3Foam::convertMeshPointSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshPointSet" << endl;
}
// Create the point sets and add as DataSet(POINTSET, 0..n)
if (pointSetDataSize_)
{
const fvMesh& mesh = *meshPtr_;
const label regionStartId = idRegionPointSets_;
const label regionEndId = regionStartId + pointSetDataSize_ - 1;
for (int i=regionStartId; i<=regionEndId ; i++)
{
if (selectedRegions_[i])
{
const word pSetName = reader_->GetRegionSelection()
->GetArrayName(i);
if (debug)
{
Info<< "Creating VTK mesh for pointSet: " << pSetName
<< " region index: " << i << endl;
}
const pointSet pSet(mesh, pSetName);
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
SetName(ugrid, pSetName.c_str());
addPointSetMesh
(
mesh,
pSet,
ugrid
);
const label nextId = output->GetNumberOfDataSets(POINTSET);
output->SetDataSet(POINTSET, nextId, ugrid);
selectedRegionDatasetIds_[i] = nextId;
ugrid->Delete();
}
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertPatchFaceField_H
#define vtkPV3FoamConvertPatchFaceField_H
// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<Type>& ptf,
const label regioni,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, regioni)
);
vtkFloatArray *cellTypes = vtkFloatArray::New();
cellTypes->SetNumberOfTuples(ptf.size());
cellTypes->SetNumberOfComponents(Type::nComponents);
cellTypes->Allocate(Type::nComponents*ptf.size());
cellTypes->SetName(name.c_str());
float vec[Type::nComponents];
forAll(ptf, i)
{
const Type& t = ptf[i];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
cellTypes->InsertTuple(i, vec);
}
vtkMesh->GetCellData()->AddArray(cellTypes);
cellTypes->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<scalar>& psf,
const label regioni,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, regioni)
);
vtkFloatArray *cellScalars = vtkFloatArray::New();
cellScalars->SetNumberOfTuples(psf.size());
cellScalars->SetNumberOfComponents(1);
cellScalars->Allocate(psf.size());
cellScalars->SetName(name.c_str());
forAll(psf, i)
{
cellScalars->InsertComponent(i, 0, psf[i]);
}
vtkMesh->GetCellData()->AddArray(cellScalars);
if (!vtkMesh->GetCellData()->GetScalars())
{
vtkMesh->GetCellData()->SetScalars(cellScalars);
}
cellScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertPatchPointField_H
#define vtkPV3FoamConvertPatchPointField_H
// VTK includes
#include "vtkPointData.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertPatchPointField
(
const word& name,
const Field<Type>& pptf,
const label regioni,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, regioni)
);
vtkFloatArray *pointTypes = vtkFloatArray::New();
pointTypes->SetNumberOfTuples(pptf.size());
pointTypes->SetNumberOfComponents(Type::nComponents);
pointTypes->Allocate(Type::nComponents*pptf.size());
pointTypes->SetName(name.c_str());
float vec[Type::nComponents];
forAll(pptf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = pptf[i][d];
}
pointTypes->InsertTuple(i, vec);
}
vtkMesh->GetPointData()->AddArray(pointTypes);
pointTypes->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPatchPointField
(
const word& name,
const Field<scalar>& ppsf,
const label regioni,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* vtkMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, regioni)
);
vtkFloatArray *pointScalars = vtkFloatArray::New();
pointScalars->SetNumberOfTuples(ppsf.size());
pointScalars->SetNumberOfComponents(1);
pointScalars->Allocate(ppsf.size());
pointScalars->SetName(name.c_str());
for (int i=0; i<ppsf.size(); i++)
{
pointScalars->InsertComponent(i, 0, ppsf[i]);
}
vtkMesh->GetPointData()->AddArray(pointScalars);
if (!vtkMesh->GetPointData()->GetScalars())
{
vtkMesh->GetPointData()->SetScalars(pointScalars);
}
pointScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,255 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertPointFields_H
#define vtkPV3FoamConvertPointFields_H
// Foam includes
#include "interpolatePointToCell.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertPointFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection* fieldSelection,
vtkMultiBlockDataSet* output
)
{
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, pointPatchField, pointMesh>::typeName
)
);
label nSelectedFields = fieldSelection->GetNumberOfArrays();
for (label i=0; i<nSelectedFields; i++)
{
if (fieldSelection->GetArraySetting(i))
{
word fieldName = fieldSelection->GetArrayName(i);
if (fieldObjects.found(fieldName))
{
if (debug)
{
Info<< "converting Foam point field: " << fieldName
<< endl;
}
pointMesh pMesh(mesh);
GeometricField<Type, pointPatchField, pointMesh> ptf
(
IOobject
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
),
pMesh
);
// Convert internal mesh
if (selectedRegions_[0])
{
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null(),
output
);
}
// Convert patches
label regioni = idRegionPatches_;
forAll (mesh.boundaryMesh(), patchi)
{
if (mesh.boundaryMesh()[patchi].size())
{
if (selectedRegions_[regioni])
{
convertPatchPointField
(
ptf.name(),
ptf.boundaryField()[patchi]
.patchInternalField()(),
selectedRegionDatasetIds_[regioni],
output
);
}
regioni++;
}
}
}
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, 0)
);
vtkFloatArray *pointTypes = vtkFloatArray::New();
pointTypes->SetNumberOfTuples(ptf.size() + addPointCellLabels_.size());
pointTypes->SetNumberOfComponents(Type::nComponents);
pointTypes->Allocate(Type::nComponents*ptf.size());
pointTypes->SetName(ptf.name().c_str());
float vec[Type::nComponents];
forAll(ptf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = ptf[i][d];
}
pointTypes->InsertTuple(i, vec);
}
label i = ptf.size();
if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
Type t = tf[addPointCellLabels_[api]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
pointTypes->InsertTuple(i++, vec);
}
}
else
{
forAll(addPointCellLabels_, api)
{
Type t = interpolatePointToCell(ptf, addPointCellLabels_[api]);
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
pointTypes->InsertTuple(i++, vec);
}
}
internalMesh->GetPointData()->AddArray(pointTypes);
pointTypes->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>& psf,
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, 0)
);
vtkFloatArray *pointScalars = vtkFloatArray::New();
pointScalars->SetNumberOfTuples(psf.size() + addPointCellLabels_.size());
pointScalars->SetNumberOfComponents(1);
pointScalars->Allocate(psf.size());
pointScalars->SetName(psf.name().c_str());
for (int i=0; i<psf.size(); i++)
{
pointScalars->InsertComponent(i, 0, psf[i]);
}
label i = psf.size();
if (&sf != &GeometricField<scalar, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
pointScalars->InsertComponent
(
i++,
0,
sf[addPointCellLabels_[api]]
);
}
}
else
{
forAll(addPointCellLabels_, api)
{
pointScalars->InsertComponent
(
i++,
0,
interpolatePointToCell(psf, addPointCellLabels_[api])
);
}
}
internalMesh->GetPointData()->AddArray(pointScalars);
if (!internalMesh->GetPointData()->GetScalars())
{
internalMesh->GetPointData()->SetScalars(pointScalars);
}
pointScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,259 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertVolFields_H
#define vtkPV3FoamConvertVolFields_H
// Foam includes
#include "emptyFvPatchField.H"
#include "vtkPV3FoamConvertPatchFaceField.H"
#include "vtkPV3FoamConvertPatchPointField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertVolFields
(
const fvMesh& mesh,
const volPointInterpolation& pInterp,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection,
vtkMultiBlockDataSet* output
)
{
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, fvPatchField, volMesh>::typeName
)
);
label nFields = fieldSelection->GetNumberOfArrays();
for (label i=0; i<nFields; i++)
{
if (fieldSelection->GetArraySetting(i))
{
const word fieldName = fieldSelection->GetArrayName(i);
if (fieldObjects.found(fieldName))
{
if (debug)
{
Info<< "converting Foam volume field: " << fieldName
<< endl;
}
GeometricField<Type, fvPatchField, volMesh> tf
(
IOobject
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
),
mesh
);
tmp<GeometricField<Type, pointPatchField, pointMesh> > tptf
(
pInterp.interpolate(tf)
);
// Convert internal mesh
if (selectedRegions_[0])
{
convertVolField(tf, output);
convertPointField(tptf(), tf, output);
}
// Convert patches
const label regionStartId = idRegionPatches_;
const label regionEndId = idRegionPatches_
+ patchDataSize_ - 1;
for (label i=regionStartId; i<=regionEndId; i++)
{
if (selectedRegions_[i])
{
const word regionName = reader_->GetRegionSelection()
->GetArrayName(i);
const label patchId = mesh.boundaryMesh()
.findPatchID(regionName);
const fvPatchField<Type>& ptf
(
tf.boundaryField()[patchId]
);
if (!isType<emptyFvPatchField<Type> >(ptf))
{
convertPatchFaceField
(
tf.name(),
ptf,
selectedRegionDatasetIds_[i],
output
);
convertPatchPointField
(
tptf().name(),
tptf().boundaryField()[patchId]
.patchInternalField()(),
selectedRegionDatasetIds_[i],
output
);
}
else
{
fvPatch p
(
ptf.patch().patch(),
tf.mesh().boundary()
);
convertPatchFaceField
(
tf.name(),
fvPatchField<Type>(p, tf)
.patchInternalField()(),
selectedRegionDatasetIds_[i],
output
);
convertPatchPointField
(
tptf().name(),
tptf().boundaryField()[patchId]
.patchInternalField()(),
selectedRegionDatasetIds_[i],
output
);
}
}
}
}
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, 0)
);
vtkFloatArray *cellTypes = vtkFloatArray::New();
cellTypes->SetNumberOfTuples(superCells_.size());
cellTypes->SetNumberOfComponents(Type::nComponents);
cellTypes->Allocate(Type::nComponents*superCells_.size());
cellTypes->SetName(tf.name().c_str());
if (debug)
{
Info<< "converting vol<Type>Field: " << tf.name() << nl
<< "nTuples = " << superCells_.size() << nl
<< "nComps = " << Type::nComponents << endl;
}
float vec[Type::nComponents];
forAll(superCells_, sci)
{
const Type& t = tf[superCells_[sci]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
cellTypes->InsertTuple(sci, vec);
}
internalMesh->GetCellData()->AddArray(cellTypes);
cellTypes->Delete();
}
template<>
void Foam::vtkPV3Foam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
output->GetDataSet(VOLUME, 0)
);
vtkFloatArray *cellScalars = vtkFloatArray::New();
cellScalars->SetNumberOfTuples(superCells_.size());
cellScalars->SetNumberOfComponents(1);
cellScalars->Allocate(superCells_.size());
cellScalars->SetName(sf.name().c_str());
if (debug)
{
Info<< "converting volScalarField: " << sf.name() << nl
<< "sf.size() = " << sf.size() << nl
<< "nTuples = " << superCells_.size() << nl
<< "nComps = 1" << endl;
}
forAll(superCells_, sci)
{
cellScalars->InsertComponent(sci, 0, sf[superCells_[sci]]);
}
internalMesh->GetCellData()->AddArray(cellScalars);
if (!internalMesh->GetCellData()->GetScalars())
{
internalMesh->GetCellData()->SetScalars(cellScalars);
}
cellScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamInsertNextPoint_H
#define vtkPV3FoamInsertNextPoint_H
// VTK includes
#include "vtkPoints.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline void vtkPV3FoamInsertNextPoint
(
vtkPoints *points,
const Foam::point& p
)
{
points->InsertNextPoint(p.x(), p.y(), p.z());
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,229 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "IOobjectList.H"
#include "vtkPV3FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#include "vtkPV3FoamConvertVolFields.H"
#include "vtkPV3FoamConvertPointFields.H"
#include "vtkPV3FoamConvertLagrangianFields.H"
void Foam::vtkPV3Foam::updateFoamMesh()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateFoamMesh" << endl;
}
if
(
!reader_->GetCacheMesh()
|| reader_->GetTimeSelection()->GetArraySetting(0)
)
{
delete meshPtr_;
meshPtr_ = NULL;
}
// Check to see if the FOAM mesh has been created
if (!meshPtr_)
{
if (debug)
{
Info<< "Creating Foam mesh" << endl;
}
meshPtr_ = new fvMesh
(
IOobject
(
fvMesh::defaultRegion,
dbPtr_().timeName(),
dbPtr_()
)
);
}
else
{
if (debug)
{
Info<< "Using existing Foam mesh" << endl;
}
}
}
void Foam::vtkPV3Foam::updateVolFields
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateVolFields" << endl;
}
const fvMesh& mesh = *meshPtr_;
// Construct interpolation on the raw mesh
Foam::pointMesh pMesh(mesh);
// Search for list of objects for this time
Foam::IOobjectList objects(mesh, dbPtr_().timeName());
// Convert volume fields
if (debug)
{
Info<< "converting Foam volume fields" << endl;
}
Foam::volPointInterpolation pInterp(mesh, pMesh);
convertVolFields<Foam::scalar>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection(), output
);
convertVolFields<Foam::vector>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection(), output
);
convertVolFields<Foam::sphericalTensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection(), output
);
convertVolFields<Foam::symmTensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection(), output
);
convertVolFields<Foam::tensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection(), output
);
}
void Foam::vtkPV3Foam::updatePointFields
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updatePointFields" << endl;
}
const fvMesh& mesh = *meshPtr_;
// Search for list of objects for this time
Foam::IOobjectList objects(mesh, dbPtr_().timeName());
// Convert point fields
if (debug)
{
Info<< "converting Foam point fields" << endl;
}
convertPointFields<Foam::scalar>
(
mesh, objects, reader_->GetPointFieldSelection(), output
);
convertPointFields<Foam::vector>
(
mesh, objects, reader_->GetPointFieldSelection(), output
);
convertPointFields<Foam::sphericalTensor>
(
mesh, objects, reader_->GetPointFieldSelection(), output
);
convertPointFields<Foam::symmTensor>
(
mesh, objects, reader_->GetPointFieldSelection(), output
);
convertPointFields<Foam::tensor>
(
mesh, objects, reader_->GetPointFieldSelection(), output
);
}
void Foam::vtkPV3Foam::updateLagrangianFields
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateLagrangianFields" << endl;
}
const fvMesh& mesh = *meshPtr_;
// Search for list of objects for this time
//- TODO - currently hard-coded to ONE cloud
Foam::IOobjectList lagrangianObjects
(
mesh,
dbPtr_().timeName(),
"lagrangian"/cloudName_
);
// Convert Lagrangian fields
if (debug)
{
Info<< "converting Foam Lagrangian fields" << endl;
}
convertLagrangianFields<Foam::scalar>
(
mesh, lagrangianObjects, reader_->GetLagrangianFieldSelection(), output
);
convertLagrangianFields<Foam::vector>
(
mesh, lagrangianObjects, reader_->GetLagrangianFieldSelection(), output
);
convertLagrangianFields<Foam::sphericalTensor>
(
mesh, lagrangianObjects, reader_->GetLagrangianFieldSelection(), output
);
convertLagrangianFields<Foam::symmTensor>
(
mesh, lagrangianObjects, reader_->GetLagrangianFieldSelection(), output
);
convertLagrangianFields<Foam::tensor>
(
mesh, lagrangianObjects, reader_->GetLagrangianFieldSelection(), output
);
}
// ************************************************************************* //

View File

@ -0,0 +1,250 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "cellSet.H"
#include "faceSet.H"
#include "IOobjectList.H"
#include "pointSet.H"
#include "polyBoundaryMeshEntries.H"
#include "vtkPV3FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#include "vtkPV3FoamAddFields.H"
#include "vtkPV3FoamUpdateInformationFields.H"
void Foam::vtkPV3Foam::updateInformationInternalMesh()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationInternalMesh" << endl;
}
// Determine number of meshes available
HashTable<const fvMesh*> meshObjects = dbPtr_().lookupClass<const fvMesh>();
nMesh_ = meshObjects.size();
// Determine regions (internal mesh and patches...)
//- Add internal mesh as first entry
idRegionVolume_ = reader_->GetRegionSelection()->GetNumberOfArrays();
reader_->GetRegionSelection()->AddArray("internalMesh");
}
void Foam::vtkPV3Foam::updateInformationLagrangian()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationLagrangian" << endl;
}
// Search for list of lagrangian objects for this time
// IOobjectList lagrangianObjects(dbPtr(), dbPtr_().timeName(), "lagrangian");
// lagrangianDataSize_ = lagrangianObjects.size();
fileNameList cloudDirs
(
readDir(dbPtr_->timePath()/"lagrangian", fileName::DIRECTORY)
);
lagrangianDataSize_ = cloudDirs.size();
if (lagrangianDataSize_)
{
idRegionLagrangian_ = reader_->GetRegionSelection()
->GetNumberOfArrays();
reader_->GetRegionSelection()->AddArray("lagrangian");
if (lagrangianDataSize_ > 1)
{
WarningIn("void Foam::vtkPV3Foam::updateInformationLagrangian()")
<< "Multiple lagrangian clouds identified. Currently only able "
<< "to process ONE cloud: " << cloudDirs[0]
<< endl;
}
// Set cloud name to first cloud found
// TODO - multiple clouds
cloudName_ = cloudDirs[0];
}
}
void Foam::vtkPV3Foam::updateInformationPatches()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationPatches" << endl;
}
//- Read patches
polyBoundaryMeshEntries patchEntries
(
IOobject
(
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
// Start regions at patches
forAll (patchEntries, entryi)
{
label nFaces(readLabel(patchEntries[entryi].dict().lookup("nFaces")));
//- Valid patch if nFace > 0
if (nFaces)
{
// Add patch to GUI region list
if (idRegionPatches_ < 0)
{
idRegionPatches_ = reader_->GetRegionSelection()
->GetNumberOfArrays();
}
reader_->GetRegionSelection()->AddArray
(
patchEntries[entryi].keyword().c_str()
);
patchDataSize_++;
}
}
}
void Foam::vtkPV3Foam::updateInformationSets()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationSets" << endl;
}
// Add sets
IOobjectList setObjects
(
dbPtr_(),
dbPtr_().findInstance(polyMesh::meshSubDir, "faces"),
polyMesh::meshSubDir/"sets"
);
IOobjectList cellSetObjects(setObjects.lookupClass(cellSet::typeName));
cellSetDataSize_ = cellSetObjects.size();
superCellSetCells_.setSize(cellSetDataSize_);
idRegionCellSets_ = reader_->GetRegionSelection()->GetNumberOfArrays();
addFields<cellSet>
(
reader_->GetRegionSelection(),
cellSetObjects
);
IOobjectList faceSetObjects(setObjects.lookupClass(faceSet::typeName));
faceSetDataSize_ = faceSetObjects.size();
idRegionFaceSets_ = reader_->GetRegionSelection()->GetNumberOfArrays();
addFields<faceSet>
(
reader_->GetRegionSelection(),
faceSetObjects
);
IOobjectList pointSetObjects(setObjects.lookupClass(pointSet::typeName));
pointSetDataSize_ = pointSetObjects.size();
idRegionPointSets_ = reader_->GetRegionSelection()->GetNumberOfArrays();
addFields<pointSet>
(
reader_->GetRegionSelection(),
pointSetObjects
);
}
void Foam::vtkPV3Foam::updateInformationLagrangianFields()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationLagrangianFields"
<< endl;
}
const wordList selectedArrayEntries = getSelectedArrayEntries
(
reader_->GetLagrangianFieldSelection()
);
reader_->GetLagrangianFieldSelection()->RemoveAllArrays();
// TODO - currently hard-coded to ONE cloud
IOobjectList lagrangianObjects(dbPtr_(), dbPtr_().timeName(), "lagrangian"/cloudName_);
addFields<IOField<scalar> >
(
reader_->GetLagrangianFieldSelection(),
lagrangianObjects
);
addFields<IOField<vector> >
(
reader_->GetLagrangianFieldSelection(),
lagrangianObjects
);
addFields<IOField<sphericalTensor> >
(
reader_->GetLagrangianFieldSelection(),
lagrangianObjects
);
addFields<IOField<symmTensor> >
(
reader_->GetLagrangianFieldSelection(),
lagrangianObjects
);
addFields<IOField<tensor> >
(
reader_->GetLagrangianFieldSelection(),
lagrangianObjects
);
setSelectedArrayEntries
(
reader_->GetLagrangianFieldSelection(),
selectedArrayEntries
);
if (debug)
{
Info<< "lagrangianObjects.size() = " << lagrangianObjects.size()
<< endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,96 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamUpdateInformationFields_H
#define vtkPV3FoamUpdateInformationFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<template<class> class patchType, class meshType>
void Foam::vtkPV3Foam::updateInformationFields
(
vtkDataArraySelection *fieldSelection
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationFields" << endl;
}
const wordList selectedArrayEntries = getSelectedArrayEntries
(
fieldSelection
);
fieldSelection->RemoveAllArrays();
// Search for list of objects for this time
IOobjectList objects(dbPtr_(), dbPtr_().timeName());
// Populate the GUI volume/point field arrays
//- Add volume fields to GUI
addFields<GeometricField<scalar, patchType, meshType> >
(
fieldSelection,
objects
);
addFields<GeometricField<vector, patchType, meshType> >
(
fieldSelection,
objects
);
addFields<GeometricField<sphericalTensor, patchType, meshType> >
(
fieldSelection,
objects
);
addFields<GeometricField<symmTensor, patchType, meshType> >
(
fieldSelection,
objects
);
addFields<GeometricField<tensor, patchType, meshType> >
(
fieldSelection,
objects
);
setSelectedArrayEntries
(
fieldSelection,
selectedArrayEntries
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,7 @@
#!/bin/sh
set -x
if [ "$ParaView_VERSION" != "3" -a "$ParaView_DIR" -a -r $ParaView_DIR ] ; then
wmake libso vtkFoam
(cd PVFoamReader; mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1; cd Make/$WM_OPTIONS; cmake ../..; make)
fi

View File

@ -0,0 +1,74 @@
# Set the project/library name here. Classes should be declared as
# "class VTK_FoamReader_EXPORT vtkFoo", where PVFoamReader is the name of the
# project set here.
PROJECT(PVFoamReader)
# Set your list of sources here. Do not change the name of the
# PVFoamReader_SRCS variable.
SET(PVFoamReader_SRCS
vtkFoamReader.cxx
vtkFoamData.cxx
)
# List the kits from VTK that are needed by this project. Do not
# change the name of the PVFoamReader_LIBS variable.
SET(PVFoamReader_LIBS
vtkGraphics
)
INCLUDE_DIRECTORIES($ENV{FOAM_SRC}/OpenFOAM/lnInclude $ENV{FOAM_SRC}/finiteVolume/lnInclude)
INCLUDE_DIRECTORIES($ENV{ParaView_INST_DIR}/include ../vtkFoam/lnInclude)
ADD_DEFINITIONS(-D$ENV{WM_PRECISION_OPTION})
#-----------------------------------------------------------------------------
# Most users should not need to change anything below this line.
# Need to include class headers and the configuration header.
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR})
# Import ParaView build settings.
FIND_PACKAGE(ParaView)
IF(NOT ParaView_FOUND)
MESSAGE(FATAL_ERROR "ParaView is required. Set ParaView_DIR.")
ENDIF(NOT ParaView_FOUND)
IF(NOT PARAVIEW_BUILD_SHARED_LIBS)
MESSAGE(FATAL_ERROR "ParaView must be built with BUILD_SHARED_LIBS ON.")
ENDIF(NOT PARAVIEW_BUILD_SHARED_LIBS)
INCLUDE(${PARAVIEW_USE_FILE})
# Configure output directories.
SET (LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN} CACHE INTERNAL
"Single output directory for building all libraries.")
SET (EXECUTABLE_OUTPUT_PATH $ENV{FOAM_APPBIN} CACHE INTERNAL
"Single output directory for building all executables.")
# Create the configuration header.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/PVFoamReaderConfigure.h.in
${PROJECT_BINARY_DIR}/vtk${PROJECT_NAME}Configure.h
@ONLY IMMEDIATE)
# Must be defined before ADD_LIBRARY for cmake version 2.3.4-20060317
LINK_DIRECTORIES($ENV{FOAM_LIBBIN})
LINK_DIRECTORIES($ENV{FOAM_USER_LIBBIN})
# Create vtk client/server wrappers for the classes.
VTK_WRAP_ClientServer(${PROJECT_NAME} PVFoamReaderCS_SRCS "${PVFoamReader_SRCS}")
# Build the package as a plugin for ParaView.
ADD_LIBRARY(${PROJECT_NAME} MODULE ${PVFoamReader_SRCS} ${PVFoamReaderCS_SRCS})
LINK_DIRECTORIES($ENV{ParaView_INST_DIR}/lib)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} vtkClientServer)
FOREACH(c ${PVFoamReader_LIBS})
TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${c}CS)
ENDFOREACH(c)
# Place the package configuration file into the build tree.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/PVFoamReader.xml.in
${PROJECT_BINARY_DIR}/../${PROJECT_NAME}.xml @ONLY IMMEDIATE)
# Place the package configuration file into the build tree.
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/PVFoamReader.pvsm.in
${PROJECT_BINARY_DIR}/../${PROJECT_NAME}.pvsm @ONLY IMMEDIATE)
TARGET_LINK_LIBRARIES(${PROJECT_NAME} OpenFOAM finiteVolume vtkFoam)

View File

@ -0,0 +1,154 @@
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy
name="FoamReader"
class="vtkFoamReader">
<StringVectorProperty
name="FileName"
command="SetFileName"
number_of_elements="1">
<StringListDomain name="files"/>
</StringVectorProperty>
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool"/>
</IntVectorProperty>
<IntVectorProperty
name="CacheMesh"
command="SetCacheMesh"
number_of_elements="1"
default_values="1">
<BooleanDomain name="bool"/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepRangeInfo"
command="GetTimeStepRange"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStep"
command="SetTimeStep"
number_of_elements="1"
animateable="1"
default_values="0">
<IntRangeDomain name="range">
<RequiredProperties>
<Property name="TimeStepRangeInfo" function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepLimitsInfo"
command="GetTimeStepLimits"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepLimits"
command="SetTimeStepLimits"
number_of_elements="2"
default_values="2 5" >
<IntRangeDomain name="range">
<RequiredProperties>
<Property name="TimeStepLimitsInfo" function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>
<StringVectorProperty
name="TimeArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Time"/>
</StringVectorProperty>
<StringVectorProperty
name="TimeStatus"
command="SetTimeArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="TimeArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="TimeArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="RegionArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Region"/>
</StringVectorProperty>
<StringVectorProperty
name="RegionStatus"
command="SetRegionArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="RegionArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="RegionArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="VolField"/>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldStatus"
command="SetVolFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="VolFieldArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="VolFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="PointField"/>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldStatus"
command="SetPointFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PointFieldArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="PointFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,71 @@
<ModuleInterfaces>
<Library name="PVFoamReader"/>
<ServerManagerFile name="PVFoamReader.pvsm"/>
<Module name="FoamReader"
class="vtkPVAdvancedReaderModule"
root_name="Foam"
output="vtkDataSet"
module_type="Reader"
extensions=".foam"
file_description="Foam case">
<Source class="vtkFoamReader"/>
<LabeledToggle
label="Update GUI"
trace_name="UpdateGUI"
property="UpdateGUI"
help="To update GUI without execution toggle this Accept and Reset."/>
<LabeledToggle
label="Cache Mesh"
trace_name="CacheMesh"
property="CacheMesh"
help="Cache the FOAM mesh between GUI selection changes."/>
<Scale
property="TimeStep"
trace_name="TimeStep"
label="Time step"
display_entry="0"
display_value="1"
entry_and_label_on_top="0"
help="Select a time step."
keeps_timesteps="1"
range_source="TimeStepRange"/>
<VectorEntry
property="TimeStepLimits"
type="int"
trace_name="TimeStepLimits"
length="2"
label="Lower and Upper Times"
help="Maximum lower and upper number of time steps displayed in the selection list."/>
<ArraySelection
label_text="Time"
property="TimeStatus"
trace_name="TimeArrays"/>
<ArraySelection
label_text="Region"
property="RegionStatus"
trace_name="RegionArrays"/>
<ArraySelection
label_text="Vol Field"
property="VolFieldStatus"
trace_name="CellArrays"/>
<ArraySelection
label_text="Point Field"
property="PointFieldStatus"
trace_name="PointArrays"/>
<Documentation>
ParaView Foam reader module
</Documentation>
</Module>
</ModuleInterfaces>

View File

@ -0,0 +1,154 @@
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy
name="FoamReader"
class="vtkFoamReader">
<StringVectorProperty
name="FileName"
command="SetFileName"
number_of_elements="1">
<StringListDomain name="files"/>
</StringVectorProperty>
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
number_of_elements="1"
default_values="0">
<BooleanDomain name="bool"/>
</IntVectorProperty>
<IntVectorProperty
name="CacheMesh"
command="SetCacheMesh"
number_of_elements="1"
default_values="1">
<BooleanDomain name="bool"/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepRangeInfo"
command="GetTimeStepRange"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStep"
command="SetTimeStep"
number_of_elements="1"
animateable="1"
default_values="0">
<IntRangeDomain name="range">
<RequiredProperties>
<Property name="TimeStepRangeInfo" function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepLimitsInfo"
command="GetTimeStepLimits"
information_only="1">
<SimpleIntInformationHelper/>
</IntVectorProperty>
<IntVectorProperty
name="TimeStepLimits"
command="SetTimeStepLimits"
number_of_elements="2"
default_values="2 5" >
<IntRangeDomain name="range">
<RequiredProperties>
<Property name="TimeStepLimitsInfo" function="Range"/>
</RequiredProperties>
</IntRangeDomain>
</IntVectorProperty>
<StringVectorProperty
name="TimeArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Time"/>
</StringVectorProperty>
<StringVectorProperty
name="TimeStatus"
command="SetTimeArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="TimeArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="TimeArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="RegionArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Region"/>
</StringVectorProperty>
<StringVectorProperty
name="RegionStatus"
command="SetRegionArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="RegionArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="RegionArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="VolField"/>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldStatus"
command="SetVolFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="VolFieldArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="VolFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="PointField"/>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldStatus"
command="SetPointFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PointFieldArrayInfo">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="PointFieldArrayInfo"
function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,71 @@
<ModuleInterfaces>
<Library name="@PROJECT_NAME@"/>
<ServerManagerFile name="@PROJECT_NAME@.pvsm"/>
<Module name="FoamReader"
class="vtkPVAdvancedReaderModule"
root_name="Foam"
output="vtkDataSet"
module_type="Reader"
extensions=".foam"
file_description="Foam case">
<Source class="vtkFoamReader"/>
<LabeledToggle
label="Update GUI"
trace_name="UpdateGUI"
property="UpdateGUI"
help="To update GUI without execution toggle this Accept and Reset."/>
<LabeledToggle
label="Cache Mesh"
trace_name="CacheMesh"
property="CacheMesh"
help="Cache the FOAM mesh between GUI selection changes."/>
<Scale
property="TimeStep"
trace_name="TimeStep"
label="Time step"
display_entry="0"
display_value="1"
entry_and_label_on_top="0"
help="Select a time step."
keeps_timesteps="1"
range_source="TimeStepRange"/>
<VectorEntry
property="TimeStepLimits"
type="int"
trace_name="TimeStepLimits"
length="2"
label="Lower and Upper Times"
help="Maximum lower and upper number of time steps displayed in the selection list."/>
<ArraySelection
label_text="Time"
property="TimeStatus"
trace_name="TimeArrays"/>
<ArraySelection
label_text="Region"
property="RegionStatus"
trace_name="RegionArrays"/>
<ArraySelection
label_text="Vol Field"
property="VolFieldStatus"
trace_name="CellArrays"/>
<ArraySelection
label_text="Point Field"
property="PointFieldStatus"
trace_name="PointArrays"/>
<Documentation>
ParaView Foam reader module
</Documentation>
</Module>
</ModuleInterfaces>

View File

@ -0,0 +1,18 @@
/*=========================================================================
This source has no copyright. It is intended to be copied by users
wishing to create their own ParaView plugin classes locally.
=========================================================================*/
#ifndef __vtk@PROJECT_NAME@_h
#define __vtk@PROJECT_NAME@_h
#if defined(_WIN32)
# if defined(@PROJECT_NAME@_EXPORTS)
# define VTK_@PROJECT_NAME@_EXPORT __declspec(dllexport)
# else
# define VTK_@PROJECT_NAME@_EXPORT __declspec(dllimport)
# endif
#else
# define VTK_@PROJECT_NAME@_EXPORT
#endif
#endif

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include <ctype.h>
#include "vtkFoamData.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkFoamData, "$Revision: 1.20 $");
vtkStandardNewMacro(vtkFoamData);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
vtkFoamData::vtkFoamData()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
vtkFoamData::~vtkFoamData()
{}
// ************************************************************************* //

View File

@ -0,0 +1,70 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
vtkFoamData
Description
SourceFiles
vtkFoamData.cxx
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamData_h
#define vtkFoamData_h
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "vtkDataSetSource.h"
/*---------------------------------------------------------------------------*\
Class vtkFoamData Declaration
\*---------------------------------------------------------------------------*/
class VTK_IO_EXPORT vtkFoamData
:
public vtkDataSetSource
{
public:
static vtkFoamData *New();
vtkTypeRevisionMacro(vtkFoamData,vtkDataSetSource);
vtkFoamData();
~vtkFoamData();
void SetNthOutput(int num, vtkDataObject *output)
{
vtkDataSetSource::SetNthOutput(num, output);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,411 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include <ctype.h>
#include "vtkFoamReader.h"
#include "vtkCallbackCommand.h"
#include "vtkDataArraySelection.h"
#include "vtkDataArrayCollection.h"
#include "vtkObjectFactory.h"
#include "vtkDataSet.h"
#include "vtkErrorCode.h"
#include "vtkUnstructuredGrid.h"
#include "vtkFoam.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
vtkCxxRevisionMacro(vtkFoamReader, "$Revision: 1.20 $");
vtkStandardNewMacro(vtkFoamReader);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
vtkFoamReader::vtkFoamReader()
{
StoredOutputs = NULL;
FileName = NULL;
foamData_ = NULL;
CacheMesh = 0;
UpdateGUI = 1;
UpdateGUIOld = 1;
TimeStep = 0;
TimeStepRange[0] = 0;
TimeStepRange[1] = 0;
TimeStepLimits[0] = 2;
TimeStepLimits[1] = 5;
TimeSelection = vtkDataArraySelection::New();
RegionSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New();
PointFieldSelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
SelectionObserver = vtkCallbackCommand::New();
SelectionObserver->SetCallback(&vtkFoamReader::SelectionModifiedCallback);
SelectionObserver->SetClientData(this);
TimeSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
RegionSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
VolFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
PointFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
// This is needed by ParaView 2.?.?
this->SetNumberOfOutputPorts(0);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
vtkFoamReader::~vtkFoamReader()
{
if (foamData_)
{
delete foamData_;
}
if (StoredOutputs)
{
StoredOutputs->Delete();
}
if (FileName)
{
delete [] FileName;
}
TimeSelection->RemoveObserver(this->SelectionObserver);
RegionSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
TimeSelection->Delete();
RegionSelection->Delete();
VolFieldSelection->Delete();
PointFieldSelection->Delete();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void vtkFoamReader::ExecuteInformation()
{
if (!foamData_)
{
vtkDebugMacro( << "Reading Foam case" << FileName);
foamData_ = new Foam::vtkFoam(FileName, this);
}
else
{
foamData_->UpdateInformation();
}
vtkDebugMacro( << "end of ExecuteInformation\n");
}
void vtkFoamReader::Execute()
{
if (!StoredOutputs)
{
foamData_->Update();
StoredOutputs = vtkFoamData::New();
for (int i = 0; i < GetNumberOfOutputs(); i++)
{
vtkDataObject* tmp = GetOutput(i);
vtkDataObject* output = tmp->NewInstance();
output->ShallowCopy(tmp);
StoredOutputs->SetNthOutput(i, output);
output->Delete();
}
}
else
{
for (int i = 0; i < GetNumberOfOutputs(); i++)
{
vtkDataObject* output = GetOutput(i);
int tempExtent[6];
output->GetUpdateExtent(tempExtent);
output->ShallowCopy(StoredOutputs->GetOutput(i));
output->SetUpdateExtent(tempExtent);
}
if (UpdateGUIOld == GetUpdateGUI())
{
foamData_->Update();
for (int i = 0; i < GetNumberOfOutputs(); i++)
{
vtkDataObject* tmp = GetOutput(i);
vtkDataObject* output = tmp->NewInstance();
output->ShallowCopy(tmp);
StoredOutputs->SetNthOutput(i, output);
output->Delete();
}
}
}
UpdateGUIOld = GetUpdateGUI();
}
void vtkFoamReader::SetFileName(const char *name)
{
if (name && !FileName || (FileName && !strcmp(FileName,name)))
{
if (!FileName)
{
FileName = new char[strlen(name) + 1];
strcpy(FileName, name);
}
}
else
{
vtkErrorMacro("Changing case is not currently supported.\nPlease delete reader and create a new one for the new case.");
return;
}
/*
if ( FileName && name && (!strcmp(FileName,name)))
{
return;
}
if (!name && !FileName)
{
return;
}
if (FileName)
{
delete [] FileName;
}
FileName = new char[strlen(name) + 1];
strcpy(FileName, name);
if (foamData_)
{
delete foamData_;
foamData_ = NULL;
if (StoredOutputs)
{
StoredOutputs->Delete();
StoredOutputs = NULL;
}
}
Modified();
*/
}
void vtkFoamReader::PrintSelf(ostream& os, vtkIndent indent)
{
Superclass::PrintSelf(os,indent);
os << indent << "File Name: "
<< (FileName ? FileName : "(none)") << "\n";
}
vtkDataArraySelection* vtkFoamReader::GetTimeSelection()
{
return TimeSelection;
}
int vtkFoamReader::GetNumberOfTimeArrays()
{
return TimeSelection->GetNumberOfArrays();
}
const char* vtkFoamReader::GetTimeArrayName(int index)
{
return TimeSelection->GetArrayName(index);
}
int vtkFoamReader::GetTimeArrayStatus(const char* name)
{
return TimeSelection->ArrayIsEnabled(name);
}
void vtkFoamReader::SetTimeArrayStatus(const char* name, int status)
{
if(status)
{
TimeSelection->EnableArray(name);
}
else
{
TimeSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkFoamReader::GetRegionSelection()
{
return RegionSelection;
}
int vtkFoamReader::GetNumberOfRegionArrays()
{
return RegionSelection->GetNumberOfArrays();
}
const char* vtkFoamReader::GetRegionArrayName(int index)
{
return RegionSelection->GetArrayName(index);
}
int vtkFoamReader::GetRegionArrayStatus(const char* name)
{
return RegionSelection->ArrayIsEnabled(name);
}
void vtkFoamReader::SetRegionArrayStatus(const char* name, int status)
{
if(status)
{
RegionSelection->EnableArray(name);
}
else
{
RegionSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkFoamReader::GetVolFieldSelection()
{
return VolFieldSelection;
}
int vtkFoamReader::GetNumberOfVolFieldArrays()
{
return VolFieldSelection->GetNumberOfArrays();
}
const char* vtkFoamReader::GetVolFieldArrayName(int index)
{
return VolFieldSelection->GetArrayName(index);
}
int vtkFoamReader::GetVolFieldArrayStatus(const char* name)
{
return VolFieldSelection->ArrayIsEnabled(name);
}
void vtkFoamReader::SetVolFieldArrayStatus(const char* name, int status)
{
if(status)
{
VolFieldSelection->EnableArray(name);
}
else
{
VolFieldSelection->DisableArray(name);
}
}
vtkDataArraySelection* vtkFoamReader::GetPointFieldSelection()
{
return PointFieldSelection;
}
int vtkFoamReader::GetNumberOfPointFieldArrays()
{
return PointFieldSelection->GetNumberOfArrays();
}
const char* vtkFoamReader::GetPointFieldArrayName(int index)
{
return PointFieldSelection->GetArrayName(index);
}
int vtkFoamReader::GetPointFieldArrayStatus(const char* name)
{
return PointFieldSelection->ArrayIsEnabled(name);
}
void vtkFoamReader::SetPointFieldArrayStatus(const char* name, int status)
{
if(status)
{
PointFieldSelection->EnableArray(name);
}
else
{
PointFieldSelection->DisableArray(name);
}
}
void vtkFoamReader::SelectionModifiedCallback
(
vtkObject*,
unsigned long,
void* clientdata,
void*
)
{
static_cast<vtkFoamReader*>(clientdata)->SelectionModified();
}
void vtkFoamReader::SelectionModified()
{
Modified();
}
// ************************************************************************* //

View File

@ -0,0 +1,200 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
vtkFoamReader
Description
SourceFiles
vtkFoamReader.cxx
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamReader_h
#define vtkFoamReader_h
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "vtkDataSetSource.h"
#include "vtkFoamData.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
namespace Foam
{
class vtkFoam;
}
class vtkPoints;
class vtkDataArraySelection;
class vtkDataArrayCollection;
class vtkCallbackCommand;
/*---------------------------------------------------------------------------*\
Class vtkFoamReader Declaration
\*---------------------------------------------------------------------------*/
class VTK_IO_EXPORT vtkFoamReader
:
public vtkDataSetSource
{
public:
//- Standard VTK class creation function
static vtkFoamReader *New();
//- Standard VTK class type and revision declaration macro
vtkTypeRevisionMacro(vtkFoamReader,vtkDataSetSource);
//- Standard VTK class print function
void PrintSelf(ostream& os, vtkIndent indent);
// File name of FOAM datafile to read
void SetFileName(const char *);
//vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
// GUI update control
vtkSetMacro(UpdateGUI, int);
vtkGetMacro(UpdateGUI, int);
// FOAM mesh caching control
vtkSetMacro(CacheMesh, int);
vtkGetMacro(CacheMesh, int);
// Time-step slider control
vtkSetMacro(TimeStep, int);
vtkGetMacro(TimeStep, int);
vtkSetVector2Macro(TimeStepRange, int);
vtkGetVector2Macro(TimeStepRange, int);
// Control of the upper and lower limits on the number of times
// displayed in the selection list
vtkSetVector2Macro(TimeStepLimits, int);
vtkGetVector2Macro(TimeStepLimits, int);
// Time selection list control
vtkDataArraySelection* GetTimeSelection();
int GetNumberOfTimeArrays();
const char* GetTimeArrayName(int index);
int GetTimeArrayStatus(const char* name);
void SetTimeArrayStatus(const char* name, int status);
// Region selection list control
vtkDataArraySelection* GetRegionSelection();
int GetNumberOfRegionArrays();
const char* GetRegionArrayName(int index);
int GetRegionArrayStatus(const char* name);
void SetRegionArrayStatus(const char* name, int status);
// volField selection list control
vtkDataArraySelection* GetVolFieldSelection();
int GetNumberOfVolFieldArrays();
const char* GetVolFieldArrayName(int index);
int GetVolFieldArrayStatus(const char* name);
void SetVolFieldArrayStatus(const char* name, int status);
// pointField selection list control
vtkDataArraySelection* GetPointFieldSelection();
int GetNumberOfPointFieldArrays();
const char* GetPointFieldArrayName(int index);
int GetPointFieldArrayStatus(const char* name);
void SetPointFieldArrayStatus(const char* name, int status);
// SetNthOutput provided so that vtkFoam can access it
void SetNthOutput(int num, vtkDataObject *output)
{
vtkDataSetSource::SetNthOutput(num, output);
}
// Standard VTK ExecuteInformation function overriding the base-class.
// Called by ParaView before GUI is displayed.
virtual void ExecuteInformation();
// Callback registered with the SelectionObserver
// for all the selection lists
static void SelectionModifiedCallback
(
vtkObject* caller,
unsigned long eid,
void* clientdata,
void* calldata
);
void SelectionModified();
protected:
vtkFoamReader();
~vtkFoamReader();
// Standard VTK execute function overriding the base-class.
// Called by ParaView when Accept is pressed.
void Execute();
// Cache for the outputs. These are stored before the end of Execute()
// and re-instated at the beginning because the Outputs would disappear
// otherwise.
vtkFoamData* StoredOutputs;
// FOAM file name (*.foam)
char *FileName;
//BTX
Foam::vtkFoam* foamData_;
//ETX
int CacheMesh;
int UpdateGUI;
int UpdateGUIOld;
int TimeStep;
int TimeStepRange[2];
int TimeStepLimits[2];
vtkDataArraySelection* TimeSelection;
vtkDataArraySelection* RegionSelection;
vtkDataArraySelection* VolFieldSelection;
vtkDataArraySelection* PointFieldSelection;
// The observer to modify this object when the array selections are modified
vtkCallbackCommand* SelectionObserver;
private:
vtkFoamReader(const vtkFoamReader&); // Not implemented.
void operator=(const vtkFoamReader&); // Not implemented.
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,531 @@
/*=========================================================================
Program: ParaView
Module: $RCSfile: vtkPVFoamSelectTimeSet.cxx,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPVFoamSelectTimeSet.h"
#include "vtkDataArrayCollection.h"
#include "vtkFloatArray.h"
#include "vtkKWFrame.h"
#include "vtkKWLabel.h"
#include "vtkKWLabeledFrame.h"
#include "vtkKWMenu.h"
#include "vtkObjectFactory.h"
#include "vtkPVAnimationInterfaceEntry.h"
#include "vtkPVApplication.h"
#include "vtkPVProcessModule.h"
#include "vtkPVScalarListWidgetProperty.h"
#include "vtkPVSource.h"
#include "vtkPVXMLElement.h"
#include <vtkstd/string>
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVFoamSelectTimeSet);
vtkCxxRevisionMacro(vtkPVFoamSelectTimeSet, "$Revision: 1.39 $");
//-----------------------------------------------------------------------------
int vtkDataArrayCollectionCommand(ClientData cd, Tcl_Interp *interp,
int argc, char *argv[]);
//-----------------------------------------------------------------------------
vtkPVFoamSelectTimeSet::vtkPVFoamSelectTimeSet()
{
this->LabeledFrame = vtkKWLabeledFrame::New();
this->LabeledFrame->SetParent(this);
this->TimeLabel = vtkKWLabel::New();
this->TimeLabel->SetParent(this->LabeledFrame->GetFrame());
this->TreeFrame = vtkKWWidget::New();
this->TreeFrame->SetParent(this->LabeledFrame->GetFrame());
this->Tree = vtkKWWidget::New();
this->Tree->SetParent(this->TreeFrame);
this->TimeValue = 0.0;
this->FrameLabel = 0;
this->TimeSets = vtkDataArrayCollection::New();
this->Property = 0;
this->SetCommand = 0;
this->ServerSideID.ID = 0;
}
//-----------------------------------------------------------------------------
vtkPVFoamSelectTimeSet::~vtkPVFoamSelectTimeSet()
{
this->LabeledFrame->Delete();
this->Tree->Delete();
this->TreeFrame->Delete();
this->TimeLabel->Delete();
this->SetFrameLabel(0);
this->TimeSets->Delete();
this->SetSetCommand(0);
if(this->ServerSideID.ID)
{
vtkPVProcessModule* pm = this->GetPVApplication()->GetProcessModule();
pm->DeleteStreamObject(this->ServerSideID);
pm->SendStream(vtkProcessModule::DATA_SERVER);
}
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SetLabel(const char* label)
{
this->SetFrameLabel(label);
if (this->GetApplication())
{
this->LabeledFrame->SetLabel(label);
}
}
//-----------------------------------------------------------------------------
const char* vtkPVFoamSelectTimeSet::GetLabel()
{
return this->GetFrameLabel();
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::Create(vtkKWApplication *pvApp)
{
// Call the superclass to create the widget and set the appropriate flags
if (!this->vtkKWWidget::Create(pvApp, "frame", "-bd 2 -relief flat"))
{
vtkErrorMacro("Failed creating widget " << this->GetClassName());
return;
}
// For getting the widget in a script.
if ((this->TraceNameState == vtkPVWidget::Uninitialized ||
this->TraceNameState == vtkPVWidget::Default) )
{
this->SetTraceName("FoamSelectTimeSet");
this->SetTraceNameState(vtkPVWidget::SelfInitialized);
}
this->LabeledFrame->Create(this->GetApplication(), 0);
if (this->FrameLabel)
{
this->LabeledFrame->SetLabel(this->FrameLabel);
}
this->TimeLabel->Create(this->GetApplication(), "");
char label[32];
sprintf(label, "Time value: %12.5e", 0.0);
this->TimeLabel->SetLabel(label);
this->Script("pack %s", this->TimeLabel->GetWidgetName());
this->TreeFrame->Create(this->GetApplication(), "ScrolledWindow",
"-relief sunken -bd 2");
this->Tree->Create(this->GetApplication(), "Tree",
"-background white -bd 0 -width 15 -padx 2 "
"-redraw 1 -relief flat -selectbackground red");
this->Script("%s bindText <ButtonPress-1> {%s SetTimeValueCallback}",
this->Tree->GetWidgetName(), this->GetTclName());
this->Script("%s setwidget %s", this->TreeFrame->GetWidgetName(),
this->Tree->GetWidgetName());
this->Script("pack %s -expand t -fill x", this->TreeFrame->GetWidgetName());
this->Script("pack %s -side top -expand t -fill x",
this->LabeledFrame->GetWidgetName());
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SetTimeValue(float time)
{
if (this->TimeValue != time ||
!this->TimeLabel->GetLabel() ||
!strcmp(this->TimeLabel->GetLabel(), "No timesets available."))
{
this->TimeValue = time;
char label[32];
sprintf(label, "Time value: %12.5e", time);
this->TimeLabel->SetLabel(label);
this->Modified();
}
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SetTimeValueCallback(const char* item)
{
if (this->TimeSets->GetNumberOfItems() == 0)
{
return;
}
if ( strncmp(item, "timeset", strlen("timeset")) == 0 )
{
this->Script("if [%s itemcget %s -open] "
"{%s closetree %s} else {%s opentree %s}",
this->Tree->GetWidgetName(), item,
this->Tree->GetWidgetName(), item,
this->Tree->GetWidgetName(), item);
return;
}
this->Script("%s selection set %s", this->Tree->GetWidgetName(),
item);
this->Script("%s itemcget %s -data", this->Tree->GetWidgetName(),
item);
const char* result = this->GetApplication()->GetMainInterp()->result;
if (result[0] == '\0')
{
return;
}
int index[2];
sscanf(result, "%d %d", &(index[0]), &(index[1]));
this->SetTimeSetsFromReader();
this->SetTimeValue(this->TimeSets->GetItem(index[0])->GetTuple1(index[1]));
this->ModifiedCallback();
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::AddRootNode(const char* name, const char* text)
{
if (!this->GetApplication())
{
return;
}
this->Script("%s insert end root %s -text {%s}", this->Tree->GetWidgetName(),
name, text);
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::AddChildNode(const char* parent, const char* name,
const char* text, const char* data)
{
if (!this->GetApplication())
{
return;
}
this->Script("%s insert end %s %s -text {%s} -data %s",
this->Tree->GetWidgetName(), parent, name, text, data);
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SaveInBatchScript(ofstream *file)
{
*file << " [$pvTemp" << this->PVSource->GetVTKSourceID(0)
<< " GetProperty " << this->SetCommand << "] SetElements1 "
<< this->Property->GetScalar(0) << endl;
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::AcceptInternal(vtkClientServerID sourceID)
{
if (this->ModifiedFlag)
{
this->Script("%s selection get", this->Tree->GetWidgetName());
this->AddTraceEntry("$kw(%s) SetTimeValueCallback {%s}",
this->GetTclName(),
this->GetApplication()->GetMainInterp()->result);
}
this->Property->SetVTKSourceID(sourceID);
this->Property->SetScalars(1, &this->TimeValue);
this->Property->AcceptInternal();
this->ModifiedFlag = 0;
}
//---------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::Trace(ofstream *file)
{
if ( ! this->InitializeTrace(file))
{
return;
}
this->Script("%s selection get", this->Tree->GetWidgetName());
*file << "$kw(" << this->GetTclName() << ") SetTimeValueCallback {"
<< this->GetApplication()->GetMainInterp()->result << "}" << endl;
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::ResetInternal()
{
if ( ! this->ModifiedFlag)
{
return;
}
// Command to update the UI.
if (!this->Tree)
{
return;
}
this->Script("%s delete [%s nodes root]", this->Tree->GetWidgetName(),
this->Tree->GetWidgetName());
this->SetTimeSetsFromReader();
int timeSetId=0;
char timeSetName[32];
char timeSetText[32];
char timeValueName[32];
char timeValueText[32];
char indices[32];
float actualTimeValue = this->Property->GetScalar(0);
int matchFound = 0;
this->ModifiedFlag = 0;
if (this->TimeSets->GetNumberOfItems() == 0)
{
this->Script("pack forget %s", this->TreeFrame->GetWidgetName());
this->TimeLabel->SetLabel("No timesets available.");
return;
}
else
{
this->SetTimeValue(actualTimeValue);
this->Script("pack %s -expand t -fill x", this->TreeFrame->GetWidgetName());
}
this->TimeSets->InitTraversal();
vtkDataArray* da;
while( (da=this->TimeSets->GetNextItem()) )
{
timeSetId++;
sprintf(timeSetName,"timeset%d", timeSetId);
sprintf(timeSetText,"Time Set %d", timeSetId);
this->AddRootNode(timeSetName, timeSetText);
vtkIdType tuple;
for(tuple=0; tuple<da->GetNumberOfTuples(); tuple++)
{
float timeValue = da->GetTuple1(tuple);
sprintf(timeValueName, "time%d_%-12.5e", timeSetId, timeValue);
sprintf(timeValueText, "%-12.5e", timeValue);
ostrstream str;
str << "{" << timeSetId-1 << " " << tuple << "}" << ends;
sprintf(indices, "%s", str.str());
str.rdbuf()->freeze(0);
this->AddChildNode(timeSetName, timeValueName, timeValueText, indices);
if (actualTimeValue == timeValue && !matchFound)
{
matchFound=1;
this->Script("%s selection set %s", this->Tree->GetWidgetName(),
timeValueName);
}
}
if (timeSetId == 1)
{
this->Script("%s opentree %s", this->Tree->GetWidgetName(),
timeSetName);
}
}
this->SetTimeValue(actualTimeValue);
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::AddAnimationScriptsToMenu(vtkKWMenu *menu,
vtkPVAnimationInterfaceEntry *ai)
{
char methodAndArgs[500];
sprintf(methodAndArgs, "AnimationMenuCallback %s", ai->GetTclName());
// I do not under stand why the trace name is used for the
// menu entry, but Berk must know.
menu->AddCommand(this->GetTraceName(), this, methodAndArgs, 0, "");
}
//-----------------------------------------------------------------------------
// What a pain. I need this method for tracing.
// Maybe the animation should call PVwidget methods and not vtk object methods.
void vtkPVFoamSelectTimeSet::AnimationMenuCallback(vtkPVAnimationInterfaceEntry *ai)
{
if (ai->InitializeTrace(NULL))
{
this->AddTraceEntry("$kw(%s) AnimationMenuCallback $kw(%s)",
this->GetTclName(), ai->GetTclName());
}
// I do not under stand why the trace name is used for the
// menu entry, but Berk must know.
ai->SetLabelAndScript(this->GetTraceName(), NULL, this->GetTraceName());
ai->SetCurrentProperty(this->Property);
ai->Update();
}
//-----------------------------------------------------------------------------
vtkPVFoamSelectTimeSet* vtkPVFoamSelectTimeSet::ClonePrototype(vtkPVSource* pvSource,
vtkArrayMap<vtkPVWidget*, vtkPVWidget*>* map)
{
vtkPVWidget* clone = this->ClonePrototypeInternal(pvSource, map);
return vtkPVFoamSelectTimeSet::SafeDownCast(clone);
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::CopyProperties(vtkPVWidget* clone,
vtkPVSource* pvSource,
vtkArrayMap<vtkPVWidget*, vtkPVWidget*>* map)
{
this->Superclass::CopyProperties(clone, pvSource, map);
vtkPVFoamSelectTimeSet* pvts = vtkPVFoamSelectTimeSet::SafeDownCast(clone);
if (pvts)
{
pvts->SetLabel(this->FrameLabel);
pvts->SetSetCommand(this->SetCommand);
}
else
{
vtkErrorMacro(
"Internal error. Could not downcast clone to PVFoamSelectTimeSet.");
}
}
//-----------------------------------------------------------------------------
int vtkPVFoamSelectTimeSet::ReadXMLAttributes(vtkPVXMLElement* element,
vtkPVXMLPackageParser* parser)
{
if(!this->Superclass::ReadXMLAttributes(element, parser)) { return 0; }
// Setup the Label.
const char* label = element->GetAttribute("label");
if(label)
{
this->SetLabel(label);
}
this->SetSetCommand(element->GetAttribute("set_command"));
return 1;
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SetTimeSetsFromReader()
{
vtkPVProcessModule* pm = this->GetPVApplication()->GetProcessModule();
this->TimeSets->RemoveAllItems();
// Create the server-side helper if necessary.
if(!this->ServerSideID.ID)
{
this->ServerSideID = pm->NewStreamObject("vtkPVFoamServerSelectTimeSet");
pm->SendStream(vtkProcessModule::DATA_SERVER);
}
// Get the time sets from the reader on the server.
// Reader -> VTKSourceID (0). We assume that there is 1 VTKSource.
pm->GetStream() << vtkClientServerStream::Invoke
<< this->ServerSideID << "GetTimeSets"
<< this->PVSource->GetVTKSourceID(0)
<< vtkClientServerStream::End;
pm->SendStream(vtkProcessModule::DATA_SERVER_ROOT);
vtkClientServerStream timeSets;
if(!pm->GetLastServerResult().GetArgument(0, 0, &timeSets))
{
vtkErrorMacro("Error getting time sets from server.");
return;
}
// There is one time set per message.
for(int m=0; m < timeSets.GetNumberOfMessages(); ++m)
{
// Each argument in the message is a time set entry.
vtkFloatArray* timeSet = vtkFloatArray::New();
int n = timeSets.GetNumberOfArguments(m);
timeSet->SetNumberOfTuples(n);
for(int i=0; i < n; ++i)
{
float value;
if(!timeSets.GetArgument(m, i, &value))
{
vtkErrorMacro("Error reading time set value.");
timeSet->Delete();
return;
}
timeSet->SetTuple1(i, value);
}
this->TimeSets->AddItem(timeSet);
timeSet->Delete();
}
if (this->Property->GetNumberOfScalars() == 0 &&
this->TimeSets->GetNumberOfItems() > 0)
{
vtkFloatArray *ts =
vtkFloatArray::SafeDownCast(this->TimeSets->GetItem(0));
this->Property->SetScalars(1, ts->GetPointer(0));
}
}
//----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SaveInBatchScriptForPart(ofstream *file,
vtkClientServerID sourceID)
{
if (sourceID.ID == 0)
{
vtkErrorMacro(<< this->GetClassName()
<< " must not have SaveInBatchScript method.");
return;
}
*file << "\t" << "pvTemp" << sourceID
<< " SetTimeValue " << this->GetTimeValue()
<< endl;;
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::SetProperty(vtkPVWidgetProperty *prop)
{
this->Property = vtkPVScalarListWidgetProperty::SafeDownCast(prop);
if (this->Property)
{
int numScalars = 1;
this->Property->SetVTKCommands(1, &this->SetCommand, &numScalars);
}
}
//-----------------------------------------------------------------------------
vtkPVWidgetProperty* vtkPVFoamSelectTimeSet::GetProperty()
{
return this->Property;
}
//-----------------------------------------------------------------------------
vtkPVWidgetProperty* vtkPVFoamSelectTimeSet::CreateAppropriateProperty()
{
return vtkPVScalarListWidgetProperty::New();
}
//-----------------------------------------------------------------------------
void vtkPVFoamSelectTimeSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "TimeValue: " << this->TimeValue << endl;
os << indent << "LabeledFrame: " << this->LabeledFrame << endl;
os << indent << "SetCommand: "
<< (this->SetCommand ? this->SetCommand : "(none)") << endl;
}

View File

@ -0,0 +1,164 @@
/*=========================================================================
Program: ParaView
Module: $RCSfile: vtkPVFoamSelectTimeSet.h,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPVFoamSelectTimeSet - Special time selection widget used by PVFoamReaderModule
// .SECTION Description
// This is a PVWidget specially designed to be used with PVFoamReaderModule.
// It provides support for multiple sets. The time value selected by
// the user is passed to the Foam reader with a SetTimeValue() call.
#ifndef __vtkPVFoamSelectTimeSet_h
#define __vtkPVFoamSelectTimeSet_h
#include "vtkPVWidget.h"
class vtkKWLabel;
class vtkKWMenu;
class vtkKWLabeledFrame;
class vtkDataArrayCollection;
class vtkPVScalarListWidgetProperty;
class VTK_EXPORT vtkPVFoamSelectTimeSet : public vtkPVWidget
{
public:
static vtkPVFoamSelectTimeSet* New();
vtkTypeRevisionMacro(vtkPVFoamSelectTimeSet, vtkPVWidget);
void PrintSelf(ostream& os, vtkIndent indent);
virtual void Create(vtkKWApplication *pvApp);
//BTX
// Description:
// Called when accept button is pushed.
// Sets objects variable to the widgets value.
// Adds a trace entry. Side effect is to turn modified flag off.
virtual void AcceptInternal(vtkClientServerID);
//ETX
// Description:
// Called when the reset button is pushed.
// Sets widget's value to the object-variable's value.
// Side effect is to turn the modified flag off.
virtual void ResetInternal();
// Description:
// Adds a script to the menu of the animation interface.
virtual void AddAnimationScriptsToMenu(vtkKWMenu *menu,
vtkPVAnimationInterfaceEntry *ai);
// Description:
// Called whenthe animation method menu item is selected.
// Needed for proper tracing.
// It would be nice if the menu and cascade menus would trace
// invokation of items (?relying of enumeration of menu items or label?)
void AnimationMenuCallback(vtkPVAnimationInterfaceEntry *ai);
// Description:
// This is the labeled frame around the timeset tree.
vtkGetObjectMacro(LabeledFrame, vtkKWLabeledFrame);
// Description:
// Label displayed on the labeled frame.
void SetLabel(const char* label);
const char* GetLabel();
// Description:
// Updates the time value label and the time ivar.
void SetTimeValue(float time);
vtkGetMacro(TimeValue, float);
// Description:
// Calls this->SetTimeValue () and Reader->SetTimeValue()
// with currently selected time value.
void SetTimeValueCallback(const char* item);
//BTX
// Description:
// Creates and returns a copy of this widget. It will create
// a new instance of the same type as the current object
// using NewInstance() and then copy some necessary state
// parameters.
vtkPVFoamSelectTimeSet* ClonePrototype(vtkPVSource* pvSource,
vtkArrayMap<vtkPVWidget*, vtkPVWidget*>* map);
//ETX
// Description:
// This serves a dual purpose. For tracing and for saving state.
virtual void Trace(ofstream *file);
// Description:
// Set/get the property to use with this widget.
virtual void SetProperty(vtkPVWidgetProperty *prop);
virtual vtkPVWidgetProperty* GetProperty();
// Description:
// Create the right property for use with this widget.
virtual vtkPVWidgetProperty* CreateAppropriateProperty();
// Description:
// Set/get the command to pass the value to VTK.
vtkSetStringMacro(SetCommand);
vtkGetStringMacro(SetCommand);
// Description:
// Save this widget to a file.
virtual void SaveInBatchScript(ofstream *file);
protected:
vtkPVFoamSelectTimeSet();
~vtkPVFoamSelectTimeSet();
vtkPVFoamSelectTimeSet(const vtkPVFoamSelectTimeSet&); // Not implemented
void operator=(const vtkPVFoamSelectTimeSet&); // Not implemented
vtkPVScalarListWidgetProperty *Property;
char *SetCommand;
vtkSetStringMacro(FrameLabel);
vtkGetStringMacro(FrameLabel);
vtkKWWidget* Tree;
vtkKWWidget* TreeFrame;
vtkKWLabel* TimeLabel;
vtkKWLabeledFrame* LabeledFrame;
void AddRootNode(const char* name, const char* text);
void AddChildNode(const char* parent, const char* name,
const char* text, const char* data);
float TimeValue;
char* FrameLabel;
vtkDataArrayCollection* TimeSets;
vtkClientServerID ServerSideID;
// Fill the TimeSets collection with that from the actual reader.
void SetTimeSetsFromReader();
//BTX
virtual void CopyProperties(vtkPVWidget* clone, vtkPVSource* pvSource,
vtkArrayMap<vtkPVWidget*, vtkPVWidget*>* map);
//ETX
int ReadXMLAttributes(vtkPVXMLElement* element,
vtkPVXMLPackageParser* parser);
// Description:
// An interface for saving a widget into a script.
virtual void SaveInBatchScriptForPart(ofstream *file, vtkClientServerID);
};
#endif

View File

@ -0,0 +1,85 @@
/*=========================================================================
Program: ParaView
Module: $RCSfile: vtkPVFoamServerSelectTimeSet.cxx,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPVFoamServerSelectTimeSet.h"
#include "vtkClientServerInterpreter.h"
#include "vtkObjectFactory.h"
#include "vtkPVProcessModule.h"
#include "vtkFoamReader.h"
#include "vtkDataArrayCollection.h"
#include "vtkDataArrayCollectionIterator.h"
#include "vtkClientServerStream.h"
#include <vtkstd/string>
//----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPVFoamServerSelectTimeSet);
vtkCxxRevisionMacro(vtkPVFoamServerSelectTimeSet, "$Revision: 1.4 $");
//----------------------------------------------------------------------------
class vtkPVFoamServerSelectTimeSetInternals
{
public:
vtkClientServerStream Result;
};
//----------------------------------------------------------------------------
vtkPVFoamServerSelectTimeSet::vtkPVFoamServerSelectTimeSet()
{
this->Internal = new vtkPVFoamServerSelectTimeSetInternals;
}
//----------------------------------------------------------------------------
vtkPVFoamServerSelectTimeSet::~vtkPVFoamServerSelectTimeSet()
{
delete this->Internal;
}
//----------------------------------------------------------------------------
void vtkPVFoamServerSelectTimeSet::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os,indent);
}
//----------------------------------------------------------------------------
const vtkClientServerStream&
vtkPVFoamServerSelectTimeSet::GetTimeSets(vtkFoamReader* reader)
{
// Reset the stream for a new list of time sets.
this->Internal->Result.Reset();
// Get the time sets from the reader.
vtkDataArrayCollection* timeSets = reader->GetTimeSets();
// Iterate through the time sets.
vtkDataArrayCollectionIterator* iter = vtkDataArrayCollectionIterator::New();
iter->SetCollection(timeSets);
for(iter->GoToFirstItem(); !iter->IsDoneWithTraversal();
iter->GoToNextItem())
{
// Each time set is stored in one message.
this->Internal->Result << vtkClientServerStream::Reply;
vtkDataArray* da = iter->GetDataArray();
for(int i=0; i < da->GetNumberOfTuples(); ++i)
{
this->Internal->Result << da->GetTuple1(i);
}
this->Internal->Result << vtkClientServerStream::End;
}
iter->Delete();
// Return the stream.
return this->Internal->Result;
}

View File

@ -0,0 +1,49 @@
/*=========================================================================
Program: ParaView
Module: $RCSfile: vtkPVFoamServerSelectTimeSet.h,v $
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.paraview.org/HTML/Copyright.html for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPVFoamServerSelectTimeSet - Server-side helper for vtkPVFoamSelectTimeSet.
// .SECTION Description
#ifndef __vtkPVFoamServerSelectTimeSet_h
#define __vtkPVFoamServerSelectTimeSet_h
#include "vtkPVServerObject.h"
class vtkClientServerStream;
class vtkPVFoamServerSelectTimeSetInternals;
class vtkFoamReader;
class VTK_EXPORT vtkPVFoamServerSelectTimeSet : public vtkPVServerObject
{
public:
static vtkPVFoamServerSelectTimeSet* New();
vtkTypeRevisionMacro(vtkPVFoamServerSelectTimeSet, vtkPVServerObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Get a list the time sets provided by the given reader.
const vtkClientServerStream& GetTimeSets(vtkFoamReader*);
protected:
vtkPVFoamServerSelectTimeSet();
~vtkPVFoamServerSelectTimeSet();
// Internal implementation details.
vtkPVFoamServerSelectTimeSetInternals* Internal;
private:
vtkPVFoamServerSelectTimeSet(const vtkPVFoamServerSelectTimeSet&); // Not implemented
void operator=(const vtkPVFoamServerSelectTimeSet&); // Not implemented
};
#endif

View File

@ -0,0 +1,5 @@
vtkFoam.C
vtkFoamAddInternalMesh.C
vtkFoamAddPatch.C
LIB = $(FOAM_LIBBIN)/libvtkFoam

View File

@ -0,0 +1,8 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(ParaView_INST_DIR)/include \
-I../PVFoamReader
LIB_LIBS = \
-lfiniteVolume \
$(GLIBS)

View File

@ -0,0 +1,665 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkFoam.H"
#include "argList.H"
#include "Time.H"
#include "polyBoundaryMeshEntries.H"
#include "IOobjectList.H"
#include "wordList.H"
#include "fvMesh.H"
#include "volFields.H"
#include "pointMesh.H"
#include "volPointInterpolation.H"
#include "vtkFoamReader.h"
#include "vtkDataArraySelection.h"
#include "vtkUnstructuredGrid.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkCharArray.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::vtkFoam, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
#include "vtkFoamConvertFields.H"
void Foam::vtkFoam::SetName
(
vtkUnstructuredGrid* vtkMesh,
const char* name
)
{
vtkCharArray* nmArray = vtkCharArray::New();
nmArray->SetName("Name");
size_t len = strlen(name);
nmArray->SetNumberOfTuples(static_cast<vtkIdType>(len)+1);
char* copy = nmArray->GetPointer(0);
memcpy(copy, name, len);
copy[len] = '\0';
vtkMesh->GetFieldData()->AddArray(nmArray);
nmArray->Delete();
}
Foam::string Foam::vtkFoam::padTimeString(const string& ts)
{
return ts + string(" ", max(label(12 - ts.size()), 0));
}
// Pad the patch name string in order to account for dynamic changes
// in patch names during topological changes
Foam::string Foam::vtkFoam::padPatchString(const string& ps)
{
label n = max(label(50 - ps.size()), 0);
return ps + string(" ", n);
}
void Foam::vtkFoam::setSelectedTime
(
Time& runTime,
vtkFoamReader* reader
)
{
// Get times list
instantList Times = runTime.times();
int timeIndex = min(max(reader->GetTimeStep() + 1, 0), Times.size()-1);
// If this is the first call timeIndex will be 0 ("constant")
// so reset to the first time step if one exists and deselect every
// element of the selection array
if (timeIndex == 0)
{
timeIndex = min(1, Times.size()-1);
reader->GetTimeSelection()->DisableAllArrays();
}
label selectedTimeIndex = -1;
label nSelectedTimes = reader->GetTimeSelection()->GetNumberOfArrays();
for (label i=nSelectedTimes-1; i>=0; i--)
{
if(reader->GetTimeSelection()->GetArraySetting(i))
{
word timeName = string::validate<word>
(
reader->GetTimeSelection()->GetArrayName(i)
);
forAll(Times, j)
{
if (Times[j].name() == timeName)
{
selectedTimeIndex = j;
break;
}
}
break;
}
}
if (selectedTimeIndex != -1)
{
timeIndex = min(selectedTimeIndex, Times.size()-1);
}
if (debug)
{
Info<< "Selecting time " << Times[timeIndex].name() << endl;
}
runTime.setTime(Times[timeIndex], timeIndex);
Times = runTime.times();
reader->SetTimeStepRange(0, max(Times.size()-2, 0));
// reset the time steps ...
reader->GetTimeSelection()->RemoveAllArrays();
int* TimeStepLimits = reader->GetTimeStepLimits();
label maxStartTimes = min(Times.size(), TimeStepLimits[0]);
label maxNTimes = min(Times.size() - maxStartTimes, TimeStepLimits[1]);
for (label i=0; i<maxStartTimes; i++)
{
reader->GetTimeSelection()
->AddArray(padTimeString(Times[i].name()).c_str());
}
if (Times.size() > TimeStepLimits[0] + TimeStepLimits[1])
{
reader->GetTimeSelection()->AddArray(padTimeString("...").c_str());
}
for (label i=Times.size() - maxNTimes; i<Times.size(); i++)
{
reader->GetTimeSelection()
->AddArray(padTimeString(Times[i].name()).c_str());
}
// Disable all the time selections (which are all selected by default) ...
reader->GetTimeSelection()->DisableAllArrays();
// But maintain the selections made previously
if (selectedTimeIndex != -1 && selectedTimeIndex < Times.size())
{
reader->GetTimeSelection()->EnableArray
(padTimeString(Times[selectedTimeIndex].name()).c_str());
}
}
void Foam::vtkFoam::updateSelectedRegions()
{
if (debug)
{
Info<< "Foam::vtkFoam::updateSelectedRegions()" << endl;
}
label nRegions = reader_->GetRegionSelection()->GetNumberOfArrays();
selectedRegions_.setSize(nRegions);
// Read the selected patches and add to the region list
for (int i=0; i<nRegions; i++)
{
selectedRegions_[i] =
reader_->GetRegionSelection()->GetArraySetting(i);
}
}
void Foam::vtkFoam::convertMesh()
{
if (debug)
{
Info<< "Foam::vtkFoam::convertMesh()" << endl;
}
const fvMesh& mesh = *meshPtr_;
// Read the internal mesh as region 0 if selected
if (reader_->GetRegionSelection()->GetArraySetting(0))
{
selectedRegions_[0] = true;
addInternalMesh
(
mesh,
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0))
);
}
else
{
selectedRegions_[0] = false;
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
vtkMesh->Initialize();
SetName(vtkMesh, "(Internal Mesh)");
}
// Read the selected patches and add to the region list
polyBoundaryMeshEntries patchEntries
(
IOobject
(
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
label regioni = 0;
label regioniLast = 0;
// Read in the number Outputs (patch regions) currently being used
label currNOutputs = reader_->GetNumberOfOutputs();
// Cycle through all the patches in the boundary file for the relevant
// time step
forAll(patchEntries, entryi)
{
// Number of faces in the current patch (Used to detect dummy patches
// of size zero)
label nFaces(readLabel(patchEntries[entryi].dict().lookup("nFaces")));
// Check to see if the patch is currently a part of the displayed list
if
(
reader_->GetRegionSelection()->ArrayExists
(
padPatchString(patchEntries[entryi].keyword()).c_str()
)
)
{
if (!nFaces)
{
// Remove patch if it is only a dummy patch in the current
// time step with zero faces
reader_->GetRegionSelection()->RemoveArrayByName
(
padPatchString(patchEntries[entryi].keyword()).c_str()
);
}
else
{
// A patch already existent in the list and which
// continues to exist found
regioni++;
}
}
else
{
// A new patch so far not yet included into the list has been found
if (nFaces)
{
regioni++;
// Add a new entry to the list of regions
reader_->GetRegionSelection()->AddArray
(
padPatchString(patchEntries[entryi].keyword()).c_str()
);
// AddArray automatically enables a new array... disable
// it manually
reader_->GetRegionSelection()->DisableArray
(
padPatchString(patchEntries[entryi].keyword()).c_str()
);
}
}
// Avoid Initialization of the same Output twice
if (regioni != regioniLast)
{
// Only setup an Output if it has not been setup before
if(regioni >= currNOutputs)
{
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
reader_->SetNthOutput(regioni,ugrid);
ugrid->Delete();
}
// Initialize -> Delete memory used, and reset to zero state
reader_->GetOutput(regioni)->Initialize();
regioniLast = regioni;
}
}
// Initialize (reset to zero and free) any outputs which are not used
// anymore
if (regioni < currNOutputs)
{
for(label i = (regioni+1); i < currNOutputs;i++)
{
reader_->GetOutput(i)->Initialize();
}
}
selectedRegions_.setSize(regioni + 1);
regioni = 0;
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAll (patches, patchi)
{
if (patches[patchi].size())
{
regioni++;
if (reader_->GetRegionSelection()->GetArraySetting(regioni))
{
selectedRegions_[regioni] = true;
addPatch
(
patches[patchi],
vtkUnstructuredGrid::SafeDownCast
(
reader_->GetOutput(regioni)
)
);
}
else
{
selectedRegions_[regioni] = false;
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast
(
reader_->GetOutput(regioni)
);
vtkMesh->Initialize();
SetName
(
vtkMesh,
('(' + padPatchString(patches[patchi].name()) + ')').c_str()
);
}
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkFoam::vtkFoam(const char* const FileName, vtkFoamReader* reader)
:
reader_(reader),
argsPtr_(NULL),
dbPtr_(NULL),
meshPtr_(NULL)
{
fileName fullCasePath(fileName(FileName).path());
if (!dir(fullCasePath))
{
return;
}
char* argvStrings[3];
argvStrings[0] = new char[9];
strcpy(argvStrings[0], "/vtkFoam");
argvStrings[1] = new char[6];
strcpy(argvStrings[1], "-case");
argvStrings[2] = new char[fullCasePath.size()+1];
strcpy(argvStrings[2], fullCasePath.c_str());
int argc = 3;
char** argv = &argvStrings[0];
argsPtr_.reset(new argList(argc, argv));
for(int i = 0; i < argc; i++)
{
delete[] argvStrings[i];
}
dbPtr_.reset
(
new Time
(
Time::controlDictName,
argsPtr_().rootPath(),
argsPtr_().caseName()
)
);
dbPtr_().functionObjects().off();
setSelectedTime(dbPtr_(), reader_);
if (debug)
{
Info<< "vtkFoam::ExecuteInformation: Initialising outputs" << endl;
}
reader_->GetRegionSelection()->AddArray("Internal Mesh");
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
reader_->SetNthOutput(0, ugrid);
ugrid->Delete();
reader_->GetOutput(0)->Initialize();
polyBoundaryMeshEntries patchEntries
(
IOobject
(
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
label regioni = 0;
forAll(patchEntries, entryi)
{
label nFaces(readLabel(patchEntries[entryi].dict().lookup("nFaces")));
if (nFaces)
{
regioni++;
reader_->GetRegionSelection()->AddArray
(
padPatchString(patchEntries[entryi].keyword()).c_str()
);
vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::New();
reader_->SetNthOutput(regioni, ugrid);
ugrid->Delete();
reader_->GetOutput(regioni)->Initialize();
}
}
selectedRegions_.setSize(regioni + 1);
selectedRegions_ = true;
UpdateInformation();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkFoam::~vtkFoam()
{
// Do NOT delete meshPtr_ since still referenced somehow.
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#include "vtkFoamAddFields.H"
void Foam::vtkFoam::UpdateInformation()
{
if (debug)
{
Info<< "TimeStep = " << reader_->GetTimeStep() << endl;
}
setSelectedTime(dbPtr_(), reader_);
// Search for list of objects for this time
IOobjectList objects(dbPtr_(), dbPtr_().timeName());
addFields<volScalarField>(reader_->GetVolFieldSelection(), objects);
addFields<volVectorField>(reader_->GetVolFieldSelection(), objects);
addFields<volSphericalTensorField>(reader_->GetVolFieldSelection(), objects);
addFields<volSymmTensorField>(reader_->GetVolFieldSelection(), objects);
addFields<volTensorField>(reader_->GetVolFieldSelection(), objects);
addFields<pointScalarField>(reader_->GetPointFieldSelection(), objects);
addFields<pointVectorField>(reader_->GetPointFieldSelection(), objects);
addFields<pointSphericalTensorField>(reader_->GetPointFieldSelection(), objects);
addFields<pointSymmTensorField>(reader_->GetPointFieldSelection(), objects);
addFields<pointTensorField>(reader_->GetPointFieldSelection(), objects);
}
void Foam::vtkFoam::Update()
{
if
(
!reader_->GetCacheMesh()
|| reader_->GetTimeSelection()->GetArraySetting(0)
)
{
meshPtr_= NULL;
}
// Clear the current set of selected fields
for (label i=0; i<reader_->GetNumberOfOutputs(); i++)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(i));
vtkCellData* cellData = vtkMesh->GetCellData();
int numberOfCellArrays = cellData->GetNumberOfArrays();
wordList cellFieldNames(numberOfCellArrays);
for (int j=0; j<numberOfCellArrays; j++)
{
cellFieldNames[j] = cellData->GetArrayName(j);
}
for (int j=0; j<numberOfCellArrays; j++)
{
cellData->RemoveArray(cellFieldNames[j].c_str());
}
vtkPointData* pointData = vtkMesh->GetPointData();
int numberOfPointArrays = pointData->GetNumberOfArrays();
wordList pointFieldNames(numberOfPointArrays);
for (int j=0; j<numberOfPointArrays; j++)
{
pointFieldNames[j] = pointData->GetArrayName(j);
}
for (int j=0; j<numberOfPointArrays; j++)
{
pointData->RemoveArray(pointFieldNames[j].c_str());
}
}
// Check to see if the mesh has been created
if (!meshPtr_)
{
if (debug)
{
Info<< "Reading Mesh" << endl;
}
meshPtr_ =
new fvMesh
(
IOobject
(
fvMesh::defaultRegion,
dbPtr_().timeName(),
dbPtr_()
)
);
convertMesh();
}
else
{
boolList oldSelectedRegions = selectedRegions_;
updateSelectedRegions();
if
(
meshPtr_->readUpdate() != fvMesh::UNCHANGED
|| oldSelectedRegions != selectedRegions_
)
{
convertMesh();
}
}
if (debug)
{
Info<< "converting fields" << endl;
}
const fvMesh& mesh = *meshPtr_;
// Construct interpolation on the raw mesh
Foam::pointMesh pMesh(mesh);
Foam::volPointInterpolation pInterp(mesh, pMesh);
// Search for list of objects for this time
Foam::IOobjectList objects(mesh, dbPtr_().timeName());
convertVolFields<Foam::scalar>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection()
);
convertVolFields<Foam::vector>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection()
);
convertVolFields<Foam::sphericalTensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection()
);
convertVolFields<Foam::symmTensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection()
);
convertVolFields<Foam::tensor>
(
mesh, pInterp, objects, reader_->GetVolFieldSelection()
);
convertPointFields<Foam::scalar>
(
mesh, objects, reader_->GetPointFieldSelection()
);
convertPointFields<Foam::vector>
(
mesh, objects, reader_->GetPointFieldSelection()
);
convertPointFields<Foam::sphericalTensor>
(
mesh, objects, reader_->GetPointFieldSelection()
);
convertPointFields<Foam::symmTensor>
(
mesh, objects, reader_->GetPointFieldSelection()
);
convertPointFields<Foam::tensor>
(
mesh, objects, reader_->GetPointFieldSelection()
);
if (debug)
{
Info<< "done" << endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,256 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::vtkFoam
Description
SourceFiles
vtkFoam.C
vtkFoamInsertNextPoint.H
vtkFoamAddFields.H
vtkFoamAddInternalMesh.H
vtkFoamConvertFields.H
vtkFoamConvertVolField.H
vtkFoamConvertPatchFaceField.H
vtkFoamConvertPointField.H
vtkFoamConvertPatchPointField.H
\*---------------------------------------------------------------------------*/
#ifndef vtkFoam_H
#define vtkFoam_H
#include "className.H"
#include "fileName.H"
#include "volPointInterpolation.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
// VTK class forward declarations
class vtkFoamReader;
class vtkUnstructuredGrid;
class vtkPoints;
class vtkDataArraySelection;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Foam class forward declarations
class argList;
class Time;
class fvMesh;
class IOobjectList;
class polyPatch;
/*---------------------------------------------------------------------------*\
Class vtkFoam Declaration
\*---------------------------------------------------------------------------*/
class vtkFoam
{
// Private data
//- Access to the controlling vtkFoamReader
vtkFoamReader *reader_;
autoPtr<argList> argsPtr_;
autoPtr<Time> dbPtr_;
fvMesh* meshPtr_;
//- Selected regions, [0] = internal mesh, [1-nPatches] = patches
boolList selectedRegions_;
//- Lables of cell-centres used as additional points when decomposing
// polyhedra
labelList addPointCellLabels_;
//- Label of original cell the decomposed cells are split from
labelList superCells_;
// Private Member Functions
//- Pad-out the time name to avoid bug in the GUI redraw
static string padTimeString(const string&);
//- Pad-out the patch name
static string padPatchString(const string&);
//- Find and set the selected time from all the methods of selection
static void setSelectedTime
(
Time& runTime,
vtkFoamReader* reader
);
//- Update the selected regions
void updateSelectedRegions();
//- Convert the mesh according to the list of selected regions
void convertMesh();
//- Add the internal mesh to the set of Outputs if selected
void addInternalMesh(const fvMesh&, vtkUnstructuredGrid*);
//- Add the internal patch to the set of Outputs if selected
void addPatch(const polyPatch&, vtkUnstructuredGrid*);
//- Add the fields in th selested time directory to the selection lists
template<class GeoField>
void addFields
(
vtkDataArraySelection *fieldSelection,
const IOobjectList& objects
);
//- Convert the selected volFields
template<class Type>
void convertVolFields
(
const fvMesh& mesh,
const volPointInterpolation& pInterp,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection
);
template<class Type>
void convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf
);
template<class Type>
void convertPatchFaceField
(
const word& name,
const Field<Type>& tf,
const label regioni
);
//- Convert the selected pointFields
template<class Type>
void convertPointFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection
);
template<class Type>
void convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf
);
template<class Type>
void convertPatchPointField
(
const word& name,
const Field<Type>& tf,
const label regioni
);
//- Set the name of the Output vtkUnstructuredGrid
void SetName(vtkUnstructuredGrid *vtkMesh, const char* name);
//- Disallow default bitwise copy construct
vtkFoam(const vtkFoam&);
//- Disallow default bitwise assignment
void operator=(const vtkFoam&);
public:
// Static data members
ClassName("vtkFoam");
// Constructors
//- Construct from components
vtkFoam(const char* const FileName, vtkFoamReader* reader);
// Destructor
~vtkFoam();
// Member Functions
void UpdateInformation();
void Update();
};
// * * * * * * * * * * * * * Template Specialisations * * * * * * * * * * * //
template<>
void vtkFoam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf
);
template<>
void vtkFoam::convertPatchFaceField
(
const word& name,
const Field<scalar>& sf,
const label regioni
);
template<>
void vtkFoam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>& psf,
const GeometricField<scalar, fvPatchField, volMesh>& sf
);
template<>
void vtkFoam::convertPatchPointField
(
const word& name,
const Field<scalar>& sf,
const label regioni
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamAddFields_H
#define vtkFoamAddFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
void Foam::vtkFoam::addFields
(
vtkDataArraySelection *fieldSelection,
const IOobjectList& objects
)
{
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
for
(
IOobjectList::iterator iter = fieldObjects.begin();
iter != fieldObjects.end();
++iter
)
{
fieldSelection->AddArray(iter()->name().c_str());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,299 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkFoam.H"
#include "fvMesh.H"
#include "cellModeller.H"
#include "vtkUnstructuredGrid.h"
#include "vtkCellArray.h"
#include "vtkFoamInsertNextPoint.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkFoam::addInternalMesh
(
const fvMesh& mesh,
vtkUnstructuredGrid* vtkMesh
)
{
SetName(vtkMesh, "Internal Mesh");
// Number of additional points needed by the decomposition of polyhedra
label nAddPoints = 0;
// Number of additional cells generated by the decomposition of polyhedra
label nAddCells = 0;
const cellModel& tet = *(cellModeller::lookup("tet"));
const cellModel& pyr = *(cellModeller::lookup("pyr"));
const cellModel& prism = *(cellModeller::lookup("prism"));
const cellModel& wedge = *(cellModeller::lookup("wedge"));
const cellModel& tetWedge = *(cellModeller::lookup("tetWedge"));
const cellModel& hex = *(cellModeller::lookup("hex"));
// Scan for cells which need to be decomposed and count additional points
// and cells
if (debug)
{
Info<< "building cell-shapes" << endl;
}
const cellShapeList& cellShapes = mesh.cellShapes();
if (debug)
{
Info<< "scanning" << endl;
}
forAll(cellShapes, cellI)
{
const cellModel& model = cellShapes[cellI].model();
if
(
model != hex
&& model != wedge
&& model != prism
&& model != pyr
&& model != tet
&& model != tetWedge
)
{
const cell& cFaces = mesh.cells()[cellI];
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
label nFacePoints = f.size();
label nQuads = (nFacePoints - 2)/2;
label nTris = (nFacePoints - 2)%2;
nAddCells += nQuads + nTris;
}
nAddCells--;
nAddPoints++;
}
}
// Set size of additional point addressing array
// (from added point to original cell)
addPointCellLabels_.setSize(nAddPoints);
// Set size of additional cells mapping array
// (from added cell to original cell)
superCells_.setSize(mesh.nCells() + nAddCells);
if (debug)
{
Info<< "converting points" << endl;
}
// Convert Foam mesh vertices to VTK
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(mesh.nPoints() + nAddPoints);
const Foam::pointField& points = mesh.points();
forAll(points, i)
{
vtkFoamInsertNextPoint(vtkpoints, points[i]);
}
if (debug)
{
Info<< "converting cells" << endl;
}
vtkMesh->Allocate(mesh.nCells() + nAddCells);
// Set counters for additional points and additional cells
label api = 0, aci = 0;
forAll(cellShapes, celli)
{
const cellShape& cellShape = cellShapes[celli];
const cellModel& cellModel = cellShape.model();
superCells_[aci++] = celli;
if (cellModel == tet)
{
vtkMesh->InsertNextCell
(
VTK_TETRA,
4,
const_cast<int*>(cellShape.begin())
);
}
else if (cellModel == pyr)
{
vtkMesh->InsertNextCell
(
VTK_PYRAMID,
5,
const_cast<int*>(cellShape.begin())
);
}
else if (cellModel == prism)
{
vtkMesh->InsertNextCell
(
VTK_WEDGE,
6,
const_cast<int*>(cellShape.begin())
);
}
else if (cellModel == tetWedge)
{
// Treat as squeezed prism
int vtkVerts[6];
vtkVerts[0] = cellShape[0];
vtkVerts[1] = cellShape[2];
vtkVerts[2] = cellShape[1];
vtkVerts[3] = cellShape[3];
vtkVerts[4] = cellShape[4];
vtkVerts[5] = cellShape[4];
vtkMesh->InsertNextCell(VTK_WEDGE, 6, vtkVerts);
}
else if (cellModel == wedge)
{
// Treat as squeezed hex
int vtkVerts[8];
vtkVerts[0] = cellShape[0];
vtkVerts[1] = cellShape[1];
vtkVerts[2] = cellShape[2];
vtkVerts[3] = cellShape[2];
vtkVerts[4] = cellShape[3];
vtkVerts[5] = cellShape[4];
vtkVerts[6] = cellShape[5];
vtkVerts[7] = cellShape[6];
vtkMesh->InsertNextCell(VTK_HEXAHEDRON, 8, vtkVerts);
}
else if (cellModel == hex)
{
vtkMesh->InsertNextCell
(
VTK_HEXAHEDRON,
8,
const_cast<int*>(cellShape.begin())
);
}
else
{
// Polyhedral cell. Decompose into tets + prisms.
// Mapping from additional point to cell
addPointCellLabels_[api] = celli;
// Insert the new vertex from the cell-centre
label newVertexLabel = mesh.nPoints() + api;
vtkFoamInsertNextPoint(vtkpoints, mesh.C()[celli]);
// Whether to insert cell in place of original or not.
bool substituteCell = true;
const labelList& cFaces = mesh.cells()[celli];
forAll(cFaces, cFaceI)
{
const face& f = mesh.faces()[cFaces[cFaceI]];
label nFacePoints = f.size();
label nQuads = (nFacePoints - 2)/2;
label nTris = (nFacePoints - 2)%2;
label qpi = 0;
for (label quadi=0; quadi<nQuads; quadi++)
{
label thisCellI = -1;
if (substituteCell)
{
thisCellI = celli;
substituteCell = false;
}
else
{
thisCellI = mesh.nCells() + aci;
superCells_[aci++] = celli;
}
int addVtkVerts[5];
addVtkVerts[0] = f[0];
addVtkVerts[1] = f[qpi + 1];
addVtkVerts[2] = f[qpi + 2];
addVtkVerts[3] = f[qpi + 3];
addVtkVerts[4] = newVertexLabel;
vtkMesh->InsertNextCell(VTK_PYRAMID, 5, addVtkVerts);
qpi += 2;
}
if (nTris)
{
label thisCellI = -1;
if (substituteCell)
{
thisCellI = celli;
substituteCell = false;
}
else
{
thisCellI = mesh.nCells() + aci;
superCells_[aci++] = celli;
}
int addVtkVerts[4];
addVtkVerts[0] = f[0];
addVtkVerts[1] = f[qpi + 1];
addVtkVerts[2] = f[qpi + 2];
addVtkVerts[3] = newVertexLabel;
vtkMesh->InsertNextCell(VTK_TETRA, 4, addVtkVerts);
}
}
api++;
}
}
vtkMesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,115 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkFoam.H"
#include "polyPatch.H"
#include "vtkUnstructuredGrid.h"
#include "vtkCellArray.h"
#include "vtkFoamInsertNextPoint.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkFoam::addPatch
(
const polyPatch& p,
vtkUnstructuredGrid *vtkPatch
)
{
if (debug)
{
Info<< "Adding patch " << p.name() << endl;
}
SetName(vtkPatch, p.name().c_str());
if (debug)
{
Info<< "converting points" << endl;
}
const Foam::pointField& points = p.localPoints();
// Convert Foam mesh vertices to VTK
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(points.size());
forAll(points, i)
{
vtkFoamInsertNextPoint(vtkpoints, points[i]);
}
if (debug)
{
Info<< "converting faces" << endl;
}
const faceList& faces = p.localFaces();
vtkPatch->Allocate(faces.size());
forAll(faces, facei)
{
const face& f = faces[facei];
if (f.size() == 3)
{
vtkPatch->InsertNextCell
(
VTK_TRIANGLE,
3,
const_cast<int*>(f.begin())
);
}
else if (f.size() == 4)
{
vtkPatch->InsertNextCell
(
VTK_QUAD,
4,
const_cast<int*>(f.begin())
);
}
else
{
vtkPatch->InsertNextCell
(
VTK_POLYGON,
f.size(),
const_cast<int*>(f.begin())
);
}
}
vtkPatch->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,235 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamConvertFields_H
#define vtkFoamConvertFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "vtkFoamConvertVolField.H"
#include "vtkFoamConvertPointField.H"
#include "vtkFoamConvertPatchFaceField.H"
#include "vtkFoamConvertPatchPointField.H"
#include "emptyFvPatchField.H"
template<class Type>
void Foam::vtkFoam::convertVolFields
(
const fvMesh& mesh,
const volPointInterpolation& pInterp,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection
)
{
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, fvPatchField, volMesh>::typeName
)
);
label nSelectedFields = fieldSelection->GetNumberOfArrays();
for (label i=0; i<nSelectedFields; i++)
{
if(fieldSelection->GetArraySetting(i))
{
word fieldName = fieldSelection->GetArrayName(i);
if (fieldObjects.found(fieldName))
{
GeometricField<Type, fvPatchField, volMesh> tf
(
IOobject
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
),
mesh
);
tmp<GeometricField<Type, pointPatchField, pointMesh> > tptf
(
pInterp.interpolate(tf)
);
if (selectedRegions_[0])
{
convertVolField(tf);
convertPointField(tptf(), tf);
}
label regioni = 0;
forAll (mesh.boundaryMesh(), patchi)
{
if (mesh.boundaryMesh()[patchi].size())
{
regioni++;
if (selectedRegions_[regioni])
{
const fvPatchField<Type>& ptf
(
tf.boundaryField()[patchi]
);
if (!isType<emptyFvPatchField<Type> >(ptf))
{
convertPatchFaceField
(
tf.name(),
ptf,
regioni
);
convertPatchPointField
(
tptf().name(),
tptf().boundaryField()[patchi]
.patchInternalField()(),
regioni
);
}
else
{
fvPatch p
(
ptf.patch().patch(),
tf.mesh().boundary()
);
convertPatchFaceField
(
tf.name(),
fvPatchField<Type>(p, tf)
.patchInternalField()(),
regioni
);
convertPatchPointField
(
tptf().name(),
tptf().boundaryField()[patchi]
.patchInternalField()(),
regioni
);
}
}
}
}
}
}
}
}
template<class Type>
void Foam::vtkFoam::convertPointFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection
)
{
IOobjectList fieldObjects
(
objects.lookupClass
(
GeometricField<Type, pointPatchField, pointMesh>::typeName
)
);
label nSelectedFields = fieldSelection->GetNumberOfArrays();
for (label i=0; i<nSelectedFields; i++)
{
if(fieldSelection->GetArraySetting(i))
{
word fieldName = fieldSelection->GetArrayName(i);
if (fieldObjects.found(fieldName))
{
pointMesh pMesh(mesh);
GeometricField<Type, pointPatchField, pointMesh> ptf
(
IOobject
(
fieldName,
mesh.time().timeName(),
mesh,
IOobject::MUST_READ
),
pMesh
);
if (selectedRegions_[0])
{
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null()
);
}
label regioni = 0;
forAll (mesh.boundaryMesh(), patchi)
{
if (mesh.boundaryMesh()[patchi].size())
{
regioni++;
if (selectedRegions_[regioni])
{
convertPatchPointField
(
ptf.name(),
ptf.boundaryField()[patchi]
.patchInternalField()(),
regioni
);
}
}
}
}
}
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamConvertPatchFaceField_H
#define vtkFoamConvertPatchFaceField_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkFoam::convertPatchFaceField
(
const word& name,
const Field<Type>& ptf,
const label regioni
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
vtkFloatArray *cellTypes = vtkFloatArray::New();
cellTypes->SetNumberOfTuples(ptf.size());
cellTypes->SetNumberOfComponents(Type::nComponents);
cellTypes->Allocate(Type::nComponents*ptf.size());
cellTypes->SetName(name.c_str());
float vec[Type::nComponents];
forAll(ptf, i)
{
const Type& t = ptf[i];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
cellTypes->InsertTuple(i, vec);
}
vtkMesh->GetCellData()->AddArray(cellTypes);
cellTypes->Delete();
}
template<>
void Foam::vtkFoam::convertPatchFaceField
(
const word& name,
const Field<scalar>& psf,
const label regioni
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
vtkFloatArray *cellScalars = vtkFloatArray::New();
cellScalars->SetNumberOfTuples(psf.size());
cellScalars->SetNumberOfComponents(1);
cellScalars->Allocate(psf.size());
cellScalars->SetName(name.c_str());
forAll(psf, i)
{
cellScalars->InsertComponent(i, 0, psf[i]);
}
vtkMesh->GetCellData()->AddArray(cellScalars);
if (!vtkMesh->GetCellData()->GetScalars())
{
vtkMesh->GetCellData()->SetScalars(cellScalars);
}
cellScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,105 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamConvertPatchPointField_H
#define vtkFoamConvertPatchPointField_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkFoam::convertPatchPointField
(
const word& name,
const Field<Type>& pptf,
const label regioni
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
vtkFloatArray *pointTypes = vtkFloatArray::New();
pointTypes->SetNumberOfTuples(pptf.size());
pointTypes->SetNumberOfComponents(Type::nComponents);
pointTypes->Allocate(Type::nComponents*pptf.size());
pointTypes->SetName(name.c_str());
float vec[Type::nComponents];
forAll(pptf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = pptf[i][d];
}
pointTypes->InsertTuple(i, vec);
}
vtkMesh->GetPointData()->AddArray(pointTypes);
pointTypes->Delete();
}
template<>
void Foam::vtkFoam::convertPatchPointField
(
const word& name,
const Field<scalar>& ppsf,
const label regioni
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(regioni));
vtkFloatArray *pointScalars = vtkFloatArray::New();
pointScalars->SetNumberOfTuples(ppsf.size());
pointScalars->SetNumberOfComponents(1);
pointScalars->Allocate(ppsf.size());
pointScalars->SetName(name.c_str());
for (int i=0; i<ppsf.size(); i++)
{
pointScalars->InsertComponent(i, 0, ppsf[i]);
}
vtkMesh->GetPointData()->AddArray(pointScalars);
if (!vtkMesh->GetPointData()->GetScalars())
{
vtkMesh->GetPointData()->SetScalars(pointScalars);
}
pointScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,163 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamConvertPointField_H
#define vtkFoamConvertPointField_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "interpolatePointToCell.H"
template<class Type>
void Foam::vtkFoam::convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
vtkFloatArray *pointTypes = vtkFloatArray::New();
pointTypes->SetNumberOfTuples(ptf.size() + addPointCellLabels_.size());
pointTypes->SetNumberOfComponents(Type::nComponents);
pointTypes->Allocate(Type::nComponents*ptf.size());
pointTypes->SetName(ptf.name().c_str());
float vec[Type::nComponents];
forAll(ptf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = ptf[i][d];
}
pointTypes->InsertTuple(i, vec);
}
label i = ptf.size();
if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
Type t = tf[addPointCellLabels_[api]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
pointTypes->InsertTuple(i++, vec);
}
}
else
{
forAll(addPointCellLabels_, api)
{
Type t = interpolatePointToCell(ptf, addPointCellLabels_[api]);
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
pointTypes->InsertTuple(i++, vec);
}
}
vtkMesh->GetPointData()->AddArray(pointTypes);
pointTypes->Delete();
}
template<>
void Foam::vtkFoam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>& psf,
const GeometricField<scalar, fvPatchField, volMesh>& sf
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
vtkFloatArray *pointScalars = vtkFloatArray::New();
pointScalars->SetNumberOfTuples(psf.size() + addPointCellLabels_.size());
pointScalars->SetNumberOfComponents(1);
pointScalars->Allocate(psf.size());
pointScalars->SetName(psf.name().c_str());
for (int i=0; i<psf.size(); i++)
{
pointScalars->InsertComponent(i, 0, psf[i]);
}
label i = psf.size();
if (&sf != &GeometricField<scalar, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
pointScalars->InsertComponent
(
i++,
0,
sf[addPointCellLabels_[api]]
);
}
}
else
{
forAll(addPointCellLabels_, api)
{
pointScalars->InsertComponent
(
i++,
0,
interpolatePointToCell(psf, addPointCellLabels_[api])
);
}
}
vtkMesh->GetPointData()->AddArray(pointScalars);
if (!vtkMesh->GetPointData()->GetScalars())
{
vtkMesh->GetPointData()->SetScalars(pointScalars);
}
pointScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,102 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamConvertVolField_H
#define vtkFoamConvertVolField_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkFoam::convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
vtkFloatArray *cellTypes = vtkFloatArray::New();
cellTypes->SetNumberOfTuples(superCells_.size());
cellTypes->SetNumberOfComponents(Type::nComponents);
cellTypes->Allocate(Type::nComponents*tf.size());
cellTypes->SetName(tf.name().c_str());
float vec[Type::nComponents];
forAll(superCells_, sci)
{
const Type& t = tf[superCells_[sci]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
cellTypes->InsertTuple(sci, vec);
}
vtkMesh->GetCellData()->AddArray(cellTypes);
cellTypes->Delete();
}
template<>
void Foam::vtkFoam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf
)
{
vtkUnstructuredGrid *vtkMesh =
vtkUnstructuredGrid::SafeDownCast(reader_->GetOutput(0));
vtkFloatArray *cellScalars = vtkFloatArray::New();
cellScalars->SetNumberOfTuples(superCells_.size());
cellScalars->SetNumberOfComponents(1);
cellScalars->Allocate(sf.size());
cellScalars->SetName(sf.name().c_str());
forAll(superCells_, sci)
{
cellScalars->InsertComponent(sci, 0, sf[superCells_[sci]]);
}
vtkMesh->GetCellData()->AddArray(cellScalars);
if (!vtkMesh->GetCellData()->GetScalars())
{
vtkMesh->GetCellData()->SetScalars(cellScalars);
}
cellScalars->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,49 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2007 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
Foam::vtkFoam
\*---------------------------------------------------------------------------*/
#ifndef vtkFoamInsertNextPoint_H
#define vtkFoamInsertNextPoint_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline void vtkFoamInsertNextPoint
(
vtkPoints *points,
const Foam::point& p
)
{
points->InsertNextPoint(p.x(), p.y(), p.z());
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1 @@
wmake libso

View File

@ -0,0 +1,3 @@
libuserd.C
LIB = $(FOAM_LIBBIN)/libuserd-foam

View File

@ -0,0 +1,11 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/browser/lnInclude \
-I$(LIB_SRC)/sampling/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude
LIB_LIBS = \
-lOpenFOAM \
-lfiniteVolume \
-llagrangian \
$(PROJECT_LIBS)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,361 @@
README_1.0_to_2.0
=================
This document exists to help those who already have a working user defined
reader (using the 1.0 API) to change it into the 2.0 API format - if desired.
Note that you do not have to update your (1.0 API) user defined reader if it
is already working fine for you.
You should consider it if:
- efficieny gains are needed or
- you need access to complex variables or
- you need access to tensor variables or
- you need multiple timeset capability or
- you want to provide your own "border" elements (as opposed to EnSight's
computation of them)
As an indication of the differences that might be realized in efficency,
consider the following comparison on an unstructured model consisting of:
1,639,058 nodes
7,079,211 elements 240530 tria3
3984 quad4
5927663 tetra4
653 pyramid5
906381 penta6
12 parts
The same model was represented in EnSight6 and EnSight Gold format.
EnSight6 format into: EnSight Gold format into:
------------------------------------ -------------------------
EnSight7.1 |Ensight7.2 |Ensight 7.1 |EnSight7.2 |Ensight7.2
internal |internal |userd reader |internal |userd reader
reader |reader |(API 1.0) |reader |(API 2.0)
| | | |
Time | Mem |Time | Mem |Time | Mem |Time | Mem |Time | Mem
(sec)| (Mb) |(sec)| (Mb) |(sec)| (Mb) |(sec)| (Mb) |(sec)| (Mb)
----------- |----------- |----------- |----------- |-----------
@ part 4.3 27.6 | 3.5 28.4 | 4.0 27.6 | 3.3 8.8 | 3.3 8.9
loader | | | |
| | | |
after 14.0 243.4 |12.8 244.3 |49.8 475.8 | 6.0 211.5 | 6.2 211.6
loading all | | | |
12 parts | | | |
(non-visual) | | | |
| | | |
after 16.8 263.2 |16.0 264.2 |52.8 490.7 | 9.1 236.2 | 9.5 236.2
activate of | | | |
a vector. | | | |
^ ^
/|\ /|\
| |
| |
| |
Compare these two!
Significant is the inefficiency of the 1.0 API, and the fact that the
2.0 API has the same improved efficiency (both in speed and memory) as
the gold internal reader!
Note: Structured data will not show much difference between the two API's,
but it was more efficient initially.
=========================================================
A note on philosophical differences between the two API's:
=========================================================
API 1.0 deals with:
-------------------
-> global coordinate array & corresponding
-> global node id array
-> global nodal variables
-> for each part:
-> local element connectivities (grouped by type) & corresponding
-> local element ids
-> local elemental variables
The element connectivities, within parts, reference the global coordinate
array. If node ids are provided, the element connectivities have to be in
terms of the node ids. If node ids are not provided, the connectivities are in
terms of the (one-based) index number of each node in the global coordinate
array. Thus, node ids are more than labels - they are a part of the
connectivity referencing scheme. Element ids are purely labels.
This API was originally setup to try to make the interface to other codes as
straightforward as possible. Efficiency was not the major consideration.
EnSight must do a fair amount of work to get data provided in the manner
described above into the form that it uses internally. There is mapping that
has to be setup and maintained between the global arrays and the local part
arrays so that updating over time can be accomplished efficiently. There is
hashing that is required in order to deal efficently with node ids.
All of this leads to a considerable amount of temporary memory and processing,
in order to get a model read into EnSight.
API 2.0 deals with:
-------------------
-> for each part:
-> part coordinates & corresponding
-> part node ids
-> part nodal variables
-> part element connectivities (grouped by type) & corresponding
-> part element ids
-> part elemental variables
API 2.0 requires that the coordinates and corresponding nodal variables be
provided per part. This eliminates the global to local mapping with all its
associated temporary memory and processing time. The connectivity of the
elements in each part reference the node indicies of its own (one-based) part
coordinate array. The connectivity of the elements do not reference the nodes
according to node ids. Node ids (and element ids for that matter) are purely
labels for screen display and for query operations within EnSight. This
eliminates the need for node id hashing as a model is read.
The 2.0 API has been created for those needing more efficiency - both in terms
of memory use and speed. The increased efficiency is possible because data is
requested in a manner which more closely represents the way that EnSight
stores and manipulates information internally. The new API requests size
information and allocates the actual internal structures and arrays
accordingly. Pointers to these arrays are passed directly to you in the
routines which gather data, thus eliminating a considerable amount of
temporary memory (and allocation time) that is needed in the old
API. Depending on what you must do to get your data into the form required,
the memory savings and the speed improvement when loading models can be quite
significant!!
Additionally, the ability to handle tensor and complex variables has been
added to the new API, and support for multiple timesets is provided.
------------------------------------------------
So, with that said, if you determine that you want to convert your existing
reader to the new API format, The following may be helpful.
====================
First the Good News! The following routines are identical in both API's!!
==================== ----------------------------------------------------
USERD_bkup
USERD_get_block_coords_by_component
USERD_get_block_iblanking
USERD_get_changing_geometry_status
USERD_get_dataset_query_file_info
USERD_get_element_label_status
USERD_get_name_of_reader
USERD_get_node_label_status
USERD_get_number_of_files_in_dataset
USERD_get_number_of_model_parts
USERD_get_number_of_variables
USERD_set_filenames
USERD_stop_part_building
========================
Second, pretty Good News! The following routines have minor changes,
======================== namely a slight name change and the addition
of arguments related to complex data, constant
(Note, the name changes type, or self contained parts vs global coords.
are needed so both
API's can exist together) The arguments must be added, but depending on
your situation, many might simply be place
holders.
-------------------------------------------------------------------------------
-----------------------------------------------------
A) Changes related to imaginary flag for complex data
=====================================================
If you don't deal with complex variables, simply add
this flag to your argument list and ignore its value.
-----------------------------------------------------
API 1.0 API 2.0
------- -------
USERD_get_constant_value USERD_get_constant_val
( (
int which var int which_var,
int imag_data
) )
USERD_get_description_lines USERD_get_descrip_lines
( (
int which_type, int which_type,
int which_var, int which_var,
int imag_data,
char line1[Z_BUFL], char line1[Z_BUFL],
char line2[Z_BUFL] char line2[Z_BUFL]
) )
USERD_get_variable_value_at_specific USERD_get_var_value_at_specific
( (
int which_var, int which_var,
int which_node_or_elem, int which_node_or_elem,
int which_part, int which_part,
int which_elem_type, int which_elem_type,
int time_step, int time_step,
float values[3] float values[3],
int imag_data
) )
---------------------------------------------------------
B) Changes related to complex data info, and constant type
(and some of the multiple timeset support)
=========================================================
If you don't deal with complex variables, simply add the
arguments for var_complex, var_ifilename, and var_freq
and assign var_complex to be FALSE.
The argument var_contran needs to be added, and set
appropriately if you have constant variables, to indicate
if the constant variable is fixed for all time or varies
over time.
The argument var_timeset needs to be added, and set
appropriately.
---------------------------------------------------------
API 1.0 API 2.0
------- -------
USERD_get_variable_info USERD_get_gold_variable_info
( (
char **var_description, char **var_description,
char **var_filename, char **var_filename,
int *var_type, int *var_type,
int *var_classify int *var_classify,
int *var_complex,
char **var_ifilename,
float *var_freq,
int *var_contran,
int *var_timeset
) )
------------------------------------------------------
C) Changes related to self contained part coordinates
======================================================
The number_of_nodes argument needs to be added and
set for each part. This one is critical for you to do.
------------------------------------------------------
API 1.0 API 2.0
------- -------
USERD_get_part_build_info USERD_get_gold_part_build_info
( (
int *part_numbers, int *part_types,
int *part_types, int *part_types,
char *part_description[Z_BUFL], char *part_description[Z_BUFL],
int *number_of_nodes,
int *number_of_elements[Z_MAXTYPE], int *number_of_elements[Z_MAXTYPE],
int *ijk_dimensions[3], int *ijk_dimensions[3],
int *iblanking_options[6] int *iblanking_options[6]
) )
------------------------------------------------------
D) Changes related to multiple timeset support
======================================================
The timeset_number argument needs to be added for the
following three routines.
The multiple timeset support also includes the change
in B) above for USERD_get_gold_variable_info and the
last three new routines in the third section of this
readme file.
------------------------------------------------------
API 1.0 API 2.0
------- -------
USERD_get_number_of_time_steps USERD_get_num_of_time_steps
( (
void int timeset_number
) )
USERD_get_solution_times USERD_get_sol_times
( (
int timeset_number,
float *solution_times float *solution_times
) )
USERD_set_time_step USERD_set_time_set_and_step
( (
int timeset_number,
int time_step int time_step
) )
------------------------------------------------------
E) Changes related to global_extern.h
======================================================
Be sure to include the updated global_extern.h file that comes
with the EnSight 7.2 release (not the one from previous releases).
=================================================================
Third, deleted and new routines. (Here is where the work lies)
Several old routines are gone. You will have to create the new
routines that replace them. I think you will find in most cases
that your old routines will form the basis of the new routines,
and that it isn't too difficult to provide the information in
the new way.
The detailed specifications for these new routines can be found
in README_USERD_2.0 (or the headers in libuserd.c of the
dummy_gold or ensight_gold readers).
=================================================================
API 1.0 API 2.0
------- -------
These routines: replaced by the single routine:
--------------------------- -------------------------------
USERD_get_block_scalar_values USERD_get_var_by_component
USERD_get_block_vector_values_by_component
USERD_get_scalar_values
USERD_get_vector_values
These global coordinate routines: replaced by part coord routines:
--------------------------------- --------------------------------
USERD_get_global_coords USERD_get_part_coords
USERD_get_global_node_ids USERD_get_part_node_ids
USERD_get_number_of_global_nodes
These part connectivity routines: replaced by part by type routines:
--------------------------------- ----------------------------------
USERD_get_element_connectivities_for_part USERD_get_part_elements_by_type
USERD_get_element_ids_for_part USERD_get_part_element_ids_by_type
These are New Routines
----------------------
(Can be a dummy) -> USERD_exit_routine
(Can be a dummy) -> USERD_get_model_extents
(Required) -> USERD_get_reader_version
multiple timeset releated:
(Required) -> USERD_get_number_timesets
(Required) -> USERD_get_timeset_description
(Required) -> USERD_get_geom_timeset_number
border provided by the reader option:
(Required) -> USERD_get_border_availability
(Can be a dummy) -> USERD_get_border_elements_by_type
transient model allocation efficency:
(Can be a dummy) -> USERD_get_maxsize_info
Possible use with Server-of-Servers:
(Can be a dummy) -> USERD_set_server_number

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,14 @@
//======================================================================
// backup is not implemented
//======================================================================
int USERD_bkup
(
FILE *archive_file,
int backup_type)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_bkup" << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,13 @@
// Do nothing
void USERD_exit_routine
(
void
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_exit_routine" << endl
<< flush;
#endif
}

View File

@ -0,0 +1,17 @@
// Not used
int USERD_get_border_availability
(
int part_number,
int number_of_elements[Z_MAXTYPE]
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_border_availability for part_number "
<< part_number << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,19 @@
// Not called if USERD_border_availability returns Z_ERR
int USERD_get_border_elements_by_type
(
int part_number,
int element_type,
int **conn_array,
short *parent_element_type,
int *parnet_element_type
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_border_elements_by_type" << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,11 @@
//======================================================================
int USERD_get_changing_geometry_status(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_changing_geometry_status" << endl << flush;
#endif
// Choose the most general option
return Z_CHANGE_CONN;
}

View File

@ -0,0 +1,15 @@
//======================================================================
// Not in use
//======================================================================
float USERD_get_constant_val
(
int which_var,
int imag_data
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_constant_val" << endl << flush;
#endif
return 0.0;
}

View File

@ -0,0 +1,8 @@
//======================================================================
// NOT SUPPORTED... yet, if ever!
//======================================================================
int USERD_get_dataset_query_file_info(Z_QFILES *qfiles)
{
// just return OK
return Z_OK;
}

View File

@ -0,0 +1,32 @@
//======================================================================
int USERD_get_descrip_lines
(
int which_type,
int which_var,
int imag_data,
char line1[Z_BUFL],
char line2[Z_BUFL]
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_descrip_lines" << endl
<< flush;
#endif
if (which_type == Z_GEOM)
{
strncpy(line1, meshName, Z_BUFL);
strncpy(line2, "", Z_BUFL);
}
else
{
strncpy(line1, "WHERE IS THIS LINE USED I WONDER???", Z_BUFL);
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_descrip_lines" << endl
<< flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,11 @@
//======================================================================
// if TRUE: set in USERD_get_element_ids_for_part
//======================================================================
int USERD_get_element_label_status(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_element_label_status" << endl << flush;
#endif
return TRUE;
}

View File

@ -0,0 +1,14 @@
int USERD_get_geom_timeset_number
(
void
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_geom_timeset_number" << endl
<< flush;
#endif
Geom_timeset_number = 1;
return Geom_timeset_number;
}

View File

@ -0,0 +1,151 @@
//======================================================================
// this is based on the current time step.
//======================================================================
int USERD_get_gold_part_build_info
(
int *part_numbers,
int *part_types,
char *part_descriptions[Z_BUFL],
int *number_of_nodes,
int *number_of_elements[Z_MAXTYPE],
int *ijk_dimensions[3],
int *iblanking_options[6]
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_gold_part_build_info" << endl << flush;
#endif
//# include "checkForNewMesh.H"
const cellShapeList& cellShapes = meshPtr->cellShapes();
const cellList& cells = meshPtr->cells();
label nCells = cells.size();
// all parts are unstructured
for (label n = 0; n<Numparts_available; n++)
{
part_numbers[n] = n + 1;
part_types[n] = Z_UNSTRUCTURED;
}
strncpy(part_descriptions[0], meshName, Z_BUFL);
for(label i=0; i<nPatches; i++)
{
word patchName(meshPtr->boundary()[i].name());
strncpy(part_descriptions[i+1], patchName.c_str(), Z_BUFL);
}
label nHex08 = 0;
label nPen06 = 0;
label nPyr05 = 0;
label nTet04 = 0;
label nFaced = 0;
for (label n=0; n<nCells; n++)
{
label nFacesInCell = cells[n].size();
labelList points = cellShapes[n];
if ((nFacesInCell == 6) && (points.size() == 8))
{
nHex08++;
}
else if ((nFacesInCell == 4) && (points.size() == 4))
{
nTet04++;
}
else if (nFacesInCell == 5)
{
if (points.size() == 6)
{
nPen06++;
}
else if (points.size() == 5)
{
nPyr05++;
}
else
{
nFaced++;
}
}
else
{
nFaced++;
}
}
for (label n=0; n < Z_MAXTYPE; n++)
{
for (label i=0; i<Numparts_available; i++)
{
number_of_elements[i][n] = 0;
}
}
number_of_elements[0][Z_TET04] = nTet04;
number_of_elements[0][Z_PYR05] = nPyr05;
number_of_elements[0][Z_HEX08] = nHex08;
number_of_elements[0][Z_PEN06] = nPen06;
number_of_elements[0][Z_NFACED] = nFaced;
/*
Info << "nTet04 = " << nTet04 << endl;
Info << "nPyr05 = " << nPyr05 << endl;
Info << "nHex08 = " << nHex08 << endl;
Info << "nPen06 = " << nPen06 << endl;
Info << "nFaced = " << nFaced << endl;
*/
number_of_nodes[0] = meshPtr->nPoints();
const polyBoundaryMesh& bMesh = meshPtr->boundaryMesh();
for(label i=0; i<nPatches; i++)
{
label nTri03 = 0;
label nQuad04 = 0;
label nPoly = 0;
forAll(bMesh[i], n)
{
label nPoints = bMesh[i][n].size();
if (nPoints == 3)
{
nTri03++;
}
else if (nPoints == 4)
{
nQuad04++;
}
else
{
nPoly++;
}
}
number_of_elements[i+1][Z_TRI03] = nTri03;
number_of_elements[i+1][Z_QUA04] = nQuad04;
number_of_elements[i+1][Z_NSIDED] = nPoly;
number_of_nodes[i+1] = bMesh[i].points().size();
}
if (Numparts_available > nPatches+1)
{
strncpy(part_descriptions[nPatches+1], sprayName.c_str(), Z_BUFL);
number_of_elements[nPatches+1][Z_POINT] = sprayPtr->size();
number_of_nodes[nPatches+1] = sprayPtr->size();
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_gold_part_build_info" << endl << flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,123 @@
//======================================================================
// variable 1 - var[0] , i.e variables are zero based
//======================================================================
int USERD_get_gold_variable_info
(
char **var_description,
char **var_filename,
int *var_type,
int *var_classify,
int *var_complex,
char **var_ifilename,
float *var_freq,
int *var_contran,
int *var_timeset
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_gold_variable_info" << endl
<< flush;
#endif
label offset = Num_variables - nSprayVariables;
// scalars first ...
for (label n=0; n<offset; n++)
{
if (isScalar[var2field[n]])
{
var_type[n] = Z_SCALAR;
var_classify[n] = Z_PER_ELEM;
var_complex[n] = FALSE;
var_timeset[n] = 1;
strncpy
(
var_description[n],
fieldNames[var2field[n]].c_str(),
Z_BUFL
);
}
}
// ... and then vectors
for (label n=0; n<offset; n++)
{
if (isVector[var2field[n]])
{
var_type[n] = Z_VECTOR;
var_classify[n] = Z_PER_ELEM;
var_complex[n] = FALSE;
var_timeset[n] = 1;
strncpy
(
var_description[n],
fieldNames[var2field[n]].c_str(),
Z_BUFL
);
}
}
// ... and tensors (NB! all tensors are treated as asymmetric)
for (label n=0; n<offset; n++)
{
if (isTensor[var2field[n]])
{
var_type[n] = Z_TENSOR9;
var_classify[n] = Z_PER_ELEM;
var_complex[n] = FALSE;
var_timeset[n] = 1;
strncpy
(
var_description[n],
fieldNames[var2field[n]].c_str(),
Z_BUFL
);
}
}
if (Numparts_available > nPatches+1)
{
label Ns = lagrangianScalarNames.size();
for (label n=0; n<Ns; n++)
{
var_type[offset + n] = Z_SCALAR;
var_classify[offset + n] = Z_PER_ELEM;
var_complex[offset + n] = FALSE;
var_timeset[offset + n] = 1;
word name = parcelPrepend + lagrangianScalarNames[n];
strncpy
(
var_description[offset + n],
name.c_str(),
Z_BUFL
);
}
for (label n=0; n<lagrangianVectorNames.size(); n++)
{
var_type[offset + Ns + n] = Z_VECTOR;
var_classify[offset + Ns + n] = Z_PER_ELEM;
var_complex[offset + Ns + n] = FALSE;
var_timeset[offset + Ns + n] = 1;
word name = parcelPrepend + lagrangianVectorNames[n];
strncpy
(
var_description[offset + Ns + n],
name.c_str(),
Z_BUFL
);
}
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_gold_variable_info" << endl
<< flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,14 @@
int USERD_get_matf_set_info
(
int *mat_set_ids,
char **mat_set_name
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_matf_set_info" << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,15 @@
int USERD_get_matf_var_info
(
int set_index,
int *mat_ids,
char **mat_desc
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_matf_var_info" << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,104 @@
int USERD_get_maxsize_info
(
int *max_number_of_nodes,
int *max_number_of_elements[Z_MAXTYPE],
int *max_ijk_dimensions[3]
)
{
return Z_ERR;
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_maxsize_info" << endl << flush;
#endif
label maxNPoints = 0;
label maxNParcels = 0;
label nPen06Max = 0;
label nHex08Max = 0;
label nPyr05Max = 0;
label nTet04Max = 0;
Info << "Checking all time steps for EnSight memory allocation purpose. This can take some time." << endl;
for (label t=1; t < TimeList.size(); t++)
{
label nPen06 = 0;
label nHex08 = 0;
label nPyr05 = 0;
label nTet04 = 0;
runTimePtr->setTime(TimeList[t], t);
Info << "Checking time = " << TimeList[t].value() << endl << flush;
const cellShapeList& cells = meshPtr->cellShapes();
label nPoints = meshPtr->nPoints();
label nCells = cells.size();
maxNPoints = max(maxNPoints, nPoints);
for (label n=0; n<nCells;n++)
{
label nFaces = cells[n].nFaces();
labelList points = cells[n];
if ((nFaces == 6) && (points.size() == 8))
{
nHex08++;
}
else if ((nFaces == 5) && (points.size() == 6))
{
nPen06++;
}
else if ((nFaces == 5) && (points.size() == 5))
{
nPyr05++;
}
else if ((nFaces == 4) && (points.size() == 4))
{
nTet04++;
}
}
nPen06Max = max(nPen06Max, nPen06);
nHex08Max = max(nHex08Max, nHex08);
nPyr05Max = max(nPyr05Max, nPyr05);
nTet04Max = max(nTet04Max, nTet04);
if (Numparts_available > 1)
{
// Get the maximum number of spray parcels
// and store it
Cloud<passiveParticle> lagrangian(*meshPtr);
if (lagrangian.size() > nMaxParcels)
{
nMaxParcels = lagrangian.size();
}
}
}
max_number_of_nodes[0] = maxNPoints;
max_number_of_elements[0][Z_HEX08] = nHex08Max;
max_number_of_elements[0][Z_PEN06] = nPen06Max;
max_number_of_elements[0][Z_PYR05] = nPyr05Max;
max_number_of_elements[0][Z_TET04] = nTet04Max;
if (Numparts_available > 1)
{
max_number_of_nodes[1] = maxNParcels;
max_number_of_elements[1][Z_POINT] = maxNParcels;
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_maxsize_info" << endl << flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,15 @@
// Not used. Let EnSight do the job.
int USERD_get_model_extents
(
float extents[6]
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_model_extents" << endl
<< flush;
#endif
return Z_ERR;
}

View File

@ -0,0 +1,18 @@
//======================================================================
// Setting name in the gui, and specifying one or two input fields
//======================================================================
int USERD_get_name_of_reader
(
char reader_name[Z_MAX_USERD_NAME],
int *two_fields
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_name_of_reader" << endl << flush;
#endif
strncpy(reader_name, readerName, Z_MAX_USERD_NAME);
*two_fields = FALSE;
return Z_OK;
}

View File

@ -0,0 +1,79 @@
int USERD_get_nfaced_conn
(
int part_number,
int *nfaced_conn_array
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_nfaced_conn"
<< ", part_number = " << part_number
<< endl
<< flush;
#endif
if (part_number == 1)
{
label nPoint = 0;
const cellShapeList& cellShapes = meshPtr->cellShapes();
const cellList& cells = meshPtr->cells();
const faceList& faces = meshPtr->faces();
label nCells = cellShapes.size();
for (label n=0; n<nCells; n++)
{
label nFacesInCell = cells[n].size();
labelList points = cellShapes[n];
if ((nFacesInCell == 6) && (points.size() == 8))
{}
else if ((nFacesInCell == 4) && (points.size() == 4))
{}
else if (nFacesInCell == 5)
{
if (points.size() == 6)
{}
else if (points.size() == 5)
{}
else
{
for(label i=0; i<nFacesInCell; i++)
{
label facei = cells[n][i];
label nPoints = faces[facei].size();
for(label j=0; j<nPoints; j++)
{
nfaced_conn_array[nPoint++] = faces[facei][j] + 1;
}
}
}
}
else
{
for(label i=0; i<nFacesInCell; i++)
{
label facei = cells[n][i];
label nPoints = faces[facei].size();
for(label j=0; j<nPoints; j++)
{
nfaced_conn_array[nPoint++] = faces[facei][j] + 1;
}
}
}
}
}
else if (part_number < nPatches+2)
{
}
else
{
return Z_ERR;
}
#ifdef ENSIGHTDEBUG
Info << "Exiting: USERD_get_nfaced_conn" << endl
<< flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,74 @@
int USERD_get_nfaced_nodes_per_face
(
int part_number,
int *nfaced_npf_array
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_nfaced_nodes_per_face"
<< ", part_number = " << part_number
<< endl
<< flush;
#endif
if (part_number == 1)
{
const cellShapeList& cellShapes = meshPtr->cellShapes();
const cellList& cells = meshPtr->cells();
const faceList& faces = meshPtr->faces();
label nCells = cellShapes.size();
label nFaced = 0;
for (label n=0; n<nCells; n++)
{
label nFacesInCell = cells[n].size();
labelList points = cellShapes[n];
label nPoints = points.size();
if ((nFacesInCell == 6) && (nPoints == 8))
{}
else if ((nFacesInCell == 4) && (nPoints == 4))
{}
else if (nFacesInCell == 5)
{
if (nPoints == 6)
{}
else if (nPoints == 5)
{}
else
{
for(label i=0; i<nFacesInCell; i++)
{
label facei = cells[n][i];
label nFacePoints = faces[facei].size();
nfaced_npf_array[nFaced++] = nFacePoints;
}
}
}
else
{
for(label i=0; i<nFacesInCell; i++)
{
label facei = cells[n][i];
label nFacePoints = faces[facei].size();
nfaced_npf_array[nFaced++] = nFacePoints;
}
}
}
}
else if (part_number < nPatches+2)
{
return Z_ERR;
}
else
{
return Z_ERR;
}
#ifdef ENSIGHTDEBUG
Info << "Exiting: USERD_get_nfaced_nodes_per_face" << endl
<< flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,12 @@
//======================================================================
// if TRUE: set in USERD_get_global_node_ids
//======================================================================
int USERD_get_node_label_status(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_node_label_status" << endl << flush;
#endif
return TRUE;
}

View File

@ -0,0 +1,49 @@
int USERD_get_nsided_conn
(
int part_number,
int *nsided_conn_array
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_nsided_conn"
<< ", part_number = " << part_number
<< endl
<< flush;
#endif
if (part_number == 1)
{
Info << "************* EEEEEEEEERRRRRRRRRRRRRRRRRR *************** " << endl << flush;
}
else if (part_number < nPatches+2)
{
//const cellList& cells = meshPtr->cells();
//const faceList& faces = meshPtr->faces();
label patchi = part_number - 2;
const polyBoundaryMesh& bMesh = meshPtr->boundaryMesh();
label np = 0;
forAll(bMesh[patchi], facei)
{
label nPoints = bMesh[patchi][facei].size();
if ((nPoints != 3) && (nPoints != 4))
{
for(label i=0; i<nPoints; i++)
{
nsided_conn_array[np++] = bMesh[patchi][facei][i] + 1;
}
}
}
}
else if (part_number == nPatches+2)
{
return Z_ERR;
}
#ifdef ENSIGHTDEBUG
Info << "Exiting: USERD_get_nsided_conn" << endl
<< flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,15 @@
//======================================================================
// don't use multiple time sets...NN
//======================================================================
int USERD_get_num_of_time_steps
(
int timeset_number
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_num_of_time_steps" << endl
<< flush;
#endif
return Num_time_steps;
}

View File

@ -0,0 +1,13 @@
//======================================================================
//
//======================================================================
int USERD_get_number_of_files_in_dataset(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_files_in_dataset" << endl << flush;
#endif
// use 1 insted of 0 which gives an un-necessary warning.
Num_dataset_files = 1;
return Num_dataset_files;;
}

View File

@ -0,0 +1,14 @@
int USERD_get_number_of_material_sets
(
void
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_material_sets" << endl
<< flush;
#endif
// No materials
return 0;
}

View File

@ -0,0 +1,14 @@
int USERD_get_number_of_materials
(
int set_index
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_materials" << endl
<< flush;
#endif
// No materials
return 0;
}

View File

@ -0,0 +1,9 @@
int USERD_get_number_of_model_parts(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_model_parts" << endl << flush;
#endif
return Numparts_available;
}

View File

@ -0,0 +1,9 @@
//======================================================================
int USERD_get_number_of_variables(void)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_variables" << endl << flush;
#endif
return Num_variables;
}

View File

@ -0,0 +1,13 @@
int USERD_get_number_of_timesets
(
void
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_number_of_timesets" << endl
<< flush;
#endif
Num_timesets = 1;
return Num_timesets;
}

View File

@ -0,0 +1,77 @@
// Note: coord_array is 1-based.
int USERD_get_part_coords
(
int part_number,
float **coord_array
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_part_coords" << endl <<
"part_number = " << part_number << endl << flush;
#endif
if (part_number == 1)
{
//# include "checkForNewMesh.H"
const vectorField& points = meshPtr->points();
label nPoints = points.size();
for (label indx=0; indx<nPoints; indx++)
{
coord_array[0][indx+1] = (float)points[indx].x();
coord_array[1][indx+1] = (float)points[indx].y();
coord_array[2][indx+1] = (float)points[indx].z();
}
}
else if (part_number < nPatches+2)
{
//# include "checkForNewMesh.H"
label patchi = part_number-2;
const polyBoundaryMesh& bMesh = meshPtr->boundaryMesh();
const vectorField& points = bMesh[patchi].points();
label nPoints = points.size();
for (label indx=0; indx<nPoints; indx++)
{
coord_array[0][indx+1] = (float)points[indx].x();
coord_array[1][indx+1] = (float)points[indx].y();
coord_array[2][indx+1] = (float)points[indx].z();
}
}
else if (part_number == nPatches+2)
{
label indx = 1;
for
(
Cloud<passiveParticle>::iterator elmnt = sprayPtr->begin();
elmnt != sprayPtr->end();
++elmnt
)
{
coord_array[0][indx] = (float)elmnt().position().x();
coord_array[1][indx] = (float)elmnt().position().y();
coord_array[2][indx] = (float)elmnt().position().z();
indx++;
}
}
else
{
return Z_ERR;
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_part_coords" << endl << flush;
#endif
return Z_OK;
}

View File

@ -0,0 +1,162 @@
int USERD_get_part_element_ids_by_type
(
int part_number,
int element_type,
int *elemid_array
)
{
#ifdef ENSIGHTDEBUG
Info << "Entering: USERD_get_part_element_ids_by_type" << endl
<< "part_number = " << part_number << endl
<< "element_type = " << element_type << endl << flush;
#endif
if (part_number == 1)
{
const cellShapeList& cellShapes = meshPtr->cellShapes();
const cellList& cells = meshPtr->cells();
label nCells = cells.size();
label nPen06 = 0;
label nHex08 = 0;
label nPyr05 = 0;
label nTet04 = 0;
label nFaced = 0;
if (element_type == Z_HEX08)
{
for (label n=0; n<nCells; n++)
{
label nFaces = cells[n].size();
labelList points = cellShapes[n];
if ((nFaces == 6) && (points.size() == 8))
{
elemid_array[nHex08++] = n + 1;
}
}
}
else if (element_type == Z_PEN06)
{
for (label n=0; n<nCells; n++)
{
label nFaces = cells[n].size();
labelList points = cellShapes[n];
if ((nFaces == 5) && (points.size() == 6))
{
elemid_array[nPen06++] = n + 1;
}
}
}
else if (element_type == Z_PYR05)
{
for (label n=0; n<nCells; n++)
{
label nFaces = cells[n].size();
labelList points = cellShapes[n];
if ((nFaces == 5) && (points.size() == 5))
{
elemid_array[nPyr05++] = n + 1;
}
}
}
else if (element_type == Z_TET04)
{
for (label n=0; n<nCells; n++)
{
label nFaces = cells[n].size();
labelList points = cellShapes[n];
if ((nFaces == 4) && (points.size() == 4))
{
elemid_array[nTet04++] = n + 1;
}
}
}
else if (element_type == Z_NFACED)
{
for (label n=0; n<nCells; n++)
{
label nFaces = cells[n].size();
labelList points = cellShapes[n];
if ((nFaces == 6) && (points.size() == 8))
{}
else if ((nFaces == 5) && (points.size() == 6))
{}
else if ((nFaces == 5) && (points.size() == 5))
{}
else if ((nFaces == 4) && (points.size() == 4))
{}
else
{
elemid_array[nFaced++] = n + 1;
}
}
}
}
else if (part_number < nPatches+2)
{
const polyBoundaryMesh& bMesh = meshPtr->boundaryMesh();
label patchi = part_number - 2;
label nTri03 = 0;
label nQuad04 = 0;
label nPoly = 0;
if (element_type == Z_TRI03)
{
forAll(bMesh[patchi], facei)
{
if (bMesh[patchi][facei].size() == 3)
{
elemid_array[nTri03++] = facei + 1;
}
}
}
else if (element_type == Z_QUA04)
{
forAll(bMesh[patchi], facei)
{
if (bMesh[patchi][facei].size() == 4)
{
elemid_array[nQuad04++] = facei + 1;
}
}
}
else if (element_type == Z_NSIDED)
{
forAll(bMesh[patchi], facei)
{
label nPoints = bMesh[patchi][facei].size();
if ((nPoints != 3) && (nPoints != 4))
{
elemid_array[nPoly++] = facei + 1;
}
}
}
}
else if (part_number == nPatches+2)
{
for (label n=0; n<sprayPtr->size(); n++)
{
elemid_array[n] = n + 1;
}
}
else
{
return Z_ERR;
}
#ifdef ENSIGHTDEBUG
Info << "Leaving: USERD_get_part_element_ids_by_type" << endl << flush;
#endif
return Z_OK;
}

Some files were not shown because too many files have changed in this diff Show More