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,50 @@
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
project(CatalystCxxFullExample)
|
||||
|
||||
find_package(ParaView 4.2 REQUIRED COMPONENTS vtkPVPythonCatalyst)
|
||||
include("${PARAVIEW_USE_FILE}")
|
||||
|
||||
if(VTK_INSTALL_PREFIX)
|
||||
# we are in the install tree of ParaView that includes development files.
|
||||
# the ParaViewConfig.cmake file is located at
|
||||
# <installdir>lib/cmake/paraview-<majorversion>.<minorversion>
|
||||
set(PV_MAIN_DIR ${VTK_INSTALL_PREFIX})
|
||||
set(PV_MAIN_SUBDIR "paraview-${PARAVIEW_VERSION_MAJOR}.${PARAVIEW_VERSION_MINOR}")
|
||||
else()
|
||||
set(PV_MAIN_DIR ${ParaView_DIR})
|
||||
endif()
|
||||
# The location of the ParaView and VTK libraries are set to an environment
|
||||
# variable that gets set in the run-catalyst-step*.sh scripts.
|
||||
set(LDLIBRARYPATH "${PV_MAIN_DIR}/lib/${PV_MAIN_SUBDIR}")
|
||||
|
||||
set(DOLFIN_EXAMPLE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(DOLFIN_EXAMPLE_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
set(DOLFIN_EXAMPLE_DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Data")
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-original.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-original.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-catalyst-step1.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-catalyst-step1.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-catalyst-step2.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-catalyst-step2.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-catalyst-step3.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-catalyst-step3.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-catalyst-step4.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-catalyst-step4.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/run-catalyst-step6.sh.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/run-catalyst-step6.sh @ONLY)
|
||||
|
||||
configure_file(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/simulation-env.py.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/simulation-env.py @ONLY)
|
||||
@ -0,0 +1,126 @@
|
||||
|
||||
try: paraview.simple
|
||||
except: from paraview.simple import *
|
||||
|
||||
from paraview import coprocessing
|
||||
import sys
|
||||
|
||||
# ----------------------- CoProcessor definition -----------------------
|
||||
def CreateCoProcessor():
|
||||
def _CreatePipeline(coprocessor, datadescription):
|
||||
class Pipeline:
|
||||
#### disable automatic camera reset on 'Show'
|
||||
paraview.simple._DisableFirstRenderCameraReset()
|
||||
|
||||
# Create a new 'Render View'
|
||||
renderView1 = CreateView('RenderView')
|
||||
renderView1.ViewSize = [441, 1029]
|
||||
renderView1.InteractionMode = '2D'
|
||||
renderView1.CenterOfRotation = [0.5, 0.5, 0.0]
|
||||
renderView1.CameraPosition = [0.6346870059402945, 1.580702880997128, 10000.0]
|
||||
renderView1.CameraFocalPoint = [0.6346870059402945, 1.580702880997128, 0.0]
|
||||
renderView1.CameraParallelScale = 1.649915822768611
|
||||
renderView1.Background = [0.32, 0.34, 0.43]
|
||||
|
||||
# register the view with coprocessor
|
||||
# and provide it with information such as the filename to use,
|
||||
# how frequently to write the images, etc.
|
||||
coprocessor.RegisterView(renderView1,
|
||||
filename='results/image_%t.png', freq=1, fittoscreen=1, magnification=1, width=400, height=400)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# setup the data processing pipelines
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
Source = coprocessor.CreateProducer( datadescription, "input" )
|
||||
threshold1 = Threshold( Source )
|
||||
threshold1.Scalars = ['POINTS', 'Pressure']
|
||||
threshold1.ThresholdRange = [0.0, 0.5]
|
||||
# ----------------------------------------------------------------
|
||||
# setup color maps and opacity mapes used in the visualization
|
||||
# note: the Get..() functions create a new object, if needed
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# get color transfer function/color map for 'Pressure'
|
||||
pressureLUT = GetColorTransferFunction('Pressure')
|
||||
pressureLUT.RGBPoints = [0.0, 0.231373, 0.298039, 0.752941, 0.10473327284884701, 0.865003, 0.865003, 0.865003, 0.20946654569769402, 0.705882, 0.0156863, 0.14902]
|
||||
pressureLUT.ScalarRangeInitialized = 1.0
|
||||
|
||||
# get opacity transfer function/opacity map for 'Pressure'
|
||||
pressurePWF = GetOpacityTransferFunction('Pressure')
|
||||
pressurePWF.Points = [0.0, 0.0, 0.5, 0.0, 0.20946654569769402, 1.0, 0.5, 0.0]
|
||||
pressurePWF.ScalarRangeInitialized = 1
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# setup the visualization in view 'renderView1'
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# show data from Source
|
||||
SourceDisplay = Show(Source, renderView1)
|
||||
# trace defaults for the display properties.
|
||||
SourceDisplay.ColorArrayName = ['POINTS', 'Pressure']
|
||||
SourceDisplay.LookupTable = pressureLUT
|
||||
SourceDisplay.ScalarOpacityUnitDistance = 0.2349792427843548
|
||||
|
||||
# show color legend
|
||||
SourceDisplay.SetScalarBarVisibility(renderView1, True)
|
||||
|
||||
# setup the color legend parameters for each legend in this view
|
||||
|
||||
# get color legend/bar for pressureLUT in view renderView1
|
||||
pressureLUTColorBar = GetScalarBar(pressureLUT, renderView1)
|
||||
pressureLUTColorBar.Title = 'Pressure'
|
||||
pressureLUTColorBar.ComponentTitle = ''
|
||||
|
||||
return Pipeline()
|
||||
|
||||
class CoProcessor(coprocessing.CoProcessor):
|
||||
def CreatePipeline(self, datadescription):
|
||||
self.Pipeline = _CreatePipeline(self, datadescription)
|
||||
|
||||
coprocessor = CoProcessor()
|
||||
freqs = {'input': [1]}
|
||||
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(True)
|
||||
|
||||
# ---------------------- 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
|
||||
timestep = datadescription.GetTimeStep()
|
||||
print "Timestep:", timestep, "Time:", datadescription.GetTime()
|
||||
|
||||
# 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)
|
||||
coprocessor.WriteData(datadescription)
|
||||
coprocessor.WriteImages(datadescription)
|
||||
coprocessor.DoLiveVisualization(datadescription,"localhost",22222)
|
||||
Binary file not shown.
@ -0,0 +1,27 @@
|
||||
[Prerequisites]
|
||||
Install the following packages (needs to be the version 1.3.0)
|
||||
dolfin-bin
|
||||
dolfin-dev
|
||||
dolfin-doc
|
||||
|
||||
[Files]
|
||||
CatalystScriptTest.py
|
||||
a test co-processing script
|
||||
Data/lshape.xml.gz
|
||||
simulation data file, describing the mesh
|
||||
simulation-catalyst-step1.py
|
||||
simulation-catalyst-step2.py
|
||||
simulation-catalyst-step3.py
|
||||
simulation-catalyst-step4.py
|
||||
a solution to exercises
|
||||
simulation.py
|
||||
original dolfin python demo
|
||||
README.txt
|
||||
this file
|
||||
run-original.sh
|
||||
executes original dolfin python demo
|
||||
run-catalyst-step1.sh
|
||||
run-catalyst-step2.sh
|
||||
run-catalyst-step3.sh
|
||||
run-catalyst-step4.sh
|
||||
executes exercise solutions
|
||||
@ -0,0 +1,2 @@
|
||||
LD_LIBRARY_PATH=@LDLIBRARYPATH@:${LD_LIBRARY_PATH} \
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation-catalyst-step1.py @DOLFIN_EXAMPLE_SOURCE_DIR@/CatalystScriptTest.py 1000
|
||||
@ -0,0 +1,2 @@
|
||||
LD_LIBRARY_PATH=@LDLIBRARYPATH@:${LD_LIBRARY_PATH} \
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation-catalyst-step2.py @DOLFIN_EXAMPLE_SOURCE_DIR@/CatalystScriptTest.py 1000
|
||||
@ -0,0 +1,2 @@
|
||||
LD_LIBRARY_PATH=@LDLIBRARYPATH@:${LD_LIBRARY_PATH} \
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation-catalyst-step3.py @DOLFIN_EXAMPLE_SOURCE_DIR@/CatalystScriptTest.py 1000
|
||||
@ -0,0 +1,2 @@
|
||||
LD_LIBRARY_PATH=@LDLIBRARYPATH@:${LD_LIBRARY_PATH} \
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation-catalyst-step4.py @DOLFIN_EXAMPLE_SOURCE_DIR@/CatalystScriptTest.py 1000
|
||||
@ -0,0 +1,2 @@
|
||||
LD_LIBRARY_PATH=@LDLIBRARYPATH@:${LD_LIBRARY_PATH} \
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation-catalyst-step6.py @DOLFIN_EXAMPLE_SOURCE_DIR@/CatalystScriptTest.py 1000
|
||||
1
ParaView-5.0.1/Examples/Catalyst/PythonDolfinExample/run-original.sh.in
Executable file
1
ParaView-5.0.1/Examples/Catalyst/PythonDolfinExample/run-original.sh.in
Executable file
@ -0,0 +1 @@
|
||||
python @DOLFIN_EXAMPLE_SOURCE_DIR@/simulation.py
|
||||
@ -0,0 +1,185 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
|
||||
#
|
||||
# SC14 Paraview's Catalyst tutorial
|
||||
#
|
||||
# Step 1 : initialization
|
||||
#
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# [SC14-Catalyst] import paraview, vtk and paraview's simple API
|
||||
import sys
|
||||
import paraview
|
||||
import paraview.vtk as vtk
|
||||
import paraview.simple as pvsimple
|
||||
|
||||
# [SC14-Catalyst] check for command line arguments
|
||||
if len(sys.argv) != 3:
|
||||
print "command is 'python",sys.argv[0],"<script name> <number of time steps>'"
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] initialize and read input parameters
|
||||
paraview.options.batch = True
|
||||
paraview.options.symmetric = True
|
||||
|
||||
# [SC14-Catalyst] import user co-processing script
|
||||
import vtkPVCatalystPython
|
||||
import os
|
||||
scriptpath, scriptname = os.path.split(sys.argv[1])
|
||||
sys.path.append(scriptpath)
|
||||
if scriptname.endswith(".py"):
|
||||
print 'script name is ', scriptname
|
||||
scriptname = scriptname[0:len(scriptname)-3]
|
||||
try:
|
||||
cpscript = __import__(scriptname)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
maxtimestep = int(sys.argv[2])
|
||||
tstep = 0
|
||||
t = dt
|
||||
while tstep < maxtimestep:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution [SC14-Catalyst] Not anymore
|
||||
# plot(p1, title="Pressure", rescale=True)
|
||||
# plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file [SC14-Catalyst] Not anymore
|
||||
# ufile << u1
|
||||
# pfile << p1
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
tstep += 1
|
||||
print "t =", t, "step =",tstep
|
||||
|
||||
# Hold plot [SC14-Catalyst] Not anymore
|
||||
# interactive()
|
||||
@ -0,0 +1,199 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
|
||||
#
|
||||
# SC14 Paraview's Catalyst tutorial
|
||||
#
|
||||
# Step 2 : plug to catalyst python API, add a coProcess function
|
||||
#
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# [SC14-Catalyst] import paraview, vtk and paraview's simple API
|
||||
import sys
|
||||
import paraview
|
||||
import paraview.vtk as vtk
|
||||
import paraview.simple as pvsimple
|
||||
|
||||
# [SC14-Catalyst] check for command line arguments
|
||||
if len(sys.argv) != 3:
|
||||
print "command is 'python",sys.argv[0],"<script name> <number of time steps>'"
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] initialize and read input parameters
|
||||
paraview.options.batch = True
|
||||
paraview.options.symmetric = True
|
||||
|
||||
# [SC14-Catalyst] import user co-processing script
|
||||
import vtkPVCatalystPython
|
||||
import os
|
||||
scriptpath, scriptname = os.path.split(sys.argv[1])
|
||||
sys.path.append(scriptpath)
|
||||
if scriptname.endswith(".py"):
|
||||
print 'script name is ', scriptname
|
||||
scriptname = scriptname[0:len(scriptname)-3]
|
||||
try:
|
||||
cpscript = __import__(scriptname)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] Co-Processing routine to be called at the end of each simulation time step
|
||||
def coProcess(grid, time, step):
|
||||
# initialize data description
|
||||
datadescription = vtkPVCatalystPython.vtkCPDataDescription()
|
||||
datadescription.SetTimeData(time, step)
|
||||
datadescription.AddInput("input")
|
||||
cpscript.RequestDataDescription(datadescription)
|
||||
# to be continued ...
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
maxtimestep = int(sys.argv[2])
|
||||
tstep = 0
|
||||
t = dt
|
||||
while tstep < maxtimestep:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution [SC14-Catalyst] Not anymore
|
||||
# plot(p1, title="Pressure", rescale=True)
|
||||
# plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file [SC14-Catalyst] Not anymore
|
||||
# ufile << u1
|
||||
# pfile << p1
|
||||
|
||||
# [SC14-Catalyst] convert solution to VTK grid
|
||||
ugrid = None
|
||||
|
||||
# [SC14-Catalyst] trigger catalyst execution
|
||||
coProcess(ugrid,t,tstep)
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
tstep += 1
|
||||
print "t =", t, "step =",tstep
|
||||
|
||||
# Hold plot [SC14-Catalyst] Not anymore
|
||||
# interactive()
|
||||
@ -0,0 +1,206 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
|
||||
#
|
||||
# SC14 Paraview's Catalyst tutorial
|
||||
#
|
||||
# Step 3 : complete coProcess function
|
||||
#
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# [SC14-Catalyst] import paraview, vtk and paraview's simple API
|
||||
import sys
|
||||
import paraview
|
||||
import paraview.vtk as vtk
|
||||
import paraview.simple as pvsimple
|
||||
|
||||
# [SC14-Catalyst] check for command line arguments
|
||||
if len(sys.argv) != 3:
|
||||
print "command is 'python",sys.argv[0],"<script name> <number of time steps>'"
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] initialize and read input parameters
|
||||
paraview.options.batch = True
|
||||
paraview.options.symmetric = True
|
||||
|
||||
# [SC14-Catalyst] import user co-processing script
|
||||
import vtkPVCatalystPython
|
||||
import os
|
||||
scriptpath, scriptname = os.path.split(sys.argv[1])
|
||||
sys.path.append(scriptpath)
|
||||
if scriptname.endswith(".py"):
|
||||
print 'script name is ', scriptname
|
||||
scriptname = scriptname[0:len(scriptname)-3]
|
||||
try:
|
||||
cpscript = __import__(scriptname)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] Co-Processing routine to be called at the end of each simulation time step
|
||||
def coProcess(grid, time, step):
|
||||
# initialize data description
|
||||
datadescription = vtkPVCatalystPython.vtkCPDataDescription()
|
||||
datadescription.SetTimeData(time, step)
|
||||
datadescription.AddInput("input")
|
||||
cpscript.RequestDataDescription(datadescription)
|
||||
inputdescription = datadescription.GetInputDescriptionByName("input")
|
||||
if inputdescription.GetIfGridIsNecessary() == False:
|
||||
return
|
||||
if grid != None:
|
||||
# attach VTK data set to pipeline input
|
||||
inputdescription.SetGrid(grid)
|
||||
# execute catalyst processing
|
||||
cpscript.DoCoProcessing(datadescription)
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
maxtimestep = int(sys.argv[2])
|
||||
tstep = 0
|
||||
t = dt
|
||||
while tstep < maxtimestep:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution [SC14-Catalyst] Not anymore
|
||||
# plot(p1, title="Pressure", rescale=True)
|
||||
# plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file [SC14-Catalyst] Not anymore
|
||||
# ufile << u1
|
||||
# pfile << p1
|
||||
|
||||
# [SC14-Catalyst] convert solution to VTK grid
|
||||
ugrid = None
|
||||
|
||||
# [SC14-Catalyst] trigger catalyst execution
|
||||
coProcess(ugrid,t,tstep)
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
tstep += 1
|
||||
print "t =", t, "step =",tstep
|
||||
|
||||
# Hold plot [SC14-Catalyst] Not anymore
|
||||
# interactive()
|
||||
@ -0,0 +1,250 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
|
||||
#
|
||||
# SC14 Paraview's Catalyst tutorial
|
||||
#
|
||||
# Step 4 : convert simulation mesh to a VTK grid
|
||||
#
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# [SC14-Catalyst] import paraview, vtk and paraview's simple API
|
||||
import sys
|
||||
import paraview
|
||||
import paraview.vtk as vtk
|
||||
import paraview.simple as pvsimple
|
||||
|
||||
# [SC14-Catalyst] check for command line arguments
|
||||
if len(sys.argv) != 3:
|
||||
print "command is 'python",sys.argv[0],"<script name> <number of time steps>'"
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] initialize and read input parameters
|
||||
paraview.options.batch = True
|
||||
paraview.options.symmetric = True
|
||||
|
||||
# [SC14-Catalyst] import user co-processing script
|
||||
import vtkPVCatalystPython
|
||||
import os
|
||||
scriptpath, scriptname = os.path.split(sys.argv[1])
|
||||
sys.path.append(scriptpath)
|
||||
if scriptname.endswith(".py"):
|
||||
print 'script name is ', scriptname
|
||||
scriptname = scriptname[0:len(scriptname)-3]
|
||||
try:
|
||||
cpscript = __import__(scriptname)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] Co-Processing routine to be called at the end of each simulation time step
|
||||
def coProcess(grid, time, step):
|
||||
# initialize data description
|
||||
datadescription = vtkPVCatalystPython.vtkCPDataDescription()
|
||||
datadescription.SetTimeData(time, step)
|
||||
datadescription.AddInput("input")
|
||||
cpscript.RequestDataDescription(datadescription)
|
||||
inputdescription = datadescription.GetInputDescriptionByName("input")
|
||||
if inputdescription.GetIfGridIsNecessary() == False:
|
||||
return
|
||||
if grid != None:
|
||||
# attach VTK data set to pipeline input
|
||||
inputdescription.SetGrid(grid)
|
||||
# execute catalyst processing
|
||||
cpscript.DoCoProcessing(datadescription)
|
||||
|
||||
# [SC14-Catalyst] convert a flattened sequence of values to VTK double array
|
||||
def Values2VTKArray(values,n,name):
|
||||
ncomps=len(values)/n
|
||||
array=vtk.vtkDoubleArray()
|
||||
array.SetNumberOfComponents(ncomps)
|
||||
array.SetNumberOfTuples(n)
|
||||
i=0
|
||||
for x in values:
|
||||
array.SetValue(i,x)
|
||||
i+=1
|
||||
array.SetName(name)
|
||||
return array
|
||||
|
||||
# [SC14-Catalyst] convert dolfin mesh to a VTK unstructured grid
|
||||
def Mesh2VTKUGrid(mesh):
|
||||
vtkcelltypes=((),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_QUAD,vtk.VTK_POLYGON,vtk.VTK_POLYGON),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_TETRA,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_HEXAHEDRON))
|
||||
npoints=mesh.num_vertices()
|
||||
geom=mesh.geometry()
|
||||
pts=vtk.vtkPoints()
|
||||
pts.SetNumberOfPoints(npoints)
|
||||
for i in xrange(npoints):
|
||||
p=geom.point(i)
|
||||
pts.SetPoint(i,p.x(),p.y(),p.z())
|
||||
dim = mesh.topology().dim()
|
||||
ncells=mesh.num_cells()
|
||||
cells=vtk.vtkCellArray()
|
||||
cellTypes=vtk.vtkUnsignedCharArray()
|
||||
cellTypes.SetNumberOfTuples(ncells)
|
||||
cellLocations=vtk.vtkIdTypeArray()
|
||||
cellLocations.SetNumberOfTuples(ncells)
|
||||
loc=0
|
||||
for (cell,i) in zip(mesh.cells(),xrange(ncells)) :
|
||||
ncellpoints=len(cell)
|
||||
cells.InsertNextCell(ncellpoints)
|
||||
for cpoint in cell:
|
||||
cells.InsertCellPoint(cpoint)
|
||||
cellTypes.SetTuple1(i,vtkcelltypes[dim][ncellpoints])
|
||||
cellLocations.SetTuple1(i,loc)
|
||||
loc+=1+ncellpoints
|
||||
ugrid = vtk.vtkUnstructuredGrid()
|
||||
ugrid.SetPoints(pts)
|
||||
ugrid.SetCells(cellTypes,cellLocations,cells)
|
||||
return ugrid
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
maxtimestep = int(sys.argv[2])
|
||||
tstep = 0
|
||||
t = dt
|
||||
while tstep < maxtimestep:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution [SC14-Catalyst] Not anymore
|
||||
# plot(p1, title="Pressure", rescale=True)
|
||||
# plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file [SC14-Catalyst] Not anymore
|
||||
# ufile << u1
|
||||
# pfile << p1
|
||||
|
||||
# [SC14-Catalyst] convert solution to VTK grid
|
||||
ugrid = Mesh2VTKUGrid( u1.function_space().mesh() )
|
||||
|
||||
# [SC14-Catalyst] trigger catalyst execution
|
||||
coProcess(ugrid,t,tstep)
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
tstep += 1
|
||||
print "t =", t, "step =",tstep
|
||||
|
||||
# Hold plot [SC14-Catalyst] Not anymore
|
||||
# interactive()
|
||||
@ -0,0 +1,267 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
|
||||
#
|
||||
# SC14 Paraview's Catalyst tutorial
|
||||
#
|
||||
# Step 6 : Add field data arrays to VTK grid
|
||||
#
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# [SC14-Catalyst] import paraview, vtk and paraview's simple API
|
||||
import sys
|
||||
import paraview
|
||||
import paraview.vtk as vtk
|
||||
import paraview.simple as pvsimple
|
||||
|
||||
# [SC14-Catalyst] check for command line arguments
|
||||
if len(sys.argv) != 3:
|
||||
print "command is 'python",sys.argv[0],"<script name> <number of time steps>'"
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] initialize and read input parameters
|
||||
paraview.options.batch = True
|
||||
paraview.options.symmetric = True
|
||||
|
||||
# [SC14-Catalyst] import user co-processing script
|
||||
import vtkPVCatalystPython
|
||||
import os
|
||||
scriptpath, scriptname = os.path.split(sys.argv[1])
|
||||
sys.path.append(scriptpath)
|
||||
if scriptname.endswith(".py"):
|
||||
print 'script name is ', scriptname
|
||||
scriptname = scriptname[0:len(scriptname)-3]
|
||||
try:
|
||||
cpscript = __import__(scriptname)
|
||||
except:
|
||||
print sys.exc_info()
|
||||
print 'Cannot find ', scriptname, ' -- no coprocessing will be performed.'
|
||||
sys.exit(1)
|
||||
|
||||
# [SC14-Catalyst] Co-Processing routine to be called at the end of each simulation time step
|
||||
def coProcess(grid, time, step):
|
||||
# initialize data description
|
||||
datadescription = vtkPVCatalystPython.vtkCPDataDescription()
|
||||
datadescription.SetTimeData(time, step)
|
||||
datadescription.AddInput("input")
|
||||
cpscript.RequestDataDescription(datadescription)
|
||||
inputdescription = datadescription.GetInputDescriptionByName("input")
|
||||
if inputdescription.GetIfGridIsNecessary() == False:
|
||||
return
|
||||
if grid != None:
|
||||
# attach VTK data set to pipeline input
|
||||
inputdescription.SetGrid(grid)
|
||||
# execute catalyst processing
|
||||
cpscript.DoCoProcessing(datadescription)
|
||||
|
||||
# [SC14-Catalyst] convert dolfin mesh to a VTK unstructured grid
|
||||
def Mesh2VTKUGrid(mesh):
|
||||
vtkcelltypes=((),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_QUAD,vtk.VTK_POLYGON,vtk.VTK_POLYGON),(vtk.VTK_EMPTY_CELL,vtk.VTK_VERTEX,vtk.VTK_LINE,vtk.VTK_TRIANGLE,vtk.VTK_TETRA,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_CONVEX_POINT_SET,vtk.VTK_HEXAHEDRON))
|
||||
npoints=mesh.num_vertices()
|
||||
geom=mesh.geometry()
|
||||
pts=vtk.vtkPoints()
|
||||
pts.SetNumberOfPoints(npoints)
|
||||
for i in xrange(npoints):
|
||||
p=geom.point(i)
|
||||
pts.SetPoint(i,p.x(),p.y(),p.z())
|
||||
dim = mesh.topology().dim()
|
||||
ncells=mesh.num_cells()
|
||||
cells=vtk.vtkCellArray()
|
||||
cellTypes=vtk.vtkUnsignedCharArray()
|
||||
cellTypes.SetNumberOfTuples(ncells)
|
||||
cellLocations=vtk.vtkIdTypeArray()
|
||||
cellLocations.SetNumberOfTuples(ncells)
|
||||
loc=0
|
||||
for (cell,i) in zip(mesh.cells(),xrange(ncells)) :
|
||||
ncellpoints=len(cell)
|
||||
cells.InsertNextCell(ncellpoints)
|
||||
for cpoint in cell:
|
||||
cells.InsertCellPoint(cpoint)
|
||||
cellTypes.SetTuple1(i,vtkcelltypes[dim][ncellpoints])
|
||||
cellLocations.SetTuple1(i,loc)
|
||||
loc+=1+ncellpoints
|
||||
ugrid = vtk.vtkUnstructuredGrid()
|
||||
ugrid.SetPoints(pts)
|
||||
ugrid.SetCells(cellTypes,cellLocations,cells)
|
||||
return ugrid
|
||||
|
||||
# [SC14-Catalyst] convert a flattened sequence of values to VTK double array
|
||||
def Values2VTKArray(values,n,name):
|
||||
ncomps=len(values)/n
|
||||
array=vtk.vtkDoubleArray()
|
||||
array.SetNumberOfComponents(ncomps)
|
||||
array.SetNumberOfTuples(n)
|
||||
for i in range(n):
|
||||
a = []
|
||||
for j in range(ncomps):
|
||||
a.append(values[i+j*n])
|
||||
array.SetTupleValue(i, a)
|
||||
|
||||
array.SetName(name)
|
||||
return array
|
||||
|
||||
def AddFieldData(ugrid, pointArrays, cellArrays ):
|
||||
# add Point data fields
|
||||
npoints = ugrid.GetNumberOfPoints()
|
||||
for (name,values) in pointArrays:
|
||||
ugrid.GetPointData().AddArray( Values2VTKArray(values,npoints,name) )
|
||||
# add Cell data fields
|
||||
ncells = ugrid.GetNumberOfCells()
|
||||
for (name,values) in cellArrays:
|
||||
ugrid.GetCellData().AddArray( Values2VTKArray(values,ncells,name) )
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
maxtimestep = int(sys.argv[2])
|
||||
tstep = 0
|
||||
t = dt
|
||||
while tstep < maxtimestep:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution [SC14-Catalyst] Not anymore
|
||||
# plot(p1, title="Pressure", rescale=True)
|
||||
# plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file [SC14-Catalyst] Not anymore
|
||||
# ufile << u1
|
||||
# pfile << p1
|
||||
|
||||
# [SC14-Catalyst] convert solution to VTK grid
|
||||
ugrid = Mesh2VTKUGrid( u1.function_space().mesh() )
|
||||
|
||||
# [SC14-Catalyst] add field data to the VTK grid
|
||||
velocity = u1.compute_vertex_values()
|
||||
pressure = p1.compute_vertex_values()
|
||||
AddFieldData( ugrid, [ ("Velocity",velocity) , ("Pressure",pressure) ] , [] )
|
||||
|
||||
# [SC14-Catalyst] trigger catalyst execution
|
||||
coProcess(ugrid,t,tstep)
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
tstep += 1
|
||||
print "t =", t, "step =",tstep
|
||||
|
||||
# Hold plot [SC14-Catalyst] Not anymore
|
||||
# interactive()
|
||||
@ -0,0 +1,11 @@
|
||||
import sys
|
||||
|
||||
DOLFIN_EXAMPLE_DATA_DIR='@DOLFIN_EXAMPLE_DATA_DIR@'
|
||||
PV_MAIN_DIR='@PV_MAIN_DIR@'
|
||||
PV_MAIN_SUBDIR='@PV_MAIN_SUBDIR@'
|
||||
BUILD_DIR='@DOLFIN_EXAMPLE_BUILD_DIR@'
|
||||
SOURCE_DIR='@DOLFIN_EXAMPLE_SOURCE_DIR@'
|
||||
|
||||
PV_PYTHON_PATH = [PV_MAIN_DIR+'/lib/'+PV_MAIN_SUBDIR+'/site-packages', PV_MAIN_DIR+'/lib/'+PV_MAIN_SUBDIR,PV_MAIN_DIR+'/lib/'+PV_MAIN_SUBDIR+'/site-packages/vtk']
|
||||
|
||||
sys.path = PV_PYTHON_PATH + sys.path
|
||||
@ -0,0 +1,144 @@
|
||||
"""This demo program solves the incompressible Navier-Stokes equations
|
||||
on an L-shaped domain using Chorin's splitting method."""
|
||||
|
||||
# Copyright (C) 2010-2011 Anders Logg
|
||||
#
|
||||
# This file is part of DOLFIN.
|
||||
#
|
||||
# DOLFIN is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# DOLFIN 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 Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Modified by Mikael Mortensen 2011
|
||||
#
|
||||
# First added: 2010-08-30
|
||||
# Last changed: 2011-06-30
|
||||
|
||||
# [SC14-Catalyst] we need a python environment that enables import of both Dolfin and ParaView
|
||||
execfile("simulation-env.py")
|
||||
|
||||
# Begin demo
|
||||
|
||||
from dolfin import *
|
||||
|
||||
# Print log messages only from the root process in parallel
|
||||
parameters["std_out_all_processes"] = False;
|
||||
|
||||
# Load mesh from file
|
||||
mesh = Mesh(DOLFIN_EXAMPLE_DATA_DIR+"/lshape.xml.gz")
|
||||
|
||||
# Define function spaces (P2-P1)
|
||||
V = VectorFunctionSpace(mesh, "Lagrange", 2)
|
||||
Q = FunctionSpace(mesh, "Lagrange", 1)
|
||||
|
||||
# Define trial and test functions
|
||||
u = TrialFunction(V)
|
||||
p = TrialFunction(Q)
|
||||
v = TestFunction(V)
|
||||
q = TestFunction(Q)
|
||||
|
||||
# Set parameter values
|
||||
dt = 0.01
|
||||
T = 3
|
||||
nu = 0.01
|
||||
|
||||
# Define time-dependent pressure boundary condition
|
||||
p_in = Expression("sin(3.0*t)", t=0.0)
|
||||
|
||||
# Define boundary conditions
|
||||
noslip = DirichletBC(V, (0, 0),
|
||||
"on_boundary && \
|
||||
(x[0] < DOLFIN_EPS | x[1] < DOLFIN_EPS | \
|
||||
(x[0] > 0.5 - DOLFIN_EPS && x[1] > 0.5 - DOLFIN_EPS))")
|
||||
inflow = DirichletBC(Q, p_in, "x[1] > 1.0 - DOLFIN_EPS")
|
||||
outflow = DirichletBC(Q, 0, "x[0] > 1.0 - DOLFIN_EPS")
|
||||
bcu = [noslip]
|
||||
bcp = [inflow, outflow]
|
||||
|
||||
# Create functions
|
||||
u0 = Function(V)
|
||||
u1 = Function(V)
|
||||
p1 = Function(Q)
|
||||
|
||||
# Define coefficients
|
||||
k = Constant(dt)
|
||||
f = Constant((0, 0))
|
||||
|
||||
# Tentative velocity step
|
||||
F1 = (1/k)*inner(u - u0, v)*dx + inner(grad(u0)*u0, v)*dx + \
|
||||
nu*inner(grad(u), grad(v))*dx - inner(f, v)*dx
|
||||
a1 = lhs(F1)
|
||||
L1 = rhs(F1)
|
||||
|
||||
# Pressure update
|
||||
a2 = inner(grad(p), grad(q))*dx
|
||||
L2 = -(1/k)*div(u1)*q*dx
|
||||
|
||||
# Velocity update
|
||||
a3 = inner(u, v)*dx
|
||||
L3 = inner(u1, v)*dx - k*inner(grad(p1), v)*dx
|
||||
|
||||
# Assemble matrices
|
||||
A1 = assemble(a1)
|
||||
A2 = assemble(a2)
|
||||
A3 = assemble(a3)
|
||||
|
||||
# Use amg preconditioner if available
|
||||
prec = "amg" if has_krylov_solver_preconditioner("amg") else "default"
|
||||
|
||||
# Create files for storing solution
|
||||
ufile = File("results/velocity.pvd")
|
||||
pfile = File("results/pressure.pvd")
|
||||
|
||||
# Time-stepping
|
||||
t = dt
|
||||
while t < T + DOLFIN_EPS:
|
||||
|
||||
# Update pressure boundary condition
|
||||
p_in.t = t
|
||||
|
||||
# Compute tentative velocity step
|
||||
begin("Computing tentative velocity")
|
||||
b1 = assemble(L1)
|
||||
[bc.apply(A1, b1) for bc in bcu]
|
||||
solve(A1, u1.vector(), b1, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Pressure correction
|
||||
begin("Computing pressure correction")
|
||||
b2 = assemble(L2)
|
||||
[bc.apply(A2, b2) for bc in bcp]
|
||||
solve(A2, p1.vector(), b2, "gmres", prec)
|
||||
end()
|
||||
|
||||
# Velocity correction
|
||||
begin("Computing velocity correction")
|
||||
b3 = assemble(L3)
|
||||
[bc.apply(A3, b3) for bc in bcu]
|
||||
solve(A3, u1.vector(), b3, "gmres", "default")
|
||||
end()
|
||||
|
||||
# Plot solution
|
||||
plot(p1, title="Pressure", rescale=True)
|
||||
plot(u1, title="Velocity", rescale=True)
|
||||
|
||||
# Save to file
|
||||
ufile << u1
|
||||
pfile << p1
|
||||
|
||||
# Move to next time step
|
||||
u0.assign(u1)
|
||||
t += dt
|
||||
print "t =", t
|
||||
|
||||
# Hold plot
|
||||
interactive()
|
||||
Reference in New Issue
Block a user