Upgrade to Paraview 4.0.1; contributed by Andreas Feymark

This commit is contained in:
Dominik Christ 2013-12-11 09:25:19 +00:00
parent 9454c3e2dd
commit 3c95ab6a8a
37 changed files with 7338 additions and 5 deletions

View file

@ -73,12 +73,12 @@ then
if [ -d "$QT_BIN_DIR" -a -r "$QT_BIN_DIR"/qmake ] if [ -d "$QT_BIN_DIR" -a -r "$QT_BIN_DIR"/qmake ]
then then
( rpm_make -p ParaView-3.14.1 -s ParaView-3.14.1.spec -u http://www.paraview.org/files/v3.14/ParaView-3.14.1-Source.tar.gz \ ( rpm_make -p ParaView-4.0.1 -s ParaView-4.0.1.spec -u http://www.paraview.org/files/v4.0/ParaView-v4.0.1-source.tgz \
-f --define='_qmakePath $QT_BIN_DIR/qmake' -f --define='_qmakePath $QT_BIN_DIR/qmake'
) )
else else
echo "WARNING: " echo "WARNING: "
echo "WARNING: Skipping the installation of ParaView-3.12.0." echo "WARNING: Skipping the installation of ParaView-4.0.1."
echo "WARNING: Please make sure the QT_BIN_DIR environment variable properly" echo "WARNING: Please make sure the QT_BIN_DIR environment variable properly"
echo "WARNING: initialized in the file prefs.sh or prefs.csh" echo "WARNING: initialized in the file prefs.sh or prefs.csh"
echo "WARNING: The command \$QT_BIN_DIR/qmake needs to be valid" echo "WARNING: The command \$QT_BIN_DIR/qmake needs to be valid"

View file

@ -0,0 +1,12 @@
diff -ruN ParaView-4.0.1_orig/Applications/ParaView-4.0.1_extra_install_Darwin.cmake ParaView-4.0.1/Applications/ParaView-4.0.1_extra_install_Darwin.cmake
--- ParaView-4.0.1_orig/Applications/ParaView-4.0.1_extra_install_Darwin.cmake 1969-12-31 19:00:00.000000000 -0500
+++ ParaView-4.0.1/Applications/ParaView-4.0.1_extra_install_Darwin.cmake 2013-10-02 19:00:00.000000000 -0400
@@ -0,0 +1,8 @@
+#
+# Additional install rules for Mac OS X platforms
+#
+INSTALL (DIRECTORY ../../buildObj/bin/paraview.app
+ DESTINATION ${PV_INSTALL_BIN_DIR}
+ USE_SOURCE_PERMISSIONS
+ COMPONENT Runtime)
+

View file

@ -0,0 +1,275 @@
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright held by original author
# \\/ 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
#
# Script
# RPM spec file for ParaView-4.0.1
#
# Description
# RPM spec file for creating a relocatable RPM
#
# Authors:
# Martin Beaudoin, Hydro-Quebec, (2010)
# Andreas Feymark, Chalmers University of Technology, (2013)
#
#------------------------------------------------------------------------------
# We grab the value of WM_THIRD_PARTY and WM_OPTIONS from the environment variable
%{expand:%%define _WM_THIRD_PARTY_DIR %(echo $WM_THIRD_PARTY_DIR)}
%{expand:%%define _WM_OPTIONS %(echo $WM_OPTIONS)}
# Disable the generation of debuginfo packages
%define debug_package %{nil}
# The topdir needs to point to the $WM_THIRD_PARTY/rpmbuild directory
%define _topdir %{_WM_THIRD_PARTY_DIR}/rpmBuild
%define _tmppath %{_topdir}/tmp
# Will install the package directly $WM_THIRD_PARTY_DIR
# Some comments about package relocation:
# By using this prefix for the Prefix: parameter in this file, you will make this
# package relocatable.
#
# This is fine, as long as your software is itself relocatable.
#
# Simply take note that libraries built with libtool are not relocatable because the
# prefix we specify will be hard-coded in the library .la files.
# Ref: http://sourceware.org/autobook/autobook/autobook_80.html
#
# In that case, if you ever change the value of the $WM_THIRD_PARTY_DIR, you will
# not be able to reutilize this RPM, even though it is relocatable. You will need to
# regenerate the RPM.
#
%define _prefix %{_WM_THIRD_PARTY_DIR}
%define name ParaView
%define release %{_WM_OPTIONS}
%define version 4.0.1
%define buildroot %{_topdir}/BUILD/%{name}-%{version}-root
BuildRoot: %{buildroot}
Summary: ParaView
License: Unkown
Name: %{name}
Version: %{version}
Release: %{release}
URL: http://www.paraview.org/files/v4.0/
Source: %url/%{name}-v%{version}-source.tgz
Prefix: %{_prefix}
Group: Development/Tools
Patch0: ParaView-4.0.1.patch_darwin
%define _installPrefix %{_prefix}/packages/%{name}-%{version}/platforms/%{_WM_OPTIONS}
#--------------------------------------------------------------------------
#
# Here, we define default compiling options for cmake
#
# One can override the option on the commande line : --define='MACRO EXPR'
#
%{!?_withVerbose: %define _withVerbose false}
%{!?_withMesa: %define _withMesa false}
%{!?_withMPI: %define _withMPI false}
%{!?_withPython: %define _withPython false}
%{!?_withQt: %define _withQt true}
%{!?_qmakePath: %define _qmakePath Undefined}
%{!?_mesaIncludePath: %define _mesaIncludePath Undefined}
%{!?_mesaLibPath: %define _mesaLibPath Undefined}
%{!?_pythonLibPath: %define _pythonLibPath Undefined}
#--------------------------------------------------------------------------
%description
%{summary}
%prep
%setup -q -n %{name}-v%{version}-source
%ifos darwin
%patch0 -p1
%endif
%build
#
# set CMake cache variables
#
addCMakeVariable()
{
while [ -n "$1" ]
do
CMAKE_VARIABLES="$CMAKE_VARIABLES -D$1"
shift
done
}
# export WM settings in a form that GNU configure recognizes
[ -n "$WM_CC" ] && export CC="$WM_CC"
[ -n "$WM_CXX" ] && export CXX="$WM_CXX"
[ -n "$WM_CFLAGS" ] && export CFLAGS="$WM_CFLAGS"
[ -n "$WM_CXXFLAGS" ] && export CXXFLAGS="$WM_CXXFLAGS"
[ -n "$WM_LDFLAGS" ] && export LDFLAGS="$WM_LDFLAGS"
set +x
echo ""
echo "Compilation options:"
echo " _withVerbose : %{_withVerbose}"
echo " _withMesa : %{_withMesa}"
echo " _withMPI : %{_withMPI}"
echo " _withPython : %{_withPython}"
echo " _withQt : %{_withQt}"
echo " _qmakePath : %{_qmakePath}"
echo " _mesaIncludePath : %{_mesaIncludePath}"
echo " _mesaLibPath : %{_mesaLibPath}"
echo " _pythonLibPath : %{_pythonLibPath}"
echo ""
set -x
# start with these general settings
addCMakeVariable VTK_USE_TK:BOOL=OFF
addCMakeVariable BUILD_SHARED_LIBS:BOOL=ON VTK_USE_RPATH:BOOL=OFF
addCMakeVariable CMAKE_BUILD_TYPE:STRING=Release
# include development files in "make install"
addCMakeVariable PARAVIEW_INSTALL_DEVELOPMENT_FILES:BOOL=ON
# new alternative to "make HTMLDocumentation"
addCMakeVariable PARAVIEW_GENERATE_PROXY_DOCUMENTATION:BOOL=ON
%ifos darwin
# Additional installation rules for Mac OS X
addCMakeVariable PARAVIEW_EXTRA_INSTALL_RULES_FILE:FILEPATH=%{_topdir}/BUILD/%{name}-%{version}/Applications/ParaView-3.8.1_extra_install_Darwin.cmake
%endif
# Add the value of _qmakePath for QT_QMAKE_EXECUTABLE
addCMakeVariable QT_QMAKE_EXECUTABLE:FILEPATH=%{_qmakePath}
echo "CMAKE_VARIABLES: $CMAKE_VARIABLES"
mkdir -p ./buildObj
cd ./buildObj
cmake \
-DCMAKE_INSTALL_PREFIX:PATH=%{_installPrefix} \
$CMAKE_VARIABLES \
..
[ -z "$WM_NCOMPPROCS" ] && WM_NCOMPPROCS=1
make -j $WM_NCOMPPROCS
%install
# On OpenSUSE, rpmbuild, will choke when detecting unreferenced symlinks
# created during installation.
# Qt version 4.6.3 will generate some unreferenced symlinks when
# ParaView is compiled and installed. By enabling the following
# environment variable, the command brp-symlink will still complain
# about missing link targets, but it won't stop rpmbuild from generating
# the final rpm.
# For all other Unix distros, this is a no-op.
export NO_BRP_STALE_LINK_ERROR=yes
cd buildObj
make install DESTDIR=$RPM_BUILD_ROOT
# Creation of OpenFOAM specific .csh and .sh files"
echo ""
echo "Generating OpenFOAM specific .csh and .sh files for the package %{name}-%{version}"
echo ""
#
# Generate package specific .sh file for OpenFOAM
#
mkdir -p $RPM_BUILD_ROOT/%{_installPrefix}/etc
cat << DOT_SH_EOF > $RPM_BUILD_ROOT/%{_installPrefix}/etc/%{name}-%{version}.sh
# Load %{name}-%{version} libraries and binaries if available
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export PARAVIEW_DIR=\$WM_THIRD_PARTY_DIR/packages/%{name}-%{version}/platforms/\$WM_OPTIONS
export PARAVIEW_BIN_DIR=\$PARAVIEW_DIR/bin
export PARAVIEW_LIB_DIR=\$PARAVIEW_DIR/lib
export PARAVIEW_INCLUDE_DIR=\$PARAVIEW_DIR/include/paraview-4.0
export PARAVIEW_VERSION=%{version}
# NB: It is important to set the PV_PLUGIN_PATH location to a directory containing only the ParaView plugins.
# Otherwise, paraview will try to automatically autoload each and every dynamic library it can find in the
# specified directory to see if a given library is a paraview plugin.
# In the case of \$FOAM_LIBBIN, with over 80 libraries, this is a total waste of time that will slow down the
# startup of paraview or even make paraview crash on startup.
export PV_PLUGIN_PATH=\$FOAM_LIBBIN/paraview_plugins
[ -d \$PARAVIEW_LIB_DIR/paraview-4.0 ] && _foamAddLib \$PARAVIEW_LIB_DIR/paraview-4.0
# Enable access to the package applications if present
[ -d \$PARAVIEW_BIN_DIR ] && _foamAddPath \$PARAVIEW_BIN_DIR
# Additional binary path if running on Mac OS X
[ -d \$PARAVIEW_BIN_DIR/paraview.app/Contents/MacOS ] && _foamAddPath \$PARAVIEW_BIN_DIR/paraview.app/Contents/MacOS
DOT_SH_EOF
#
# Generate package specific .csh file for OpenFOAM
#
cat << DOT_CSH_EOF > $RPM_BUILD_ROOT/%{_installPrefix}/etc/%{name}-%{version}.csh
# Load %{name}-%{version} libraries and binaries if available
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
setenv PARAVIEW_DIR \$WM_THIRD_PARTY_DIR/packages/%{name}-%{version}/platforms/\$WM_OPTIONS
setenv PARAVIEW_BIN_DIR \$PARAVIEW_DIR/bin
setenv PARAVIEW_LIB_DIR \$PARAVIEW_DIR/lib
setenv PARAVIEW_INCLUDE_DIR \$PARAVIEW_DIR/include/paraview-4.0
setenv PARAVIEW_VERSION %{version}
# NB: It is important to set the PV_PLUGIN_PATH location to a directory containing only the ParaView plugins.
# Otherwise, paraview will try to automatically autoload each and every dynamic library it can find in the
# specified directory to see if a given library is a paraview plugin.
# In the case of \$FOAM_LIBBIN, with over 80 libraries, this is a total waste of time that will slow down the
# startup of paraview or even make paraview crash on startup.
setenv PV_PLUGIN_PATH \$FOAM_LIBBIN/paraview_plugins
if ( -e \$PARAVIEW_BIN_DIR ) then
_foamAddPath \$PARAVIEW_BIN_DIR
endif
if ( -e \$PARAVIEW_LIB_DIR/paraview-4.0 ) then
_foamAddLib \$PARAVIEW_LIB_DIR/paraview-4.0
endif
# Additional binary path if running on Mac OS X
if ( -e \$PARAVIEW_BIN_DIR/paraview.app/Contents/MacOS ) then
_foamAddPath \$PARAVIEW_BIN_DIR/paraview.app/Contents/MacOS
endif
DOT_CSH_EOF
#finally, generate a .tgz file for systems where using rpm for installing packages
# as a non-root user might be a problem.
(mkdir -p %{_topdir}/TGZS/%{_target_cpu}; cd $RPM_BUILD_ROOT/%{_prefix}; tar -zcvf %{_topdir}/TGZS/%{_target_cpu}/%{name}-%{version}.tgz packages/%{name}-%{version})
%clean
%files
%defattr(-,root,root)
%{_installPrefix}

View file

@ -0,0 +1,8 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
rm -rf PV4FoamReader/Make
wclean libso vtkPV4Foam
# ----------------------------------------------------------------- end-of-file

View file

@ -0,0 +1,26 @@
#!/bin/bash
cd ${0%/*} || exit 1 # run from this directory
set -x
if [ -d "$PARAVIEW_DIR" -a -r "$PARAVIEW_DIR" ]
then
case "$PARAVIEW_VERSION" in
4*)
wmake libso vtkPV4Foam
(
cd PV4FoamReader
mkdir -p Make/$WM_OPTIONS > /dev/null 2>&1
cd Make/$WM_OPTIONS
cmake ../..
if [ "$WM_ARCH_BASE" == "darwin" ]
then
sed -i bak -e 's/-dynamiclib /& -undefined dynamic_lookup /' CMakeFiles/PV4FoamReader.dir/link.txt
sed -i bak -e 's/-dynamiclib /& -undefined dynamic_lookup /' CMakeFiles/PV4FoamReader_SM.dir/link.txt
fi
make
)
;;
esac
fi
# ----------------------------------------------------------------- end-of-file

View file

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

View file

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

View file

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

View file

@ -0,0 +1,209 @@
<ServerManagerConfiguration>
<ProxyGroup name="sources">
<SourceProxy
name="PV4FoamReader"
class="vtkPV4FoamReader">
<!-- File name - compulsory -->
<StringVectorProperty
name="FileName"
command="SetFileName"
number_of_elements="1"
animateable="0">
<FileListDomain name="files"/>
<Documentation>
Specifies the filename for the OpenFOAM Reader.
</Documentation>
</StringVectorProperty>
<!-- Send discrete time info to the animation panel -->
<DoubleVectorProperty
name="TimestepValues"
repeatable="1"
information_only="1">
<TimeStepsInformationHelper/>
<Documentation>
Available timestep values.
</Documentation>
</DoubleVectorProperty>
<!-- Global settings -->
<!-- Extrapolate Patches check-box -->
<IntVectorProperty
name="ExtrapolatePatches"
command="SetExtrapolatePatches"
number_of_elements="1"
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Extrapolate internalField to non-constraint patches
</Documentation>
</IntVectorProperty>
<!-- Include Sets check-box -->
<IntVectorProperty
name="IncludeSets"
command="SetIncludeSets"
number_of_elements="1"
default_values="0"
animateable="0">
<Documentation>
Searches the polyMesh/sets/ directory
</Documentation>
<BooleanDomain name="bool"/>
</IntVectorProperty>
<!-- Include Zones check-box -->
<IntVectorProperty
name="IncludeZones"
command="SetIncludeZones"
number_of_elements="1"
default_values="0"
animateable="0">
<Documentation>
ZoneMesh information is used to find {cell,face,point}Zones.
The polyMesh/ directory is only checked on startup.
</Documentation>
<BooleanDomain name="bool"/>
</IntVectorProperty>
<!-- Show Patch Names check-box -->
<IntVectorProperty
name="ShowPatchNames"
command="SetShowPatchNames"
number_of_elements="1"
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
Show patch names in render window.
</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 -->
<IntVectorProperty
name="UpdateGUI"
command="SetUpdateGUI"
number_of_elements="1"
default_values="0"
animateable="0">
<BooleanDomain name="bool"/>
<Documentation>
A simple way cause a reader GUI modification.
</Documentation>
</IntVectorProperty>
<!-- Selections -->
<!-- Available Parts (volume, patches, lagrangian) array -->
<StringVectorProperty
name="PartArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="Part"/>
</StringVectorProperty>
<StringVectorProperty
name="PartStatus"
label="Mesh Parts"
command="SetPartArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PartArrayInfo"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="PartArrayInfo" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available volFields array -->
<StringVectorProperty
name="VolFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="VolField"/>
</StringVectorProperty>
<StringVectorProperty
name="VolFieldStatus"
label="Volume Fields"
command="SetVolFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="VolFieldArrayInfo"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="VolFieldArrayInfo" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available Lagrangian fields array -->
<StringVectorProperty
name="LagrangianFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="LagrangianField"/>
</StringVectorProperty>
<StringVectorProperty
name="LagrangianFieldStatus"
label="Lagrangian Fields"
command="SetLagrangianFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="LagrangianFieldArrayInfo"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="LagrangianFieldArrayInfo" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
<!-- Available pointFields array -->
<StringVectorProperty
name="PointFieldArrayInfo"
information_only="1">
<ArraySelectionInformationHelper attribute_name="PointField"/>
</StringVectorProperty>
<StringVectorProperty
name="PointFieldStatus"
label="Point Fields"
command="SetPointFieldArrayStatus"
number_of_elements="0"
repeat_command="1"
number_of_elements_per_command="2"
element_types="2 0"
information_property="PointFieldArrayInfo"
animateable="0">
<ArraySelectionDomain name="array_list">
<RequiredProperties>
<Property name="PointFieldArrayInfo" function="ArrayList"/>
</RequiredProperties>
</ArraySelectionDomain>
</StringVectorProperty>
</SourceProxy>
</ProxyGroup>
</ServerManagerConfiguration>

View file

@ -0,0 +1,683 @@
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkPV4FoamReader.cxx,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkPV4FoamReader.h"
#include "pqApplicationCore.h"
#include "pqRenderView.h"
#include "pqServerManagerModel.h"
// VTK includes
#include "vtkCallbackCommand.h"
#include "vtkDataArraySelection.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkObjectFactory.h"
#include "vtkSMRenderViewProxy.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkStringArray.h"
// Foam includes
#include "vtkPV4Foam.H"
vtkCxxRevisionMacro(vtkPV4FoamReader, "$Revision: 1.5$");
vtkStandardNewMacro(vtkPV4FoamReader);
#undef EXPERIMENTAL_TIME_CACHING
vtkPV4FoamReader::vtkPV4FoamReader()
{
Debug = 0;
vtkDebugMacro(<<"Constructor");
SetNumberOfInputPorts(0);
FileName = NULL;
foamData_ = NULL;
output0_ = NULL;
#ifdef VTKPV4FOAM_DUALPORT
// Add second output for the Lagrangian
this->SetNumberOfOutputPorts(2);
vtkMultiBlockDataSet *lagrangian = vtkMultiBlockDataSet::New();
lagrangian->ReleaseData();
this->GetExecutive()->SetOutputData(1, lagrangian);
lagrangian->Delete();
#endif
TimeStepRange[0] = 0;
TimeStepRange[1] = 0;
CacheMesh = 1;
ExtrapolatePatches = 0;
IncludeSets = 0;
IncludeZones = 0;
ShowPatchNames = 0;
UpdateGUI = 0;
PartSelection = vtkDataArraySelection::New();
VolFieldSelection = vtkDataArraySelection::New();
PointFieldSelection = vtkDataArraySelection::New();
LagrangianFieldSelection = vtkDataArraySelection::New();
// Setup the selection callback to modify this object when an array
// selection is changed.
SelectionObserver = vtkCallbackCommand::New();
SelectionObserver->SetCallback
(
&vtkPV4FoamReader::SelectionModifiedCallback
);
SelectionObserver->SetClientData(this);
PartSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
VolFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
PointFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
LagrangianFieldSelection->AddObserver
(
vtkCommand::ModifiedEvent,
this->SelectionObserver
);
}
vtkPV4FoamReader::~vtkPV4FoamReader()
{
vtkDebugMacro(<<"Deconstructor");
delete foamData_;
if (FileName)
{
delete [] FileName;
}
if (output0_)
{
output0_->Delete();
}
PartSelection->RemoveObserver(this->SelectionObserver);
VolFieldSelection->RemoveObserver(this->SelectionObserver);
PointFieldSelection->RemoveObserver(this->SelectionObserver);
LagrangianFieldSelection->RemoveObserver(this->SelectionObserver);
SelectionObserver->Delete();
PartSelection->Delete();
VolFieldSelection->Delete();
PointFieldSelection->Delete();
LagrangianFieldSelection->Delete();
}
// Do everything except set the output info
int vtkPV4FoamReader::RequestInformation
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestInformation");
if (Foam::vtkPV4Foam::debug)
{
cout<<"REQUEST_INFORMATION\n";
}
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
int nInfo = outputVector->GetNumberOfInformationObjects();
if (Foam::vtkPV4Foam::debug)
{
cout<<"RequestInformation with " << nInfo << " item(s)\n";
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Print(cout);
}
}
if (!foamData_)
{
foamData_ = new Foam::vtkPV4Foam(FileName, this);
}
else
{
foamData_->updateInfo();
}
int nTimeSteps = 0;
double* timeSteps = foamData_->findTimes(nTimeSteps);
if (!nTimeSteps)
{
vtkErrorMacro("could not find valid OpenFOAM mesh");
// delete foamData and flag it as fatal error
delete foamData_;
foamData_ = NULL;
return 0;
}
// set identical time steps for all ports
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Set
(
vtkStreamingDemandDrivenPipeline::TIME_STEPS(),
timeSteps,
nTimeSteps
);
}
if (nTimeSteps)
{
double timeRange[2];
timeRange[0] = timeSteps[0];
timeRange[1] = timeSteps[nTimeSteps-1];
if (Foam::vtkPV4Foam::debug > 1)
{
cout<<"nTimeSteps " << nTimeSteps << "\n"
<<"timeRange " << timeRange[0] << " to " << timeRange[1]
<< "\n";
for (int timeI = 0; timeI < nTimeSteps; ++timeI)
{
cout<< "step[" << timeI << "] = " << timeSteps[timeI] << "\n";
}
}
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Set
(
vtkStreamingDemandDrivenPipeline::TIME_RANGE(),
timeRange,
2
);
}
}
delete timeSteps;
return 1;
}
// Set the output info
int vtkPV4FoamReader::RequestData
(
vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector),
vtkInformationVector* outputVector
)
{
vtkDebugMacro(<<"RequestData");
if (!FileName)
{
vtkErrorMacro("FileName has to be specified!");
return 0;
}
// catch previous error
if (!foamData_)
{
vtkErrorMacro("Reader failed - perhaps no mesh?");
return 0;
}
int nInfo = outputVector->GetNumberOfInformationObjects();
if (Foam::vtkPV4Foam::debug)
{
cout<<"RequestData with " << nInfo << " item(s)\n";
for (int infoI = 0; infoI < nInfo; ++infoI)
{
outputVector->GetInformationObject(infoI)->Print(cout);
}
}
// Get the requested time step.
// We only support requests for a single time step
int nRequestTime = 0;
double requestTime[nInfo];
// taking port0 as the lead for other outputs would be nice, but fails when
// a filter is added - we need to check everything
// but since PREVIOUS_UPDATE_TIME_STEPS() is protected, relay the logic
// to the vtkPV4Foam::setTime() method
for (int infoI = 0; infoI < nInfo; ++infoI)
{
vtkInformation *outInfo = outputVector->GetInformationObject(infoI);
if
(
outInfo->Has(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP())
&& outInfo->Length(vtkStreamingDemandDrivenPipeline::TIME_STEPS()) >= 1
)
{
requestTime[nRequestTime++] = outInfo->Get
(
vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()
);
}
}
if (nRequestTime)
{
foamData_->setTime(nRequestTime, requestTime);
}
vtkMultiBlockDataSet* output = vtkMultiBlockDataSet::SafeDownCast
(
outputVector->GetInformationObject(0)->Get
(
vtkMultiBlockDataSet::DATA_OBJECT()
)
);
if (Foam::vtkPV4Foam::debug)
{
cout<< "update output with "
<< output->GetNumberOfBlocks() << " blocks\n";
}
#ifdef EXPERIMENTAL_TIME_CACHING
bool needsUpdate = false;
if (!output0_)
{
output0_ = vtkMultiBlockDataSet::New();
needsUpdate = true;
}
// This experimental bit of code seems to work for the geometry,
// but trashes the fields and still triggers the GeometryFilter
if (needsUpdate)
{
foamData_->Update(output);
output0_->ShallowCopy(output);
}
else
{
output->ShallowCopy(output0_);
}
if (Foam::vtkPV4Foam::debug)
{
if (needsUpdate)
{
cout<< "full UPDATE ---------\n";
}
else
{
cout<< "cached UPDATE ---------\n";
}
cout<< "UPDATED output: ";
output->Print(cout);
cout<< "UPDATED output0_: ";
output0_->Print(cout);
}
#else
#ifdef VTKPV4FOAM_DUALPORT
foamData_->Update
(
output,
vtkMultiBlockDataSet::SafeDownCast
(
outputVector->GetInformationObject(1)->Get
(
vtkMultiBlockDataSet::DATA_OBJECT()
)
);
);
#else
foamData_->Update(output, output);
#endif
if (ShowPatchNames)
{
addPatchNamesToView();
}
else
{
removePatchNamesFromView();
}
#endif
// Do any cleanup on the Foam side
foamData_->CleanUp();
return 1;
}
void vtkPV4FoamReader::addPatchNamesToView()
{
pqApplicationCore* appCore = pqApplicationCore::instance();
// Server manager model for querying items in the server manager
pqServerManagerModel* smModel = appCore->getServerManagerModel();
// Get all the pqRenderView instances
QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>();
for (int viewI=0; viewI<renderViews.size(); viewI++)
{
foamData_->addPatchNames
(
renderViews[viewI]->getRenderViewProxy()->GetRenderer()
);
}
}
void vtkPV4FoamReader::removePatchNamesFromView()
{
pqApplicationCore* appCore = pqApplicationCore::instance();
// Server manager model for querying items in the server manager
pqServerManagerModel* smModel = appCore->getServerManagerModel();
// Get all the pqRenderView instances
QList<pqRenderView*> renderViews = smModel->findItems<pqRenderView*>();
for (int viewI=0; viewI<renderViews.size(); viewI++)
{
foamData_->removePatchNames
(
renderViews[viewI]->getRenderViewProxy()->GetRenderer()
);
}
}
void vtkPV4FoamReader::PrintSelf(ostream& os, vtkIndent indent)
{
vtkDebugMacro(<<"PrintSelf");
this->Superclass::PrintSelf(os,indent);
os<< indent << "File name: "
<< (this->FileName ? this->FileName : "(none)") << "\n";
foamData_->PrintSelf(os, indent);
os<< indent << "Time step range: "
<< this->TimeStepRange[0] << " - " << this->TimeStepRange[1]
<< "\n";
os<< indent << "Time step: " << this->GetTimeStep() << endl;
}
int vtkPV4FoamReader::GetTimeStep()
{
return foamData_ ? foamData_->timeIndex() : -1;
}
// ----------------------------------------------------------------------
// Parts selection list control
vtkDataArraySelection* vtkPV4FoamReader::GetPartSelection()
{
vtkDebugMacro(<<"GetPartSelection");
return PartSelection;
}
int vtkPV4FoamReader::GetNumberOfPartArrays()
{
vtkDebugMacro(<<"GetNumberOfPartArrays");
return PartSelection->GetNumberOfArrays();
}
const char* vtkPV4FoamReader::GetPartArrayName(int index)
{
vtkDebugMacro(<<"GetPartArrayName");
return PartSelection->GetArrayName(index);
}
int vtkPV4FoamReader::GetPartArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetPartArrayStatus");
return PartSelection->ArrayIsEnabled(name);
}
void vtkPV4FoamReader::SetPartArrayStatus(const char* name, int status)
{
vtkDebugMacro(<<"SetPartArrayStatus");
if (status)
{
PartSelection->EnableArray(name);
}
else
{
PartSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
// volField selection list control
vtkDataArraySelection* vtkPV4FoamReader::GetVolFieldSelection()
{
vtkDebugMacro(<<"GetVolFieldSelection");
return VolFieldSelection;
}
int vtkPV4FoamReader::GetNumberOfVolFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfVolFieldArrays");
return VolFieldSelection->GetNumberOfArrays();
}
const char* vtkPV4FoamReader::GetVolFieldArrayName(int index)
{
vtkDebugMacro(<<"GetVolFieldArrayName");
return VolFieldSelection->GetArrayName(index);
}
int vtkPV4FoamReader::GetVolFieldArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetVolFieldArrayStatus");
return VolFieldSelection->ArrayIsEnabled(name);
}
void vtkPV4FoamReader::SetVolFieldArrayStatus(const char* name, int status)
{
vtkDebugMacro(<<"SetVolFieldArrayStatus");
if (status)
{
VolFieldSelection->EnableArray(name);
}
else
{
VolFieldSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
// pointField selection list control
vtkDataArraySelection* vtkPV4FoamReader::GetPointFieldSelection()
{
vtkDebugMacro(<<"GetPointFieldSelection");
return PointFieldSelection;
}
int vtkPV4FoamReader::GetNumberOfPointFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfPointFieldArrays");
return PointFieldSelection->GetNumberOfArrays();
}
const char* vtkPV4FoamReader::GetPointFieldArrayName(int index)
{
vtkDebugMacro(<<"GetPointFieldArrayName");
return PointFieldSelection->GetArrayName(index);
}
int vtkPV4FoamReader::GetPointFieldArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetPointFieldArrayStatus");
return PointFieldSelection->ArrayIsEnabled(name);
}
void vtkPV4FoamReader::SetPointFieldArrayStatus(const char* name, int status)
{
vtkDebugMacro(<<"SetPointFieldArrayStatus");
if (status)
{
PointFieldSelection->EnableArray(name);
}
else
{
PointFieldSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
// lagrangianField selection list control
vtkDataArraySelection* vtkPV4FoamReader::GetLagrangianFieldSelection()
{
vtkDebugMacro(<<"GetLagrangianFieldSelection");
return LagrangianFieldSelection;
}
int vtkPV4FoamReader::GetNumberOfLagrangianFieldArrays()
{
vtkDebugMacro(<<"GetNumberOfLagrangianFieldArrays");
return LagrangianFieldSelection->GetNumberOfArrays();
}
const char* vtkPV4FoamReader::GetLagrangianFieldArrayName(int index)
{
vtkDebugMacro(<<"GetLagrangianFieldArrayName");
return LagrangianFieldSelection->GetArrayName(index);
}
int vtkPV4FoamReader::GetLagrangianFieldArrayStatus(const char* name)
{
vtkDebugMacro(<<"GetLagrangianFieldArrayStatus");
return LagrangianFieldSelection->ArrayIsEnabled(name);
}
void vtkPV4FoamReader::SetLagrangianFieldArrayStatus
(
const char* name,
int status
)
{
vtkDebugMacro(<<"SetLagrangianFieldArrayStatus");
if (status)
{
LagrangianFieldSelection->EnableArray(name);
}
else
{
LagrangianFieldSelection->DisableArray(name);
}
}
// ----------------------------------------------------------------------
void vtkPV4FoamReader::SelectionModifiedCallback
(
vtkObject*,
unsigned long,
void* clientdata,
void*
)
{
static_cast<vtkPV4FoamReader*>(clientdata)->SelectionModified();
}
void vtkPV4FoamReader::SelectionModified()
{
vtkDebugMacro(<<"SelectionModified");
Modified();
}
int vtkPV4FoamReader::FillOutputPortInformation
(
int port,
vtkInformation* info
)
{
if (port == 0)
{
return this->Superclass::FillOutputPortInformation(port, info);
}
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkMultiBlockDataSet");
return 1;
}
// ************************************************************************* //

View file

@ -0,0 +1,212 @@
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkPV4FoamReader.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkPV4FoamReader - reads a dataset in OpenFOAM format
// .SECTION Description
// vtkPV4FoamReader creates an multiblock dataset.
// It uses the OpenFOAM infrastructure (fvMesh, etc) to
// handle mesh and field data.
#ifndef __vtkPV4FoamReader_h
#define __vtkPV4FoamReader_h
// Foam forward declarations
namespace Foam
{
class vtkPV4Foam;
}
// VTK includes
#include "vtkMultiBlockDataSetAlgorithm.h"
#include "vtkIOGeometryModule.h"
// VTK forward declarations
class vtkDataArraySelection;
class vtkCallbackCommand;
class VTKIOGEOMETRY_EXPORT vtkPV4FoamReader
:
public vtkMultiBlockDataSetAlgorithm
{
public:
vtkTypeRevisionMacro(vtkPV4FoamReader,vtkMultiBlockDataSetAlgorithm);
void PrintSelf(ostream&, vtkIndent);
static vtkPV4FoamReader* New();
// Description:
// Get the current timestep and the timestep range.
vtkGetVector2Macro(TimeStepRange, int);
// Description:
// Set/Get the filename.
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:
// FOAM extrapolate internal values onto the patches
vtkSetMacro(ExtrapolatePatches, int);
vtkGetMacro(ExtrapolatePatches, int);
// FOAM read sets control
vtkSetMacro(IncludeSets, int);
vtkGetMacro(IncludeSets, int);
// Description:
// FOAM read zones control
vtkSetMacro(IncludeZones, int);
vtkGetMacro(IncludeZones, int);
// Description:
// FOAM display patch names control
vtkSetMacro(ShowPatchNames, int);
vtkGetMacro(ShowPatchNames, int);
// Description:
// Get the current timestep
int GetTimeStep();
// Description:
// Parts selection list control
vtkDataArraySelection* GetPartSelection();
int GetNumberOfPartArrays();
int GetPartArrayStatus(const char* name);
void SetPartArrayStatus(const char* name, int status);
const char* GetPartArrayName(int index);
// Description:
// volField selection list control
vtkDataArraySelection* GetVolFieldSelection();
int GetNumberOfVolFieldArrays();
int GetVolFieldArrayStatus(const char* name);
void SetVolFieldArrayStatus(const char* name, int status);
const char* GetVolFieldArrayName(int index);
// Description:
// pointField selection list control
vtkDataArraySelection* GetPointFieldSelection();
int GetNumberOfPointFieldArrays();
int GetPointFieldArrayStatus(const char* name);
void SetPointFieldArrayStatus(const char* name, int status);
const char* GetPointFieldArrayName(int index);
// Description:
// lagrangianField selection list control
vtkDataArraySelection* GetLagrangianFieldSelection();
int GetNumberOfLagrangianFieldArrays();
int GetLagrangianFieldArrayStatus(const char* name);
void SetLagrangianFieldArrayStatus(const char* name, int status);
const char* GetLagrangianFieldArrayName(int index);
// Description:
// Callback registered with the SelectionObserver
// for all the selection lists
static void SelectionModifiedCallback
(
vtkObject* caller,
unsigned long eid,
void* clientdata,
void* calldata
);
void SelectionModified();
protected:
//- Construct null
vtkPV4FoamReader();
//- Destructor
~vtkPV4FoamReader();
//- Return information about mesh, times, etc without loading anything
virtual int RequestInformation
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
//- Get the mesh/fields for a particular time
//- Destructor
virtual int RequestData
(
vtkInformation*,
vtkInformationVector**,
vtkInformationVector*
);
//- Fill in additional port information
virtual int FillOutputPortInformation(int, vtkInformation*);
// The observer to modify this object when array selections are modified
vtkCallbackCommand* SelectionObserver;
char* FileName;
private:
//- Disallow default bitwise copy construct
vtkPV4FoamReader(const vtkPV4FoamReader&);
//- Disallow default bitwise assignment
void operator=(const vtkPV4FoamReader&);
//- Add patch names to the view
void addPatchNamesToView();
//- Remove patch names from the view
void removePatchNamesFromView();
int TimeStepRange[2];
int CacheMesh;
int ExtrapolatePatches;
int IncludeSets;
int IncludeZones;
int ShowPatchNames;
//- Dummy variable/switch for invoke a reader update
int UpdateGUI;
vtkDataArraySelection* PartSelection;
vtkDataArraySelection* VolFieldSelection;
vtkDataArraySelection* PointFieldSelection;
vtkDataArraySelection* LagrangianFieldSelection;
//- Cached data for output port0 (experimental!)
vtkMultiBlockDataSet* output0_;
//BTX
Foam::vtkPV4Foam* foamData_;
//ETX
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,12 @@
vtkPV4Foam.C
vtkPV4FoamFields.C
vtkPV4FoamMesh.C
vtkPV4FoamMeshLagrangian.C
vtkPV4FoamMeshPatch.C
vtkPV4FoamMeshSet.C
vtkPV4FoamMeshVolume.C
vtkPV4FoamMeshZone.C
vtkPV4FoamUpdateInfo.C
vtkPV4FoamUtilities.C
LIB = $(FOAM_LIBBIN)/libvtkPV4Foam

View file

@ -0,0 +1,12 @@
EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/lagrangian/basic/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(PARAVIEW_INCLUDE_DIR) \
-I../PV4FoamReader
LIB_LIBS = \
-lfiniteVolume \
-llagrangian \
-lmeshTools \
$(GLIBS)

View file

@ -0,0 +1,72 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkOpenFOAMTupleRemap_H
#define vtkOpenFOAMTupleRemap_H
// OpenFOAM includes
#include "StaticAssert.H"
#include "Swap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
inline void vtkOpenFOAMTupleRemap(float vec[]);
// a symmTensor specialization to remap OpenFOAM -> ParaView naming order
// Qt/Core/pqScalarBarRepresentation.cxx defines this order
// { "XX", "YY", "ZZ", "XY", "YZ", "XZ" }
// in pqScalarBarRepresentation::getDefaultComponentLabel()
// whereas OpenFOAM uses this order
// { XX, XY, XZ, YY, YZ, ZZ }
//
// for extra safety, assert that symmTensor indeed has 6 components
StaticAssert(Foam::symmTensor::nComponents == 6);
// Template specialization for symmTensor
template<>
inline void vtkOpenFOAMTupleRemap<Foam::symmTensor>(float vec[])
{
Foam::Swap(vec[1], vec[3]); // swap XY <-> YY
Foam::Swap(vec[2], vec[5]); // swap XZ <-> ZZ
}
template<class Type>
inline void vtkOpenFOAMTupleRemap(float vec[])
{}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,821 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 "vtkPV4Foam.H"
#include "vtkPV4FoamReader.h"
// Foam includes
#include "fvMesh.H"
#include "Time.H"
#include "patchZones.H"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkRenderer.h"
#include "vtkTextActor.h"
#include "vtkTextProperty.h"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::vtkPV4Foam, 0);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
#include "vtkPV4FoamAddToSelection.H"
#include "vtkPV4FoamUpdateInfoFields.H"
void Foam::vtkPV4Foam::resetCounters()
{
// Reset mesh part ids and sizes
partInfoVolume_.reset();
partInfoPatches_.reset();
partInfoLagrangian_.reset();
partInfoCellZones_.reset();
partInfoFaceZones_.reset();
partInfoPointZones_.reset();
partInfoCellSets_.reset();
partInfoFaceSets_.reset();
partInfoPointSets_.reset();
}
void Foam::vtkPV4Foam::reduceMemory()
{
forAll(regionPolyDecomp_, i)
{
regionPolyDecomp_[i].clear();
}
forAll(zonePolyDecomp_, i)
{
zonePolyDecomp_[i].clear();
}
forAll(csetPolyDecomp_, i)
{
csetPolyDecomp_[i].clear();
}
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = NULL;
}
}
int Foam::vtkPV4Foam::setTime(int nRequest, const double requestTimes[])
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::setTime(";
for (int requestI = 0; requestI < nRequest; ++requestI)
{
if (requestI)
{
Info<< ", ";
}
Info<< requestTimes[requestI];
}
Info << ") - previousIndex = " << timeIndex_ << endl;
}
Time& runTime = dbPtr_();
// Get times list
instantList Times = runTime.times();
int nearestIndex = timeIndex_;
for (int requestI = 0; requestI < nRequest; ++requestI)
{
int index = Time::findClosestTimeIndex(Times, requestTimes[requestI]);
if (index >= 0 && index != timeIndex_)
{
nearestIndex = index;
break;
}
}
if (nearestIndex < 0)
{
nearestIndex = 0;
}
// see what has changed
if (timeIndex_ != nearestIndex)
{
timeIndex_ = nearestIndex;
runTime.setTime(Times[nearestIndex], nearestIndex);
// the fields change each time
fieldsChanged_ = true;
if (meshPtr_)
{
if (meshPtr_->readUpdate() != polyMesh::UNCHANGED)
{
meshChanged_ = true;
}
}
else
{
meshChanged_ = true;
}
reader_->UpdateProgress(0.05);
// this seems to be needed for catching Lagrangian fields
updateInfo();
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::setTime() - selectedTime="
<< Times[nearestIndex].name() << " index=" << timeIndex_
<< "/" << Times.size()
<< " meshChanged=" << Switch(meshChanged_)
<< " fieldsChanged=" << Switch(fieldsChanged_) << endl;
}
return nearestIndex;
}
void Foam::vtkPV4Foam::updateMeshPartsStatus()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateMeshPartsStatus" << endl;
}
vtkDataArraySelection* selection = reader_->GetPartSelection();
label nElem = selection->GetNumberOfArrays();
if (partStatus_.size() != nElem)
{
partStatus_.setSize(nElem);
partStatus_ = false;
meshChanged_ = true;
}
// this needs fixing if we wish to re-use the datasets
partDataset_.setSize(nElem);
partDataset_ = -1;
// Read the selected mesh parts (zones, patches ...) and add to list
forAll(partStatus_, partId)
{
const int setting = selection->GetArraySetting(partId);
if (partStatus_[partId] != setting)
{
partStatus_[partId] = setting;
meshChanged_ = true;
}
if (debug)
{
Info<< " part[" << partId << "] = "
<< partStatus_[partId]
<< " : " << selection->GetArrayName(partId) << endl;
}
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::updateMeshPartsStatus" << endl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkPV4Foam::vtkPV4Foam
(
const char* const FileName,
vtkPV4FoamReader* reader
)
:
reader_(reader),
dbPtr_(NULL),
meshPtr_(NULL),
meshRegion_(polyMesh::defaultRegion),
meshDir_(polyMesh::meshSubDir),
timeIndex_(-1),
meshChanged_(true),
fieldsChanged_(true),
partInfoVolume_("unzoned"),
partInfoPatches_("patches"),
partInfoLagrangian_("lagrangian"),
partInfoCellZones_("cellZone"),
partInfoFaceZones_("faceZone"),
partInfoPointZones_("pointZone"),
partInfoCellSets_("cellSet"),
partInfoFaceSets_("faceSet"),
partInfoPointSets_("pointSet")
{
if (debug)
{
Info<< "Foam::vtkPV4Foam::vtkPV4Foam - " << FileName << endl;
printMemory();
}
// avoid argList and get rootPath/caseName directly from the file
fileName fullCasePath(fileName(FileName).path());
if (!isDir(fullCasePath))
{
return;
}
if (fullCasePath == ".")
{
fullCasePath = cwd();
}
// Set the case as an environment variable - some BCs might use this
if (fullCasePath.name().find("processor", 0) == 0)
{
const fileName globalCase = fullCasePath.path();
setEnv("FOAM_CASE", globalCase, true);
setEnv("FOAM_CASENAME", globalCase.name(), true);
}
else
{
setEnv("FOAM_CASE", fullCasePath, true);
setEnv("FOAM_CASENAME", fullCasePath.name(), true);
}
// look for 'case{region}.OpenFOAM'
// could be stringent and insist the prefix match the directory name...
// Note: cannot use fileName::name() due to the embedded '{}'
string caseName(fileName(FileName).lessExt());
string::size_type beg = caseName.find_last_of("/{");
string::size_type end = caseName.find('}', beg);
if
(
beg != string::npos && caseName[beg] == '{'
&& end != string::npos && end == caseName.size()-1
)
{
meshRegion_ = caseName.substr(beg+1, end-beg-1);
// some safety
if (!meshRegion_.size())
{
meshRegion_ = polyMesh::defaultRegion;
}
if (meshRegion_ != polyMesh::defaultRegion)
{
meshDir_ = meshRegion_/polyMesh::meshSubDir;
}
}
if (debug)
{
Info<< "fullCasePath=" << fullCasePath << nl
<< "FOAM_CASE=" << getEnv("FOAM_CASE") << nl
<< "FOAM_CASENAME=" << getEnv("FOAM_CASENAME") << nl
<< "region=" << meshRegion_ << endl;
}
// Create time object
dbPtr_.reset
(
new Time
(
Time::controlDictName,
fileName(fullCasePath.path()),
fileName(fullCasePath.name())
)
);
dbPtr_().functionObjects().off();
updateInfo();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkPV4Foam::~vtkPV4Foam()
{
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::~vtkPV4Foam" << endl;
}
delete meshPtr_;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV4Foam::updateInfo()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfo"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "] timeIndex="
<< timeIndex_ << endl;
}
resetCounters();
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
// enable 'internalMesh' on the first call
// or preserve the enabled selections
stringList enabledEntries;
if (!partSelection->GetNumberOfArrays() && !meshPtr_)
{
enabledEntries.setSize(1);
enabledEntries[0] = "internalMesh";
}
else
{
enabledEntries = getSelectedArrayEntries(partSelection);
}
// Clear current mesh parts list
partSelection->RemoveAllArrays();
// Update mesh parts list - add Lagrangian at the bottom
updateInfoInternalMesh();
updateInfoPatches();
updateInfoSets();
updateInfoZones();
updateInfoLagrangian();
// restore the enabled selections
setSelectedArrayEntries(partSelection, enabledEntries);
if (meshChanged_)
{
fieldsChanged_ = true;
}
// Update volume, point and lagrangian fields
updateInfoFields<fvPatchField, volMesh>
(
reader_->GetVolFieldSelection()
);
updateInfoFields<pointPatchField, pointMesh>
(
reader_->GetPointFieldSelection()
);
updateInfoLagrangianFields();
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::updateInfo" << endl;
}
}
void Foam::vtkPV4Foam::updateFoamMesh()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateFoamMesh" << endl;
printMemory();
}
if (!reader_->GetCacheMesh())
{
delete meshPtr_;
meshPtr_ = NULL;
}
// Check to see if the FOAM mesh has been created
if (!meshPtr_)
{
if (debug)
{
Info<< "Creating Foam mesh for region " << meshRegion_
<< " at time=" << dbPtr_().timeName()
<< endl;
}
meshPtr_ = new fvMesh
(
IOobject
(
meshRegion_,
dbPtr_().timeName(),
dbPtr_(),
IOobject::MUST_READ
)
);
meshChanged_ = true;
}
else
{
if (debug)
{
Info<< "Using existing Foam mesh" << endl;
}
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::updateFoamMesh" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::Update
(
vtkMultiBlockDataSet* output,
vtkMultiBlockDataSet* lagrangianOutput
)
{
if (debug)
{
cout<< "<beg> Foam::vtkPV4Foam::Update - output with "
<< output->GetNumberOfBlocks() << " and "
<< lagrangianOutput->GetNumberOfBlocks() << " blocks\n";
output->Print(cout);
lagrangianOutput->Print(cout);
printMemory();
}
reader_->UpdateProgress(0.1);
// Set up mesh parts selection(s)
updateMeshPartsStatus();
reader_->UpdateProgress(0.15);
// Update the Foam mesh
updateFoamMesh();
reader_->UpdateProgress(0.4);
// Convert meshes - start port0 at block=0
int blockNo = 0;
convertMeshVolume(output, blockNo);
convertMeshPatches(output, blockNo);
reader_->UpdateProgress(0.6);
if (reader_->GetIncludeZones())
{
convertMeshCellZones(output, blockNo);
convertMeshFaceZones(output, blockNo);
convertMeshPointZones(output, blockNo);
reader_->UpdateProgress(0.65);
}
if (reader_->GetIncludeSets())
{
convertMeshCellSets(output, blockNo);
convertMeshFaceSets(output, blockNo);
convertMeshPointSets(output, blockNo);
reader_->UpdateProgress(0.7);
}
#ifdef VTKPV4FOAM_DUALPORT
// restart port1 at block=0
blockNo = 0;
#endif
convertMeshLagrangian(lagrangianOutput, blockNo);
reader_->UpdateProgress(0.8);
// Update fields
convertVolFields(output);
convertPointFields(output);
convertLagrangianFields(lagrangianOutput);
reader_->UpdateProgress(0.95);
meshChanged_ = fieldsChanged_ = false;
}
void Foam::vtkPV4Foam::CleanUp()
{
// reclaim some memory
reduceMemory();
reader_->UpdateProgress(1.0);
}
double* Foam::vtkPV4Foam::findTimes(int& nTimeSteps)
{
int nTimes = 0;
double* tsteps = NULL;
if (dbPtr_.valid())
{
Time& runTime = dbPtr_();
instantList timeLst = runTime.times();
// find the first time for which this mesh appears to exist
label timeI = 0;
for (; timeI < timeLst.size(); ++timeI)
{
const word& timeName = timeLst[timeI].name();
if
(
isFile(runTime.path()/timeName/meshDir_/"points")
&& IOobject("points", timeName, meshDir_, runTime).headerOk()
)
{
break;
}
}
nTimes = timeLst.size() - timeI;
// always skip "constant" time if possible
if (timeI == 0 && nTimes > 1)
{
timeI = 1;
--nTimes;
}
if (nTimes)
{
tsteps = new double[nTimes];
for (label stepI = 0; stepI < nTimes; ++stepI, ++timeI)
{
tsteps[stepI] = timeLst[timeI].value();
}
}
}
else
{
if (debug)
{
cout<< "no valid dbPtr:\n";
}
}
// vector length returned via the parameter
nTimeSteps = nTimes;
return tsteps;
}
void Foam::vtkPV4Foam::addPatchNames(vtkRenderer* renderer)
{
// Remove any patch names previously added to the renderer
removePatchNames(renderer);
// get the display patches, strip off any suffix
wordHashSet selectedPatches = getSelected
(
reader_->GetPartSelection(),
partInfoPatches_
);
if (!selectedPatches.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::addPatchNames" << nl
<<"... add patches: " << selectedPatches << endl;
}
const polyBoundaryMesh& pbMesh = meshPtr_->boundaryMesh();
// Find the total number of zones
// Each zone will take the patch name
// Number of zones per patch ... zero zones should be skipped
labelList nZones(pbMesh.size(), 0);
// Per global zone number the average face centre position
DynamicList<point> zoneCentre(pbMesh.size());
if (debug)
{
Info<< "... determining patch zones" << endl;
}
// Loop through all patches to determine zones, and centre of each zone
forAll(pbMesh, patchI)
{
const polyPatch& pp = pbMesh[patchI];
// Only include the patch if it is selected
if (!selectedPatches.found(pp.name()))
{
continue;
}
const labelListList& edgeFaces = pp.edgeFaces();
const vectorField& n = pp.faceNormals();
boolList featEdge(pp.nEdges(), false);
forAll(edgeFaces, edgeI)
{
const labelList& eFaces = edgeFaces[edgeI];
if (eFaces.size() == 1)
{
// Note: could also do ones with > 2 faces but this gives
// too many zones for baffles
featEdge[edgeI] = true;
}
else if (mag(n[eFaces[0]] & n[eFaces[1]]) < 0.5)
{
featEdge[edgeI] = true;
}
}
// Do topological analysis of patch, find disconnected regions
patchZones pZones(pp, featEdge);
nZones[patchI] = pZones.nZones();
labelList zoneNFaces(pZones.nZones(), 0);
// Save start of information for current patch
label patchStart = zoneCentre.size();
// Create storage for additional zone centres
forAll(zoneNFaces, zoneI)
{
zoneCentre.append(vector::zero);
}
// Do averaging per individual zone
forAll(pp, faceI)
{
label zoneI = pZones[faceI];
zoneCentre[patchStart+zoneI] += pp[faceI].centre(pp.points());
zoneNFaces[zoneI]++;
}
for (label i=0; i<nZones[patchI]; i++)
{
zoneCentre[patchStart + i] /= zoneNFaces[i];
}
}
// Count number of zones we're actually going to display. This is truncated
// to a max per patch
const label MAXPATCHZONES = 20;
label displayZoneI = 0;
forAll(pbMesh, patchI)
{
displayZoneI += min(MAXPATCHZONES, nZones[patchI]);
}
zoneCentre.shrink();
if (debug)
{
Info<< "patch zone centres = " << zoneCentre << nl
<< "displayed zone centres = " << displayZoneI << nl
<< "zones per patch = " << nZones << endl;
}
// Set the size of the patch labels to max number of zones
patchTextActorsPtrs_.setSize(displayZoneI);
if (debug)
{
Info<< "constructing patch labels" << endl;
}
// Actor index
displayZoneI = 0;
// Index in zone centres
label globalZoneI = 0;
forAll(pbMesh, patchI)
{
const polyPatch& pp = pbMesh[patchI];
// Only selected patches will have a non-zero number of zones
label nDisplayZones = min(MAXPATCHZONES, nZones[patchI]);
label increment = 1;
if (nZones[patchI] >= MAXPATCHZONES)
{
increment = nZones[patchI]/MAXPATCHZONES;
}
for (label i = 0; i < nDisplayZones; i++)
{
if (debug)
{
Info<< "patch name = " << pp.name() << nl
<< "anchor = " << zoneCentre[globalZoneI] << nl
<< "globalZoneI = " << globalZoneI << endl;
}
vtkTextActor* txt = vtkTextActor::New();
txt->SetInput(pp.name().c_str());
// Set text properties
vtkTextProperty* tprop = txt->GetTextProperty();
tprop->SetFontFamilyToArial();
tprop->BoldOff();
tprop->ShadowOff();
tprop->SetLineSpacing(1.0);
tprop->SetFontSize(12);
tprop->SetColor(1.0, 0.0, 0.0);
tprop->SetJustificationToCentered();
// Set text to use 3-D world co-ordinates
txt->GetPositionCoordinate()->SetCoordinateSystemToWorld();
txt->GetPositionCoordinate()->SetValue
(
zoneCentre[globalZoneI].x(),
zoneCentre[globalZoneI].y(),
zoneCentre[globalZoneI].z()
);
// Add text to each renderer
renderer->AddViewProp(txt);
// Maintain a list of text labels added so that they can be
// removed later
patchTextActorsPtrs_[displayZoneI] = txt;
globalZoneI += increment;
displayZoneI++;
}
}
// Resize the patch names list to the actual number of patch names added
patchTextActorsPtrs_.setSize(displayZoneI);
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::addPatchNames" << endl;
}
}
void Foam::vtkPV4Foam::removePatchNames(vtkRenderer* renderer)
{
forAll(patchTextActorsPtrs_, patchI)
{
renderer->RemoveViewProp(patchTextActorsPtrs_[patchI]);
patchTextActorsPtrs_[patchI]->Delete();
}
patchTextActorsPtrs_.clear();
}
void Foam::vtkPV4Foam::PrintSelf(ostream& os, vtkIndent indent) const
{
os << indent << "Number of nodes: "
<< (meshPtr_ ? meshPtr_->nPoints() : 0) << "\n";
os << indent << "Number of cells: "
<< (meshPtr_ ? meshPtr_->nCells() : 0) << "\n";
os << indent << "Number of available time steps: "
<< (dbPtr_.valid() ? dbPtr_().times().size() : 0) << endl;
os << indent << "mesh region: " << meshRegion_ << "\n";
}
// ************************************************************************* //

View file

@ -0,0 +1,758 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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::vtkPV4Foam
Description
Provides a reader interface for OpenFOAM to VTK interaction.
SourceFiles
vtkPV4Foam.C
vtkPV4Foam.H
vtkPV4FoamI.H
vtkPV4FoamFields.C
vtkPV4FoamMesh.C
vtkPV4FoamMeshLagrangian.C
vtkPV4FoamMeshPatch.C
vtkPV4FoamMeshSet.C
vtkPV4FoamMeshVolume.C
vtkPV4FoamMeshZone.C
vtkPV4FoamFaceField.H
vtkPV4FoamLagrangianFields.H
vtkPV4FoamPatchField.H
vtkPV4FoamPointFields.H
vtkPV4FoamPoints.H
vtkPV4FoamUpdateInfo.C
vtkPV4FoamUpdateInfoFields.H
vtkPV4FoamUtilities.C
vtkPV4FoamVolFields.H
vtkPV4FoamAddToSelection.H
// Needed by VTK:
vtkDataArrayTemplateImplicit.txx
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4Foam_H
#define vtkPV4Foam_H
// do not include legacy strstream headers
#ifndef VTK_EXCLUDE_STRSTREAM_HEADERS
# define VTK_EXCLUDE_STRSTREAM_HEADERS
#endif
#include "className.H"
#include "fileName.H"
#include "stringList.H"
#include "wordList.H"
#include "primitivePatch.H"
#include "PrimitivePatchInterpolation.H"
#include "volPointInterpolation.H"
#undef VTKPV4FOAM_DUALPORT
// * * * * * * * * * * * * * Forward Declarations * * * * * * * * * * * * * //
class vtkDataArraySelection;
class vtkDataSet;
class vtkPoints;
class vtkPV4FoamReader;
class vtkRenderer;
class vtkTextActor;
class vtkMultiBlockDataSet;
class vtkPolyData;
class vtkUnstructuredGrid;
class vtkIndent;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Foam class forward declarations
class argList;
class Time;
class fvMesh;
class IOobjectList;
class polyPatch;
class faceSet;
class pointSet;
template<class Type> class IOField;
template<class Type> class List;
/*---------------------------------------------------------------------------*\
Class vtkPV4Foam Declaration
\*---------------------------------------------------------------------------*/
class vtkPV4Foam
{
// Private classes
//- 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;
}
};
//- bookkeeping for polyhedral cell decomposition
// hide in extra pointMap (cellSet/cellZone) for now
class polyDecomp
{
labelList superCells_;
labelList addPointCellLabels_;
labelList pointMap_;
public:
polyDecomp()
{}
//- Label of original cell for decomposed cells
labelList& superCells()
{
return superCells_;
}
//- Label of original cell for decomposed cells
const labelList& superCells() const
{
return superCells_;
}
//- Cell-centre labels for additional points of decomposed cells
labelList& addPointCellLabels()
{
return addPointCellLabels_;
}
//- Cell-centre labels for additional points of decomposed cells
const labelList& addPointCellLabels() const
{
return addPointCellLabels_;
}
//- Point labels for subsetted meshes
labelList& pointMap()
{
return pointMap_;
}
//- Point labels for subsetted meshes
const labelList& pointMap() const
{
return pointMap_;
}
//- Clear
void clear()
{
superCells_.clear();
addPointCellLabels_.clear();
pointMap_.clear();
}
};
// Private Data
//- Access to the controlling vtkPV4FoamReader
vtkPV4FoamReader* reader_;
//- Foam time control
autoPtr<Time> dbPtr_;
//- Foam mesh
fvMesh* meshPtr_;
//- The mesh region
word meshRegion_;
//- The mesh directory for the region
fileName meshDir_;
//- The time index
int timeIndex_;
//- Track changes in mesh geometry
bool meshChanged_;
//- Track changes in fields
bool fieldsChanged_;
//- Selected geometrical parts (internalMesh, patches, ...)
boolList partStatus_;
//- Datasets corresponding to selected geometrical pieces
// a negative number indicates that no vtkmesh exists for this piece
labelList partDataset_;
//- First instance and size of various mesh parts
// used to index into partStatus_ and partDataset_
partInfo partInfoVolume_;
partInfo partInfoPatches_;
partInfo partInfoLagrangian_;
partInfo partInfoCellZones_;
partInfo partInfoFaceZones_;
partInfo partInfoPointZones_;
partInfo partInfoCellSets_;
partInfo partInfoFaceSets_;
partInfo partInfoPointSets_;
//- Decomposed cells information (mesh regions)
// TODO: regions
List<polyDecomp> regionPolyDecomp_;
//- Decomposed cells information (cellZone meshes)
List<polyDecomp> zonePolyDecomp_;
//- Decomposed cells information (cellSet meshes)
List<polyDecomp> csetPolyDecomp_;
//- List of patch names for rendering to window
List<vtkTextActor*> patchTextActorsPtrs_;
// Private Member Functions
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static void AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const partInfo&,
const label datasetNo,
const string& datasetName
);
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static vtkDataSet* GetDataSetFromBlock
(
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo
);
// Convenience method use to convert the readers from VTK 5
// multiblock API to the current composite data infrastructure
static label GetNumberOfDataSets
(
vtkMultiBlockDataSet* output,
const partInfo&
);
//- Reset data counters
void resetCounters();
// Update information helper functions
//- Update the mesh parts selected in the GUI
void updateMeshPartsStatus();
//- Internal mesh info
void updateInfoInternalMesh();
//- Lagrangian info
void updateInfoLagrangian();
//- Patch info
void updateInfoPatches();
//- Set info
void updateInfoSets();
//- Zone info
void updateInfoZones();
//- Read zone names for zoneType from file
wordList readZoneNames(const word& zoneType);
//- Add objects of Type to paraview array selection
template<class Type>
label addToSelection
(
vtkDataArraySelection*,
const IOobjectList&,
const string& suffix=string::null
);
//- Field info
template<template<class> class patchType, class meshType>
void updateInfoFields(vtkDataArraySelection*);
//- Lagrangian field info
void updateInfoLagrangianFields();
// Update helper functions
//- Foam mesh
void updateFoamMesh();
//- Reduce memory footprint after conversion
void reduceMemory();
//- Volume fields
void updateVolFields(vtkMultiBlockDataSet*);
//- Point fields
void updatePointFields(vtkMultiBlockDataSet*);
//- Lagrangian fields
void updateLagrangianFields(vtkMultiBlockDataSet*);
// Mesh conversion functions
//- Volume mesh
void convertMeshVolume(vtkMultiBlockDataSet*, int& blockNo);
//- Lagrangian mesh
void convertMeshLagrangian(vtkMultiBlockDataSet*, int& blockNo);
//- Patch meshes
void convertMeshPatches(vtkMultiBlockDataSet*, int& blockNo);
//- Cell zone meshes
void convertMeshCellZones(vtkMultiBlockDataSet*, int& blockNo);
//- Face zone meshes
void convertMeshFaceZones(vtkMultiBlockDataSet*, int& blockNo);
//- Point zone meshes
void convertMeshPointZones(vtkMultiBlockDataSet*, int& blockNo);
//- Cell set meshes
void convertMeshCellSets(vtkMultiBlockDataSet*, int& blockNo);
//- Face set meshes
void convertMeshFaceSets(vtkMultiBlockDataSet*, int& blockNo);
//- Point set meshes
void convertMeshPointSets(vtkMultiBlockDataSet*, int& blockNo);
// Add mesh functions
//- Add internal mesh/cell set meshes
vtkUnstructuredGrid* volumeVTKMesh(const fvMesh&, polyDecomp&);
//- Add Lagrangian mesh
vtkPolyData* lagrangianVTKMesh
(
const fvMesh&,
const word& cloudName
);
//- Add patch mesh
vtkPolyData* patchVTKMesh(const polyPatch&);
//- Add face zone mesh
vtkPolyData* faceZoneVTKMesh
(
const fvMesh&,
const labelList& faceLabels
);
//- Add point zone
vtkPolyData* pointZoneVTKMesh
(
const fvMesh&,
const labelList& pointLabels
);
//- Add face set mesh
vtkPolyData* faceSetVTKMesh
(
const fvMesh&,
const faceSet&
);
//- Add point mesh
vtkPolyData* pointSetVTKMesh
(
const fvMesh&,
const pointSet&
);
// Field conversion functions
//- Convert volume fields
void convertVolFields(vtkMultiBlockDataSet*);
//- Convert point fields
void convertPointFields(vtkMultiBlockDataSet*);
//- Convert Lagrangian fields
void convertLagrangianFields(vtkMultiBlockDataSet*);
//- Add the fields in the selected time directory to the selection
// lists
template<class GeoField>
label addObjectsToSelection
(
vtkDataArraySelection*,
const IOobjectList&,
const string& suffix=string::null
);
// Convert Foam fields
//- Volume fields - all types
template<class Type>
void convertVolFields
(
const fvMesh&,
const PtrList<PrimitivePatchInterpolation<primitivePatch> >&,
const IOobjectList&,
vtkMultiBlockDataSet* output
);
//- Volume field - all selected parts
template<class Type>
void convertVolFieldBlock
(
const GeometricField<Type, fvPatchField, volMesh>&,
autoPtr<GeometricField<Type, pointPatchField, pointMesh> >&,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
);
//- Volume field
template<class Type>
void convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo,
const polyDecomp&
);
//- Patch field
template<class Type>
void convertPatchField
(
const word& name,
const Field<Type>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo
);
//- face set/zone field
template<class Type>
void convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo,
const fvMesh&,
const labelList& faceLabels
);
//- face set/zone field
template<class Type>
void convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo,
const fvMesh&,
const faceSet&
);
//- Lagrangian fields - all types
template<class Type>
void convertLagrangianFields
(
const IOobjectList&,
vtkMultiBlockDataSet* output,
const label datasetNo
);
//- Lagrangian field
template<class Type>
void convertLagrangianField
(
const IOField<Type>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo
);
//- Point fields - all types
template<class Type>
void convertPointFields
(
const fvMesh&,
const pointMesh&,
const IOobjectList&,
vtkMultiBlockDataSet* output
);
//- Point field - all selected parts
template<class Type>
void convertPointFieldBlock
(
const GeometricField<Type, pointPatchField, pointMesh>&,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>&
);
//- Point fields
template<class Type>
void convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>&,
const GeometricField<Type, fvPatchField, volMesh>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo,
const polyDecomp&
);
//- Patch point field
template<class Type>
void convertPatchPointField
(
const word& name,
const Field<Type>&,
vtkMultiBlockDataSet* output,
const partInfo&,
const label datasetNo
);
// GUI selection helper functions
//- Extract up to the first non-word characters
inline static word getFirstWord(const char*);
//- Only keep what is listed in hashSet
static void pruneObjectList
(
IOobjectList&,
const wordHashSet&
);
//- Retrieve the current selections
static wordHashSet getSelected(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
static wordHashSet getSelected
(
vtkDataArraySelection*,
const partInfo&
);
//- Retrieve the current selections
static stringList getSelectedArrayEntries(vtkDataArraySelection*);
//- Retrieve a sub-list of the current selections
static stringList getSelectedArrayEntries
(
vtkDataArraySelection*,
const partInfo&
);
//- Set selection(s)
static void setSelectedArrayEntries
(
vtkDataArraySelection*,
const stringList&
);
//- Get the first word from the mesh parts selection
word getPartName(int);
//- Disallow default bitwise copy construct
vtkPV4Foam(const vtkPV4Foam&);
//- Disallow default bitwise assignment
void operator=(const vtkPV4Foam&);
public:
//- Static data members
ClassName("vtkPV4Foam");
// Constructors
//- Construct from components
vtkPV4Foam
(
const char* const FileName,
vtkPV4FoamReader* reader
);
//- Destructor
~vtkPV4Foam();
// Member Functions
//- Update
void updateInfo();
void Update
(
vtkMultiBlockDataSet* output,
vtkMultiBlockDataSet* lagrangianOutput
);
//- Clean any storage
void CleanUp();
//- Allocate and return a list of selected times
// returns the count via the parameter
double* findTimes(int& nTimeSteps);
//- Add patch names to the display
void addPatchNames(vtkRenderer* renderer);
//- Remove patch names from the display
void removePatchNames(vtkRenderer* renderer);
//- set the runTime to the first plausible request time,
// returns the timeIndex
// sets to "constant" on error
int setTime(int count, const double requestTimes[]);
//- The current time index
int timeIndex() const
{
return timeIndex_;
}
// Access
//- Debug information
void PrintSelf(ostream&, vtkIndent) const;
//- Simple memory used debugging information
static void printMemory();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
# include "vtkPV4FoamI.H"
#endif
// ************************************************************************* //

View file

@ -0,0 +1,69 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 vtkPV4FoamAddToSelection_H
#define vtkPV4FoamAddToSelection_H
// FOAM includes
#include "IOobjectList.H"
#include "SortableList.H"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
Foam::label Foam::vtkPV4Foam::addToSelection
(
vtkDataArraySelection *select,
const IOobjectList& objectLst,
const string& suffix
)
{
SortableList<word> names(objectLst.names(Type::typeName));
forAll(names, nameI)
{
if (suffix.size())
{
select->AddArray((names[nameI] + suffix).c_str());
}
else
{
select->AddArray(names[nameI].c_str());
}
}
return names.size();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,210 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamFaceField_H
#define vtkPV4FoamFaceField_H
// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
#include "vtkOpenFOAMTupleRemap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV4Foam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const labelList& faceLabels
)
{
const label nComp = pTraits<Type>::nComponents;
const label nInternalFaces = mesh.nInternalFaces();
const label nFaces = mesh.nFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples( faceLabels.size() );
cellData->SetNumberOfComponents( nComp );
cellData->Allocate( nComp*faceLabels.size() );
cellData->SetName( tf.name().c_str() );
if (debug)
{
Info<< "convert convertFaceField: "
<< tf.name()
<< " size = " << tf.size()
<< " nComp=" << nComp
<< " nTuples = " << faceLabels.size() << endl;
}
float vec[nComp];
// for interior faces: average owner/neighbour
// for boundary faces: owner
forAll(faceLabels, faceI)
{
// Bug fix: filter inactive faces. HJ, 21/Mar/2011
const label faceNo = faceLabels[faceI];
if (faceNo < nInternalFaces)
{
Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]);
for (direction d = 0; d < nComp; d++)
{
vec[d] = component(t, d);
}
}
else if (faceNo < nFaces)
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d = 0; d < nComp; d++)
{
vec[d] = component(t, d);
}
}
else
{
for (direction d = 0; d < nComp; d++)
{
vec[d] = 0;
}
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(faceI, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
template<class Type>
void Foam::vtkPV4Foam::convertFaceField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo,
const fvMesh& mesh,
const faceSet& fSet
)
{
const label nComp = pTraits<Type>::nComponents;
const label nInternalFaces = mesh.nInternalFaces();
const label nFaces = mesh.nFaces();
const labelList& faceOwner = mesh.faceOwner();
const labelList& faceNeigh = mesh.faceNeighbour();
vtkFloatArray *cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples( fSet.size() );
cellData->SetNumberOfComponents( nComp );
cellData->Allocate( nComp*fSet.size() );
cellData->SetName( tf.name().c_str() );
if (debug)
{
Info<< "convert convertFaceField: "
<< tf.name()
<< " size = " << tf.size()
<< " nComp=" << nComp
<< " nTuples = " << fSet.size() << endl;
}
float vec[nComp];
// for interior faces: average owner/neighbour
// for boundary faces: owner
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
const label faceNo = iter.key();
// Bug fix: filter inactive faces. HJ, 21/Mar/2011
if (faceNo < nInternalFaces)
{
Type t = 0.5*(tf[faceOwner[faceNo]] + tf[faceNeigh[faceNo]]);
for (direction d = 0; d < nComp; d++)
{
vec[d] = component(t, d);
}
}
else if (faceNo < nFaces)
{
const Type& t = tf[faceOwner[faceNo]];
for (direction d = 0; d < nComp; d++)
{
vec[d] = component(t, d);
}
}
else
{
for (direction d = 0; d < nComp; d++)
{
vec[d] = 0;
}
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(faceI, vec);
++faceI;
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,326 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "IOobjectList.H"
#include "vtkPV4FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
#include "vtkPV4FoamVolFields.H"
#include "vtkPV4FoamPointFields.H"
#include "vtkPV4FoamLagrangianFields.H"
void Foam::vtkPV4Foam::pruneObjectList
(
IOobjectList& objects,
const wordHashSet& selected
)
{
// hash all the selected field names
if (!selected.size())
{
objects.clear();
}
// only keep selected fields
forAllIter(IOobjectList, objects, iter)
{
if (!selected.found(iter()->name()))
{
objects.erase(iter);
}
}
}
void Foam::vtkPV4Foam::convertVolFields
(
vtkMultiBlockDataSet* output
)
{
const fvMesh& mesh = *meshPtr_;
wordHashSet selectedFields = getSelected
(
reader_->GetVolFieldSelection()
);
if (!selectedFields.size())
{
return;
}
// Get objects (fields) for this time - only keep selected fields
// the region name is already in the mesh db
IOobjectList objects(mesh, dbPtr_().timeName());
pruneObjectList(objects, selectedFields);
if (!objects.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertVolFields" << nl
<< "converting Foam volume fields" << endl;
forAllConstIter(IOobjectList, objects, iter)
{
Info<< " " << iter()->name()
<< " == " << iter()->objectPath() << nl;
}
printMemory();
}
PtrList<PrimitivePatchInterpolation<primitivePatch> >
ppInterpList(mesh.boundaryMesh().size());
forAll(ppInterpList, i)
{
ppInterpList.set
(
i,
new PrimitivePatchInterpolation<primitivePatch>
(
mesh.boundaryMesh()[i]
)
);
}
convertVolFields<scalar>
(
mesh, ppInterpList, objects, output
);
convertVolFields<vector>
(
mesh, ppInterpList, objects, output
);
convertVolFields<sphericalTensor>
(
mesh, ppInterpList, objects, output
);
convertVolFields<symmTensor>
(
mesh, ppInterpList, objects, output
);
convertVolFields<tensor>
(
mesh, ppInterpList, objects, output
);
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertVolFields" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertPointFields
(
vtkMultiBlockDataSet* output
)
{
const fvMesh& mesh = *meshPtr_;
wordHashSet selectedFields = getSelected
(
reader_->GetPointFieldSelection()
);
if (!selectedFields.size())
{
return;
}
// Get objects (fields) for this time - only keep selected fields
// the region name is already in the mesh db
IOobjectList objects(mesh, dbPtr_().timeName());
pruneObjectList(objects, selectedFields);
if (!objects.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertPointFields" << nl
<< "converting Foam volume fields" << endl;
forAllConstIter(IOobjectList, objects, iter)
{
Info<< " " << iter()->name()
<< " == " << iter()->objectPath() << nl;
}
printMemory();
}
// Construct interpolation on the raw mesh
// HJ, bug fix? Point mesh handled by objectRegistry
// HJ, 11/Nov/2010
const pointMesh& pMesh = pointMesh::New(mesh);
// pointMesh pMesh(mesh);
convertPointFields<scalar>
(
mesh, pMesh, objects, output
);
convertPointFields<vector>
(
mesh, pMesh, objects, output
);
convertPointFields<sphericalTensor>
(
mesh, pMesh, objects, output
);
convertPointFields<symmTensor>
(
mesh, pMesh, objects, output
);
convertPointFields<tensor>
(
mesh, pMesh, objects, output
);
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertPointFields" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertLagrangianFields
(
vtkMultiBlockDataSet* output
)
{
partInfo& selector = partInfoLagrangian_;
const fvMesh& mesh = *meshPtr_;
wordHashSet selectedFields = getSelected
(
reader_->GetLagrangianFieldSelection()
);
if (!selectedFields.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertLagrangianFields" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word cloudName = getPartName(partId);
const label datasetNo = partDataset_[partId];
if (!partStatus_[partId] || datasetNo < 0)
{
continue;
}
// Get the Lagrangian fields for this time and this cloud
// but only keep selected fields
// the region name is already in the mesh db
IOobjectList objects
(
mesh,
dbPtr_().timeName(),
cloud::prefix/cloudName
);
pruneObjectList(objects, selectedFields);
if (!objects.size())
{
continue;
}
if (debug)
{
Info<< "converting Foam lagrangian fields" << nl;
forAllConstIter(IOobjectList, objects, iter)
{
Info<< " " << iter()->name()
<< " == " << iter()->objectPath() << nl;
}
}
convertLagrangianFields<label>
(
objects, output, datasetNo
);
convertLagrangianFields<scalar>
(
objects, output, datasetNo
);
convertLagrangianFields<vector>
(
objects, output, datasetNo
);
convertLagrangianFields<sphericalTensor>
(
objects, output, datasetNo
);
convertLagrangianFields<symmTensor>
(
objects, output, datasetNo
);
convertLagrangianFields<tensor>
(
objects, output, datasetNo
);
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertLagrangianFields" << endl;
printMemory();
}
}
// ************************************************************************* //

View file

@ -0,0 +1,48 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline Foam::word Foam::vtkPV4Foam::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;
}
}
// ************************************************************************* //

View file

@ -0,0 +1,114 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamLagrangianFields_H
#define vtkPV4FoamLagrangianFields_H
#include "Cloud.H"
#include "vtkOpenFOAMTupleRemap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV4Foam::convertLagrangianFields
(
const IOobjectList& objects,
vtkMultiBlockDataSet* output,
const label datasetNo
)
{
const partInfo& selector = partInfoLagrangian_;
forAllConstIter(IOobjectList, objects, iter)
{
// restrict to this IOField<Type>
if (iter()->headerClassName() == IOField<Type>::typeName)
{
IOField<Type> tf(*iter());
convertLagrangianField(tf, output, selector, datasetNo);
}
}
}
template<class Type>
void Foam::vtkPV4Foam::convertLagrangianField
(
const IOField<Type>& tf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
)
{
const label nComp = pTraits<Type>::nComponents;
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples( tf.size() );
pointData->SetNumberOfComponents( nComp );
pointData->Allocate( nComp*tf.size() );
pointData->SetName( tf.name().c_str() );
if (debug)
{
Info<< "convert LagrangianField: "
<< tf.name()
<< " size = " << tf.size()
<< " nComp=" << nComp
<< " nTuples = " << tf.size() << endl;
}
float vec[nComp];
forAll(tf, i)
{
const Type& t = tf[i];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,644 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "fvMeshSubset.H"
#include "vtkPV4FoamReader.h"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPolyData.h"
#include "vtkUnstructuredGrid.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkPV4Foam::convertMeshVolume
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoVolume_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
regionPolyDecomp_.setSize(selector.size());
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshVolume" << endl;
printMemory();
}
// Convert the internalMesh
// this looks like more than one part, but it isn't
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word partName = "internalMesh";
if (!partStatus_[partId])
{
continue;
}
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
mesh,
regionPolyDecomp_[datasetNo]
);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshVolume" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshLagrangian
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoLagrangian_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshLagrangian" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word cloudName = getPartName(partId);
if (!partStatus_[partId])
{
continue;
}
vtkPolyData* vtkmesh = lagrangianVTKMesh(mesh, cloudName);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, cloudName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshLagrangian" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshPatches
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoPatches_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
const polyBoundaryMesh& patches = mesh.boundaryMesh();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshPatches" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word patchName = getPartName(partId);
const label patchId = patches.findPatchID(patchName);
if (!partStatus_[partId] || patchId < 0)
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for patch[" << patchId <<"] "
<< patchName << endl;
}
vtkPolyData* vtkmesh = patchVTKMesh(patches[patchId]);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, patchName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshPatches" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshCellZones
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoCellZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
zonePolyDecomp_.setSize(selector.size());
if (!selector.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshCellZones" << endl;
printMemory();
}
const cellZoneMesh& zMesh = mesh.cellZones();
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word zoneName = getPartName(partId);
const label zoneId = zMesh.findZoneID(zoneName);
if (!partStatus_[partId] || zoneId < 0)
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for cellZone[" << zoneId << "] "
<< zoneName << endl;
}
fvMeshSubset subsetMesh
(
IOobject
(
"set",
mesh.time().constant(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
);
subsetMesh.setLargeCellSubset(labelHashSet(zMesh[zoneId]));
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
subsetMesh.subMesh(),
zonePolyDecomp_[datasetNo]
);
if (vtkmesh)
{
// superCells + addPointCellLabels must contain global cell ids
inplaceRenumber
(
subsetMesh.cellMap(),
zonePolyDecomp_[datasetNo].superCells()
);
inplaceRenumber
(
subsetMesh.cellMap(),
zonePolyDecomp_[datasetNo].addPointCellLabels()
);
// copy pointMap as well, otherwise pointFields fail
zonePolyDecomp_[datasetNo].pointMap() = subsetMesh.pointMap();
AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshCellZones" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshCellSets
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoCellSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
// resize for decomposed polyhedra
csetPolyDecomp_.setSize(selector.size());
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshCellSets" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word partName = getPartName(partId);
if (!partStatus_[partId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for cellSet=" << partName << endl;
}
const cellSet cSet(mesh, partName);
fvMeshSubset subsetMesh
(
IOobject
(
"set",
mesh.time().constant(),
mesh,
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh
);
subsetMesh.setLargeCellSubset(cSet);
vtkUnstructuredGrid* vtkmesh = volumeVTKMesh
(
subsetMesh.subMesh(),
csetPolyDecomp_[datasetNo]
);
if (vtkmesh)
{
// superCells + addPointCellLabels must contain global cell ids
inplaceRenumber
(
subsetMesh.cellMap(),
csetPolyDecomp_[datasetNo].superCells()
);
inplaceRenumber
(
subsetMesh.cellMap(),
csetPolyDecomp_[datasetNo].addPointCellLabels()
);
// copy pointMap as well, otherwise pointFields fail
csetPolyDecomp_[datasetNo].pointMap() = subsetMesh.pointMap();
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshCellSets" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshFaceZones
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoFaceZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (!selector.size())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshFaceZones" << endl;
printMemory();
}
const faceZoneMesh& zMesh = mesh.faceZones();
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word zoneName = getPartName(partId);
const label zoneId = zMesh.findZoneID(zoneName);
if (!partStatus_[partId] || zoneId < 0)
{
continue;
}
if (debug)
{
Info<< "Creating VTKmesh for faceZone[" << zoneId << "] "
<< zoneName << endl;
}
vtkPolyData* vtkmesh = faceZoneVTKMesh(mesh, zMesh[zoneId]);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshFaceZones" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshFaceSets
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoFaceSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshFaceSets" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const word partName = getPartName(partId);
if (!partStatus_[partId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for faceSet=" << partName << endl;
}
const faceSet fSet(mesh, partName);
vtkPolyData* vtkmesh = faceSetVTKMesh(mesh, fSet);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshFaceSets" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshPointZones
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoPointZones_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshPointZones" << endl;
printMemory();
}
if (selector.size())
{
const pointZoneMesh& zMesh = mesh.pointZones();
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
word zoneName = getPartName(partId);
label zoneId = zMesh.findZoneID(zoneName);
if (!partStatus_[partId] || zoneId < 0)
{
continue;
}
vtkPolyData* vtkmesh = pointZoneVTKMesh(mesh, zMesh[zoneId]);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, zoneName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshPointZones" << endl;
printMemory();
}
}
void Foam::vtkPV4Foam::convertMeshPointSets
(
vtkMultiBlockDataSet* output,
int& blockNo
)
{
partInfo& selector = partInfoPointSets_;
selector.block(blockNo); // set output block
label datasetNo = 0; // restart at dataset 0
const fvMesh& mesh = *meshPtr_;
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::convertMeshPointSets" << endl;
printMemory();
}
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
word partName = getPartName(partId);
if (!partStatus_[partId])
{
continue;
}
if (debug)
{
Info<< "Creating VTK mesh for pointSet=" << partName << endl;
}
const pointSet pSet(mesh, partName);
vtkPolyData* vtkmesh = pointSetVTKMesh(mesh, pSet);
if (vtkmesh)
{
AddToBlock(output, vtkmesh, selector, datasetNo, partName);
vtkmesh->Delete();
partDataset_[partId] = datasetNo++;
}
}
// anything added?
if (datasetNo)
{
++blockNo;
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::convertMeshPointSets" << endl;
printMemory();
}
}
// ************************************************************************* //

View file

@ -0,0 +1,112 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "Cloud.H"
#include "fvMesh.H"
#include "IOobjectList.H"
#include "passiveParticle.H"
#include "vtkPV4FoamPoints.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkPolyData* Foam::vtkPV4Foam::lagrangianVTKMesh
(
const fvMesh& mesh,
const word& cloudName
)
{
vtkPolyData* vtkmesh = NULL;
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::lagrangianVTKMesh - timePath "
<< mesh.time().timePath()/cloud::prefix/cloudName << endl;
printMemory();
}
// the region name is already in the mesh db
IOobjectList sprayObjs
(
mesh,
mesh.time().timeName(),
cloud::prefix/cloudName
);
IOobject* positionsPtr = sprayObjs.lookup("positions");
if (positionsPtr)
{
Cloud<passiveParticle> parcels(mesh, cloudName, false);
if (debug)
{
Info<< "cloud with " << parcels.size() << " parcels" << endl;
}
vtkmesh = vtkPolyData::New();
vtkPoints* vtkpoints = vtkPoints::New();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkpoints->Allocate( parcels.size() );
vtkcells->Allocate( parcels.size() );
vtkIdType particleId = 0;
forAllConstIter(Cloud<passiveParticle>, parcels, iter)
{
vtkPV4FoamInsertNextPoint(vtkpoints, iter().position());
vtkcells->InsertNextCell(1, &particleId);
particleId++;
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
vtkmesh->SetVerts(vtkcells);
vtkcells->Delete();
}
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::lagrangianVTKMesh" << endl;
printMemory();
}
return vtkmesh;
}
// ************************************************************************* //

View file

@ -0,0 +1,100 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "polyPatch.H"
#include "primitivePatch.H"
#include "vtkPV4FoamPoints.H"
// VTK includes
#include "vtkCellArray.h"
#include "vtkPoints.h"
#include "vtkPolyData.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkPolyData* Foam::vtkPV4Foam::patchVTKMesh
(
const polyPatch& p
)
{
vtkPolyData* vtkmesh = vtkPolyData::New();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::patchVTKMesh - " << p.name() << endl;
printMemory();
}
// Convert Foam mesh vertices to VTK
const Foam::pointField& points = p.localPoints();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate( points.size() );
forAll(points, i)
{
vtkPV4FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkcells->Allocate( faces.size() );
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll(f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::patchVTKMesh - " << p.name() << endl;
printMemory();
}
return vtkmesh;
}
// ************************************************************************* //

View file

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "faceSet.H"
#include "pointSet.H"
#include "vtkPV4FoamPoints.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkPolyData* Foam::vtkPV4Foam::faceSetVTKMesh
(
const fvMesh& mesh,
const faceSet& fSet
)
{
vtkPolyData* vtkmesh = vtkPolyData::New();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::faceSetVTKMesh" << endl;
printMemory();
}
// Construct primitivePatch of faces in fSet.
const faceList& meshFaces = mesh.faces();
faceList patchFaces(fSet.size());
label faceI = 0;
forAllConstIter(faceSet, fSet, iter)
{
patchFaces[faceI++] = meshFaces[iter.key()];
}
primitiveFacePatch p(patchFaces, mesh.points());
// The balance of this routine should be identical to patchVTKMesh
// Convert Foam mesh vertices to VTK
const pointField& points = p.localPoints();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate( points.size() );
forAll(points, i)
{
vtkPV4FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkcells->Allocate( faces.size() );
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll(f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::faceSetVTKMesh" << endl;
printMemory();
}
return vtkmesh;
}
vtkPolyData* Foam::vtkPV4Foam::pointSetVTKMesh
(
const fvMesh& mesh,
const pointSet& pSet
)
{
vtkPolyData* vtkmesh = vtkPolyData::New();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::pointSetVTKMesh" << endl;
printMemory();
}
const pointField& meshPoints = mesh.points();
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate( pSet.size() );
forAllConstIter(pointSet, pSet, iter)
{
vtkPV4FoamInsertNextPoint(vtkpoints, meshPoints[iter.key()]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::pointSetVTKMesh" << endl;
printMemory();
}
return vtkmesh;
}
// ************************************************************************* //

View file

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

View file

@ -0,0 +1,174 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "vtkPV4Foam.H"
// Foam includes
#include "vtkPV4FoamPoints.H"
// VTK includes
#include "vtkPoints.h"
#include "vtkPolyData.h"
#include "vtkCellArray.h"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
vtkPolyData* Foam::vtkPV4Foam::faceZoneVTKMesh
(
const fvMesh& mesh,
const labelList& faceLabels
)
{
vtkPolyData* vtkmesh = vtkPolyData::New();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::faceZoneVTKMesh" << endl;
printMemory();
}
// Construct primitivePatch of faces in faceZone
const faceList& meshFaces = mesh.allFaces();
faceList patchFaces(faceLabels.size());
label npf = 0;
// Filter faces that are not in live mesh
// Bug fix. HJ, 21/Mar/2011
forAll(faceLabels, faceI)
{
if (faceLabels[faceI] < mesh.nFaces())
{
patchFaces[npf] = meshFaces[faceLabels[faceI]];
npf++;
}
}
patchFaces.setSize(npf);
primitiveFacePatch p(patchFaces, mesh.points());
// The balance of this routine should be identical to patchVTKMesh
// Convert Foam mesh vertices to VTK
const pointField& points = p.localPoints();
vtkPoints* vtkpoints = vtkPoints::New();
vtkpoints->Allocate(points.size());
forAll(points, i)
{
vtkPV4FoamInsertNextPoint(vtkpoints, points[i]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
// Add faces as polygons
const faceList& faces = p.localFaces();
vtkCellArray* vtkcells = vtkCellArray::New();
vtkcells->Allocate( faces.size() );
forAll(faces, faceI)
{
const face& f = faces[faceI];
vtkIdType nodeIds[f.size()];
forAll(f, fp)
{
nodeIds[fp] = f[fp];
}
vtkcells->InsertNextCell(f.size(), nodeIds);
}
vtkmesh->SetPolys(vtkcells);
vtkcells->Delete();
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::faceZoneVTKMesh" << endl;
printMemory();
}
return vtkmesh;
}
vtkPolyData* Foam::vtkPV4Foam::pointZoneVTKMesh
(
const fvMesh& mesh,
const labelList& pointLabels
)
{
vtkPolyData* vtkmesh = vtkPolyData::New();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::pointZoneVTKMesh" << endl;
printMemory();
}
const pointField& meshPoints = mesh.allPoints();
// Filter point labels to include only live points
labelList pl(pointLabels.size());
label npl = 0;
forAll (pointLabels, pointI)
{
if (pointLabels[pointI] < mesh.nPoints())
{
pl[npl] = pointLabels[pointI];
npl++;
}
}
pl.setSize(npl);
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->Allocate( pl.size());
forAll(pointLabels, pointI)
{
vtkPV4FoamInsertNextPoint(vtkpoints, meshPoints[pl[pointI]]);
}
vtkmesh->SetPoints(vtkpoints);
vtkpoints->Delete();
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::pointZoneVTKMesh" << endl;
printMemory();
}
return vtkmesh;
}
// ************************************************************************* //

View file

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamPatchField_H
#define vtkPV4FoamPatchField_H
// VTK includes
#include "vtkCellData.h"
#include "vtkFloatArray.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkPointData.h"
#include "vtkPolyData.h"
#include "vtkOpenFOAMTupleRemap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV4Foam::convertPatchField
(
const word& name,
const Field<Type>& ptf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
)
{
const label nComp = pTraits<Type>::nComponents;
vtkFloatArray* cellData = vtkFloatArray::New();
cellData->SetNumberOfTuples( ptf.size() );
cellData->SetNumberOfComponents( nComp );
cellData->Allocate( nComp*ptf.size() );
cellData->SetName( name.c_str() );
float vec[nComp];
forAll(ptf, i)
{
const Type& t = ptf[i];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
cellData->InsertTuple(i, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(cellData);
cellData->Delete();
}
// as above, but with PointData()
template<class Type>
void Foam::vtkPV4Foam::convertPatchPointField
(
const word& name,
const Field<Type>& pptf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo
)
{
const label nComp = pTraits<Type>::nComponents;
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples( pptf.size() );
pointData->SetNumberOfComponents( nComp );
pointData->Allocate( nComp*pptf.size() );
pointData->SetName( name.c_str() );
float vec[nComp];
forAll(pptf, i)
{
const Type& t = pptf[i];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i, vec);
}
vtkPolyData::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,285 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamPointFields_H
#define vtkPV4FoamPointFields_H
// Foam includes
#include "interpolatePointToCell.H"
#include "vtkOpenFOAMTupleRemap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV4Foam::convertPointFields
(
const fvMesh& mesh,
const pointMesh& pMesh,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAllConstIter(IOobjectList, objects, iter)
{
const word& fieldName = iter()->name();
// restrict to this GeometricField<Type, ...>
if
(
iter()->headerClassName()
!= GeometricField<Type, pointPatchField, pointMesh>::typeName
)
{
continue;
}
if (debug)
{
Info<< "Foam::vtkPV4Foam::convertPointFields : "
<< fieldName << endl;
}
GeometricField<Type, pointPatchField, pointMesh> ptf
(
*iter(),
pMesh
);
// Convert activated internalMesh regions
convertPointFieldBlock
(
ptf,
output,
partInfoVolume_,
regionPolyDecomp_
);
// Convert activated cellZones
convertPointFieldBlock
(
ptf,
output,
partInfoCellZones_,
zonePolyDecomp_
);
// Convert activated cellSets
convertPointFieldBlock
(
ptf,
output,
partInfoCellSets_,
csetPolyDecomp_
);
//
// Convert patches - if activated
//
for
(
int partId = partInfoPatches_.start();
partId < partInfoPatches_.end();
++partId
)
{
const word patchName = getPartName(partId);
const label datasetNo = partDataset_[partId];
const label patchId = patches.findPatchID(patchName);
if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
{
continue;
}
convertPatchPointField
(
fieldName,
ptf.boundaryField()[patchId].patchInternalField()(),
output,
partInfoPatches_,
datasetNo
);
}
}
}
template<class Type>
void Foam::vtkPV4Foam::convertPointFieldBlock
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
)
{
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const label datasetNo = partDataset_[partId];
if (datasetNo >= 0 && partStatus_[partId])
{
convertPointField
(
ptf,
GeometricField<Type, fvPatchField, volMesh>::null(),
output,
selector,
datasetNo,
decompLst[datasetNo]
);
}
}
}
template<class Type>
void Foam::vtkPV4Foam::convertPointField
(
const GeometricField<Type, pointPatchField, pointMesh>& ptf,
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo,
const polyDecomp& decomp
)
{
const label nComp = pTraits<Type>::nComponents;
const labelList& addPointCellLabels = decomp.addPointCellLabels();
const labelList& pointMap = decomp.pointMap();
// use a pointMap or address directly into mesh
label nPoints;
if (pointMap.size())
{
nPoints = pointMap.size();
}
else
{
nPoints = ptf.size();
}
vtkFloatArray *pointData = vtkFloatArray::New();
pointData->SetNumberOfTuples(nPoints + addPointCellLabels.size());
pointData->SetNumberOfComponents(nComp);
pointData->Allocate(nComp*(nPoints + addPointCellLabels.size()));
pointData->SetName(ptf.name().c_str());
if (debug)
{
Info<< "convert convertPointField: "
<< ptf.name()
<< " size = " << nPoints
<< " nComp=" << nComp
<< " nTuples = " << (nPoints + addPointCellLabels.size())
<< endl;
}
float vec[nComp];
if (pointMap.size())
{
forAll(pointMap, i)
{
const Type& t = ptf[pointMap[i]];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i, vec);
}
}
else
{
forAll(ptf, i)
{
const Type& t = ptf[i];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i, vec);
}
}
// continue insertion from here
label i = nPoints;
if (&tf != &GeometricField<Type, fvPatchField, volMesh>::null())
{
forAll(addPointCellLabels, apI)
{
const Type& t = tf[addPointCellLabels[apI]];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i++, vec);
}
}
else
{
forAll(addPointCellLabels, apI)
{
Type t = interpolatePointToCell(ptf, addPointCellLabels[apI]);
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
pointData->InsertTuple(i++, vec);
}
}
vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetPointData()
->AddArray(pointData);
pointData->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,80 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamPoints_H
#define vtkPV4FoamPoints_H
// VTK includes
#include "vtkPoints.h"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline void vtkPV4FoamInsertNextPoint
(
vtkPoints *points,
const Foam::point& p
)
{
points->InsertNextPoint(p.x(), p.y(), p.z());
}
#if 0
// this should be faster, but didn't get it working ...
inline void vtkPV4FoamSetPoint
(
vtkPoints *points,
const Foam::label id,
const Foam::point& p
)
{
points->SetPoint(id, p.x(), p.y(), p.z());
}
// Convert Foam mesh vertices to VTK
inline vtkPoints* vtkPV4FoamVTKPoints(const Foam::pointField& points)
{
vtkPoints *vtkpoints = vtkPoints::New();
vtkpoints->SetNumberOfPoints(points.size());
forAll(points, i)
{
const Foam::point& p = points[i];
vtkpoints->SetPoint(i, p.x(), p.y(), p.z());
}
return vtkpoints;
}
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,523 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 "vtkPV4Foam.H"
// Foam includes
#include "cellSet.H"
#include "faceSet.H"
#include "pointSet.H"
#include "IOobjectList.H"
#include "IOPtrList.H"
#include "polyBoundaryMeshEntries.H"
#include "entry.H"
#include "Cloud.H"
#include "vtkPV4FoamReader.h"
// local headers
#include "vtkPV4FoamAddToSelection.H"
#include "vtkPV4FoamUpdateInfoFields.H"
// VTK includes
#include "vtkDataArraySelection.h"
// * * * * * * * * * * * * * * * Private Classes * * * * * * * * * * * * * * //
namespace Foam
{
//- A class for reading zone information without requiring a mesh
class zonesEntries
:
public regIOobject,
public PtrList<entry>
{
public:
// Constructors
explicit zonesEntries(const IOobject& io)
:
regIOobject(io),
PtrList<entry>(readStream("regIOobject"))
{
close();
}
// Member functions
bool writeData(Ostream&) const
{
notImplemented("zonesEntries::writeData(Ostream&) const");
return false;
}
};
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::wordList Foam::vtkPV4Foam::readZoneNames(const word& zoneType)
{
wordList zoneNames;
// mesh not loaded - read from file
IOobject ioObj
(
zoneType,
dbPtr_().findInstance
(
meshDir_,
zoneType,
IOobject::READ_IF_PRESENT
),
meshDir_,
dbPtr_(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
);
if (ioObj.headerOk())
{
zonesEntries zones(ioObj);
zoneNames.setSize(zones.size());
forAll(zones, zoneI)
{
zoneNames[zoneI] = zones[zoneI].keyword();
}
}
return zoneNames;
}
void Foam::vtkPV4Foam::updateInfoInternalMesh()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoInternalMesh" << endl;
}
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
// Determine mesh parts (internalMesh, patches...)
//- Add internal mesh as first entry
partInfoVolume_ = partSelection->GetNumberOfArrays();
partSelection->AddArray("internalMesh");
partInfoVolume_ += 1;
if (debug)
{
// just for debug info
getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV4Foam::updateInfoInternalMesh" << endl;
}
}
void Foam::vtkPV4Foam::updateInfoLagrangian()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoLagrangian" << nl
<< " " << dbPtr_->timePath()/cloud::prefix << endl;
}
// use the db directly since this might be called without a mesh,
// but the region must get added back in
fileName lagrangianPrefix(cloud::prefix);
if (meshRegion_ != polyMesh::defaultRegion)
{
lagrangianPrefix = meshRegion_/cloud::prefix;
}
// Search for list of lagrangian objects for this time
fileNameList cloudDirs
(
readDir(dbPtr_->timePath()/lagrangianPrefix, fileName::DIRECTORY)
);
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
partInfoLagrangian_ = partSelection->GetNumberOfArrays();
int nClouds = 0;
forAll(cloudDirs, cloudI)
{
// Add cloud to GUI list
partSelection->AddArray
(
(cloudDirs[cloudI] + " - lagrangian").c_str()
);
++nClouds;
}
partInfoLagrangian_ += nClouds;
if (debug)
{
// just for debug info
getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV4Foam::updateInfoLagrangian" << endl;
}
}
void Foam::vtkPV4Foam::updateInfoPatches()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoPatches"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
}
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
partInfoPatches_ = partSelection->GetNumberOfArrays();
int nPatches = 0;
if (meshPtr_)
{
const polyBoundaryMesh& patches = meshPtr_->boundaryMesh();
forAll(patches, patchI)
{
const polyPatch& pp = patches[patchI];
if (pp.size())
{
// Add patch to GUI list
partSelection->AddArray
(
(pp.name() + " - patch").c_str()
);
++nPatches;
}
}
}
else
{
// mesh not loaded - read from file
// but this could fail if we've supplied a bad region name
IOobject ioObj
(
"boundary",
dbPtr_().findInstance
(
meshDir_,
"boundary",
IOobject::READ_IF_PRESENT
),
meshDir_,
dbPtr_(),
IOobject::READ_IF_PRESENT,
IOobject::NO_WRITE,
false
);
// this should only ever fail if the mesh region doesn't exist
if (ioObj.headerOk())
{
polyBoundaryMeshEntries patchEntries(ioObj);
// Add (non-zero) patches to the list of mesh parts
forAll(patchEntries, entryI)
{
label nFaces
(
readLabel(patchEntries[entryI].dict().lookup("nFaces"))
);
// Valid patch if nFace > 0 - add patch to GUI list
if (nFaces)
{
partSelection->AddArray
(
(patchEntries[entryI].keyword() + " - patch").c_str()
);
++nPatches;
}
}
}
}
partInfoPatches_ += nPatches;
if (debug)
{
// just for debug info
getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV4Foam::updateInfoPatches" << endl;
}
}
void Foam::vtkPV4Foam::updateInfoZones()
{
if (!reader_->GetIncludeZones())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoZones"
<< " [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]" << endl;
}
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
wordList namesLst;
//
// cellZones information
// ~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
namesLst = meshPtr_->cellZones().names();
}
else
{
namesLst = readZoneNames("cellZones");
}
partInfoCellZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI)
{
partSelection->AddArray((namesLst[elemI] + " - cellZone").c_str());
}
partInfoCellZones_ += namesLst.size();
//
// faceZones information
// ~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
namesLst = meshPtr_->faceZones().names();
}
else
{
namesLst = readZoneNames("faceZones");
}
partInfoFaceZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI)
{
partSelection->AddArray
(
(namesLst[elemI] + " - faceZone").c_str()
);
}
partInfoFaceZones_ += namesLst.size();
//
// pointZones information
// ~~~~~~~~~~~~~~~~~~~~~~
if (meshPtr_)
{
namesLst = meshPtr_->pointZones().names();
}
else
{
namesLst = readZoneNames("pointZones");
}
partInfoPointZones_ = partSelection->GetNumberOfArrays();
forAll(namesLst, elemI)
{
partSelection->AddArray
(
(namesLst[elemI] + " - pointZone").c_str()
);
}
partInfoPointZones_ += namesLst.size();
if (debug)
{
// just for debug info
getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV4Foam::updateInfoZones" << endl;
}
}
void Foam::vtkPV4Foam::updateInfoSets()
{
if (!reader_->GetIncludeSets())
{
return;
}
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoSets" << endl;
}
vtkDataArraySelection* partSelection = reader_->GetPartSelection();
// Add names of sets
IOobjectList objects
(
dbPtr_(),
dbPtr_().findInstance(meshDir_, "faces", IOobject::READ_IF_PRESENT),
meshDir_/"sets"
);
partInfoCellSets_ = partSelection->GetNumberOfArrays();
partInfoCellSets_ += addToSelection<cellSet>
(
partSelection,
objects,
" - cellSet"
);
partInfoFaceSets_ = partSelection->GetNumberOfArrays();
partInfoFaceSets_ += addToSelection<faceSet>
(
partSelection,
objects,
" - faceSet"
);
partInfoPointSets_ = partSelection->GetNumberOfArrays();
partInfoPointSets_ += addToSelection<pointSet>
(
partSelection,
objects,
" - pointSet"
);
if (debug)
{
// just for debug info
getSelectedArrayEntries(partSelection);
Info<< "<end> Foam::vtkPV4Foam::updateInfoSets" << endl;
}
}
void Foam::vtkPV4Foam::updateInfoLagrangianFields()
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoLagrangianFields"
<< endl;
}
vtkDataArraySelection *fieldSelection =
reader_->GetLagrangianFieldSelection();
// preserve the enabled selections
stringList enabledEntries = getSelectedArrayEntries(fieldSelection);
fieldSelection->RemoveAllArrays();
//
// TODO - currently only get fields from ONE cloud
// have to decide if the second set of fields get mixed in
// or dealt with separately
const partInfo& selector = partInfoLagrangian_;
int partId = selector.start();
if (!selector.size() || partId < 0)
{
return;
}
word cloudName = getPartName(partId);
// use the db directly since this might be called without a mesh,
// but the region must get added back in
fileName lagrangianPrefix(cloud::prefix);
if (meshRegion_ != polyMesh::defaultRegion)
{
lagrangianPrefix = meshRegion_/cloud::prefix;
}
IOobjectList objects
(
dbPtr_(),
dbPtr_().timeName(),
lagrangianPrefix/cloudName
);
addToSelection<IOField<label> >
(
fieldSelection,
objects
);
addToSelection<IOField<scalar> >
(
fieldSelection,
objects
);
addToSelection<IOField<vector> >
(
fieldSelection,
objects
);
addToSelection<IOField<sphericalTensor> >
(
fieldSelection,
objects
);
addToSelection<IOField<symmTensor> >
(
fieldSelection,
objects
);
addToSelection<IOField<tensor> >
(
fieldSelection,
objects
);
// restore the enabled selections
setSelectedArrayEntries(fieldSelection, enabledEntries);
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::updateInfoLagrangianFields - "
<< "lagrangian objects.size() = " << objects.size() << endl;
}
}
// ************************************************************************* //

View file

@ -0,0 +1,115 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamUpdateInfoFields_H
#define vtkPV4FoamUpdateInfoFields_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<template<class> class patchType, class meshType>
void Foam::vtkPV4Foam::updateInfoFields
(
vtkDataArraySelection *select
)
{
if (debug)
{
Info<< "<beg> Foam::vtkPV4Foam::updateInfoFields <"
<< meshType::Mesh::typeName
<< "> [meshPtr=" << (meshPtr_ ? "set" : "NULL") << "]"
<< endl;
}
stringList enabledEntries;
// enable 'p' and 'U' on the first call
if (select->GetNumberOfArrays() == 0 && !meshPtr_)
{
enabledEntries.setSize(2);
enabledEntries[0] = "p";
enabledEntries[1] = "U";
}
else
{
// preserve the enabled selections
enabledEntries = getSelectedArrayEntries(select);
}
select->RemoveAllArrays();
// use the db directly since this might be called without a mesh,
// but the region must get added back in
word regionPrefix;
if (meshRegion_ != polyMesh::defaultRegion)
{
regionPrefix = meshRegion_;
}
// Search for list of objects for this time and mesh region
IOobjectList objects(dbPtr_(), dbPtr_().timeName(), regionPrefix);
//- Add volume fields to GUI
addToSelection<GeometricField<scalar, patchType, meshType> >
(
select,
objects
);
addToSelection<GeometricField<vector, patchType, meshType> >
(
select,
objects
);
addToSelection<GeometricField<sphericalTensor, patchType, meshType> >
(
select,
objects
);
addToSelection<GeometricField<symmTensor, patchType, meshType> >
(
select,
objects
);
addToSelection<GeometricField<tensor, patchType, meshType> >
(
select,
objects
);
// restore the enabled selections
setSelectedArrayEntries(select, enabledEntries);
if (debug)
{
Info<< "<end> Foam::vtkPV4Foam::updateInfoFields" << endl;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,342 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 "vtkPV4Foam.H"
#include "vtkPV4FoamReader.h"
// Foam includes
#include "fvMesh.H"
#include "Time.H"
#include "IFstream.H"
// VTK includes
#include "vtkDataArraySelection.h"
#include "vtkDataSet.h"
#include "vtkMultiBlockDataSet.h"
#include "vtkInformation.h"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::vtkPV4Foam::AddToBlock
(
vtkMultiBlockDataSet* output,
vtkDataSet* dataset,
const partInfo& selector,
const label datasetNo,
const string& datasetName
)
{
const int blockNo = selector.block();
vtkDataObject* blockDO = output->GetBlock(blockNo);
vtkMultiBlockDataSet* block = vtkMultiBlockDataSet::SafeDownCast(blockDO);
if (!block)
{
if (blockDO)
{
FatalErrorIn("Foam::vtkPV4Foam::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::vtkPV4Foam::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::vtkPV4Foam::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::vtkPV4Foam::getPartName(int partId)
{
return getFirstWord(reader_->GetPartArrayName(partId));
}
Foam::wordHashSet Foam::vtkPV4Foam::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::vtkPV4Foam::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::vtkPV4Foam::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::vtkPV4Foam::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::vtkPV4Foam::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 * * * * * * * * * * * * * //
// parse these bits of info from /proc/meminfo (Linux)
//
// MemTotal: 2062660 kB
// MemFree: 1124400 kB
//
// used = MemTotal - MemFree is what the free(1) uses.
//
void Foam::vtkPV4Foam::printMemory()
{
const char* meminfo = "/proc/meminfo";
if (exists(meminfo))
{
IFstream is(meminfo);
label memTotal = 0;
label memFree = 0;
string line;
while (is.getLine(line).good())
{
char tag[32];
int value;
if (sscanf(line.c_str(), "%30s %d", tag, &value) == 2)
{
if (!strcmp(tag, "MemTotal:"))
{
memTotal = value;
}
else if (!strcmp(tag, "MemFree:"))
{
memFree = value;
}
}
}
Info << "memUsed: " << (memTotal - memFree) << " kB\n";
}
}
// ************************************************************************* //

View file

@ -0,0 +1,378 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
InClass
vtkPV4Foam
\*---------------------------------------------------------------------------*/
#ifndef vtkPV4FoamVolFields_H
#define vtkPV4FoamVolFields_H
// Foam includes
#include "emptyFvPatchField.H"
#include "wallPolyPatch.H"
#include "faceSet.H"
#include "volPointInterpolation.H"
#include "vtkPV4FoamFaceField.H"
#include "vtkPV4FoamPatchField.H"
#include "vtkOpenFOAMTupleRemap.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkPV4Foam::convertVolFields
(
const fvMesh& mesh,
const PtrList<PrimitivePatchInterpolation<primitivePatch> >& ppInterpList,
const IOobjectList& objects,
vtkMultiBlockDataSet* output
)
{
const polyBoundaryMesh& patches = mesh.boundaryMesh();
forAllConstIter(IOobjectList, objects, iter)
{
// restrict to GeometricField<Type, ...>
if
(
iter()->headerClassName()
!= GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
continue;
}
// Load field
GeometricField<Type, fvPatchField, volMesh> tf
(
*iter(),
mesh
);
// Interpolated field (demand driven)
autoPtr<GeometricField<Type, pointPatchField, pointMesh> > ptfPtr;
// Convert activated internalMesh regions
convertVolFieldBlock
(
tf,
ptfPtr,
output,
partInfoVolume_,
regionPolyDecomp_
);
// Convert activated cellZones
convertVolFieldBlock
(
tf,
ptfPtr,
output,
partInfoCellZones_,
zonePolyDecomp_
);
// Convert activated cellSets
convertVolFieldBlock
(
tf,
ptfPtr,
output,
partInfoCellSets_,
csetPolyDecomp_
);
//
// 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();
partId < partInfoPatches_.end();
++partId
)
{
const word patchName = getPartName(partId);
const label datasetNo = partDataset_[partId];
const label patchId = patches.findPatchID(patchName);
if (!partStatus_[partId] || datasetNo < 0 || patchId < 0)
{
continue;
}
const fvPatchField<Type>& ptf = tf.boundaryField()[patchId];
if
(
isType<emptyFvPatchField<Type> >(ptf)
||
(
reader_->GetExtrapolatePatches()
&& !polyPatch::constraintType(patches[patchId].type())
)
)
{
fvPatch p(ptf.patch().patch(), tf.mesh().boundary());
tmp<Field<Type> > tpptf
(
fvPatchField<Type>(p, tf).patchInternalField()
);
convertPatchField
(
tf.name(),
tpptf(),
output,
partInfoPatches_,
datasetNo
);
convertPatchPointField
(
pointFldName,
ppInterpList[patchId].faceToPointInterpolate(tpptf)(),
output,
partInfoPatches_,
datasetNo
);
}
else
{
convertPatchField
(
tf.name(),
ptf,
output,
partInfoPatches_,
datasetNo
);
convertPatchPointField
(
pointFldName,
ppInterpList[patchId].faceToPointInterpolate(ptf)(),
output,
partInfoPatches_,
datasetNo
);
}
}
//
// Convert face zones - if activated
//
for
(
int partId = partInfoFaceZones_.start();
partId < partInfoFaceZones_.end();
++partId
)
{
const word zoneName = getPartName(partId);
const label datasetNo = partDataset_[partId];
if (!partStatus_[partId] || datasetNo < 0)
{
continue;
}
const faceZoneMesh& zMesh = mesh.faceZones();
const label zoneId = zMesh.findZoneID(zoneName);
if (zoneId < 0)
{
continue;
}
convertFaceField
(
tf,
output,
partInfoFaceZones_,
datasetNo,
mesh,
zMesh[zoneId]
);
// TODO: points
}
//
// Convert face sets - if activated
//
for
(
int partId = partInfoFaceSets_.start();
partId < partInfoFaceSets_.end();
++partId
)
{
const word selectName = getPartName(partId);
const label datasetNo = partDataset_[partId];
if (!partStatus_[partId] || datasetNo < 0)
{
continue;
}
const faceSet fSet(mesh, selectName);
convertFaceField
(
tf,
output,
partInfoFaceSets_,
datasetNo,
mesh,
fSet
);
// TODO: points
}
}
}
template<class Type>
void Foam::vtkPV4Foam::convertVolFieldBlock
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
autoPtr<GeometricField<Type, pointPatchField, pointMesh> >& ptfPtr,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const List<polyDecomp>& decompLst
)
{
for (int partId = selector.start(); partId < selector.end(); ++partId)
{
const label datasetNo = partDataset_[partId];
if (datasetNo >= 0 && partStatus_[partId])
{
convertVolField
(
tf,
output,
selector,
datasetNo,
decompLst[datasetNo]
);
if (!ptfPtr.valid())
{
if (debug)
{
Info<< "convertVolFieldBlock interpolating:" << tf.name()
<< endl;
}
ptfPtr.reset
(
volPointInterpolation::New(tf.mesh()).interpolate(tf).ptr()
);
}
convertPointField
(
ptfPtr(),
tf,
output,
selector,
datasetNo,
decompLst[datasetNo]
);
}
}
}
template<class Type>
void Foam::vtkPV4Foam::convertVolField
(
const GeometricField<Type, fvPatchField, volMesh>& tf,
vtkMultiBlockDataSet* output,
const partInfo& selector,
const label datasetNo,
const polyDecomp& decompInfo
)
{
const label nComp = pTraits<Type>::nComponents;
const labelList& superCells = decompInfo.superCells();
vtkFloatArray* celldata = vtkFloatArray::New();
celldata->SetNumberOfTuples(superCells.size());
celldata->SetNumberOfComponents(nComp);
celldata->Allocate(nComp*superCells.size());
celldata->SetName(tf.name().c_str());
if (debug)
{
Info<< "convert volField: "
<< tf.name()
<< " size = " << tf.size()
<< " nComp=" << nComp
<< " nTuples = " << superCells.size() << endl;
}
float vec[nComp];
forAll(superCells, i)
{
const Type& t = tf[superCells[i]];
for (direction d=0; d<nComp; d++)
{
vec[d] = component(t, d);
}
vtkOpenFOAMTupleRemap<Type>(vec);
celldata->InsertTuple(i, vec);
}
vtkUnstructuredGrid::SafeDownCast
(
GetDataSetFromBlock(output, selector, datasetNo)
) ->GetCellData()
->AddArray(celldata);
celldata->Delete();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -485,6 +485,9 @@ endif
# PARAVIEW # PARAVIEW
# ~~~~~ # ~~~~~
if ( $?PARAVIEW_SYSTEM == 0 && -e "$WM_THIRD_PARTY_DIR"/packages/ParaView-4.0.1/platforms/$WM_OPTIONS ) then
_foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-4.0.1/platforms/$WM_OPTIONS/etc/ParaView-4.0.1.csh
if ( $?PARAVIEW_SYSTEM == 0 && -e "$WM_THIRD_PARTY_DIR"/packages/ParaView-3.14.1/platforms/$WM_OPTIONS ) then if ( $?PARAVIEW_SYSTEM == 0 && -e "$WM_THIRD_PARTY_DIR"/packages/ParaView-3.14.1/platforms/$WM_OPTIONS ) then
_foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS/etc/ParaView-3.14.1.csh _foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS/etc/ParaView-3.14.1.csh

View file

@ -503,7 +503,7 @@ export MPI_BUFFER_SIZE
[ -z "$PARMGRIDGEN_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParMGridGen-1.0/platforms/$WM_OPTIONS ] && { [ -z "$PARMGRIDGEN_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParMGridGen-1.0/platforms/$WM_OPTIONS ] && {
_foamSource $WM_THIRD_PARTY_DIR/packages/ParMGridGen-1.0/platforms/$WM_OPTIONS/etc/ParMGridGen-1.0.sh _foamSource $WM_THIRD_PARTY_DIR/packages/ParMGridGen-1.0/platforms/$WM_OPTIONS/etc/ParMGridGen-1.0.sh
} }
[ "$FOAM_VERBOSE" -a "$PS1" ] && echo " PARMGR IDGEN_DIR is initialized to: $PARMGRIDGEN_DIR" [ "$FOAM_VERBOSE" -a "$PS1" ] && echo " PARMGRIDGEN_DIR is initialized to: $PARMGRIDGEN_DIR"
# Load Libccmio library # Load Libccmio library
@ -590,8 +590,10 @@ export MPI_BUFFER_SIZE
# Load ParaView # Load ParaView
# ~~~~~~~~~~~~~ # ~~~~~~~~~~~~~
[ -z "$PARAVIEW_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS ] && { [ -z "$PARAVIEW_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParaView-4.0.1/platforms/$WM_OPTIONS ] && {
_foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS/etc/ParaView-3.14.1.sh _foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-4.0.1/platforms/$WM_OPTIONS/etc/ParaView-4.0.1.sh
#[ -z "$PARAVIEW_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS ] && {
# _foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.14.1/platforms/$WM_OPTIONS/etc/ParaView-3.14.1.sh
#[ -z "$PARAVIEW_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParaView-3.8.1/platforms/$WM_OPTIONS ] && { #[ -z "$PARAVIEW_SYSTEM" ] && [ -e $WM_THIRD_PARTY_DIR/packages/ParaView-3.8.1/platforms/$WM_OPTIONS ] && {
# _foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.8.1/platforms/$WM_OPTIONS/etc/ParaView-3.8.1.sh # _foamSource $WM_THIRD_PARTY_DIR/packages/ParaView-3.8.1/platforms/$WM_OPTIONS/etc/ParaView-3.8.1.sh
} }