82 return m_config.at(
"function").as<std::string>();
85 if (
m_f->m_session->DefinesElement(
"Nektar/Forcing"))
87 TiXmlElement *forcing =
m_f->m_session->GetElement(
"Nektar/Forcing");
88 TiXmlElement *force = forcing->FirstChildElement(
"FORCE");
91 const char *type = force->Attribute(
"TYPE");
94 TiXmlElement *fields =
95 force->FirstChildElement(
"ELECTRICMAGNETICFIELDS");
96 ASSERTL0(fields && fields->GetText(),
97 "ForcingLorentz requires an ELECTRICMAGNETICFIELDS "
98 "function for MHDCurrentDensity.");
99 return fields->GetText();
101 force = force->NextSiblingElement(
"FORCE");
105 ASSERTL0(
m_f->m_session->DefinesFunction(
"ElectricMagneticFields"),
106 "MHDCurrentDensity could not find a ForcingLorentz "
107 "ELECTRICMAGNETICFIELDS function. Specify one with "
109 return "ElectricMagneticFields";
116 int spacedim =
m_f->m_graph->GetMeshDimension() +
m_f->m_numHomogeneousDir;
117 ASSERTL0(spacedim == 2 || spacedim == 3,
118 "MHDCurrentDensity only supports two- and three-dimensional "
124 ASSERTL0(velocity[0] >= 0 && velocity[1] >= 0,
125 "MHDCurrentDensity requires velocity fields u and v.");
126 ASSERTL0(spacedim == 2 || velocity[2] >= 0,
127 "MHDCurrentDensity requires velocity field w in 3D.");
129 "MHDCurrentDensity requires electric potential field phi.");
132 m_f->m_session->LoadParameter(
"ElectricConductivity", sigma, -1.0);
134 "ElectricConductivity must be defined and positive for "
135 "MHDCurrentDensity.");
138 ASSERTL0(
m_f->m_session->DefinesFunction(functionName),
139 "Function '" + functionName +
"' is not defined in the session.");
141 std::array<NekDouble, 3> electric = {0.0, 0.0, 0.0};
142 std::array<NekDouble, 3> magnetic = {0.0, 0.0, 0.0};
143 const std::array<std::string, 3> electricVars = {
"Ex",
"Ey",
"Ez"};
144 const std::array<std::string, 3> magneticVars = {
"Bx",
"By",
"Bz"};
145 for (
int i = 0; i < 3; ++i)
147 if (
m_f->m_session->DefinesFunction(functionName, electricVars[i]))
150 m_f->m_session->GetFunction(functionName, electricVars[i])
151 ->Evaluate(0.0, 0.0, 0.0, 0.0);
153 if (
m_f->m_session->DefinesFunction(functionName, magneticVars[i]))
156 m_f->m_session->GetFunction(functionName, magneticVars[i])
157 ->Evaluate(0.0, 0.0, 0.0, 0.0);
161 int nfields =
m_f->m_variables.size();
162 m_f->m_variables.insert(
m_f->m_variables.end(), {
"Jx",
"Jy",
"Jz"});
163 m_f->m_exp.resize(nfields + 3);
167 if (
m_f->m_exp[0]->GetNumElmts() == 0)
172 int npoints =
m_f->m_exp[0]->GetNpoints();
173 for (
int i = 0; i < spacedim; ++i)
175 ASSERTL0(
m_f->m_exp[velocity[i]]->GetNpoints() == npoints,
176 "MHDCurrentDensity requires velocity fields on the same "
179 ASSERTL0(
m_f->m_exp[potential]->GetNpoints() == npoints,
180 "MHDCurrentDensity requires phi on the same points as the "
185 for (
int i = 0; i < 3; ++i)
190 for (
int i = 0; i < spacedim; ++i)
193 m_f->m_exp[potential]->GetPhys(),
203 w =
m_f->m_exp[velocity[2]]->GetPhys();
206 for (
int i = 0; i < npoints; ++i)
208 current[0][i] = sigma * (electric[0] + v[i] * magnetic[2] -
209 w[i] * magnetic[1] - gradPhi[0][i]);
210 current[1][i] = sigma * (electric[1] + w[i] * magnetic[0] -
211 u[i] * magnetic[2] - gradPhi[1][i]);
212 current[2][i] = sigma * (electric[2] + u[i] * magnetic[1] -
213 v[i] * magnetic[0] - gradPhi[2][i]);
216 for (
int i = 0; i < 3; ++i)
218 m_f->m_exp[nfields + i] =
m_f->AppendExpList(
m_f->m_numHomogeneousDir);
220 m_f->m_exp[nfields + i]->UpdatePhys(), 1);
221 m_f->m_exp[nfields + i]->FwdTransLocalElmt(
222 current[i],
m_f->m_exp[nfields + i]->UpdateCoeffs());