From 9a7b843531aa6530d887af669b1039c304f5055b Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Mon, 20 May 2024 13:53:50 +0000 Subject: [PATCH 01/13] Added Reset method to FluxMonitorAux. --- src/auxsolvers/flux_monitor_aux.cpp | 7 +++++++ src/auxsolvers/flux_monitor_aux.hpp | 2 ++ 2 files changed, 9 insertions(+) diff --git a/src/auxsolvers/flux_monitor_aux.cpp b/src/auxsolvers/flux_monitor_aux.cpp index 70ddae701..f4647497e 100644 --- a/src/auxsolvers/flux_monitor_aux.cpp +++ b/src/auxsolvers/flux_monitor_aux.cpp @@ -89,6 +89,13 @@ FluxMonitorAux::Init(const hephaestus::GridFunctions & gridfunctions, } } +void +FluxMonitorAux::Reset() +{ + _times.DeleteAll(); + _fluxes.DeleteAll(); +} + void FluxMonitorAux::Solve(double t) { diff --git a/src/auxsolvers/flux_monitor_aux.hpp b/src/auxsolvers/flux_monitor_aux.hpp index d2d52fda6..dd76c9ca3 100644 --- a/src/auxsolvers/flux_monitor_aux.hpp +++ b/src/auxsolvers/flux_monitor_aux.hpp @@ -23,6 +23,8 @@ class FluxMonitorAux : public AuxSolver void Init(const hephaestus::GridFunctions & gridfunctions, hephaestus::Coefficients & coefficients) override; + void Reset(); + void Update() override {} void Solve(double t = 0.0) override; From 135763d3ffea20cbe4b8be5cc791a3c22b228290 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Mon, 20 May 2024 13:53:50 +0000 Subject: [PATCH 02/13] Added additional mesh update test case to test_team4_Hform which runs problem for different refinement levels. --- test/integration/test_team4_hform.cpp | 109 ++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 8c226d203..3d088d875 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -182,3 +182,112 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") REQUIRE(peak_current_time < 0.012); REQUIRE(peak_current_time > 0.01); } + +/// Test case for checking "Updates" work as expected following a mesh refinement. +TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun]") +{ + // Create Formulation + auto problem_builder = std::make_unique( + "electric_resistivity", "electric_conductivity", "magnetic_permeability", "magnetic_field"); + // Set Mesh + mfem::Mesh mesh((std::string(DATA_DIR) + std::string("./team4_symmetrized.g")).c_str(), 1, 1); + auto pmesh = std::make_shared(MPI_COMM_WORLD, mesh); + + problem_builder->SetMesh(pmesh); + problem_builder->AddFESpace("H1", "H1_3D_P1"); + problem_builder->AddFESpace("HCurl", "ND_3D_P1"); + problem_builder->AddFESpace("HDiv", "RT_3D_P0"); + problem_builder->AddFESpace("Scalar_L2", "L2_3D_P0"); + problem_builder->AddFESpace("Vector_L2", "L2_3D_P0", 3); + problem_builder->AddGridFunction("magnetic_field", "HCurl"); + + problem_builder->AddGridFunction("dmagnetic_potential_dt", "H1"); + problem_builder->AddGridFunction("magnetic_flux_density", "HDiv"); + problem_builder->RegisterMagneticFluxDensityAux("magnetic_flux_density"); + + problem_builder->AddGridFunction("current_density", "HDiv"); + problem_builder->RegisterCurrentDensityAux("current_density"); + + problem_builder->AddGridFunction("electric_field", "HCurl"); + problem_builder->RegisterElectricFieldAux("electric_field"); + + hephaestus::Coefficients coefficients = DefineCoefficients(); + problem_builder->SetCoefficients(coefficients); + + hephaestus::Sources sources = DefineSources(); + problem_builder->SetSources(sources); + + hephaestus::Outputs outputs = DefineOutputs(); + problem_builder->SetOutputs(outputs); + + problem_builder->AddBoundaryCondition("tangential_dhdt_bc", + std::make_shared( + "dmagnetic_field_dt", + mfem::Array({1, 2, 5, 6}), + coefficients._vectors.Get("surface_tangential_dHdt"))); + problem_builder->AddBoundaryCondition( + "magnetic_potential_bc", + std::make_shared( + "dmagnetic_potential_dt", + mfem::Array({1, 2}), + coefficients._scalars.Get("magnetic_potential_time_derivative"))); + + auto fluxmonitor = std::make_shared("current_density", 3); + fluxmonitor->SetPriority(2); + problem_builder->AddPostprocessor("FluxMonitor", fluxmonitor); + + hephaestus::InputParameters solver_options; + solver_options.SetParam("AbsTolerance", float(1.0e-20)); + solver_options.SetParam("Tolerance", float(1.0e-20)); + solver_options.SetParam("MaxIter", (unsigned int)500); + problem_builder->SetSolverOptions(solver_options); + + problem_builder->FinalizeProblem(); + + auto problem = problem_builder->ReturnProblem(); + hephaestus::InputParameters exec_params; + exec_params.SetParam("TimeStep", float(0.001)); + exec_params.SetParam("StartTime", float(0.00)); + exec_params.SetParam("EndTime", float(0.015)); + exec_params.SetParam("VisualisationSteps", int(1)); + exec_params.SetParam("Problem", static_cast(problem.get())); + + hephaestus::logger.set_level(spdlog::level::info); + + const int imax_refinement = 3; + for (int irefinement = 0; irefinement < imax_refinement; irefinement++) + { + // Remove any stored fluxes. + fluxmonitor->Reset(); + + // Reconstruct executioner each time we start. + hephaestus::TransientExecutioner executioner(exec_params); + executioner.Execute(); + + double peak_current = -2 * fluxmonitor->_fluxes.Min(); + double peak_current_time; + for (std::size_t i = 0; i < fluxmonitor->_times.Size(); ++i) + { + if (fluxmonitor->_fluxes[i] == fluxmonitor->_fluxes.Min()) + { + peak_current_time = fluxmonitor->_times[i]; + } + } + + hephaestus::logger.info("Refinement Level: {}, Peak current: {}, Time: {} seconds", + irefinement, + peak_current, + peak_current_time); + + REQUIRE(peak_current > 3.2e3); + REQUIRE(peak_current < 3.6e3); + REQUIRE(peak_current_time < 0.012); + REQUIRE(peak_current_time > 0.01); + + if (irefinement != (imax_refinement - 1)) + { + mesh.UniformRefinement(); + problem->Update(); + } + } +} From f53313b3edd3f5c8671e8dd14ad06be5f701590a Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Fri, 24 May 2024 13:02:34 +0000 Subject: [PATCH 03/13] Fixes issue with test4 where the serial mesh was mistakenly refined rather than the ParMesh. --- test/integration/test_team4_hform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 3d088d875..34cf3d534 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -286,7 +286,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun]") if (irefinement != (imax_refinement - 1)) { - mesh.UniformRefinement(); + pmesh->UniformRefinement(); problem->Update(); } } From 3166048dc1dfe56e4fc2d8a3ea34293a5703c861 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Fri, 24 May 2024 16:06:56 +0000 Subject: [PATCH 04/13] Rebuild a0 solver in ScalarPotentialSource when Apply called. Required for updates to work correctly. Refer to TestTEAM4HFormMeshUpdates test. --- src/sources/scalar_potential_source.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/sources/scalar_potential_source.cpp b/src/sources/scalar_potential_source.cpp index c3aabaae0..7bb61eb9b 100644 --- a/src/sources/scalar_potential_source.cpp +++ b/src/sources/scalar_potential_source.cpp @@ -117,11 +117,8 @@ ScalarPotentialSource::Apply(mfem::ParLinearForm * lf) _a0->FormLinearSystem( poisson_ess_tdof_list, phi_gf, *_b0, *_diffusion_mat, *_p_tdofs, *_b0_tdofs); - if (_a0_solver == nullptr) - { - _a0_solver = std::make_unique(_solver_options, *_diffusion_mat); - } // Solve + _a0_solver = std::make_unique(_solver_options, *_diffusion_mat); _a0_solver->Mult(*_b0_tdofs, *_p_tdofs); // "undo" the static condensation saving result in grid function dP From 53ffaa17336298dff8fd2f0ba581c65273dd9555 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Fri, 24 May 2024 16:18:41 +0000 Subject: [PATCH 05/13] Reduces max refinement level due to time taken to execute problem. --- test/integration/test_team4_hform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 34cf3d534..3d17373dd 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -254,7 +254,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun]") hephaestus::logger.set_level(spdlog::level::info); - const int imax_refinement = 3; + const int imax_refinement = 2; for (int irefinement = 0; irefinement < imax_refinement; irefinement++) { // Remove any stored fluxes. From b73a233dc0a2165197a22eb97013cfb7ce86748d Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 08:25:56 +0000 Subject: [PATCH 06/13] Adds "[!benchmark]" tag to TestTeam4HFormMeshUpdates to ensure it is skipped when running test cases because it is a very heavy test. --- test/integration/test_team4_hform.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 3d17373dd..e89879f19 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -184,7 +184,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") } /// Test case for checking "Updates" work as expected following a mesh refinement. -TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun]") +TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!benchmark]") { // Create Formulation auto problem_builder = std::make_unique( From 195e67c12854f6cec0fbbc196d1bf6f15239c143 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 09:09:36 +0000 Subject: [PATCH 07/13] Adds "ConfigureProblem" method to TestTEAM4HForm to reduce code duplication. --- test/integration/test_team4_hform.cpp | 187 ++++++++++---------------- 1 file changed, 73 insertions(+), 114 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index e89879f19..568b200e3 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -43,6 +43,70 @@ class TestTEAM4HForm dh_dt(2) = 0.0; } + std::unique_ptr ConfigureProblem() + { + // Create Formulation + auto problem_builder = std::make_unique( + "electric_resistivity", "electric_conductivity", "magnetic_permeability", "magnetic_field"); + // Set Mesh + mfem::Mesh mesh((std::string(DATA_DIR) + std::string("./team4_symmetrized.g")).c_str(), 1, 1); + auto pmesh = std::make_shared(MPI_COMM_WORLD, mesh); + + problem_builder->SetMesh(pmesh); + problem_builder->AddFESpace("H1", "H1_3D_P1"); + problem_builder->AddFESpace("HCurl", "ND_3D_P1"); + problem_builder->AddFESpace("HDiv", "RT_3D_P0"); + problem_builder->AddFESpace("Scalar_L2", "L2_3D_P0"); + problem_builder->AddFESpace("Vector_L2", "L2_3D_P0", 3); + problem_builder->AddGridFunction("magnetic_field", "HCurl"); + + problem_builder->AddGridFunction("dmagnetic_potential_dt", "H1"); + problem_builder->AddGridFunction("magnetic_flux_density", "HDiv"); + problem_builder->RegisterMagneticFluxDensityAux("magnetic_flux_density"); + + problem_builder->AddGridFunction("current_density", "HDiv"); + problem_builder->RegisterCurrentDensityAux("current_density"); + + problem_builder->AddGridFunction("electric_field", "HCurl"); + problem_builder->RegisterElectricFieldAux("electric_field"); + + hephaestus::Coefficients coefficients = DefineCoefficients(); + problem_builder->SetCoefficients(coefficients); + + hephaestus::Sources sources = DefineSources(); + problem_builder->SetSources(sources); + + hephaestus::Outputs outputs = DefineOutputs(); + problem_builder->SetOutputs(outputs); + + problem_builder->AddBoundaryCondition( + "tangential_dhdt_bc", + std::make_shared( + "dmagnetic_field_dt", + mfem::Array({1, 2, 5, 6}), + coefficients._vectors.Get("surface_tangential_dHdt"))); + problem_builder->AddBoundaryCondition( + "magnetic_potential_bc", + std::make_shared( + "dmagnetic_potential_dt", + mfem::Array({1, 2}), + coefficients._scalars.Get("magnetic_potential_time_derivative"))); + + auto fluxmonitor = std::make_shared("current_density", 3); + fluxmonitor->SetPriority(2); + problem_builder->AddPostprocessor("FluxMonitor", fluxmonitor); + + hephaestus::InputParameters solver_options; + solver_options.SetParam("AbsTolerance", float(1.0e-20)); + solver_options.SetParam("Tolerance", float(1.0e-20)); + solver_options.SetParam("MaxIter", (unsigned int)500); + problem_builder->SetSolverOptions(solver_options); + + problem_builder->FinalizeProblem(); + + return problem_builder; + } + hephaestus::Coefficients DefineCoefficients() { hephaestus::Subdomain brick("brick", 1); @@ -98,64 +162,12 @@ class TestTEAM4HForm TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") { // Create Formulation - auto problem_builder = std::make_unique( - "electric_resistivity", "electric_conductivity", "magnetic_permeability", "magnetic_field"); - // Set Mesh - mfem::Mesh mesh((std::string(DATA_DIR) + std::string("./team4_symmetrized.g")).c_str(), 1, 1); - auto pmesh = std::make_shared(MPI_COMM_WORLD, mesh); - - problem_builder->SetMesh(pmesh); - problem_builder->AddFESpace("H1", "H1_3D_P1"); - problem_builder->AddFESpace("HCurl", "ND_3D_P1"); - problem_builder->AddFESpace("HDiv", "RT_3D_P0"); - problem_builder->AddFESpace("Scalar_L2", "L2_3D_P0"); - problem_builder->AddFESpace("Vector_L2", "L2_3D_P0", 3); - problem_builder->AddGridFunction("magnetic_field", "HCurl"); - - problem_builder->AddGridFunction("dmagnetic_potential_dt", "H1"); - problem_builder->AddGridFunction("magnetic_flux_density", "HDiv"); - problem_builder->RegisterMagneticFluxDensityAux("magnetic_flux_density"); - - problem_builder->AddGridFunction("current_density", "HDiv"); - problem_builder->RegisterCurrentDensityAux("current_density"); - - problem_builder->AddGridFunction("electric_field", "HCurl"); - problem_builder->RegisterElectricFieldAux("electric_field"); - - hephaestus::Coefficients coefficients = DefineCoefficients(); - problem_builder->SetCoefficients(coefficients); - - hephaestus::Sources sources = DefineSources(); - problem_builder->SetSources(sources); - - hephaestus::Outputs outputs = DefineOutputs(); - problem_builder->SetOutputs(outputs); - - problem_builder->AddBoundaryCondition("tangential_dhdt_bc", - std::make_shared( - "dmagnetic_field_dt", - mfem::Array({1, 2, 5, 6}), - coefficients._vectors.Get("surface_tangential_dHdt"))); - problem_builder->AddBoundaryCondition( - "magnetic_potential_bc", - std::make_shared( - "dmagnetic_potential_dt", - mfem::Array({1, 2}), - coefficients._scalars.Get("magnetic_potential_time_derivative"))); - - auto fluxmonitor = std::make_shared("current_density", 3); - fluxmonitor->SetPriority(2); - problem_builder->AddPostprocessor("FluxMonitor", fluxmonitor); - - hephaestus::InputParameters solver_options; - solver_options.SetParam("AbsTolerance", float(1.0e-20)); - solver_options.SetParam("Tolerance", float(1.0e-20)); - solver_options.SetParam("MaxIter", (unsigned int)500); - problem_builder->SetSolverOptions(solver_options); - - problem_builder->FinalizeProblem(); + auto problem_builder = ConfigureProblem(); auto problem = problem_builder->ReturnProblem(); + + auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); + hephaestus::InputParameters exec_params; exec_params.SetParam("TimeStep", float(0.001)); exec_params.SetParam("StartTime", float(0.00)); @@ -186,65 +198,12 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") /// Test case for checking "Updates" work as expected following a mesh refinement. TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!benchmark]") { - // Create Formulation - auto problem_builder = std::make_unique( - "electric_resistivity", "electric_conductivity", "magnetic_permeability", "magnetic_field"); - // Set Mesh - mfem::Mesh mesh((std::string(DATA_DIR) + std::string("./team4_symmetrized.g")).c_str(), 1, 1); - auto pmesh = std::make_shared(MPI_COMM_WORLD, mesh); - - problem_builder->SetMesh(pmesh); - problem_builder->AddFESpace("H1", "H1_3D_P1"); - problem_builder->AddFESpace("HCurl", "ND_3D_P1"); - problem_builder->AddFESpace("HDiv", "RT_3D_P0"); - problem_builder->AddFESpace("Scalar_L2", "L2_3D_P0"); - problem_builder->AddFESpace("Vector_L2", "L2_3D_P0", 3); - problem_builder->AddGridFunction("magnetic_field", "HCurl"); - - problem_builder->AddGridFunction("dmagnetic_potential_dt", "H1"); - problem_builder->AddGridFunction("magnetic_flux_density", "HDiv"); - problem_builder->RegisterMagneticFluxDensityAux("magnetic_flux_density"); - - problem_builder->AddGridFunction("current_density", "HDiv"); - problem_builder->RegisterCurrentDensityAux("current_density"); - - problem_builder->AddGridFunction("electric_field", "HCurl"); - problem_builder->RegisterElectricFieldAux("electric_field"); - - hephaestus::Coefficients coefficients = DefineCoefficients(); - problem_builder->SetCoefficients(coefficients); - - hephaestus::Sources sources = DefineSources(); - problem_builder->SetSources(sources); - - hephaestus::Outputs outputs = DefineOutputs(); - problem_builder->SetOutputs(outputs); - - problem_builder->AddBoundaryCondition("tangential_dhdt_bc", - std::make_shared( - "dmagnetic_field_dt", - mfem::Array({1, 2, 5, 6}), - coefficients._vectors.Get("surface_tangential_dHdt"))); - problem_builder->AddBoundaryCondition( - "magnetic_potential_bc", - std::make_shared( - "dmagnetic_potential_dt", - mfem::Array({1, 2}), - coefficients._scalars.Get("magnetic_potential_time_derivative"))); - - auto fluxmonitor = std::make_shared("current_density", 3); - fluxmonitor->SetPriority(2); - problem_builder->AddPostprocessor("FluxMonitor", fluxmonitor); - - hephaestus::InputParameters solver_options; - solver_options.SetParam("AbsTolerance", float(1.0e-20)); - solver_options.SetParam("Tolerance", float(1.0e-20)); - solver_options.SetParam("MaxIter", (unsigned int)500); - problem_builder->SetSolverOptions(solver_options); - - problem_builder->FinalizeProblem(); + auto problem_builder = ConfigureProblem(); auto problem = problem_builder->ReturnProblem(); + + auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); + hephaestus::InputParameters exec_params; exec_params.SetParam("TimeStep", float(0.001)); exec_params.SetParam("StartTime", float(0.00)); @@ -286,7 +245,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench if (irefinement != (imax_refinement - 1)) { - pmesh->UniformRefinement(); + problem->_pmesh->UniformRefinement(); problem->Update(); } } From f344c4dea02e5d31b9ca807364dd20d390eec68e Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 09:13:32 +0000 Subject: [PATCH 08/13] Adds DefineExecutionerParameters method. --- test/integration/test_team4_hform.cpp | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 568b200e3..71231584b 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -107,6 +107,19 @@ class TestTEAM4HForm return problem_builder; } + hephaestus::InputParameters DefineExecutionerParameters(hephaestus::TimeDomainProblem & problem) + { + hephaestus::InputParameters exec_params; + + exec_params.SetParam("TimeStep", float(0.001)); + exec_params.SetParam("StartTime", float(0.00)); + exec_params.SetParam("EndTime", float(0.015)); + exec_params.SetParam("VisualisationSteps", int(1)); + exec_params.SetParam("Problem", &problem); + + return exec_params; + } + hephaestus::Coefficients DefineCoefficients() { hephaestus::Subdomain brick("brick", 1); @@ -168,12 +181,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); - hephaestus::InputParameters exec_params; - exec_params.SetParam("TimeStep", float(0.001)); - exec_params.SetParam("StartTime", float(0.00)); - exec_params.SetParam("EndTime", float(0.015)); - exec_params.SetParam("VisualisationSteps", int(1)); - exec_params.SetParam("Problem", static_cast(problem.get())); + hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); auto executioner = std::make_unique(exec_params); @@ -204,12 +212,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); - hephaestus::InputParameters exec_params; - exec_params.SetParam("TimeStep", float(0.001)); - exec_params.SetParam("StartTime", float(0.00)); - exec_params.SetParam("EndTime", float(0.015)); - exec_params.SetParam("VisualisationSteps", int(1)); - exec_params.SetParam("Problem", static_cast(problem.get())); + hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); hephaestus::logger.set_level(spdlog::level::info); From 617ee808f1d5107b04dfe9d23b944e3e96a59261 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 09:44:51 +0000 Subject: [PATCH 09/13] Adds ExtractPeakCurrentAndTime method. --- test/integration/test_team4_hform.cpp | 47 +++++++++++++++------------ 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 71231584b..1ab6fc201 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -170,6 +170,29 @@ class TestTEAM4HForm std::make_shared("Team4ParaView")); return outputs; } + + void ExtractPeakCurrentAndTime(hephaestus::TimeDomainProblem & problem, + double & peak_current, + double & peak_current_time) + { + auto flux_monitor = problem._postprocessors.Get("FluxMonitor"); + + const mfem::real_t min_flux = flux_monitor->_fluxes.Min(); + + peak_current = -2.0 * min_flux; + peak_current_time = 0.0; + + for (int i = 0; i < flux_monitor->_times.Size(); i++) + { + const mfem::real_t flux = flux_monitor->_fluxes[i]; + const mfem::real_t flux_time = flux_monitor->_times[i]; + + if (flux == min_flux) + { + peak_current_time = flux_time; + } + } + } }; TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") @@ -179,23 +202,14 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") auto problem = problem_builder->ReturnProblem(); - auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); - hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); auto executioner = std::make_unique(exec_params); executioner->Execute(); - double peak_current = -2 * fluxmonitor->_fluxes.Min(); - double peak_current_time; - for (std::size_t i = 0; i < fluxmonitor->_times.Size(); ++i) - { - if (fluxmonitor->_fluxes[i] == fluxmonitor->_fluxes.Min()) - { - peak_current_time = fluxmonitor->_times[i]; - } - } + double peak_current, peak_current_time; + ExtractPeakCurrentAndTime(*problem, peak_current, peak_current_time); REQUIRE(peak_current > 3.2e3); REQUIRE(peak_current < 3.6e3); @@ -226,15 +240,8 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench hephaestus::TransientExecutioner executioner(exec_params); executioner.Execute(); - double peak_current = -2 * fluxmonitor->_fluxes.Min(); - double peak_current_time; - for (std::size_t i = 0; i < fluxmonitor->_times.Size(); ++i) - { - if (fluxmonitor->_fluxes[i] == fluxmonitor->_fluxes.Min()) - { - peak_current_time = fluxmonitor->_times[i]; - } - } + double peak_current, peak_current_time; + ExtractPeakCurrentAndTime(*problem, peak_current, peak_current_time); hephaestus::logger.info("Refinement Level: {}, Peak current: {}, Time: {} seconds", irefinement, From 71121968701ed79b0d2e25c22832f1921a569ef4 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 09:59:13 +0000 Subject: [PATCH 10/13] Adds "VerifyPeakCurrentAndTimeWithinTolerances". --- test/integration/test_team4_hform.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 1ab6fc201..7960b05b0 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -193,6 +193,21 @@ class TestTEAM4HForm } } } + + void VerifyPeakCurrentAndTimeWithinTolerances(double & peak_current, double & peak_current_time) + { + const double min_peak_current = 3.2e3; + const double max_peak_current = 3.6e3; + + const double min_peak_current_time = 0.010; + const double max_peak_current_time = 0.012; + + REQUIRE(peak_current > min_peak_current); + REQUIRE(peak_current < max_peak_current); + + REQUIRE(peak_current_time > min_peak_current_time); + REQUIRE(peak_current_time < max_peak_current_time); + } }; TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") @@ -211,10 +226,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") double peak_current, peak_current_time; ExtractPeakCurrentAndTime(*problem, peak_current, peak_current_time); - REQUIRE(peak_current > 3.2e3); - REQUIRE(peak_current < 3.6e3); - REQUIRE(peak_current_time < 0.012); - REQUIRE(peak_current_time > 0.01); + VerifyPeakCurrentAndTimeWithinTolerances(peak_current, peak_current_time); } /// Test case for checking "Updates" work as expected following a mesh refinement. @@ -248,10 +260,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench peak_current, peak_current_time); - REQUIRE(peak_current > 3.2e3); - REQUIRE(peak_current < 3.6e3); - REQUIRE(peak_current_time < 0.012); - REQUIRE(peak_current_time > 0.01); + VerifyPeakCurrentAndTimeWithinTolerances(peak_current, peak_current_time); if (irefinement != (imax_refinement - 1)) { From 440421d26eea76a0b52810dde63dea2fd8a0e472 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 10:04:36 +0000 Subject: [PATCH 11/13] Updates comments in TestTEAM4HForm. --- test/integration/test_team4_hform.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 7960b05b0..d93b55ecf 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -43,6 +43,7 @@ class TestTEAM4HForm dh_dt(2) = 0.0; } + /// Returns a unique pointer to the constructed problem builder. std::unique_ptr ConfigureProblem() { // Create Formulation @@ -171,6 +172,7 @@ class TestTEAM4HForm return outputs; } + /// Sets the peak current and time using the flux monitor. void ExtractPeakCurrentAndTime(hephaestus::TimeDomainProblem & problem, double & peak_current, double & peak_current_time) @@ -194,6 +196,7 @@ class TestTEAM4HForm } } + /// Checks peak current and time are within expected range. void VerifyPeakCurrentAndTimeWithinTolerances(double & peak_current, double & peak_current_time) { const double min_peak_current = 3.2e3; @@ -212,7 +215,6 @@ class TestTEAM4HForm TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") { - // Create Formulation auto problem_builder = ConfigureProblem(); auto problem = problem_builder->ReturnProblem(); @@ -262,6 +264,7 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench VerifyPeakCurrentAndTimeWithinTolerances(peak_current, peak_current_time); + // Refine if we have another iteration. if (irefinement != (imax_refinement - 1)) { problem->_pmesh->UniformRefinement(); From 670cce916c90eef5aafefc2187609f41a608bbb8 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 10:11:37 +0000 Subject: [PATCH 12/13] Moves pmesh refinement to top of for loop. --- test/integration/test_team4_hform.cpp | 33 ++++++++++++++------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index d93b55ecf..0371e00f0 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -211,18 +211,24 @@ class TestTEAM4HForm REQUIRE(peak_current_time > min_peak_current_time); REQUIRE(peak_current_time < max_peak_current_time); } + + /// Calls Reset method of FluxMonitorAux. + void ResetFluxMonitor(const hephaestus::TimeDomainProblem & problem) + { + auto fluxmonitor = problem._postprocessors.Get("FluxMonitor"); + + fluxmonitor->Reset(); + } }; TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") { auto problem_builder = ConfigureProblem(); - auto problem = problem_builder->ReturnProblem(); hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); auto executioner = std::make_unique(exec_params); - executioner->Execute(); double peak_current, peak_current_time; @@ -235,22 +241,24 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!benchmark]") { auto problem_builder = ConfigureProblem(); - auto problem = problem_builder->ReturnProblem(); - auto fluxmonitor = problem->_postprocessors.Get("FluxMonitor"); - hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); - hephaestus::logger.set_level(spdlog::level::info); const int imax_refinement = 2; for (int irefinement = 0; irefinement < imax_refinement; irefinement++) { - // Remove any stored fluxes. - fluxmonitor->Reset(); + // Refine and reset flux monitor on subsequent runs. + if (irefinement != 0) + { + problem->_pmesh->UniformRefinement(); + problem->Update(); + + ResetFluxMonitor(*problem); + } - // Reconstruct executioner each time we start. + // Create a new executioner. hephaestus::TransientExecutioner executioner(exec_params); executioner.Execute(); @@ -263,12 +271,5 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HFormMeshUpdates", "[CheckRun][!bench peak_current_time); VerifyPeakCurrentAndTimeWithinTolerances(peak_current, peak_current_time); - - // Refine if we have another iteration. - if (irefinement != (imax_refinement - 1)) - { - problem->_pmesh->UniformRefinement(); - problem->Update(); - } } } From bc3a110f757c6c6eb29dcbe82b11526274106ca5 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Thu, 30 May 2024 10:14:10 +0000 Subject: [PATCH 13/13] Removes use of unique pointer for TransientExecutioner in TestTEAM4HForm. --- test/integration/test_team4_hform.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/test_team4_hform.cpp b/test/integration/test_team4_hform.cpp index 0371e00f0..4a78c50d0 100644 --- a/test/integration/test_team4_hform.cpp +++ b/test/integration/test_team4_hform.cpp @@ -228,8 +228,8 @@ TEST_CASE_METHOD(TestTEAM4HForm, "TestTEAM4HForm", "[CheckRun]") hephaestus::InputParameters exec_params = DefineExecutionerParameters(*problem); - auto executioner = std::make_unique(exec_params); - executioner->Execute(); + hephaestus::TransientExecutioner executioner(exec_params); + executioner.Execute(); double peak_current, peak_current_time; ExtractPeakCurrentAndTime(*problem, peak_current, peak_current_time);