From b12c40f51ca42898a7ee0de8f18baa923921e547 Mon Sep 17 00:00:00 2001 From: Henning Scheufler Date: Sun, 14 Jul 2024 15:29:50 +0200 Subject: [PATCH] all test run: update headers and class names --- CMakeLists.txt | 4 +- NeoFOAM | 2 +- applications/test_treeAMR/CMakeLists.txt | 17 ++--- benchmarks/explicitOperators/CMakeLists.txt | 2 +- benchmarks/gradOperator/CMakeLists.txt | 2 +- benchmarks/gradOperator/gradOperator.cpp | 10 +-- benchmarks/matrixAssembly/CMakeLists.txt | 2 +- .../NeoFoamScalarAdvection.cpp | 12 +-- .../scalarAdvection/scalarAdvection.cpp | 12 +-- .../comparison/fieldComparison.hpp | 18 +++-- include/FoamAdapter/fvcc/mesh/fvccNeoMesh.hpp | 2 +- include/FoamAdapter/readers/foamFields.hpp | 21 ++++- include/FoamAdapter/writers/writers.hpp | 10 +-- test/CMakeLists.txt | 7 ++ test/test_geometricFields.cpp | 53 +++++++------ test/test_operators.cpp | 76 +++++++++---------- test/test_unstructuredMesh.cpp | 54 ++++++------- tests/test_operator/Allrun | 8 +- 18 files changed, 160 insertions(+), 152 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee3551..2b2c418 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ project( DESCRIPTION "An implementation of FOAM") set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) # Add the cmake folder so the find_package command finds custom packages set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) @@ -24,4 +24,4 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON) add_subdirectory(NeoFOAM) add_subdirectory(src) - +add_subdirectory(test) diff --git a/NeoFOAM b/NeoFOAM index c7b14f6..47749e0 160000 --- a/NeoFOAM +++ b/NeoFOAM @@ -1 +1 @@ -Subproject commit c7b14f6879ab05d7ac0c59dbbfd1ca1c3a820645 +Subproject commit 47749e053efd0f45e0e944cf9ce9819d055e17b5 diff --git a/applications/test_treeAMR/CMakeLists.txt b/applications/test_treeAMR/CMakeLists.txt index 31aae61..0658565 100644 --- a/applications/test_treeAMR/CMakeLists.txt +++ b/applications/test_treeAMR/CMakeLists.txt @@ -5,18 +5,15 @@ add_executable(test_treeAMR "test_treeAMR.cpp") find_package(MPI REQUIRED) find_package(ZLIB REQUIRED) -set_target_properties(test_treeAMR PROPERTIES CXX_STANDARD 17) +set_target_properties(test_treeAMR PROPERTIES CXX_STANDARD 20) -# target_compile_definitions(test_treeAMR PUBLIC WM_LABEL_SIZE=32 NoRepository WM_DP OPENFOAM=2306 OMPI_SKIP_MPICXX) +# target_compile_definitions(test_treeAMR PUBLIC WM_LABEL_SIZE=32 NoRepository WM_DP OPENFOAM=2306 +# OMPI_SKIP_MPICXX) target_include_directories( -test_treeAMR - SYSTEM - PUBLIC ${CMAKE_SOURCE_DIR}/FoamAdapter/include - ${CMAKE_SOURCE_DIR}/NeoFOAM/include - ${MPI_INCLUDE_PATH} - ${ZLIB_INCLUDE_DIRS} - ${CMAKE_SOURCE_DIR}/include + test_treeAMR SYSTEM + PUBLIC ${CMAKE_SOURCE_DIR}/FoamAdapter/include ${CMAKE_SOURCE_DIR}/NeoFOAM/include + ${MPI_INCLUDE_PATH} ${ZLIB_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR}/include ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries( @@ -29,6 +26,4 @@ target_link_libraries( Kokkos::kokkos ${ZLIB_LIBRARIES}) - install(TARGETS test_treeAMR DESTINATION bin) - diff --git a/benchmarks/explicitOperators/CMakeLists.txt b/benchmarks/explicitOperators/CMakeLists.txt index d261148..c41cb30 100644 --- a/benchmarks/explicitOperators/CMakeLists.txt +++ b/benchmarks/explicitOperators/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(explicitOperators "explicitOperators.cpp") -set_target_properties(explicitOperators PROPERTIES CXX_STANDARD 17) +set_target_properties(explicitOperators PROPERTIES CXX_STANDARD 20) target_compile_definitions(explicitOperators PUBLIC WM_LABEL_SIZE=32 NoRepository WM_DP OPENFOAM=2306 OMPI_SKIP_MPICXX) diff --git a/benchmarks/gradOperator/CMakeLists.txt b/benchmarks/gradOperator/CMakeLists.txt index f2bc734..c221fda 100644 --- a/benchmarks/gradOperator/CMakeLists.txt +++ b/benchmarks/gradOperator/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-FileCopyrightText: 2023 NeoFOAM authors add_executable(gradOperator "gradOperator.cpp") -set_target_properties(gradOperator PROPERTIES CXX_STANDARD 17) +set_target_properties(gradOperator PROPERTIES CXX_STANDARD 20) target_compile_definitions(gradOperator PUBLIC WM_LABEL_SIZE=32 NoRepository WM_DP OPENFOAM=2306 OMPI_SKIP_MPICXX) diff --git a/benchmarks/gradOperator/gradOperator.cpp b/benchmarks/gradOperator/gradOperator.cpp index df8b785..0787810 100644 --- a/benchmarks/gradOperator/gradOperator.cpp +++ b/benchmarks/gradOperator/gradOperator.cpp @@ -46,7 +46,7 @@ template void print_field(NeoFOAM::Field a) { std::cout << "a has a size of: " << a.size() << std::endl; - auto tmp_view = a.copyToHost().field(); + auto tmp_view = a.copyToHost().span(); for (int i = 0; i < a.size(); i++) { std::cout << "tmp_view: " << tmp_view[i] << " at: " << i << std::endl; @@ -56,7 +56,7 @@ template<> void print_field(NeoFOAM::Field a) { std::cout << "a has a size of: " << a.size() << std::endl; - auto tmp_view = a.copyToHost().field(); + auto tmp_view = a.copyToHost().span(); for (int i = 0; i < a.size(); i++) { std::cout << "tmp_view: " << tmp_view[i](0) << " " << tmp_view[i](1) << " " @@ -95,7 +95,7 @@ int main(int argc, char* argv[]) { NeoFOAM::Executor exec = NeoFOAM::GPUExecutor(); Foam::Info << "reading mesh" << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); + NeoFOAM::UnstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); NeoFOAM::scalarField Temperature(exec, T.internalField().size()); Temperature.apply(KOKKOS_LAMBDA(int i) { return i; }); @@ -113,7 +113,7 @@ int main(int argc, char* argv[]) { NeoFOAM::Executor exec = NeoFOAM::CPUExecutor(); Foam::Info << "reading mesh" << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); + NeoFOAM::UnstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); NeoFOAM::scalarField Temperature(exec, T.internalField().size()); Temperature.apply(KOKKOS_LAMBDA(int i) { return i; }); @@ -131,7 +131,7 @@ int main(int argc, char* argv[]) { NeoFOAM::Executor exec = NeoFOAM::OMPExecutor(); Foam::Info << "reading mesh" << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); + NeoFOAM::UnstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); NeoFOAM::scalarField Temperature(exec, T.internalField().size()); Temperature.apply(KOKKOS_LAMBDA(int i) { return i; }); diff --git a/benchmarks/matrixAssembly/CMakeLists.txt b/benchmarks/matrixAssembly/CMakeLists.txt index 6d97d29..1e61c15 100644 --- a/benchmarks/matrixAssembly/CMakeLists.txt +++ b/benchmarks/matrixAssembly/CMakeLists.txt @@ -3,7 +3,7 @@ add_executable(matrixAssembly "matrixAssembly.cpp") -set_target_properties(matrixAssembly PROPERTIES CXX_STANDARD 17) +set_target_properties(matrixAssembly PROPERTIES CXX_STANDARD 20) target_compile_definitions(matrixAssembly PUBLIC WM_LABEL_SIZE=32 NoRepository WM_DP OPENFOAM=2306 OMPI_SKIP_MPICXX) diff --git a/benchmarks/scalarAdvection/NeoFoamScalarAdvection.cpp b/benchmarks/scalarAdvection/NeoFoamScalarAdvection.cpp index e94a813..c15167e 100644 --- a/benchmarks/scalarAdvection/NeoFoamScalarAdvection.cpp +++ b/benchmarks/scalarAdvection/NeoFoamScalarAdvection.cpp @@ -6,7 +6,7 @@ #include "NeoFOAM/mesh/unstructuredMesh/unstructuredMesh.hpp" #include "NeoFOAM/cellCentredFiniteVolume/grad/gaussGreenGrad.hpp" #include "NeoFOAM/cellCentredFiniteVolume/div/gaussGreenDiv.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/surfaceInterpolationSelector.hpp" +#include "NeoFOAM/finiteVolume/interpolation/surfaceInterpolationSelector.hpp" #define namespaceFoam // Suppress #include "fvCFD.H" @@ -52,8 +52,8 @@ int main(int argc, char* argv[]) T.write(); // creating neofoam fields Foam::Info << "creating neofoam mesh" << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = Foam::readOpenFOAMMesh(exec, mesh); - NeoFOAM::fvccVolField neoT = Foam::constructFrom(exec, uMesh, T); + NeoFOAM::UnstructuredMesh uMesh = Foam::readOpenFOAMMesh(exec, mesh); + fvcc::VolumeField neoT = Foam::constructFrom(exec, uMesh, T); neoT.correctBoundaryConditions(); NeoFOAM::fvccSurfaceField neoPhi = constructSurfaceField(exec, uMesh, phi); @@ -88,7 +88,7 @@ int main(int argc, char* argv[]) Foam::volScalarField ofDivT("ofDivT", Foam::fvc::div(phi, T)); - NeoFOAM::fvccVolField neoDivT = constructFrom(exec, uMesh, ofDivT); + fvcc::VolumeField neoDivT = constructFrom(exec, uMesh, ofDivT); NeoFOAM::fill(neoDivT.internalField(), 0.0); NeoFOAM::fill(neoDivT.boundaryField().value(), 0.0); @@ -134,8 +134,8 @@ int main(int argc, char* argv[]) // neoT.internalField() = neoT.internalField() - neoDivT.internalField() * // runTime.deltaT().value(); double dt = runTime.deltaT().value(); - auto s_neoT = neoT.internalField().field(); - auto s_neoDivT = neoDivT.internalField().field(); + auto s_neoT = neoT.internalField().span(); + auto s_neoDivT = neoDivT.internalField().span(); neoT.internalField().apply(KOKKOS_LAMBDA(const int celli) { return s_neoT[celli] + dt * s_neoDivT[celli]; }); diff --git a/benchmarks/scalarAdvection/scalarAdvection.cpp b/benchmarks/scalarAdvection/scalarAdvection.cpp index d297411..100b18e 100644 --- a/benchmarks/scalarAdvection/scalarAdvection.cpp +++ b/benchmarks/scalarAdvection/scalarAdvection.cpp @@ -6,7 +6,7 @@ #include "NeoFOAM/mesh/unstructuredMesh/unstructuredMesh.hpp" #include "NeoFOAM/cellCentredFiniteVolume/grad/gaussGreenGrad.hpp" #include "NeoFOAM/cellCentredFiniteVolume/div/gaussGreenDiv.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/surfaceInterpolationSelector.hpp" +#include "NeoFOAM/finiteVolume/interpolation/surfaceInterpolationSelector.hpp" #define namespaceFoam // Suppress #include "fvCFD.H" @@ -52,12 +52,12 @@ int main(int argc, char* argv[]) T.write(); // creating neofoam fields Foam::Info << "creating neofoam mesh" << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = Foam::readOpenFOAMMesh(exec, mesh); - NeoFOAM::fvccVolField neoT = Foam::constructFrom(exec, uMesh, T); + NeoFOAM::UnstructuredMesh uMesh = Foam::readOpenFOAMMesh(exec, mesh); + fvcc::VolumeField neoT = Foam::constructFrom(exec, uMesh, T); neoT.correctBoundaryConditions(); - // NeoFOAM::fvccVolField neoU = constructFrom(exec, uMesh, U); + // fvcc::VolumeField neoU = constructFrom(exec, uMesh, U); - // auto s_cc = uMesh.cellCentres().field(); + // auto s_cc = uMesh.cellCentres().span(); // neoT.internalField().apply(KOKKOS_LAMBDA(int celli) // { // return std::exp(-0.5 * (std::pow((s_cc[celli][0] - 0.5) / spread, 2.0) + @@ -100,7 +100,7 @@ int main(int argc, char* argv[]) Foam::volScalarField ofDivT("ofDivT", Foam::fvc::div(phi, T)); - NeoFOAM::fvccVolField neoDivT = constructFrom(exec, uMesh, ofDivT); + fvcc::VolumeField neoDivT = constructFrom(exec, uMesh, ofDivT); NeoFOAM::fill(neoDivT.internalField(), 0.0); NeoFOAM::fill(neoDivT.boundaryField().value(), 0.0); diff --git a/include/FoamAdapter/comparison/fieldComparison.hpp b/include/FoamAdapter/comparison/fieldComparison.hpp index 7ccf093..44b6370 100644 --- a/include/FoamAdapter/comparison/fieldComparison.hpp +++ b/include/FoamAdapter/comparison/fieldComparison.hpp @@ -5,8 +5,8 @@ #include "Field.H" #include "FoamAdapter/conversion/convert.hpp" #include "FoamAdapter/conversion/type_conversion.hpp" -#include "NeoFOAM/fields/Field.hpp" -#include "NeoFOAM/primitives/label.hpp" +#include "NeoFOAM/fields/field.hpp" +#include "NeoFOAM/core/primitives/label.hpp" #include "surfaceFields.H" #include "volFields.H" #include @@ -14,10 +14,12 @@ namespace Foam { +namespace fvcc = NeoFOAM::finiteVolume::cellCentred; + #define FIELD_EQUALITY_OPERATOR(NFIELD_TYPE, FFIELD_TYPE) \ bool operator==(NeoFOAM::Field& nfield, const Foam::Field& ffield) \ { \ - auto hostSpan = nfield.copyToHost().field(); \ + auto hostSpan = nfield.copyToHost().span(); \ \ for (int i = 0; i < hostSpan.size(); i++) \ { \ @@ -34,11 +36,11 @@ FIELD_EQUALITY_OPERATOR(NeoFOAM::Vector, Foam::vector) #define VOLGEOFIELD_EQUALITY_OPERATOR(NFIELD_TYPE, FFIELD_TYPE) \ bool operator==( \ - NeoFOAM::fvccVolField& nfield, \ + fvcc::VolumeField& nfield, \ const Foam::GeometricField& ffield \ ) \ { \ - auto hostSpan = nfield.internalField().copyToHost().field(); \ + auto hostSpan = nfield.internalField().copyToHost().span(); \ const auto& internalFField = ffield.internalField(); \ /* compare internalField*/ \ for (int i = 0; i < hostSpan.size(); i++) \ @@ -51,7 +53,7 @@ FIELD_EQUALITY_OPERATOR(NeoFOAM::Vector, Foam::vector) /* compare boundaryField */ \ /* NeoFOAM boundaries are stored in contiguous memory */ \ /* whereas OpenFOAM boundaries are stored in a vector of patches */ \ - auto patchValueSpan = nfield.boundaryField().value().copyToHost().field(); \ + auto patchValueSpan = nfield.boundaryField().value().copyToHost().span(); \ NeoFOAM::label pFacei = 0; \ for (const auto& patch : ffield.boundaryField()) \ { \ @@ -74,11 +76,11 @@ VOLGEOFIELD_EQUALITY_OPERATOR(NeoFOAM::Vector, Foam::vector) #define SURFGEOFIELD_EQUALITY_OPERATOR(NFIELD_TYPE, FFIELD_TYPE) \ bool operator==( \ - NeoFOAM::fvccSurfaceField& nfield, \ + fvcc::SurfaceField& nfield, \ const Foam::GeometricField& ffield \ ) \ { \ - auto hostSpan = nfield.internalField().copyToHost().field(); \ + auto hostSpan = nfield.internalField().copyToHost().span(); \ const auto& internalFField = ffield.internalField(); \ /* compare internalField the fvccSurfaceField contains the boundaryValues \ */ \ diff --git a/include/FoamAdapter/fvcc/mesh/fvccNeoMesh.hpp b/include/FoamAdapter/fvcc/mesh/fvccNeoMesh.hpp index d158df2..79fb1c5 100644 --- a/include/FoamAdapter/fvcc/mesh/fvccNeoMesh.hpp +++ b/include/FoamAdapter/fvcc/mesh/fvccNeoMesh.hpp @@ -75,7 +75,7 @@ class fvccNeoMesh : public Foam::fvMesh virtual ~fvccNeoMesh() = default; NeoFOAM::UnstructuredMesh& uMesh() { return uMesh_; } - // const NeoFOAM::unstructuredMesh &uMesh() { return uMesh_; } const + // const NeoFOAM::UnstructuredMesh &uMesh() { return uMesh_; } const }; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/include/FoamAdapter/readers/foamFields.hpp b/include/FoamAdapter/readers/foamFields.hpp index 6e78f24..bfb8d9b 100644 --- a/include/FoamAdapter/readers/foamFields.hpp +++ b/include/FoamAdapter/readers/foamFields.hpp @@ -70,7 +70,18 @@ auto readVolBoundaryConditions(const NeoFOAM::UnstructuredMesh& uMesh, const Foa Foam::word type = patchDict.get("type"); NeoFOAM::Dictionary neoPatchDict; neoPatchDict.insert("type", std::string(type)); - bcs.push_back(VolumeBoundary(uMesh, patchi, neoPatchDict)); + if (type == "zeroGradient") + { + neoPatchDict.insert("type", std::string("fixedGradient")); + neoPatchDict.insert("fixedGradient", type_primitive_t {}); + } + if (type == "extrapolatedCalculated") + { + neoPatchDict.insert("type", std::string("calculated")); + } + bcs.push_back( + std::make_unique>(uMesh, neoPatchDict, patchi) + ); patchi++; } return bcs; @@ -117,9 +128,11 @@ auto readSurfaceBoundaryConditions( Foam::dictionary patchDict = bDict.subDict(bName); Foam::Info << "Boundary type: " << patchDict.get("type") << Foam::endl; Foam::word type = patchDict.get("type"); - NeoFOAM::Dictionary npatchDict; - npatchDict.insert("type", std::string(type)); - bcs.push_back(SurfaceBoundary(uMesh, patchi, npatchDict)); + NeoFOAM::Dictionary neoPatchDict; + neoPatchDict.insert("type", std::string(type)); + bcs.push_back( + std::make_unique>(uMesh, neoPatchDict, patchi) + ); patchi++; } return bcs; diff --git a/include/FoamAdapter/writers/writers.hpp b/include/FoamAdapter/writers/writers.hpp index 450cf42..3eb741e 100644 --- a/include/FoamAdapter/writers/writers.hpp +++ b/include/FoamAdapter/writers/writers.hpp @@ -3,7 +3,7 @@ #pragma once #include "FoamAdapter/conversion/convert.hpp" -#include "NeoFOAM/fields/FieldTypeDefs.hpp" +#include "NeoFOAM/fields/field.hpp" #include "fvMesh.H" #include "volFields.H" @@ -16,7 +16,7 @@ void write(NeoFOAM::scalarField& sf, const Foam::fvMesh& mesh, const std::string if (field) { // field is already present and needs to be updated - auto sf_host = sf.copyToHost().field(); + auto sf_host = sf.copyToHost().span(); Foam::scalarField& field_ref = field->ref(); for (int i = 0; i < field_ref.size(); i++) { @@ -37,7 +37,7 @@ void write(NeoFOAM::scalarField& sf, const Foam::fvMesh& mesh, const std::string mesh, Foam::dimensionedScalar(Foam::dimless, 0) ); - auto sf_host = sf.copyToHost().field(); + auto sf_host = sf.copyToHost().span(); Foam::scalarField& field_ref = foamField.ref(); for (int i = 0; i < field_ref.size(); i++) { @@ -53,7 +53,7 @@ void write(NeoFOAM::vectorField& sf, const Foam::fvMesh& mesh, const std::string if (field) { // field is already present and needs to be updated - auto sf_host = sf.copyToHost().field(); + auto sf_host = sf.copyToHost().span(); Foam::vectorField& field_ref = field->ref(); for (int i = 0; i < field_ref.size(); i++) { @@ -74,7 +74,7 @@ void write(NeoFOAM::vectorField& sf, const Foam::fvMesh& mesh, const std::string mesh, Foam::dimensionedVector(Foam::dimless, Foam::Zero) ); - auto sf_host = sf.copyToHost().field(); + auto sf_host = sf.copyToHost().span(); Foam::vectorField& field_ref = foamField.ref(); for (int i = 0; i < field_ref.size(); i++) { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c6b68ea..583c894 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,6 +3,13 @@ list(APPEND CMAKE_MODULE_PATH ${catch2_SOURCE_DIR}/extras) +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.4.0 # or a later release +) +FetchContent_MakeAvailable(Catch2) + add_executable(test_geometricFields "test_geometricFields.cpp") set_target_properties(test_geometricFields PROPERTIES CXX_STANDARD 20) diff --git a/test/test_geometricFields.cpp b/test/test_geometricFields.cpp index 9a327bd..7ae7e83 100644 --- a/test/test_geometricFields.cpp +++ b/test/test_geometricFields.cpp @@ -7,23 +7,16 @@ #include #include -#include "NeoFOAM/fields/Field.hpp" -#include "NeoFOAM/fields/FieldOperations.hpp" -#include "NeoFOAM/fields/FieldTypeDefs.hpp" -#include "NeoFOAM/fields/comparisions/fieldComparision.hpp" +#include "NeoFOAM/fields/field.hpp" #include "NeoFOAM/fields/boundaryFields.hpp" #include "NeoFOAM/fields/domainField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/fields/fvccVolField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/fields/fvccSurfaceField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/fvccBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/vol/scalar/fvccScalarFixedValueBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/vol/scalar/fvccScalarZeroGradientBoundaryField.hpp" +#include "NeoFOAM/finiteVolume/cellCentred.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/grad/gaussGreenGrad.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/linear.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/upwind.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/surfaceInterpolation.hpp" +#include "NeoFOAM/finiteVolume/operators/gaussGreenGrad.hpp" +#include "NeoFOAM/finiteVolume/interpolation/linear.hpp" +#include "NeoFOAM/finiteVolume/interpolation/upwind.hpp" +#include "NeoFOAM/finiteVolume/interpolation/surfaceInterpolation.hpp" #include "FoamAdapter/readers/foamMesh.hpp" #include "FoamAdapter/writers/writers.hpp" @@ -63,7 +56,17 @@ int main(int argc, char* argv[]) return result; } -TEST_CASE("fvccVolField") +template +void checkField(const NeoFOAM::Field& field, ValueType value) +{ + auto field_host = field.copyToHost().span(); + for (int i = 0; i < field_host.size(); i++) + { + REQUIRE(field_host[i] == value); + } +} + +TEST_CASE("fvcc::VolumeField") { Foam::Time& runTime = *timePtr; Foam::argList& args = *argsPtr; @@ -96,35 +99,37 @@ TEST_CASE("fvccVolField") { Foam::Info << "reading mesh with executor: " << exec_name << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); + NeoFOAM::UnstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); - NeoFOAM::fvccVolField neoT = constructFrom(exec, uMesh, T); + NeoFOAM::fvcc::VolumeField neoT = constructFrom(exec, uMesh, T); + REQUIRE(neoT.internalField().size() == T.internalField().size()); fill(neoT.internalField(), 1.0); - REQUIRE(compare(neoT.internalField(), 1.0)); + checkField(neoT.internalField(), 1.0); neoT.correctBoundaryConditions(); - REQUIRE(compare(neoT.boundaryField().value(), 1.0)); + checkField(neoT.boundaryField().value(), 1.0); fill(neoT.internalField(), 2.0); neoT.correctBoundaryConditions(); - REQUIRE(compare(neoT.boundaryField().value(), 2.0)); + checkField(neoT.boundaryField().value(), 2.0); } SECTION("fvccVolField_[vector]" + exec_name) { Foam::Info << "reading mesh with executor: " << exec_name << Foam::endl; - NeoFOAM::unstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); + NeoFOAM::UnstructuredMesh uMesh = readOpenFOAMMesh(exec, mesh); - NeoFOAM::fvccVolField neoU = constructFrom(exec, uMesh, U); + NeoFOAM::fvcc::VolumeField neoU = constructFrom(exec, uMesh, U); + REQUIRE(neoU.internalField().size() == U.internalField().size()); fill(neoU.internalField(), NeoFOAM::Vector(1.0, 1.0, 1.0)); - REQUIRE(compare(neoU.internalField(), NeoFOAM::Vector(1.0, 1.0, 1.0))); + checkField(neoU.internalField(), NeoFOAM::Vector(1.0, 1.0, 1.0)); neoU.correctBoundaryConditions(); - REQUIRE(compare(neoU.boundaryField().value(), NeoFOAM::Vector(1.0, 1.0, 1.0))); + checkField(neoU.boundaryField().value(), NeoFOAM::Vector(1.0, 1.0, 1.0)); fill(neoU.internalField(), NeoFOAM::Vector(2.0, 2.0, 2.0)); neoU.correctBoundaryConditions(); - REQUIRE(compare(neoU.boundaryField().value(), NeoFOAM::Vector(2.0, 2.0, 2.0))); + checkField(neoU.boundaryField().value(), NeoFOAM::Vector(2.0, 2.0, 2.0)); } } diff --git a/test/test_operators.cpp b/test/test_operators.cpp index fbdb17f..e553ec0 100644 --- a/test/test_operators.cpp +++ b/test/test_operators.cpp @@ -9,29 +9,20 @@ #include #include -#include "NeoFOAM/fields/Field.hpp" -#include "NeoFOAM/fields/FieldOperations.hpp" -#include "NeoFOAM/fields/FieldTypeDefs.hpp" -#include "NeoFOAM/fields/comparisions/fieldComparision.hpp" +#include "NeoFOAM/fields/field.hpp" #include "NeoFOAM/fields/boundaryFields.hpp" #include "NeoFOAM/fields/domainField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/fields/fvccVolField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/fields/fvccSurfaceField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/fvccBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/vol/scalar/fvccScalarFixedValueBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/vol/scalar/fvccScalarZeroGradientBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/surface/scalar/fvccSurfaceScalarCalculatedBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/surface/scalar/fvccSurfaceScalarEmptyBoundaryField.hpp" +#include "NeoFOAM/finiteVolume/cellCentred.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/grad/gaussGreenGrad.hpp" +#include "NeoFOAM/finiteVolume/operators/gaussGreenGrad.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/linear.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/upwind.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/surfaceInterpolation.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/surfaceInterpolation/surfaceInterpolationSelector.hpp" +#include "NeoFOAM/finiteVolume/interpolation/linear.hpp" +#include "NeoFOAM/finiteVolume/interpolation/upwind.hpp" +#include "NeoFOAM/finiteVolume/interpolation/surfaceInterpolation.hpp" + +#include "NeoFOAM/finiteVolume/operators/gaussGreenDiv.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/div/gaussGreenDiv.hpp" #include "FoamAdapter/fvcc/surfaceInterpolation/surfaceInterpolationFactory.hpp" #include "FoamAdapter/readers/foamMesh.hpp" @@ -47,6 +38,8 @@ #include "fvCFD.H" #include "gaussConvectionScheme.H" +namespace fvcc = NeoFOAM::finiteVolume::cellCentred; + Foam::Time* timePtr; // A single time object Foam::argList* argsPtr; // Some forks want argList access at createMesh.H @@ -139,26 +132,22 @@ TEST_CASE("Interpolation") T.correctBoundaryConditions(); Foam::surfaceScalarField surfT(foamInterPol->interpolate(T)); - NeoFOAM::fvccVolField neoT = constructFrom(exec, uMesh, T); + fvcc::VolumeField neoT = constructFrom(exec, uMesh, T); neoT.correctBoundaryConditions(); REQUIRE(neoT == T); - std::vector>> bcs; - bcs.push_back(std::make_unique(uMesh, 0) - ); - bcs.push_back(std::make_unique(uMesh, 1)); - NeoFOAM::fvccSurfaceField neoSurfT(exec, uMesh, std::move(bcs)); + + fvcc::SurfaceField neoSurfT = constructSurfaceField(exec, uMesh, surfT); SECTION("linear") { - // std::unique_ptr linearKernel(new - // NeoFOAM::linear(exec, uMesh)); - - NeoFOAM::surfaceInterpolation interp( - NeoFOAM::surfaceInterpolationSelector(std::string("linear"), exec, mesh.uMesh()) + std::unique_ptr linearKernel( + new NeoFOAM::Linear(exec, uMesh) ); + + NeoFOAM::SurfaceInterpolation interp(exec, uMesh, std::move(linearKernel)); interp.interpolate(neoSurfT, neoT); - auto s_neoSurfT = neoSurfT.internalField().copyToHost().field(); + auto s_neoSurfT = neoSurfT.internalField().copyToHost().span(); std::span surfT_span(surfT.primitiveFieldRef().data(), surfT.size()); REQUIRE_THAT( s_neoSurfT.subspan(0, surfT.size()), @@ -218,14 +207,14 @@ TEST_CASE("GradOperator") Foam::volVectorField ofGradT("ofGradT", foamGradScalar.calcGrad(T, "test")); ofGradT.write(); - NeoFOAM::fvccVolField neoT = constructFrom(exec, uMesh, T); + fvcc::VolumeField neoT = constructFrom(exec, uMesh, T); neoT.correctBoundaryConditions(); REQUIRE_THAT( - neoT.internalField().copyToHost().field(), + neoT.internalField().copyToHost().span(), Catch::Matchers::RangeEquals(s_T, ApproxScalar(1e-16)) ); - NeoFOAM::fvccVolField neoGradT = constructFrom(exec, uMesh, ofGradT); + fvcc::VolumeField neoGradT = constructFrom(exec, uMesh, ofGradT); NeoFOAM::fill(neoGradT.internalField(), NeoFOAM::Vector(0.0, 0.0, 0.0)); NeoFOAM::fill(neoGradT.boundaryField().value(), NeoFOAM::Vector(0.0, 0.0, 0.0)); NeoFOAM::gaussGreenGrad(exec, uMesh).grad(neoGradT, neoT); @@ -234,7 +223,7 @@ TEST_CASE("GradOperator") std::span s_ofGradT(ofGradT.primitiveFieldRef().data(), ofGradT.size()); REQUIRE_THAT( - neoGradT.internalField().copyToHost().field(), + neoGradT.internalField().copyToHost().span(), Catch::Matchers::RangeEquals(s_ofGradT, ApproxVector(1e-12)) ); } @@ -301,12 +290,13 @@ TEST_CASE("DivOperator") Foam::volScalarField ofDivT("ofDivT", foamDivScalar.fvcDiv(phi, T)); ofDivT.write(); - NeoFOAM::fvccVolField neoT = constructFrom(exec, uMesh, T); + fvcc::VolumeField neoT = constructFrom(exec, uMesh, T); - NeoFOAM::fvccSurfaceField neoPhi = constructSurfaceField(exec, uMesh, phi); + NeoFOAM::fvcc::SurfaceField neoPhi = + constructSurfaceField(exec, uMesh, phi); std::span s_phi(phi.primitiveFieldRef().data(), T.size()); - const auto s_neoPhi_host = neoPhi.internalField().copyToHost().field(); + const auto s_neoPhi_host = neoPhi.internalField().copyToHost().span(); REQUIRE_THAT( s_neoPhi_host.subspan(0, s_phi.size()), Catch::Matchers::RangeEquals(s_phi, ApproxScalar(1e-15)) @@ -314,15 +304,19 @@ TEST_CASE("DivOperator") neoT.correctBoundaryConditions(); REQUIRE_THAT( - neoT.internalField().copyToHost().field(), + neoT.internalField().copyToHost().span(), Catch::Matchers::RangeEquals(s_T, ApproxScalar(1e-15)) ); - NeoFOAM::fvccVolField neoDivT = constructFrom(exec, uMesh, ofDivT); + fvcc::VolumeField neoDivT = constructFrom(exec, uMesh, ofDivT); NeoFOAM::fill(neoDivT.internalField(), 0.0); NeoFOAM::fill(neoDivT.boundaryField().value(), 0.0); - NeoFOAM::gaussGreenDiv( - exec, uMesh, NeoFOAM::surfaceInterpolationSelector(std::string("linear"), exec, uMesh) + NeoFOAM::GaussGreenDiv( + exec, + uMesh, + NeoFOAM::SurfaceInterpolation( + exec, uMesh, std::make_unique(exec, uMesh) + ) ) .div(neoDivT, neoPhi, neoT); Foam::Info << "writing divT field for exector: " << exec_name << Foam::endl; @@ -330,7 +324,7 @@ TEST_CASE("DivOperator") std::span s_ofDivT(ofDivT.primitiveFieldRef().data(), ofDivT.size()); REQUIRE_THAT( - neoDivT.internalField().copyToHost().field(), + neoDivT.internalField().copyToHost().span(), Catch::Matchers::RangeEquals(s_ofDivT, ApproxScalar(1e-15)) ); } diff --git a/test/test_unstructuredMesh.cpp b/test/test_unstructuredMesh.cpp index a5a9152..b0ebf6e 100644 --- a/test/test_unstructuredMesh.cpp +++ b/test/test_unstructuredMesh.cpp @@ -8,21 +8,15 @@ #include #include -#include "NeoFOAM/fields/Field.hpp" -#include "NeoFOAM/fields/FieldOperations.hpp" -#include "NeoFOAM/fields/FieldTypeDefs.hpp" -#include "NeoFOAM/fields/comparisions/fieldComparision.hpp" +#include "NeoFOAM/fields/field.hpp" #include "NeoFOAM/fields/boundaryFields.hpp" #include "NeoFOAM/fields/domainField.hpp" -#include "NeoFOAM/fields/operations/sum.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/fields/fvccVolField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/fvccBoundaryField.hpp" -#include "NeoFOAM/cellCentredFiniteVolume/bcFields/vol/scalar/fvccScalarFixedValueBoundaryField.hpp" +#include "NeoFOAM/finiteVolume/cellCentred.hpp" -#include "NeoFOAM/mesh/unstructuredMesh/unstructuredMesh.hpp" -#include "NeoFOAM/mesh/stencil/FvccGeometryScheme.hpp" -#include "NeoFOAM/mesh/stencil/BasicFvccGeometryScheme.hpp" +#include "NeoFOAM/mesh/unstructured.hpp" +#include "NeoFOAM/mesh/stencil/fvccGeometryScheme.hpp" +#include "NeoFOAM/mesh/stencil/basicFvccGeometryScheme.hpp" #include "FoamAdapter/readers/foamMesh.hpp" #include "FoamAdapter/writers/writers.hpp" @@ -101,7 +95,7 @@ TEST_CASE("unstructuredMesh") SECTION("points") { - const auto points = uMesh.points().copyToHost().field(); + const auto points = uMesh.points().copyToHost().span(); REQUIRE(uMesh.points().size() == mesh.points().size()); for (int i = 0; i < points.size(); i++) { @@ -112,7 +106,7 @@ TEST_CASE("unstructuredMesh") SECTION("cellVolumes") { - const auto cellVolumes = uMesh.cellVolumes().copyToHost().field(); + const auto cellVolumes = uMesh.cellVolumes().copyToHost().span(); REQUIRE(cellVolumes.size() == mesh.cellVolumes().size()); for (int i = 0; i < cellVolumes.size(); i++) { @@ -122,7 +116,7 @@ TEST_CASE("unstructuredMesh") SECTION("cellCentres") { - const auto cellCentres = uMesh.cellCentres().copyToHost().field(); + const auto cellCentres = uMesh.cellCentres().copyToHost().span(); REQUIRE(cellCentres.size() == mesh.cellCentres().size()); for (int i = 0; i < cellCentres.size(); i++) { @@ -132,7 +126,7 @@ TEST_CASE("unstructuredMesh") SECTION("faceCentres") { - const auto faceCentres = uMesh.faceCentres().copyToHost().field(); + const auto faceCentres = uMesh.faceCentres().copyToHost().span(); REQUIRE(faceCentres.size() == mesh.faceCentres().size()); for (int i = 0; i < faceCentres.size(); i++) { @@ -142,7 +136,7 @@ TEST_CASE("unstructuredMesh") SECTION("faceAreas") { - const auto faceAreas = uMesh.faceAreas().copyToHost().field(); + const auto faceAreas = uMesh.faceAreas().copyToHost().span(); // REQUIRE(faceAreas.size() == mesh.Sf().size()); for (int i = 0; i < mesh.Sf().size(); i++) { @@ -154,7 +148,7 @@ TEST_CASE("unstructuredMesh") SECTION("magFaceAreas") { Foam::scalarField magSf(mag(mesh.faceAreas())); - const auto magFaceAreas = uMesh.magFaceAreas().copyToHost().field(); + const auto magFaceAreas = uMesh.magFaceAreas().copyToHost().span(); REQUIRE(magFaceAreas.size() == magSf.size()); for (int i = 0; i < magFaceAreas.size(); i++) { @@ -165,7 +159,7 @@ TEST_CASE("unstructuredMesh") SECTION("faceOwner") { - const auto faceOwner = uMesh.faceOwner().copyToHost().field(); + const auto faceOwner = uMesh.faceOwner().copyToHost().span(); REQUIRE(faceOwner.size() == mesh.faceOwner().size()); for (int i = 0; i < faceOwner.size(); i++) { @@ -175,7 +169,7 @@ TEST_CASE("unstructuredMesh") SECTION("faceNeighbour") { - const auto faceNeighbour = uMesh.faceNeighbour().copyToHost().field(); + const auto faceNeighbour = uMesh.faceNeighbour().copyToHost().span(); REQUIRE(faceNeighbour.size() == mesh.faceNeighbour().size()); for (int i = 0; i < faceNeighbour.size(); i++) { @@ -203,7 +197,7 @@ TEST_CASE("unstructuredMesh") // TODO: prettify the following tests SECTION("faceCells") { - auto faceCells = bMesh.faceCells().copyToHost().field(); + auto faceCells = bMesh.faceCells().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -219,7 +213,7 @@ TEST_CASE("unstructuredMesh") SECTION("Cf") { - const auto& Cf = bMesh.Cf().copyToHost().field(); + const auto& Cf = bMesh.cf().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -237,7 +231,7 @@ TEST_CASE("unstructuredMesh") SECTION("Cn") { - const auto& Cn = bMesh.Cn().copyToHost().field(); + const auto& Cn = bMesh.cn().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -255,7 +249,7 @@ TEST_CASE("unstructuredMesh") SECTION("Sf") { - const auto& Sf = bMesh.Sf().copyToHost().field(); + const auto& Sf = bMesh.sf().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -273,7 +267,7 @@ TEST_CASE("unstructuredMesh") SECTION("magSf") { - const auto& magSf = bMesh.magSf().copyToHost().field(); + const auto& magSf = bMesh.magSf().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -289,7 +283,7 @@ TEST_CASE("unstructuredMesh") SECTION("nf") { - const auto& nf = bMesh.nf().copyToHost().field(); + const auto& nf = bMesh.nf().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -307,7 +301,7 @@ TEST_CASE("unstructuredMesh") SECTION("delta") { - const auto& delta = bMesh.delta().copyToHost().field(); + const auto& delta = bMesh.delta().copyToHost().span(); ; forAll(bMeshOF, patchi) { @@ -326,7 +320,7 @@ TEST_CASE("unstructuredMesh") SECTION("weights") { - const auto& weights = bMesh.weights().copyToHost().field(); + const auto& weights = bMesh.weights().copyToHost().span(); forAll(bMeshOF, patchi) { const Foam::fvPatch& patchOF = bMeshOF[patchi]; @@ -342,7 +336,7 @@ TEST_CASE("unstructuredMesh") SECTION("deltaCoeffs") { - const auto& deltaCoeffs = bMesh.deltaCoeffs().copyToHost().field(); + const auto& deltaCoeffs = bMesh.deltaCoeffs().copyToHost().span(); ; forAll(bMeshOF, patchi) { @@ -385,7 +379,7 @@ TEST_CASE("fvccGeometryScheme") scheme.update(); // make sure it uptodate auto foam_weights = mesh.weights(); - auto weights = scheme.weights().internalField().copyToHost().field(); + auto weights = scheme.weights().internalField().copyToHost().span(); std::span s_foam_weights( foam_weights.primitiveFieldRef().data(), foam_weights.size() ); @@ -402,7 +396,7 @@ TEST_CASE("fvccGeometryScheme") scheme.update(); // make sure it uptodate auto foam_weights = mesh.weights(); - auto weights = scheme.weights().internalField().copyToHost().field(); + auto weights = scheme.weights().internalField().copyToHost().span(); std::span s_foam_weights( foam_weights.primitiveFieldRef().data(), foam_weights.size() ); diff --git a/tests/test_operator/Allrun b/tests/test_operator/Allrun index d85492a..ad21bb2 100755 --- a/tests/test_operator/Allrun +++ b/tests/test_operator/Allrun @@ -8,11 +8,9 @@ restore0Dir runApplication blockMesh -runApplication ../../build/src/test/test_unstructuredMesh -runApplication ../../build/src/test/test_geometricFields -runApplication ../../build/src/test/test_operators - - +runApplication ../../build/ReleaseAll/bin/test_unstructuredMesh +runApplication ../../build/ReleaseAll/bin/test_geometricFields +runApplication ../../build/ReleaseAll/bin/test_operators #------------------------------------------------------------------------------