From 55e3b5bafa6dad8b08b68322371fc9d95ca4d785 Mon Sep 17 00:00:00 2001 From: Luis Manuel Diaz Angulo Date: Wed, 17 Aug 2022 19:47:16 +0200 Subject: [PATCH] Reorganizes codes. Removes using namespace mfem from headers. --- src/maxwell/CMakeLists.txt | 6 +- src/maxwell/FiniteElementEvolution.cpp | 3 + src/maxwell/FiniteElementEvolution.h | 14 +- src/maxwell/Material.h | 2 +- src/maxwell/Model.h | 10 +- src/maxwell/Probes.h | 9 +- src/maxwell/Solver.h | 24 ++- src/maxwell/Sources.cpp | 3 +- src/maxwell/Sources.h | 23 ++- src/maxwell/Types.h | 6 - .../BilinearIntegrators.cpp | 3 +- .../{ => mfemExtension}/BilinearIntegrators.h | 22 +- .../TestMfemHesthaven1D.cpp | 4 +- .../TestMfemHesthaven3D.cpp | 2 +- .../TestMfemHesthavenFunctions.cpp | 8 +- .../TestMfemHesthavenFunctions.h | 11 +- .../TestMfemHesthavenTrace1D.cpp | 3 +- test/helpers/AnalyticalFunctions1D.h | 31 +++ test/helpers/CMakeLists.txt | 4 +- ...lobalFunctions.cpp => GlobalFunctions.cpp} | 7 +- ...estGlobalFunctions.h => GlobalFunctions.h} | 4 +- test/maxwell/CMakeLists.txt | 2 +- test/maxwell/TestBilinearIntegrators.cpp | 2 +- test/maxwell/TestMFEMFunctionality.cpp | 9 +- test/maxwell/TestMaterial.cpp | 14 +- test/maxwell/TestProbes.cpp | 12 +- .../{TestSolver.cpp => TestSolver1D.cpp} | 188 ++++++++---------- test/maxwell/TestSolver2D.cpp | 4 +- test/maxwell/TestSources.cpp | 13 +- 29 files changed, 227 insertions(+), 216 deletions(-) rename src/maxwell/{ => mfemExtension}/BilinearIntegrators.cpp (99%) rename src/maxwell/{ => mfemExtension}/BilinearIntegrators.h (93%) create mode 100644 test/helpers/AnalyticalFunctions1D.h rename test/helpers/{TestGlobalFunctions.cpp => GlobalFunctions.cpp} (95%) rename test/helpers/{TestGlobalFunctions.h => GlobalFunctions.h} (93%) rename test/maxwell/{TestSolver.cpp => TestSolver1D.cpp} (91%) diff --git a/src/maxwell/CMakeLists.txt b/src/maxwell/CMakeLists.txt index 272995b6..e55aa53b 100644 --- a/src/maxwell/CMakeLists.txt +++ b/src/maxwell/CMakeLists.txt @@ -7,13 +7,13 @@ include_directories(${MFEM_INCLUDE_DIRS}) add_library(maxwell_solvers STATIC "Solver.h" "Solver.cpp" "FiniteElementEvolution.h" "FiniteElementEvolution.cpp" - "BilinearIntegrators.h" "BilinearIntegrators.cpp" + "mfemExtension/BilinearIntegrators.h" "mfemExtension/BilinearIntegrators.cpp" "Types.h" - "Material.h" "Material.cpp" "Model.h" "Model.cpp" "Probes.h" "Probes.cpp" - "Sources.h" "Sources.cpp") + "Sources.h" "Sources.cpp" +) target_link_libraries(maxwell_solvers mfem) diff --git a/src/maxwell/FiniteElementEvolution.cpp b/src/maxwell/FiniteElementEvolution.cpp index 16b2f99f..8a95c967 100644 --- a/src/maxwell/FiniteElementEvolution.cpp +++ b/src/maxwell/FiniteElementEvolution.cpp @@ -2,6 +2,9 @@ namespace maxwell { +using namespace mfem; +using namespace mfemExtension; + FiniteElementEvolution::FiniteElementEvolution(FiniteElementSpace* fes, Options options, Model& model, Sources& sources) : TimeDependentOperator(numberOfFieldComponents* numberOfMaxDimensions* fes->GetNDofs()), opts_(options), diff --git a/src/maxwell/FiniteElementEvolution.h b/src/maxwell/FiniteElementEvolution.h index 7e30fa6a..db677a37 100644 --- a/src/maxwell/FiniteElementEvolution.h +++ b/src/maxwell/FiniteElementEvolution.h @@ -1,19 +1,19 @@ #pragma once -#include "mfem.hpp" -#include "BilinearIntegrators.h" +#include "mfemExtension/BilinearIntegrators.h" + #include "Types.h" #include "Model.h" #include "Sources.h" -#include - namespace maxwell { -class FiniteElementEvolution : public TimeDependentOperator { +class FiniteElementEvolution : public mfem::TimeDependentOperator { public: - - typedef std::unique_ptr FiniteElementOperator; + using Vector = mfem::Vector; + using FiniteElementSpace = mfem::FiniteElementSpace; + using BilinearForm = mfem::BilinearForm; + using FiniteElementOperator = std::unique_ptr; struct Options { FluxType fluxType = FluxType::Upwind; diff --git a/src/maxwell/Material.h b/src/maxwell/Material.h index 5d196e62..c3150c5b 100644 --- a/src/maxwell/Material.h +++ b/src/maxwell/Material.h @@ -11,7 +11,7 @@ class Material { double getPermittivity() const { return epsilon_; } double getPermeability() const { return mu_; } double getImpedance() const { return sqrt(mu_ / epsilon_); } - double getConductance() const { return sqrt(epsilon_ / mu_); } + double getAdmitance() const { return sqrt(epsilon_ / mu_); } private: double epsilon_, mu_; diff --git a/src/maxwell/Model.h b/src/maxwell/Model.h index d630eb22..2e82eb1d 100644 --- a/src/maxwell/Model.h +++ b/src/maxwell/Model.h @@ -1,11 +1,10 @@ #pragma once -#include "mfem.hpp" -#include "Material.h" -#include "Types.h" +#include #include -using namespace mfem; +#include "Material.h" +#include "Types.h" namespace maxwell { @@ -16,6 +15,7 @@ using AttributeToBoundary = std::map; class Model { public: + using Mesh = mfem::Mesh; Model(Mesh&, const AttributeToMaterial&, const AttributeToBoundary&); Mesh& getMesh() { return mesh_; }; @@ -24,11 +24,9 @@ class Model { const AttributeToBoundary& getAttToBdr() const { return attToBdrMap_; } private: - Mesh mesh_; AttributeToMaterial attToMatMap_; AttributeToBoundary attToBdrMap_; - }; } \ No newline at end of file diff --git a/src/maxwell/Probes.h b/src/maxwell/Probes.h index e4b3b6cb..ebf4d99c 100644 --- a/src/maxwell/Probes.h +++ b/src/maxwell/Probes.h @@ -1,9 +1,8 @@ #pragma once -#include "mfem.hpp" +#include #include "Types.h" - namespace maxwell { class Probe { @@ -24,11 +23,10 @@ class ExporterProbe : public Probe { class PointsProbe : public Probe { public: - PointsProbe(const FieldType&, const Direction&, std::vector>& integPoints); const FieldType& getFieldType() const { return fieldToExtract_; } const Direction& getDirection() const { return directionToExtract_; } - DenseMatrix& getIntegPointMat() { return integPointMat_; } + mfem::DenseMatrix& getIntegPointMat() { return integPointMat_; } FieldMovie& getFieldMovie() { return fieldMovie_; } const FieldMovie& getConstFieldMovie() const { return fieldMovie_; } @@ -36,13 +34,12 @@ class PointsProbe : public Probe { FieldType fieldToExtract_; Direction directionToExtract_; - DenseMatrix integPointMat_; + mfem::DenseMatrix integPointMat_; FieldMovie fieldMovie_; const bool verifyEntryVectorsSameSize(std::vector>& points) const; const void verifyEntrySubvectorsNotEmpty(std::vector>& points) const; const void buildIntegPointMat(std::vector>& points); - }; class Probes { diff --git a/src/maxwell/Solver.h b/src/maxwell/Solver.h index 607c22ae..2176c837 100644 --- a/src/maxwell/Solver.h +++ b/src/maxwell/Solver.h @@ -1,19 +1,20 @@ #pragma once -#include "mfem.hpp" +#include #include "Material.h" #include "FiniteElementEvolution.h" -#include "Types.h" -#include "Model.h" #include "Probes.h" -#include "Sources.h" -#include +#include "Types.h" namespace maxwell { class Solver { public: - + using Vector = mfem::Vector; + using Position = Vector; + using GridFunction = mfem::GridFunction; + using IntegrationPoint = mfem::IntegrationPoint; + using ODESolver = mfem::ODESolver; using IntegrationPointsSet = std::vector>; struct Options { @@ -29,7 +30,6 @@ class Solver { const PointsProbe& getPointsProbe(const std::size_t probe) { return probes_.getPointsProbes().at(probe); } const mfem::Mesh& getMesh() const { return mesh_; } - const mfem::Mesh& getConstMesh() const { return mesh_; } const FiniteElementEvolution& getFEEvol() const { return *maxwellEvol_; } void run(); @@ -56,21 +56,23 @@ class Solver { std::array E_, H_; - std::vector> elemIds_; + std::vector> elemIds_; std::vector integPointSet_; double timeRecord_; std::vector fieldRecord_; std::unique_ptr pd_; - socketstream sout_; + mfem::socketstream sout_; void checkOptionsAreValid(const Options&); void Solver::initializeSources(); - const std::pair, Array> buildElemAndIntegrationPointArrays(DenseMatrix& physPoints) const; - const IntegrationPointsSet buildIntegrationPointsSet(const Array& ipArray) const; + const std::pair, mfem::Array> + buildElemAndIntegrationPointArrays(mfem::DenseMatrix& physPoints) const; + const IntegrationPointsSet + buildIntegrationPointsSet(const mfem::Array& ipArray) const; const std::vector saveFieldAtPointsForAllProbes(); void initializeParaviewData(); diff --git a/src/maxwell/Sources.cpp b/src/maxwell/Sources.cpp index abea0139..5b97204b 100644 --- a/src/maxwell/Sources.cpp +++ b/src/maxwell/Sources.cpp @@ -1,10 +1,9 @@ #include "Sources.h" #include - namespace maxwell { - +using namespace mfem; Source::Source( Model& model, diff --git a/src/maxwell/Sources.h b/src/maxwell/Sources.h index 4be7adf9..44f3af09 100644 --- a/src/maxwell/Sources.h +++ b/src/maxwell/Sources.h @@ -1,20 +1,29 @@ #pragma once #include + #include "Types.h" #include "Model.h" namespace maxwell { - class Source { public: - Source(Model& model, const FieldType& ft, const Direction& d, const double spread, const double coeff, - const Vector devFromCenter); - - double evalGaussianFunction3D(const Position& pos) const; - double evalGaussianFunction2D(const Position& pos) const; - double evalGaussianFunction1D(const Position& pos) const; + using Vector = mfem::Vector; + using Position = mfem::Vector; + + Source( + Model& model, + const FieldType& ft, + const Direction& d, + const double spread, + const double coeff, + const Vector devFromCenter + ); + + double evalGaussianFunction3D(const Position&) const; + double evalGaussianFunction2D(const Position&) const; + double evalGaussianFunction1D(const Position&) const; FieldType getFieldType() const { return fieldType_; } Direction getDirection() const { return direction_; } diff --git a/src/maxwell/Types.h b/src/maxwell/Types.h index 4fe00870..26edfe2c 100644 --- a/src/maxwell/Types.h +++ b/src/maxwell/Types.h @@ -4,19 +4,13 @@ #include #include -#include "mfem.hpp" - namespace maxwell { -using namespace mfem; - using Time = double; using CVec3 = std::array; using FieldFrame = std::vector; using FieldMovie = std::map; -using Position = mfem::Vector; - enum FieldType { E, H diff --git a/src/maxwell/BilinearIntegrators.cpp b/src/maxwell/mfemExtension/BilinearIntegrators.cpp similarity index 99% rename from src/maxwell/BilinearIntegrators.cpp rename to src/maxwell/mfemExtension/BilinearIntegrators.cpp index ac9f0b96..66d13eed 100644 --- a/src/maxwell/BilinearIntegrators.cpp +++ b/src/maxwell/mfemExtension/BilinearIntegrators.cpp @@ -1,6 +1,7 @@ #include "BilinearIntegrators.h" namespace maxwell { +namespace mfemExtension { const IntegrationRule* MaxwellDGTraceJumpIntegrator::setIntegrationRule( const FiniteElement& el1, @@ -363,5 +364,5 @@ void HesthavenDerivativeIntegrator::AssembleElementMatrix2( } - +} diff --git a/src/maxwell/BilinearIntegrators.h b/src/maxwell/mfemExtension/BilinearIntegrators.h similarity index 93% rename from src/maxwell/BilinearIntegrators.h rename to src/maxwell/mfemExtension/BilinearIntegrators.h index b94a287a..1a325f83 100644 --- a/src/maxwell/BilinearIntegrators.h +++ b/src/maxwell/mfemExtension/BilinearIntegrators.h @@ -1,16 +1,18 @@ -#ifndef _HEADER_MAXWELLDGTRACEINTEGRATOR -#define _HEADER_MAXWELLDGTRACEINTEGRATOR +#pragma once + +#include -#include "mfem.hpp" #include "../../../general/forall.hpp" -#include "Types.h" +#include "../Types.h" -namespace maxwell { +namespace maxwell{ +namespace mfemExtension { using namespace mfem; +using DisForm = maxwell::DisForm; +using Direction = maxwell::Direction; -class MaxwellDGTraceIntegrator : public BilinearFormIntegrator -{ +class MaxwellDGTraceIntegrator : public mfem::BilinearFormIntegrator { public: //When explicitly undeclared, rho = 1.0; @@ -126,8 +128,6 @@ class HesthavenDerivativeIntegrator : public BilinearFormIntegrator ElementTransformation& Trans, DenseMatrix& elmat); }; -} - - -#endif +} +} \ No newline at end of file diff --git a/test/MFEMHesthavenComparison/TestMfemHesthaven1D.cpp b/test/MFEMHesthavenComparison/TestMfemHesthaven1D.cpp index ed573743..dbcd9b51 100644 --- a/test/MFEMHesthavenComparison/TestMfemHesthaven1D.cpp +++ b/test/MFEMHesthavenComparison/TestMfemHesthaven1D.cpp @@ -1,7 +1,9 @@ #include #include "TestMfemHesthavenFunctions.h" -#include "TestGlobalFunctions.h" +#include "GlobalFunctions.h" + +using namespace mfem; class MFEMHesthaven1D : public ::testing::Test { protected: diff --git a/test/MFEMHesthavenComparison/TestMfemHesthaven3D.cpp b/test/MFEMHesthavenComparison/TestMfemHesthaven3D.cpp index fe06416f..706b74b5 100644 --- a/test/MFEMHesthavenComparison/TestMfemHesthaven3D.cpp +++ b/test/MFEMHesthavenComparison/TestMfemHesthaven3D.cpp @@ -1,7 +1,7 @@ #include #include "TestMfemHesthavenFunctions.h" -#include "TestGlobalFunctions.h" +#include "GlobalFunctions.h" using namespace mfem; diff --git a/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.cpp b/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.cpp index d78a2582..c610ef72 100644 --- a/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.cpp +++ b/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.cpp @@ -1,10 +1,12 @@ #include +#include "maxwell/mfemExtension/BilinearIntegrators.h" + #include "TestMfemHesthavenFunctions.h" -#include "TestGlobalFunctions.h" -#include "mfem.hpp" +#include "GlobalFunctions.h" using namespace mfem; +using namespace maxwell::mfemExtension; Eigen::MatrixXd buildExpectedAverageDenseMatrix1D( const int order, @@ -75,7 +77,7 @@ Eigen::MatrixXd buildMaxwellDGTrace1DEigen( { BilinearForm DGmat(&fes); std::vector n{ VectorConstantCoefficient(Vector({1.0})) }; - DGmat.AddInteriorFaceIntegrator(new maxwell::MaxwellDGTraceJumpIntegrator(dir, beta)); + DGmat.AddInteriorFaceIntegrator(new MaxwellDGTraceJumpIntegrator(dir, beta)); DGmat.Assemble(); DGmat.Finalize(); diff --git a/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.h b/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.h index 54727d48..7d17156f 100644 --- a/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.h +++ b/test/MFEMHesthavenComparison/TestMfemHesthavenFunctions.h @@ -1,14 +1,17 @@ #pragma once -#include "mfem.hpp" +#include #include "maxwell/Types.h" -#include "maxwell/BilinearIntegrators.h" #include #include Eigen::MatrixXd buildExpectedAverageDenseMatrix1D(const int order,const int elements); Eigen::MatrixXd buildExpectedJumpDenseMatrix1D(const int order, const int elements); -Eigen::MatrixXd buildDGTrace1DEigen(FiniteElementSpace& fes, maxwell::FluxCoefficient ab); -Eigen::MatrixXd buildMaxwellDGTrace1DEigen(FiniteElementSpace& fes, const std::vector& dir, const double beta); + +Eigen::MatrixXd buildDGTrace1DEigen( + mfem::FiniteElementSpace& fes, maxwell::FluxCoefficient ab); +Eigen::MatrixXd buildMaxwellDGTrace1DEigen( + mfem::FiniteElementSpace& fes, const std::vector& dir, const double beta); + Eigen::MatrixXd build3DOneElementDMatrix(); \ No newline at end of file diff --git a/test/MFEMHesthavenComparison/TestMfemHesthavenTrace1D.cpp b/test/MFEMHesthavenComparison/TestMfemHesthavenTrace1D.cpp index 84438d33..78aa8136 100644 --- a/test/MFEMHesthavenComparison/TestMfemHesthavenTrace1D.cpp +++ b/test/MFEMHesthavenComparison/TestMfemHesthavenTrace1D.cpp @@ -1,9 +1,10 @@ #include #include "TestMfemHesthavenFunctions.h" -#include "TestGlobalFunctions.h" +#include "GlobalFunctions.h" using namespace maxwell; +using namespace mfem; class MFEMHesthaven1DTrace : public ::testing::Test { protected: diff --git a/test/helpers/AnalyticalFunctions1D.h b/test/helpers/AnalyticalFunctions1D.h new file mode 100644 index 00000000..58cd73cd --- /dev/null +++ b/test/helpers/AnalyticalFunctions1D.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +using Interval = std::pair; + +namespace AnalyticalFunctions1D { + mfem::Vector meshBoundingBoxMin, meshBoundingBoxMax; + + const double PI = atan(1.0) * 4; + + double gaussianFunction(const mfem::Vector pos) + { + double normalizedPos; + double center = (meshBoundingBoxMin[0] + meshBoundingBoxMax[0]) * 0.5; + normalizedPos = 2.0 * (pos[0] - center) / + ((meshBoundingBoxMax[0] - meshBoundingBoxMin[0])); + + return exp(-20. * pow(normalizedPos, 2)); + } + + double gaussianFunctionHalfWidth(const mfem::Vector pos) + { + double normalizedPos; + double center = (meshBoundingBoxMin[0] + meshBoundingBoxMax[0]) * 0.5; + normalizedPos = 4.0 * (pos[0] - center / 2) / + ((meshBoundingBoxMax[0] - meshBoundingBoxMin[0])); + + return exp(-20. * pow(normalizedPos, 2)); + } +} diff --git a/test/helpers/CMakeLists.txt b/test/helpers/CMakeLists.txt index 2442cb34..c24b5f7d 100644 --- a/test/helpers/CMakeLists.txt +++ b/test/helpers/CMakeLists.txt @@ -6,8 +6,8 @@ find_package(mfem CONFIG REQUIRED) include_directories(${MFEM_INCLUDE_DIRS}) add_library(testHelpers - "TestGlobalFunctions.cpp" "TestGlobalFunctions.h" -) + "GlobalFunctions.cpp" "GlobalFunctions.h" + "AnalyticalFunctions1D.h") target_link_libraries(testHelpers Eigen3::Eigen) diff --git a/test/helpers/TestGlobalFunctions.cpp b/test/helpers/GlobalFunctions.cpp similarity index 95% rename from test/helpers/TestGlobalFunctions.cpp rename to test/helpers/GlobalFunctions.cpp index 16ad5c92..61103f13 100644 --- a/test/helpers/TestGlobalFunctions.cpp +++ b/test/helpers/GlobalFunctions.cpp @@ -1,10 +1,11 @@ -#include "TestGlobalFunctions.h" +#include "GlobalFunctions.h" -#include "maxwell/BilinearIntegrators.h" +#include "maxwell/mfemExtension/BilinearIntegrators.h" #include "maxwell/Model.h" -using namespace mfem; using namespace maxwell; +using namespace mfem; +using namespace mfemExtension; std::unique_ptr toUnique(DenseMatrix* matPtr) { diff --git a/test/helpers/TestGlobalFunctions.h b/test/helpers/GlobalFunctions.h similarity index 93% rename from test/helpers/TestGlobalFunctions.h rename to test/helpers/GlobalFunctions.h index cc98bf3a..3e6c3172 100644 --- a/test/helpers/TestGlobalFunctions.h +++ b/test/helpers/GlobalFunctions.h @@ -1,6 +1,8 @@ +#pragma once + #include -#include "mfem.hpp" +#include #include "maxwell/Types.h" std::unique_ptr toUnique(mfem::DenseMatrix*); diff --git a/test/maxwell/CMakeLists.txt b/test/maxwell/CMakeLists.txt index d7b2a1b8..9f0ae17d 100644 --- a/test/maxwell/CMakeLists.txt +++ b/test/maxwell/CMakeLists.txt @@ -12,7 +12,7 @@ include_directories( ) add_executable(maxwell_tests - "TestSolver.cpp" + "TestSolver1D.cpp" "TestBilinearIntegrators.cpp" "TestMaterial.cpp" "TestProbes.cpp" diff --git a/test/maxwell/TestBilinearIntegrators.cpp b/test/maxwell/TestBilinearIntegrators.cpp index b0f6a4d8..5516d63d 100644 --- a/test/maxwell/TestBilinearIntegrators.cpp +++ b/test/maxwell/TestBilinearIntegrators.cpp @@ -1,7 +1,7 @@ #include "gtest/gtest.h" #include "maxwell/Solver.h" -#include "maxwell/BilinearIntegrators.h" +#include "maxwell/mfemExtension/BilinearIntegrators.h" using namespace maxwell; diff --git a/test/maxwell/TestMFEMFunctionality.cpp b/test/maxwell/TestMFEMFunctionality.cpp index 6e552bbf..6c8b9919 100644 --- a/test/maxwell/TestMFEMFunctionality.cpp +++ b/test/maxwell/TestMFEMFunctionality.cpp @@ -1,16 +1,15 @@ -#pragma once - #include "gtest/gtest.h" -#include "mfem.hpp" -#include "../src/maxwell/BilinearIntegrators.h" -#include "../src/maxwell/Types.h" #include #include #include #include + +#include "maxwell/mfemExtension/BilinearIntegrators.h" +#include "maxwell/Types.h" #include + using namespace mfem; namespace HelperFunctions { diff --git a/test/maxwell/TestMaterial.cpp b/test/maxwell/TestMaterial.cpp index 84e4d180..c41c8b0b 100644 --- a/test/maxwell/TestMaterial.cpp +++ b/test/maxwell/TestMaterial.cpp @@ -5,9 +5,9 @@ using namespace maxwell; -class TestMaxwellMaterial : public ::testing::Test { +class TestMaterial : public ::testing::Test { }; -TEST_F(TestMaxwellMaterial, checkImpedanceAndConductance) +TEST_F(TestMaterial, checkImpedanceAndConductance) { Material mat1(1.0, 2.0); Material mat2(100.0, 1.0); @@ -17,14 +17,12 @@ TEST_F(TestMaxwellMaterial, checkImpedanceAndConductance) EXPECT_EQ(sqrt( 2.0 / 1.0), mat1.getImpedance()); EXPECT_EQ(sqrt( 1.0 / 100.0), mat2.getImpedance()); EXPECT_EQ(sqrt( 20.0 / 10.0), mat3.getImpedance()); - EXPECT_EQ(sqrt( 1.0 / 2.0), mat1.getConductance()); - EXPECT_EQ(sqrt(100.0 / 1.0), mat2.getConductance()); - EXPECT_EQ(sqrt( 10.0 / 20.0), mat3.getConductance()); - - + EXPECT_EQ(sqrt( 1.0 / 2.0), mat1.getAdmitance()); + EXPECT_EQ(sqrt(100.0 / 1.0), mat2.getAdmitance()); + EXPECT_EQ(sqrt( 10.0 / 20.0), mat3.getAdmitance()); } -TEST_F(TestMaxwellMaterial, invalidEpsOrMu) +TEST_F(TestMaterial, invalidEpsOrMu) { EXPECT_ANY_THROW(Material( 0.5, 1.0)); EXPECT_ANY_THROW(Material( 1.0, 0.5)); diff --git a/test/maxwell/TestProbes.cpp b/test/maxwell/TestProbes.cpp index 8a49a408..4edea300 100644 --- a/test/maxwell/TestProbes.cpp +++ b/test/maxwell/TestProbes.cpp @@ -1,14 +1,14 @@ #include "gtest/gtest.h" - #include "maxwell/Probes.h" using namespace maxwell; +using mfem::DenseMatrix; -class TestMaxwellProbes : public ::testing::Test { +class TestProbes : public ::testing::Test { }; -TEST_F(TestMaxwellProbes, integPointConvChecker_1D) +TEST_F(TestProbes, integPointConvChecker_1D) { Probes probes; auto pointVec = std::vector>({ {0.0}, { 0.5 }, { 1.0 } }); @@ -25,7 +25,7 @@ TEST_F(TestMaxwellProbes, integPointConvChecker_1D) } } } -TEST_F(TestMaxwellProbes, integPointDiffDimsVector) +TEST_F(TestProbes, integPointDiffDimsVector) { Probes probes; auto pointVec = std::vector>({ {0.0, 0.5}, {0.5}, {1.0, 0.5, 1.0} }); @@ -33,14 +33,14 @@ TEST_F(TestMaxwellProbes, integPointDiffDimsVector) } -TEST_F(TestMaxwellProbes, integPointEmptySubvectors) +TEST_F(TestProbes, integPointEmptySubvectors) { Probes probes; auto pointVec = std::vector>({ {},{} }); ASSERT_ANY_THROW(probes.addPointsProbeToCollection(PointsProbe(E, X, pointVec))); } -TEST_F(TestMaxwellProbes, integPointOneSubvector) +TEST_F(TestProbes, integPointOneSubvector) { Probes probes; auto pointVec = std::vector>({ {0.5} }); diff --git a/test/maxwell/TestSolver.cpp b/test/maxwell/TestSolver1D.cpp similarity index 91% rename from test/maxwell/TestSolver.cpp rename to test/maxwell/TestSolver1D.cpp index c2120601..e082a916 100644 --- a/test/maxwell/TestSolver.cpp +++ b/test/maxwell/TestSolver1D.cpp @@ -1,98 +1,16 @@ #include "gtest/gtest.h" -#include +#include "AnalyticalFunctions1D.h" #include "maxwell/Solver.h" -#include "TestGlobalFunctions.h" - -using namespace maxwell; +#include "GlobalFunctions.h" using Interval = std::pair; -namespace AnalyticalFunctions1D { - mfem::Vector meshBoundingBoxMin, meshBoundingBoxMax; - - const double PI = atan(1.0) * 4; - - double gaussianFunction(const mfem::Vector pos) - { - double normalizedPos; - double center = (meshBoundingBoxMin[0] + meshBoundingBoxMax[0]) * 0.5; - normalizedPos = 2.0 * (pos[0] - center) / - ((meshBoundingBoxMax[0] - meshBoundingBoxMin[0])); - - return exp(-20. * pow(normalizedPos, 2)); - } - - double gaussianFunctionHalfWidth(const mfem::Vector pos) - { - double normalizedPos; - double center = (meshBoundingBoxMin[0] + meshBoundingBoxMax[0]) * 0.5; - normalizedPos = 4.0 * (pos[0] - center/2) / - ((meshBoundingBoxMax[0] - meshBoundingBoxMin[0])); - - return exp(-20. * pow(normalizedPos, 2)); - } -} - -namespace HelperFunctions { - - void setAttributeIntervalMesh1D( - const std::map& attToInterval, - Mesh& mesh) - { - for (auto const& kv : attToInterval) { - DenseMatrix changeAttMat(1, 2); - changeAttMat.Elem(0, 0) = kv.second.first; - changeAttMat.Elem(0, 1) = kv.second.second; - Array elemID; - Array integPoint; - mesh.FindPoints(changeAttMat, elemID, integPoint); - - if (elemID.begin() > elemID.end()) { - throw std::exception("Lower Index bigger than Higher Index."); - } - if (elemID[1] > mesh.GetNE()) { - throw std::exception("Declared element index bigger than Mesh Number of Elements."); - } - for (int i = elemID[0]; i <= elemID[1]; i++) { - mesh.SetAttribute((int) i, (int) kv.first); - } - } - } - - std::vector mapQuadElementTopLeftVertex( - const mfem::Mesh& mesh) - { - std::vector res; - for (int i = 0; i < mesh.GetNE(); i++) { - mfem::Array meshArrayElement; - mesh.GetElementVertices(i, meshArrayElement); - res.push_back(meshArrayElement[0]); - } - - return res; - } - - std::map::const_iterator findTimeId( - const std::map& timeMap, - const Time& timeToFind, - const double tolerance) - { - for (auto it = timeMap.begin(); it != timeMap.end(); it++) { - const Time& time = it->first; - if (abs(time - timeToFind) < tolerance) { - return it; - } - } - return timeMap.end(); - } - -} - using namespace AnalyticalFunctions1D; -using namespace HelperFunctions; +using namespace maxwell; +using namespace mfem; -class TestMaxwellSolver : public ::testing::Test { +class TestSolver1D : public ::testing::Test { protected: Model buildOneDimOneMatModel( @@ -157,7 +75,7 @@ class TestMaxwellSolver : public ::testing::Test { const Time& timeToFind, const int denseMatPointByOrder) { - auto itpos = HelperFunctions::findTimeId(probe.getConstFieldMovie(), timeToFind, 1e-6); + auto itpos = findTimeId(probe.getConstFieldMovie(), timeToFind, 1e-6); if (itpos == probe.getConstFieldMovie().end()) { throw std::exception("Time value has not been found within the specified tolerance."); } @@ -166,8 +84,60 @@ class TestMaxwellSolver : public ::testing::Test { return FieldValueForTimeAtPoint; } + void setAttributeIntervalMesh1D( + const std::map& attToInterval, + Mesh& mesh) + { + for (auto const& kv : attToInterval) { + DenseMatrix changeAttMat(1, 2); + changeAttMat.Elem(0, 0) = kv.second.first; + changeAttMat.Elem(0, 1) = kv.second.second; + Array elemID; + Array integPoint; + mesh.FindPoints(changeAttMat, elemID, integPoint); + + if (elemID.begin() > elemID.end()) { + throw std::exception("Lower Index bigger than Higher Index."); + } + if (elemID[1] > mesh.GetNE()) { + throw std::exception("Declared element index bigger than Mesh Number of Elements."); + } + for (int i = elemID[0]; i <= elemID[1]; i++) { + mesh.SetAttribute((int)i, (int)kv.first); + } + } + } + + std::vector mapQuadElementTopLeftVertex( + const mfem::Mesh& mesh) + { + std::vector res; + for (int i = 0; i < mesh.GetNE(); i++) { + mfem::Array meshArrayElement; + mesh.GetElementVertices(i, meshArrayElement); + res.push_back(meshArrayElement[0]); + } + + return res; + } + + std::map::const_iterator findTimeId( + const std::map& timeMap, + const Time& timeToFind, + const double tolerance) + { + for (auto it = timeMap.begin(); it != timeMap.end(); it++) { + const Time& time = it->first; + if (abs(time - timeToFind) < tolerance) { + return it; + } + } + return timeMap.end(); + } + + }; -TEST_F(TestMaxwellSolver, oneDimensional_centered) +TEST_F(TestSolver1D, oneDimensional_centered) { /*The purpose of this test is to verify the functionality of the Maxwell Solver when using a centered type flux. @@ -199,7 +169,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_centered) EXPECT_NEAR(0.0, error, 2e-3); } -TEST_F(TestMaxwellSolver, oneDimensional_centered_energy) +TEST_F(TestSolver1D, oneDimensional_centered_energy) { /*The purpose of this test is to verify the functionality of the Maxwell Solver when using a centered type flux. @@ -233,7 +203,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_centered_energy) } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EX) +TEST_F(TestSolver1D, oneDimensional_upwind_PEC_EX) { Model model = buildOneDimOneMatModel(); @@ -252,7 +222,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EX) EXPECT_NEAR(0.0, error, 2e-3); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EY) +TEST_F(TestSolver1D, oneDimensional_upwind_PEC_EY) { Model model = buildOneDimOneMatModel(); @@ -281,7 +251,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EY) EXPECT_NE( eOld.Max(), getBoundaryFieldValueAtTime(solver.getPointsProbe(0), 1.5, 1)); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EZ) +TEST_F(TestSolver1D, oneDimensional_upwind_PEC_EZ) { Model model = buildOneDimOneMatModel(); @@ -310,7 +280,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PEC_EZ) } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HX) +TEST_F(TestSolver1D, oneDimensional_upwind_PMC_HX) { Model model = buildOneDimOneMatModel(51, BdrCond::PMC, BdrCond::PMC); @@ -328,7 +298,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HX) EXPECT_NEAR(0.0, error, 2e-3); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HY) +TEST_F(TestSolver1D, oneDimensional_upwind_PMC_HY) { Model model = buildOneDimOneMatModel(51, BdrCond::PMC, BdrCond::PMC); @@ -358,7 +328,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HY) EXPECT_NE(hOld.Max(), getBoundaryFieldValueAtTime(solver.getPointsProbe(0), 1.5, 1)); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HZ) +TEST_F(TestSolver1D, oneDimensional_upwind_PMC_HZ) { Model model = buildOneDimOneMatModel(51, BdrCond::PMC, BdrCond::PMC); @@ -388,7 +358,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_PMC_HZ) } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EX) +TEST_F(TestSolver1D, oneDimensional_upwind_SMA_EX) { Model model = buildOneDimOneMatModel(51, BdrCond::SMA, BdrCond::SMA); @@ -406,7 +376,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EX) EXPECT_NEAR(0.0, error, 2e-3); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EY) +TEST_F(TestSolver1D, oneDimensional_upwind_SMA_EY) { Model model = buildOneDimOneMatModel(51, BdrCond::SMA, BdrCond::SMA); @@ -443,7 +413,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EY) EXPECT_NEAR(0.0, getBoundaryFieldValueAtTime(solver.getPointsProbe(2), 1.0, 2), 2e-3); } -TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EZ) +TEST_F(TestSolver1D, oneDimensional_upwind_SMA_EZ) { Model model = buildOneDimOneMatModel(51, BdrCond::SMA, BdrCond::SMA); @@ -470,7 +440,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_upwind_SMA_EZ) } -TEST_F(TestMaxwellSolver, oneDimensional_strong_flux_PEC_EY) +TEST_F(TestSolver1D, oneDimensional_strong_flux_PEC_EY) { Mesh mesh = Mesh::MakeCartesian1D(51); Model model = Model(mesh, AttributeToMaterial(), AttributeToBoundary()); @@ -507,7 +477,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_strong_flux_PEC_EY) } -TEST_F(TestMaxwellSolver, oneDimensional_weak_strong_flux_comparison) +TEST_F(TestSolver1D, oneDimensional_weak_strong_flux_comparison) { Model model = buildOneDimOneMatModel(); @@ -544,7 +514,7 @@ TEST_F(TestMaxwellSolver, oneDimensional_weak_strong_flux_comparison) } -TEST_F(TestMaxwellSolver, twoSourceWaveTravelsToTheRight_SMA) +TEST_F(TestSolver1D, twoSourceWaveTravelsToTheRight_SMA) { Model model = buildOneDimOneMatModel(51, BdrCond::SMA, BdrCond::SMA); @@ -569,7 +539,7 @@ TEST_F(TestMaxwellSolver, twoSourceWaveTravelsToTheRight_SMA) 2e-3); } -TEST_F(TestMaxwellSolver, twoSourceWaveTwoMaterialsReflection_SMA_PEC) +TEST_F(TestSolver1D, twoSourceWaveTwoMaterialsReflection_SMA_PEC) { Mesh mesh1D = Mesh::MakeCartesian1D(101); setAttributeIntervalMesh1D({ { 2, std::make_pair(0.76, 1.0) } }, mesh1D); @@ -619,7 +589,7 @@ TEST_F(TestMaxwellSolver, twoSourceWaveTwoMaterialsReflection_SMA_PEC) EXPECT_NEAR(0.0, getBoundaryFieldValueAtTime(solver.getPointsProbe(0), 1.30, 1), 2e-3); } -TEST_F(TestMaxwellSolver, twoDimensional_Periodic) //TODO ADD ENERGY CHECK +TEST_F(TestSolver1D, twoDimensional_Periodic) //TODO ADD ENERGY CHECK { Mesh mesh2D = Mesh::MakeCartesian2D(21, 3, Element::Type::QUADRILATERAL); Vector periodic({ 0.0, 1.0 }); @@ -642,7 +612,7 @@ TEST_F(TestMaxwellSolver, twoDimensional_Periodic) //TODO ADD ENERGY CHECK } -TEST_F(TestMaxwellSolver, DISABLED_twoDimensional_Periodic_strong) //TODO ADD ENERGY CHECK +TEST_F(TestSolver1D, DISABLED_twoDimensional_Periodic_strong) //TODO ADD ENERGY CHECK { Mesh mesh2D = Mesh::MakeCartesian2D(21, 3, Element::Type::QUADRILATERAL); Vector periodic({ 0.0, 1.0 }); @@ -672,7 +642,7 @@ TEST_F(TestMaxwellSolver, DISABLED_twoDimensional_Periodic_strong) //TODO ADD EN solver.run(); } -TEST_F(TestMaxwellSolver, twoDimensional_centered_NC_MESH) //TODO ADD ENERGY CHECK +TEST_F(TestSolver1D, DISABLED_twoDimensional_centered_NC_MESH) //TODO ADD ENERGY CHECK { /*The purpose of this test is to verify the functionality of the Maxwell Solver when using a centered type flux. A non-conforming mesh is loaded to test MFEM functionalities on the code. @@ -710,7 +680,7 @@ TEST_F(TestMaxwellSolver, twoDimensional_centered_NC_MESH) //TODO ADD ENERGY CHE EXPECT_GT(eOld.Max(), eNew.Max()); } -TEST_F(TestMaxwellSolver, twoDimensional_centered_AMR_MESH) +TEST_F(TestSolver1D, twoDimensional_centered_AMR_MESH) { /*The purpose of this test is to verify the functionality of the Maxwell Solver when using a centered type flux. A non-conforming mesh is loaded to test MFEM functionalities on the code. @@ -745,7 +715,7 @@ TEST_F(TestMaxwellSolver, twoDimensional_centered_AMR_MESH) EXPECT_GT(eOld.Max(), eNew.Max()); } -TEST_F(TestMaxwellSolver, DISABLED_threeDimensional) +TEST_F(TestSolver1D, DISABLED_threeDimensional) { Mesh mesh = Mesh::MakeCartesian3D(1, 1, 1, Element::Type::HEXAHEDRON); Model model = Model(mesh, AttributeToMaterial(), AttributeToBoundary()); @@ -765,7 +735,7 @@ TEST_F(TestMaxwellSolver, DISABLED_threeDimensional) solver.run(); } -TEST_F(TestMaxwellSolver, checkFluxOperator_O2) +TEST_F(TestSolver1D, checkFluxOperator_O2) { Model model = buildOneDimOneMatModel(3); diff --git a/test/maxwell/TestSolver2D.cpp b/test/maxwell/TestSolver2D.cpp index f7ea8b9a..9f35e0e7 100644 --- a/test/maxwell/TestSolver2D.cpp +++ b/test/maxwell/TestSolver2D.cpp @@ -1,9 +1,7 @@ #include "gtest/gtest.h" #include -#include "Solver2D.h" - -using namespace Maxwell; +using namespace maxwell; namespace AnalyticalFunctions2D { mfem::Vector meshBoundingBoxMin, meshBoundingBoxMax; diff --git a/test/maxwell/TestSources.cpp b/test/maxwell/TestSources.cpp index 5defd7f7..affe67f4 100644 --- a/test/maxwell/TestSources.cpp +++ b/test/maxwell/TestSources.cpp @@ -3,8 +3,9 @@ #include "maxwell/Sources.h" using namespace maxwell; +using namespace mfem; -class TestMaxwellSources : public ::testing::Test { +class TestSources : public ::testing::Test { protected: AttributeToBoundary buildAttrToBdrMap1D(const BdrCond& bdrL, const BdrCond& bdrR) @@ -25,27 +26,27 @@ class TestMaxwellSources : public ::testing::Test { }; -TEST_F(TestMaxwellSources, negSpreadInput) +TEST_F(TestSources, negSpreadInput) { ASSERT_ANY_THROW(Source(buildOneDimOneMatModel(), E, X, -2.0, 1.0, Vector({0.5}))); } -TEST_F(TestMaxwellSources, negCoeffInput) +TEST_F(TestSources, negCoeffInput) { ASSERT_ANY_THROW(Source(buildOneDimOneMatModel(), E, X, 2.0, -1.0, Vector({0.5}))); } -TEST_F(TestMaxwellSources, emptyDevInput) +TEST_F(TestSources, emptyDevInput) { ASSERT_ANY_THROW(Source(buildOneDimOneMatModel(), E, X, 2.0, 1.0, Vector({ }))); } -TEST_F(TestMaxwellSources, outOfBoundsDevInput1D) +TEST_F(TestSources, outOfBoundsDevInput1D) { ASSERT_ANY_THROW(Source(buildOneDimOneMatModel(), E, X, 2.0, 1.0, Vector({ 20.0 }))); } -TEST_F(TestMaxwellSources, outOfBoundsDevInput2D) +TEST_F(TestSources, outOfBoundsDevInput2D) { Model model = Model( Mesh::MakeCartesian2D(5, 5, Element::Type::QUADRILATERAL),