Skip to content
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
4 changes: 3 additions & 1 deletion src/applications/solvers/common/scalar_transport_fo.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
// * ddt: TRANSIENT IS supported. This object owns the field's old time levels (old/old2/ddt0,
// device_ddt.cuh:95) and solvePassiveScalar advances them with the SOLVER's time scheme -- a case
// has one time scheme, and choosing it is not a functionObject's business. On a steady solver the
// term drops out, exactly as OF's ddt does.
// term drops out, which is OF's ddt only under `ddtSchemes default steadyState`: OF's tracer takes
// fvm::ddt(s) under a steady solver's Euler too (scalarTransport.C:341), so gpuSimpleFoam and
// gpuRhoSimpleFoam refuse that pairing at start-up.
//
// PASSIVE: nothing here writes back into U, p, T, rho or the turbulence, so a case solves identically
// with the tracer present or absent. That is what makes it safe to run from the functionObject
Expand Down
16 changes: 8 additions & 8 deletions src/applications/solvers/common/solver_dispatch.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -205,18 +205,18 @@ inline SolverDecision decideSolver(const std::string& caseDir, const FoamDict& c
// The case names a solver but its ddtSchemes says the other thing -- one of the two is wrong, and
// guessing which would silently produce the wrong answer.
// A STEADY solver with a transient ddtSchemes entry is NOT an error in OpenFOAM. simpleFoam's
// UEqn has no ddt term at all --
// UEqn has no ddt term --
// fvm::div(phi, U) + MRF.DDt(U) + turbulence->divDevSigma(U) == fvOptions(U)
// -- so the entry is never looked up and is simply inert. OF's OWN squareBend tutorial ships
// `application simpleFoam` with `ddtSchemes { default Euler; }` and runs fine; brae refused it.
// Report that the entry is ignored (the steady path forces steadyState regardless) rather than
// reject a valid, shipped case.
// -- but its turbulence model's equations do (fvm::ddt(alpha, rho, k), kEpsilon.C:254, 275): under Euler they
// are pseudo-transient with the solver's deltaT. OF's OWN squareBend tutorial ships `application simpleFoam`
// with `ddtSchemes { default Euler; }`. The steady drivers decide what they carry: simpleFoam takes Euler in
// the turbulence equations and refuses any other scheme (gpuSimpleFoam.cu); the notice says where it goes.
if (!ddt.empty() && chosen->transient != transientCase && !chosen->transient)
{
noticeIgnored("fvSchemes/ddtSchemes.default",
"'" + ddt + "' on the steady solver '" + application + "'. OpenFOAM's steady "
"solvers construct no ddt term, so this entry is inert there and is ignored "
"here too -- the run is steady.");
"'" + ddt + "' on the steady solver '" + application + "': the momentum equation has no "
"ddt; the turbulence equations take it where the driver carries it (simpleFoam: Euler), "
"and the driver refuses it where it does not.");
}
// The reverse IS an error: a transient solver with steadyState would silently drop the time
// derivative, which is a different equation rather than an unused entry.
Expand Down
31 changes: 31 additions & 0 deletions src/applications/solvers/rhoSimpleFoam/gpuRhoSimpleFoam.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "foam_field_reader.cuh"
#include "foam_field_writer.cuh"
#include "foam_dict.cuh"
#include "../common/solver_dispatch.cuh" // readDdtSchemeWord
#include "fvc.cuh"
#include "device_simple_foam.cuh"
#include "thermo_parse.cuh"
Expand Down Expand Up @@ -388,6 +389,22 @@ int main(int argc, char** argv)
// COMPRESSIBLE legacy: rhoSimpleStep applies the generalized-Newtonian nu
// (device_simple_foam.cu:3540) and the boundary muEff arm at :1319 is its compressible half.
readTurbulenceModel(turbProps, ctl, {"rhoSimpleFoam (legacy)", true, true});
// A RAS model's equations take fvm::ddt(alpha, rho, k) (kEpsilon.C:254, 275) whatever the solver, so a ddtSchemes
// default other than steadyState makes them pseudo-transient (gasMixing/injectorPipe ships Euler). This path's
// rhoSimpleStep carries no time derivative; the OF-mirror arms do (BRAE_RHOSIMPLEFOAM_MIRROR, the closures' ddt
// with rho.oldTime()). Refused here rather than run steady with a notice.
if (ctl.turbulent)
{
const std::string ddtWord = readDdtSchemeWord(caseDir + "/system/fvSchemes");
if (!ddtWord.empty() && ddtWord != "steadyState")
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default '" + ddtWord + "' with a RAS model on "
"rhoSimpleFoam's default device path: OpenFOAM's turbulence equations take "
"fvm::ddt(alpha, rho, k|epsilon|omega) under it, which this path does not carry. "
"The OF-mirror arms do (BRAE_RHOSIMPLEFOAM_MIRROR=1 or cuda). Refusing rather "
"than run them steady.");
}
}
// kOmegaSST and kEpsilon are both rho-weighted (every RHS term, the diffusivity, the volumetric
// divU and the per-face wall nu). SA and the kOmegaSST variants are not, so they stay refused:
// running one down the incompressible path converges to a wrong answer rather than failing.
Expand Down Expand Up @@ -835,6 +852,20 @@ int main(int argc, char** argv)
+ startName + "): there is nothing to run. endTime is an ABSOLUTE time, not a number of "
"iterations -- on a restart set it past the time you are restarting from.");
Time time(controlDict, &wc, static_cast<int>(nSteps), foTypes);
// OpenFOAM's scalarTransport on a mass flux solves fvm::ddt(rho, s) + fvm::div(phi, s) - fvm::laplacian(D, s)
// (scalarTransport.C:319) under the case's ddt default; rhoSimpleStep's solvePassiveScalar carries none. The RAS
// refusal above covers a turbulent case; this covers a laminar one.
if (!scalarTransports.empty())
{
const std::string ddtWord = readDdtSchemeWord(caseDir + "/system/fvSchemes");
if (!ddtWord.empty() && ddtWord != "steadyState")
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default '" + ddtWord + "' with a scalarTransport "
"function object on rhoSimpleFoam's default device path: OpenFOAM's tracer "
"equation takes fvm::ddt(rho, s) under it, which this path does not carry. "
"Refusing rather than solve the tracer steady.");
}
}

int nIter = static_cast<int>(nSteps);
bool converged = false;
Expand Down
25 changes: 24 additions & 1 deletion src/applications/solvers/simpleFoam/device_simple_foam.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1435,7 +1435,11 @@ SimplecSnGrad simplecSnGrad(
{
// transient URANS fvm::ddt(k/eps/omega/nuTilda): a per-scalar bundle (steady -> active==false -> no-op, so
// the steady SIMPLE turbulence stays byte-for-byte). dk_=k|nuTilda (kOld_), de_=epsilon|omega (e2Old_).
const DdtCoeffs ddtc = ddtCoeffs(ddtScheme_, deltaT_, deltaT0_, ocCoeff_, cnWarm_);
// ...or, on the steady step, the turbulence equations' own Euler derivative (setSteadyTurbulenceDdt), whose old
// levels step() took at the start of the iteration
const bool steadyDdt = (ddtScheme_ == DdtScheme::steadyState) && steadyTurbulenceDdtActive();
const DdtCoeffs ddtc = steadyDdt ? ddtCoeffs(steadyTurbDdt_, steadyTurbDeltaT_, scalar(0))
: ddtCoeffs(ddtScheme_, deltaT_, deltaT0_, ocCoeff_, cnWarm_);
const ScalarDdt kDdt{ ddtc, &kOld_, kOld2_.size() ? &kOld2_ : nullptr, ddtc.cn ? &kddt0_ : nullptr };
const ScalarDdt sDdt{ ddtc, &e2Old_, e2Old2_.size() ? &e2Old2_ : nullptr, ddtc.cn ? &e2ddt0_ : nullptr };
const ScalarDdt reDdt{ ddtc, &ReThetatOld_, ReThetatOld2_.size() ? &ReThetatOld2_ : nullptr, ddtc.cn ? &ReThetatddt0_ : nullptr }; // kOmegaSSTLM
Expand Down Expand Up @@ -4401,6 +4405,25 @@ SimplecSnGrad simplecSnGrad(
correctPressureVelocity(res, /*releaseMomentumMatrix*/ true);
const double msP = phaseTime ? phaseMs() : 0.0;
detail::devicePool().phase("turbulence");
// The turbulence fields' old levels for their Euler derivative (setSteadyTurbulenceDdt): the fields as the iteration
// found them, which is what GeometricField::storeOldTimes keeps at their first write in the time step -- nothing
// in the momentum or pressure phase writes them. MEASURED on incompressible/simpleFoam/squareBend from rest, one
// iteration, every solve pinned, against OpenFOAM's assembled epsilon equation (tools/dumpKEpsilon): every cell's
// diagonal 1.0*V above brae's, the Euler term at deltaT 1; with the inlet's k and epsilon fixed at iteration 1's
// values nut was 4.3e-02 off after that iteration (Arrhenius 5870941, 5871717).
if (steadyTurbulenceDdtActive() && ctl_.turbulent && !ctl_.les)
{
deviceCopy(kOld_, dk_);
if (!ctl_.sa)
{
deviceCopy(e2Old_, de_);
}
if (ctl_.lm)
{
deviceCopy(ReThetatOld_, ReThetat_);
deviceCopy(gammaIntOld_, gammaInt_);
}
}
// this step drops the grad(U) memo after turbulence (below), so the model may drop it as soon as it has
// read it
correctTurbulence(/*releaseGradUMemo*/ true);
Expand Down
20 changes: 20 additions & 0 deletions src/applications/solvers/simpleFoam/device_simple_foam.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ public:
// --- Transient (PIMPLE) interface -- reuses the three composable phases above under an outer/inner-corrector loop,
// with the implicit fvm::ddt(U) folded into solveMomentumPredictor. setDdtScheme() switches this solver from steady
// (SIMPLE, the default) to transient; the steady step() path is completely unaffected (ddt stays a no-op).
// The steady step's TURBULENCE time derivative. OpenFOAM's turbulence models construct fvm::ddt(alpha, rho, k) and
// fvm::ddt(alpha, rho, epsilon|omega) (nuTilda, the transition scalars) whatever the solver (kEpsilon.C:254, 275,
// kOmegaSSTBase.C:572, 602, SpalartAllmarasBase.C:468), so a steady case whose ddtSchemes default is Euler solves each
// of them with (psi - psi.oldTime())/deltaT, deltaT the solver's own time step: incompressible/simpleFoam/squareBend
// and lumpedPointMotion's steady cases ship it. simpleFoam's UEqn has no ddt, so the momentum assembly takes none and
// ddtScheme_ stays steadyState. step() takes the old level at the start of the iteration (Time::operator++).
void setSteadyTurbulenceDdt(DdtScheme s, scalar deltaT)
{
steadyTurbDdt_ = s;
steadyTurbDeltaT_ = deltaT;
}
// Set and not switched off by the control: BRAE_CONTROL_STEADY_TURBULENCE_DDT_IGNORED=1 drops the term, as before.
bool steadyTurbulenceDdtActive() const
{
static const bool ignored = std::getenv("BRAE_CONTROL_STEADY_TURBULENCE_DDT_IGNORED") != nullptr;
return steadyTurbDdt_ != DdtScheme::steadyState && steadyTurbDeltaT_ > scalar(0) && !ignored;
}

void setDdtScheme(DdtScheme s, scalar ocCoeff = scalar(1))
{
ddtScheme_ = s;
Expand Down Expand Up @@ -1072,6 +1090,8 @@ private:
// simpleFoam run them, each in the constructor or evaluate of its own field's equation -- totalPressure at every
// pressure assembly, for one. rhoSimpleStep keeps the momentum assembly's points.
bool ofUpdatePoints_ = false;
DdtScheme steadyTurbDdt_ = DdtScheme::steadyState; // setSteadyTurbulenceDdt
scalar steadyTurbDeltaT_ = 0;
bool hasCyclic_ = false; // any cyclic (periodic) interface -> Jacobi-PCG pressure (no AMG)
DeviceCyclic cyc_; // periodic interface coupling (OF updateInterfaceMatrix)
// (fvPatch index, face count) of each side stacked into cyc_.phi / ami_.phi, in the order
Expand Down
59 changes: 59 additions & 0 deletions src/applications/solvers/simpleFoam/gpuSimpleFoam.cu
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,65 @@ int main(int argc, char** argv)
const scalar writeInterval = controlDict.scalarOr("writeInterval", 1e30); // OF default GREAT -> only the final state
const int purgeWrite = std::max(0, controlDict.intOr("purgeWrite", 0));
const scalar deltaT = controlDict.scalarOr("deltaT", 1.0);
// ddtSchemes on this steady solver. simpleFoam's UEqn has no ddt, but OpenFOAM's turbulence models construct
// fvm::ddt of every field they transport whatever the solver, so `default Euler` is a real term in those equations
// (DeviceSimpleSolver::setSteadyTurbulenceDdt), with controlDict's deltaT -- which OpenFOAM requires (TimeIO.C:274).
// Any other scheme, or a per-field entry, is refused by name rather than run as a different equation.
{
const std::string fvs = caseDir + "/system/fvSchemes";
const std::string ddtWord = readDdtSchemeWord(fvs);
std::string block;
try
{
const std::string text = readFileExpanded(fvs);
const std::size_t b = text.find("ddtSchemes");
const std::size_t o = (b == std::string::npos) ? b : text.find('{', b);
const std::size_t c = (o == std::string::npos) ? o : text.find('}', o);
if (c != std::string::npos)
{
block = text.substr(o + 1, c - o - 1);
}
}
catch (...)
{
}
if (block.find("ddt(") != std::string::npos)
{
throw std::runtime_error("brae: fvSchemes ddtSchemes names a per-field entry on the steady solver simpleFoam; only "
"its `default` is read here (steadyState, or Euler for the turbulence equations). "
"Refusing rather than give that field another scheme.");
}
if (ddtWord == "Euler")
{
if (!controlDict.found("deltaT"))
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default Euler on simpleFoam needs controlDict's deltaT: "
"it is the turbulence equations' time step, and OpenFOAM requires the entry.");
}
if (ctl.maxwell)
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default Euler with the laminar Maxwell model on "
"simpleFoam: OpenFOAM's stress equation takes fvm::ddt(sigma), which this steady "
"step does not carry. Refusing rather than run it steady.");
}
// OpenFOAM's scalarTransport solves fvm::ddt(s) + fvm::div(phi, s) - fvm::laplacian(D, s) under the same
// default (scalarTransport.C:341); the steady step's solvePassiveScalar drops the ddt.
if (!scalarTransports.empty())
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default Euler with a scalarTransport function "
"object on simpleFoam: OpenFOAM's tracer equation takes fvm::ddt(s) under it, "
"which this steady step does not carry for the tracer. Refusing rather than "
"solve the tracer steady.");
}
solver.setSteadyTurbulenceDdt(DdtScheme::Euler, deltaT);
}
else if (!ddtWord.empty() && ddtWord != "steadyState")
{
throw std::runtime_error("brae: fvSchemes ddtSchemes default '" + ddtWord + "' on the steady solver simpleFoam: "
"OpenFOAM's turbulence equations take it (fvm::ddt), and this steady step carries "
"steadyState and Euler only. Refusing rather than run them as another equation.");
}
}
// The RESOLVED start, not controlDict's startTime: `startFrom latestTime` can make them differ,
// and every time value below is measured from the start. Taking the dict's value made a run
// restarted from 10 name its output 1, 2, 3... -- overwriting the case's own early history.
Expand Down
7 changes: 7 additions & 0 deletions tests/cmake/solver_simplefoam.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ set_tests_properties(simple_freestream_stored_vs_openfoam PROPERTIES SKIP_RETURN
add_test(NAME simple_update_points_vs_openfoam COMMAND bash ${PROJECT_SOURCE_DIR}/tests/simple_update_points_vs_openfoam.sh)
set_tests_properties(simple_update_points_vs_openfoam PROPERTIES SKIP_RETURN_CODE 77 LABELS slow TIMEOUT 1800
ENVIRONMENT "BRAE_BIN=$<TARGET_FILE:brae>;BRAE_OF_TUTORIALS=${BRAE_OF_TUTORIALS}")
# simpleFoam's turbulence equations under `ddtSchemes default Euler` (squareBend as shipped): OpenFOAM's models construct
# fvm::ddt of k and epsilon whatever the solver. Three pinned iterations from rest, every entry held; the term dropped
# (BRAE_CONTROL_STEADY_TURBULENCE_DDT_IGNORED=1) fails; backward on simpleFoam and Euler with RAS on rhoSimpleFoam's default
# device path are refused by name.
add_test(NAME simple_turbulence_ddt_vs_openfoam COMMAND bash ${PROJECT_SOURCE_DIR}/tests/simple_turbulence_ddt_vs_openfoam.sh)
set_tests_properties(simple_turbulence_ddt_vs_openfoam PROPERTIES SKIP_RETURN_CODE 77 LABELS slow TIMEOUT 1800
ENVIRONMENT "BRAE_BIN=$<TARGET_FILE:brae>;BRAE_OF_TUTORIALS=${BRAE_OF_TUTORIALS}")
# omegaWallFunction's and epsilonWallFunction's G0 from the STORED wall nut in the legacy closures: pitzDailySST with Spalding walls
# at tolerance 1e-9, one iteration from OpenFOAM's own iteration 50 against real OpenFOAM; the made-again nut
# (BRAE_CONTROL_G0_NUT_RECOMPUTED=1) fails.
Expand Down
Loading
Loading