Merge commit 'bundle/home' into olesenm

Conflicts:
	src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.C
	src/OpenFOAM/matrices/simpleMatrix/simpleMatrix.H
	tutorials/incompressible/simpleFoam/airFoil2D/Allclean
	tutorials/multiphase/settlingFoam/ras/tank3D/Allclean
This commit is contained in:
Mark Olesen
2009-11-04 08:54:34 +01:00
106 changed files with 3673 additions and 229 deletions

View File

@ -40,6 +40,7 @@ using namespace Foam;
int main()
{
HASHTABLE_CLASS<double> table1(13);
HASHTABLE_CLASS<double>::iterator iter;
table1.insert("aaa", 1.0);
table1.insert("aba", 2.0);
@ -52,8 +53,12 @@ int main()
table1.insert("adx", 9.0);
table1.insert("aec", 10.0);
// erase by key
table1.erase("aaw");
table1.erase("abs");
// erase by iterator
iter = table1.find("abs");
table1.erase(iter);
Info<< "\ntable1 toc: " << table1.toc() << endl;
Info<< "\ntable1 sortedToc: " << table1.sortedToc() << endl;

View File

@ -0,0 +1,3 @@
hashTableTest3.C
EXE = $(FOAM_USER_APPBIN)/hashTableTest3

View File

@ -0,0 +1,2 @@
/* EXE_INC = -I$(LIB_SRC)/cfdTools/include */
/* EXE_LIBS = -lfiniteVolume */

View File

@ -0,0 +1,87 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 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
Test speeds for some HashTable operations
\*---------------------------------------------------------------------------*/
#include "argList.H"
#include "HashTable.H"
#include "HashPtrTable.H"
#include "Map.H"
#include "StaticHashTable.H"
#include "HashTbl.H"
#include "cpuTime.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
const label nLoops = 30;
const label nBase = 100000;
const label nSize = nLoops * nBase;
cpuTime timer;
// ie, a
// Map<label> map(2 * nSize);
// HashTable<label, label, Hash<label> > map(2 * nSize);
// StaticHashTable<label, label, Hash<label> > map(2 * nSize);
HashTbl<label, label, Hash<label> > map(2 * nSize);
Info<< "Constructed map of size: " << nSize
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< " " << timer.cpuTimeIncrement() << " s\n\n";
for (label i = 0; i < nSize; i++)
{
map.insert(i, i);
}
Info<< "Inserted " << nSize << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
label elemI = 0;
for (label iLoop = 0; iLoop < nLoops; iLoop++)
{
for (label i = 0; i < nBase; i++)
{
map.erase(elemI++);
}
map.shrink();
Info<< "loop " << iLoop << " - Erased " << nBase << " elements"
<< " (size " << map.size() << " capacity " << map.capacity() << ") "
<< timer.cpuTimeIncrement() << " s\n";
}
return 0;
}
// ************************************************************************* //

View File

@ -1,21 +0,0 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
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
# ----------------------------------------------------------------- end-of-file

View File

@ -0,0 +1,16 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
if [ -d "$ParaView_DIR" -a -r "$ParaView_DIR" ]
then
case "$ParaView_VERSION" in
3*)
wmake libso vtkPV3Readers
PV3blockMeshReader/Allwmake
PV3FoamReader/Allwmake
;;
esac
fi
# ----------------------------------------------------------------- end-of-file

View File

@ -2,6 +2,9 @@
cd ${0%/*} || exit 1 # run from this directory
set -x
# deal with client/server vs combined plugins
rm -f $FOAM_LIBBIN/libPV3FoamReader* 2>/dev/null
rm -rf PV3FoamReader/Make
wclean libso vtkPV3Foam

View File

@ -0,0 +1,21 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
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
# ----------------------------------------------------------------- end-of-file

View File

@ -7,7 +7,7 @@
# the pqReader.xml file contains xml defining readers with their
# file extensions and descriptions.
cmake_minimum_required(VERSION 2.4)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
@ -33,19 +33,46 @@ SET(
"Single output directory for building all libraries."
)
# Build the server-side plugin
#
# Defined combined plugin
#
# Extend the auto-generated panel
QT4_WRAP_CPP(MOC_SRCS pqPV3FoamReaderPanel.h)
ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS
CLASS_NAME pqPV3FoamReaderPanel
XML_NAME PV3FoamReader # name of SourceProxy in *SM.xml
XML_GROUP sources
)
ADD_PARAVIEW_PLUGIN(
PV3FoamReader_SM "1.0"
SERVER_MANAGER_XML PV3FoamReader_SM.xml
SERVER_MANAGER_SOURCES vtkPV3FoamReader.cxx
GUI_INTERFACES ${IFACES}
GUI_SOURCES pqPV3FoamReaderPanel.cxx
${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS}
GUI_RESOURCE_FILES PV3FoamReader.xml
)
# Build the client-side plugin
ADD_PARAVIEW_PLUGIN(
PV3FoamReader
"1.0"
GUI_RESOURCES PV3FoamReader.qrc
)
# #
# # Define the server-side portion of the reader plugin
# #
# ADD_PARAVIEW_PLUGIN(
# PV3FoamReader_SM "1.0"
# SERVER_MANAGER_XML PV3FoamReader_SM.xml
# SERVER_MANAGER_SOURCES vtkPV3FoamReader.cxx
# )
# #
# # Define the client-side portion of the reader plugin
# #
# ADD_PARAVIEW_PLUGIN(
# PV3FoamReader "1.0"
# GUI_RESOURCES PV3FoamReader.qrc
# )
#
TARGET_LINK_LIBRARIES(
PV3FoamReader_SM

View File

@ -16,6 +16,21 @@
</Documentation>
</StringVectorProperty>
<!-- Cache Mesh check-box -->
<IntVectorProperty
name="UiCacheMesh"
command="SetCacheMesh"
number_of_elements="1"
is_internal="1"
default_values="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Cache the fvMesh in memory.
</Documentation>
</IntVectorProperty>
<!-- Send discrete time info to the animation panel -->
<DoubleVectorProperty
name="TimestepValues"
@ -72,10 +87,11 @@
<!-- Show Patch Names check-box -->
<IntVectorProperty
name="ShowPatchNames"
name="UiShowPatchNames"
command="SetShowPatchNames"
number_of_elements="1"
default_values="0"
is_internal="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
@ -83,21 +99,7 @@
</Documentation>
</IntVectorProperty>
<!-- Cache Mesh check-box -->
<IntVectorProperty
name="CacheMesh"
command="SetCacheMesh"
number_of_elements="1"
default_values="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Cache the fvMesh in memory.
</Documentation>
</IntVectorProperty>
<!-- Update GUI check box -->
<!-- Force GUI update check box -->
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
@ -204,6 +206,14 @@
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<Hints>
<Property name="FileName" show="0"/>
<Property name="UiCacheMesh" show="0"/>
<Property name="UiShowPatchNames" show="0"/>
</Hints>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,135 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "pqPV3FoamReaderPanel.h"
// QT
#include <QGridLayout>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QString>
#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 * * * * * * * * * * * * * * //
pqPV3FoamReaderPanel::pqPV3FoamReaderPanel
(
pqProxy *proxy,
QWidget *p
)
:
pqAutoGeneratedObjectPanel(proxy, p),
sourceProxy_(vtkSMSourceProxy::SafeDownCast(this->proxy()))
{
// create first sublayout (at top of the panel)
QGridLayout *sect1 = new QGridLayout();
this->PanelLayout->addLayout(sect1, 0, 0, 1, -1);
// checkbox for caching mesh
CacheMesh_ = new QCheckBox("Cache Mesh");
CacheMesh_->setChecked(true);
// checkbox for caching mesh
ShowPatchNames_ = new QCheckBox("Show Patch Names");
ShowPatchNames_->setChecked(false);
connect
(
CacheMesh_,
SIGNAL(stateChanged(int)),
this,
SLOT(CacheMeshToggled())
);
connect
(
ShowPatchNames_,
SIGNAL(stateChanged(int)),
this,
SLOT(ShowPatchNamesToggled())
);
sect1->addWidget(CacheMesh_);
sect1->addWidget(ShowPatchNames_);
// immediate update on the Server Manager side
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->GetProperty("UiCacheMesh")
)->SetImmediateUpdate(true);
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->GetProperty("UiShowPatchNames")
)->SetImmediateUpdate(true);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void pqPV3FoamReaderPanel::CacheMeshToggled()
{
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->GetProperty("UiCacheMesh")
)->SetElement(0, CacheMesh_->isChecked());
}
void pqPV3FoamReaderPanel::ShowPatchNamesToggled()
{
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->GetProperty("UiShowPatchNames")
)->SetElement(0, ShowPatchNames_->isChecked());
// update the active view
if (this->view())
{
this->view()->render();
}
// OR: update all views
// pqApplicationCore::instance()->render();
}
// ************************************************************************* //

View File

@ -0,0 +1,98 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 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
pqPV3FoamReaderPanel
Description
GUI modifications for the ParaView reader panel
A custom panel for the PV3FoamReader.
SourceFiles
pqPV3FoamReaderPanel.cxx
\*---------------------------------------------------------------------------*/
#ifndef pqPV3FoamReaderPanel_h
#define pqPV3FoamReaderPanel_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 pqPV3FoamReaderPanel Declaration
\*---------------------------------------------------------------------------*/
class pqPV3FoamReaderPanel
:
public pqAutoGeneratedObjectPanel
{
// Private data
Q_OBJECT;
typedef pqAutoGeneratedObjectPanel Superclass;
//- Server Manager Source Proxy
vtkSMSourceProxy* sourceProxy_;
//- CacheMesh checkbox
QCheckBox* CacheMesh_;
//- Show Patch Names checkbox
QCheckBox* ShowPatchNames_;
protected slots:
void CacheMeshToggled();
void ShowPatchNamesToggled();
public:
// Constructors
//- Construct from components
pqPV3FoamReaderPanel(pqProxy*, QWidget*);
//- Destructor
// virtual ~pqPV3FoamReaderPanel();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,18 +1,28 @@
/*=========================================================================
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3FoamReader.cxx,v $
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.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
=========================================================================*/
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkPV3FoamReader.h"
#include "pqApplicationCore.h"
@ -33,10 +43,15 @@
// Foam includes
#include "vtkPV3Foam.H"
#undef EXPERIMENTAL_TIME_CACHING
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
vtkCxxRevisionMacro(vtkPV3FoamReader, "$Revision: 1.5$");
vtkStandardNewMacro(vtkPV3FoamReader);
#undef EXPERIMENTAL_TIME_CACHING
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
vtkPV3FoamReader::vtkPV3FoamReader()
{
@ -109,11 +124,18 @@ vtkPV3FoamReader::vtkPV3FoamReader()
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
vtkPV3FoamReader::~vtkPV3FoamReader()
{
vtkDebugMacro(<<"Deconstructor");
delete foamData_;
if (foamData_)
{
// remove patch names
updatePatchNamesView(false);
delete foamData_;
}
if (FileName)
{
@ -140,6 +162,8 @@ vtkPV3FoamReader::~vtkPV3FoamReader()
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
// Do everything except set the output info
int vtkPV3FoamReader::RequestInformation
(
@ -396,13 +420,35 @@ int vtkPV3FoamReader::RequestData
}
void vtkPV3FoamReader::SetShowPatchNames(const int val)
{
if (ShowPatchNames != val)
{
ShowPatchNames = val;
updatePatchNamesView(ShowPatchNames);
}
}
void vtkPV3FoamReader::updatePatchNamesView(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*>();
@ -414,6 +460,8 @@ void vtkPV3FoamReader::updatePatchNamesView(const bool show)
show
);
}
// use refresh here?
}

View File

@ -1,25 +1,52 @@
/*=========================================================================
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3FoamReader.h,v $
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.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
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
=========================================================================*/
// .NAME vtkPV3FoamReader - reads a dataset in OpenFOAM format
// .SECTION Description
// vtkPV3FoamReader creates an multiblock dataset.
// It uses the OpenFOAM infrastructure (fvMesh, etc) to
// handle mesh and field data.
Class
vtkPV3FoamReader
#ifndef __vtkPV3FoamReader_h
#define __vtkPV3FoamReader_h
Description
reads a dataset in OpenFOAM format
vtkPV3blockMeshReader creates an multiblock dataset.
It uses the OpenFOAM infrastructure (fvMesh, etc) to handle mesh and
field data.
SourceFiles
vtkPV3blockMeshReader.cxx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3FoamReader_h
#define vtkPV3FoamReader_h
// VTK includes
#include "vtkMultiBlockDataSetAlgorithm.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
// VTK forward declarations
class vtkDataArraySelection;
class vtkCallbackCommand;
// Foam forward declarations
namespace Foam
@ -27,13 +54,10 @@ namespace Foam
class vtkPV3Foam;
}
// VTK includes
#include "vtkMultiBlockDataSetAlgorithm.h"
// VTK forward declarations
class vtkDataArraySelection;
class vtkCallbackCommand;
/*---------------------------------------------------------------------------*\
Class vtkPV3FoamReader Declaration
\*---------------------------------------------------------------------------*/
class VTK_IO_EXPORT vtkPV3FoamReader
:
@ -54,16 +78,16 @@ public:
vtkSetStringMacro(FileName);
vtkGetStringMacro(FileName);
// Description:
// GUI update control
vtkSetMacro(UpdateGUI, int);
vtkGetMacro(UpdateGUI, int);
// Description:
// FOAM mesh caching control
vtkSetMacro(CacheMesh, int);
vtkGetMacro(CacheMesh, int);
// Description:
// GUI update control
vtkSetMacro(UpdateGUI, int);
vtkGetMacro(UpdateGUI, int);
// Description:
// FOAM extrapolate internal values onto the patches
vtkSetMacro(ExtrapolatePatches, int);
@ -80,7 +104,7 @@ public:
// Description:
// FOAM display patch names control
vtkSetMacro(ShowPatchNames, int);
virtual void SetShowPatchNames(int);
vtkGetMacro(ShowPatchNames, int);
// Description:

View File

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

View File

@ -109,6 +109,13 @@ void Foam::vtkPV3Foam::convertVolFields
//
// Convert patches - if activated
//
// the name for the interpolated patch point field must be consistent
// with the interpolated volume point field
// this could be done better
const word pointFldName = "volPointInterpolate(" + tf.name() + ')';
for
(
int partId = partInfoPatches_.start();
@ -155,7 +162,7 @@ void Foam::vtkPV3Foam::convertVolFields
convertPatchPointField
(
tf.name(),
pointFldName,
ppInterpList[patchId].faceToPointInterpolate(tpptf)(),
output,
partInfoPatches_,
@ -175,7 +182,7 @@ void Foam::vtkPV3Foam::convertVolFields
convertPatchPointField
(
tf.name(),
pointFldName,
ppInterpList[patchId].faceToPointInterpolate(ptf)(),
output,
partInfoPatches_,

View File

@ -2,6 +2,9 @@
cd ${0%/*} || exit 1 # run from this directory
set -x
# deal with client/server vs combined plugins
rm -f $FOAM_LIBBIN/libPV3blockMeshReader* 2>/dev/null
rm -rf PV3blockMeshReader/Make
wclean libso vtkPV3blockMesh

View File

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

View File

@ -7,7 +7,7 @@
# the pqReader.xml file contains xml defining readers with their
# file extensions and descriptions.
cmake_minimum_required(VERSION 2.4)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
FIND_PACKAGE(ParaView REQUIRED)
INCLUDE(${PARAVIEW_USE_FILE})
@ -33,19 +33,46 @@ SET(
"Single output directory for building all libraries."
)
# Build the server-side plugin
#
# Define combined plugin
#
# Try to extend the auto-generated panel
QT4_WRAP_CPP(MOC_SRCS pqPV3blockMeshReaderPanel.h)
ADD_PARAVIEW_OBJECT_PANEL(IFACES IFACE_SRCS
CLASS_NAME pqPV3blockMeshReaderPanel
XML_NAME PV3blockMeshReader # name of SourceProxy in *SM.xml
XML_GROUP sources
)
ADD_PARAVIEW_PLUGIN(
PV3blockMeshReader_SM "1.0"
SERVER_MANAGER_XML PV3blockMeshReader_SM.xml
SERVER_MANAGER_SOURCES vtkPV3blockMeshReader.cxx
SERVER_MANAGER_SOURCES vtkPV3blockMeshReader.cxx
GUI_INTERFACES ${IFACES}
GUI_SOURCES pqPV3blockMeshReaderPanel.cxx
${MOC_SRCS} ${UI_SRCS} ${IFACE_SRCS}
GUI_RESOURCE_FILES PV3blockMeshReader.xml
)
# #
# # Define the server-side portion of the reader plugin
# #
# ADD_PARAVIEW_PLUGIN(PV3blockMeshReader_SM "1.0"
# SERVER_MANAGER_XML PV3blockMeshReader_SM.xml
# SERVER_MANAGER_SOURCES vtkPV3blockMeshReader.cxx
# )
# #
# # Define the client-side portion of the reader plugin
# #
# ADD_PARAVIEW_PLUGIN(
# PV3blockMeshReader "1.0"
# GUI_RESOURCES PV3blockMeshReader.qrc
# )
# Build the client-side plugin
ADD_PARAVIEW_PLUGIN(
PV3blockMeshReader
"1.0"
GUI_RESOURCES PV3blockMeshReader.qrc
)
TARGET_LINK_LIBRARIES(
PV3blockMeshReader_SM

View File

@ -16,14 +16,13 @@
</Documentation>
</StringVectorProperty>
<!-- Global settings -->
<!-- Show Point Numbers check-box -->
<IntVectorProperty
name="ShowPointNumbers"
name="UiShowPointNumbers"
command="SetShowPointNumbers"
number_of_elements="1"
default_values="1"
is_internal="1"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
@ -44,7 +43,6 @@
</Documentation>
</IntVectorProperty>
<!-- Selections -->
<!-- Available Parts (blocks) array -->
@ -93,6 +91,11 @@
</ArraySelectionDomain>
</StringVectorProperty>
<Hints>
<Property name="FileName" show="0"/>
<Property name="UiShowPointNumbers" show="0"/>
</Hints>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View File

@ -0,0 +1,109 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "pqPV3blockMeshReaderPanel.h"
// QT
#include <QGridLayout>
#include <QCheckBox>
#include <QLabel>
#include <QLayout>
#include <QString>
#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 * * * * * * * * * * * * * * //
pqPV3blockMeshReaderPanel::pqPV3blockMeshReaderPanel
(
pqProxy *proxy,
QWidget *p
)
:
pqAutoGeneratedObjectPanel(proxy, p),
sourceProxy_(vtkSMSourceProxy::SafeDownCast(this->proxy()))
{
// create first sublayout (at top of the panel)
QGridLayout *sect1 = new QGridLayout();
this->PanelLayout->addLayout(sect1, 0, 0, 1, -1);
// checkbox for showing point numbers
ShowPointNumbers_ = new QCheckBox("Show Point Numbers");
ShowPointNumbers_->setChecked(true);
connect
(
ShowPointNumbers_,
SIGNAL(stateChanged(int)),
this,
SLOT(ShowPointNumbersToggled())
);
sect1->addWidget(ShowPointNumbers_);
// immediate update on the Server Manager side
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->GetProperty("UiShowPointNumbers")
)->SetImmediateUpdate(true);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void pqPV3blockMeshReaderPanel::ShowPointNumbersToggled()
{
vtkSMIntVectorProperty::SafeDownCast
(
sourceProxy_->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,94 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2009-2009 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
pqPV3blockMeshReaderPanel
Description
GUI modifications for the ParaView reader panel
A custom panel for the PV3blockMeshReader.
SourceFiles
pqPV3blockMeshReaderPanel.cxx
\*---------------------------------------------------------------------------*/
#ifndef pqPV3blockMeshReaderPanel_h
#define pqPV3blockMeshReaderPanel_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 pqPV3blockMeshReaderPanel Declaration
\*---------------------------------------------------------------------------*/
class pqPV3blockMeshReaderPanel
:
public pqAutoGeneratedObjectPanel
{
// Private data
Q_OBJECT;
typedef pqAutoGeneratedObjectPanel Superclass;
//- Server Manager Source Proxy
vtkSMSourceProxy* sourceProxy_;
//- Show Point Numbers checkbox
QCheckBox* ShowPointNumbers_;
protected slots:
void ShowPointNumbersToggled();
public:
// Constructors
//- Construct from components
pqPV3blockMeshReaderPanel(pqProxy*, QWidget*);
//- Destructor
// virtual ~pqPV3blockMeshReaderPanel();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -1,18 +1,28 @@
/*=========================================================================
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3blockMeshReader.cxx,v $
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.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
=========================================================================*/
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkPV3blockMeshReader.h"
#include "pqApplicationCore.h"
@ -33,9 +43,14 @@
// Foam includes
#include "vtkPV3blockMesh.H"
vtkCxxRevisionMacro(vtkPV3blockMeshReader, "$Revision: 1.5$");
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
vtkCxxRevisionMacro(vtkPV3blockMeshReader, "$Revision:$");
vtkStandardNewMacro(vtkPV3blockMeshReader);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
vtkPV3blockMeshReader::vtkPV3blockMeshReader()
{
Debug = 0;
@ -76,11 +91,18 @@ vtkPV3blockMeshReader::vtkPV3blockMeshReader()
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
vtkPV3blockMeshReader::~vtkPV3blockMeshReader()
{
vtkDebugMacro(<<"Deconstructor");
delete foamData_;
if (foamData_)
{
// remove point numbers
updatePointNumbersView(false);
delete foamData_;
}
if (FileName)
{
@ -95,6 +117,8 @@ vtkPV3blockMeshReader::~vtkPV3blockMeshReader()
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
// Do everything except set the output info
int vtkPV3blockMeshReader::RequestInformation
(
@ -211,16 +235,37 @@ int vtkPV3blockMeshReader::RequestData
}
void vtkPV3blockMeshReader::SetShowPointNumbers(const int val)
{
if (ShowPointNumbers != val)
{
ShowPointNumbers = val;
updatePointNumbersView(ShowPointNumbers);
}
}
void vtkPV3blockMeshReader::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
@ -229,6 +274,8 @@ void vtkPV3blockMeshReader::updatePointNumbersView(const bool show)
show
);
}
// use refresh here?
}

View File

@ -1,38 +1,61 @@
/*=========================================================================
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
Program: Visualization Toolkit
Module: $RCSfile: vtkPV3blockMeshReader.h,v $
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.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
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.
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.
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
=========================================================================*/
// .NAME vtkPV3blockMeshReader - reads a dataset in OpenFOAM bockMesh format
// .SECTION Description
// vtkPV3blockMeshReader creates an multiblock dataset.
// It uses the OpenFOAM infrastructure (blockMesh).
Class
vtkPV3blockMeshReader
#ifndef __vtkPV3blockMeshReader_h
#define __vtkPV3blockMeshReader_h
Description
reads a dataset in OpenFOAM bockMesh format
// Foam forward declarations
namespace Foam
{
class vtkPV3blockMesh;
}
vtkPV3blockMeshReader creates an multiblock dataset.
It uses the OpenFOAM infrastructure (blockMesh).
SourceFiles
vtkPV3blockMeshReader.cxx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3blockMeshReader_h
#define vtkPV3blockMeshReader_h
// VTK includes
#include "vtkMultiBlockDataSetAlgorithm.h"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
// VTK forward declarations
class vtkDataArraySelection;
class vtkCallbackCommand;
namespace Foam
{
class vtkPV3blockMesh;
}
/*---------------------------------------------------------------------------*\
Class vtkPV3blockMeshReader Declaration
\*---------------------------------------------------------------------------*/
class VTK_IO_EXPORT vtkPV3blockMeshReader
:
@ -49,15 +72,16 @@ public:
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:
// FOAM display patch names control
vtkSetMacro(ShowPointNumbers, int);
vtkGetMacro(ShowPointNumbers, int);
// Description:
// Parts (blocks) selection list control
@ -121,6 +145,7 @@ protected:
char* FileName;
private:
//- Disallow default bitwise copy construct
@ -132,6 +157,8 @@ private:
//- 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

View File

@ -7,9 +7,11 @@ EXE_INC = \
-I$(ParaView_INST_DIR)/VTK/Common \
-I$(ParaView_INST_DIR)/VTK/Filtering \
-I$(ParaView_INST_DIR)/VTK/Rendering \
-I../../vtkPV3Readers/lnInclude \
-I../PV3blockMeshReader
LIB_LIBS = \
-lvtkPV3Readers \
-lmeshTools \
-lblockMesh \
$(GLIBS)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -44,6 +44,21 @@ inline void vtkInsertNextOpenFOAMPoint
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

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -219,6 +219,14 @@ Foam::vtkPV3blockMesh::~vtkPV3blockMesh()
Info<< "<end> Foam::vtkPV3blockMesh::~vtkPV3blockMesh" << endl;
}
// Hmm. pointNumberTextActors are not getting removed
//
forAll(pointNumberTextActorsPtrs_, pointI)
{
pointNumberTextActorsPtrs_[pointI]->Delete();
}
pointNumberTextActorsPtrs_.clear();
delete meshPtr_;
}
@ -376,6 +384,7 @@ void Foam::vtkPV3blockMesh::renderPointNumbers
if (show && meshPtr_)
{
const pointField& cornerPts = meshPtr_->blockPointField();
const scalar scaleFactor = meshPtr_->scaleFactor();
pointNumberTextActorsPtrs_.setSize(cornerPts.size());
forAll(cornerPts, pointI)
@ -399,9 +408,9 @@ void Foam::vtkPV3blockMesh::renderPointNumbers
txt->GetPositionCoordinate()->SetValue
(
cornerPts[pointI].x(),
cornerPts[pointI].y(),
cornerPts[pointI].z()
cornerPts[pointI].x()*scaleFactor,
cornerPts[pointI].y()*scaleFactor,
cornerPts[pointI].z()*scaleFactor
);
// Add text to each renderer

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -66,6 +66,7 @@ void Foam::vtkPV3blockMesh::convertMeshBlocks
}
int blockI = 0;
const scalar scaleFactor = blkMesh.scaleFactor();
for
(
@ -103,7 +104,8 @@ void Foam::vtkPV3blockMesh::convertMeshBlocks
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
blockPoints[blockLabels[ptI]]
blockPoints[blockLabels[ptI]],
scaleFactor
);
nodeIds[ptI] = ptI;
@ -159,6 +161,7 @@ void Foam::vtkPV3blockMesh::convertMeshEdges
const curvedEdgeList& edges = blkMesh.edges();
int edgeI = 0;
const scalar scaleFactor = blkMesh.scaleFactor();
for
(
@ -212,7 +215,12 @@ void Foam::vtkPV3blockMesh::convertMeshEdges
vtkIdType pointIds[edgePoints.size()];
forAll(edgePoints, ptI)
{
vtkInsertNextOpenFOAMPoint(vtkpoints, edgePoints[ptI]);
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
edgePoints[ptI],
scaleFactor
);
pointIds[ptI] = ptI;
}
@ -266,6 +274,7 @@ void Foam::vtkPV3blockMesh::convertMeshCorners
label datasetNo = 0; // restart at dataset 0
const pointField& blockPoints = meshPtr_->blockPointField();
const scalar& scaleFactor = meshPtr_->scaleFactor();
if (debug)
{
@ -284,7 +293,12 @@ void Foam::vtkPV3blockMesh::convertMeshCorners
vtkIdType pointId = 0;
forAll(blockPoints, ptI)
{
vtkInsertNextOpenFOAMPoint(vtkpoints, blockPoints[ptI]);
vtkInsertNextOpenFOAMPoint
(
vtkpoints,
blockPoints[ptI],
scaleFactor
);
vtkcells->InsertNextCell(1, &pointId);
pointId++;

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2008-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

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

View File

@ -0,0 +1,10 @@
EXE_INC = \
-I$(ParaView_DIR)/VTK \
-I$(ParaView_INST_DIR) \
-I$(ParaView_INST_DIR)/VTK \
-I$(ParaView_INST_DIR)/VTK/Common \
-I$(ParaView_INST_DIR)/VTK/Filtering \
-I$(ParaView_INST_DIR)/VTK/Rendering
LIB_LIBS = \
$(GLIBS)

View File

@ -0,0 +1,330 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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
Misc helper methods and utilities
\*---------------------------------------------------------------------------*/
#include "vtkPV3Readers.H"
// Foam includes
#include "IFstream.H"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::vtkPV3Readers, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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 fileScope
} // End namespace Foam
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV3Readers::AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const partInfo& selector,
const label datasetNo,
const std::string& datasetName
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (!block)
{
if (blockDO)
{
FatalErrorIn("Foam::vtkPV3Readers::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(),
selector.name()
);
}
if (datasetName.size())
{
block->GetMetaData(datasetNo)->Set
(
vtkCompositeDataSet::NAME(),
datasetName.c_str()
);
}
}
vtkDataSet* Foam::vtkPV3Readers::GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
)
{
const int blockNo = selector.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::vtkPV3Readers::GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const partInfo& selector
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (block)
{
return block->GetNumberOfBlocks();
}
return 0;
}
// Foam::word Foam::vtkPV3Readers::getPartName(int partId)
// {
// return getFirstWord(reader_->GetPartArrayName(partId));
// }
Foam::wordHashSet Foam::vtkPV3Readers::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::vtkPV3Readers::getSelected
(
vtkDataArraySelection* select,
const partInfo& selector
)
{
int nElem = select->GetNumberOfArrays();
wordHashSet selections(2*nElem);
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections.insert(getFirstWord(select->GetArrayName(elemI)));
}
}
return selections;
}
Foam::stringList Foam::vtkPV3Readers::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::vtkPV3Readers::getSelectedArrayEntries
(
vtkDataArraySelection* select,
const partInfo& selector
)
{
stringList selections(selector.size());
label nElem = 0;
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
if (select->GetArraySetting(elemI))
{
selections[nElem++] = select->GetArrayName(elemI);
}
}
selections.setSize(nElem);
if (debug)
{
Info<< "available(";
for (int elemI = selector.start(); elemI < selector.end(); ++elemI)
{
Info<< " \"" << select->GetArrayName(elemI) << "\"";
}
Info<< " )\nselected(";
forAll(selections, elemI)
{
Info<< " " << selections[elemI];
}
Info<< " )\n";
}
return selections;
}
void Foam::vtkPV3Readers::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;
}
}
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,229 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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
Namespace
Foam::vtkPV3Readers
Description
A collection of helper functions when building a reader interface in
ParaView3.
SourceFiles
vtkPV3Readers.C
\*---------------------------------------------------------------------------*/
#ifndef vtkPV3Readers_H
#define vtkPV3Readers_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 "HashSet.H"
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
class vtkDataSet;
class vtkPoints;
class vtkPV3FoamReader;
class vtkRenderer;
class vtkTextActor;
class vtkMultiBlockDataSet;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkIndent;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace vtkPV3Readers
{
//- Declare name of the class and its debug switch
NamespaceName("vtkPV3Readers");
//- Bookkeeping for GUI checklists and the multi-block organization
class partInfo
{
const char *name_;
int block_;
int start_;
int size_;
public:
partInfo(const char *name, const int blockNo=0)
:
name_(name),
block_(blockNo),
start_(-1),
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;
}
const char* name() const
{
return name_;
}
int start() const
{
return start_;
}
int end() const
{
return start_ + size_;
}
int size() const
{
return size_;
}
bool empty() 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;
}
};
//- Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
void AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const partInfo& selector,
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
vtkDataSet* GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
);
//- Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
// ununsed at the moment
label GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const partInfo& selector
);
//- Retrieve the current selections as a wordHashSet
wordHashSet getSelected
(
vtkDataArraySelection* select
);
//- Retrieve a sub-list of the current selections
wordHashSet getSelected
(
vtkDataArraySelection*,
const partInfo&
);
//- Retrieve the current selections
stringList getSelectedArrayEntries(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
stringList getSelectedArrayEntries
(
vtkDataArraySelection* select,
const partInfo& selector
);
//- Set selection(s)
void setSelectedArrayEntries
(
vtkDataArraySelection*,
const stringList&
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace vtkPV3
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

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

View File

@ -61,8 +61,9 @@ $(sha1)/SHA1Digest.C
primitives/random/Random.C
containers/HashTables/HashTbl/HashTblCore.C
containers/HashTables/HashTable/HashTableName.C
containers/HashTables/StaticHashTable/StaticHashTableName.C
containers/HashTables/StaticHashTable/StaticHashTableCore.C
containers/Lists/SortableList/ParSortableListName.C
containers/Lists/PackedList/PackedListName.C
containers/Lists/ListOps/ListOps.C

View File

@ -0,0 +1,645 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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
\*---------------------------------------------------------------------------*/
#ifndef HashTbl_C
#define HashTbl_C
#include "HashTbl.H"
#include "List.H"
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
Foam::label Foam::HashTblCore::canonicalSize(const label size)
{
if (size < 1)
{
return 0;
}
// enforce power of two
unsigned int goodSize = size;
if (goodSize & (goodSize - 1))
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
}
return goodSize;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::HashTbl<T, Key, Hash>::HashTbl(const label size)
:
HashTblCore(),
nElmts_(0),
tableSize_(HashTblCore::canonicalSize(size)),
table_(NULL)
{
if (tableSize_)
{
table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[hashIdx] = 0;
}
}
}
template<class T, class Key, class Hash>
Foam::HashTbl<T, Key, Hash>::HashTbl(const HashTbl<T, Key, Hash>& ht)
:
HashTblCore(),
nElmts_(0),
tableSize_(ht.tableSize_),
table_(NULL)
{
if (tableSize_)
{
table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[hashIdx] = 0;
}
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
{
insert(iter.key(), *iter);
}
}
}
template<class T, class Key, class Hash>
Foam::HashTbl<T, Key, Hash>::HashTbl
(
const Xfer<HashTbl<T, Key, Hash> >& ht
)
:
HashTblCore(),
nElmts_(0),
tableSize_(0),
table_(NULL)
{
transfer(ht());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::HashTbl<T, Key, Hash>::~HashTbl()
{
if (table_)
{
clear();
delete[] table_;
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::found(const Key& key) const
{
if (nElmts_)
{
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == ep->key_)
{
return true;
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::found(const Key& key) : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
return false;
}
template<class T, class Key, class Hash>
typename Foam::HashTbl<T, Key, Hash>::iterator
Foam::HashTbl<T, Key, Hash>::find
(
const Key& key
)
{
if (nElmts_)
{
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == ep->key_)
{
return iterator(this, ep, hashIdx);
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::find(const Key& key) : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
return iterator();
}
template<class T, class Key, class Hash>
typename Foam::HashTbl<T, Key, Hash>::const_iterator
Foam::HashTbl<T, Key, Hash>::find
(
const Key& key
) const
{
if (nElmts_)
{
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == ep->key_)
{
return const_iterator(this, ep, hashIdx);
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::find(const Key& key) const : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
return const_iterator();
}
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTbl<T, Key, Hash>::toc() const
{
List<Key> keys(nElmts_);
label keyI = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
keys[keyI++] = iter.key();
}
return keys;
}
template<class T, class Key, class Hash>
Foam::List<Key> Foam::HashTbl<T, Key, Hash>::sortedToc() const
{
List<Key> sortedLst = this->toc();
sort(sortedLst);
return sortedLst;
}
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::set
(
const Key& key,
const T& newEntry,
const bool protect
)
{
if (!tableSize_)
{
resize(2);
}
const label hashIdx = hashKeyIndex(key);
hashedEntry* existing = 0;
hashedEntry* prev = 0;
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == ep->key_)
{
existing = ep;
break;
}
prev = ep;
}
// not found, insert it at the head
if (!existing)
{
table_[hashIdx] = new hashedEntry(key, table_[hashIdx], newEntry);
nElmts_++;
if (double(nElmts_)/tableSize_ > 0.8 && tableSize_ < maxTableSize)
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::set"
"(const Key& key, T newEntry) : "
"Doubling table size\n";
}
# endif
resize(2*tableSize_);
}
}
else if (protect)
{
// found - but protected from overwriting
// this corresponds to the STL 'insert' convention
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::set"
"(const Key& key, T newEntry, true) : "
"Cannot insert " << key << " already in hash table\n";
}
# endif
return false;
}
else
{
// found - overwrite existing entry
// this corresponds to the Perl convention
hashedEntry* ep = new hashedEntry(key, existing->next_, newEntry);
// replace existing element - within list or insert at the head
if (prev)
{
prev->next_ = ep;
}
else
{
table_[hashIdx] = ep;
}
delete existing;
}
return true;
}
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::iteratorBase::erase()
{
// note: entryPtr_ is NULL for end(), so this catches that too
if (entryPtr_)
{
// Search element before entryPtr_
hashedEntry* prev = 0;
for
(
hashedEntry* ep = hashTable_->table_[hashIndex_];
ep;
ep = ep->next_
)
{
if (ep == entryPtr_)
{
break;
}
prev = ep;
}
if (prev)
{
// has an element before entryPtr - reposition to there
prev->next_ = entryPtr_->next_;
delete entryPtr_;
entryPtr_ = prev;
}
else
{
// entryPtr was first element on SLList
hashTable_->table_[hashIndex_] = entryPtr_->next_;
delete entryPtr_;
// assign any non-NULL pointer value so it doesn't look
// like end()/cend()
entryPtr_ = reinterpret_cast<hashedEntry*>(this);
// Mark with special hashIndex value to signal it has been rewound.
// The next increment will bring it back to the present location.
//
// From the current position 'curPos', we wish to continue at
// prevPos='curPos-1', which we mark as markPos='-curPos-1'.
// The negative lets us notice it is special, the extra '-1'
// is needed to avoid ambiguity for position '0'.
// To retrieve prevPos, we would later use '-(markPos+1) - 1'
hashIndex_ = -hashIndex_ - 1;
}
hashTable_->nElmts_--;
return true;
}
else
{
return false;
}
}
// NOTE:
// We use (const iterator&) here, but manipulate its contents anyhow.
// The parameter should be (iterator&), but then the compiler doesn't find
// it correctly and tries to call as (iterator) instead.
//
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::erase(const iterator& cit)
{
// adjust iterator after erase
return const_cast<iterator&>(cit).erase();
}
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::erase(const Key& key)
{
return erase(find(key));
}
template<class T, class Key, class Hash>
Foam::label Foam::HashTbl<T, Key, Hash>::erase(const UList<Key>& keys)
{
const label nTotal = nElmts_;
label count = 0;
// Remove listed keys from this table - terminates early if possible
for (label keyI = 0; count < nTotal && keyI < keys.size(); ++keyI)
{
if (erase(keys[keyI]))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
template<class AnyType, class AnyHash>
Foam::label Foam::HashTbl<T, Key, Hash>::erase
(
const HashTbl<AnyType, Key, AnyHash>& rhs
)
{
label count = 0;
// Remove rhs keys from this table - terminates early if possible
// Could optimize depending on which hash is smaller ...
for (iterator iter = begin(); iter != end(); ++iter)
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::resize(const label sz)
{
label newSize = HashTblCore::canonicalSize(sz);
if (newSize == tableSize_)
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTbl<T, Key, Hash>::resize(const label) : "
<< "new table size == old table size\n";
}
# endif
return;
}
HashTbl<T, Key, Hash>* tmpTable = new HashTbl<T, Key, Hash>(newSize);
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tmpTable->insert(iter.key(), *iter);
}
label oldSize = tableSize_;
tableSize_ = tmpTable->tableSize_;
tmpTable->tableSize_ = oldSize;
hashedEntry** oldTable = table_;
table_ = tmpTable->table_;
tmpTable->table_ = oldTable;
delete tmpTable;
}
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::clear()
{
if (nElmts_)
{
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
if (table_[hashIdx])
{
hashedEntry* ep = table_[hashIdx];
while (hashedEntry* next = ep->next_)
{
delete ep;
ep = next;
}
delete ep;
table_[hashIdx] = 0;
}
}
nElmts_ = 0;
}
}
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::clearStorage()
{
clear();
resize(0);
}
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::shrink()
{
const label newSize = HashTblCore::canonicalSize(nElmts_);
if (newSize < tableSize_)
{
// avoid having the table disappear on us
resize(newSize ? newSize : 2);
}
}
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::transfer(HashTbl<T, Key, Hash>& ht)
{
// as per the Destructor
if (table_)
{
clear();
delete[] table_;
}
tableSize_ = ht.tableSize_;
ht.tableSize_ = 0;
table_ = ht.table_;
ht.table_ = NULL;
nElmts_ = ht.nElmts_;
ht.nElmts_ = 0;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
void Foam::HashTbl<T, Key, Hash>::operator=
(
const HashTbl<T, Key, Hash>& rhs
)
{
// Check for assignment to self
if (this == &rhs)
{
FatalErrorIn
(
"HashTbl<T, Key, Hash>::operator="
"(const HashTbl<T, Key, Hash>&)"
) << "attempted assignment to self"
<< abort(FatalError);
}
// could be zero-sized from a previous transfer()
if (!tableSize_)
{
resize(rhs.tableSize_);
}
else
{
clear();
}
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
insert(iter.key(), *iter);
}
}
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::operator==
(
const HashTbl<T, Key, Hash>& rhs
) const
{
// sizes (number of keys) must match
if (size() != rhs.size())
{
return false;
}
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
if (fnd == cend() || fnd() != iter())
{
return false;
}
}
return true;
}
template<class T, class Key, class Hash>
bool Foam::HashTbl<T, Key, Hash>::operator!=
(
const HashTbl<T, Key, Hash>& rhs
) const
{
return !(operator==(rhs));
}
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "HashTblIO.C"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,563 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 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::HashTbl
Description
An STL-conforming hash table.
Note
Hashing index collisions are handled via chaining using a singly-linked
list with the colliding entry being added to the head of the linked
list. Thus copying the hash table (or indeed even resizing it) will
often result in a different hash order. Use a sorted table-of-contents
when the hash order is important.
SourceFiles
HashTblI.H
HashTbl.C
HashTblIO.C
\*---------------------------------------------------------------------------*/
#ifndef HashTbl_H
#define HashTbl_H
#include "label.H"
#include "uLabel.H"
#include "word.H"
#include "Xfer.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class T> class List;
template<class T> class UList;
template<class T, class Key, class Hash> class HashTbl;
template<class T, class Key, class Hash> class HashPtrTable;
template<class T, class Key, class Hash>
Istream& operator>>(Istream&, HashTbl<T, Key, Hash>&);
template<class T, class Key, class Hash>
Ostream& operator<<(Ostream&, const HashTbl<T, Key, Hash>&);
/*---------------------------------------------------------------------------*\
Class HashTblCore Declaration
\*---------------------------------------------------------------------------*/
//- Template-invariant bits for HashTbl
struct HashTblCore
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Maximum allowable table size
static const label maxTableSize;
//- Construct null
HashTblCore()
{}
//- Define template name and debug
ClassName("HashTbl");
//- A zero-sized end iterator
struct iteratorEnd
{
//- Construct null
iteratorEnd()
{}
};
//- iteratorEnd set to beyond the end of any HashTbl
static iteratorEnd cend()
{
return iteratorEnd();
}
//- iteratorEnd set to beyond the end of any HashTbl
static iteratorEnd end()
{
return iteratorEnd();
}
};
/*---------------------------------------------------------------------------*\
Class HashTbl Declaration
\*---------------------------------------------------------------------------*/
template<class T, class Key=word, class Hash=string::hash>
class HashTbl
:
public HashTblCore
{
// Private data type for table entries
//- Structure to hold a hashed entry with SLList for collisions
struct hashedEntry
{
//- The lookup key
Key key_;
//- Pointer to next hashedEntry in sub-list
hashedEntry* next_;
//- The data object
T obj_;
//- Construct from key, next pointer and object
inline hashedEntry(const Key&, hashedEntry* next, const T&);
private:
//- Disallow default bitwise copy construct
hashedEntry(const hashedEntry&);
//- Disallow default bitwise assignment
void operator=(const hashedEntry&);
};
// Private data: size of table, the table and current number of elements
//- The current number of elements in table
label nElmts_;
//- Number of primary entries allocated in table
label tableSize_;
//- The table of primary entries
hashedEntry** table_;
// Private Member Functions
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Return the hash index of the Key within the current table size.
// No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const;
//- Assign a new hashedEntry to a possibly already existing key
bool set(const Key&, const T& newElmt, bool protect);
public:
// Forward declaration of iterators
class iteratorBase;
class iterator;
class const_iterator;
//- Declare friendship with the HashPtrTable class
template<class T2, class Key2, class Hash2>
friend class HashPtrTable;
//- Declare friendship with the iteratorBase
friend class iteratorBase;
//- Declare friendship with the iterator
friend class iterator;
//- Declare friendship with the const_iterator
friend class const_iterator;
// Constructors
//- Construct given initial table size
HashTbl(const label size = 128);
//- Construct from Istream
HashTbl(Istream&, const label size = 128);
//- Construct as copy
HashTbl(const HashTbl<T, Key, Hash>&);
//- Construct by transferring the parameter contents
HashTbl(const Xfer<HashTbl<T, Key, Hash> >&);
// Destructor
~HashTbl();
// Member Functions
// Access
//- The size of the underlying table
inline label capacity() const;
//- Return number of elements in table
inline label size() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashedEntry is found in table
bool found(const Key&) const;
//- Find and return an iterator set at the hashedEntry
// If not found iterator = end()
iterator find(const Key&);
//- Find and return an const_iterator set at the hashedEntry
// If not found iterator = end()
const_iterator find(const Key&) const;
//- Return the table of contents
List<Key> toc() const;
//- Return the table of contents as a sorted list
List<Key> sortedToc() const;
//- Print information
Ostream& printInfo(Ostream&) const;
// Edit
//- Insert a new hashedEntry
inline bool insert(const Key&, const T& newElmt);
//- Assign a new hashedEntry, overwriting existing entries
inline bool set(const Key&, const T& newElmt);
//- Erase a hashedEntry specified by given iterator
// This invalidates the iterator until the next operator++
bool erase(const iterator&);
//- Erase a hashedEntry specified by the given key
bool erase(const Key&);
//- Remove entries given by the listed keys from this HashTbl
// Return the number of elements removed
label erase(const UList<Key>&);
//- Remove entries given by the given keys from this HashTbl
// Return the number of elements removed.
// The parameter HashTbl needs the same type of key, but the
// type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash>
label erase(const HashTbl<AnyType, Key, AnyHash>&);
//- Resize the hash table for efficiency
void resize(const label newSize);
//- Clear all entries from table
void clear();
//- Clear the table entries and the table itself.
// Equivalent to clear() followed by resize(0)
void clearStorage();
//- Shrink the allocated table to approx. twice number of elements
void shrink();
//- Transfer the contents of the argument table into this table
// and annull the argument table.
void transfer(HashTbl<T, Key, Hash>&);
//- Transfer contents to the Xfer container
inline Xfer< HashTbl<T, Key, Hash> > xfer();
// Member Operators
//- Find and return a hashedEntry
inline T& operator[](const Key&);
//- Find and return a hashedEntry
inline const T& operator[](const Key&) const;
//- Find and return a hashedEntry, create it null if not present
inline T& operator()(const Key&);
//- Assignment
void operator=(const HashTbl<T, Key, Hash>&);
//- Equality. Hash tables are equal if the keys and values are equal.
// Independent of table storage size and table order.
bool operator==(const HashTbl<T, Key, Hash>&) const;
//- The opposite of the equality operation. Takes linear time.
bool operator!=(const HashTbl<T, Key, Hash>&) const;
// STL type definitions
//- Type of values the HashTbl contains.
typedef T value_type;
//- Type that can be used for storing into HashTbl::value_type
// objects. This type is usually List::value_type&.
typedef T& reference;
//- Type that can be used for storing into constant
// HashTbl::value_type objects. This type is usually const
// HashTbl::value_type&.
typedef const T& const_reference;
//- The type that can represent the size of a HashTbl.
typedef label size_type;
// Iterators and helpers
//- The iterator base for HashTbl
// Note: data and functions are protected, to allow reuse by iterator
// and prevent most external usage.
// iterator and const_iterator have the same size, allowing
// us to reinterpret_cast between them (if desired)
class iteratorBase
{
// Private Data
//- Pointer to the HashTbl for which this is an iterator
// This also lets us use the default bitwise copy/assignment
HashTbl<T, Key, Hash>* hashTable_;
//- Current element
hashedEntry* entryPtr_;
//- Current hash index
label hashIndex_;
protected:
// Protected Member Functions
// Constructors
//- Construct null - equivalent to an 'end' position
inline iteratorBase();
//- Construct from hash table, moving to its 'begin' position
inline explicit iteratorBase
(
const HashTbl<T, Key, Hash>* curHashTbl
);
//- Construct from hash table, element and hash index
inline explicit iteratorBase
(
const HashTbl<T, Key, Hash>* curHashTbl,
const hashedEntry* elmt,
const label hashIndex
);
//- Increment to the next position
inline void increment();
//- Erase the HashTbl element at the current position
bool erase();
//- Return non-const access to referenced object
inline T& object();
//- Return const access to referenced object
inline const T& cobject() const;
public:
// Member operators
// Access
//- Return the Key corresponding to the iterator
inline const Key& key() const;
//- Compare hashedEntry element pointers
inline bool operator==(const iteratorBase&) const;
inline bool operator!=(const iteratorBase&) const;
//- Compare hashedEntry to iteratorEnd pointers
inline bool operator==(const iteratorEnd&) const;
inline bool operator!=(const iteratorEnd&) const;
};
//- An STL-conforming iterator
class iterator
:
public iteratorBase
{
friend class HashTbl;
// Private Member Functions
//- Construct from hash table, moving to its 'begin' position
inline explicit iterator
(
HashTbl<T, Key, Hash>* curHashTbl
);
//- Construct from hash table, element and hash index
inline explicit iterator
(
HashTbl<T, Key, Hash>* curHashTbl,
hashedEntry* elmt,
const label hashIndex
);
public:
// Constructors
//- Construct null (end iterator)
inline iterator();
//- Construct end iterator
inline iterator(const iteratorEnd&);
// Member operators
//- Conversion to a const_iterator
inline operator const_iterator() const;
// Access
//- Return referenced hash value
inline T& operator*();
inline T& operator()();
//- Return referenced hash value
inline const T& operator*() const;
inline const T& operator()() const;
inline iterator& operator++();
inline iterator operator++(int);
};
//- iterator set to the begining of the HashTbl
inline iterator begin();
// STL const_iterator
//- An STL-conforming const_iterator
class const_iterator
:
public iteratorBase
{
friend class HashTbl;
// Private Member Functions
//- Construct from hash table, moving to its 'begin' position
inline explicit const_iterator
(
const HashTbl<T, Key, Hash>* curHashTbl
);
//- Construct from hash table, element and hash index
inline explicit const_iterator
(
const HashTbl<T, Key, Hash>* curHashTbl,
const hashedEntry* elmt,
const label hashIndex
);
public:
// Constructors
//- Construct null (end iterator)
inline const_iterator();
//- Construct end iterator
inline const_iterator(const iteratorEnd&);
// Member operators
// Access
//- Return referenced hash value
inline const T& operator*() const;
inline const T& operator()() const;
inline const_iterator& operator++();
inline const_iterator operator++(int);
};
//- const_iterator set to the beginning of the HashTbl
inline const_iterator cbegin() const;
//- const_iterator set to the beginning of the HashTbl
inline const_iterator begin() const;
// IOstream Operator
friend Istream& operator>> <T, Key, Hash>
(
Istream&,
HashTbl<T, Key, Hash>&
);
friend Ostream& operator<< <T, Key, Hash>
(
Ostream&,
const HashTbl<T, Key, Hash>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "HashTblI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifndef NoHashTblC
#ifdef NoRepository
# include "HashTbl.C"
#endif
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "HashTbl.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::HashTblCore, 0);
const Foam::label Foam::HashTblCore::maxTableSize
(
Foam::HashTblCore::canonicalSize
(
Foam::labelMax/2
)
);
// ************************************************************************* //

View File

@ -0,0 +1,530 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "error.H"
// * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::hashedEntry::hashedEntry
(
const Key& key,
hashedEntry* next,
const T& obj
)
:
key_(key),
next_(next),
obj_(obj)
{}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label
Foam::HashTbl<T, Key, Hash>::hashKeyIndex(const Key& key) const
{
// size is power of two - this is the modulus
return Hash()(key) & (tableSize_ - 1);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTbl<T, Key, Hash>::capacity() const
{
return tableSize_;
}
template<class T, class Key, class Hash>
inline Foam::label Foam::HashTbl<T, Key, Hash>::size() const
{
return nElmts_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::empty() const
{
return !nElmts_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::insert
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, true);
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::set
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, false);
}
template<class T, class Key, class Hash>
inline Foam::Xfer<Foam::HashTbl<T, Key, Hash> >
Foam::HashTbl<T, Key, Hash>::xfer()
{
return xferMove(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline T& Foam::HashTbl<T, Key, Hash>::operator[](const Key& key)
{
iterator iter = find(key);
if (iter == end())
{
FatalErrorIn("HashTbl<T, Key, Hash>::operator[](const Key&)")
<< key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
return *iter;
}
template<class T, class Key, class Hash>
inline const T& Foam::HashTbl<T, Key, Hash>::operator[](const Key& key) const
{
const_iterator iter = find(key);
if (iter == cend())
{
FatalErrorIn("HashTbl<T, Key, Hash>::operator[](const Key&) const")
<< key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
return *iter;
}
template<class T, class Key, class Hash>
inline T& Foam::HashTbl<T, Key, Hash>::operator()(const Key& key)
{
iterator iter = find(key);
if (iter == end())
{
insert(key, T());
return *find(key);
}
else
{
return *iter;
}
}
// * * * * * * * * * * * * * * * iterator base * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iteratorBase::iteratorBase()
:
hashTable_(0),
entryPtr_(0),
hashIndex_(0)
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iteratorBase::iteratorBase
(
const HashTbl<T, Key, Hash>* hashTbl
)
:
hashTable_(const_cast<HashTbl<T, Key, Hash>*>(hashTbl)),
entryPtr_(0),
hashIndex_(0)
{
if (hashTable_->nElmts_ && hashTable_->table_)
{
// find first non-NULL table entry
while
(
!(entryPtr_ = hashTable_->table_[hashIndex_])
&& ++hashIndex_ < hashTable_->tableSize_
)
{}
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
hashIndex_ = 0;
}
}
}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iteratorBase::iteratorBase
(
const HashTbl<T, Key, Hash>* hashTbl,
const hashedEntry* elmt,
const label hashIndex
)
:
hashTable_(const_cast<HashTbl<T, Key, Hash>*>(hashTbl)),
entryPtr_(const_cast<hashedEntry*>(elmt)),
hashIndex_(hashIndex)
{}
template<class T, class Key, class Hash>
inline void
Foam::HashTbl<T, Key, Hash>::iteratorBase::increment()
{
// A negative index is a special value from erase
if (hashIndex_ < 0)
{
// the markPos='-curPos-1', but we wish to continue at 'curPos-1'
// thus use '-(markPos+1) -1'
hashIndex_ = -(hashIndex_+1) - 1;
}
else if (entryPtr_)
{
if (entryPtr_->next_)
{
// Move to next element on the SLList
entryPtr_ = entryPtr_->next_;
return;
}
}
// else
// {
// // if we reach here (entryPtr_ is NULL) it is already at the end()
// // we should probably stop
// }
// Step to the next table entry
while
(
++hashIndex_ < hashTable_->tableSize_
&& !(entryPtr_ = hashTable_->table_[hashIndex_])
)
{}
if (hashIndex_ >= hashTable_->tableSize_)
{
// make into an end iterator
entryPtr_ = 0;
hashIndex_ = 0;
}
}
template<class T, class Key, class Hash>
inline
const Key& Foam::HashTbl<T, Key, Hash>::iteratorBase::key() const
{
return entryPtr_->key_;
}
template<class T, class Key, class Hash>
inline T&
Foam::HashTbl<T, Key, Hash>::iteratorBase::object()
{
return entryPtr_->obj_;
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTbl<T, Key, Hash>::iteratorBase::cobject() const
{
return entryPtr_->obj_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::iteratorBase::operator==
(
const iteratorBase& iter
) const
{
return entryPtr_ == iter.entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::iteratorBase::operator!=
(
const iteratorBase& iter
) const
{
return entryPtr_ != iter.entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::iteratorBase::operator==
(
const iteratorEnd&
) const
{
return !entryPtr_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTbl<T, Key, Hash>::iteratorBase::operator!=
(
const iteratorEnd&
) const
{
return entryPtr_;
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iterator::iterator()
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iterator::iterator
(
const iteratorEnd&
)
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iterator::iterator
(
HashTbl<T, Key, Hash>* hashTbl
)
:
iteratorBase(hashTbl)
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iterator::iterator
(
HashTbl<T, Key, Hash>* hashTbl,
hashedEntry* elmt,
const label hashIndex
)
:
iteratorBase(hashTbl, elmt, hashIndex)
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::iterator::operator
typename Foam::HashTbl<T, Key, Hash>::const_iterator() const
{
return *reinterpret_cast
<
const typename Foam::HashTbl<T, Key, Hash>::const_iterator*
>(this);
}
template<class T, class Key, class Hash>
inline T&
Foam::HashTbl<T, Key, Hash>::iterator::operator*()
{
return this->object();
}
template<class T, class Key, class Hash>
inline T&
Foam::HashTbl<T, Key, Hash>::iterator::operator()()
{
return this->object();
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTbl<T, Key, Hash>::iterator::operator*() const
{
return this->cobject();
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTbl<T, Key, Hash>::iterator::operator()() const
{
return this->cobject();
}
template<class T, class Key, class Hash>
inline
typename Foam::HashTbl<T, Key, Hash>::iterator&
Foam::HashTbl<T, Key, Hash>::iterator::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTbl<T, Key, Hash>::iterator
Foam::HashTbl<T, Key, Hash>::iterator::operator++(int)
{
iterator old = *this;
this->increment();
return old;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTbl<T, Key, Hash>::iterator
Foam::HashTbl<T, Key, Hash>::begin()
{
return iterator(this);
}
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::const_iterator::const_iterator()
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::const_iterator::const_iterator
(
const iteratorEnd&
)
:
iteratorBase()
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::const_iterator::const_iterator
(
const HashTbl<T, Key, Hash>* hashTbl
)
:
iteratorBase(hashTbl)
{}
template<class T, class Key, class Hash>
inline Foam::HashTbl<T, Key, Hash>::const_iterator::const_iterator
(
const HashTbl<T, Key, Hash>* hashTbl,
const hashedEntry* elmt,
const label hashIndex
)
:
iteratorBase(hashTbl, elmt, hashIndex)
{}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTbl<T, Key, Hash>::const_iterator::operator*() const
{
return this->cobject();
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTbl<T, Key, Hash>::const_iterator::operator()() const
{
return this->cobject();
}
template<class T, class Key, class Hash>
inline
typename Foam::HashTbl<T, Key, Hash>::const_iterator&
Foam::HashTbl<T, Key, Hash>::const_iterator::operator++()
{
this->increment();
return *this;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTbl<T, Key, Hash>::const_iterator
Foam::HashTbl<T, Key, Hash>::const_iterator::operator++(int)
{
const_iterator old = *this;
this->increment();
return old;
}
template<class T, class Key, class Hash>
inline typename Foam::HashTbl<T, Key, Hash>::const_iterator
Foam::HashTbl<T, Key, Hash>::cbegin() const
{
return const_iterator(this);
}
template<class T, class Key, class Hash>
inline typename Foam::HashTbl<T, Key, Hash>::const_iterator
Foam::HashTbl<T, Key, Hash>::begin() const
{
return this->cbegin();
}
// ************************************************************************* //

View File

@ -0,0 +1,249 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "HashTbl.H"
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::HashTbl<T, Key, Hash>::HashTbl(Istream& is, const label size)
:
HashTblCore(),
nElmts_(0),
tableSize_(HashTblCore::canonicalSize(size)),
table_(NULL)
{
if (tableSize_)
{
table_ = new hashedEntry*[tableSize_];
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[hashIdx] = 0;
}
}
operator>>(is, *this);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Ostream&
Foam::HashTbl<T, Key, Hash>::printInfo(Ostream& os) const
{
label used = 0;
label maxChain = 0;
unsigned avgChain = 0;
for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
{
label count = 0;
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
++count;
}
if (count)
{
++used;
avgChain += count;
if (maxChain < count)
{
maxChain = count;
}
}
}
os << "HashTbl<T,Key,Hash>"
<< " elements:" << size() << " slots:" << used << "/" << tableSize_
<< " chaining(avg/max):" << (used ? (float(avgChain)/used) : 0)
<< "/" << maxChain << endl;
return os;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Istream& Foam::operator>>
(
Istream& is,
HashTbl<T, Key, Hash>& L
)
{
is.fatalCheck("operator>>(Istream&, HashTbl<T, Key, Hash>&)");
// Anull list
L.clear();
is.fatalCheck("operator>>(Istream&, HashTbl<T, Key, Hash>&)");
token firstToken(is);
is.fatalCheck
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&) : "
"reading first token"
);
if (firstToken.isLabel())
{
label s = firstToken.labelToken();
// Read beginning of contents
char delimiter = is.readBeginList("HashTbl<T, Key, Hash>");
if (s)
{
if (2*s > L.tableSize_)
{
L.resize(2*s);
}
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
{
Key key;
is >> key;
L.insert(key, pTraits<T>(is));
is.fatalCheck
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&) : "
"reading entry"
);
}
}
else
{
FatalIOErrorIn
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
}
// Read end of contents
is.readEndList("HashTbl");
}
else if (firstToken.isPunctuation())
{
if (firstToken.pToken() != token::BEGIN_LIST)
{
FatalIOErrorIn
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
token lastToken(is);
while
(
!(
lastToken.isPunctuation()
&& lastToken.pToken() == token::END_LIST
)
)
{
is.putBack(lastToken);
Key key;
is >> key;
T element;
is >> element;
L.insert(key, element);
is.fatalCheck
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&) : "
"reading entry"
);
is >> lastToken;
}
}
else
{
FatalIOErrorIn
(
"operator>>(Istream&, HashTbl<T, Key, Hash>&)",
is
) << "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
}
is.fatalCheck("operator>>(Istream&, HashTbl<T, Key, Hash>&)");
return is;
}
template<class T, class Key, class Hash>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const HashTbl<T, Key, Hash>& L
)
{
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
// Write contents
for
(
typename HashTbl<T, Key, Hash>::const_iterator iter = L.cbegin();
iter != L.cend();
++iter
)
{
os << iter.key() << token::SPACE << iter() << nl;
}
// Write end delimiter
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const HashTbl&)");
return os;
}
// ************************************************************************* //

View File

@ -33,8 +33,7 @@ License
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::label Foam::StaticHashTable<T, Key, Hash>::canonicalSize(const label size)
Foam::label Foam::StaticHashTableCore::canonicalSize(const label size)
{
if (size < 1)
{
@ -64,8 +63,8 @@ Foam::label Foam::StaticHashTable<T, Key, Hash>::canonicalSize(const label size)
template<class T, class Key, class Hash>
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)
:
StaticHashTableName(),
keys_(canonicalSize(size)),
StaticHashTableCore(),
keys_(StaticHashTableCore::canonicalSize(size)),
objects_(keys_.size()),
nElmts_(0),
endIter_(*this, keys_.size(), 0),
@ -89,7 +88,7 @@ Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
const StaticHashTable<T, Key, Hash>& ht
)
:
StaticHashTableName(),
StaticHashTableCore(),
keys_(ht.keys_),
objects_(ht.objects_),
nElmts_(ht.nElmts_),
@ -105,7 +104,7 @@ Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
const Xfer< StaticHashTable<T, Key, Hash> >& ht
)
:
StaticHashTableName(),
StaticHashTableCore(),
keys_(0),
objects_(0),
nElmts_(0),
@ -224,15 +223,15 @@ Foam::StaticHashTable<T, Key, Hash>::find
template<class T, class Key, class Hash>
Foam::List<Key> Foam::StaticHashTable<T, Key, Hash>::toc() const
{
List<Key> tofc(nElmts_);
label i = 0;
List<Key> keys(nElmts_);
label keyI = 0;
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tofc[i++] = iter.key();
keys[keyI++] = iter.key();
}
return tofc;
return keys;
}
@ -319,24 +318,9 @@ bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
if (it.elemIndex_ < 0)
{
// No previous element in the local list
// Search back for previous non-zero table entry
while (--it.hashIndex_ >= 0 && !objects_[it.hashIndex_].size())
{}
if (it.hashIndex_ >= 0)
{
// The last element in the local list
it.elemIndex_ = objects_[it.hashIndex_].size() - 1;
}
else
{
// No previous found. Mark with special value which is
// - not end()
// - handled by operator++
it.hashIndex_ = -1;
it.elemIndex_ = 0;
}
// Mark with as special value (see notes in HashTable)
it.hashIndex_ = -it.hashIndex_ - 1;
it.elemIndex_ = 0;
}
nElmts_--;
@ -407,8 +391,8 @@ Foam::label Foam::StaticHashTable<T, Key, Hash>::erase
template<class T, class Key, class Hash>
void Foam::StaticHashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = canonicalSize(sz);
label newSize = StaticHashTableCore::canonicalSize(sz);
if (newSize == keys_.size())
{
# ifdef FULLDEBUG
@ -543,18 +527,8 @@ bool Foam::StaticHashTable<T, Key, Hash>::operator==
const StaticHashTable<T, Key, Hash>& rhs
) const
{
// Are all my elements in rhs?
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
const_iterator fnd = rhs.find(iter.key());
// sizes (number of keys) must match
if (fnd == rhs.cend() || fnd() != iter())
{
return false;
}
}
// Are all rhs elements in me?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
@ -564,6 +538,7 @@ bool Foam::StaticHashTable<T, Key, Hash>::operator==
return false;
}
}
return true;
}

View File

@ -76,7 +76,33 @@ template<class T, class Key, class Hash> Ostream& operator<<
Class StaticHashTableName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(StaticHashTable);
/*---------------------------------------------------------------------------*\
Class StaticHashTableCore Declaration
\*---------------------------------------------------------------------------*/
//- Template-invariant bits for StaticHashTable
struct StaticHashTableCore
{
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Construct null
StaticHashTableCore()
{}
//- Define template name and debug
ClassName("StaticHashTable");
//- A zero-sized end iterator
struct iteratorEnd
{
//- Construct null
iteratorEnd()
{}
};
};
/*---------------------------------------------------------------------------*\
@ -86,7 +112,7 @@ TemplateName(StaticHashTable);
template<class T, class Key=word, class Hash=string::hash>
class StaticHashTable
:
public StaticHashTableName
public StaticHashTableCore
{
// Private data type for table entries

View File

@ -28,6 +28,6 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::StaticHashTableName, 0);
defineTypeNameAndDebug(Foam::StaticHashTableCore, 0);
// ************************************************************************* //

View File

@ -267,8 +267,13 @@ Foam::StaticHashTable<T, Key, Hash>::Iterator
TableRef
>::operator++()
{
// Check for special value from erase. (sets hashIndex to -1)
if (hashIndex_ >= 0)
// A negative index is a special value from erase
// (see notes in HashTable)
if (hashIndex_ < 0)
{
hashIndex_ = -(hashIndex_+1) - 1;
}
else
{
// Try the next element on the local list
elemIndex_++;

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