Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • nektar/redesign-prototypes
1 result
Show changes
Commits on Source (6)
cmake_minimum_required(VERSION 3.0)
project(Redesign CXX)
enable_testing()
option(NEKTAR_USE_CUDA "Enable CUDA support" FALSE)
option(NEKTAR_USE_SIMD "Enable SIMD support, if available" TRUE)
......@@ -49,5 +51,7 @@ target_link_libraries(main Operators)
target_include_directories(main PRIVATE "${CMAKE_SOURCE_DIR}")
target_compile_definitions(main PUBLIC ${NEKTAR++_DEFINITIONS})
add_subdirectory(tests)
find_package(Doxygen)
add_custom_target(doc COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_SOURCE_DIR}/Doxyfile)
......@@ -87,6 +87,7 @@ public:
m_storage = std::move(rhs.m_storage);
block_attributes = std::move(rhs.block_attributes);
component_names = std::move(rhs.component_names);
m_curVecWidth = std::move(rhs.m_curVecWidth);
return *this;
}
......
......@@ -9,8 +9,8 @@ template <typename TData>
class OperatorBwdTransImpl<TData, ImplCUDA> : public OperatorBwdTrans<TData>
{
public:
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr& expansionList)
: OperatorBwdTrans<TData>(std::move(expansionList))
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr &expansionList)
: OperatorBwdTrans<TData>(expansionList)
{
}
......@@ -26,7 +26,7 @@ public:
MultiRegions::ExpListSharedPtr expansionList)
{
return std::make_unique<OperatorBwdTransImpl<TData, ImplCUDA>>(
std::move(expansionList));
expansionList);
}
static std::string className;
......
......@@ -8,8 +8,8 @@ template <typename TData>
class OperatorBwdTransImpl<TData, ImplMatFree> : public OperatorBwdTrans<TData>
{
public:
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr& expansionList)
: OperatorBwdTrans<TData>(std::move(expansionList))
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr &expansionList)
: OperatorBwdTrans<TData>(expansionList)
{
}
......@@ -27,10 +27,10 @@ public:
}
static std::unique_ptr<Operator<TData>> instantiate(
const MultiRegions::ExpListSharedPtr& expansionList)
const MultiRegions::ExpListSharedPtr &expansionList)
{
return std::make_unique<OperatorBwdTransImpl<TData, ImplMatFree>>(
std::move(expansionList));
expansionList);
}
static std::string className;
......
......@@ -9,8 +9,8 @@ template <typename TData>
class OperatorBwdTransImpl<TData, ImplStdMat> : public OperatorBwdTrans<TData>
{
public:
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr& expansionList)
: OperatorBwdTrans<TData>(std::move(expansionList))
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr &expansionList)
: OperatorBwdTrans<TData>(expansionList)
{
}
......@@ -42,10 +42,10 @@ public:
}
static std::unique_ptr<Operator<TData>> instantiate(
const MultiRegions::ExpListSharedPtr& expansionList)
const MultiRegions::ExpListSharedPtr &expansionList)
{
return std::make_unique<OperatorBwdTransImpl<TData, ImplStdMat>>(
std::move(expansionList));
expansionList);
}
static std::string className;
......
......@@ -8,8 +8,8 @@ template <typename TData>
class OperatorBwdTransImpl<TData, ImplSumFac> : public OperatorBwdTrans<TData>
{
public:
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr& expansionList)
: OperatorBwdTrans<TData>(std::move(expansionList))
OperatorBwdTransImpl(const MultiRegions::ExpListSharedPtr &expansionList)
: OperatorBwdTrans<TData>(expansionList)
{
}
......@@ -20,10 +20,10 @@ public:
}
static std::unique_ptr<Operator<TData>> instantiate(
const MultiRegions::ExpListSharedPtr& expansionList)
const MultiRegions::ExpListSharedPtr &expansionList)
{
return std::make_unique<OperatorBwdTransImpl<TData, ImplSumFac>>(
std::move(expansionList));
expansionList);
}
static std::string className;
......
......@@ -4,7 +4,7 @@
#include <LibUtilities/BasicUtils/NekFactory.hpp>
#include <MultiRegions/ExpList.h>
//#include <StdRegions/StdExpansion.h>
// #include <StdRegions/StdExpansion.h>
namespace Nektar::Operators
{
......@@ -26,7 +26,7 @@ template <typename TData> class Operator;
template <typename TData>
using OperatorFactory =
Nektar::LibUtilities::NekFactory<std::string, Operator<TData>,
const MultiRegions::ExpListSharedPtr&>;
const MultiRegions::ExpListSharedPtr &>;
// Operator factory singleton
template <typename TData> OperatorFactory<TData> &GetOperatorFactory();
......@@ -36,14 +36,14 @@ template <typename TData> class Operator
public:
virtual ~Operator() = default;
Operator(const MultiRegions::ExpListSharedPtr& expansionList)
: m_expansionList(std::move(expansionList))
Operator(const MultiRegions::ExpListSharedPtr &expansionList)
: m_expansionList(expansionList)
{
}
template <typename TDescriptor>
static std::shared_ptr<typename TDescriptor::class_name> create(
const MultiRegions::ExpListSharedPtr& expansionList,
const MultiRegions::ExpListSharedPtr &expansionList,
std::string pKey = "")
{
std::string key = TDescriptor::key;
......@@ -57,8 +57,7 @@ public:
}
return std::static_pointer_cast<typename TDescriptor::class_name>(
GetOperatorFactory<TData>().CreateInstance(
key, std::move(expansionList)));
GetOperatorFactory<TData>().CreateInstance(key, expansionList));
}
protected:
......
......@@ -13,8 +13,8 @@ template <typename TData> class OperatorBwdTrans : public Operator<TData>
public:
virtual ~OperatorBwdTrans() = default;
OperatorBwdTrans(const MultiRegions::ExpListSharedPtr& expansionList)
: Operator<TData>(std::move(expansionList))
OperatorBwdTrans(const MultiRegions::ExpListSharedPtr &expansionList)
: Operator<TData>(expansionList)
{
}
......@@ -37,11 +37,10 @@ template <typename TData = default_fp_type> struct BwdTrans
static const std::string default_impl;
static std::shared_ptr<class_name> create(
const MultiRegions::ExpListSharedPtr& expansionList,
const MultiRegions::ExpListSharedPtr &expansionList,
std::string pKey = "")
{
return Operator<TData>::template create<BwdTrans>(
std::move(expansionList), pKey);
return Operator<TData>::template create<BwdTrans>(expansionList, pKey);
}
};
......
set(test_src test_bwdtrans.cpp)
find_package(
Boost
REQUIRED
COMPONENTS unit_test_framework
)
add_executable(test_bwdtrans ${test_src})
target_link_libraries(test_bwdtrans PRIVATE Operators)
target_link_libraries(test_bwdtrans PRIVATE ${NEKTAR++_LIBRARIES})
target_link_libraries(test_bwdtrans PRIVATE Boost::unit_test_framework)
target_include_directories(test_bwdtrans PRIVATE "${CMAKE_SOURCE_DIR}")
target_include_directories(test_bwdtrans PRIVATE ${NEKTAR++_INCLUDE_DIRS})
add_test(
NAME BwdTrans
COMMAND test_bwdtrans
# Test executable is looking for input session file in the working
# directory
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/input"
)
#include <boost/test/unit_test_log.hpp>
#include <vector>
#include <string>
#include "Field.hpp"
#include <MultiRegions/ExpList.h>
#include <Operators/OperatorBwdTrans.hpp>
using namespace Nektar::Operators;
using namespace Nektar::LibUtilities;
using namespace Nektar;
/**
* @struct InitFields
*
* A test fixture responsible for making available input and output
* Field objects. The structure constructor (destrucor) is called
* before (after) each call to BOOST_FIXTURE_TEST_CASE(<test name>,
* InitFields) macro.
*
* See "Single test case fixture" on the Boost.Test documentation for more details:
* https://www.boost.org/doc/libs/1_82_0/libs/test/doc/html/boost_test/tests_organization/fixtures/case.html
*/
struct InitFields {
Field<double, FieldState::Coeff> *fixt_in;
Field<double, FieldState::Phys> *fixt_out;
MultiRegions::ExpListSharedPtr fixt_explist {nullptr};
~InitFields() {BOOST_TEST_MESSAGE("teardown fixture");}
static std::vector<BlockAttributes>
GetBlockAttributes(FieldState state,
const MultiRegions::ExpListSharedPtr explist) {
const int n = explist->GetNumElmts();
std::map<std::tuple<LibUtilities::ShapeType,unsigned int,unsigned int>,size_t> blockList;
for (int i = 0; i < explist->GetNumElmts(); ++i)
{
auto e = explist->GetExp(i);
blockList[{e->DetShapeType(),e->GetNcoeffs(),e->GetTotPoints()}]++;
}
std::vector<BlockAttributes> blockAttr;
for (auto &x : blockList)
{
auto val = state == FieldState::Phys ? std::get<2>(x.first) : std::get<1>(x.first);
blockAttr.push_back( { x.second, val } );
}
return blockAttr;
}
InitFields() {
BOOST_TEST_MESSAGE("Creating input and output fields");
// Initialise a session, graph and create an expansion list
LibUtilities::SessionReaderSharedPtr session;
SpatialDomains::MeshGraphSharedPtr graph;
// Construct a fake command-line argument array to be fed to
// Session::Reader::CreateInstance. The first element stands for
// the name of the executable which, in our case, doesn't matter.
int argc = 2;
char *argv[] = {
(char*)"exe_name", (char*)"square.xml"
};
session = LibUtilities::SessionReader::CreateInstance(argc, argv);
graph = SpatialDomains::MeshGraph::Read(session);
fixt_explist = MemoryManager<MultiRegions::ExpList>::AllocateSharedPtr
(session, graph);
// Generate a blocks definition from the expansion list for each state
auto blocks_phys = InitFields::GetBlockAttributes(FieldState::Phys, fixt_explist);
auto blocks_coeff = InitFields::GetBlockAttributes(FieldState::Coeff, fixt_explist);
// Create two Field objects with a MemoryRegionCPU backend by default
auto f_in = Field<double, FieldState::Coeff>::create(blocks_coeff);
auto f_out = Field<double, FieldState::Phys >::create(blocks_phys);
fixt_in = new Field<double, FieldState::Coeff>(std::move(f_in));
fixt_out = new Field<double, FieldState::Phys>(std::move(f_out));
}
};
#define BOOST_TEST_MODULE example
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <memory>
#include "Field.hpp"
#include "Operators/OperatorBwdTrans.hpp"
#include <LibUtilities/BasicUtils/SessionReader.h>
#include <SpatialDomains/MeshGraph.h>
#include <MultiRegions/ExpList.h>
#include "init_fields.hpp"
using namespace std;
using namespace Nektar::Operators;
using namespace Nektar::LibUtilities;
using namespace Nektar;
BOOST_FIXTURE_TEST_CASE( bwdtrans, InitFields )
{
double *x = fixt_in->GetStorage().GetCPUPtr();
// For each element, initialise first coefficient to zero and rest
// to 1.
for (auto const &block : fixt_in->GetBlocks())
{
for (size_t el = 0; el < block.num_elements; ++el)
{
for (size_t coeff = 0; coeff < block.num_pts; ++coeff)
{
if (coeff == 0) {
*(x++) = 1.0;
}
else {
*(x++) = 0.0;
}
}
}
}
BwdTrans<>::create(fixt_explist, "StdMat")->apply(*fixt_in, *fixt_out);
double *y = fixt_out->GetStorage().GetCPUPtr();
BOOST_TEST( y[0] == 1.0 );
}