Add the OpenFOAM source tree

This commit is contained in:
Henry
2014-12-10 22:40:10 +00:00
parent ee487c860d
commit 446e5777f0
13379 changed files with 3983377 additions and 0 deletions

View File

@ -0,0 +1,11 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
# deal with client/server vs combined plugins
rm -f $FOAM_LIBBIN/libPV4blockMeshReader* 2>/dev/null
rm -rf PV4blockMeshReader/Make
wclean libso vtkPV4blockMesh
# ----------------------------------------------------------------- end-of-file

View File

@ -0,0 +1,17 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
if [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ]
then
wmake libso vtkPV4blockMesh
(
cd PV4blockMeshReader
mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
cd Make/$WM_OPTIONS
cmake ../..
make
)
fi
# ----------------------------------------------------------------- end-of-file

View File

@ -0,0 +1,81 @@
# 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.
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
LINK_DIRECTORIES(
$ENV{FOAM_LIBBIN}
$ENV{FOAM_EXT_LIBBIN}
)
INCLUDE_DIRECTORIES(
$ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude
$ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude
$ENV{WM_PROJECT_DIR}/src/meshing/blockMesh/lnInclude
${PROJECT_SOURCE_DIR}/../vtkPV4blockMesh
)
ADD_DEFINITIONS(
-DWM_$ENV{WM_PRECISION_OPTION}
)
# Set output library destination to plugin directory
SET(
LIBRARY_OUTPUT_PATH $ENV{PV_PLUGIN_PATH}
CACHE INTERNAL
"Single output directory for building all libraries."
)
#
# Define combined plugin
#
# Extend the auto-generated panel
QT4_WRAP_CPP(MOC_SRCS pqPV4blockMeshReaderPanel.h)
ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS
CLASS_NAME pqPV4blockMeshReaderPanel
XML_NAME PV4blockMeshReader # name of SourceProxy in *SM.xml
XML_GROUP sources
)
IF("${PARAVIEW_VERSION_MINOR}" EQUAL 0)
ADD_PARAVIEW_PLUGIN(
PV4blockMeshReader_SM "1.0"
SERVER_MANAGER_XML PV4blockMeshReader_SM.xml
SERVER_MANAGER_SOURCES vtkPV4blockMeshReader.cxx
GUI_INTERFACES ${IFACES}
GUI_SOURCES pqPV4blockMeshReaderPanel.cxx
${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS}
GUI_RESOURCE_FILES PV4blockMeshReader.xml
)
ELSE("${PARAVIEW_VERSION_MINOR}" EQUAL 0)
ADD_PARAVIEW_PLUGIN(
PV4blockMeshReader_SM "1.0"
SERVER_MANAGER_XML PV4blockMeshReader_SM.xml
SERVER_MANAGER_SOURCES vtkPV4blockMeshReader.cxx
GUI_INTERFACES ${IFACES}
GUI_SOURCES pqPV4blockMeshReaderPanel.cxx
${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS}
)
ENDIF("${PARAVIEW_VERSION_MINOR}" EQUAL 0)
# Build the client-side plugin
TARGET_LINK_LIBRARIES(
PV4blockMeshReader_SM
OpenFOAM
blockMesh
vtkPV4blockMesh
)
#-----------------------------------------------------------------------------

View File

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

View File

@ -0,0 +1,6 @@
<ParaViewReaders>
<Reader name="PV4blockMeshReader"
extensions="blockMesh"
file_description="OpenFOAM blockMesh reader">
</Reader>
</ParaViewReaders>

View File

@ -0,0 +1,112 @@
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy
name="PV4blockMeshReader"
class="vtkPV4blockMeshReader">
<!-- File name - compulsory -->
<StringVectorProperty
name="FileName"
command="SetFileName"
number_of_elements="1"
animateable="0">
<FileListDomain name="files"/>
<Documentation>
Specifies the filename for the OpenFOAM blockMesh Reader.
</Documentation>
</StringVectorProperty>
<!-- Show Point Numbers check-box -->
<IntVectorProperty
name="UiShowPointNumbers"
command="SetShowPointNumbers"
number_of_elements="1"
default_values="1"
is_internal="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Show point numbers in render window.
</Documentation>
</IntVectorProperty>
<!-- Update GUI check box -->
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
number_of_elements="1"
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
A simple way to cause a reader GUI modification.
</Documentation>
</IntVectorProperty>
<!--
| Selections
-->
<!-- Available Blocks array -->
<StringVectorProperty
name="BlockArrayStatus"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Block"/>
</StringVectorProperty>
<StringVectorProperty
name="BlockStatus"
label="Blocks"
command="SetBlockArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="BlockArrayStatus"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="BlockArrayStatus" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
<Documentation>
This property contains a list of the blocks
</Documentation>
</StringVectorProperty>
<!-- Available CurvedEdges array -->
<StringVectorProperty
name="CurvedEdgesArrayStatus"
information_only="1">
<ArraySelectionInformationHelper attribute_name="CurvedEdges"/>
</StringVectorProperty>
<StringVectorProperty
name="CurvedEdgesStatus"
label="Curved Edges"
command="SetCurvedEdgesArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="CurvedEdgesArrayStatus"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="CurvedEdgesArrayStatus" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
<Documentation>
This property contains a list of the curved edges
</Documentation>
</StringVectorProperty>
<Hints>
<Property name="FileName" show="0"/>
<Property name="UiShowPointNumbers" show="0"/>
<ReaderFactory extensions="blockMesh"
file_description="OpenFOAM blockMesh"/>
</Hints>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,110 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "pqPV4blockMeshReaderPanel.h"
// QT
#include <QGridLayout>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QString>
#include <QPushButton>
#include <QtDebug>
// Paraview <-> QT UI
#include "pqAnimationScene.h"
#include "pqApplicationCore.h"
#include "pqPipelineRepresentation.h"
#include "pqServerManagerModel.h"
#include "pqView.h"
// Paraview Server Manager
#include "vtkSMDoubleVectorProperty.h"
#include "vtkSMIntVectorProperty.h"
#include "vtkSMProperty.h"
#include "vtkSMSourceProxy.h"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
pqPV4blockMeshReaderPanel::pqPV4blockMeshReaderPanel
(
pqProxy *proxy,
QWidget *p
)
:
pqAutoGeneratedObjectPanel(proxy, p)
{
// create first sublayout (at top of the panel)
QGridLayout *form = new QGridLayout();
this->PanelLayout->addLayout(form, 0, 0, 1, -1);
vtkSMProperty* prop = 0;
// checkbox for showing point numbers
if ((prop = this->proxy()->GetProperty("UiShowPointNumbers")) != 0)
{
prop->SetImmediateUpdate(true);
ShowPointNumbers_ = new QCheckBox("Show Point Numbers");
ShowPointNumbers_->setToolTip("Show point numbers in render window.");
ShowPointNumbers_->setChecked
(
vtkSMIntVectorProperty::SafeDownCast(prop)->GetElement(0)
);
form->addWidget(ShowPointNumbers_);
connect
(
ShowPointNumbers_,
SIGNAL(stateChanged(int)),
this,
SLOT(ShowPointNumbersToggled())
);
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void pqPV4blockMeshReaderPanel::ShowPointNumbersToggled()
{
vtkSMIntVectorProperty::SafeDownCast
(
this->proxy()->GetProperty("UiShowPointNumbers")
)->SetElement(0, ShowPointNumbers_->isChecked());
// update the active view
if (this->view())
{
this->view()->render();
}
// OR: update all views
// pqApplicationCore::instance()->render();
}
// ************************************************************************* //

View File

@ -0,0 +1,89 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
pqPV4blockMeshReaderPanel
Description
GUI modifications for the ParaView reader panel
A custom panel for the PV4blockMeshReader.
SourceFiles
pqPV4blockMeshReaderPanel.cxx
\*---------------------------------------------------------------------------*/
#ifndef pqPV4blockMeshReaderPanel_h
#define pqPV4blockMeshReaderPanel_h
#include "pqAutoGeneratedObjectPanel.h"
// Forward declaration of QT classes
class QCheckBox;
class QLineEdit;
class QTimer;
class QToolButton;
// Forward declaration of ParaView classes
class vtkSMSourceProxy;
/*---------------------------------------------------------------------------*\
Class pqPV4blockMeshReaderPanel Declaration
\*---------------------------------------------------------------------------*/
class pqPV4blockMeshReaderPanel
:
public pqAutoGeneratedObjectPanel
{
// Private data
Q_OBJECT;
typedef pqAutoGeneratedObjectPanel Superclass;
//- Show Point Numbers checkbox
QCheckBox* ShowPointNumbers_;
protected slots:
void ShowPointNumbersToggled();
public:
// Constructors
//- Construct from components
pqPV4blockMeshReaderPanel(pqProxy*, QWidget*);
//- Destructor
// virtual ~pqPV4blockMeshReaderPanel();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,419 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "vtkPV4blockMeshReader.h"
#include "pqApplicationCore.h"
#include "pqRenderView.h"
#include "pqServerManagerModel.h"
// VTK includes
#include "vtkCallbackCommand.h"
#include "vtkDataArraySelection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkSMRenderViewProxy.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
// OpenFOAM includes
#include "vtkPV4blockMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
vtkStandardNewMacro(vtkPV4blockMeshReader);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
vtkPV4blockMeshReader::vtkPV4blockMeshReader()
{
Debug = 0;
vtkDebugMacro(<<"Constructor");
SetNumberOfInputPorts(0);
FileName = NULL;
foamData_ = NULL;
ShowPointNumbers = 1;
UpdateGUI = 0;
BlockSelection = vtkDataArraySelection::New();
CurvedEdgesSelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
SelectionObserver = vtkCallbackCommand::New();
SelectionObserver->SetCallback
(
&vtkPV4blockMeshReader::SelectionModifiedCallback
);
SelectionObserver->SetClientData(this);
BlockSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
CurvedEdgesSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
vtkPV4blockMeshReader::~vtkPV4blockMeshReader()
{
vtkDebugMacro(<<"Deconstructor");
if (foamData_)
{
// remove point numbers
updatePointNumbersView(false);
delete foamData_;
}
if (FileName)
{
delete [] FileName;
}
BlockSelection->RemoveObserver(this->SelectionObserver);
CurvedEdgesSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
BlockSelection->Delete();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
// Do everything except set the output info
int vtkPV4blockMeshReader::RequestInformation
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestInformation");
if (Foam::vtkPV4blockMesh::debug)
{
cout<<"REQUEST_INFORMATION\n";
}
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
int nInfo = outputVector->GetNumberOfInformationObjects();
if (Foam::vtkPV4blockMesh::debug)
{
cout<<"RequestInformation with " << nInfo << " item(s)\n";
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Print(cout);
}
}
if (!foamData_)
{
foamData_ = new Foam::vtkPV4blockMesh(FileName, this);
}
else
{
foamData_->updateInfo();
}
// might need some other type of error handling
// {
// vtkErrorMacro("could not find valid OpenFOAM blockMesh");
//
// // delete foamData and flag it as fatal error
// delete foamData_;
// foamData_ = NULL;
// return 0;
// }
return 1;
}
// Set the output info
int vtkPV4blockMeshReader::RequestData
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestData");
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
// catch previous error
if (!foamData_)
{
vtkErrorMacro("Reader failed - perhaps no mesh?");
return 0;
}
int nInfo = outputVector->GetNumberOfInformationObjects();
if (Foam::vtkPV4blockMesh::debug)
{
cout<<"RequestData with " << nInfo << " item(s)\n";
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Print(cout);
}
}
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outputVector->GetInformationObject(0)->Get
(
vtkMultiBlockDataSet::DATA_OBJECT()
)
);
if (Foam::vtkPV4blockMesh::debug)
{
cout<< "update output with "
<< output->GetNumberOfBlocks() << " blocks\n";
}
foamData_->Update(output);
updatePointNumbersView(ShowPointNumbers);
// Do any cleanup on the OpenFOAM side
foamData_->CleanUp();
return 1;
}
void vtkPV4blockMeshReader::SetShowPointNumbers(const int val)
{
if (ShowPointNumbers != val)
{
ShowPointNumbers = val;
updatePointNumbersView(ShowPointNumbers);
}
}
void vtkPV4blockMeshReader::updatePointNumbersView(const bool show)
{
pqApplicationCore* appCore = pqApplicationCore::instance();
// need to check this, since our destructor calls this
if (!appCore)
{
return;
}
// Server manager model for querying items in the server manager
pqServerManagerModel* smModel = appCore->getServerManagerModel();
if (!smModel || !foamData_)
{
return;
}
// Get all the pqRenderView instances
QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>();
for (int viewI=0; viewI<renderViews.size(); ++viewI)
{
foamData_->renderPointNumbers
(
renderViews[viewI]->getRenderViewProxy()->GetRenderer(),
show
);
}
// use refresh here?
}
void vtkPV4blockMeshReader::PrintSelf(ostream& os, vtkIndent indent)
{
vtkDebugMacro(<<"PrintSelf");
this->Superclass::PrintSelf(os,indent);
os << indent << "File name: "
<< (this->FileName ? this->FileName : "(none)") << "\n";
foamData_->PrintSelf(os, indent);
}
// ----------------------------------------------------------------------
// Block selection list control
vtkDataArraySelection* vtkPV4blockMeshReader::GetBlockSelection()
{
vtkDebugMacro(<<"GetBlockSelection");
return BlockSelection;
}
int vtkPV4blockMeshReader::GetNumberOfBlockArrays()
{
vtkDebugMacro(<<"GetNumberOfBlockArrays");
return BlockSelection->GetNumberOfArrays();
}
const char* vtkPV4blockMeshReader::GetBlockArrayName(int index)
{
vtkDebugMacro(<<"GetBlockArrayName");
return BlockSelection->GetArrayName(index);
}
int vtkPV4blockMeshReader::GetBlockArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetBlockArrayStatus");
return BlockSelection->ArrayIsEnabled(name);
}
void vtkPV4blockMeshReader::SetBlockArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetBlockArrayStatus");
if (status)
{
BlockSelection->EnableArray(name);
}
else
{
BlockSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
// CurvedEdges selection list control
vtkDataArraySelection* vtkPV4blockMeshReader::GetCurvedEdgesSelection()
{
vtkDebugMacro(<<"GetCurvedEdgesSelection");
return CurvedEdgesSelection;
}
int vtkPV4blockMeshReader::GetNumberOfCurvedEdgesArrays()
{
vtkDebugMacro(<<"GetNumberOfCurvedEdgesArrays");
return CurvedEdgesSelection->GetNumberOfArrays();
}
const char* vtkPV4blockMeshReader::GetCurvedEdgesArrayName(int index)
{
vtkDebugMacro(<<"GetCurvedEdgesArrayName");
return CurvedEdgesSelection->GetArrayName(index);
}
int vtkPV4blockMeshReader::GetCurvedEdgesArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetCurvedEdgesArrayStatus");
return CurvedEdgesSelection->ArrayIsEnabled(name);
}
void vtkPV4blockMeshReader::SetCurvedEdgesArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetCurvedEdgesArrayStatus");
if (status)
{
CurvedEdgesSelection->EnableArray(name);
}
else
{
CurvedEdgesSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
void vtkPV4blockMeshReader::SelectionModifiedCallback
(
vtkObject*,
unsigned long,
void* clientdata,
void*
)
{
static_cast<vtkPV4blockMeshReader*>(clientdata)->Modified();
}
int vtkPV4blockMeshReader::FillOutputPortInformation
(
int port,
vtkInformation* info
)
{
if (port == 0)
{
return this->Superclass::FillOutputPortInformation(port, info);
}
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
return 1;
}
// ************************************************************************* //

View File

@ -0,0 +1,177 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
vtkPV4blockMeshReader
Description
reads a dataset in OpenFOAM bockMesh format
vtkPV4blockMeshReader creates an multiblock dataset.
It uses the OpenFOAM infrastructure (blockMesh).
SourceFiles
vtkPV4blockMeshReader.cxx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4blockMeshReader_h
#define vtkPV4blockMeshReader_h
// VTK includes
#include "vtkMultiBlockDataSetAlgorithm.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
// VTK forward declarations
class vtkDataArraySelection;
class vtkCallbackCommand;
namespace Foam
{
class vtkPV4blockMesh;
}
/*---------------------------------------------------------------------------*\
Class vtkPV4blockMeshReader Declaration
\*---------------------------------------------------------------------------*/
class vtkPV4blockMeshReader
:
public vtkMultiBlockDataSetAlgorithm
{
public:
vtkTypeMacro(vtkPV4blockMeshReader, vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream&, vtkIndent);
static vtkPV4blockMeshReader* New();
// Description:
// Set/Get the filename.
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
// Description:
// Display corner point labels
virtual void SetShowPointNumbers(int);
vtkGetMacro(ShowPointNumbers, int);
// Description:
// GUI update control
vtkSetMacro(UpdateGUI, int);
vtkGetMacro(UpdateGUI, int);
// Description:
// Blocks selection list control
vtkDataArraySelection* GetBlockSelection();
int GetNumberOfBlockArrays();
int GetBlockArrayStatus(const char*);
void SetBlockArrayStatus(const char*, int status);
const char* GetBlockArrayName(int index);
// Description:
// CurvedEdges selection list control
vtkDataArraySelection* GetCurvedEdgesSelection();
int GetNumberOfCurvedEdgesArrays();
int GetCurvedEdgesArrayStatus(const char*);
void SetCurvedEdgesArrayStatus(const char*, int status);
const char* GetCurvedEdgesArrayName(int index);
// Description:
// Callback registered with the SelectionObserver
// for all the selection lists
static void SelectionModifiedCallback
(
vtkObject* caller,
unsigned long eid,
void* clientdata,
void* calldata
);
protected:
//- Construct null
vtkPV4blockMeshReader();
//- Destructor
~vtkPV4blockMeshReader();
//- Return information about mesh, times, etc without loading anything
virtual int RequestInformation
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
//- Get the mesh/fields for a particular time
virtual int RequestData
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
//- Fill in additional port information
virtual int FillOutputPortInformation(int, vtkInformation*);
// The observer to modify this object when array selections are modified
vtkCallbackCommand* SelectionObserver;
char* FileName;
private:
//- Disallow default bitwise copy construct
vtkPV4blockMeshReader(const vtkPV4blockMeshReader&);
//- Disallow default bitwise assignment
void operator=(const vtkPV4blockMeshReader&);
//- Add/remove point numbers to/from the view
void updatePointNumbersView(const bool show);
//- Show Point Numbers
int ShowPointNumbers;
//- Dummy variable/switch to invoke a reader update
int UpdateGUI;
vtkDataArraySelection* BlockSelection;
vtkDataArraySelection* CurvedEdgesSelection;
//BTX
Foam::vtkPV4blockMesh* foamData_;
//ETX
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,5 @@
vtkPV4blockMesh.C
vtkPV4blockMeshConvert.C
vtkPV4blockMeshUtils.C
LIB = $(FOAM_LIBBIN)/libvtkPV4blockMesh

View File

@ -0,0 +1,12 @@
EXE_INC = \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/mesh/blockMesh/lnInclude \
-I$(ParaView_INCLUDE_DIR) \
-I../../vtkPV4Readers/lnInclude \
-I../PV4blockMeshReader
LIB_LIBS = \
-lmeshTools \
-lblockMesh \
-L$(FOAM_LIBBIN) -lvtkPV4Readers \
$(GLIBS)

View File

@ -0,0 +1,65 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
InClass
vtkPV4blockMesh
\*---------------------------------------------------------------------------*/
#ifndef vtkOpenFOAMPoints_H
#define vtkOpenFOAMPoints_H
// VTK includes
#include "vtkPoints.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline void vtkInsertNextOpenFOAMPoint
(
vtkPoints *points,
const Foam::point& p
)
{
points->InsertNextPoint(p.x(), p.y(), p.z());
}
inline void vtkInsertNextOpenFOAMPoint
(
vtkPoints *points,
const Foam::point& p,
const Foam::scalar scaleFactor
)
{
points->InsertNextPoint
(
p.x()*scaleFactor,
p.y()*scaleFactor,
p.z()*scaleFactor
);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,473 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "vtkPV4blockMesh.H"
#include "vtkPV4blockMeshReader.h"
// OpenFOAM includes
#include "blockMesh.H"
#include "Time.H"
#include "patchZones.H"
#include "OStringStream.H"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(vtkPV4blockMesh, 0);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV4blockMesh::resetCounters()
{
// Reset mesh part ids and sizes
arrayRangeBlocks_.reset();
arrayRangeEdges_.reset();
arrayRangeCorners_.reset();
}
void Foam::vtkPV4blockMesh::updateInfoBlocks
(
vtkDataArraySelection* arraySelection
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::updateInfoBlocks"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
}
arrayRangeBlocks_.reset( arraySelection->GetNumberOfArrays() );
const blockMesh& blkMesh = *meshPtr_;
const int nBlocks = blkMesh.size();
for (int blockI = 0; blockI < nBlocks; ++blockI)
{
const blockDescriptor& blockDef = blkMesh[blockI].blockDef();
word partName = Foam::name(blockI);
// append the (optional) zone name
if (!blockDef.zoneName().empty())
{
partName += " - " + blockDef.zoneName();
}
// Add blockId and zoneName to GUI list
arraySelection->AddArray(partName.c_str());
}
arrayRangeBlocks_ += nBlocks;
if (debug)
{
// just for debug info
getSelectedArrayEntries(arraySelection);
Info<< "<end> Foam::vtkPV4blockMesh::updateInfoBlocks" << endl;
}
}
void Foam::vtkPV4blockMesh::updateInfoEdges
(
vtkDataArraySelection* arraySelection
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::updateInfoEdges"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
}
arrayRangeEdges_.reset( arraySelection->GetNumberOfArrays() );
const blockMesh& blkMesh = *meshPtr_;
const curvedEdgeList& edges = blkMesh.edges();
const int nEdges = edges.size();
forAll(edges, edgeI)
{
OStringStream ostr;
ostr<< edges[edgeI].start() << ":" << edges[edgeI].end() << " - "
<< edges[edgeI].type();
// Add "beg:end - type" to GUI list
arraySelection->AddArray(ostr.str().c_str());
}
arrayRangeEdges_ += nEdges;
if (debug)
{
// just for debug info
getSelectedArrayEntries(arraySelection);
Info<< "<end> Foam::vtkPV4blockMesh::updateInfoEdges" << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkPV4blockMesh::vtkPV4blockMesh
(
const char* const FileName,
vtkPV4blockMeshReader* reader
)
:
reader_(reader),
dbPtr_(NULL),
meshPtr_(NULL),
meshRegion_(polyMesh::defaultRegion),
meshDir_(polyMesh::meshSubDir),
arrayRangeBlocks_("block"),
arrayRangeEdges_("edges"),
arrayRangeCorners_("corners")
{
if (debug)
{
Info<< "Foam::vtkPV4blockMesh::vtkPV4blockMesh - "
<< FileName << endl;
}
// avoid argList and get rootPath/caseName directly from the file
fileName fullCasePath(fileName(FileName).path());
if (!isDir(fullCasePath))
{
return;
}
if (fullCasePath == ".")
{
fullCasePath = cwd();
}
// Set the case as an environment variable - some BCs might use this
if (fullCasePath.name().find("processor", 0) == 0)
{
const fileName globalCase = fullCasePath.path();
setEnv("FOAM_CASE", globalCase, true);
setEnv("FOAM_CASENAME", globalCase.name(), true);
}
else
{
setEnv("FOAM_CASE", fullCasePath, true);
setEnv("FOAM_CASENAME", fullCasePath.name(), true);
}
// look for 'case{region}.OpenFOAM'
// could be stringent and insist the prefix match the directory name...
// Note: cannot use fileName::name() due to the embedded '{}'
string caseName(fileName(FileName).lessExt());
string::size_type beg = caseName.find_last_of("/{");
string::size_type end = caseName.find('}', beg);
if
(
beg != string::npos && caseName[beg] == '{'
&& end != string::npos && end == caseName.size()-1
)
{
meshRegion_ = caseName.substr(beg+1, end-beg-1);
// some safety
if (meshRegion_.empty())
{
meshRegion_ = polyMesh::defaultRegion;
}
if (meshRegion_ != polyMesh::defaultRegion)
{
meshDir_ = meshRegion_/polyMesh::meshSubDir;
}
}
if (debug)
{
Info<< "fullCasePath=" << fullCasePath << nl
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << endl;
}
// Create time object
dbPtr_.reset
(
new Time
(
Time::controlDictName,
fileName(fullCasePath.path()),
fileName(fullCasePath.name())
)
);
dbPtr_().functionObjects().off();
updateInfo();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkPV4blockMesh::~vtkPV4blockMesh()
{
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::~vtkPV4blockMesh" << endl;
}
// Hmm. pointNumberTextActors are not getting removed
//
forAll(pointNumberTextActorsPtrs_, pointI)
{
pointNumberTextActorsPtrs_[pointI]->Delete();
}
pointNumberTextActorsPtrs_.clear();
delete meshPtr_;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV4blockMesh::updateInfo()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::updateInfo"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "] " << endl;
}
resetCounters();
vtkDataArraySelection* blockSelection = reader_->GetBlockSelection();
vtkDataArraySelection* edgeSelection = reader_->GetCurvedEdgesSelection();
// enable 'internalMesh' on the first call
// or preserve the enabled selections
stringList enabledParts;
stringList enabledEdges;
bool firstTime = false;
if (!blockSelection->GetNumberOfArrays() && !meshPtr_)
{
firstTime = true;
}
else
{
enabledParts = getSelectedArrayEntries(blockSelection);
enabledEdges = getSelectedArrayEntries(edgeSelection);
}
// Clear current mesh parts list
blockSelection->RemoveAllArrays();
edgeSelection->RemoveAllArrays();
// need a blockMesh
updateFoamMesh();
// Update mesh parts list
updateInfoBlocks( blockSelection );
// Update curved edges list
updateInfoEdges( edgeSelection );
// restore the enabled selections
if (!firstTime)
{
setSelectedArrayEntries(blockSelection, enabledParts);
setSelectedArrayEntries(edgeSelection, enabledEdges);
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::updateInfo" << endl;
}
}
void Foam::vtkPV4blockMesh::updateFoamMesh()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::updateFoamMesh" << endl;
}
// Check to see if the OpenFOAM mesh has been created
if (!meshPtr_)
{
if (debug)
{
Info<< "Creating blockMesh at time=" << dbPtr_().timeName()
<< endl;
}
IOdictionary meshDict
(
IOobject
(
"blockMeshDict",
dbPtr_().constant(),
meshDir_,
dbPtr_(),
IOobject::MUST_READ_IF_MODIFIED,
IOobject::NO_WRITE,
false
)
);
meshPtr_ = new blockMesh(meshDict, meshRegion_);
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::updateFoamMesh" << endl;
}
}
void Foam::vtkPV4blockMesh::Update
(
vtkMultiBlockDataSet* output
)
{
reader_->UpdateProgress(0.1);
// Set up mesh parts selection(s)
updateBoolListStatus(blockStatus_, reader_->GetBlockSelection());
// Set up curved edges selection(s)
updateBoolListStatus(edgeStatus_, reader_->GetCurvedEdgesSelection());
reader_->UpdateProgress(0.2);
// Update the OpenFOAM mesh
updateFoamMesh();
reader_->UpdateProgress(0.5);
// Convert mesh elemente
int blockNo = 0;
convertMeshCorners(output, blockNo);
convertMeshBlocks(output, blockNo);
convertMeshEdges(output, blockNo);
reader_->UpdateProgress(0.8);
}
void Foam::vtkPV4blockMesh::CleanUp()
{
reader_->UpdateProgress(1.0);
}
void Foam::vtkPV4blockMesh::renderPointNumbers
(
vtkRenderer* renderer,
const bool show
)
{
// always remove old actors first
forAll(pointNumberTextActorsPtrs_, pointI)
{
renderer->RemoveViewProp(pointNumberTextActorsPtrs_[pointI]);
pointNumberTextActorsPtrs_[pointI]->Delete();
}
pointNumberTextActorsPtrs_.clear();
if (show && meshPtr_)
{
const pointField& cornerPts = meshPtr_->blockPointField();
const scalar scaleFactor = meshPtr_->scaleFactor();
pointNumberTextActorsPtrs_.setSize(cornerPts.size());
forAll(cornerPts, pointI)
{
vtkTextActor* txt = vtkTextActor::New();
txt->SetInput(Foam::name(pointI).c_str());
// Set text properties
vtkTextProperty* tprop = txt->GetTextProperty();
tprop->SetFontFamilyToArial();
tprop->BoldOn();
tprop->ShadowOff();
tprop->SetLineSpacing(1.0);
tprop->SetFontSize(14);
tprop->SetColor(1.0, 0.0, 1.0);
tprop->SetJustificationToCentered();
// Set text to use 3-D world co-ordinates
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
txt->GetPositionCoordinate()->SetValue
(
cornerPts[pointI].x()*scaleFactor,
cornerPts[pointI].y()*scaleFactor,
cornerPts[pointI].z()*scaleFactor
);
// Add text to each renderer
renderer->AddViewProp(txt);
// Maintain a list of text labels added so that they can be
// removed later
pointNumberTextActorsPtrs_[pointI] = txt;
}
}
}
void Foam::vtkPV4blockMesh::PrintSelf(ostream& os, vtkIndent indent) const
{
#if 0
os << indent << "Number of nodes: "
<< (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n";
os << indent << "Number of cells: "
<< (meshPtr_ ? meshPtr_->nCells() : 0) << "\n";
os << indent << "Number of available time steps: "
<< (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
#endif
}
// ************************************************************************* //

View File

@ -0,0 +1,353 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Class
Foam::vtkPV4blockMesh
Description
Provides a reader interface for OpenFOAM blockMesh to VTK interaction
SourceFiles
vtkPV4blockMesh.C
vtkPV4blockMeshConvert.C
vtkPV4blockMeshUpdate.C
vtkPV4blockMeshUtils.C
// Needed by VTK:
vtkDataArrayTemplateImplicit.txx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4blockMesh_H
#define vtkPV4blockMesh_H
// do not include legacy strstream headers
#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS
# define VTK_EXCLUDE_STRSTREAM_HEADERS
#endif
#include "className.H"
#include "fileName.H"
#include "stringList.H"
#include "wordList.H"
#include "primitivePatch.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
class vtkDataSet;
class vtkPoints;
class vtkPV4blockMeshReader;
class vtkRenderer;
class vtkTextActor;
class vtkMultiBlockDataSet;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkIndent;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// OpenFOAM class forward declarations
class argList;
class Time;
class blockMesh;
template<class Type> class List;
/*---------------------------------------------------------------------------*\
Class vtkPV4blockMesh Declaration
\*---------------------------------------------------------------------------*/
class vtkPV4blockMesh
{
// Private classes
//- Bookkeeping for GUI checklists and the multi-block organization
class arrayRange
{
const char *name_;
int block_;
int start_;
int size_;
public:
arrayRange(const char *name, const int blockNo=0)
:
name_(name),
block_(blockNo),
start_(0),
size_(0)
{}
//- Return the block holding these datasets
int block() const
{
return block_;
}
//- Assign block number, return previous value
int block(int blockNo)
{
int prev = block_;
block_ = blockNo;
return prev;
}
//- Return block name
const char* name() const
{
return name_;
}
//- Return array start index
int start() const
{
return start_;
}
//- Return array end index
int end() const
{
return start_ + size_;
}
//- Return sublist size
int size() const
{
return size_;
}
bool empty() const
{
return !size_;
}
//- Reset the size to zero and optionally assign a new start
void reset(const int startAt = 0)
{
start_ = startAt;
size_ = 0;
}
//- Increment the size
void operator+=(const int n)
{
size_ += n;
}
};
// Private Data
//- Access to the controlling vtkPV4blockMeshReader
vtkPV4blockMeshReader* reader_;
//- OpenFOAM time control
autoPtr<Time> dbPtr_;
//- OpenFOAM mesh
blockMesh* meshPtr_;
//- The mesh region
word meshRegion_;
//- The mesh directory for the region
fileName meshDir_;
//- Selected geometrical parts
boolList blockStatus_;
//- Selected curved edges
boolList edgeStatus_;
//- First instance and size of bleckMesh blocks
// used to index into blockStatus_
arrayRange arrayRangeBlocks_;
//- First instance and size of CurvedEdges (only partially used)
arrayRange arrayRangeEdges_;
//- First instance and size of block corners (only partially used)
arrayRange arrayRangeCorners_;
//- List of point numbers for rendering to window
List<vtkTextActor*> pointNumberTextActorsPtrs_;
// 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,
vtkDataSet* dataset,
const arrayRange&,
const label datasetNo,
const std::string& datasetName
);
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static vtkDataSet* GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const arrayRange&,
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 arrayRange&
);
//- Update boolList from GUI selection
static void updateBoolListStatus
(
boolList&,
vtkDataArraySelection*
);
//- Reset data counters
void resetCounters();
// Update information helper functions
//- Internal block info
void updateInfoBlocks(vtkDataArraySelection*);
//- block curved edges info
void updateInfoEdges(vtkDataArraySelection*);
// Update helper functions
//- OpenFOAM mesh
void updateFoamMesh();
// Mesh conversion functions
//- mesh blocks
void convertMeshBlocks(vtkMultiBlockDataSet*, int& blockNo);
//- mesh curved edges
void convertMeshEdges(vtkMultiBlockDataSet*, int& blockNo);
//- mesh corners
void convertMeshCorners(vtkMultiBlockDataSet*, int& blockNo);
// GUI selection helper functions
//- Retrieve the current selections
static wordHashSet getSelected(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
static wordHashSet getSelected
(
vtkDataArraySelection*,
const arrayRange&
);
//- Retrieve the current selections
static stringList getSelectedArrayEntries(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
static stringList getSelectedArrayEntries
(
vtkDataArraySelection*,
const arrayRange&
);
//- Set selection(s)
static void setSelectedArrayEntries
(
vtkDataArraySelection*,
const stringList&
);
//- Disallow default bitwise copy construct
vtkPV4blockMesh(const vtkPV4blockMesh&);
//- Disallow default bitwise assignment
void operator=(const vtkPV4blockMesh&);
public:
//- Static data members
ClassName("vtkPV4blockMesh");
// Constructors
//- Construct from components
vtkPV4blockMesh
(
const char* const FileName,
vtkPV4blockMeshReader* reader
);
//- Destructor
~vtkPV4blockMesh();
// Member Functions
//- Update
void updateInfo();
void Update(vtkMultiBlockDataSet* output);
//- Clean any storage
void CleanUp();
//- Add/remove point numbers to/from the view
void renderPointNumbers(vtkRenderer*, const bool show);
// Access
//- Debug information
void PrintSelf(ostream&, vtkIndent) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,319 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "vtkPV4blockMesh.H"
#include "vtkPV4blockMeshReader.h"
// OpenFOAM includes
#include "blockMesh.H"
#include "Time.H"
#include "vtkOpenFOAMPoints.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV4blockMesh::convertMeshBlocks
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
vtkDataArraySelection* selection = reader_->GetBlockSelection();
arrayRange& range = arrayRangeBlocks_;
range.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const blockMesh& blkMesh = *meshPtr_;
const Foam::pointField& blockPoints = blkMesh.blockPointField();
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::convertMeshBlocks" << endl;
}
int blockI = 0;
const scalar scaleFactor = blkMesh.scaleFactor();
for
(
int partId = range.start();
partId < range.end();
++partId, ++blockI
)
{
if (!blockStatus_[partId])
{
continue;
}
const blockDescriptor& blockDef = blkMesh[blockI].blockDef();
vtkUnstructuredGrid* vtkmesh = vtkUnstructuredGrid::New();
// Convert OpenFOAM mesh vertices to VTK
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate( blockDef.nPoints() );
const labelList& blockLabels = blockDef.blockShape();
vtkmesh->Allocate(1);
vtkIdType nodeIds[8];
forAll(blockLabels, ptI)
{
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
blockPoints[blockLabels[ptI]],
scaleFactor
);
nodeIds[ptI] = ptI;
}
vtkmesh->InsertNextCell
(
VTK_HEXAHEDRON,
8,
nodeIds
);
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
AddToBlock
(
output, vtkmesh, range, datasetNo,
selection->GetArrayName(partId)
);
vtkmesh->Delete();
datasetNo++;
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::convertMeshBlocks" << endl;
}
}
void Foam::vtkPV4blockMesh::convertMeshEdges
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
vtkDataArraySelection* selection = reader_->GetCurvedEdgesSelection();
arrayRange& range = arrayRangeEdges_;
range.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const blockMesh& blkMesh = *meshPtr_;
const curvedEdgeList& edges = blkMesh.edges();
int edgeI = 0;
const scalar scaleFactor = blkMesh.scaleFactor();
for
(
int partId = range.start();
partId < range.end();
++partId, ++edgeI
)
{
if (!edgeStatus_[partId])
{
continue;
}
// search each block
forAll(blkMesh, blockI)
{
const blockDescriptor& blockDef = blkMesh[blockI].blockDef();
edgeList blkEdges = blockDef.blockShape().edges();
// find the corresponding edge within the block
label foundEdgeI = -1;
forAll(blkEdges, blkEdgeI)
{
if (edges[edgeI].compare(blkEdges[blkEdgeI]))
{
foundEdgeI = blkEdgeI;
break;
}
}
if (foundEdgeI != -1)
{
const List<point>& edgePoints =
blockDef.blockEdgePoints()[foundEdgeI];
vtkPolyData* vtkmesh = vtkPolyData::New();
vtkPoints* vtkpoints = vtkPoints::New();
vtkpoints->Allocate( edgePoints.size() );
vtkmesh->Allocate(1);
vtkIdType pointIds[edgePoints.size()];
forAll(edgePoints, ptI)
{
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
edgePoints[ptI],
scaleFactor
);
pointIds[ptI] = ptI;
}
vtkmesh->InsertNextCell
(
VTK_POLY_LINE,
edgePoints.size(),
pointIds
);
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
AddToBlock
(
output, vtkmesh, range, datasetNo,
selection->GetArrayName(partId)
);
vtkmesh->Delete();
datasetNo++;
break;
}
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::convertMeshEdges" << endl;
}
}
void Foam::vtkPV4blockMesh::convertMeshCorners
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
arrayRange& range = arrayRangeCorners_;
range.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const pointField& blockPoints = meshPtr_->blockPointField();
const scalar& scaleFactor = meshPtr_->scaleFactor();
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::convertMeshCorners" << endl;
}
if (true) // or some flag or other condition
{
vtkPolyData* vtkmesh = vtkPolyData::New();
vtkPoints* vtkpoints = vtkPoints::New();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkpoints->Allocate( blockPoints.size() );
vtkcells->Allocate( blockPoints.size() );
vtkIdType pointId = 0;
forAll(blockPoints, ptI)
{
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
blockPoints[ptI],
scaleFactor
);
vtkcells->InsertNextCell(1, &pointId);
pointId++;
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
vtkmesh->SetVerts(vtkcells);
vtkcells->Delete();
AddToBlock
(
output, vtkmesh, range, datasetNo,
arrayRangeCorners_.name()
);
vtkmesh->Delete();
datasetNo++;
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::convertMeshCorners" << endl;
}
}
// ************************************************************************* //

View File

@ -0,0 +1,357 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ 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 3 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, see <http://www.gnu.org/licenses/>.
Description
Misc helper methods and utilities
\*---------------------------------------------------------------------------*/
#include "vtkPV4blockMesh.H"
#include "vtkPV4blockMeshReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
//! \cond fileScope
// Extract up to the first non-word characters
inline word getFirstWord(const char* str)
{
if (str)
{
label n = 0;
while (str[n] && word::valid(str[n]))
{
++n;
}
return word(str, n, true);
}
else
{
return word::null;
}
}
//! \endcond
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV4blockMesh::AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const arrayRange& range,
const label datasetNo,
const std::string& datasetName
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (!block)
{
if (blockDO)
{
FatalErrorIn("Foam::vtkPV4blockMesh::AddToBlock")
<< "Block already has a vtkDataSet assigned to it"
<< endl;
return;
}
block = vtkMultiBlockDataSet::New();
output->SetBlock(blockNo, block);
block->Delete();
}
if (debug)
{
Info<< "block[" << blockNo << "] has "
<< block->GetNumberOfBlocks()
<< " datasets prior to adding set " << datasetNo
<< " with name: " << datasetName << endl;
}
block->SetBlock(datasetNo, dataset);
// name the block when assigning dataset 0
if (datasetNo == 0)
{
output->GetMetaData(blockNo)->Set
(
vtkCompositeDataSet::NAME(),
range.name()
);
}
if (datasetName.size())
{
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(),
datasetName.c_str()
);
}
}
vtkDataSet* Foam::vtkPV4blockMesh::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const arrayRange& range,
const label datasetNo
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return vtkDataSet::SafeDownCast(block->GetBlock(datasetNo));
}
return 0;
}
// ununsed at the moment
Foam::label Foam::vtkPV4blockMesh::GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const arrayRange& range
)
{
const int blockNo = range.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return block->GetNumberOfBlocks();
}
return 0;
}
Foam::wordHashSet Foam::vtkPV4blockMesh::getSelected
(
vtkDataArraySelection* select
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI=0; elemI < nElem; ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::wordHashSet Foam::vtkPV4blockMesh::getSelected
(
vtkDataArraySelection* select,
const arrayRange& range
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::stringList Foam::vtkPV4blockMesh::getSelectedArrayEntries
(
vtkDataArraySelection* select
)
{
stringList selections(select->GetNumberOfArrays());
label nElem = 0;
forAll(selections, elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
label nElem = select->GetNumberOfArrays();
Info<< "available(";
for (int elemI = 0; elemI < nElem; ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
Foam::stringList Foam::vtkPV4blockMesh::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const arrayRange& range
)
{
stringList selections(range.size());
label nElem = 0;
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
Info<< "available(";
for (int elemI = range.start(); elemI < range.end(); ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
void Foam::vtkPV4blockMesh::setSelectedArrayEntries
(
vtkDataArraySelection* select,
const stringList& selections
)
{
const int nElem = select->GetNumberOfArrays();
select->DisableAllArrays();
// Loop through entries, setting values from selectedEntries
for (int elemI=0; elemI < nElem; ++elemI)
{
string arrayName(select->GetArrayName(elemI));
forAll(selections, elemI)
{
if (selections[elemI] == arrayName)
{
select->EnableArray(arrayName.c_str());
break;
}
}
}
}
void Foam::vtkPV4blockMesh::updateBoolListStatus
(
boolList& status,
vtkDataArraySelection* selection
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4blockMesh::updateBoolListStatus" << endl;
}
const label nElem = selection->GetNumberOfArrays();
if (status.size() != nElem)
{
status.setSize(nElem);
status = false;
}
forAll(status, elemI)
{
const int setting = selection->GetArraySetting(elemI);
status[elemI] = setting;
if (debug)
{
Info<< " part[" << elemI << "] = "
<< status[elemI]
<< " : " << selection->GetArrayName(elemI) << endl;
}
}
if (debug)
{
Info<< "<end> Foam::vtkPV4blockMesh::updateBoolListStatus" << endl;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //