From a9d08b580890e2b97506771c55e237a0d33b7215 Mon Sep 17 00:00:00 2001
From: BOYANG XIA <k21147549@kcl.ac.uk>
Date: Tue, 3 Oct 2023 09:23:36 +0000
Subject: [PATCH] Add tests for IProductWRTBaseMatFree and PhysderivMatFree

---
 tests/CMakeLists.txt             |  30 +++++
 tests/test_ipwrtbase_matfree.cpp | 188 +++++++++++++++++++++++++++++++
 tests/test_physderiv_matfree.cpp | 169 +++++++++++++++++++++++++++
 3 files changed, 387 insertions(+)
 create mode 100644 tests/test_ipwrtbase_matfree.cpp
 create mode 100644 tests/test_physderiv_matfree.cpp

diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 9705637..885a16a 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -42,6 +42,15 @@ target_include_directories(test_ipwrtbase PRIVATE ${NEKTAR++_INCLUDE_DIRS})
 target_compile_definitions(test_ipwrtbase PRIVATE
     -DTEST_PATH="${CMAKE_SOURCE_DIR}")
 
+add_executable(test_ipwrtbase_matfree test_ipwrtbase_matfree.cpp)
+target_link_libraries(test_ipwrtbase_matfree PRIVATE Operators)
+target_link_libraries(test_ipwrtbase_matfree PRIVATE ${NEKTAR++_LIBRARIES})
+target_link_libraries(test_ipwrtbase_matfree PRIVATE Boost::unit_test_framework)
+target_include_directories(test_ipwrtbase_matfree PRIVATE "${CMAKE_SOURCE_DIR}")
+target_include_directories(test_ipwrtbase_matfree PRIVATE ${NEKTAR++_INCLUDE_DIRS})
+target_compile_definitions(test_ipwrtbase_matfree PRIVATE
+    -DTEST_PATH="${CMAKE_SOURCE_DIR}")
+
 IF (NEKTAR_USE_CUDA)
     add_executable(test_ipwrtbasecuda test_ipwrtbasecuda.cpp)
     target_link_libraries(test_ipwrtbasecuda PRIVATE Operators)
@@ -62,6 +71,15 @@ target_include_directories(test_physderiv PRIVATE ${NEKTAR++_INCLUDE_DIRS})
 target_compile_definitions(test_physderiv PRIVATE
     -DTEST_PATH="${CMAKE_SOURCE_DIR}")
 
+add_executable(test_physderiv_matfree test_physderiv_matfree.cpp)
+target_link_libraries(test_physderiv_matfree PRIVATE Operators)
+target_link_libraries(test_physderiv_matfree PRIVATE ${NEKTAR++_LIBRARIES})
+target_link_libraries(test_physderiv_matfree PRIVATE Boost::unit_test_framework)
+target_include_directories(test_physderiv_matfree PRIVATE "${CMAKE_SOURCE_DIR}")
+target_include_directories(test_physderiv_matfree PRIVATE ${NEKTAR++_INCLUDE_DIRS})
+target_compile_definitions(test_physderiv_matfree PRIVATE
+    -DTEST_PATH="${CMAKE_SOURCE_DIR}")
+
 IF (NEKTAR_USE_CUDA)
     add_executable(test_physderivcuda test_physderivcuda.cpp)
     target_link_libraries(test_physderivcuda PRIVATE Operators)
@@ -119,6 +137,12 @@ add_test(
   WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
 )
 
+add_test(
+  NAME IProductWRTBaseMatFree
+  COMMAND test_ipwrtbase_matfree
+  WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+)
+
 IF (NEKTAR_USE_CUDA)
     add_test(
       NAME IProductWRTBaseCUDA
@@ -133,6 +157,12 @@ add_test(
   WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
 )
 
+add_test(
+  NAME PhysDerivMatFree
+  COMMAND test_physderiv_matfree
+  WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+)
+
 IF (NEKTAR_USE_CUDA)
     add_test(
       NAME PhysDerivCUDA
diff --git a/tests/test_ipwrtbase_matfree.cpp b/tests/test_ipwrtbase_matfree.cpp
new file mode 100644
index 0000000..fce9bb2
--- /dev/null
+++ b/tests/test_ipwrtbase_matfree.cpp
@@ -0,0 +1,188 @@
+#define BOOST_TEST_MODULE TestIProductWRTBase
+#include <boost/test/tools/output_test_stream.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <memory>
+
+#include "Operators/OperatorIProductWRTBase.hpp"
+#include "init_ipwrtbasefields.hpp"
+
+BOOST_AUTO_TEST_SUITE(TestIProductWRTBase)
+
+using namespace std;
+using namespace Nektar::Operators;
+using namespace Nektar::LibUtilities;
+using namespace Nektar;
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_seg, Seg)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_quad, Quad)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_tri, Tri)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_square_all_elements, SquareAllElements)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_hex, Hex)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_prism, Prism)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_pyr, Pyr)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_tet, Tet)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_cube_prism_hex, CubePrismHex)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(ipwrtbase_cube_all_elements, CubeAllElements)
+{
+    Configure();
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    IProductWRTBase<>::create(fixt_explist, "MatFree")
+        ->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_AUTO_TEST_SUITE_END()
diff --git a/tests/test_physderiv_matfree.cpp b/tests/test_physderiv_matfree.cpp
new file mode 100644
index 0000000..d5eb056
--- /dev/null
+++ b/tests/test_physderiv_matfree.cpp
@@ -0,0 +1,169 @@
+#define BOOST_TEST_MODULE TestPhysDeriv
+#include <boost/test/tools/output_test_stream.hpp>
+#include <boost/test/unit_test.hpp>
+
+#include <iostream>
+#include <memory>
+
+#include "Operators/OperatorPhysDeriv.hpp"
+#include "init_physderivfields.hpp"
+
+BOOST_FIXTURE_TEST_CASE(physderiv_seg, Seg)
+{
+    Configure(1, 1);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_quad, Quad)
+{
+    Configure(1, 2);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_tri, Tri)
+{
+    Configure(1, 2);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_square_all_elements, SquareAllElements)
+{
+    Configure(1, 2);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-12));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_hex, Hex)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_prism, Prism)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_pyr, Pyr)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    NektarSolution(fixt_expected->GetBlocks(),
+                   fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_tet, Tet)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_cube_prism_hex, CubePrismHex)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
+
+BOOST_FIXTURE_TEST_CASE(physderiv_cube_all_elements, CubeAllElements)
+{
+    Configure(1, 3);
+    SetTestCase(fixt_in->GetBlocks(), fixt_in->GetStorage().GetCPUPtr());
+    ExpectedSolution(fixt_expected->GetBlocks(),
+                     fixt_expected->GetStorage().GetCPUPtr());
+    PhysDeriv<>::create(fixt_explist, "MatFree")->apply(*fixt_in, *fixt_out);
+    fixt_out->ReshapeStorage<1>();
+    BOOST_TEST(fixt_out->compare(*fixt_expected, 1.0E-10));
+    boost::test_tools::output_test_stream output;
+    {
+        OutputIfNotMatch(fixt_out->GetStorage().GetCPUPtr(),
+                         fixt_expected->GetStorage().GetCPUPtr(), 1.0E-12);
+    }
+}
-- 
GitLab