ENH: electricPotential: enable electric field calculations

This commit is contained in:
Kutalmis Bercin
2023-04-21 10:32:28 +01:00
committed by Kutalmış Berçin
parent efe8220a26
commit c7e5e7f4a2
2 changed files with 55 additions and 20 deletions

View File

@ -209,8 +209,17 @@ Foam::functionObjects::electricPotential::electricPotential
IOobject::scopedName(typeName, "V")
)
),
Ename_
(
dict.getOrDefault<word>
(
"E",
IOobject::scopedName(typeName, "E")
)
),
nCorr_(1),
writeDerivedFields_(false)
writeDerivedFields_(false),
electricField_(false)
{
read(dict);
@ -218,6 +227,28 @@ Foam::functionObjects::electricPotential::electricPotential
// look it up
volScalarField& eV = getOrReadField(Vname_);
eV.correctBoundaryConditions();
if (electricField_)
{
auto* ptr = getObjectPtr<volVectorField>(Ename_);
if (!ptr)
{
ptr = new volVectorField
(
IOobject
(
Ename_,
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::NO_WRITE
),
-fvc::grad(eV)
);
mesh_.objectRegistry::store(ptr);
}
}
}
@ -236,6 +267,7 @@ bool Foam::functionObjects::electricPotential::read(const dictionary& dict)
dict.readIfPresent("epsilonr", epsilonr_);
dict.readIfPresent("nCorr", nCorr_);
dict.readIfPresent("writeDerivedFields", writeDerivedFields_);
dict.readIfPresent("electricField", electricField_);
// If flow is multiphase
if (!phasesDict_.empty())
@ -334,6 +366,12 @@ bool Foam::functionObjects::electricPotential::execute()
eVEqn.solve();
}
if (electricField_)
{
auto& E = lookupObjectRef<volVectorField>(Ename_);
E == -fvc::grad(eV);
}
Log << endl;
return true;
@ -348,29 +386,17 @@ bool Foam::functionObjects::electricPotential::write()
volScalarField& eV = getOrReadField(Vname_);
if (writeDerivedFields_)
if (electricField_)
{
// Write the electric field
const volVectorField E
(
IOobject
(
IOobject::scopedName(typeName, "E"),
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
-fvc::grad(eV),
fvPatchFieldBase::calculatedType()
);
const auto& E = lookupObject<volVectorField>(Ename_);
Log << tab << E.name() << endl;
E.write();
}
if (writeDerivedFields_)
{
// Write the current density field
tmp<volScalarField> tsigma = this->sigma();
@ -408,7 +434,7 @@ bool Foam::functionObjects::electricPotential::write()
IOobject::NO_WRITE,
IOobject::NO_REGISTER
),
fvc::div(tepsilonm*E),
fvc::div(tepsilonm*(-fvc::grad(eV))),
fvPatchFieldBase::calculatedType()
);

View File

@ -121,6 +121,8 @@ Usage
nCorr <int>;
writeDerivedFields <bool>;
V <word>;
electricField <bool>;
E <word>;
// Inherited entries
...
@ -137,6 +139,8 @@ Usage
nCorr | Number of corrector iterations | int | no | 1
writeDerivedFields | Flag to write extra fields | bool | no | false
V | Name of electric potential field | word | no | electricPotential:V
electricField | Flag to calculate electric field | bool | no | false
E | Name of electric field | word | no | electricPotential:E
\endtable
The inherited entries are elaborated in:
@ -145,7 +149,6 @@ Usage
Fields written out when the \c writeDerivedFields entry is \c true:
\table
Operand | Type | Location
Electric field | volVectorField | \<time\>/electricPotential:E
Current density | volVectorField | \<time\>/electricPotential:J
Charge density | volScalarField | \<time\>/electricPotential:rho
\endtable
@ -202,6 +205,9 @@ class electricPotential
//- Name of electric potential field
word Vname_;
//- Name of electric field
word Ename_;
//- Number of corrector iterations
int nCorr_;
@ -209,6 +215,9 @@ class electricPotential
//- electric field, current density and free-charge density
bool writeDerivedFields_;
//- Flag to calculate electric field
bool electricField_;
// Private Member Functions