Commit cd69ead1 authored by Dave Moxey's avatar Dave Moxey

Little bit of reorganisation, fix issue with memory pointer and tolerance testing

parent c1644742
......@@ -27,7 +27,6 @@ IF (NEKTAR_BUILD_PYTHON)
FIND_PACKAGE(PythonLibsNew ${PYTHONVER} REQUIRED)
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_DIRS})
ADD_DEFINITIONS(-DWITH_PYTHON)
# Include headers from root directory for config file.
......
SUBDIRS(LibUtilities StdRegions SpatialDomains LocalRegions Collections MultiRegions)
IF(NEKTAR_BUILD_PYTHON)
SUBDIRS(Python)
ENDIF()
......@@ -27,13 +27,3 @@ ADD_NEKTAR_TEST(TimeIntegrationDemoDIRKIMEXOrder2)
ADD_NEKTAR_TEST(TimeIntegrationDemoDIRKIMEXOrder3)
ADD_NEKTAR_TEST(TimeIntegrationDemoCNAB)
ADD_NEKTAR_TEST(TimeIntegrationDemoMCNAB)
IF(NEKTAR_BUILD_PYTHON)
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)
ADD_NEKTAR_TEST(NekPy_ReferenceTest_CppDeleteFirst)
ADD_NEKTAR_TEST(NekPy_ReferenceTest_PythonDeleteFirst)
ADD_NEKTAR_TEST(NekPy_MemoryTest_PythonToCpp_Address)
ENDIF()
\ No newline at end of file
<?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>
from NekPy.LibUtilities import SessionReader
from NekPy.SpatialDomains import MeshGraph
from NekPy.MultiRegions import ExpList2D
import sys
import ctypes
import gc
# import guppy
def get_refcount(coords_address):
gc.collect()
# return len(gc.get_referrers(ctypes.cast(coords_address, ctypes.py_object).value))
return ctypes.c_long.from_address(coords_address).value
# def namestr(obj, namespace):
# return [name for name in namespace if namespace[name] is obj]
def main():
# hp = guppy.hpy()
session_name = ["MemoryTest.py", "newsquare_2x2.xml"]
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d" % graph.GetMeshDimension())
print("\n")
coords = exp.GetCoords()
coords1 = coords[1]
coords = coords[0]
# print coords
coords_address = id(coords)
coords_data_address = coords.ctypes.data
coords_data_size = coords.nbytes
print("Got coordinates...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address)) #1
print "The memory address of coordinates is: {}\n".format(hex(coords_address))
print "The memory address of data is: {}\n".format(hex(coords_data_address))
print "The size of the data is: {}\n".format(coords_data_size)
# print hp.iso(coords).referrers
print("Setting PhysArray (exp.SetPhysArray())...")
exp.SetPhysArray(coords)
print("exp.SetPhysArray() completed...")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address)) #2
# print hp.iso(coords).referrers
print exp.GetPhysAddress()
print exp.GetPhys()
del coords
gc.collect()
print("del coords completed...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address)) #1
print "Calculating the integral..."
print exp.PhysIntegral()
print "Clearing 0x%08x size %i bytes" % (coords_data_address, coords_data_size)
ctypes.memset(coords_data_address, 0, coords_data_size)
print "Calculating the integral..."
print exp.PhysIntegral()
# print "Memory has been cleared. Attempting to retrieve the data..."
# print ctypes.cast(coords_data_address, ctypes.py_object).value
# exp.SetPhysArray(coords1)
# exp.DelPhys()
# del exp
# print("coords substituted")
# print("Reference count for expansion coordinates: %d" % get_refcount(coords_address)) # 0
if __name__ == '__main__':
main()
from NekPy.LibUtilities import SessionReader
from NekPy.SpatialDomains import MeshGraph
from NekPy.MultiRegions import ExpList2D
import sys
import ctypes
import gc
def get_refcount(coords_address):
gc.collect()
# return len(gc.get_referrers(ctypes.cast(coords_address, ctypes.py_object).value))
return ctypes.c_long.from_address(coords_address).value
# def namestr(obj, namespace):
# return [name for name in namespace if namespace[name] is obj]
def test(coords, coords_address, exp):
print("Jumped into test() method...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
exp.SetPhys(coords)
print("exp.SetPhys() completed...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
del coords
print("del coords completed...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
def main():
session_name = ["MemoryTest.py", "newsquare_2x2.xml"]
session = SessionReader.CreateInstance(session_name)
graph = MeshGraph.Read(session)
exp = ExpList2D(session, graph)
print("Loaded session: %s" % session.GetSessionName())
print("Loaded MeshGraph of dimension: %d" % graph.GetMeshDimension())
coords = exp.GetCoords()
coords = coords[0]
# print coords
coords_address = id(coords)
print("Got coordinates...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
test(coords, coords_address, exp)
print("Jumped out of test() method...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
# print exp.GetPhys()
print exp.PhysIntegral()
del exp
print("del exp completed...")
print("Reference count for expansion coordinates: %d" % get_refcount(coords_address))
# print ctypes.cast(coords_address, ctypes.py_object).value
if __name__ == '__main__':
main()
\ No newline at end of file
......@@ -15,7 +15,7 @@ def main():
coords = exp.GetCoords()
coords = coords[0]
coords_data_address = hex(coords.ctypes.data)
coords_data_address = str(hex(coords.ctypes.data)).rstrip('L')
print "The memory address of data is: {}\n".format(coords_data_address)
......
......@@ -4,6 +4,7 @@ from NekPy.MultiRegions import ExpList2D
import ctypes
import gc
import sys
import numpy as np
def get_refcount(coords_address):
gc.collect()
......@@ -11,7 +12,7 @@ def get_refcount(coords_address):
def main():
session_name = ["memory-test-python-to-c-address.py", "newsquare_2x2.xml"]
expected_test_outcome = [1, 2, 2, -9.187094450483263e-15]
expected_test_outcome = [1, 2, 1, -9.187094450483263e-15]
actual_test_outcome = []
session = SessionReader.CreateInstance(session_name)
......@@ -47,7 +48,7 @@ def main():
print("The sum of coordinates array entires is: %r" % sum(coords))
actual_test_outcome.append(sum(coords))
if actual_test_outcome == expected_test_outcome:
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
......
......@@ -4,6 +4,7 @@ from NekPy.MultiRegions import ExpList2D
import ctypes
import gc
import sys
import numpy as np
def get_refcount(coords_address):
gc.collect()
......@@ -38,18 +39,19 @@ def main():
print("Deleting coordinates in Python...")
del coords
gc.collect()
print("Coordinates deleted in Python.")
print("Reference count for expansion coordinates: %d\n" % get_refcount(coords_address))
actual_test_outcome.append(get_refcount(coords_address))
# Ensure we are in PhysState to avoid ASSERT inside ExpList.
exp.SetPhysState(True)
print("Attempting to calculate the integral...")
print("Integral calculated to be: %r" % exp.PhysIntegral())
actual_test_outcome.append(exp.PhysIntegral())
if actual_test_outcome == expected_test_outcome:
if np.allclose(actual_test_outcome, expected_test_outcome):
print("Test successful!")
else:
print("Test unsuccessful")
......
<?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>
......@@ -56,7 +56,3 @@ ADD_NEKTAR_TEST(StdProject_Diff3D_Hex_Mod_P6_Q7)
ADD_NEKTAR_TEST(StdProject_Diff3D_Hex_Lagrange_P6_Q7)
ADD_NEKTAR_TEST(StdProject_Diff3D_Hex_Legendre_P6_Q7)
ADD_NEKTAR_TEST(StdProject_Diff3D_Hex_Chebyshev_P6_Q7)
IF (NEKTAR_BUILD_PYTHON)
SUBDIRS(Python)
ENDIF()
ADD_NEKPY_EXECUTABLE(StdIntegral2D.py StdIntegral2D.py)
ADD_NEKTAR_TEST(StdIntegral2D-python)
......@@ -45,11 +45,6 @@
#include <boost/assign/list_of.hpp>
#include <boost/multi_array.hpp>
#ifdef WITH_PYTHON
#include <sstream>
#include <string>
#endif
namespace Nektar
{
class LinearSystem;
......@@ -77,10 +72,10 @@ namespace Nektar
public:
/// \brief Creates an empty array.
Array() :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer( nullptr ),
m_python_decrement( nullptr ),
#endif
#endif
m_size( 0 ),
m_capacity( 0 ),
m_data( nullptr ),
......@@ -96,10 +91,10 @@ namespace Nektar
/// uninitialized. If it is any other type, each element is initialized with DataType's default
/// constructor.
explicit Array(unsigned int dim1Size) :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer( nullptr ),
m_python_decrement( nullptr ),
#endif
#endif
m_size( dim1Size ),
m_capacity( dim1Size ),
m_data( nullptr ),
......@@ -120,10 +115,10 @@ namespace Nektar
/// element. Otherwise, the DataType's copy constructor
/// is used to initialize each element.
Array(unsigned int dim1Size, const DataType& initValue) :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer( nullptr ),
m_python_decrement( nullptr ),
#endif
#endif
m_size( dim1Size ),
m_capacity( dim1Size ),
m_data( nullptr ),
......@@ -142,10 +137,10 @@ namespace Nektar
/// directly into the underlying storage. Otherwise, the DataType's copy constructor
/// is used to copy each element.
Array(unsigned int dim1Size, const DataType* data) :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer( nullptr ),
m_python_decrement( nullptr ),
#endif
#endif
m_size( dim1Size ),
m_capacity( dim1Size ),
m_data( nullptr ),
......@@ -166,10 +161,10 @@ namespace Nektar
/// The memory for the array will only be deallocated when
/// both rhs and this array have gone out of scope.
Array(unsigned int dim1Size, const Array<OneD, const DataType>& rhs) :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer(rhs.m_memory_pointer),
m_python_decrement(rhs.m_python_decrement),
#endif
#endif
m_size(dim1Size),
m_capacity(rhs.m_capacity),
m_data(rhs.m_data),
......@@ -180,7 +175,7 @@ namespace Nektar
ASSERTL0(m_size <= rhs.num_elements(), "Requested size is larger than input array size.");
}
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
/// \brief Creates a 1D array a copies data into it.
/// \param dim1Size the array's size.
/// \param data The data to reference.
......@@ -198,14 +193,14 @@ namespace Nektar
m_count = new unsigned int();
*m_count = 1;
}
#endif
#endif
/// \brief Creates a reference to rhs.
Array(const Array<OneD, const DataType>& rhs) :
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
m_memory_pointer(rhs.m_memory_pointer),
m_python_decrement(rhs.m_python_decrement),
#endif
#endif
m_size(rhs.m_size),
m_capacity(rhs.m_capacity),
m_data(rhs.m_data),
......@@ -225,7 +220,7 @@ namespace Nektar
*m_count -= 1;
if( *m_count == 0 )
{
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
if (m_memory_pointer == nullptr)
{
ArrayDestructionPolicy<DataType>::Destroy( m_data, m_capacity );
......@@ -233,13 +228,13 @@ namespace Nektar
}
else
{
m_python_decrement(m_data);
m_python_decrement(m_memory_pointer);
}
#else
#else
ArrayDestructionPolicy<DataType>::Destroy( m_data, m_capacity );
MemoryManager<DataType>::RawDeallocate( m_data, m_capacity );
#endif
#endif
delete m_count; // Clean up the memory used for the reference count.
}
}
......@@ -250,8 +245,7 @@ namespace Nektar
*m_count -= 1;
if( *m_count == 0 )
{
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
if (m_memory_pointer == nullptr)
{
ArrayDestructionPolicy<DataType>::Destroy( m_data, m_capacity );
......@@ -259,12 +253,12 @@ namespace Nektar
}
else
{
m_python_decrement(m_data);
m_python_decrement(m_memory_pointer);
}
#else
#else
ArrayDestructionPolicy<DataType>::Destroy( m_data, m_capacity );
MemoryManager<DataType>::RawDeallocate( m_data, m_capacity );
#endif
#endif
delete m_count; // Clean up the memory used for the reference count.
}
......@@ -274,10 +268,10 @@ namespace Nektar
*m_count += 1;
m_offset = rhs.m_offset;
m_size = rhs.m_size;
#ifdef WITH_PYTHON
m_memory_pointer = rhs.m_memory_pointer;
m_python_decrement = rhs.m_python_decrement;
#endif
#ifdef WITH_PYTHON
m_memory_pointer = rhs.m_memory_pointer;
m_python_decrement = rhs.m_python_decrement;
#endif
return *this;
}
......@@ -312,18 +306,6 @@ namespace Nektar
/// \brief Returns the array's reference counter.
unsigned int GetCount() const { return m_count; }
/// \brief Prints the memory address of m_data.
#ifdef WITH_PYTHON
std::string GetDataAddress()
{
const void * address = static_cast<const void*>(m_data);
std::stringstream ss;
ss << address;
std::string name = ss.str();
return name;
}
#endif
/// \brief Returns true is this array and rhs overlap.
bool Overlaps(const Array<OneD, const DataType>& rhs) const
{
......@@ -360,13 +342,13 @@ namespace Nektar
protected:
#ifdef WITH_PYTHON
// m_memory_pointer holds a pointer to the array.
void* m_memory_pointer;
// m_python_decrement holds a pointer to a function decrementing the reference
// counter in Python memory manager.
void (*m_python_decrement)(void *);
#endif
#ifdef WITH_PYTHON
// m_memory_pointer holds a pointer to the array.
void* m_memory_pointer;
// m_python_decrement holds a pointer to a function decrementing the reference
// counter in Python memory manager.
void (*m_python_decrement)(void *);
#endif
unsigned int m_size;
unsigned int m_capacity;
......@@ -627,12 +609,12 @@ namespace Nektar
{
}
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON
Array(unsigned int dim1Size, DataType* data, void* memory_pointer, void (*python_decrement)(void *)) :