OpenFOAM: v1912 released! - For more information see https://www.openfoam.com/releases/openfoam-v1912

Commit b8796587 authored by Mark Olesen's avatar Mark Olesen

New function object for using ParaView Catalyst with OpenFOAM

This integration represents a collective work
  - CINECA (Simone.Bna@cineca.it)
  - OpenCFD
  - with additional input from KitWare (Andy.Bauer@kitware.com)

NB: requires ParaView or ParaView Catalyst with MPI and Python
parents
# git-ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# Editor and misc backup files - anywhere
*~
.*~
*.bak
*.bak[0-9][0-9]
\#*\#
# File-browser settings - anywhere
.directory
# CVS recovered versions - anywhere
.#*
# Objects and archives - anywhere
*.[oa]
*.la
*.so
# Derived files
lex.yy.c
# Corefiles
core
# Dependency files - anywhere
*.dep
# lnInclude (symlink) directories - anywhere
lnInclude
# Build directories - anywhere
linux*Clang*/
linux*Gcc*/
linux*Icc*/
solaris*Gcc*/
SunOS*Gcc*/
platforms/
# Top-level build directories
/build/
/platforms/
# Reinstate wmake rules that might look like build directories
!/wmake/rules/*/
# doxygen generated documentation
doc/Doxygen/html
doc/Doxygen/latex
doc/Doxygen/man
doc/Doxygen/DTAGS
# Generated files in the main directory (e.g. ReleaseNotes-?.?.html)
# and in the doc directory
/*.html
/doc/*.html
# Untracked configuration files
/etc/prefs.csh
/etc/prefs.sh
/etc/config.csh/prefs.csh
/etc/config.sh/prefs.sh
/wmake/rules/General/mplibUSER*
# Source packages - anywhere
*.tar.bz2
*.tar.gz
*.tar.xz
*.tar
*.tgz
*.gtgz
# Ignore the persistent .build tag in the main directory
/.build
# Ignore .timeStamp in the main directory
/.timeStamp
# Ignore .tags in the main directory
/.tags
# Ignore project files in the main directory
/.cproject
/.project
/.dir-locals.el
# Ignore the test directory
/tutorialsTest
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
#------------------------------------------------------------------------------
src/Allwclean
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
targetType=libso
. $WM_PROJECT_DIR/wmake/scripts/AllwmakeParseArguments
[ -n "$FOAM_USER_LIBBIN" ] || {
echo "Error: FOAM_USER_LIBBIN not set"
echo " Check the OpenFOAM entries in your dot-files and source them."
exit 1
}
src/Allwmake $targetType $*
#------------------------------------------------------------------------------
What:
Library and function object for embedding the ParaView Catalyst
into OpenFOAM.
Requirements:
OpenFOAM.com development version (April-2018 or newer) or OpenFOAM-v1806.
ParaView or ParaView Catalyst 5.4 or newer, compiled with mpi and
python support.
Authors:
Mark Olesen <Mark.Olesen@esi-group.com>
Simone Bna <Simone.Bna@cineca.it>
License:
Same terms as OpenFOAM.
Licensed under GNU General Public License <http://www.gnu.org/licenses/>.
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
catalyst/Allwclean
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
catalyst/Allwmake
# -----------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/wmakeFunctions # The wmake functions
rm -f $FOAM_LIBBIN/libcatalystFoam* 2>/dev/null # Cleanup library
# Cleanup generated files - remove entire top-level
removeObjectDir $PWD
#------------------------------------------------------------------------------
#!/bin/sh
cd ${0%/*} || exit 1 # Run from this directory
. $WM_PROJECT_DIR/wmake/scripts/cmakeFunctions # The cmake functions
# CMake into objectsDir with external dependency
# - This function override can be removed with OpenFOAM-1806
cmakeVersioned()
{
local depend="$1"
local sourceDir="$2"
local objectsDir
# Where generated files are stored
objectsDir=$(findObjectDir "$sourceDir") || exit 1 # Fatal
# Version changed
sentinel=$(sameDependency "$depend" "$sourceDir") || \
rm -rf "$objectsDir" > /dev/null 2>&1
mkdir -p $objectsDir \
&& (cd $objectsDir && _cmake $sourceDir && make) \
&& echo "$depend" >| "${sentinel:-/dev/null}"
}
# -----------------------------------------------------------------------------
echo "======================================================================"
echo "${PWD##*/} : $PWD"
echo
unset depend
if [ -d "$ParaView_DIR" ]
then
depend="ParaView_DIR=$ParaView_DIR"
fi
if [ -n "$depend" ]
then
if [ "$targetType" != objects ]
then
if command -v cmake > /dev/null 2>&1
then
cmakeVersioned "$depend" $PWD || {
echo
echo " WARNING: incomplete build of ParaView Catalyst"
echo
}
else
echo "WARNING: skipped - needs cmake"
fi
fi
else
echo "WARNING: skip ParaView Catalyst (missing or incorrrect ParaView)"
fi
echo "======================================================================"
# -----------------------------------------------------------------------------
include(${PARAVIEW_USE_FILE})
include_directories(
$ENV{WM_PROJECT_DIR}/src/OpenFOAM/lnInclude
$ENV{WM_PROJECT_DIR}/src/OSspecific/$ENV{WM_OSTYPE}/lnInclude
$ENV{WM_PROJECT_DIR}/src/finiteArea/lnInclude
$ENV{WM_PROJECT_DIR}/src/finiteVolume/lnInclude
$ENV{WM_PROJECT_DIR}/src/fileFormats/lnInclude
$ENV{WM_PROJECT_DIR}/src/conversion/lnInclude
$ENV{WM_PROJECT_DIR}/src/meshTools/lnInclude
$ENV{WM_PROJECT_DIR}/src/lagrangian/basic/lnInclude
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
)
link_directories(
$ENV{FOAM_LIBBIN}
$ENV{FOAM_LIBBIN}/dummy
)
add_definitions(
-DWM_$ENV{WM_PRECISION_OPTION} -DNoRepository
-DWM_LABEL_SIZE=$ENV{WM_LABEL_SIZE}
)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS_DEBUG
"-g -O0 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual"
)
set(CMAKE_C_FLAGS_DEBUG "-g -O0 -std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE
"-O3 -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wnon-virtual-dtor -Wno-overloaded-virtual")
set(CMAKE_C_FLAGS_RELEASE "-O3 -std=c++11")
# Set output library destination to OpenFOAM library directory
set(LIBRARY_OUTPUT_PATH $ENV{FOAM_LIBBIN}
CACHE INTERNAL
""
)
file(GLOB SOURCE_FILES
catalystCoprocess.C
catalystCloud.C
foamVtkCloudAdaptor.C
catalystFaMesh.C
foamVtkFaMeshAdaptor.C
foamVtkFaMeshAdaptorGeom.C
foamVtkFaMeshAdaptorFields.C
catalystFvMesh.C
foamVtkFvMeshAdaptor.C
foamVtkFvMeshAdaptorGeom.C
foamVtkFvMeshAdaptorGeomVtu.C
foamVtkFvMeshAdaptorFields.C
)
set(OPENFOAM_LIBRARIES
OpenFOAM
finiteArea
finiteVolume
fileFormats
conversion
Pstream
meshTools
lagrangian
)
add_library(
catalystFoam
SHARED
${SOURCE_FILES}
)
target_link_libraries(
catalystFoam
vtkPVPythonCatalyst vtkParallelMPI
${OPENFOAM_LIBRARIES}
)
#-----------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8)
project(catalyst)
# Set policy for CMP0002 needed for cmake > 3
cmake_policy(SET CMP0002 OLD)
if (EXISTS "$ENV{ParaView_DIR}")
message("Building with Paraview from $ENV{ParaView_DIR}")
find_package(ParaView REQUIRED COMPONENTS vtkPVPythonCatalyst)
if(NOT PARAVIEW_USE_MPI)
message(SEND_ERROR "ParaView must be built with MPI enabled")
endif()
else ()
message (FATAL_ERROR "ParaView_DIR not set")
endif ()
include(CMakeLists-Common.txt)
#-----------------------------------------------------------------------------
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "catalystCloud.H"
#include "catalystCoprocess.H"
#include "cloud.H"
#include "foamVtkCloudAdaptor.H"
#include "addToRunTimeSelectionTable.H"
#include <vtkNew.h>
#include <vtkCPDataDescription.h>
#include <vtkMultiBlockDataSet.h>
#include <vtkInformation.h>
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(catalystCloud, 0);
addToRunTimeSelectionTable(functionObject, catalystCloud, dictionary);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::catalystCloud::catalystCloud
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
selectClouds_(),
selectFields_(),
adaptor_()
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::catalystCloud::~catalystCloud()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::catalystCloud::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
int debugLevel = 0;
if (dict.readIfPresent("debug", debugLevel))
{
catalystCoprocess::debug = debugLevel;
}
selectClouds_.clear();
dict.readIfPresent("clouds", selectClouds_);
if (selectClouds_.empty())
{
selectClouds_.resize(1);
selectClouds_.first() =
dict.lookupOrDefault<word>("cloud", cloud::defaultName);
}
selectFields_.clear();
dict.readIfPresent("fields", selectFields_);
dict.lookup("scripts") >> scripts_; // Python scripts
catalystCoprocess::expand(scripts_, dict); // Expand and check availability
Info<< type() << " " << name() << ":" << nl
<<" clouds " << flatOutput(selectClouds_) << nl
<<" fields " << flatOutput(selectFields_) << nl
<<" scripts " << scripts_ << nl;
// Run-time modification of pipeline
if (adaptor_.valid())
{
adaptor_().reset(scripts_);
}
return true;
}
bool Foam::functionObjects::catalystCloud::execute()
{
const wordList cloudNames(mesh_.sortedNames<cloud>(selectClouds_));
if (cloudNames.empty())
{
return true;
}
const catalystCoprocess::timeQuery when(time_);
// Enforce sanity for backends and adaptor
{
if (!adaptor_.valid())
{
adaptor_.reset(new catalystCoprocess());
adaptor_().reset(scripts_);
}
}
// Difficult to get the names of the fields from particles
// ... need to skip for now
wordHashSet allFields;
// Data description for co-processing
vtkNew<vtkCPDataDescription> descrip;
// Form query for catalyst
catalystCoprocess::dataQuery query
(
vtk::cloudAdaptor::channelNames.names(),
when,
descrip.Get()
);
// Query catalyst
HashTable<wordHashSet> expecting = adaptor_().check(query, allFields);
if (expecting.empty())
{
Info<< "No data expected for ParaView Catalyst. " << when << endl;
return true;
}
else if (catalystCoprocess::debug)
{
Info<< type() << " expecting data:" << expecting << endl;
}
auto output = vtkSmartPointer<vtkMultiBlockDataSet>::New();
// Store each cloud in a separate block
unsigned int cloudNo = 0;
for (const word& cloudName : cloudNames)
{
auto pieces =
vtk::cloudAdaptor(mesh_).getCloud(cloudName, selectFields_);
output->SetBlock(cloudNo, pieces);
output->GetMetaData(cloudNo)->Set
(
vtkCompositeDataSet::NAME(),
cloudName
);
++cloudNo;
}
if (cloudNo)
{
Info<< "Send data to ParaView Catalyst. " << when << endl;
adaptor_().process(query, output);
}
return true;
}
bool Foam::functionObjects::catalystCloud::write()
{
return true;
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::functionObjects::catalystCloud
Group
grpUtilitiesFunctionObjects
Description
A Paraview Catalyst adaptor for a single OpenFOAM cloud (lagrangian).
Example of function object specification:
\verbatim
catalystCloud1
{
type catalyst::cloud;
libs ("libcatalystFoam.so");
executeControl timeStep;
executeInterval 101;
cloud NAME;
fields (U T rho);
scripts ( ... );
}
\endverbatim
Usage
\table
Property | Description | Required | Default value
cloud | | no | defaultCloud
clouds | List of wordRe | no |
\endtable
See also
Foam::functionObjects::fvMeshFunctionObject
Foam::functionObjects::timeControl
SourceFiles
catalystCloud.C
catalystCloudTemplates.C
\*---------------------------------------------------------------------------*/
#ifndef functionObjects_catalystCloud_H
#define functionObjects_catalystCloud_H
#include "fvMeshFunctionObject.H"
#include "wordRes.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declarations
class catalystCoprocess;
namespace functionObjects
{
/*---------------------------------------------------------------------------*\
Class catalystCloud Declaration
\*---------------------------------------------------------------------------*/
class catalystCloud
:
public fvMeshFunctionObject
{
protected:
// Protected data
//- Requested names of clouds to process
wordRes selectClouds_;
//- Subset of cloud fields to process
wordRes selectFields_;
//- Python scripts for the catalyst pipeline
stringList scripts_;
//- The catalyst coprocess
autoPtr<catalystCoprocess> adaptor_;
// Private Member Functions
//- No copy construct
catalystCloud(const catalystCloud&) = delete;
//- No copy assignment
void operator=(const catalystCloud&) = delete;
public:
//- Runtime type information
TypeName("catalyst::cloud");
// Constructors
//- Construct from Time and dictionary
catalystCloud
(
const word& name,
const Time& runTime,
const dictionary& dict
);
//- Destructor
virtual ~catalystCloud();
// Member Functions
//- Read the specification
virtual bool read(const dictionary& dict);
//- Execute pipeline
virtual bool execute();
//- Write - does nothing
virtual bool write();
};