checkin paraview3.3 reader as 'work-in-progress'

This commit is contained in:
Mark Olesen
2008-05-08 15:20:57 +02:00
parent 86c5794294
commit 6179a6fd5a
32 changed files with 6970 additions and 0 deletions

View File

@ -0,0 +1,18 @@
#!/bin/sh
set -x
if [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ]
then
case "$ParaView_VERSION" in
3*)
wmake libso vtkPV3Foam
(
cd PV3FoamReader
mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
cd Make/$WM_OPTIONS
cmake ../..
make
)
;;
esac
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">
</Reader>
</ParaViewReaders>

View File

@ -0,0 +1,261 @@
<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>
<!-- ExtrapolateWalls check box -->
<IntVectorProperty
name="ExtrapolateWalls"
command="SetExtrapolateWalls"
number_of_elements="1"
default_values="0">
<BooleanDomain
name="bool"/>
</IntVectorProperty>
<!-- Include sets check box -->
<IntVectorProperty
name="IncludeSets / Zones"
command="SetIncludeSets"
number_of_elements="1"
default_values="0">
<BooleanDomain
name="bool"/>
</IntVectorProperty>
<!-- Include zones check box -->
<IntVectorProperty
name="IncludeZones"
command="SetIncludeZones"
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 -->
<!-- OLESEN
<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 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>
<!-- 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>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,748 @@
/*=========================================================================
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"
#include "vtkAlgorithmOutput.h"
#include "vtkMultiBlockDataSet.h"
// Foam includes
#include "vtkPV3Foam.H"
vtkCxxRevisionMacro(vtkPV3FoamReader, "$Revision: 1.2$");
vtkStandardNewMacro(vtkPV3FoamReader);
vtkPV3FoamReader::vtkPV3FoamReader()
{
Debug = 0;
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();
RegionSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New();
PointFieldSelection = 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");
cout << "Destroy ~vtkPV3FoamReader\n";
if (foamData_)
{
delete foamData_;
}
if (FileName)
{
delete [] FileName;
}
TimeSelection->RemoveObserver(this->SelectionObserver);
RegionSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver);
LagrangianFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
TimeSelection->Delete();
RegionSelection->Delete();
VolFieldSelection->Delete();
PointFieldSelection->Delete();
LagrangianFieldSelection->Delete();
}
// Do everything except set the output info
int vtkPV3FoamReader::RequestInformation
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestInformation");
cout<<"REQUEST_INFORMATION\n";
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
{
vtkInformation* outputInfo = this->GetOutputPortInformation(0);
outputInfo->Print(cout);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outputInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
if (output)
{
output->Print(cout);
}
else
{
cout << "no output\n";
}
cout << "GetExecutive:\n";
this->GetExecutive()->GetOutputInformation(0)->Print(cout);
}
{
int nInfo = outputVector->GetNumberOfInformationObjects();
cout<<"requestInfo with " << nInfo << " items\n";
for (int i=0; i<nInfo; i++)
{
vtkInformation *info = outputVector->GetInformationObject(i);
info->Print(cout);
}
}
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (!foamData_)
{
vtkDebugMacro("RequestInformation: creating foamData_");
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();
}
int nTimeSteps = 0;
double* timeSteps = foamData_->timeSteps(nTimeSteps);
cout<<"Have nTimeSteps: " << nTimeSteps << "\n";
outInfo->Set
(
vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
timeSteps,
nTimeSteps
);
double timeRange[2];
if (nTimeSteps)
{
timeRange[0] = timeSteps[0];
timeRange[1] = timeSteps[nTimeSteps-1];
cout<<"nTimeSteps " << nTimeSteps << "\n";
cout<<"timeRange " << timeRange[0] << " -> " << timeRange[1] << "\n";
// for (int i = 0; i < nTimeSteps; ++i)
// {
// cout<<"step[" << i << "] = " << timeSteps[i] << "\n";
// }
outInfo->Set
(
vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
timeRange,
2
);
}
delete timeSteps;
cout<<"done RequestInformation\n";
return 1;
}
// Set the output info
int vtkPV3FoamReader::RequestData
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestData");
cout<<"REQUEST_DATA\n";
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
{
int nInfo = outputVector->GetNumberOfInformationObjects();
cout<<"requestData with " << nInfo << " items\n";
for (int i=0; i<nInfo; i++)
{
vtkInformation *info = outputVector->GetInformationObject(i);
info->Print(cout);
}
}
vtkInformation* outInfo = outputVector->GetInformationObject(0);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
#if 1
{
vtkInformation* outputInfo = this->GetOutputPortInformation(0);
outputInfo->Print(cout);
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outputInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
if (output)
{
output->Print(cout);
}
else
{
cout << "no output\n";
}
vtkInformation* execInfo = this->GetExecutive()->GetOutputInformation(0);
execInfo->Print(cout);
outInfo->Print(cout);
vtkMultiBlockDataSet* dobj = vtkMultiBlockDataSet::SafeDownCast
(
outInfo->Get(vtkMultiBlockDataSet::DATA_OBJECT())
);
if (dobj)
{
dobj->Print(cout);
vtkInformation* dobjInfo = dobj->GetInformation();
dobjInfo->Print(cout);
}
else
{
cout << "no data_object\n";
}
}
#endif
if (outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS()))
{
cout<<"Has UPDATE_TIME_STEPS\n";
cout<<"output->GetNumberOfBlocks() " << output->GetNumberOfBlocks() <<
"\n";
// Get the requested time step.
// We only supprt requests of a single time step
int nRequestedTimeSteps = outInfo->Length
(
vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS()
);
if (nRequestedTimeSteps >= 1)
{
double *requestedTimeSteps = outInfo->Get
(
vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEPS()
);
foamData_->setTime(requestedTimeSteps[0]);
}
}
if
(
(UpdateGUIOld == GetUpdateGUI())
|| (output->GetNumberOfBlocks() == 0)
)
{
foamData_->Update(output);
if (ShowPatchNames == 1)
{
addPatchNamesToView();
}
else
{
removePatchNamesFromView();
}
}
UpdateGUIOld = GetUpdateGUI();
cout<<"done RequestData\n";
cout<<"done output->GetNumberOfBlocks() "
<< output->GetNumberOfBlocks() << "\n";
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 available time steps: " << foamData_->numberOfAvailableTimes()
<< 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,207 @@
/*=========================================================================
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 extrapolate internal values onto the walls
vtkSetMacro(ExtrapolateWalls, int);
vtkGetMacro(ExtrapolateWalls, int);
// FOAM read sets control
vtkSetMacro(IncludeSets, int);
vtkGetMacro(IncludeSets, int);
// FOAM read zones control
vtkSetMacro(IncludeZones, int);
vtkGetMacro(IncludeZones, 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 ExtrapolateWalls;
int IncludeSets;
int IncludeZones;
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,13 @@
vtkPV3Foam.C
vtkPV3FoamAddVolumeMesh.C
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddFaceZoneMesh.C
vtkPV3FoamAddPointZoneMesh.C
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamUpdate.C
vtkPV3FoamUpdateInformation.C
vtkPV3FoamConvertMesh.C
LIB = $(FOAM_LIBBIN)/libvtkPV3Foam

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,737 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
Provides a reader interface for OpenFOAM to VTK interaction.
SourceFiles
interpolatePointToCell.C
interpolatePointToCell.H
vtkPV3Foam.C
vtkPV3Foam.H
vtkPV3FoamAddFaceSetMesh.C
vtkPV3FoamAddFaceZoneMesh.C
vtkPV3FoamAddFields.H
vtkPV3FoamAddLagrangianMesh.C
vtkPV3FoamAddPatchMesh.C
vtkPV3FoamAddPointSetMesh.C
vtkPV3FoamAddPointZoneMesh.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"
#include "stringList.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
class vtkDataSet;
class vtkMultiBlockDataSet;
class vtkPoints;
class vtkPV3FoamReader;
class vtkRenderer;
class vtkTextActor;
class vtkPolyData;
class vtkUnstructuredGrid;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Foam class forward declarations
class argList;
class Time;
class fvMesh;
class IOobjectList;
class polyPatch;
class faceSet;
class pointSet;
template<class Type>
class IOField;
template<class Type>
class List;
/*---------------------------------------------------------------------------*\
Class vtkPV3Foam Declaration
\*---------------------------------------------------------------------------*/
class vtkPV3Foam
{
public:
// Public data
//- bookkeeping for the GUI checklists and the multi-block organization
class selectionInfo
{
int block_;
const char *name_;
int start_;
int size_;
public:
selectionInfo(const int blockNo, const char *name)
:
block_(blockNo),
name_(name),
start_(-1),
size_(0)
{}
//- Return the block holding these datasets
const int block() const
{
return block_;
}
const char* name() const
{
return name_;
}
const int start() const
{
return start_;
}
const int end() const
{
return start_ + size_;
}
const int size() const
{
return size_;
}
void reset()
{
start_ = -1;
size_ = 0;
}
//- Assign new start and reset the size
void operator=(const int i)
{
start_ = i;
size_ = 0;
}
//- Increment the size
void operator+=(const int n)
{
size_ += n;
}
};
private:
// Private data
//BTX
//- Indices for datasets in vtkMultiBlockDataSet
enum
{
VOLUME = 0, // internal mesh
PATCHES = 1, // patches
LAGRANGIAN = 2,
CELLZONE = 3,
FACEZONE = 4,
POINTZONE = 5,
CELLSET = 6,
FACESET = 7,
POINTSET = 8
};
//ETX
//- Access to the controlling vtkPV3FoamReader
vtkPV3FoamReader* reader_;
//- Access to the output block
vtkMultiBlockDataSet* output_;
//- Foam time control
autoPtr<Time> dbPtr_;
//- Foam mesh
fvMesh* meshPtr_;
//- First instance and size of various regions
selectionInfo selectInfoVolume_;
selectionInfo selectInfoPatches_;
selectionInfo selectInfoLagrangian_;
selectionInfo selectInfoCellZones_;
selectionInfo selectInfoFaceZones_;
selectionInfo selectInfoPointZones_;
selectionInfo selectInfoCellSets_;
selectionInfo selectInfoFaceSets_;
selectionInfo selectInfoPointSets_;
//- Selected regions
// [0] = internal mesh, then lagrangian, patches, zones, sets
boolList selectedRegions_;
//- Selected regions indices in each respective block
labelList selectedRegionDatasetIds_;
//- Labels of cell-centres used as additional points when decomposing
// polyhedra
labelList addPointCellLabels_;
//- Label of original cell for decomposed cells
// - internal mesh
labelList superCells_;
//- Label of original cell for decomposed cells
// - cell zone meshes
List<labelList> superCellZonesCells_;
//- Label of original cell for decomposed cells
// - 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_;
//- Cloud name to be processed
// TODO - currently only set up to process ONE cloud
word cloudName_;
// Private Member Functions
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static void AddToBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
vtkDataSet* dataset,
const string& blockName = string::null
);
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static vtkDataSet* GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static label GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const selectionInfo&
);
//- Reset data counters
void resetCounters();
//- Get all the available times and select the latestTime
void initializeTime();
// 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();
//- Zone info
void updateInformationZones();
//- 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 zone meshes
void convertMeshCellZones(vtkMultiBlockDataSet* output);
//- Cell zone meshes
void convertMeshFaceZones(vtkMultiBlockDataSet* output);
//- Cell zone meshes
void convertMeshPointZones(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&,
vtkUnstructuredGrid*,
labelList& superCells
);
//- Add Lagrangian mesh
void addLagrangianMesh
(
const fvMesh&,
vtkPolyData*
);
//- Add patch mesh
void addPatchMesh
(
const polyPatch&,
vtkPolyData*
);
//- Add face zone mesh
void addFaceZoneMesh
(
const fvMesh&,
const labelList& faceLabels,
vtkPolyData*
);
//- Add point zone
void addPointZoneMesh
(
const fvMesh&,
const labelList& pointLabels,
vtkPolyData*
);
//- Add cell set mesh
void addCellSetMesh
(
const fvMesh&,
vtkUnstructuredGrid*
);
//- Add face set mesh
void addFaceSetMesh
(
const fvMesh&,
const faceSet&,
vtkPolyData*
);
//- Add point mesh
void addPointSetMesh
(
const fvMesh&,
const pointSet&,
vtkPolyData*
);
//- Add the fields in the selected time directory to the selection
// lists
template<class GeoField>
label addFields
(
vtkDataArraySelection* fieldSelection,
const IOobjectList& objects,
const string& suffix = string::null
);
// Convert Foam fields
//- Volume fields - all types
template<class Type>
void convertVolFields
(
const fvMesh&,
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>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
labelList& superCells
);
//- Patch field
template<class Type>
void convertPatchFaceField
(
const word& name,
const Field<Type>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
//- face set/zone field
template<class Type>
void convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
const fvMesh&,
const labelList& faceLabels
);
//- face set/zone field
template<class Type>
void convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
const fvMesh&,
const faceSet&
);
//- Lagrangian fields - all types
template<class Type>
void convertLagrangianFields
(
const fvMesh&,
const IOobjectList& objects,
vtkDataArraySelection *fieldSelection,
vtkMultiBlockDataSet* output
);
//- Lagrangian field - all types except scalar
template<class Type>
void convertLagrangianField
(
const IOField<Type>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
//- 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,
const selectionInfo&,
const label datasetNo
);
//- Patch point field - all types except scalar
template<class Type>
void convertPatchPointField
(
const word& name,
const Field<Type>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
// GUI selection helper functions
//- Extract up to the first non-word characters
inline static word getFirstWord(const char*);
//- Store the current selection(s)
static stringList getSelectedArrayEntries
(
vtkDataArraySelection* arraySelection,
const bool firstWord = false
);
//- Store the current selection(s) for a sub-selection
static stringList getSelectedArrayEntries
(
vtkDataArraySelection* arraySelection,
const selectionInfo&,
const bool firstWord = false
);
//- Set selection(s)
static void setSelectedArrayEntries
(
vtkDataArraySelection* arraySelection,
const stringList& selectedEntries
);
//- 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);
//- allocate and return a list of selected times
// returns the count via the parameter
double* timeSteps(int& nTimeSteps);
//- Add patch names to the display
void addPatchNames(vtkRenderer* renderer);
//- Remove patch names from the display
void removePatchNames(vtkRenderer* renderer);
//- set the runTime to the requested time
// sets to "constant" on error
bool setTime(const double& requestedTime);
// Access
//- Return the total number of available timesets
int numberOfAvailableTimes() const;
int numberOfCells();
int numberOfPoints();
int numberOfMeshes() const;
};
// * * * * * * * * * * * * * Template Specialisations * * * * * * * * * * * //
template<>
void vtkPV3Foam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
labelList& superCells
);
template<>
void vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<scalar>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
template<>
void vtkPV3Foam::convertFaceField
(
const GeometricField<scalar, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
const fvMesh&,
const labelList& faceLabels
);
template<>
void vtkPV3Foam::convertFaceField
(
const GeometricField<scalar, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo,
const fvMesh&,
const faceSet&
);
template<>
void vtkPV3Foam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>&,
const GeometricField<scalar, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
template<>
void vtkPV3Foam::convertPatchPointField
(
const word& name,
const Field<scalar>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
template<>
void vtkPV3Foam::convertLagrangianField
(
const IOField<scalar>&,
vtkMultiBlockDataSet* output,
const selectionInfo&,
const label datasetNo
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "vtkPV3FoamI.H"
#endif
// ************************************************************************* //

View File

@ -0,0 +1,101 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "vtkPolyData.h"
#include "vtkCellArray.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addFaceSetMesh
(
const fvMesh& mesh,
const faceSet& fSet,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "entered add face set internal mesh" << endl;
}
// Construct primitivePatch of faces in fSet.
const faceList& meshFaces = mesh.faces();
faceList patchFaces(fSet.size());
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
patchFaces[faceI++] = meshFaces[iter.key()];
}
primitiveFacePatch p(patchFaces, mesh.points());
// The balance of this routine should be identical to addPatchMesh
// Convert Foam mesh vertices to VTK
const pointField& points = p.localPoints();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(points.size());
forAll(points, i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkcells->Allocate(p.size());
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll (f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addFaceZoneMesh
(
const fvMesh& mesh,
const labelList& faceLabels,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "entered addFaceZoneMesh" << endl;
}
// Construct primitivePatch of faces in fSet.
const faceList& meshFaces = mesh.faces();
faceList patchFaces(faceLabels.size());
forAll(faceLabels, faceI)
{
patchFaces[faceI] = meshFaces[faceLabels[faceI]];
}
primitiveFacePatch p(patchFaces, mesh.points());
// The balance of this routine should be identical to addPatchMesh
// Convert Foam mesh vertices to VTK
const pointField& points = p.localPoints();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(p.size());
forAll(points, i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkcells->Allocate(points.size());
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll (f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->Delete();
}
// ************************************************************************* //

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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamAddFields_H
#define vtkPV3FoamAddFields_H
// FOAM includes
#include "SortableList.H"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class GeoField>
Foam::label Foam::vtkPV3Foam::addFields
(
vtkDataArraySelection *fieldSelection,
const IOobjectList& objects,
const string& suffix
)
{
IOobjectList fieldObjects(objects.lookupClass(GeoField::typeName));
SortableList<word> fields(fieldObjects.size());
label count = 0;
forAllConstIter(IOobjectList, fieldObjects, iter)
{
fields[count++] = iter()->name();
}
if (count)
{
fields.sort();
forAll(fields, fieldI)
{
if (debug)
{
Info<<"add region " << GeoField::typeName
<< ":" << fields[fieldI] << endl;
}
if (suffix.size())
{
fieldSelection->AddArray
(
(fields[fieldI] + suffix).c_str()
);
}
else
{
fieldSelection->AddArray
(
fields[fieldI].c_str()
);
}
}
}
return count;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#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
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV3Foam.H"
// Foam includes
#include "Cloud.H"
#include "fvMesh.H"
#include "passiveParticle.H"
#include "vtkPV3FoamInsertNextPoint.H"
#include "IOobjectList.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addLagrangianMesh
(
const fvMesh& mesh,
vtkPolyData *vtkmesh
)
{
if (debug)
{
Info<< "entered add Lagrangian mesh with timePath "
<< mesh.time().timePath()/"lagrangian" << endl;
}
fileNameList cloudDirs
(
readDir(mesh.time().timePath()/"lagrangian", fileName::DIRECTORY)
);
if (debug && cloudDirs.size())
{
Info<< "check cloudDirs: " << cloudDirs << endl;
}
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);
if (debug)
{
Info<< "cloud with " << parcels.size() << " parcels" << endl;
}
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,90 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "primitivePatch.H"
#include "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPatchMesh
(
const polyPatch& p,
vtkPolyData *vtkmesh
)
{
if (debug)
{
Info<< "Adding patch: " << p.name() << endl;
}
// Convert Foam mesh vertices to VTK
const Foam::pointField& points = p.localPoints();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(points.size());
forAll(points, i)
{
vtkPV3FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray * vtkcells = vtkCellArray::New();
vtkcells->Allocate(faces.size());
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll (f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->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 "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPointSetMesh
(
const fvMesh& mesh,
const pointSet& pSet,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "entered add point set mesh" << endl;
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(pSet.size());
forAllConstIter(pointSet, pSet, iter)
{
vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "vtkPV3FoamInsertNextPoint.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::addPointZoneMesh
(
const fvMesh& mesh,
const labelList& pointLabels,
vtkPolyData* vtkmesh
)
{
if (debug)
{
Info<< "entered add point zone mesh" << endl;
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate(pointLabels.size());
forAll(pointLabels, pointI)
{
vtkPV3FoamInsertNextPoint(vtkpoints, meshPoints[pointLabels[pointI]]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
}
// ************************************************************************* //

View File

@ -0,0 +1,360 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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;
}
// 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,286 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertFaceField_H
#define vtkPV3FoamConvertFaceField_H
// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(faceLabels.size());
cellData->SetNumberOfComponents(Type::nComponents);
cellData->Allocate(Type::nComponents*faceLabels.size());
cellData->SetName(tf.name().c_str());
float vec[Type::nComponents];
forAll(faceLabels, faceI)
{
const label faceNo = faceLabels[faceI];
if (faceNo < nInternalFaces)
{
Type t = 0.5 *
(
tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]
);
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
}
else
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
}
cellData->InsertTuple(faceI, vec);
}
vtkmesh->GetCellData()->AddArray(cellData);
cellData->Delete();
}
template<class Type>
void Foam::vtkPV3Foam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const faceSet& fSet
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(fSet.size());
cellData->SetNumberOfComponents(Type::nComponents);
cellData->Allocate(Type::nComponents*fSet.size());
cellData->SetName(tf.name().c_str());
float vec[Type::nComponents];
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
const label faceNo = iter.key();
if (faceNo < nInternalFaces)
{
Type t = 0.5 *
(
tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]
);
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
}
else
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = t[d];
}
}
cellData->InsertTuple(faceI, vec);
++faceI;
}
vtkmesh->GetCellData()->AddArray(cellData);
cellData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertFaceField
(
const GeometricField<scalar, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(faceLabels.size());
cellData->SetNumberOfComponents(1);
cellData->Allocate(faceLabels.size());
cellData->SetName(tf.name().c_str());
forAll(faceLabels, faceI)
{
const label faceNo = faceLabels[faceI];
if (faceNo < nInternalFaces)
{
cellData->InsertComponent
(
faceI,
0,
0.5 * (tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]])
);
}
else
{
cellData->InsertComponent
(
faceI, 0, tf[faceOwner[faceNo]]
);
}
}
vtkmesh->GetCellData()->AddArray(cellData);
if (!vtkmesh->GetCellData()->GetScalars())
{
vtkmesh->GetCellData()->SetScalars(cellData);
}
cellData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertFaceField
(
const GeometricField<scalar, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const faceSet& fSet
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
const label nInternalFaces = mesh.nInternalFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(fSet.size());
cellData->SetNumberOfComponents(1);
cellData->Allocate(fSet.size());
cellData->SetName(tf.name().c_str());
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
const label faceNo = iter.key();
if (faceNo < nInternalFaces)
{
cellData->InsertComponent
(
faceI,
0,
0.5 * (tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]])
);
}
else
{
cellData->InsertComponent
(
faceI, 0, tf[faceOwner[faceNo]]
);
}
++faceI;
}
vtkmesh->GetCellData()->AddArray(cellData);
if (!vtkmesh->GetCellData()->GetScalars())
{
vtkmesh->GetCellData()->SetScalars(cellData);
}
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,179 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertLagrangianFields_H
#define vtkPV3FoamConvertLagrangianFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertLagrangianFields
(
const fvMesh& mesh,
const IOobjectList& objects,
vtkDataArraySelection* fieldSelection,
vtkMultiBlockDataSet* output
)
{
const selectionInfo& selector = selectInfoLagrangian_;
const label datasetId = 0;
if (!selector.size())
{
return;
}
IOobjectList fieldObjects
(
objects.lookupClass
(
IOField<Type>::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))
{
IOField<Type> iotf
(
IOobject
(
fieldName,
mesh.time().timeName(),
"lagrangian"/cloudName_,
mesh,
IOobject::MUST_READ
)
);
convertLagrangianField(iotf, output, selector, datasetId);
}
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertLagrangianField
(
const IOField<Type>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(tf.size());
pointData->SetNumberOfComponents(Type::nComponents);
pointData->Allocate(Type::nComponents*tf.size());
pointData->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];
}
pointData->InsertTuple(i, vec);
}
vtkmesh->GetPointData()->AddArray(pointData);
pointData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertLagrangianField
(
const IOField<scalar>& sf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(sf.size());
pointData->SetNumberOfComponents(1);
pointData->Allocate(sf.size());
pointData->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++)
{
pointData->InsertComponent(i, 0, sf[i]);
}
vtkmesh->GetPointData()->AddArray(pointData);
if (!vtkmesh->GetPointData()->GetScalars())
{
vtkmesh->GetPointData()->SetScalars(pointData);
}
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,587 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "pointSet.H"
#include "fvMeshSubset.H"
#include "vtkPV3FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV3Foam::convertMeshVolume
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshVolume" << endl;
}
const selectionInfo& selector = selectInfoVolume_;
const fvMesh& mesh = *meshPtr_;
// Create the internal mesh and add as dataset 0
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
// word selectName = getFirstWord
// (
// arraySelection->GetArrayName(regionId)
// );
if (debug)
{
Info<< "Creating VTK internal mesh" << endl;
}
const label datasetId = 0;
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
addVolumeMesh(mesh, vtkmesh, superCells_);
AddToBlock(output, selector, datasetId, vtkmesh, "internalMesh");
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
void Foam::vtkPV3Foam::convertMeshLagrangian
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshLagrangian" << endl;
}
const selectionInfo& selector = selectInfoLagrangian_;
const fvMesh& mesh = *meshPtr_;
// Create the Lagrangian mesh and add as dataset 0
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK Lagrangian mesh" << endl;
}
const label datasetId = 0;
vtkPolyData* vtkmesh = vtkPolyData::New();
addLagrangianMesh(mesh, vtkmesh);
AddToBlock(output, selector, datasetId, vtkmesh, cloudName_);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
void Foam::vtkPV3Foam::convertMeshPatches
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshPatches" << endl;
}
const selectionInfo& selector = selectInfoPatches_;
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
if (selector.size())
{
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& patches = mesh.boundaryMesh();
// Create the patches and add as dataset ...
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelection->GetArrayName(regionId)
);
const label patchId = patches.findPatchID(selectName);
if (debug)
{
Info<< "Creating VTK mesh for patch: " << selectName
<< " region index: " << regionId << endl;
}
const label datasetId = GetNumberOfDataSets(output, selector);
vtkPolyData* vtkmesh = vtkPolyData::New();
addPatchMesh
(
patches[patchId],
vtkmesh
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
selectName + ":patch"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshCellZones
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshCellZones" << endl;
}
const selectionInfo& selector = selectInfoCellZones_;
const fvMesh& mesh = *meshPtr_;
// Create the cell zone(s) and add as DataSet(CELLZONE, 0..n)
if (selector.size())
{
const cellZoneMesh& czMesh = mesh.cellZones();
// use the zoneId directly instead of the name
for (int zoneI=0; zoneI < selector.size(); ++zoneI)
{
const int regionId = selector.start() + zoneI;
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for cellZone: "
<< zoneI << endl;
}
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(czMesh[zoneI]);
const label datasetId = GetNumberOfDataSets(output, selector);
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
addVolumeMesh
(
subsetter.subMesh(),
vtkmesh,
superCellZonesCells_[datasetId]
);
// renumber - superCells must contain global cell ids
inplaceRenumber
(
subsetter.cellMap(),
superCellZonesCells_[datasetId]
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
czMesh.names()[zoneI] + ":cellZone"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshCellSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshCellSet" << endl;
}
const selectionInfo& selector = selectInfoCellSets_;
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
// Create the cell sets and add as dataset
if (selector.size())
{
const fvMesh& mesh = *meshPtr_;
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelection->GetArrayName(regionId)
);
if (debug)
{
Info<< "Creating VTK mesh for cellSet: " << selectName
<< " region index: " << regionId << endl;
}
const cellSet cSet(mesh, selectName);
fvMeshSubset subsetter(mesh);
subsetter.setLargeCellSubset(cSet);
const label datasetId = GetNumberOfDataSets(output, selector);
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
addVolumeMesh
(
subsetter.subMesh(),
vtkmesh,
superCellSetCells_[datasetId]
);
// renumber - superCells must contain global cell ids
inplaceRenumber
(
subsetter.cellMap(),
superCellSetCells_[datasetId]
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
selectName + ":cellSet"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshFaceZones
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshFaceZones" << endl;
}
const selectionInfo& selector = selectInfoFaceZones_;
const fvMesh& mesh = *meshPtr_;
// Create the cell zone(s) and add as datasets
if (selector.size())
{
const faceZoneMesh& fzMesh = mesh.faceZones();
// use the zoneId directly instead of the name
for (int zoneI=0; zoneI < selector.size(); ++zoneI)
{
const int regionId = selector.start() + zoneI;
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for faceZone: "
<< zoneI << endl;
}
const label datasetId = GetNumberOfDataSets(output, selector);
vtkPolyData* vtkmesh = vtkPolyData::New();
addFaceZoneMesh
(
mesh,
fzMesh[zoneI],
vtkmesh
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
fzMesh.names()[zoneI] + ":faceZone"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshFaceSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshFaceSet" << endl;
}
const selectionInfo& selector = selectInfoFaceSets_;
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
// Create the face sets and add as dataset
if (selector.size())
{
const fvMesh& mesh = *meshPtr_;
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelection->GetArrayName(regionId)
);
if (debug)
{
Info<< "Creating VTK mesh for faceSet: " << selectName
<< " region index: " << regionId << endl;
}
const faceSet fSet(mesh, selectName);
const label datasetId = GetNumberOfDataSets(output, selector);
vtkPolyData* vtkmesh = vtkPolyData::New();
addFaceSetMesh
(
mesh,
fSet,
vtkmesh
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
selectName + ":faceSet"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshPointZones
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshPointZones" << endl;
}
const selectionInfo& selector = selectInfoPointZones_;
const fvMesh& mesh = *meshPtr_;
// Create the point sets and add as dataset
if (selector.size())
{
const pointZoneMesh& pzMesh = mesh.pointZones();
// use the zoneId directly instead of the name
for (int zoneI=0; zoneI < selector.size(); ++zoneI)
{
const int regionId = selector.start() + zoneI;
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for pointZone: "
<< zoneI << endl;
}
const label datasetId = GetNumberOfDataSets(output, selector);
vtkPolyData* vtkmesh = vtkPolyData::New();
addPointZoneMesh
(
mesh,
pzMesh[zoneI],
vtkmesh
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
pzMesh.names()[zoneI] + ":pointZone"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
void Foam::vtkPV3Foam::convertMeshPointSet
(
vtkMultiBlockDataSet* output
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::convertMeshPointSet" << endl;
}
const selectionInfo& selector = selectInfoPointSets_;
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
// Create the point sets and add as dataset
if (selector.size())
{
const fvMesh& mesh = *meshPtr_;
for
(
int regionId = selector.start();
regionId < selector.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelection->GetArrayName(regionId)
);
if (debug)
{
Info<< "Creating VTK mesh for pointSet: " << selectName
<< " region index: " << regionId << endl;
}
const pointSet pSet(mesh, selectName);
const label datasetId = GetNumberOfDataSets(output, selector);
vtkPolyData* vtkmesh = vtkPolyData::New();
addPointSetMesh
(
mesh,
pSet,
vtkmesh
);
AddToBlock
(
output, selector, datasetId, vtkmesh,
selectName + ":pointSet"
);
selectedRegionDatasetIds_[regionId] = datasetId;
vtkmesh->Delete();
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,121 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertPatchFaceField_H
#define vtkPV3FoamConvertPatchFaceField_H
// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<Type>& ptf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(ptf.size());
cellData->SetNumberOfComponents(Type::nComponents);
cellData->Allocate(Type::nComponents*ptf.size());
cellData->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];
}
cellData->InsertTuple(i, vec);
}
vtkmesh->GetCellData()->AddArray(cellData);
cellData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPatchFaceField
(
const word& name,
const Field<scalar>& psf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(psf.size());
cellData->SetNumberOfComponents(1);
cellData->Allocate(psf.size());
cellData->SetName(name.c_str());
forAll(psf, i)
{
cellData->InsertComponent(i, 0, psf[i]);
}
vtkmesh->GetCellData()->AddArray(cellData);
if (!vtkmesh->GetCellData()->GetScalars())
{
vtkmesh->GetCellData()->SetScalars(cellData);
}
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,116 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
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,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(pptf.size());
pointData->SetNumberOfComponents(Type::nComponents);
pointData->Allocate(Type::nComponents*pptf.size());
pointData->SetName(name.c_str());
float vec[Type::nComponents];
forAll(pptf, i)
{
for (direction d=0; d<Type::nComponents; d++)
{
vec[d] = pptf[i][d];
}
pointData->InsertTuple(i, vec);
}
vtkmesh->GetPointData()->AddArray(pointData);
pointData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPatchPointField
(
const word& name,
const Field<scalar>& ppsf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkPolyData* vtkmesh = vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(ppsf.size());
pointData->SetNumberOfComponents(1);
pointData->Allocate(ppsf.size());
pointData->SetName(name.c_str());
for (int i=0; i<ppsf.size(); i++)
{
pointData->InsertComponent(i, 0, ppsf[i]);
}
vtkmesh->GetPointData()->AddArray(pointData);
if (!vtkmesh->GetPointData()->GetScalars())
{
vtkmesh->GetPointData()->SetScalars(pointData);
}
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,274 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertPointFields_H
#define vtkPV3FoamConvertPointFields_H
// Foam includes
#include "interpolatePointToCell.H"
// VTK includes
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
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
for
(
int regionId = selectInfoVolume_.start();
regionId < selectInfoVolume_.end();
++regionId
)
{
if (selectedRegions_[regionId])
{
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null(),
output,
selectInfoVolume_,
selectedRegionDatasetIds_[regionId]
);
}
}
// Convert patches
label regionId = selectInfoPatches_.start();
forAll (patches, patchI)
{
if (patches[patchI].size())
{
if (selectedRegions_[regionId])
{
convertPatchPointField
(
ptf.name(),
ptf.boundaryField()[patchI]
.patchInternalField()(),
output,
selectInfoPatches_,
selectedRegionDatasetIds_[regionId]
);
}
regionId++;
}
}
}
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(ptf.size() + addPointCellLabels_.size());
pointData->SetNumberOfComponents(Type::nComponents);
pointData->Allocate(Type::nComponents*ptf.size());
pointData->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];
}
pointData->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];
}
pointData->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];
}
pointData->InsertTuple(i++, vec);
}
}
internalMesh->GetPointData()->AddArray(pointData);
pointData->Delete();
}
template<>
void Foam::vtkPV3Foam::convertPointField
(
const GeometricField<scalar, pointPatchField, pointMesh>& psf,
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo
)
{
vtkUnstructuredGrid* internalMesh = vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(psf.size() + addPointCellLabels_.size());
pointData->SetNumberOfComponents(1);
pointData->Allocate(psf.size());
pointData->SetName(psf.name().c_str());
for (int i=0; i<psf.size(); i++)
{
pointData->InsertComponent(i, 0, psf[i]);
}
label i = psf.size();
if (&sf != &GeometricField<scalar, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels_, api)
{
pointData->InsertComponent
(
i++,
0,
sf[addPointCellLabels_[api]]
);
}
}
else
{
forAll(addPointCellLabels_, api)
{
pointData->InsertComponent
(
i++,
0,
interpolatePointToCell(psf, addPointCellLabels_[api])
);
}
}
internalMesh->GetPointData()->AddArray(pointData);
if (!internalMesh->GetPointData()->GetScalars())
{
internalMesh->GetPointData()->SetScalars(pointData);
}
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,459 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamConvertVolFields_H
#define vtkPV3FoamConvertVolFields_H
// Foam includes
#include "emptyFvPatchField.H"
#include "wallPolyPatch.H"
#include "faceSet.H"
#include "vtkPV3FoamConvertPatchFaceField.H"
#include "vtkPV3FoamConvertPatchPointField.H"
#include "vtkPV3FoamConvertFaceField.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();
const polyBoundaryMesh& patches = mesh.boundaryMesh();
vtkDataArraySelection* arraySelector = reader_->GetRegionSelection();
for (label i=0; i<nFields; i++)
{
const word fieldName = fieldSelection->GetArrayName(i);
if
(
!fieldSelection->GetArraySetting(i)
|| !fieldObjects.found(fieldName))
{
continue;
}
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
for
(
int regionId = selectInfoVolume_.start();
regionId < selectInfoVolume_.end();
++regionId
)
{
if (selectedRegions_[regionId])
{
convertVolField
(
tf,
output,
selectInfoVolume_,
selectedRegionDatasetIds_[regionId],
superCells_
);
convertPointField
(
tptf(), tf,
output,
selectInfoVolume_,
selectedRegionDatasetIds_[regionId]
);
}
}
// Convert patches
for
(
int regionId = selectInfoPatches_.start();
regionId < selectInfoPatches_.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelector->GetArrayName(regionId)
);
const label patchId = patches.findPatchID(selectName);
const fvPatchField<Type>& ptf
(
tf.boundaryField()[patchId]
);
if
(
isType<emptyFvPatchField<Type> >(ptf)
||
(
typeid(patches[patchId]) == typeid(wallPolyPatch)
&& reader_->GetExtrapolateWalls()
)
)
{
fvPatch p
(
ptf.patch().patch(),
tf.mesh().boundary()
);
convertPatchFaceField
(
tf.name(),
fvPatchField<Type>(p, tf)
.patchInternalField()(),
output,
selectInfoPatches_,
selectedRegionDatasetIds_[regionId]
);
}
else
{
convertPatchFaceField
(
tf.name(),
ptf,
output,
selectInfoPatches_,
selectedRegionDatasetIds_[regionId]
);
}
convertPatchPointField
(
tptf().name(),
tptf().boundaryField()[patchId]
.patchInternalField()(),
output,
selectInfoPatches_,
selectedRegionDatasetIds_[regionId]
);
}
// Convert cell zones
for
(
int regionId = selectInfoCellZones_.start();
regionId < selectInfoCellZones_.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
word selectName = getFirstWord
(
arraySelector->GetArrayName(regionId)
);
Info<< "wish to convert cellzone: " << selectName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
const label datasetId =
selectedRegionDatasetIds_[regionId];
convertVolField
(
tf,
output, selectInfoCellZones_, datasetId,
superCellZonesCells_[datasetId]
);
}
// Convert cell sets
for
(
int regionId = selectInfoCellSets_.start();
regionId < selectInfoCellSets_.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
word selectName = getFirstWord
(
arraySelector->GetArrayName(regionId)
);
Info<< "wish to convert cellset: " << selectName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
const label datasetId =
selectedRegionDatasetIds_[regionId];
convertVolField
(
tf,
output, selectInfoCellSets_, datasetId,
superCellSetCells_[datasetId]
);
}
// Convert face zones
for
(
int regionId = selectInfoFaceZones_.start();
regionId < selectInfoFaceZones_.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
if (debug)
{
word selectName = getFirstWord
(
arraySelector->GetArrayName(regionId)
);
Info<< "wish to convert facezone: " << selectName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
const faceZoneMesh& fzMesh = mesh.faceZones();
const label zoneI = regionId - selectInfoFaceZones_.start();
const label datasetId =
selectedRegionDatasetIds_[regionId];
convertFaceField
(
tf,
output, selectInfoFaceZones_, datasetId,
mesh,
fzMesh[zoneI]
);
}
// Convert face sets
for
(
int regionId = selectInfoFaceSets_.start();
regionId < selectInfoFaceSets_.end();
++regionId
)
{
if (!selectedRegions_[regionId])
{
continue;
}
word selectName = getFirstWord
(
arraySelector->GetArrayName(regionId)
);
if (debug)
{
Info<< "wish to convert faceset: " << selectName
<< " regionId: " << regionId
<< " volume field: " << fieldName
<< endl;
}
const faceSet fSet(mesh, selectName);
const label datasetId =
selectedRegionDatasetIds_[regionId];
convertFaceField
(
tf,
output, selectInfoFaceSets_, datasetId,
mesh,
fSet
);
}
}
}
template<class Type>
void Foam::vtkPV3Foam::convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
labelList& superCells
)
{
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray* celldata = vtkFloatArray::New();
celldata->SetNumberOfTuples(superCells.size());
celldata->SetNumberOfComponents(Type::nComponents);
celldata->Allocate(Type::nComponents*superCells.size());
celldata->SetName(tf.name().c_str());
if (debug)
{
Info<< "converting vol<Type>Field: " << tf.name() << nl
<< "field size = " << tf.size() << 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];
}
celldata->InsertTuple(scI, vec);
}
vtkmesh->GetCellData()->AddArray(celldata);
celldata->Delete();
}
template<>
void Foam::vtkPV3Foam::convertVolField
(
const GeometricField<scalar, fvPatchField, volMesh>& sf,
vtkMultiBlockDataSet* output,
const selectionInfo& selector,
const label datasetNo,
labelList& superCells
)
{
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
);
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples(superCells.size());
cellData->SetNumberOfComponents(1);
cellData->Allocate(superCells.size());
cellData->SetName(sf.name().c_str());
if (debug)
{
Info<< "converting volScalarField: " << sf.name() << nl
<< "field size = " << sf.size() << nl
<< "nTuples = " << superCells.size() << nl
<< "nComps = 1" << endl;
}
forAll(superCells, scI)
{
cellData->InsertComponent(scI, 0, sf[superCells[scI]]);
}
vtkmesh->GetCellData()->AddArray(cellData);
if (!vtkmesh->GetCellData()->GetScalars())
{
vtkmesh->GetCellData()->SetScalars(cellData);
}
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,77 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//- Extract up to the first non-word characters
inline Foam::word Foam::vtkPV3Foam::getFirstWord(const char* str)
{
if (str)
{
label n = 0;
while (str[n] && word::valid(str[n]))
{
++n;
}
return word(str, n);
}
else
{
return word::null;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructors * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

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
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,239 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.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
pointMesh pMesh(mesh);
// Search for list of objects for this time
IOobjectList objects(mesh, dbPtr_().timeName());
vtkDataArraySelection* arraySelection = reader_->GetVolFieldSelection();
// Convert volume fields
if (debug)
{
Info<< "converting Foam volume fields" << endl;
}
volPointInterpolation pInterp(mesh, pMesh);
convertVolFields<Foam::scalar>
(
mesh, pInterp, objects, arraySelection, output
);
convertVolFields<Foam::vector>
(
mesh, pInterp, objects, arraySelection, output
);
convertVolFields<Foam::sphericalTensor>
(
mesh, pInterp, objects, arraySelection, output
);
convertVolFields<Foam::symmTensor>
(
mesh, pInterp, objects, arraySelection, output
);
convertVolFields<Foam::tensor>
(
mesh, pInterp, objects, arraySelection, 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
IOobjectList objects(mesh, dbPtr_().timeName());
vtkDataArraySelection* arraySelection = reader_->GetPointFieldSelection();
// Convert point fields
if (debug)
{
Info<< "converting Foam point fields" << endl;
}
convertPointFields<Foam::scalar>
(
mesh, objects, arraySelection, output
);
convertPointFields<Foam::vector>
(
mesh, objects, arraySelection, output
);
convertPointFields<Foam::sphericalTensor>
(
mesh, objects, arraySelection, output
);
convertPointFields<Foam::symmTensor>
(
mesh, objects, arraySelection, output
);
convertPointFields<Foam::tensor>
(
mesh, objects, arraySelection, 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
IOobjectList objects
(
mesh,
dbPtr_().timeName(),
"lagrangian"/cloudName_
);
vtkDataArraySelection* arraySelection =
reader_->GetLagrangianFieldSelection();
// Convert Lagrangian fields
if (debug)
{
Info<< "converting Foam Lagrangian fields" << endl;
}
convertLagrangianFields<Foam::scalar>
(
mesh, objects, arraySelection, output
);
convertLagrangianFields<Foam::vector>
(
mesh, objects, arraySelection, output
);
convertLagrangianFields<Foam::sphericalTensor>
(
mesh, objects, arraySelection, output
);
convertLagrangianFields<Foam::symmTensor>
(
mesh, objects, arraySelection, output
);
convertLagrangianFields<Foam::tensor>
(
mesh, objects, arraySelection, output
);
}
// ************************************************************************* //

View File

@ -0,0 +1,417 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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 "IOPtrList.H"
#include "pointSet.H"
#include "polyBoundaryMeshEntries.H"
#include "entry.H"
#include "vtkPV3FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
namespace Foam
{
//- A class for reading zone information without requiring a mesh
class zonesEntries
:
public regIOobject,
public PtrList<entry>
{
public:
// Constructors
explicit zonesEntries(const IOobject& io)
:
regIOobject(io),
PtrList<entry>(readStream("regIOobject"))
{
close();
}
// Member functions
bool writeData(Ostream&) const
{
notImplemented("zonesEntries::writeData(Ostream&) const");
return false;
}
};
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#include "vtkPV3FoamAddFields.H"
#include "vtkPV3FoamUpdateInformationFields.H"
void Foam::vtkPV3Foam::updateInformationInternalMesh()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationInternalMesh"
<< endl;
}
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
// 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
selectInfoVolume_ = arraySelection->GetNumberOfArrays();
arraySelection->AddArray("internalMesh");
selectInfoVolume_ += 1;
}
void Foam::vtkPV3Foam::updateInformationLagrangian()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationLagrangian at timePath "
<< dbPtr_->timePath()/"lagrangian" << endl;
}
vtkDataArraySelection* arraySelection = reader_->GetRegionSelection();
// Search for list of lagrangian objects for this time
// IOobjectList lagrangianObjects(dbPtr(), dbPtr_().timeName(), "lagrangian");
fileNameList cloudDirs
(
readDir(dbPtr_->timePath()/"lagrangian", fileName::DIRECTORY)
);
selectInfoLagrangian_ = arraySelection->GetNumberOfArrays();
if (cloudDirs.size())
{
arraySelection->AddArray("lagrangian");
selectInfoLagrangian_ += 1;
Info<<"added cloudDirs\n";
if (cloudDirs.size() > 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];
}
else
{
Info<<"no cloudDirs @ " << dbPtr_->timePath()/"lagrangian" << endl;
}
}
void Foam::vtkPV3Foam::updateInformationPatches()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationPatches" << endl;
}
vtkDataArraySelection *arraySelection = reader_->GetRegionSelection();
//- Read patches
polyBoundaryMeshEntries patchEntries
(
IOobject
(
"boundary",
dbPtr_().findInstance(polyMesh::meshSubDir, "boundary"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
selectInfoPatches_ = arraySelection->GetNumberOfArrays();
int nPatches = 0;
// 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
arraySelection->AddArray
(
(patchEntries[entryI].keyword() + " - patch").c_str()
);
++nPatches;
}
}
selectInfoPatches_ += nPatches;
}
void Foam::vtkPV3Foam::updateInformationZones()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationZones" << endl;
}
vtkDataArraySelection *arraySelection = reader_->GetRegionSelection();
//- Read cell zone information
{
zonesEntries zones
(
IOobject
(
"cellZones",
dbPtr_().findInstance(polyMesh::meshSubDir, "cellZones"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
);
selectInfoCellZones_ = arraySelection->GetNumberOfArrays();
if (zones.headerOk())
{
forAll(zones, zoneI)
{
arraySelection->AddArray
(
(zones[zoneI].keyword() + " - cellZone").c_str()
);
}
selectInfoCellZones_ += zones.size();
}
superCellZonesCells_.setSize(selectInfoCellZones_.size());
}
//- Read face zone information
{
zonesEntries zones
(
IOobject
(
"faceZones",
dbPtr_().findInstance(polyMesh::meshSubDir, "faceZones"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
);
selectInfoFaceZones_ = arraySelection->GetNumberOfArrays();
if (zones.headerOk())
{
forAll(zones, zoneI)
{
arraySelection->AddArray
(
(zones[zoneI].keyword() + " - faceZone").c_str()
);
}
selectInfoFaceZones_ += zones.size();
}
}
//- Read point zone information
{
zonesEntries zones
(
IOobject
(
"pointZones",
dbPtr_().findInstance(polyMesh::meshSubDir, "pointZones"),
polyMesh::meshSubDir,
dbPtr_(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
)
);
selectInfoPointZones_ = arraySelection->GetNumberOfArrays();
if (zones.headerOk())
{
forAll(zones, zoneI)
{
arraySelection->AddArray
(
(zones[zoneI].keyword() + " - pointZone").c_str()
);
}
selectInfoPointZones_ += zones.size();
}
}
}
void Foam::vtkPV3Foam::updateInformationSets()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationSets" << endl;
}
vtkDataArraySelection *arraySelection = reader_->GetRegionSelection();
// Add sets
IOobjectList objects
(
dbPtr_(),
dbPtr_().findInstance(polyMesh::meshSubDir, "faces"),
polyMesh::meshSubDir/"sets"
);
selectInfoCellSets_ = arraySelection->GetNumberOfArrays();
selectInfoCellSets_ += addFields<cellSet>
(
arraySelection,
objects,
" - cellSet"
);
superCellSetCells_.setSize(selectInfoCellSets_.size());
selectInfoFaceSets_ = arraySelection->GetNumberOfArrays();
selectInfoFaceSets_ += addFields<faceSet>
(
arraySelection,
objects,
" - faceSet"
);
selectInfoPointSets_ = arraySelection->GetNumberOfArrays();
selectInfoPointSets_ += addFields<pointSet>
(
arraySelection,
objects,
" - pointSet"
);
}
void Foam::vtkPV3Foam::updateInformationLagrangianFields()
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationLagrangianFields"
<< endl;
}
vtkDataArraySelection *arraySelection =
reader_->GetLagrangianFieldSelection();
// preserve the currently selected values
const stringList selectedEntries = getSelectedArrayEntries
(
arraySelection
);
arraySelection->RemoveAllArrays();
// TODO - currently hard-coded to ONE cloud
IOobjectList objects
(
dbPtr_(),
dbPtr_().timeName(),
"lagrangian"/cloudName_
);
addFields<IOField<scalar> >
(
arraySelection,
objects
);
addFields<IOField<vector> >
(
arraySelection,
objects
);
addFields<IOField<sphericalTensor> >
(
arraySelection,
objects
);
addFields<IOField<symmTensor> >
(
arraySelection,
objects
);
addFields<IOField<tensor> >
(
arraySelection,
objects
);
// restore the currently enabled values
setSelectedArrayEntries
(
arraySelection,
selectedEntries
);
if (debug)
{
Info<< "lagrangian objects.size() = " << objects.size()
<< endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,97 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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
vtkPV3Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamUpdateInformationFields_H
#define vtkPV3FoamUpdateInformationFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<template<class> class patchType, class meshType>
void Foam::vtkPV3Foam::updateInformationFields
(
vtkDataArraySelection *arraySelection
)
{
if (debug)
{
Info<< "entered Foam::vtkPV3Foam::updateInformationFields" << endl;
}
// preserve the currently selected values
const stringList selectedEntries = getSelectedArrayEntries
(
arraySelection
);
arraySelection->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> >
(
arraySelection,
objects
);
addFields<GeometricField<vector, patchType, meshType> >
(
arraySelection,
objects
);
addFields<GeometricField<sphericalTensor, patchType, meshType> >
(
arraySelection,
objects
);
addFields<GeometricField<symmTensor, patchType, meshType> >
(
arraySelection,
objects
);
addFields<GeometricField<tensor, patchType, meshType> >
(
arraySelection,
objects
);
// restore the currently enabled values
setSelectedArrayEntries
(
arraySelection,
selectedEntries
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //