Commit 11678925 authored by David Moxey's avatar David Moxey

Add examples, update CMakeLists

parent ad0798bf
......@@ -156,9 +156,11 @@ OPTION(NEKTAR_BUILD_UTILITIES "Build utilities." ON)
OPTION(NEKTAR_BUILD_UNIT_TESTS "Build unit tests." ON)
OPTION(NEKTAR_BUILD_TESTS "Build regression tests." ON)
OPTION(NEKTAR_BUILD_TIMINGS "Build benchmark timing codes." OFF)
OPTION(NEKTAR_BUILD_PYTHON "Build Nektar++ Python bindings" OFF)
OPTION(NEKTAR_BUILD_PACKAGES "Build Nektar++ binary packages" OFF)
MARK_AS_ADVANCED(NEKTAR_BUILD_PACKAGES)
OPTION(NEKTAR_TEST_ALL "Include full set of regression tests to this build." OFF)
OPTION(NEKTAR_TEST_USE_HOSTFILE "Use a hostfile to explicitly specify number of
slots." OFF)
......
......@@ -9,7 +9,13 @@
#If the user has not set BOOST_ROOT, look in a couple common places first.
MESSAGE(STATUS "Searching for Boost:")
SET(MIN_VER "1.56.0")
SET(NEEDED_BOOST_LIBS thread iostreams filesystem system program_options regex)
IF (NEKTAR_BUILD_PYTHON)
SET(NEEDED_BOOST_LIBS ${NEEDED_BOOST_LIBS} python)
ENDIF()
SET(Boost_DEBUG 0)
SET(Boost_NO_BOOST_CMAKE ON)
IF( BOOST_ROOT )
......
......@@ -26,3 +26,8 @@ ENDIF()
IF (NEKTAR_UTILITY_FIELDCONVERT OR NEKTAR_UTILITY_NEKMESH OR NEKTAR_BUILD_SOLVERS)
SUBDIRS(FieldUtils)
ENDIF()
IF (NEKTAR_BUILD_PYTHON)
SUBDIRS(Python)
INCLUDE_DIRECTORIES(Python)
ENDIF()
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
# Nektar++ requires C++11. Try to infer this for older CMake versions (less than
# 3.1.0)
IF ("${CMAKE_VERSION}" VERSION_LESS "3.1")
IF (NOT MSVC)
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
IF (COMPILER_SUPPORTS_CXX11)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
ELSE()
MESSAGE(FATAL_ERROR "Nektar++ requires a compiler with C++11 support.")
ENDIF()
ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
MESSAGE(FATAL_ERROR "Nektar++ requires full C++11 support: please upgrade to Visual Studio 2013 or later")
ENDIF()
ELSE()
SET(CMAKE_CXX_STANDARD 11)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
SET(CMAKE_CXX_EXTENSIONS OFF)
ENDIF()
# Default install location
IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/dist CACHE PATH "" FORCE)
ENDIF()
# Find Nektar++
FIND_PACKAGE(Nektar++ REQUIRED)
ADD_DEFINITIONS(${NEKTAR++_DEFINITIONS})
INCLUDE_DIRECTORIES(SYSTEM ${NEKTAR++_INCLUDE_DIRS} ${NEKTAR++_TP_INCLUDE_DIRS})
LINK_DIRECTORIES(${NEKTAR++_LIBRARY_DIRS} ${NEKTAR++_TP_LIBRARY_DIRS})
MESSAGE(STATUS "Found Nektar++: version ${NEKTAR++_VERSION}")
# Set up RPATH so that we grab Nektar++ libraries
SET(CMAKE_MACOSX_RPATH ON)
SET(CMAKE_INSTALL_RPATH ${NEKTAR++_LIBRARY_DIRS})
# Find Boost.Python
FIND_PACKAGE(Boost REQUIRED COMPONENTS python system)
INCLUDE_DIRECTORIES(SYSTEM ${Boost_INCLUDE_DIRS})
SET(BOOST_TMP_LIBS "${Boost_LIBRARIES}")
# Find Python
FIND_PACKAGE(PythonInterp REQUIRED)
FIND_PACKAGE(PythonLibsNew REQUIRED)
INCLUDE_DIRECTORIES(SYSTEM ${PYTHON_INCLUDE_DIRS})
# Fix RPATH issue on OS X
SET(TPSRC ${CMAKE_SOURCE_DIR}/ThirdParty)
SET(TPBUILD ${CMAKE_BINARY_DIR}/ThirdParty)
SET(TPDIST ${CMAKE_BINARY_DIR}/ThirdParty/dist)
IF (NOT EXISTS ${TPSRC})
FILE(MAKE_DIRECTORY ${TPSRC})
ENDIF ()
# Include headers from root directory for config file.
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
# Try to find Boost.NumPy
FIND_LIBRARY(BOOST_NUMPY_LIB boost_numpy PATHS ${Boost_LIBRARY_DIRS})
......@@ -83,12 +26,11 @@ IF (NOT BOOST_NUMPY_LIB)
${TPSRC}/boost-numpy
)
message(STATUS ${TPDIST})
SET(BOOST_NUMPY_LIB ${TPDIST}/lib64/${CMAKE_SHARED_LIBRARY_PREFIX}boost_numpy${CMAKE_SHARED_LIBRARY_SUFFIX})
INCLUDE_DIRECTORIES(SYSTEM ${TPDIST}/include)
# Add this directory to the RPATH.
SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${TPDIST}/lib64)
#SET(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_RPATH} ${TPDIST}/lib64)
ELSE()
ADD_CUSTOM_TARGET(boost-numpy ALL)
ADD_DEFINITIONS(-DBOOST_HAS_NUMPY)
......@@ -106,12 +48,11 @@ MACRO(ADD_NEKPY_LIBRARY name sources)
# Add target link libraries.
TARGET_LINK_LIBRARIES(_${name}
${BOOST_TMP_LIBS}
${Boost_SYSTEM_LIBRARY}
${Boost_PYTHON_LIBRARY}
${BOOST_NUMPY_LIB}
${PYTHON_LIBRARIES}
${NEKTAR++_LIBRARIES}
${NEKTAR++_TP_LIBRARIES}
)
${name})
INSTALL(TARGETS _${name} DESTINATION
${CMAKE_INSTALL_PREFIX}/NekPy/${name})
......@@ -125,9 +66,7 @@ ADD_SUBDIRECTORY(LocalRegions)
ADD_SUBDIRECTORY(MultiRegions)
# Copy lib structure.
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/lib/
DESTINATION ${CMAKE_INSTALL_PREFIX}/NekPy)
INSTALL(DIRECTORY lib/ DESTINATION ${CMAKE_INSTALL_PREFIX}/NekPy)
# Copy examples
INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/example/
DESTINATION ${CMAKE_INSTALL_PREFIX})
INSTALL(DIRECTORY example/ DESTINATION ${CMAKE_INSTALL_PREFIX})
##
## NekPy example: basic interactions with the Points and Basis classes.
##
## This example shows some of the functionality of the Points and Basis
## wrappers. It constructs the Modified C^0 basis (found in the Karniadakis &
## Sherwin book) on a set of Gauss-Lobatto-Legendre points on the standard
## segment [-1,1]. It then constructs a mass matrix and uses this to perform a
## Galerkin L^2 projection of the function u(x) = sin(x).
##
## Functionally this is equivalent to the StdProject demo in Nektar++. You can
## check the output is correct by running the Python script StdProject.py, which
## uses the Nektar++ StdRegions classes directly.
##
# Import necessary LibUtilities components
from math import sin
from NekPy.LibUtilities import PointsKey, Points, Basis, BasisKey, PointsType, BasisType
import numpy as np
# Create a PointsKey and a Points object for numPts GLL points
numPts = 10
ptsKey = PointsKey(numPts, PointsType.GaussLobattoLegendre)
pts = Points.Create(ptsKey)
# Print out some basic information
print("Created PointsKey with %d points" % pts.GetNumPoints())
print("Points locations:")
print(pts.GetZ())
# Test our integration points on something nice like sin(x), which has exact
# integral zero over [-1, 1]
z, w = pts.GetZW()
integral = sum([ sin(z[i]) * w[i] for i in range(0, numPts) ])
print("\nIntegral of sin(x) over [-1,1] = %g", integral)
# Create the modified C^0 basis on our integration points
numModes = numPts-1
basisKey = BasisKey(BasisType.Modified_A, numModes, ptsKey)
basis = Basis.Create(basisKey)
print("\nCreated Basis with %d modes" % basis.GetNumModes())
# Get the basis evaluated at the points. We take a copy since GetBdata returns a
# read-only array. Note also the use of "order='F'" -- this is to store the
# resulting matrix in column-major format to align with Nektar++ storage.
bData = basis.GetBdata().copy().reshape(numPts, numModes, order='F')
# Form a mass matrix = \int \phi_i \phi_j dx
massMat = np.zeros((numModes, numModes))
for i in range(0, numModes):
for j in range(0, numModes):
massMat[i,j] = sum([ bData[k,i] * bData[k,j] * w[k] for k in range(0, numPts) ])
# Project sin(x)
rhs = np.zeros(numModes)
for i in range(0, numModes):
rhs[i] = sum([sin(z[j]) * bData[j,i] * w[j] for j in range(0, numPts) ])
print("\nCalculated projection coefficients:")
print(np.linalg.solve(massMat, rhs))
from NekPy.LibUtilities import SessionReader, BasisKey, PointsKey, PointsType, BasisType
from NekPy.SpatialDomains import MeshGraph, QuadGeom
import NekPy.StdRegions
from NekPy.LocalRegions import QuadExp
import sys
import numpy as np
session = SessionReader.CreateInstance(sys.argv)
graph = MeshGraph.Read(session)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d" % graph.GetMeshDimension())
# Get a map of all quadrilateral geometries
quad_geoms = graph.GetAllQuadGeoms()
print("Mesh contains %d quads" % len(quad_geoms))
for quaditer in quad_geoms:
i = quaditer.key()
quad = quaditer.data()
# Print some basic information about each quad: it's ID, coordinate
# dimension and the number of modes in its geometric representation
# (i.e. NUMPOINTS in the CURVED tags).
sys.stdout.write("\n%15s : %d\n" % ("ID", quad.GetGlobalID()))
sys.stdout.write("%15s : %d\n" % ("Coord. Dim", quad.GetCoordim()))
sys.stdout.write("%15s : %d, %d\n" % (
"# modes", quad.GetBasis(0).GetNumModes(), quad.GetBasis(1).GetNumModes()))
# Fill the geometry with its curvature and generate the geometric factors
quad.FillGeom()
quad.GenGeomFactors()
# Determine if this quad contains the point (0.5, 0.5)?
sys.stdout.write("%15s : %s\n" % (
"Contains point", "yes" if quad.ContainsPoint(np.array([0.25, 0.25])) else "no"))
# Create a LocalRegions expansion of this quad and print out the box that
# bounds it.
basisKey = BasisKey(BasisType.Modified_A, 7,
PointsKey(8, PointsType.GaussLobattoLegendre))
quadExp = QuadExp(basisKey, basisKey, quad)
x, y = quadExp.GetCoords()
sys.stdout.write("%15s : [%f,%f] -> [%f,%f]\n" %
("Bounding box", x.min(), y.min(), x.max(), y.max()))
from NekPy.LibUtilities import SessionReader
import sys
session = SessionReader.CreateInstance(sys.argv)
print("Loaded session: %s" % session.GetSessionName())
##
## NekPy example: basic interactions with the StdRegions classes
##
## This example constructs some simple StdRegions shapes and shows some of the
## operations that can be performed on the wrapper classes.
##
# Import necessary LibUtilities and StdRegions components
from NekPy.LibUtilities import PointsKey, Points, Basis, BasisKey, PointsType, BasisType
from NekPy.StdRegions import StdSegExp, StdQuadExp
# Other Python imports
from math import sin, cos
import numpy as np
# Create a PointsKey and a Points object for numPts GLL points. Create a
# Modified_A basis for the segment.
numPts = 10
numModes = 9
ptsKey = PointsKey(numPts, PointsType.GaussLobattoLegendre)
basisKey = BasisKey(BasisType.Modified_A, numModes, ptsKey)
# Create StdSegExp
seg = StdSegExp(basisKey)
# Use GetCoords to get coordinates of the segment. Note GetCoords always returns
# a tuple.
func = np.sin(seg.GetCoords()[0])
# Project sin(x). You can check the output here with the manual implementation
# in Basis.py.
print("Coefficients of projection of sin(x):")
print(seg.FwdTrans(func))
# Now let's create a quad on a tensor product of the points and basis above.
quad = StdQuadExp(basisKey, basisKey)
# Calculate the integral of the function cos(x)cos(y) on [-1,1]^2
xi, yi = quad.GetCoords()
func = np.cos(xi) * np.cos(yi)
integral = quad.Integral(func)
# Print details of our calculation.
print("Integral of cos(x) * cos(y) over the square [-1,1]^2")
print(" calculated = %g" % integral)
print(" error = %g" % abs(4.0 * sin(1) * sin(1) - integral))
from NekPy.LibUtilities import SessionReader
from NekPy.SpatialDomains import MeshGraph
from NekPy.MultiRegions import ExpList2D
import sys
if len(sys.argv) < 3:
print("Usage: python XmlToVtk.py input1.xml input2.xml ... output.vtu")
exit(1)
# Load up session and create ExpList2D
session = SessionReader.CreateInstance(sys.argv[:-1])
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded %s with %d elements" % (session.GetSessionName(), exp.GetExpSize()))
# Write a VTK file
exp.WriteVTK(sys.argv[-1])
print ("Written: %s" % sys.argv[-1])
<?xml version="1.0" encoding="utf-8" ?>
<NEKTAR>
<GEOMETRY DIM="2" SPACE="2">
<VERTEX>
<V ID="0">-5.00000000e-01 -5.00000000e-01 0.00000000e+00</V>
<V ID="1">-1.31294975e-12 -5.00000000e-01 0.00000000e+00</V>
<V ID="2">0.00000000e+00 0.00000000e+00 0.00000000e+00</V>
<V ID="3">-5.00000000e-01 1.31294975e-12 0.00000000e+00</V>
<V ID="4">5.00000000e-01 -5.00000000e-01 0.00000000e+00</V>
<V ID="5">5.00000000e-01 -1.31294975e-12 0.00000000e+00</V>
<V ID="6">5.00000000e-01 5.00000000e-01 0.00000000e+00</V>
<V ID="7">1.31294975e-12 5.00000000e-01 0.00000000e+00</V>
<V ID="8">-5.00000000e-01 5.00000000e-01 0.00000000e+00</V>
</VERTEX>
<EDGE>
<E ID="0"> 0 1 </E>
<E ID="1"> 1 2 </E>
<E ID="2"> 2 3 </E>
<E ID="3"> 3 0 </E>
<E ID="4"> 1 4 </E>
<E ID="5"> 4 5 </E>
<E ID="6"> 5 2 </E>
<E ID="7"> 5 6 </E>
<E ID="8"> 6 7 </E>
<E ID="9"> 7 2 </E>
<E ID="10"> 7 8 </E>
<E ID="11"> 8 3 </E>
</EDGE>
<ELEMENT>
<Q ID="0"> 0 1 2 3 </Q>
<Q ID="1"> 4 5 6 1 </Q>
<Q ID="2"> 6 7 8 9 </Q>
<Q ID="3"> 2 9 10 11 </Q>
</ELEMENT>
<CURVED>
<E ID="0" EDGEID="9" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 1.31294975e-12 5.00000000e-01 0.00000000e+00 6.56474874e-13 2.50000000e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00</E>
<E ID="1" EDGEID="4" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> -1.31294975e-12 -5.00000000e-01 0.00000000e+00 2.50000000e-01 -5.00000000e-01 0.00000000e+00 5.00000000e-01 -5.00000000e-01 0.00000000e+00</E>
<E ID="2" EDGEID="6" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 5.00000000e-01 -1.31294975e-12 0.00000000e+00 2.50000000e-01 -6.56474874e-13 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00</E>
<E ID="3" EDGEID="1" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> -1.31294975e-12 -5.00000000e-01 0.00000000e+00 -6.56474874e-13 -2.50000000e-01 0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00</E>
<E ID="4" EDGEID="11" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> -5.00000000e-01 5.00000000e-01 0.00000000e+00 -5.00000000e-01 2.50000000e-01 0.00000000e+00 -5.00000000e-01 1.31294975e-12 0.00000000e+00</E>
<E ID="5" EDGEID="5" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 5.00000000e-01 -5.00000000e-01 0.00000000e+00 5.00000000e-01 -2.50000000e-01 0.00000000e+00 5.00000000e-01 -1.31294975e-12 0.00000000e+00</E>
<E ID="6" EDGEID="0" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> -5.00000000e-01 -5.00000000e-01 0.00000000e+00 -2.50000000e-01 -5.00000000e-01 0.00000000e+00 -1.31294975e-12 -5.00000000e-01 0.00000000e+00</E>
<E ID="7" EDGEID="10" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 1.31294975e-12 5.00000000e-01 0.00000000e+00 -2.50000000e-01 5.00000000e-01 0.00000000e+00 -5.00000000e-01 5.00000000e-01 0.00000000e+00</E>
<E ID="8" EDGEID="3" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> -5.00000000e-01 1.31294975e-12 0.00000000e+00 -5.00000000e-01 -2.50000000e-01 0.00000000e+00 -5.00000000e-01 -5.00000000e-01 0.00000000e+00</E>
<E ID="9" EDGEID="8" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 5.00000000e-01 5.00000000e-01 0.00000000e+00 2.50000000e-01 5.00000000e-01 0.00000000e+00 1.31294975e-12 5.00000000e-01 0.00000000e+00</E>
<E ID="10" EDGEID="2" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 0.00000000e+00 0.00000000e+00 0.00000000e+00 -2.50000000e-01 6.56474874e-13 0.00000000e+00 -5.00000000e-01 1.31294975e-12 0.00000000e+00</E>
<E ID="11" EDGEID="7" NUMPOINTS="3" TYPE="PolyEvenlySpaced"> 5.00000000e-01 -1.31294975e-12 0.00000000e+00 5.00000000e-01 2.50000000e-01 0.00000000e+00 5.00000000e-01 5.00000000e-01 0.00000000e+00</E>
</CURVED>
<COMPOSITE>
<C ID="1"> E[0,4] </C>
<C ID="2"> E[5,7] </C>
<C ID="3"> E[8,10] </C>
<C ID="4"> E[3,11] </C>
<C ID="5"> Q[0-3] </C>
</COMPOSITE>
<DOMAIN> C[5] </DOMAIN>
</GEOMETRY>
<EXPANSIONS>
<E COMPOSITE="C[5]" NUMMODES="12" TYPE="GLL_LAGRANGE_SEM" />
</EXPANSIONS>
<CONDITIONS>
<!-- Tol = 1e-09-->
<PARAMETERS>
<P> TimeStep = 0.01 </P>
<P> NumSteps = 1000 </P>
<P> FinTime = TimeStep*NumSteps </P>
<P> IO_CheckSteps = 1000 </P>
<P> IO_InfoSteps = 1000 </P>
<P> wavefreq = PI </P>
<P> epsilon = 0.5 </P>
</PARAMETERS>
<SOLVERINFO>
<I PROPERTY="EQTYPE" VALUE="UnsteadyDiffusion" />
<I PROPERTY="Projection" VALUE="Galerkin" />
<I PROPERTY="DiffusionAdvancement" VALUE="Implicit" />
<I PROPERTY="TimeIntegrationMethod" VALUE="BACKWARDEuler" />
</SOLVERINFO>
<VARIABLES>
<V ID="0"> u </V>
</VARIABLES>
<BOUNDARYREGIONS>
<B ID="0"> C[1] </B>
<B ID="1"> C[2] </B>
<B ID="2"> C[3] </B>
<B ID="3"> C[4] </B>
</BOUNDARYREGIONS>
<BOUNDARYCONDITIONS>
<REGION REF="0">
<N VAR="u" VALUE = "-2.0" />
</REGION>
<REGION REF="1">
<N VAR="u" VALUE= "-2.0" />
</REGION>
<REGION REF="2">
<N VAR="u" VALUE= "5.0" />
</REGION>
<REGION REF="3">
<N VAR="u" VALUE= "5.0" />
</REGION>
</BOUNDARYCONDITIONS>
<FUNCTION NAME="InitialConditions">
<E VAR="u" VALUE="10.0" />
</FUNCTION>
</CONDITIONS>
</NEKTAR>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment