Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MFEMOpenCoilSource #48

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 16 additions & 28 deletions examples/MFEM/coil/AFormCoil.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

[Problem]
type = MFEMProblem
use_glvis = true
[]

[Formulation]
Expand All @@ -14,6 +15,7 @@
magnetic_reluctivity_name = magnetic_reluctivity
magnetic_permeability_name = magnetic_permeability
electric_conductivity_name = electrical_conductivity
magnetic_flux_density_name = magnetic_flux_density
[]

[FESpaces]
Expand Down Expand Up @@ -43,25 +45,23 @@
type = MFEMVariable
fespace = HDivFESpace
[]
[source_current_density]
type = MFEMVariable
fespace = HCurlFESpace
[]
[electric_potential]
type = MFEMVariable
fespace = H1FESpace
[]
[]

[Functions]
[potential_high]
[current_magnitude]
type = ParsedFunction
value = cos(2.0*pi*freq*t)
vars = 'freq'
vals = '0.01666667'
[]
[potential_low]
type = ParsedFunction
value = -cos(2.0*pi*freq*t)
vars = 'freq'
vals = '0.01666667'
[]
[]

[BCs]
Expand All @@ -71,18 +71,6 @@
vector_coefficient = TangentialECoef
boundary = '1 2 3 4'
[]
[high_terminal]
type = MFEMScalarDirichletBC
variable = electric_potential
boundary = '1'
function = potential_high
[]
[low_terminal]
type = MFEMScalarDirichletBC
variable = electric_potential
boundary = '2'
function = potential_low
[]
[]

[Materials]
Expand Down Expand Up @@ -158,20 +146,20 @@
value = 0.0
[]

[OneCoef]
type = MFEMConstantCoefficient
value = 1.0e12
[CurrentCoef]
type = MFEMFunctionCoefficient
function = current_magnitude
[]
[]

[Sources]
[SourcePotential]
type = MFEMScalarPotentialSource
potential = electric_potential
conductivity = electrical_conductivity
hcurl_fespace = HCurlFESpace
h1_fespace = H1FESpace
solver_max_its = 1000
type = MFEMOpenCoilSource
total_current_coef = CurrentCoef
source_current_density_gridfunction = source_current_density
source_potential_gridfunction = electric_potential
coil_in_boundary = 1
coil_out_boundary = 2
block = 1
[]
[]
Expand Down
29 changes: 29 additions & 0 deletions include/sources/MFEMOpenCoilSource.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once
#include "MFEMSource.h"
#include "MFEMVariable.h"
#include "MFEMCoefficient.h"

class MFEMOpenCoilSource : public MFEMSource
{
public:
static InputParameters validParams();

MFEMOpenCoilSource(const InputParameters & parameters);
virtual ~MFEMOpenCoilSource();

virtual void execute() override {}
virtual void initialize() override {}
virtual void finalize() override {}

virtual hephaestus::Source * getSource() override;
virtual void storeCoefficients(hephaestus::Coefficients & coefficients) override;

protected:
const MFEMVariable & _source_current_density_gridfunction;
const MFEMVariable & _source_potential_gridfunction;
const MFEMCoefficient & _total_current_coef;
const hephaestus::InputParameters _open_coil_params;
mfem::Array<int> _coil_domains;
const int _coil_in_id, _coil_out_id;
const std::pair<int,int> _electrodes;
};
62 changes: 62 additions & 0 deletions src/sources/MFEMOpenCoilSource.C
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "MFEMOpenCoilSource.h"

registerMooseObject("ApolloApp", MFEMOpenCoilSource);

InputParameters
MFEMOpenCoilSource::validParams()
{
InputParameters params = MFEMSource::validParams();

params.addParam<UserObjectName>(
"total_current_coef",
"The total current ($I$) flowing through the coil. May be time dependent.");

params.addParam<UserObjectName>("source_current_density_gridfunction",
"The gridfunction to store the source current density.");

params.addParam<UserObjectName>("source_potential_gridfunction",
"The gridfunction to store the scalar potential in the coil.");

params.addParam<BoundaryName>(
"coil_in_boundary",
"The boundary (id or name) from the mesh determinining the coil input terminal");

params.addParam<BoundaryName>(
"coil_out_boundary",
"The boundary (id or name) from the mesh determinining the coil output terminal");
return params;
}

MFEMOpenCoilSource::MFEMOpenCoilSource(const InputParameters & parameters)
: MFEMSource(parameters),
_source_current_density_gridfunction(
getUserObject<MFEMVariable>("source_current_density_gridfunction")),
_source_potential_gridfunction(getUserObject<MFEMVariable>("source_potential_gridfunction")),
_total_current_coef(getUserObject<MFEMCoefficient>("total_current_coef")),
_open_coil_params({{"SourceName", _source_current_density_gridfunction.name()},
{"PotentialName", _source_potential_gridfunction.name()},
{"IFuncCoefName", _total_current_coef.name()}}),
_coil_domains(blocks.size()),
_coil_in_id(std::stoi(getParam<BoundaryName>("coil_in_boundary"))),
_coil_out_id(std::stoi(getParam<BoundaryName>("coil_out_boundary"))),
_electrodes(std::make_pair(_coil_in_id, _coil_out_id))
{
for (unsigned int bid = 0; bid < blocks.size(); ++bid)
{
_coil_domains[bid] = blocks[bid];
}
_source = new hephaestus::OpenCoilSolver(_open_coil_params, _coil_domains, _electrodes);
}

hephaestus::Source *
MFEMOpenCoilSource::getSource()
{
return _source;
}

void
MFEMOpenCoilSource::storeCoefficients(hephaestus::Coefficients & coefficients)
{
}

MFEMOpenCoilSource::~MFEMOpenCoilSource() {}
Loading