mirror of
https://github.com/OpenFOAM/ThirdParty-6.git
synced 2025-12-08 06:57:43 +00:00
ParaView-5.0.1: Added the source-tree to ThirdParty-dev and patched as described in the README file
Resolves bug-report http://bugs.openfoam.org/view.php?id=2098
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
project(CatalystFortran90FullExample CXX Fortran)
|
||||
|
||||
find_package(ParaView 4.1 REQUIRED COMPONENTS vtkPVPythonCatalyst)
|
||||
|
||||
include(${PARAVIEW_USE_FILE})
|
||||
if(NOT PARAVIEW_USE_MPI)
|
||||
message(SEND_ERROR "ParaView must be built with MPI enabled")
|
||||
endif()
|
||||
if(NOT MPI_Fortran_LIBRARIES)
|
||||
find_package(MPI)
|
||||
endif()
|
||||
|
||||
add_executable(Fortran90FullExample FEDriver.f90 FEFortranAdaptor.f90 FECxxAdaptor.cxx)
|
||||
target_link_libraries(Fortran90FullExample vtkPVPythonCatalyst ${MPI_Fortran_LIBRARIES})
|
||||
set_target_properties(Fortran90FullExample PROPERTIES
|
||||
LINKER_LANGUAGE Fortran)
|
||||
|
||||
option(BUILD_TESTING "Build Testing" OFF)
|
||||
# Setup testing.
|
||||
if (BUILD_TESTING)
|
||||
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/SampleScripts/coproc.py DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||
include(CTest)
|
||||
add_test(NAME Fortran90FullExampleTest COMMAND Fortran90FullExample)
|
||||
set_tests_properties(Fortran90FullExampleTest PROPERTIES LABELS "PARAVIEW;CATALYST")
|
||||
endif()
|
||||
@ -0,0 +1,67 @@
|
||||
// Adaptor for getting Fortran simulation code into ParaView CoProcessor.
|
||||
|
||||
// CoProcessor specific headers
|
||||
#include "vtkCPDataDescription.h"
|
||||
#include "vtkCPInputDataDescription.h"
|
||||
#include "vtkCPProcessor.h"
|
||||
#include "vtkCPPythonScriptPipeline.h"
|
||||
#include "vtkSmartPointer.h"
|
||||
#include "vtkDoubleArray.h"
|
||||
#include "vtkPointData.h"
|
||||
#include "vtkImageData.h"
|
||||
|
||||
// Fortran specific header
|
||||
#include "vtkCPPythonAdaptorAPI.h"
|
||||
|
||||
|
||||
// These will be called from the Fortran "glue" code"
|
||||
// Completely dependent on data layout, structured vs. unstructured, etc.
|
||||
// since VTK/ParaView uses different internal layouts for each.
|
||||
|
||||
// Creates the data container for the CoProcessor.
|
||||
extern "C" void createcpimagedata_(int* nxstart, int* nxend, int* nx,
|
||||
int* ny, int* nz)
|
||||
{
|
||||
if (!vtkCPPythonAdaptorAPI::GetCoProcessorData())
|
||||
{
|
||||
vtkGenericWarningMacro("Unable to access CoProcessorData.");
|
||||
return;
|
||||
}
|
||||
|
||||
// The simulation grid is a 3-dimensional topologically and geometrically
|
||||
// regular grid. In VTK/ParaView, this is considered an image data set.
|
||||
vtkSmartPointer<vtkImageData> grid = vtkSmartPointer<vtkImageData>::New();
|
||||
|
||||
grid->SetExtent(*nxstart-1, *nxend-1, 0, *ny-1, 0, *nz-1);
|
||||
|
||||
// Name should be consistent between here, Fortran and Python client script.
|
||||
vtkCPPythonAdaptorAPI::GetCoProcessorData()->GetInputDescriptionByName("input")->SetGrid(grid);
|
||||
vtkCPPythonAdaptorAPI::GetCoProcessorData()->GetInputDescriptionByName("input")->SetWholeExtent(0, *nx-1, 0, *ny-1, 0, *nz-1);
|
||||
}
|
||||
|
||||
// Add field(s) to the data container.
|
||||
// Separate from above because this will be dynamic, grid is static.
|
||||
// By hand name mangling for fortran.
|
||||
extern "C" void addfield_(double* scalars, char* name)
|
||||
{
|
||||
vtkCPInputDataDescription* idd =
|
||||
vtkCPPythonAdaptorAPI::GetCoProcessorData()->GetInputDescriptionByName("input");
|
||||
|
||||
vtkImageData* Image = vtkImageData::SafeDownCast(idd->GetGrid());
|
||||
|
||||
if (!Image)
|
||||
{
|
||||
vtkGenericWarningMacro("No adaptor grid to attach field data to.");
|
||||
return;
|
||||
}
|
||||
|
||||
// field name must match that in the fortran code.
|
||||
if (idd->IsFieldNeeded(name))
|
||||
{
|
||||
vtkSmartPointer<vtkDoubleArray> field = vtkSmartPointer<vtkDoubleArray>::New();
|
||||
field->SetNumberOfComponents(2);
|
||||
field->SetName(name);
|
||||
field->SetArray(scalars, 2*Image->GetNumberOfPoints(), 1);
|
||||
Image->GetPointData()->AddArray(field);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
! A Fortran Catalyst example. Note that coproc.py
|
||||
! must be in the directory where the example
|
||||
! is run from.
|
||||
! Thanks to Lucas Pettey for helping create the example.
|
||||
|
||||
PROGRAM coproc
|
||||
use tcp
|
||||
implicit none
|
||||
include 'mpif.h'
|
||||
integer,parameter :: nx=100,ny=100,nz=100,ntime=10
|
||||
integer :: i,j,k,time,nxstart,nxend
|
||||
real :: max
|
||||
complex(kind=8), allocatable :: psi01(:,:,:)
|
||||
integer :: numtasks,rank,ierr
|
||||
|
||||
call mpi_init(ierr)
|
||||
call mpi_comm_size(MPI_COMM_WORLD, numtasks, ierr)
|
||||
call mpi_comm_rank(MPI_COMM_WORLD, rank, ierr)
|
||||
|
||||
call coprocessorinitializewithpython("coproc.py",9)
|
||||
|
||||
! partition in the x-direction only
|
||||
nxstart=rank*nx/numtasks+1
|
||||
nxend=(rank+1)*nx/numtasks
|
||||
if(numtasks .ne. rank+1) then
|
||||
nxend=nxend+1
|
||||
endif
|
||||
|
||||
allocate(psi01(nxend-nxstart+1,ny,nz))
|
||||
! set initial values
|
||||
max=sqrt(real(nx)**2+real(ny)**2+real(nz)**2)
|
||||
do k=1,nz
|
||||
do j=1,ny
|
||||
do i=1,nxend-nxstart+1
|
||||
psi01(i,j,k)=CMPLX(max-sqrt(real(i-50)**2+real(j-50)**2+real(k-50)**2),&
|
||||
real(1+j+k))/max*100.0
|
||||
enddo
|
||||
enddo
|
||||
enddo
|
||||
|
||||
do time=1,ntime
|
||||
do k=1,nz
|
||||
do j=1,ny
|
||||
do i=1,nxend-nxstart+1
|
||||
psi01(i,j,k)=CMPLX(real(0.30),0.0)+psi01(i,j,k)
|
||||
end do
|
||||
end do
|
||||
end do
|
||||
call testcoprocessor(nxstart,nxend,nx,ny,nz,time,dble(time),psi01)
|
||||
enddo
|
||||
deallocate(psi01)
|
||||
|
||||
call coprocessorfinalize()
|
||||
call mpi_finalize(ierr)
|
||||
|
||||
end program coproc
|
||||
@ -0,0 +1,32 @@
|
||||
module tcp
|
||||
use iso_c_binding
|
||||
implicit none
|
||||
public
|
||||
interface tcp_adaptor
|
||||
module procedure testcoprocessor
|
||||
end interface
|
||||
contains
|
||||
|
||||
subroutine testcoprocessor(nxstart,nxend,nx,ny,nz,step,time,psi01)
|
||||
use iso_c_binding
|
||||
implicit none
|
||||
integer, intent(in) :: nxstart,nxend,nx,ny,nz,step
|
||||
real(kind=8), intent(in) :: time
|
||||
complex(kind=8), dimension(:,:,:), intent (in) :: psi01
|
||||
integer :: flag
|
||||
call requestdatadescription(step,time,flag)
|
||||
if (flag .ne. 0) then
|
||||
call needtocreategrid(flag)
|
||||
if (flag .ne. 0) then
|
||||
call createcpimagedata(nxstart,nxend,nx,nz,nz)
|
||||
end if
|
||||
! adding //char(0) appends the C++ terminating character
|
||||
! to the Fortran array
|
||||
call addfield(psi01,"psi01"//char(0))
|
||||
call coprocess()
|
||||
end if
|
||||
|
||||
return
|
||||
|
||||
end subroutine
|
||||
end module tcp
|
||||
@ -0,0 +1,83 @@
|
||||
|
||||
try: paraview.simple
|
||||
except: from paraview.simple import *
|
||||
|
||||
from paraview import coprocessing
|
||||
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# Code generated from cpstate.py to create the CoProcessor.
|
||||
|
||||
|
||||
# ----------------------- CoProcessor definition -----------------------
|
||||
|
||||
def CreateCoProcessor():
|
||||
def _CreatePipeline(coprocessor, datadescription):
|
||||
class Pipeline:
|
||||
filename_6_pvti = coprocessor.CreateProducer( datadescription, "input" )
|
||||
|
||||
Slice1 = Slice( guiName="Slice1", Crinkleslice=0, SliceOffsetValues=[0.0], Triangulatetheslice=1, SliceType="Plane" )
|
||||
Slice1.SliceType.Offset = 0.0
|
||||
Slice1.SliceType.Origin = [49.5, 49.5, 49.5]
|
||||
Slice1.SliceType.Normal = [1.0, 0.0, 0.0]
|
||||
|
||||
ParallelPolyDataWriter1 = coprocessor.CreateWriter( XMLPPolyDataWriter, "slice_%t.pvtp", 10 )
|
||||
|
||||
return Pipeline()
|
||||
|
||||
class CoProcessor(coprocessing.CoProcessor):
|
||||
def CreatePipeline(self, datadescription):
|
||||
self.Pipeline = _CreatePipeline(self, datadescription)
|
||||
|
||||
coprocessor = CoProcessor()
|
||||
freqs = {'input': [10]}
|
||||
coprocessor.SetUpdateFrequencies(freqs)
|
||||
return coprocessor
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# Global variables that will hold the pipeline for each timestep
|
||||
# Creating the CoProcessor object, doesn't actually create the ParaView pipeline.
|
||||
# It will be automatically setup when coprocessor.UpdateProducers() is called the
|
||||
# first time.
|
||||
coprocessor = CreateCoProcessor()
|
||||
|
||||
#--------------------------------------------------------------
|
||||
# Enable Live-Visualizaton with ParaView
|
||||
coprocessor.EnableLiveVisualization(False)
|
||||
|
||||
|
||||
# ---------------------- Data Selection method ----------------------
|
||||
|
||||
def RequestDataDescription(datadescription):
|
||||
"Callback to populate the request for current timestep"
|
||||
global coprocessor
|
||||
if datadescription.GetForceOutput() == True:
|
||||
# We are just going to request all fields and meshes from the simulation
|
||||
# code/adaptor.
|
||||
for i in range(datadescription.GetNumberOfInputDescriptions()):
|
||||
datadescription.GetInputDescription(i).AllFieldsOn()
|
||||
datadescription.GetInputDescription(i).GenerateMeshOn()
|
||||
return
|
||||
|
||||
# setup requests for all inputs based on the requirements of the
|
||||
# pipeline.
|
||||
coprocessor.LoadRequestedData(datadescription)
|
||||
|
||||
# ------------------------ Processing method ------------------------
|
||||
|
||||
def DoCoProcessing(datadescription):
|
||||
"Callback to do co-processing for current timestep"
|
||||
global coprocessor
|
||||
|
||||
# Update the coprocessor by providing it the newly generated simulation data.
|
||||
# If the pipeline hasn't been setup yet, this will setup the pipeline.
|
||||
coprocessor.UpdateProducers(datadescription)
|
||||
|
||||
# Write output data, if appropriate.
|
||||
coprocessor.WriteData(datadescription);
|
||||
|
||||
# Write image capture (Last arg: rescale lookup table), if appropriate.
|
||||
coprocessor.WriteImages(datadescription, rescale_lookuptable=False)
|
||||
|
||||
# Live Visualization, if enabled.
|
||||
coprocessor.DoLiveVisualization(datadescription, "localhost", 22222)
|
||||
Reference in New Issue
Block a user