From 20c4fd83ea716bf4bbfae919f8f24f29ce416a49 Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Mon, 10 Jun 2024 16:00:56 +0100 Subject: [PATCH 1/2] Add MFEMLineSampler as an auxsolver --- .../team7_closed_coil_frequency_domain.i | 12 ++++++ include/auxkernels/MFEMLineSamplerAux.h | 32 +++++++++++++++ include/mesh/ExclusiveMFEMMesh.h | 5 ++- src/auxkernels/MFEMLineSamplerAux.C | 39 +++++++++++++++++++ src/mesh/ExclusiveMFEMMesh.C | 8 +++- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 include/auxkernels/MFEMLineSamplerAux.h create mode 100644 src/auxkernels/MFEMLineSamplerAux.C diff --git a/examples/TEAM/Problem_7/team7_closed_coil_frequency_domain.i b/examples/TEAM/Problem_7/team7_closed_coil_frequency_domain.i index af884d9f..886479c7 100644 --- a/examples/TEAM/Problem_7/team7_closed_coil_frequency_domain.i +++ b/examples/TEAM/Problem_7/team7_closed_coil_frequency_domain.i @@ -77,6 +77,18 @@ [] [] +[AuxKernels] + [LineSampler] + type = MFEMLineSamplerAux + filename = 'bfield.csv' + variable = magnetic_flux_density_real + num_points = 100 + start_point = '0.09 0.072 0.034' + end_point = '0.1 0.072 0.034' + header = 't (s), x (m), y (m), z (m), B_x (T), B_y (T), B_z (T)' + [] +[] + [Sources] [SourceCoil] type = MFEMClosedCoilSource diff --git a/include/auxkernels/MFEMLineSamplerAux.h b/include/auxkernels/MFEMLineSamplerAux.h new file mode 100644 index 00000000..28bd594a --- /dev/null +++ b/include/auxkernels/MFEMLineSamplerAux.h @@ -0,0 +1,32 @@ +#pragma once + +#include "MFEMAuxSolver.h" +#include "MFEMVariable.h" + +class MFEMLineSamplerAux : public MFEMAuxSolver +{ +public: + static InputParameters validParams(); + + MFEMLineSamplerAux(const InputParameters & parameters); + virtual ~MFEMLineSamplerAux(); + + virtual void execute() override {} + virtual void initialize() override {} + virtual void finalize() override {} + + inline std::shared_ptr getAuxSolver() const override + { + return _line_sampler_aux; + } + +protected: + const MFEMVariable & _mfem_variable; + const Point _start_point; + const Point _end_point; + mfem::Vector _start_vec; + mfem::Vector _end_vec; + unsigned int _num_points; + + std::shared_ptr _line_sampler_aux{nullptr}; +}; diff --git a/include/mesh/ExclusiveMFEMMesh.h b/include/mesh/ExclusiveMFEMMesh.h index d84ad692..6326ecd9 100644 --- a/include/mesh/ExclusiveMFEMMesh.h +++ b/include/mesh/ExclusiveMFEMMesh.h @@ -24,7 +24,7 @@ #include "libmesh/numeric_vector.h" #include "libmesh/system.h" #include "libmesh/vtk_io.h" -#include "mfem.hpp" +#include "hephaestus.hpp" /** * ExclusiveMFEMMesh @@ -92,4 +92,7 @@ class ExclusiveMFEMMesh : public FileMesh */ std::shared_ptr _mfem_mesh; std::shared_ptr _mfem_par_mesh; + mfem::H1_FECollection default_nodal_fecoll; + std::shared_ptr default_nodal_fespace{nullptr}; + // std::shared_ptr default_nodal_fespace(pmesh.get(), &fecm, 3); }; diff --git a/src/auxkernels/MFEMLineSamplerAux.C b/src/auxkernels/MFEMLineSamplerAux.C new file mode 100644 index 00000000..c858aef6 --- /dev/null +++ b/src/auxkernels/MFEMLineSamplerAux.C @@ -0,0 +1,39 @@ +#include "MFEMLineSamplerAux.h" + +registerMooseObject("ApolloApp", MFEMLineSamplerAux); + +InputParameters +MFEMLineSamplerAux::validParams() +{ + InputParameters params = MFEMAuxSolver::validParams(); + params.addRequiredParam("start_point", "The beginning of the line"); + params.addRequiredParam("end_point", "The end of the line"); + params.addRequiredParam("num_points", + "The number of points to sample along the line"); + params.addRequiredParam( + "variable", "The FESpace associated with the test variable the source will be applied to."); + params.addRequiredParam("header", "Header for the output CSV."); + params.addRequiredParam("filename", "Name of the output CSV."); + return params; +} + +MFEMLineSamplerAux::MFEMLineSamplerAux(const InputParameters & parameters) + : MFEMAuxSolver(parameters), + _mfem_variable(getUserObject("variable")), + _start_point(getParam("start_point")), + _end_point(getParam("end_point")), + _start_vec({_start_point(0), _start_point(1), _start_point(2)}), + _end_vec({_end_point(0), _end_point(1), _end_point(2)}), + _num_points(getParam("num_points")), + _line_sampler_aux{ + std::make_shared(_mfem_variable.name(), + _start_vec, + _end_vec, + _num_points, + getParam("filename"), + getParam("header"))} +{ + _line_sampler_aux->SetPriority(10); +} + +MFEMLineSamplerAux::~MFEMLineSamplerAux() {} diff --git a/src/mesh/ExclusiveMFEMMesh.C b/src/mesh/ExclusiveMFEMMesh.C index 95f6e4b6..a1f44751 100644 --- a/src/mesh/ExclusiveMFEMMesh.C +++ b/src/mesh/ExclusiveMFEMMesh.C @@ -18,7 +18,10 @@ ExclusiveMFEMMesh::validParams() return params; } -ExclusiveMFEMMesh::ExclusiveMFEMMesh(const InputParameters & parameters) : FileMesh(parameters) {} +ExclusiveMFEMMesh::ExclusiveMFEMMesh(const InputParameters & parameters) + : FileMesh(parameters), default_nodal_fecoll(1, 3) +{ +} ExclusiveMFEMMesh::~ExclusiveMFEMMesh() {} @@ -62,6 +65,9 @@ ExclusiveMFEMMesh::buildMFEMParMesh() { _mfem_par_mesh = std::make_shared(MPI_COMM_WORLD, getMFEMMesh()); _mfem_mesh.reset(); // Lower reference count of serial mesh since no longer needed. + default_nodal_fespace = + std::make_shared(_mfem_par_mesh.get(), &default_nodal_fecoll, 3); + _mfem_par_mesh->SetNodalFESpace(default_nodal_fespace.get()); } MFEMMesh & From 4db2d9210d1765672fe4898d52520eff1b93a8bb Mon Sep 17 00:00:00 2001 From: Alexander Blair Date: Thu, 27 Jun 2024 16:16:38 +0100 Subject: [PATCH 2/2] Add default nodal FESpace creation to CoupledMFEMMesh --- contrib/hephaestus | 2 +- src/auxkernels/MFEMLineSamplerAux.C | 2 +- src/mesh/CoupledMFEMMesh.C | 3 +++ 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/contrib/hephaestus b/contrib/hephaestus index ff359ff3..b9b6fd46 160000 --- a/contrib/hephaestus +++ b/contrib/hephaestus @@ -1 +1 @@ -Subproject commit ff359ff38f1706fa0a960367c20dc1f712ca29f2 +Subproject commit b9b6fd46f1863fcd2a2d25b6a819bb09c08fcde2 diff --git a/src/auxkernels/MFEMLineSamplerAux.C b/src/auxkernels/MFEMLineSamplerAux.C index c858aef6..f193913c 100644 --- a/src/auxkernels/MFEMLineSamplerAux.C +++ b/src/auxkernels/MFEMLineSamplerAux.C @@ -33,7 +33,7 @@ MFEMLineSamplerAux::MFEMLineSamplerAux(const InputParameters & parameters) getParam("filename"), getParam("header"))} { - _line_sampler_aux->SetPriority(10); + _line_sampler_aux->SetPriority(99); } MFEMLineSamplerAux::~MFEMLineSamplerAux() {} diff --git a/src/mesh/CoupledMFEMMesh.C b/src/mesh/CoupledMFEMMesh.C index ff1d4a9e..6e0e70c4 100644 --- a/src/mesh/CoupledMFEMMesh.C +++ b/src/mesh/CoupledMFEMMesh.C @@ -438,6 +438,9 @@ CoupledMFEMMesh::buildMFEMParMesh() convertSerialDofMappingsToParallel(*_mfem_mesh.get(), *_mfem_par_mesh.get()); _mfem_mesh.reset(); // Lower reference count of serial mesh since no longer needed. + default_nodal_fespace = + std::make_shared(_mfem_par_mesh.get(), &default_nodal_fecoll, 3); + _mfem_par_mesh->SetNodalFESpace(default_nodal_fespace.get()); } void