Commit 19829fe4 authored by David Moxey's avatar David Moxey

Restructure demo code and ensure all tests are running

parent c482abff
......@@ -304,9 +304,34 @@ MACRO(ADD_NEKPY_LIBRARY name)
INSTALL(TARGETS _${name} DESTINATION ${CMAKE_BINARY_DIR}/NekPy/${name})
ENDMACRO()
#
# ADD_NEKPY_EXECUTABLE(name source)
#
# Adds a NekPy Python-based executable. No compilation is obviously required
# for Python scripts, so this macro simply copies the given file into the
# appropriate install directory.
#
MACRO(ADD_NEKPY_EXECUTABLE name source)
# Copy the files into binary directory.
INSTALL(FILES ${source} DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
FILE(COPY ${source} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
ADD_CUSTOM_TARGET(${name} SOURCES ${source})
ENDMACRO()
#
# ADD_NEKPY_TEST(name)
#
# Adds a NekPy test with a given name. The Test Definition File should be in a
# subdirectory called Tests relative to the CMakeLists.txt file calling this
# macros. The test file should be called NAME.tst, where NAME is given as a
# parameter to this macro.
#
# Arguments:
# - `name`: name of the test file
#
MACRO(ADD_NEKPY_TEST name)
GET_FILENAME_COMPONENT(dir ${CMAKE_CURRENT_SOURCE_DIR} NAME)
ADD_TEST(NAME NekPy_${dir}_${name}
COMMAND Tester ${CMAKE_CURRENT_SOURCE_DIR}/Tests/${name}.tst)
ENDMACRO(ADD_NEKPY_TEST)
SUBDIRS(NekMesh)
ADD_NEKPY_EXECUTABLE(StdIntegral2D.py StdIntegral2D.py)
ADD_NEKPY_EXECUTABLE(Helmholtz2D.py Helmholtz2D.py)
ADD_NEKPY_EXECUTABLE(CurvedGeom.py CurvedGeom.py)
ADD_NEKPY_EXECUTABLE(NekPy_ReferenceTest_CppDeleteFirst.py NekPy_ReferenceTest_CppDeleteFirst.py)
ADD_NEKPY_EXECUTABLE(NekPy_ReferenceTest_PythonDeleteFirst.py NekPy_ReferenceTest_PythonDeleteFirst.py)
ADD_NEKPY_EXECUTABLE(NekPy_MemoryTest_PythonToCpp_Address.py NekPy_MemoryTest_PythonToCpp_Address.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKTAR_TEST(StdIntegral2D)
ADD_NEKTAR_TEST(CurvedGeom)
ADD_NEKTAR_TEST(NekPy_ReferenceTest_CppDeleteFirst)
ADD_NEKTAR_TEST(NekPy_ReferenceTest_PythonDeleteFirst)
ADD_NEKTAR_TEST(NekPy_MemoryTest_PythonToCpp_Address)
IF (NEKTAR_USE_MPI)
ADD_NEKTAR_TEST(Helmholtz2D)
ENDIF()
ENDIF()
SUBDIRS(LibUtilities StdRegions MultiRegions NekMesh)
ADD_NEKPY_EXECUTABLE(ReferenceTest_CppDeleteFirst.py ReferenceTest_CppDeleteFirst.py)
ADD_NEKPY_EXECUTABLE(ReferenceTest_PythonDeleteFirst.py ReferenceTest_PythonDeleteFirst.py)
ADD_NEKPY_EXECUTABLE(MemoryTest_PythonToCpp_Address.py MemoryTest_PythonToCpp_Address.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKPY_TEST(ReferenceTest_CppDeleteFirst)
ADD_NEKPY_TEST(ReferenceTest_PythonDeleteFirst)
ADD_NEKPY_TEST(MemoryTest_PythonToCpp_Address)
ENDIF()
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> NekPy_MemoryTest_PythonToCpp_Address.py </executable>
<parameters></parameters>
<files>
<file description="Session File">newsquare_2x2.xml</file>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> MemoryTest_PythonToCpp_Address.py </executable>
<parameters></parameters>
<files>
<file description="Session File">../../MultiRegions/Tests/newsquare_2x2.xml</file>
</files>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<matches>
<match>
<field id="0">successful!</field>
</match>
</matches>
</metric>
</metrics>
</test>
\ No newline at end of file
</metric>
</metrics>
</test>
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> NekPy_ReferenceTest_PythonDeleteFirst.py </executable>
<parameters></parameters>
<files>
<file description="Session File">newsquare_2x2.xml</file>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> ReferenceTest_CppDeleteFirst.py </executable>
<parameters></parameters>
<files>
<file description="Session File">../../MultiRegions/Tests/newsquare_2x2.xml</file>
</files>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<matches>
<match>
<field id="0">successful!</field>
</match>
</matches>
</metric>
</metrics>
</test>
\ No newline at end of file
</metric>
</metrics>
</test>
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> NekPy_ReferenceTest_CppDeleteFirst.py </executable>
<parameters></parameters>
<files>
<file description="Session File">newsquare_2x2.xml</file>
<description> Memory test for NekPy: Python to C++ array conversion </description>
<executable python="true"> ReferenceTest_PythonDeleteFirst.py </executable>
<parameters></parameters>
<files>
<file description="Session File">../../MultiRegions/Tests/newsquare_2x2.xml</file>
</files>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<metrics>
<metric type="regex" id="1">
<regex>^.*Test (.*)</regex>
<matches>
<match>
<field id="0">successful!</field>
</match>
</matches>
</metric>
</metrics>
</test>
\ No newline at end of file
</metric>
</metrics>
</test>
ADD_NEKPY_EXECUTABLE(Helmholtz2D.py Helmholtz2D.py)
ADD_NEKPY_EXECUTABLE(CurvedGeom.py CurvedGeom.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKPY_TEST(CurvedGeom)
IF (NEKTAR_USE_MPI)
ADD_NEKPY_TEST(Helmholtz2D)
ENDIF()
ENDIF()
......@@ -19,7 +19,7 @@ s = [ SegGeom(i, 2, [p[i], p[(i+1) % 4]]) for i in range(0,4) ]
# Create a quadratic curve along the base edge.
curve = Curve(1, PointsType.PolyEvenlySpaced)
curve.points = [ p[0], PointGeom(2, 4, 0.5, -0.2, 0.0), p[1] ]
s[0] = SegGeom(i, 2, [p[0], p[1]], curve)
s[0] = SegGeom(0, 2, [p[0], p[1]], curve)
# Construct the geometry object for the square.
geom = QuadGeom(0, s)
......
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description> Integral in standard 2D quad region </description>
<executable python="true"> StdIntegral2D.py </executable>
<executable python="true"> CurvedGeom.py </executable>
<parameters></parameters>
<metrics>
<metric type="regex" id="1">
<regex>.*error.*= ([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?)$</regex>
<regex>L infinity error: ([-+]?[0-9]*\.?[0-9]+(?:[eE][-+]?[0-9]+)?)$</regex>
<matches>
<match>
<field id="0" tolerance="1e-12">0.000000e+00</field>
......
......@@ -5,7 +5,7 @@
<parameters>Helmholtz2D_P7.xml</parameters>
<processes>4</processes>
<files>
<file description="Session File">../../MultiRegions/Tests/Helmholtz2D_P7.xml</file>
<file description="Session File">../../../MultiRegions/Tests/Helmholtz2D_P7.xml</file>
</files>
<metrics>
<metric type="Linf" id="1">
......
ADD_NEKPY_EXECUTABLE(test_nekmesh_node.py test_nekmesh_node.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_element.py test_nekmesh_element.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_mesh.py test_nekmesh_mesh.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_module.py test_nekmesh_module.py)
ADD_NEKPY_EXECUTABLE(StructuredGrid.py StructuredGrid.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKTAR_TEST(test_nekmesh_node)
ADD_NEKTAR_TEST(test_nekmesh_element)
ADD_NEKTAR_TEST(test_nekmesh_mesh)
ADD_NEKTAR_TEST(test_nekmesh_module)
ADD_NEKPY_TEST(structured_grid)
ENDIF()
IF (NEKTAR_USE_MESHGEN)
ADD_NEKPY_EXECUTABLE(LoadCAD.py LoadCAD.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKPY_TEST(load_cad)
ENDIF()
ENDIF()
IF (NEKTAR_BUILD_UNIT_TESTS)
ADD_NEKPY_EXECUTABLE(test_nekmesh_node.py test_nekmesh_node.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_element.py test_nekmesh_element.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_mesh.py test_nekmesh_mesh.py)
ADD_NEKPY_EXECUTABLE(test_nekmesh_module.py test_nekmesh_module.py)
ADD_NEKPY_TEST(test_nekmesh_node)
ADD_NEKPY_TEST(test_nekmesh_element)
ADD_NEKPY_TEST(test_nekmesh_mesh)
ADD_NEKPY_TEST(test_nekmesh_module)
ENDIF()
......@@ -28,5 +28,8 @@ mesh.expDim = 2
# Create a high-order surface
ProcessModule.Create("hosurface", mesh).Process()
# Dump out elemental Jacobians
ProcessModule.Create("jac", mesh, list=True).Process()
# Dump out the surface mesh.
OutputModule.Create("xml", mesh, outfile=sys.argv[2]).Process()
OutputModule.Create("xml", mesh, test=True, outfile=sys.argv[2]).Process()
import NekPy
import sys
from NekPy.LibUtilities import ShapeType
from NekPy.NekMesh import Node, Element, ElmtConfig, NodeSet, Mesh, Module, ModuleType, InputModule, OutputModule
import NekPy.NekMesh as NekMesh
import numpy as np
#
# StructuredGrid creates a 2D structured grid of triangles or quads.
#
class StructuredGrid(InputModule):
class StructuredGrid(NekMesh.InputModule):
def __init__(self, mesh):
super().__init__(mesh)
......@@ -30,7 +29,8 @@ class StructuredGrid(InputModule):
self.AddConfigOption("ly", "0", "Lower-left y-coordinate")
self.AddConfigOption("ry", "0", "Upper-right y-coordinate")
self.AddConfigOption("compid", "0", "Composite ID")
self.AddConfigOption("shape", "Quadrilateral", "Triangular/Quadrilateral Mesh")
self.AddConfigOption("shape", "Quadrilateral",
"Triangular/Quadrilateral Mesh")
def Process(self):
# Get the input variables from our configuration options. You can use
......@@ -44,7 +44,7 @@ class StructuredGrid(InputModule):
coord_2y = self.GetFloatConfig("ry")
nx = self.GetIntConfig("nx")
ny = self.GetIntConfig("ny")
comp_ID = self.GetIntConfig("compid")
compID = self.GetIntConfig("compid")
shape_type = self.GetStringConfig("shape")
x_points = np.linspace(coord_1x, coord_2x, nx)
y_points = np.linspace(coord_1y, coord_2y, ny)
......@@ -55,14 +55,14 @@ class StructuredGrid(InputModule):
for y in range(ny):
tmp = []
for x in range(nx):
tmp.append(Node(id_cnt, x_points[x], y_points[y], 0.0))
tmp.append(NekMesh.Node(id_cnt, x_points[x], y_points[y], 0.0))
id_cnt += 1
nodes.append(tmp)
if shape_type[0].lower() == "q":
self._create_quadrilaterals(nodes, nx, ny, comp_ID)
self._create_quadrilaterals(nodes, nx, ny, compID)
elif shape_type[0].lower() == "t":
self._create_triangles(nodes, nx, ny, comp_ID)
self._create_triangles(nodes, nx, ny, compID)
else:
raise ValueError("Unknown shape type: should be quad or tri.")
......@@ -74,33 +74,36 @@ class StructuredGrid(InputModule):
self.ProcessElements()
self.ProcessComposites()
def _create_quadrilaterals(self, nodes, nx, ny, comp_ID):
def _create_quadrilaterals(self, nodes, nx, ny, compID):
config = NekMesh.ElmtConfig(ShapeType.Quadrilateral, 1, False, False)
for y in range(ny-1):
for x in range(nx-1):
config = ElmtConfig(ShapeType.Quadrilateral, 1, False, False)
self.mesh.element[2].append(
Element.Create(
config, # Element configuration
[nodes[y][x], nodes[y][x+1], nodes[y+1][x+1], nodes[y+1][x]], # node list
[comp_ID])) # tag for composite.
NekMesh.Element.Create(
config, [
nodes[y][x], nodes[y][x+1],
nodes[y+1][x+1], nodes[y+1][x]
], [compID]))
def _create_triangles(self, nodes, nx, ny, comp_ID):
def _create_triangles(self, nodes, nx, ny, compID):
config = NekMesh.ElmtConfig(ShapeType.Triangle, 1, False, False)
for y in range(ny-1):
for x in range(nx-1):
config = ElmtConfig(ShapeType.Triangle, 1, False, False)
self.mesh.element[2].append(
Element.Create(
config,
[nodes[y][x], nodes[y+1][x+1], nodes[y+1][x]],
[comp_ID]))
NekMesh.Element.Create(
config,
[nodes[y][x], nodes[y+1][x+1], nodes[y+1][x]],
[compID]))
self.mesh.element[2].append(
Element.Create(
config,
[nodes[y][x], nodes[y][x+1], nodes[y+1][x+1]],
[comp_ID]))
config,
[nodes[y][x], nodes[y][x+1], nodes[y+1][x+1]],
[compID]))
# Register our TestInput module with the factory.
Module.Register(ModuleType.Input, "StructuredGrid", StructuredGrid)
NekMesh.Module.Register(
NekMesh.ModuleType.Input, "StructuredGrid", StructuredGrid)
if __name__ == '__main__':
if len(sys.argv) != 10:
......@@ -111,10 +114,19 @@ if __name__ == '__main__':
exit(1)
# Create a 'pipeline' of the input and output modules.
mesh = Mesh()
InputModule.Create(
mesh = NekMesh.Mesh()
# First, call our input module's create function from the NekMesh factory.
NekMesh.InputModule.Create(
"StructuredGrid", mesh,
nx = sys.argv[1], ny = sys.argv[2], lx = sys.argv[3],
ly = sys.argv[4], rx = sys.argv[5], ry = sys.argv[6],
compid = sys.argv[7], shape = sys.argv[8]).Process()
OutputModule.Create("xml", mesh, outfile=sys.argv[9]).Process()
# Then ensure there's no negative Jacobians.
NekMesh.ProcessModule.Create("jac", mesh, list=True).Process()
# Finally, output the resulting file (making sure to test it inside Nektar++
# first).
NekMesh.OutputModule.Create(
"xml", mesh, test=True, outfile=sys.argv[9]).Process()
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description>Structured grid generation from NekMesh wrapper</description>
<executable python="true">LoadCAD.py</executable>
<parameters>3d_sphere.stp output.xml</parameters>
<files>
<file description="STEP file input">../../../../../utilities/NekMesh/Tests/MeshGen/STEP/3d_sphere.stp</file>
</files>
<metrics>
<metric type="regex" id="1">
<regex>^Total negative Jacobians: (\d+)</regex>
<matches>
<match>
<field id="0">0</field>
</match>
</matches>
</metric>
</metrics>
</test>
<?xml version="1.0" encoding="utf-8" ?>
<test>
<description>Structured grid generation from NekMesh wrapper</description>
<executable python="true">StructuredGrid.py</executable>
<parameters> 5 6 0.0 1.0 2.0 3.0 2 Quad output.xml </parameters>
<files />
<metrics>
<metric type="regex" id="1">
<regex>^Total negative Jacobians: (\d+)</regex>
<matches>
<match>
<field id="0">0</field>
</match>
</matches>
</metric>
</metrics>
</test>
from NekPy.LibUtilities import SessionReader
import sys
session = SessionReader.CreateInstance(sys.argv)
print("Loaded session: %s" % session.GetSessionName())
ADD_NEKPY_EXECUTABLE(StdIntegral2D.py StdIntegral2D.py)
IF (NEKTAR_BUILD_TESTS)
ADD_NEKPY_TEST(StdIntegral2D)
ENDIF()
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