Commit ae5c7dab authored by Mark Olesen's avatar Mark Olesen
Browse files

DEFEATURE: remove runTimePostProcessing (migrate to submodule)

parent de57d2da
......@@ -11,8 +11,6 @@ wmake $targetType lagrangian
wmake $targetType utilities
wmake $targetType solvers
./graphics/Allwmake $targetType
./randomProcesses/Allwmake $targetType
#------------------------------------------------------------------------------
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/AllwmakeParseArguments
#------------------------------------------------------------------------------
if [ "$targetType" != "objects" ]
then
runTimePostProcessing/Allwmake $*
fi
#------------------------------------------------------------------------------
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/wmakeFunctions # Require wmake functions
#------------------------------------------------------------------------------
# This cleanup handles both cmake runTimePostProcessing and the dummy version
# Cleanup library files with .so version endings
rm -f $FOAM_LIBBIN/librunTimePostProcessing*
# Cleanup generated files - remove entire top-level
removeObjectDir "$PWD"
#------------------------------------------------------------------------------
#!/bin/sh
cd "${0%/*}" || exit # Run from this directory
. ${WM_PROJECT_DIR:?}/wmake/scripts/cmakeFunctions # Require cmake functions
# -----------------------------------------------------------------------------
echo "======================================================================"
echo "${PWD##*/} : $PWD"
unset depend runTimePostProDebug
# If available, prefer use of ParaView MESA
if [ -d "$ParaView_MESA_DIR" ]
then
export ParaView_DIR="$ParaView_MESA_DIR"
fi
if [ -d "$VTK_DIR" ]
then
depend="VTK_DIR=$VTK_DIR"
elif [ -d "$ParaView_DIR" ]
then
depend="ParaView_DIR=$ParaView_DIR"
fi
# Force use of dummy only
# unset depend
# For rebuilding (on error) instead of dropping back to dummy
# runTimePostProDebug=true
if [ "$targetType" = objects ]
then
depend=ignore
elif [ -n "$depend" ]
then
if command -v cmake >/dev/null
then
cmakeVersioned "$depend" $PWD || {
echo
echo " WARNING: incomplete build of VTK-based post-processing"
echo
if [ -z "$runTimePostProDebug" ]
then
depend="dummy"
fi
}
else
echo "==> skip runTimePostProcessing (needs cmake)"
depend="dummy"
fi
else
echo "WARNING: skip runTimePostProcessing (no VTK or ParaView)"
echo " - ParaView : export the 'ParaView_DIR' variable"
echo " - VTK : export the 'VTK_DIR' variable"
fi
if [ "${depend:-dummy}" = dummy ]
then
echo "==> dummy runTimePostProcessing"
wmakeVersioned "vtk=dummy" $PWD dummy
fi
echo "======================================================================"
# -----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
# Standard definitions when using OpenFOAM
if (NOT EXISTS "$ENV{WM_PROJECT_DIR}")
message(FATAL_ERROR "WM_PROJECT_DIR not set - no OpenFOAM??")
endif()
# WM_OSTYPE env variable is optional (only POSIX anyhow)
if (EXISTS "$ENV{WM_OSTYPE}")
set(WM_OSTYPE "$ENV{WM_OSTYPE}")
else()
set(WM_OSTYPE "POSIX")
endif()
# Convenience name, as per wmake internals
set(LIB_SRC "$ENV{WM_PROJECT_DIR}/src")
# Needed for internal label-size, scalar-size, templates
add_definitions(
-DWM_$ENV{WM_PRECISION_OPTION}
-DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE}
-DNoRepository
)
set(CMAKE_CXX_FLAGS_DEBUG
"-g -O0 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
)
set(CMAKE_CXX_FLAGS_RELEASE
"-O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
)
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
project(runTimePostProcessing)
message("VTK version: " ${VTK_VERSION})
if(${VTK_VERSION_MAJOR} LESS 6)
message(FATAL_ERROR " VTK version is too old - requires VTK6 or newer")
endif()
#-----------------------------------------------------------------------------
# Test some characteristics
set(test_file ${CMAKE_CURRENT_BINARY_DIR}/check_mpi.cxx)
file(WRITE ${test_file}
"#include <vtkMPICommunicator.h>\n"
"int main() {\n"
" vtkMPICommunicator* p = vtkMPICommunicator::New();\n"
" p->Delete();\n"
" return 0;\n"
"}"
)
try_compile(FOAM_USING_VTK_MPI
${CMAKE_CURRENT_BINARY_DIR} ${test_file}
LINK_LIBRARIES vtkParallelMPI
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${VTK_INCLUDE_DIRS}"
)
if (FOAM_USING_VTK_MPI)
add_definitions(-DFOAM_USING_VTK_MPI)
message("Building with VTK MPI")
include(vtkMPI)
else()
message(WARNING "==== Building without VTK MPI ====")
endif()
#-----------------------------------------------------------------------------
include_directories(
${LIB_SRC}/OpenFOAM/include
${LIB_SRC}/OpenFOAM/lnInclude
${LIB_SRC}/OSspecific/${WM_OSTYPE}/lnInclude
${LIB_SRC}/finiteVolume/lnInclude
${LIB_SRC}/fileFormats/lnInclude
${LIB_SRC}/conversion/lnInclude
${LIB_SRC}/surfMesh/lnInclude
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
link_directories(
$ENV{FOAM_LIBBIN}
)
set(CMAKE_BUILD_TYPE Release)
# Build intermediate (library) directly into the OpenFOAM libdir
# - implies CMAKE_INSTALL_PREFIX is ignored and there is no 'install' phase
set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
CACHE INTERNAL
""
)
## Record VTK version for general bookkeeping
# file(WRITE
# ${CMAKE_BINARY_DIR}/version
# "VTK_VERSION=${VTK_VERSION}\n"
# )
file(GLOB SOURCE_FILES
fieldVisualisationBase.C
scalarBar.C
functionObjectBase.C
functionObjectCloud.C
functionObjectLine.C
functionObjectSurface.C
geometryBase.C
geometryCloud.C
geometryCloudGather.C
geometryPatches.C
geometryPatchesGather.C
geometrySurface.C
pathline.C
pointData.C
runTimePostProcessing.C
runTimePostProcessingFunctionObject.C
scene.C
surface.C
surfaceGather.C
text.C
contourFilter.C
cuttingPlaneFilter.C
volumeFilter.C
)
set(OPENFOAM_LIBRARIES
OpenFOAM
finiteVolume
surfMesh
fileFormats
conversion
)
if (FOAM_USING_VTK_MPI)
set(LINK_LIBRARIES vtkParallelMPI)
else()
set(LINK_LIBRARIES)
endif()
add_library(
runTimePostProcessing
SHARED
${SOURCE_FILES}
)
set_target_properties(
runTimePostProcessing
PROPERTIES
VERSION ${VTK_VERSION}
SOVERSION ${VTK_VERSION_MAJOR}
)
target_link_libraries(
runTimePostProcessing
${VTK_LIBRARIES}
${LINK_LIBRARIES}
${OPENFOAM_LIBRARIES}
)
#-----------------------------------------------------------------------------
#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
cmake_policy(SET CMP0002 NEW) # Policy CMP0002 required for for cmake >= 3
# Fail if not building out-of-source
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
message(FATAL_ERROR
"In-source builds disallowed. Use a separate build directory")
endif()
#-----------------------------------------------------------------------------
# Simple discovery and sanity checks
unset(VTK_VERSION)
unset(VTK_VERSION_MAJOR)
if (EXISTS "$ENV{VTK_DIR}")
message("Building with VTK from $ENV{VTK_DIR}")
find_package(VTK REQUIRED HINTS $ENV{VTK_DIR})
elseif (EXISTS "$ENV{ParaView_DIR}")
message("Building with Paraview from $ENV{ParaView_DIR}")
find_package(ParaView REQUIRED HINTS $ENV{ParaView_DIR})
else()
message(FATAL_ERROR "VTK not found using VTK_DIR or ParaView_DIR")
endif()
if (VTK_USE_FILE)
message("VTK from ${VTK_USE_FILE}")
include(${VTK_USE_FILE})
endif()
#-----------------------------------------------------------------------------
# Handle name changes (eg, VTK_MAJOR_VERSION to VTK_VERSION_MAJOR etc.)
if (VTK_MAJOR_VERSION AND NOT VTK_VERSION_MAJOR)
message("Found older VTK version naming")
set(VTK_VERSION_MAJOR ${VTK_MAJOR_VERSION})
set(VTK_VERSION_MINOR ${VTK_MINOR_VERSION})
set(VTK_VERSION_PATCH ${VTK_BUILD_VERSION})
if (NOT VTK_VERSION)
set(
VTK_VERSION
"${VTK_VERSION_MAJOR}.${VTK_VERSION_MINOR}.${VTK_VERSION_PATCH}"
)
message("Synthesized VTK version: " ${VTK_VERSION})
endif()
endif()
#-----------------------------------------------------------------------------
include(CMakeLists-OpenFOAM.txt)
include(CMakeLists-Project.txt)
#-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
// OpenFOAM includes
#include "contourFilter.H"
#include "runTimePostProcessing.H"
#include "addToRunTimeSelectionTable.H"
// VTK includes
#include "vtkActor.h"
#include "vtkCellDataToPointData.h"
#include "vtkCompositeDataGeometryFilter.h"
#include "vtkCompositeDataSet.h"
#include "vtkCompositePolyDataMapper.h"
#include "vtkContourFilter.h"
#include "vtkMultiPieceDataSet.h"
#include "vtkPolyData.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkSmartPointer.h"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
namespace runTimePostPro
{
defineTypeName(contourFilter);
addToRunTimeSelectionTable(surface, contourFilter, dictionary);
}
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::runTimePostPro::contourFilter::contourFilter
(
const runTimePostProcessing& parent,
const dictionary& dict,
const HashPtrTable<Function1<vector>>& colours
)
:
volumeFilter(parent, dict, colours),
fieldVisualisationBase(dict, colours),
colourFieldName_(dict.get<word>("colourField")),
values_()
{
dict.readEntry("values", values_);
// Extra safety
if (values_.empty())
{
values_.resize(1);
values_.first() = Zero;
}
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::functionObjects::runTimePostPro::contourFilter::
addGeometry
(
const scalar position,
vtkRenderer* renderer
)
{
if (!visible_)
{
return false;
}
if (needsCollective())
{
Info<< type() << " : Not available for collective operation" << endl;
return false;
}
DebugInfo << " Adding iso-surface" << endl;
// Bookkeeping for vtkUnstructuredGrid
vtk::vtuAdaptor adaptor;
vtkSmartPointer<vtkMultiPieceDataSet> multiPiece = mesh(adaptor);
// Add (scalar/vector) field.
// - always need field(s) for glyphs or colourByField:
int nCmpt = 0;
{
const auto* ioptr =
parent().mesh().cfindObject<regIOobject>(fieldName_);
if (!nCmpt)
{
nCmpt = addDimField<scalar>
(
multiPiece, adaptor, ioptr, fieldName_
);
}
if (!nCmpt)
{
nCmpt = addDimField<vector>
(
multiPiece, adaptor, ioptr, fieldName_
);
}
}
// If the input is vector, need magnitude
word magFieldName = fieldName_;
if (nCmpt == 3)
{
addMagField(fieldName_, multiPiece);
magFieldName = "mag(" + fieldName_ + ")";
}
// Colouring
nCmpt = 0;
if (colourBy_ == cbField && fieldName_ != colourFieldName_)
{
const auto* ioptr =
parent().mesh().cfindObject<regIOobject>(fieldName_);
if (!nCmpt)
{
nCmpt = addDimField<scalar>
(
multiPiece, adaptor, ioptr, colourFieldName_
);
}
if (!nCmpt)
{
nCmpt = addDimField<vector>
(
multiPiece, adaptor, ioptr, colourFieldName_
);
}
}
// Now have a multi-piece dataset that is one of the following:
//
// - one-piece per processor (OpenFOAM = parallel, VTK=parallel)
// Re-query field information - we may have stored it differently
// than the original source.
fieldSummary fieldInfo = queryFieldSummary(magFieldName, multiPiece);
fieldInfo.reduce();
fieldSummary colourFieldInfo =
queryFieldSummary(colourFieldName_, multiPiece);
colourFieldInfo.reduce();
DebugInfo
<< " Field " << fieldName_ << ' ' << fieldInfo.info() << nl
<< " Field " << colourFieldName_ << ' ' << colourFieldInfo.info()
<< endl;
// Not rendered on this processor?
// This is where we stop, but could also have an MPI barrier
if (!renderer)
{
return true;
}
// Rendering
{
auto contour = vtkSmartPointer<vtkContourFilter>::New();
vtkSmartPointer<vtkCellDataToPointData> cellToPoint;
// CellData - Need a cell->point filter
if (!fieldInfo.hasPointData() || !colourFieldInfo.hasPointData())
{
cellToPoint = vtkSmartPointer<vtkCellDataToPointData>::New();
cellToPoint->SetInputData(multiPiece);
contour->SetInputConnection(cellToPoint->GetOutputPort());
}
else
{
contour->SetInputData(multiPiece);
}
contour->SetNumberOfContours(values_.size());
forAll(values_, valuei)
{
contour->SetValue(valuei, values_[valuei]);
}
contour->SetInputArrayToProcess
(
0, // index: scalars(0)
0, // port
0, // connection
vtkDataObject::FIELD_ASSOCIATION_POINTS,
magFieldName.c_str()
);
contour->Modified();
contour->Update();
auto polyData = vtkSmartPointer<vtkCompositeDataGeometryFilter>::New();
polyData->SetInputConnection(contour->GetOutputPort());
polyData->Update();
auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(polyData->GetOutputPort());
if (representation_ == rtGlyph)
{
addGlyphs
(
position,
colourFieldName_, colourFieldInfo, // scaling
colourFieldName_, colourFieldInfo, // colouring
maxGlyphLength_,
polyData->GetOutput(),
surfaceActor_,
renderer
);
}
else
{
setField
(
position,
colourFieldName_,
FieldAssociation::POINT_DATA,
mapper,
renderer
);
surfaceActor_->SetMapper(mapper);
setRepresentation(surfaceActor_);
renderer->AddActor(surfaceActor_);
}
}
return true;
}
void Foam::functionObjects::runTimePostPro::contourFilter::
addGeometryToScene
(