From 43fc1c0a5573ce1db3df3eb77666385e634dd417 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Tue, 1 Oct 2024 11:16:03 -0400 Subject: [PATCH 01/19] Change to vector output for solution/aux field. Something got messed up with mixed cells as well that I have to wait to be adressed --- .../tracerParticles2DHDF5Monitor/domain.xmf | 512 ++++-------------- 1 file changed, 96 insertions(+), 416 deletions(-) diff --git a/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf b/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf index a4219e7f6..ff517f8c9 100644 --- a/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf +++ b/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf @@ -39,20 +39,10 @@ - - - - 0 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 0 0 1 1 1 2 1 25 1 + 0 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -79,20 +69,10 @@ - - - - 0 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 0 0 1 1 1 2 1 25 1 + 0 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -131,20 +111,10 @@ - - - - 1 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 1 0 1 1 1 2 1 25 1 + 1 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -171,20 +141,10 @@ - - - - 1 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 1 0 1 1 1 2 1 25 1 + 1 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -223,20 +183,10 @@ - - - - 2 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 2 0 1 1 1 2 1 25 1 + 2 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -263,20 +213,10 @@ - - - - 2 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 2 0 1 1 1 2 1 25 1 + 2 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -315,20 +255,10 @@ - - - - 3 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 3 0 1 1 1 2 1 25 1 + 3 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -355,20 +285,10 @@ - - - - 3 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 3 0 1 1 1 2 1 25 1 + 3 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -407,20 +327,10 @@ - - - - 4 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 4 0 1 1 1 2 1 25 1 + 4 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -447,20 +357,10 @@ - - - - 4 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 4 0 1 1 1 2 1 25 1 + 4 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -499,20 +399,10 @@ - - - - 5 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 5 0 1 1 1 2 1 25 1 + 5 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -539,20 +429,10 @@ - - - - 5 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 5 0 1 1 1 2 1 25 1 + 5 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -591,20 +471,10 @@ - - - - 6 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 6 0 1 1 1 2 1 25 1 + 6 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -631,20 +501,10 @@ - - - - 6 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 6 0 1 1 1 2 1 25 1 + 6 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -683,20 +543,10 @@ - - - - 7 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 7 0 1 1 1 2 1 25 1 + 7 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -723,20 +573,10 @@ - - - - 7 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 7 0 1 1 1 2 1 25 1 + 7 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -775,20 +615,10 @@ - - - - 8 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 8 0 1 1 1 2 1 25 1 + 8 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -815,20 +645,10 @@ - - - - 8 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 8 0 1 1 1 2 1 25 1 + 8 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -867,20 +687,10 @@ - - - - 9 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 9 0 1 1 1 2 1 25 1 + 9 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -907,20 +717,10 @@ - - - - 9 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 9 0 1 1 1 2 1 25 1 + 9 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -959,20 +759,10 @@ - - - - 10 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 10 0 1 1 1 2 1 25 1 + 10 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -999,20 +789,10 @@ - - - - 10 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 10 0 1 1 1 2 1 25 1 + 10 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -1051,20 +831,10 @@ - - - - 11 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 11 0 1 1 1 2 1 25 1 + 11 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -1091,20 +861,10 @@ - - - - 11 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 11 0 1 1 1 2 1 25 1 + 11 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -1143,20 +903,10 @@ - - - - 12 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 12 0 1 1 1 2 1 25 1 + 12 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -1183,20 +933,10 @@ - - - - 12 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 12 0 1 1 1 2 1 25 1 + 12 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -1235,20 +975,10 @@ - - - - 13 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 13 0 1 1 1 2 1 25 1 + 13 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -1275,20 +1005,10 @@ - - - - 13 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 13 0 1 1 1 2 1 25 1 + 13 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -1327,20 +1047,10 @@ - - - - 14 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 14 0 1 1 1 2 1 25 1 + 14 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -1367,20 +1077,10 @@ - - - - 14 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 14 0 1 1 1 2 1 25 1 + 14 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity @@ -1419,20 +1119,10 @@ - - - - 15 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/exact_velocity - - - - - + + - 15 0 1 1 1 2 1 25 1 + 15 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/exact_velocity @@ -1459,20 +1149,10 @@ - - - - 15 0 0 1 1 2 1 25 1 - - - domain.hdf5:/vertex_fields/solution_velocity - - - - - + + - 15 0 1 1 1 2 1 25 1 + 15 0 0 1 1 1 1 25 2 domain.hdf5:/vertex_fields/solution_velocity From 43d991adafbe0d71b1d29872fa1e8da0f3261452 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Thu, 3 Oct 2024 11:11:17 -0400 Subject: [PATCH 02/19] Allow for multiple Fields to be updated in a flux/rhs calculation. --- src/finiteVolume/cellInterpolant.cpp | 59 ++++++++++--------- src/finiteVolume/cellInterpolant.hpp | 2 +- src/finiteVolume/faceInterpolant.cpp | 57 +++++++++--------- src/finiteVolume/faceInterpolant.hpp | 2 +- src/finiteVolume/finiteVolumeSolver.cpp | 24 +++++--- src/finiteVolume/finiteVolumeSolver.hpp | 6 +- src/finiteVolume/processes/evTransport.cpp | 10 ++-- src/finiteVolume/processes/les.cpp | 10 ++-- .../processes/navierStokesTransport.cpp | 7 ++- .../processes/navierStokesTransport.hpp | 20 +++---- .../processes/speciesTransport.cpp | 10 ++-- .../processes/speciesTransport.hpp | 1 - .../processes/thermophoreticDiffusion.cpp | 6 +- .../processes/twoPhaseEulerAdvection.cpp | 4 +- 14 files changed, 115 insertions(+), 103 deletions(-) diff --git a/src/finiteVolume/cellInterpolant.cpp b/src/finiteVolume/cellInterpolant.cpp index e3f814ec7..389dc5d08 100644 --- a/src/finiteVolume/cellInterpolant.cpp +++ b/src/finiteVolume/cellInterpolant.cpp @@ -499,8 +499,8 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD PetscScalar *auxL = nullptr, *auxR = nullptr; // Precompute the offsets to pass into the rhsFluxFunctionDescriptions - std::vector fluxComponentSize(rhsFunctions.size()); - std::vector fluxId(rhsFunctions.size()); + std::vector> fluxComponentSize(rhsFunctions.size()); + std::vector> fluxId(rhsFunctions.size()); std::vector> uOff(rhsFunctions.size()); std::vector> aOff(rhsFunctions.size()); @@ -509,9 +509,11 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD PetscDSGetComponentOffsets(ds, &uOffTotal) >> utilities::PetscUtilities::checkError; for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { - const auto& field = subDomain->GetField(rhsFunctions[fun].field); - fluxComponentSize[fun] = field.numberComponents; - fluxId[fun] = field.id; + for (std::size_t f = 0; f < rhsFunctions[fun].updateFields.size(); f++) { + const auto& field = subDomain->GetField(rhsFunctions[fun].updateFields[f]); + fluxComponentSize[fun].push_back(field.numberComponents); + fluxId[fun].push_back(field.id); + } for (std::size_t f = 0; f < rhsFunctions[fun].inputFields.size(); f++) { uOff[fun].push_back(uOffTotal[rhsFunctions[fun].inputFields[f]]); } @@ -534,7 +536,6 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD DMLabel regionLabel = nullptr; PetscInt regionValue = 0; domain::Region::GetLabel(solverRegion, subDomain->GetDM(), regionLabel, regionValue); - // March over each face in this region for (PetscInt f = faceRange.start; f < faceRange.end; ++f) { const PetscInt face = faceRange.points ? faceRange.points[f] : f; @@ -571,36 +572,36 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD DMPlexPointLocalRead(dmAux, faceCells[0], auxArray, &auxL) >> utilities::PetscUtilities::checkError; DMPlexPointLocalRead(dmAux, faceCells[1], auxArray, &auxR) >> utilities::PetscUtilities::checkError; } - // March over each source function for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { PetscArrayzero(flux, totDim) >> utilities::PetscUtilities::checkError; const auto& rhsFluxFunctionDescription = rhsFunctions[fun]; rhsFluxFunctionDescription.function(dim, fg, uOff[fun].data(), uL, uR, aOff[fun].data(), auxL, auxR, flux, rhsFluxFunctionDescription.context) >> utilities::PetscUtilities::checkError; + // add the fluxes back to the cell + for (std::size_t updateFieldIdx = 0; updateFieldIdx < rhsFunctions[fun].updateFields.size(); updateFieldIdx++) { + PetscInt cellLabelValue = regionValue; + PetscScalar *fL = nullptr, *fR = nullptr; + DMLabelGetValue(ghostLabel, faceCells[0], &ghost) >> utilities::PetscUtilities::checkError; + if (regionLabel) { + DMLabelGetValue(regionLabel, faceCells[0], &cellLabelValue) >> utilities::PetscUtilities::checkError; + } + if (ghost <= 0 && regionValue == cellLabelValue) { + DMPlexPointLocalFieldRef(dm, faceCells[0], fluxId[fun][updateFieldIdx], locFArray, &fL) >> utilities::PetscUtilities::checkError; + } - // add the flux back to the cell - PetscScalar *fL = nullptr, *fR = nullptr; - PetscInt cellLabelValue = regionValue; - DMLabelGetValue(ghostLabel, faceCells[0], &ghost) >> utilities::PetscUtilities::checkError; - if (regionLabel) { - DMLabelGetValue(regionLabel, faceCells[0], &cellLabelValue) >> utilities::PetscUtilities::checkError; - } - if (ghost <= 0 && regionValue == cellLabelValue) { - DMPlexPointLocalFieldRef(dm, faceCells[0], fluxId[fun], locFArray, &fL) >> utilities::PetscUtilities::checkError; - } - - cellLabelValue = regionValue; - DMLabelGetValue(ghostLabel, faceCells[1], &ghost) >> utilities::PetscUtilities::checkError; - if (regionLabel) { - DMLabelGetValue(regionLabel, faceCells[1], &cellLabelValue) >> utilities::PetscUtilities::checkError; - } - if (ghost <= 0 && regionValue == cellLabelValue) { - DMPlexPointLocalFieldRef(dm, faceCells[1], fluxId[fun], locFArray, &fR) >> utilities::PetscUtilities::checkError; - } + cellLabelValue = regionValue; + DMLabelGetValue(ghostLabel, faceCells[1], &ghost) >> utilities::PetscUtilities::checkError; + if (regionLabel) { + DMLabelGetValue(regionLabel, faceCells[1], &cellLabelValue) >> utilities::PetscUtilities::checkError; + } + if (ghost <= 0 && regionValue == cellLabelValue) { + DMPlexPointLocalFieldRef(dm, faceCells[1], fluxId[fun][updateFieldIdx], locFArray, &fR) >> utilities::PetscUtilities::checkError; + } - for (PetscInt d = 0; d < fluxComponentSize[fun]; ++d) { - if (fL) fL[d] -= flux[d] / cgL->volume; - if (fR) fR[d] += flux[d] / cgR->volume; + for (PetscInt d = 0; d < fluxComponentSize[fun][updateFieldIdx]; ++d) { + if (fL) fL[d] -= flux[d] / cgL->volume; + if (fR) fR[d] += flux[d] / cgR->volume; + } } } } diff --git a/src/finiteVolume/cellInterpolant.hpp b/src/finiteVolume/cellInterpolant.hpp index 97fe51c64..6bfbdc7c9 100644 --- a/src/finiteVolume/cellInterpolant.hpp +++ b/src/finiteVolume/cellInterpolant.hpp @@ -26,7 +26,7 @@ class CellInterpolant { DiscontinuousFluxFunction function; void* context; - PetscInt field; + std::vector updateFields; std::vector inputFields; std::vector auxFields; }; diff --git a/src/finiteVolume/faceInterpolant.cpp b/src/finiteVolume/faceInterpolant.cpp index 7be985a2b..9ea4b442a 100644 --- a/src/finiteVolume/faceInterpolant.cpp +++ b/src/finiteVolume/faceInterpolant.cpp @@ -314,8 +314,8 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV ablate::domain::Region::GetLabel(solverRegion, subDomain->GetDM(), regionLabel, regionValue); // Precompute the offsets to pass into the rhsFluxFunctionDescriptions - std::vector fluxComponentSize(rhsFunctions.size()); - std::vector fluxId(rhsFunctions.size()); + std::vector> fluxComponentSize(rhsFunctions.size()); + std::vector> fluxId(rhsFunctions.size()); std::vector> uOff(rhsFunctions.size()); std::vector> aOff(rhsFunctions.size()); std::vector> uOff_x(rhsFunctions.size()); @@ -328,9 +328,11 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV PetscDSGetComponentDerivativeOffsets(subDomain->GetDiscreteSystem(), &uGradOffTotal) >> utilities::PetscUtilities::checkError; for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { - const auto& field = subDomain->GetField(rhsFunctions[fun].field); - fluxComponentSize[fun] = field.numberComponents; - fluxId[fun] = field.id; + for (std::size_t f = 0; f < rhsFunctions[fun].updateFields.size(); f++) { + const auto& field = subDomain->GetField(rhsFunctions[fun].updateFields[f]); + fluxComponentSize[fun].push_back(field.numberComponents); + fluxId[fun].push_back(field.id); + } for (std::size_t f = 0; f < rhsFunctions[fun].inputFields.size(); f++) { uOff[fun].push_back(uOffTotal[rhsFunctions[fun].inputFields[f]]); uOff_x[fun].push_back(uGradOffTotal[rhsFunctions[fun].inputFields[f]]); @@ -402,30 +404,31 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV flux.data(), rhsFluxFunctionDescription.context) >> utilities::PetscUtilities::checkError; + for (std::size_t updateFieldIdx = 0; updateFieldIdx < rhsFunctions[fun].updateFields.size(); updateFieldIdx++) { + // add the flux back to the cell + PetscScalar *fL = nullptr, *fR = nullptr; + PetscInt cellLabelValue = regionValue; + DMLabelGetValue(ghostLabel, faceCells[0], &ghost) >> utilities::PetscUtilities::checkError; + if (regionLabel) { + DMLabelGetValue(regionLabel, faceCells[0], &cellLabelValue) >> utilities::PetscUtilities::checkError; + } + if (ghost <= 0 && regionValue == cellLabelValue) { + DMPlexPointLocalFieldRef(dm, faceCells[0], rhsFunctions[fun].updateFields[updateFieldIdx], locFArray, &fL) >> utilities::PetscUtilities::checkError; + } - // add the flux back to the cell - PetscScalar *fL = nullptr, *fR = nullptr; - PetscInt cellLabelValue = regionValue; - DMLabelGetValue(ghostLabel, faceCells[0], &ghost) >> utilities::PetscUtilities::checkError; - if (regionLabel) { - DMLabelGetValue(regionLabel, faceCells[0], &cellLabelValue) >> utilities::PetscUtilities::checkError; - } - if (ghost <= 0 && regionValue == cellLabelValue) { - DMPlexPointLocalFieldRef(dm, faceCells[0], rhsFunctions[fun].field, locFArray, &fL) >> utilities::PetscUtilities::checkError; - } - - cellLabelValue = regionValue; - DMLabelGetValue(ghostLabel, faceCells[1], &ghost) >> utilities::PetscUtilities::checkError; - if (regionLabel) { - DMLabelGetValue(regionLabel, faceCells[1], &cellLabelValue) >> utilities::PetscUtilities::checkError; - } - if (ghost <= 0 && regionValue == cellLabelValue) { - DMPlexPointLocalFieldRef(dm, faceCells[1], rhsFunctions[fun].field, locFArray, &fR) >> utilities::PetscUtilities::checkError; - } + cellLabelValue = regionValue; + DMLabelGetValue(ghostLabel, faceCells[1], &ghost) >> utilities::PetscUtilities::checkError; + if (regionLabel) { + DMLabelGetValue(regionLabel, faceCells[1], &cellLabelValue) >> utilities::PetscUtilities::checkError; + } + if (ghost <= 0 && regionValue == cellLabelValue) { + DMPlexPointLocalFieldRef(dm, faceCells[1], rhsFunctions[fun].updateFields[updateFieldIdx], locFArray, &fR) >> utilities::PetscUtilities::checkError; + } - for (PetscInt d = 0; d < fluxComponentSize[fun]; ++d) { - if (fL) fL[d] -= flux[d] / cgL->volume; - if (fR) fR[d] += flux[d] / cgR->volume; + for (PetscInt d = 0; d < fluxComponentSize[fun][updateFieldIdx]; ++d) { + if (fL) fL[d] -= flux[d] / cgL->volume; + if (fR) fR[d] += flux[d] / cgR->volume; + } } } } diff --git a/src/finiteVolume/faceInterpolant.hpp b/src/finiteVolume/faceInterpolant.hpp index e2637bdc3..0a0cabd9c 100644 --- a/src/finiteVolume/faceInterpolant.hpp +++ b/src/finiteVolume/faceInterpolant.hpp @@ -85,7 +85,7 @@ class FaceInterpolant { ContinuousFluxFunction function; void* context; - PetscInt field; + std::vector updateFields; std::vector inputFields; std::vector auxFields; }; diff --git a/src/finiteVolume/finiteVolumeSolver.cpp b/src/finiteVolume/finiteVolumeSolver.cpp index 80d7d74e4..11a2f116a 100644 --- a/src/finiteVolume/finiteVolumeSolver.cpp +++ b/src/finiteVolume/finiteVolumeSolver.cpp @@ -290,13 +290,16 @@ PetscErrorCode ablate::finiteVolume::FiniteVolumeSolver::ComputeRHSFunction(Pets PetscFunctionReturn(0); } -void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(CellInterpolant::DiscontinuousFluxFunction function, void* context, const std::string& field, + +void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(CellInterpolant::DiscontinuousFluxFunction function, void* context, const std::vector& fields, const std::vector& inputFields, const std::vector& auxFields) { - // map the field, inputFields, and auxFields to locations - auto& fieldId = subDomain->GetField(field); + CellInterpolant::DiscontinuousFluxFunctionDescription functionDescription{.function = function, .context = context}; - // Create the FVMRHS Function - CellInterpolant::DiscontinuousFluxFunctionDescription functionDescription{.function = function, .context = context, .field = fieldId.id}; + // map the field, inputFields, and auxFields to locations + for (auto& field : fields){ + auto& fieldId = subDomain->GetField(field); + functionDescription.updateFields.push_back(fieldId.id); + } for (auto& inputField : inputFields) { auto& inputFieldId = subDomain->GetField(inputField); @@ -311,13 +314,18 @@ void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(CellInterpola discontinuousFluxFunctionDescriptions.push_back(functionDescription); } -void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(ablate::finiteVolume::FaceInterpolant::ContinuousFluxFunction function, void* context, const std::string& field, + +void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(ablate::finiteVolume::FaceInterpolant::ContinuousFluxFunction function, void* context, const std::vector& updateFields, const std::vector& inputFields, const std::vector& auxFields) { // map the field, inputFields, and auxFields to locations - auto& fieldId = subDomain->GetField(field); + FaceInterpolant::ContinuousFluxFunctionDescription functionDescription{.function = function, .context = context}; + for (auto& field: updateFields) { + auto& fieldId = subDomain->GetField(field); + functionDescription.updateFields.push_back(fieldId.id); + } // Create the FVMRHS Function - FaceInterpolant::ContinuousFluxFunctionDescription functionDescription{.function = function, .context = context, .field = fieldId.id}; + for (auto& inputField : inputFields) { auto& inputFieldId = subDomain->GetField(inputField); diff --git a/src/finiteVolume/finiteVolumeSolver.hpp b/src/finiteVolume/finiteVolumeSolver.hpp index bfa46ab3d..fd40dc2cf 100644 --- a/src/finiteVolume/finiteVolumeSolver.hpp +++ b/src/finiteVolume/finiteVolumeSolver.hpp @@ -111,14 +111,14 @@ class FiniteVolumeSolver : public solver::CellSolver, PetscErrorCode ComputeBoundary(PetscReal time, Vec locX, Vec locX_t) override; /** - * Register a FVM rhs discontinuous flux function + * Register a FVM rhs discontinuous flux function for multiple fields * @param function * @param context * @param field * @param inputFields * @param auxFields */ - void RegisterRHSFunction(CellInterpolant::DiscontinuousFluxFunction function, void* context, const std::string& field, const std::vector& inputFields, + void RegisterRHSFunction(CellInterpolant::DiscontinuousFluxFunction function, void* context, const std::vector& field, const std::vector& inputFields, const std::vector& auxFields); /** @@ -129,7 +129,7 @@ class FiniteVolumeSolver : public solver::CellSolver, * @param inputFields * @param auxFields */ - void RegisterRHSFunction(FaceInterpolant::ContinuousFluxFunction function, void* context, const std::string& field, const std::vector& inputFields, + void RegisterRHSFunction(FaceInterpolant::ContinuousFluxFunction function, void* context, const std::vector& fields, const std::vector& inputFields, const std::vector& auxFields); /** diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index ee2de66cf..0cde39ae9 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -39,7 +39,7 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, evConservedField.name, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}, {}); + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}, {}); } if (transportModel) { @@ -49,9 +49,9 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F if (diffusionData.diffFunction.function) { if (diffusionData.diffFunction.propertySize == 1) { - flow.RegisterRHSFunction(DiffusionEVFlux, &diffusionData, evConservedField.name, {CompressibleFlowFields::EULER_FIELD}, {nonConserved}); + flow.RegisterRHSFunction(DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved,CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.diffFunction.propertySize == diffusionData.numberEV) { - flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, evConservedField.name, {CompressibleFlowFields::EULER_FIELD}, {nonConserved}); + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved}); } else { throw std::invalid_argument("The diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::EVTransport."); } @@ -231,7 +231,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFlux(Pet // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - +// const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in // compute diff PetscReal diff = 0.0; flowParameters->diffFunction.function(field, &diff, flowParameters->diffFunction.context.get()); @@ -263,7 +263,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFluxVari // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - +// const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in // compute diff flowParameters->diffFunction.function(field, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); diff --git a/src/finiteVolume/processes/les.cpp b/src/finiteVolume/processes/les.cpp index 7db5010f0..64dfa33b6 100644 --- a/src/finiteVolume/processes/les.cpp +++ b/src/finiteVolume/processes/les.cpp @@ -24,21 +24,21 @@ void ablate::finiteVolume::processes::LES::Setup(ablate::finiteVolume::FiniteVol // Register the euler/Energy LESdiffusion source term tke flow.RegisterRHSFunction(LesEnergyFlux, nullptr, - CompressibleFlowFields::EULER_FIELD, + {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::VELOCITY_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); // Register the N_S LESdiffusion source terms - flow.RegisterRHSFunction(LesMomentumFlux, nullptr, CompressibleFlowFields::EULER_FIELD, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::VELOCITY_FIELD}); + flow.RegisterRHSFunction(LesMomentumFlux, nullptr, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::VELOCITY_FIELD}); // Register the tke LESdiffusion source term - flow.RegisterRHSFunction(LesTkeFlux, nullptr, conservedFieldName, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::VELOCITY_FIELD}); + flow.RegisterRHSFunction(LesTkeFlux, nullptr, {conservedFieldName}, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::VELOCITY_FIELD}); // Register the Species LESdiffusion source term if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::DENSITY_YI_FIELD)) { // the species are treated like any other transported ev auto& numberComponent = numberComponents.emplace_back(flow.GetSubDomain().GetField(CompressibleFlowFields::YI_FIELD).numberComponents); - flow.RegisterRHSFunction(LesEvFlux, &numberComponent, CompressibleFlowFields::DENSITY_YI_FIELD, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::YI_FIELD}); + flow.RegisterRHSFunction(LesEvFlux, &numberComponent, {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {tkeField, CompressibleFlowFields::YI_FIELD}); } // March over any ev @@ -48,7 +48,7 @@ void ablate::finiteVolume::processes::LES::Setup(ablate::finiteVolume::FiniteVol // the species are treated like any other transported ev auto& numberComponent = numberComponents.emplace_back(evConservedField.numberComponents); - flow.RegisterRHSFunction(LesEvFlux, &numberComponent, evConservedField.name, {CompressibleFlowFields::EULER_FIELD}, {tkeField, nonConservedEvName}); + flow.RegisterRHSFunction(LesEvFlux, &numberComponent, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {tkeField, nonConservedEvName}); } } diff --git a/src/finiteVolume/processes/navierStokesTransport.cpp b/src/finiteVolume/processes/navierStokesTransport.cpp index 27eed9f1a..420148ec7 100644 --- a/src/finiteVolume/processes/navierStokesTransport.cpp +++ b/src/finiteVolume/processes/navierStokesTransport.cpp @@ -35,7 +35,9 @@ ablate::finiteVolume::processes::NavierStokesTransport::NavierStokesTransport(co void ablate::finiteVolume::processes::NavierStokesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) { // Register the euler source terms if (fluxCalculator) { - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, CompressibleFlowFields::EULER_FIELD, {CompressibleFlowFields::EULER_FIELD}, {}); + //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + //If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); // PetscErrorCode PetscOptionsGetBool(PetscOptions options,const char pre[],const char name[],PetscBool *ivalue,PetscBool *set) flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); @@ -56,7 +58,7 @@ void ablate::finiteVolume::processes::NavierStokesTransport::Setup(ablate::finit // Register the euler diffusion source terms flow.RegisterRHSFunction(DiffusionFlux, &diffusionData, - CompressibleFlowFields::EULER_FIELD, + {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); } @@ -255,6 +257,7 @@ double ablate::finiteVolume::processes::NavierStokesTransport::ComputeCflTimeSte PetscReal rho = euler[CompressibleFlowFields::RHO]; // Get the speed of sound from the eos + //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) PetscReal temperature; advectionData->computeTemperature.function(conserved, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; PetscReal a; diff --git a/src/finiteVolume/processes/navierStokesTransport.hpp b/src/finiteVolume/processes/navierStokesTransport.hpp index b957f2285..787cb8237 100644 --- a/src/finiteVolume/processes/navierStokesTransport.hpp +++ b/src/finiteVolume/processes/navierStokesTransport.hpp @@ -38,7 +38,14 @@ class NavierStokesTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction muFunction; }; - private: + // static function to compute time step for euler advection + static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + +private: const std::shared_ptr fluxCalculator; const std::shared_ptr eos; const std::shared_ptr transportModel; @@ -81,16 +88,7 @@ class NavierStokesTransport : public FlowProcess { }; DiffusionTimeStepData diffusionTimeStepData; - // static function to compute time step for euler advection - static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); - - // static function to compute the conduction based time step - static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); - - // static function to compute the conduction based time step - static double ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); - - public: + public: /** * Function to compute the temperature field. This function assumes that the input values will be {"euler", "densityYi"} */ diff --git a/src/finiteVolume/processes/speciesTransport.cpp b/src/finiteVolume/processes/speciesTransport.cpp index c4f741967..da696fe86 100644 --- a/src/finiteVolume/processes/speciesTransport.cpp +++ b/src/finiteVolume/processes/speciesTransport.cpp @@ -35,7 +35,7 @@ ablate::finiteVolume::processes::SpeciesTransport::SpeciesTransport(std::shared_ void ablate::finiteVolume::processes::SpeciesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { if (!eos->GetSpeciesVariables().empty()) { if (fluxCalculator) { - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, CompressibleFlowFields::DENSITY_YI_FIELD, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {}); + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); advectionData.computeTemperature = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); @@ -49,23 +49,23 @@ void ablate::finiteVolume::processes::SpeciesTransport::Setup(ablate::finiteVolu if (diffusionData.diffFunction.propertySize == 1) { flow.RegisterRHSFunction(DiffusionEnergyFlux, &diffusionData, - CompressibleFlowFields::EULER_FIELD, + {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); flow.RegisterRHSFunction(DiffusionSpeciesFlux, &diffusionData, - CompressibleFlowFields::DENSITY_YI_FIELD, + {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.diffFunction.propertySize == numberSpecies) { flow.RegisterRHSFunction(DiffusionEnergyFluxVariableDiffusionCoefficient, &diffusionData, - CompressibleFlowFields::EULER_FIELD, + {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); flow.RegisterRHSFunction(DiffusionSpeciesFluxVariableDiffusionCoefficient, &diffusionData, - CompressibleFlowFields::DENSITY_YI_FIELD, + {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); } else { diff --git a/src/finiteVolume/processes/speciesTransport.hpp b/src/finiteVolume/processes/speciesTransport.hpp index 8f2863124..4a5305bdf 100644 --- a/src/finiteVolume/processes/speciesTransport.hpp +++ b/src/finiteVolume/processes/speciesTransport.hpp @@ -87,7 +87,6 @@ class SpeciesTransport : public FlowProcess { */ static void NormalizeSpecies(TS ts, ablate::solver::Solver&); - private: /** * This computes the energy transfer for species diffusion flux for rhoE * f = "euler" diff --git a/src/finiteVolume/processes/thermophoreticDiffusion.cpp b/src/finiteVolume/processes/thermophoreticDiffusion.cpp index f1aebceff..4a5ea334d 100644 --- a/src/finiteVolume/processes/thermophoreticDiffusion.cpp +++ b/src/finiteVolume/processes/thermophoreticDiffusion.cpp @@ -9,17 +9,17 @@ ablate::finiteVolume::processes::ThermophoreticDiffusion::ThermophoreticDiffusio void ablate::finiteVolume::processes::ThermophoreticDiffusion::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { flow.RegisterRHSFunction(ThermophoreticDiffusionEnergyFlux, &viscosityTemperatureFunction, - CompressibleFlowFields::EULER_FIELD, + {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD, CompressibleFlowFields::DENSITY_PROGRESS_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); flow.RegisterRHSFunction(ThermophoreticDiffusionVariableFlux, &viscosityTemperatureFunction, - CompressibleFlowFields::DENSITY_YI_FIELD, + {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); flow.RegisterRHSFunction(ThermophoreticDiffusionVariableFlux, &viscosityTemperatureFunction, - CompressibleFlowFields::DENSITY_PROGRESS_FIELD, + {CompressibleFlowFields::DENSITY_PROGRESS_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_PROGRESS_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); diff --git a/src/finiteVolume/processes/twoPhaseEulerAdvection.cpp b/src/finiteVolume/processes/twoPhaseEulerAdvection.cpp index b7247b0ad..8f045c18e 100644 --- a/src/finiteVolume/processes/twoPhaseEulerAdvection.cpp +++ b/src/finiteVolume/processes/twoPhaseEulerAdvection.cpp @@ -232,8 +232,8 @@ void ablate::finiteVolume::processes::TwoPhaseEulerAdvection::Setup(ablate::fini decoder = CreateTwoPhaseDecoder(flow.GetSubDomain().GetDimensions(), eosGas, eosLiquid); // Currently, no option for species advection - flow.RegisterRHSFunction(CompressibleFlowComputeEulerFlux, this, CompressibleFlowFields::EULER_FIELD, {VOLUME_FRACTION_FIELD, DENSITY_VF_FIELD, CompressibleFlowFields::EULER_FIELD}, {}); - flow.RegisterRHSFunction(CompressibleFlowComputeVFFlux, this, DENSITY_VF_FIELD, {VOLUME_FRACTION_FIELD, DENSITY_VF_FIELD, CompressibleFlowFields::EULER_FIELD}, {}); + flow.RegisterRHSFunction(CompressibleFlowComputeEulerFlux, this, {CompressibleFlowFields::EULER_FIELD}, {VOLUME_FRACTION_FIELD, DENSITY_VF_FIELD, CompressibleFlowFields::EULER_FIELD}, {}); + flow.RegisterRHSFunction(CompressibleFlowComputeVFFlux, this, {DENSITY_VF_FIELD}, {VOLUME_FRACTION_FIELD, DENSITY_VF_FIELD, CompressibleFlowFields::EULER_FIELD}, {}); flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); timeStepData.computeSpeedOfSound = eosTwoPhase->GetThermodynamicFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); From 12de3667a02ea0e6490c45c64d5d365c779ac35f Mon Sep 17 00:00:00 2001 From: klbudzin Date: Thu, 3 Oct 2024 11:48:39 -0400 Subject: [PATCH 03/19] NavierStokes Interpolate advection Temperature --- src/finiteVolume/processes/navierStokesTransport.cpp | 9 +++++---- src/finiteVolume/processes/navierStokesTransport.hpp | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/finiteVolume/processes/navierStokesTransport.cpp b/src/finiteVolume/processes/navierStokesTransport.cpp index 420148ec7..54d79f579 100644 --- a/src/finiteVolume/processes/navierStokesTransport.cpp +++ b/src/finiteVolume/processes/navierStokesTransport.cpp @@ -42,7 +42,7 @@ void ablate::finiteVolume::processes::NavierStokesTransport::Setup(ablate::finit // PetscErrorCode PetscOptionsGetBool(PetscOptions options,const char pre[],const char name[],PetscBool *ivalue,PetscBool *set) flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); - advectionData.computeTemperature = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); @@ -104,6 +104,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection auto eulerAdvectionData = (AdvectionData*)ctx; const int EULER_FIELD = 0; + const int TEMP_FIELD = 0; // Compute the norm PetscReal norm[3]; @@ -123,7 +124,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -148,7 +149,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -259,7 +260,7 @@ double ablate::finiteVolume::processes::NavierStokesTransport::ComputeCflTimeSte // Get the speed of sound from the eos //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) PetscReal temperature; - advectionData->computeTemperature.function(conserved, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; + advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; PetscReal a; advectionData->computeSpeedOfSound.function(conserved, temperature, &a, advectionData->computeSpeedOfSound.context.get()) >> utilities::PetscUtilities::checkError; diff --git a/src/finiteVolume/processes/navierStokesTransport.hpp b/src/finiteVolume/processes/navierStokesTransport.hpp index 787cb8237..58478e663 100644 --- a/src/finiteVolume/processes/navierStokesTransport.hpp +++ b/src/finiteVolume/processes/navierStokesTransport.hpp @@ -20,7 +20,7 @@ class NavierStokesTransport : public FlowProcess { PetscInt numberSpecies; // EOS function calls - eos::ThermodynamicFunction computeTemperature; + eos::ThermodynamicTemperatureFunction computeTemperature; eos::ThermodynamicTemperatureFunction computeInternalEnergy; eos::ThermodynamicTemperatureFunction computeSpeedOfSound; eos::ThermodynamicTemperatureFunction computePressure; From 3b3efc4ddf321484ddf3f1219e4c4a636dcd7c53 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Thu, 3 Oct 2024 11:50:17 -0400 Subject: [PATCH 04/19] Test fix wasn't included --- .../finiteVolume/processes/navierStokesTransportTests.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp b/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp index b7bd3c303..32c049315 100644 --- a/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp +++ b/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp @@ -30,7 +30,7 @@ TEST_P(NavierStokesTransportFluxTestFixture, ShouldComputeCorrectFlux) { // set a perfect gas for testing auto eos = std::make_shared(std::make_shared()); auto eulerFieldMock = ablateTesting::domain::MockField::Create("euler", 3); - eulerFlowData.computeTemperature = eos->GetThermodynamicFunction(ablate::eos::ThermodynamicProperty::Temperature, {eulerFieldMock}); + eulerFlowData.computeTemperature = eos->GetThermodynamicTemperatureFunction(ablate::eos::ThermodynamicProperty::Temperature, {eulerFieldMock}); eulerFlowData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(ablate::eos::ThermodynamicProperty::InternalSensibleEnergy, {eulerFieldMock}); eulerFlowData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(ablate::eos::ThermodynamicProperty::SpeedOfSound, {eulerFieldMock}); eulerFlowData.computePressure = eos->GetThermodynamicTemperatureFunction(ablate::eos::ThermodynamicProperty::Pressure, {eulerFieldMock}); @@ -42,7 +42,9 @@ TEST_P(NavierStokesTransportFluxTestFixture, ShouldComputeCorrectFlux) { // act std::vector computedFlux(params.expectedFlux.size()); PetscInt uOff[1] = {0}; - ablate::finiteVolume::processes::NavierStokesTransport::AdvectionFlux(params.area.size(), &faceGeom, uOff, ¶ms.xLeft[0], ¶ms.xRight[0], NULL, NULL, NULL, &computedFlux[0], &eulerFlowData); + PetscInt aOff[1] = {0}; + PetscReal TempGuess[1] = {300}; + ablate::finiteVolume::processes::NavierStokesTransport::AdvectionFlux(params.area.size(), &faceGeom, uOff, ¶ms.xLeft[0], ¶ms.xRight[0], aOff, TempGuess, TempGuess, &computedFlux[0], &eulerFlowData); // assert for (std::size_t i = 0; i < params.expectedFlux.size(); i++) { From a65b89da703d4cbfc7643260ecf7c186754a86e7 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Thu, 3 Oct 2024 12:00:40 -0400 Subject: [PATCH 05/19] Add species and EV Guess temperatures --- src/finiteVolume/processes/evTransport.cpp | 18 +++++++++--------- src/finiteVolume/processes/evTransport.hpp | 4 ++-- .../processes/speciesTransport.cpp | 6 +++--- .../processes/speciesTransport.hpp | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index 0cde39ae9..560b22eb2 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -34,18 +34,18 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); // set decode state functions - advectionData.computeTemperature = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}, {}); + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}, {CompressibleFlowFields::TEMPERATURE_FIELD}); } if (transportModel) { diffusionData.evDiffusionCoefficient.resize(diffusionData.numberEV); - diffusionData.diffFunction = transportModel->GetTransportFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); if (diffusionData.diffFunction.function) { if (diffusionData.diffFunction.propertySize == 1) { @@ -160,7 +160,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67 + auxR[aOff[0]]*.33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -184,7 +184,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]]*.33 + auxR[aOff[0]]*.67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -231,10 +231,10 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFlux(Pet // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; -// const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in // compute diff PetscReal diff = 0.0; - flowParameters->diffFunction.function(field, &diff, flowParameters->diffFunction.context.get()); + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); // species equations for (PetscInt ev = 0; ev < flowParameters->numberEV; ++ev) { @@ -263,9 +263,9 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFluxVari // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; -// const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in // compute diff - flowParameters->diffFunction.function(field, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + flowParameters->diffFunction.function(field, temperature, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); // species equations for (PetscInt ev = 0; ev < flowParameters->numberEV; ++ev) { diff --git a/src/finiteVolume/processes/evTransport.hpp b/src/finiteVolume/processes/evTransport.hpp index 1d7283924..159e2ed42 100644 --- a/src/finiteVolume/processes/evTransport.hpp +++ b/src/finiteVolume/processes/evTransport.hpp @@ -25,7 +25,7 @@ class EVTransport : public FlowProcess { PetscInt numberEV; // EOS function calls - eos::ThermodynamicFunction computeTemperature; + eos::ThermodynamicTemperatureFunction computeTemperature; eos::ThermodynamicTemperatureFunction computeInternalEnergy; eos::ThermodynamicTemperatureFunction computeSpeedOfSound; eos::ThermodynamicTemperatureFunction computePressure; @@ -40,7 +40,7 @@ class EVTransport : public FlowProcess { PetscInt numberEV; /* functions to compute diffusion */ - eos::ThermodynamicFunction diffFunction; + eos::ThermodynamicTemperatureFunction diffFunction; /* store a scratch space for evDiffusionCoefficient */ std::vector evDiffusionCoefficient; diff --git a/src/finiteVolume/processes/speciesTransport.cpp b/src/finiteVolume/processes/speciesTransport.cpp index da696fe86..6bae73fe1 100644 --- a/src/finiteVolume/processes/speciesTransport.cpp +++ b/src/finiteVolume/processes/speciesTransport.cpp @@ -36,7 +36,7 @@ void ablate::finiteVolume::processes::SpeciesTransport::Setup(ablate::finiteVolu if (!eos->GetSpeciesVariables().empty()) { if (fluxCalculator) { flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); - advectionData.computeTemperature = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); @@ -280,7 +280,7 @@ PetscErrorCode ablate::finiteVolume::processes::SpeciesTransport::AdvectionFlux( densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67 + auxR[aOff[0]]*.33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -302,7 +302,7 @@ PetscErrorCode ablate::finiteVolume::processes::SpeciesTransport::AdvectionFlux( densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]]*.33 + auxR[aOff[0]]*.67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; diff --git a/src/finiteVolume/processes/speciesTransport.hpp b/src/finiteVolume/processes/speciesTransport.hpp index 4a5305bdf..3fabd2575 100644 --- a/src/finiteVolume/processes/speciesTransport.hpp +++ b/src/finiteVolume/processes/speciesTransport.hpp @@ -19,7 +19,7 @@ class SpeciesTransport : public FlowProcess { PetscInt numberSpecies; // EOS function calls - eos::ThermodynamicFunction computeTemperature; + eos::ThermodynamicTemperatureFunction computeTemperature; eos::ThermodynamicTemperatureFunction computeInternalEnergy; eos::ThermodynamicTemperatureFunction computeSpeedOfSound; eos::ThermodynamicTemperatureFunction computePressure; From c12d647b39d26936f20c95932579ee25659a00f6 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Thu, 3 Oct 2024 12:29:58 -0400 Subject: [PATCH 06/19] Add the compact transport solver, that still needs tests as well as just commit the timers for now --- src/finiteVolume/cellInterpolant.cpp | 11 +- src/finiteVolume/cellInterpolant.hpp | 2 +- src/finiteVolume/compressibleFlowSolver.cpp | 15 +- src/finiteVolume/compressibleFlowSolver.hpp | 4 +- .../CompactCompressibleTransport.cpp | 251 ++++++++++++++++++ .../CompactCompressibleTransport.hpp | 121 +++++++++ 6 files changed, 394 insertions(+), 10 deletions(-) create mode 100644 src/finiteVolume/processes/CompactCompressibleTransport.cpp create mode 100644 src/finiteVolume/processes/CompactCompressibleTransport.hpp diff --git a/src/finiteVolume/cellInterpolant.cpp b/src/finiteVolume/cellInterpolant.cpp index 389dc5d08..bf0782177 100644 --- a/src/finiteVolume/cellInterpolant.cpp +++ b/src/finiteVolume/cellInterpolant.cpp @@ -42,6 +42,7 @@ ablate::finiteVolume::CellInterpolant::~CellInterpolant() { void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXVec, Vec locAuxVec, Vec locFVec, const std::shared_ptr& solverRegion, std::vector& rhsFunctions, const ablate::domain::Range& faceRange, const ablate::domain::Range& cellRange, Vec cellGeomVec, Vec faceGeomVec) { + StartEvent("CellInterpolant:ComputeRHS_Setup"); auto dm = subDomain->GetDM(); auto dmAux = subDomain->GetAuxDM(); @@ -84,6 +85,9 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV PetscScalar* locFArray; VecGetArray(locFVec, &locFArray) >> utilities::PetscUtilities::checkError; + EndEvent(); + StartEvent("CellInterpolant:ComputeRHS_ComputeGradients"); + // there must be a separate gradient vector/dm for field because they can be different sizes std::vector locGradVecs(nf, nullptr); @@ -99,7 +103,8 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV VecGetArrayRead(locGradVecs[field.subId], &locGradArrays[field.subId]) >> utilities::PetscUtilities::checkError; } } - + EndEvent(); + StartEvent("CellInterpolant:ComputeRHS_ComputeFluxes"); ComputeFluxSourceTerms(dm, ds, totDim, @@ -119,7 +124,8 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV rhsFunctions, faceRange, cellRange); - + EndEvent(); + StartEvent("CellInterpolant:ComputeRHS_Cleanup"); // clean up cell grads for (const auto& field : subDomain->GetFields()) { if (locGradVecs[field.subId]) { @@ -137,6 +143,7 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV VecRestoreArray(locFVec, &locFArray) >> utilities::PetscUtilities::checkError; VecRestoreArrayRead(faceGeomVec, (const PetscScalar**)&faceGeomArray) >> utilities::PetscUtilities::checkError; VecRestoreArrayRead(cellGeomVec, (const PetscScalar**)&cellGeomArray) >> utilities::PetscUtilities::checkError; + EndEvent(); } void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXVec, Vec locAuxVec, Vec locFVec, const std::shared_ptr& solverRegion, diff --git a/src/finiteVolume/cellInterpolant.hpp b/src/finiteVolume/cellInterpolant.hpp index 6bfbdc7c9..e497bc0bd 100644 --- a/src/finiteVolume/cellInterpolant.hpp +++ b/src/finiteVolume/cellInterpolant.hpp @@ -8,7 +8,7 @@ #include "domain/subDomain.hpp" namespace ablate::finiteVolume { -class CellInterpolant { +class CellInterpolant : private utilities::Loggable{ public: /** * Function assumes that the left/right solution and aux variables are discontinuous across the interface diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index 45125ab65..2b11e952b 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -4,6 +4,7 @@ #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" +#include "finiteVolume/processes/CompactCompressibleTransport.hpp" #include "utilities/vectorUtilities.hpp" ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, @@ -12,8 +13,11 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string const std::shared_ptr& fluxCalculatorIn, std::vector> additionalProcesses, std::vector> boundaryConditions, - const std::shared_ptr& evTransport) - : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), + const std::shared_ptr& evTransport, PetscInt compact) + : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? + utilities::VectorUtilities::Merge( {std::make_shared( + parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ) + }, additionalProcesses) : utilities::VectorUtilities::Merge( { // create assumed processes for compressible flow @@ -30,8 +34,8 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string const std::shared_ptr& transport, const std::shared_ptr& fluxCalculatorIn, std::vector> boundaryConditions, - const std::shared_ptr& evTransport) - : CompressibleFlowSolver(std::move(solverId), std::move(region), std::move(options), eosIn, parameters, transport, fluxCalculatorIn, {}, std::move(boundaryConditions), evTransport) {} + const std::shared_ptr& evTransport, PetscInt compact) + : CompressibleFlowSolver(std::move(solverId), std::move(region), std::move(options), eosIn, parameters, transport, fluxCalculatorIn, {}, std::move(boundaryConditions), evTransport, compact) {} #include "registrar.hpp" REGISTER(ablate::solver::Solver, ablate::finiteVolume::CompressibleFlowSolver, "compressible finite volume flow", ARG(std::string, "id", "the name of the flow field"), @@ -41,4 +45,5 @@ REGISTER(ablate::solver::Solver, ablate::finiteVolume::CompressibleFlowSolver, " OPT(ablate::finiteVolume::fluxCalculator::FluxCalculator, "fluxCalculator", "the flux calculators (defaults to none)"), OPT(std::vector, "additionalProcesses", "any additional processes besides euler/yi/ev transport"), OPT(std::vector, "boundaryConditions", "the boundary conditions for the flow field"), - OPT(ablate::eos::transport::TransportModel, "evTransport", "when provided, this model will be used for ev transport instead of default")); \ No newline at end of file + OPT(ablate::eos::transport::TransportModel, "evTransport", "when provided, this model will be used for ev transport instead of default"), + OPT(PetscInt, "compact", "")); \ No newline at end of file diff --git a/src/finiteVolume/compressibleFlowSolver.hpp b/src/finiteVolume/compressibleFlowSolver.hpp index 9c378637e..59335bfc2 100644 --- a/src/finiteVolume/compressibleFlowSolver.hpp +++ b/src/finiteVolume/compressibleFlowSolver.hpp @@ -31,7 +31,7 @@ class CompressibleFlowSolver : public FiniteVolumeSolver { CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eos, const std::shared_ptr& parameters, const std::shared_ptr& transport, const std::shared_ptr& = {}, std::vector> additionalProcesses = {}, - std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}); + std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}, PetscInt compact = 0); /** * Constructor without ev or additional processes @@ -48,7 +48,7 @@ class CompressibleFlowSolver : public FiniteVolumeSolver { CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eos, const std::shared_ptr& parameters, const std::shared_ptr& transport, const std::shared_ptr& = {}, std::vector> boundaryConditions = {}, - const std::shared_ptr& evTransport = {}); + const std::shared_ptr& evTransport = {}, PetscInt compact = 0); ~CompressibleFlowSolver() override = default; }; } // namespace ablate::finiteVolume diff --git a/src/finiteVolume/processes/CompactCompressibleTransport.cpp b/src/finiteVolume/processes/CompactCompressibleTransport.cpp new file mode 100644 index 000000000..28b4dcde5 --- /dev/null +++ b/src/finiteVolume/processes/CompactCompressibleTransport.cpp @@ -0,0 +1,251 @@ +#include "CompactCompressibleTransport.hpp" +#include +#include "finiteVolume/compressibleFlowFields.hpp" +#include "finiteVolume/fluxCalculator/ausm.hpp" +#include "finiteVolume/processes/navierStokesTransport.hpp" +#include "finiteVolume/processes/speciesTransport.hpp" +#include "parameters/emptyParameters.hpp" +#include "utilities/constants.hpp" +#include "utilities/mathUtilities.hpp" +#include "utilities/petscUtilities.hpp" + +ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressibleTransport( + const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { + auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); + if(fluxCalculator) { + // cfl + advectionData.cfl = parameters->Get("cfl", 0.5); + + // extract the difference function from fluxDifferencer object + advectionData.fluxCalculatorFunction = fluxCalculator->GetFluxCalculatorFunction(); + advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); + } + advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + timeStepData.advectionData = &advectionData; + timeStepData.pgs = std::move(pgs); + if(baseTransport) { + // Add in the time stepping + diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); + diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); + diffusionTimeStepData.diffusiveStabilityFactor = parameters->Get("speciesStabilityFactor", 0.0); + diffusionTimeStepData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + + diffusionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + diffusionData.speciesSpeciesSensibleEnthalpy.resize(eos->GetSpeciesVariables().size()); + diffusionData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + } +} + +void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { + // Register the euler,eulerYi, and species source terms + if (fluxCalculator) { + //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + //If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); + + //Set the ComputeCFLTimestepFrom flow Process through + flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeCflTimeStep, &timeStepData, "cfl"); + + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); + advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); + advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + } + + // if there are any coefficients for diffusion, compute diffusion, for here we will follow suit in allowing multiple diffusion functions + + if (transportModel) { + // Store the required data for the low level c functions + diffusionData.muFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Viscosity, flow.GetSubDomain().GetFields()); + diffusionData.kFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Conductivity, flow.GetSubDomain().GetFields()); + diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + diffusionData.computeSpeciesSensibleEnthalpyFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeciesSensibleEnthalpy, flow.GetSubDomain().GetFields()); + + /* For now we will do 3 different diffusive flux calls just since it doesn't seem like their splitting costs too much time in redundant calculations */ + if (diffusionData.muFunction.function || diffusionData.kFunction.function) { + // Register the Diffusion Source term + flow.RegisterRHSFunction(ablate::finiteVolume::processes::NavierStokesTransport::DiffusionFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); + } + if (diffusionData.diffFunction.function) { + // Specify a different rhs function depending on if the diffusion flux is constant + if (diffusionData.diffFunction.propertySize == 1) { + flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionEnergyFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionSpeciesFlux, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { + flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionEnergyFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else { + throw std::invalid_argument("The diffusion property size must be 1 or number of species in ablate::finiteVolume::processes::SpeciesTransport."); + } + } + + // Check to see if time step calculations should be added for viscosity or conduction + if (diffusionTimeStepData.conductionStabilityFactor > 0 || diffusionTimeStepData.viscousStabilityFactor > 0) { + diffusionTimeStepData.kFunction = diffusionData.kFunction; + diffusionTimeStepData.muFunction = diffusionData.muFunction; + diffusionTimeStepData.specificHeat = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpecificHeatConstantVolume, flow.GetSubDomain().GetFields()); + diffusionTimeStepData.density = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Density, flow.GetSubDomain().GetFields()); + + if (diffusionTimeStepData.conductionStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeConductionTimeStep, &diffusionTimeStepData, "cond"); + } + if (diffusionTimeStepData.viscousStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); + } + } + } + + //Setup up aux updates and normalizations + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { + computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { + computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::YI_FIELD)) { + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &numberSpecies, {CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + // clean up the species + flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); + } +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, + const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, + PetscScalar* flux, void* ctx) { + PetscFunctionBeginUser; + + auto advectionData = (AdvectionData*)ctx; + + const int EULER_FIELD = 0; + const int RHOYI_FIELD = 1; + + // Compute the norm + PetscReal norm[3]; + utilities::MathUtilities::NormVector(dim, fg->normal, norm); + const PetscReal areaMag = utilities::MathUtilities::MagVector(dim, fg->normal); + + // Decode the left and right states + PetscReal densityL; + PetscReal normalVelocityL; + PetscReal velocityL[3]; + PetscReal internalEnergyL; + PetscReal aL; + PetscReal pL; + + // decode the left side + { + densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureL; + //grab Temperature from aux field somehow and use that here, probably just auxL[0] and auxR[0] //I want to see how different tempL and it's calculated temperature are + // If the same perfect, get rid of this step -klb + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.66+.34*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + // Get the velocity in this direction + normalVelocityL = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityL[d] = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityL; + normalVelocityL += velocityL[d] * norm[d]; + } + PetscCall(advectionData->computeInternalEnergy.function(fieldL, temperatureL, &internalEnergyL, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldL, temperatureL, &aL, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldL, temperatureL, &pL, advectionData->computePressure.context.get())); + } + + PetscReal densityR; + PetscReal normalVelocityR; + PetscReal velocityR[3]; + PetscReal internalEnergyR; + PetscReal aR; + PetscReal pR; + + { // decode right state + densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureR; + + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.66+.34*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + + // Get the velocity in this direction + normalVelocityR = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityR[d] = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityR; + normalVelocityR += velocityR[d] * norm[d]; + } + + PetscCall(advectionData->computeInternalEnergy.function(fieldR, temperatureR, &internalEnergyR, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldR, temperatureR, &aR, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldR, temperatureR, &pR, advectionData->computePressure.context.get())); + } + + // get the face values + PetscReal massFlux; + PetscReal p12; + + fluxCalculator::Direction direction = + advectionData->fluxCalculatorFunction(advectionData->fluxCalculatorCtx, normalVelocityL, aL, densityL, pL, normalVelocityR, aR, densityR, pR, &massFlux, &p12); + + if (direction == fluxCalculator::LEFT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + flux[CompressibleFlowFields::RHOE] = HL * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; + } else if (direction == fluxCalculator::RIGHT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + flux[CompressibleFlowFields::RHOE] = HR * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; + } else { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + + flux[CompressibleFlowFields::RHOE] = 0.5 * (HL + HR) * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; + } + + PetscFunctionReturn(0); +} diff --git a/src/finiteVolume/processes/CompactCompressibleTransport.hpp b/src/finiteVolume/processes/CompactCompressibleTransport.hpp new file mode 100644 index 000000000..205ae3e2d --- /dev/null +++ b/src/finiteVolume/processes/CompactCompressibleTransport.hpp @@ -0,0 +1,121 @@ +#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H +#define ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H + +#include +#include "eos/transport/transportModel.hpp" +#include "finiteVolume/fluxCalculator/fluxCalculator.hpp" +#include "flowProcess.hpp" +#include "pressureGradientScaling.hpp" + +namespace ablate::finiteVolume::processes { + +class CompactCompressibleTransport : public FlowProcess { +private: + // store ctx needed for function advection function that is passed into Petsc + struct AdvectionData { + //flow CFL + PetscReal cfl; + + /* number of gas species and extra species */ + PetscInt numberSpecies; + PetscInt numberEV; + + // EOS function calls (For Temperature it's better to just use the TemperatureTemperature function so we can guess Temperature from t + eos::ThermodynamicTemperatureFunction computeTemperature; + eos::ThermodynamicTemperatureFunction computeInternalEnergy; + eos::ThermodynamicTemperatureFunction computeSpeedOfSound; + eos::ThermodynamicTemperatureFunction computePressure; + + /* store method used for flux calculator */ + ablate::finiteVolume::fluxCalculator::FluxCalculatorFunction fluxCalculatorFunction; + void* fluxCalculatorCtx; + }; + AdvectionData advectionData; + + struct DiffusionData { + /* thermal conductivity Diffusivity, and Dynamic Viscosity*/ + eos::ThermodynamicTemperatureFunction kFunction; + eos::ThermodynamicTemperatureFunction muFunction; + eos::ThermodynamicTemperatureFunction diffFunction; + /* number of gas species */ + PetscInt numberSpecies; + /* functions to compute species enthalpy */ + eos::ThermodynamicTemperatureFunction computeSpeciesSensibleEnthalpyFunction; + /* store a scratch space for speciesSpeciesSensibleEnthalpy */ + std::vector speciesSpeciesSensibleEnthalpy; + /* store an optional scratch space for individual species diffusion */ + std::vector speciesDiffusionCoefficient; + /* store a scratch space for evDiffusionCoefficient */ + std::vector evDiffusionCoefficient; + }; + DiffusionData diffusionData; + + const std::shared_ptr fluxCalculator; + const std::shared_ptr eos; + const std::shared_ptr transportModel; + + + eos::ThermodynamicTemperatureFunction computeTemperatureFunction; + eos::ThermodynamicFunction computePressureFunction; + + // Store the required ctx for time stepping + struct CflTimeStepData { + /* thermal conductivity*/ + AdvectionData* advectionData; + /* pressure gradient scaling */ + std::shared_ptr pgs; + }; + CflTimeStepData timeStepData; + + //! methods and functions to compute diffusion based time stepping + struct DiffusionTimeStepData { + /* number of gas species */ + PetscInt numberSpecies; + /* store an optional scratch space for individual species diffusion */ + std::vector speciesDiffusionCoefficient; + + //! stability factor for condition time step. 0 (default) does not compute factor + PetscReal diffusiveStabilityFactor; + //! stability factor for condition time step. 0 (default) does not compute factor + PetscReal conductionStabilityFactor; + //! stability factor for viscous diffusion time step. 0 (default) does not compute factor + PetscReal viscousStabilityFactor; + + /* diffusivity */ + eos::ThermodynamicTemperatureFunction diffFunction; + /* thermal conductivity*/ + eos::ThermodynamicTemperatureFunction kFunction; + /* dynamic viscosity*/ + eos::ThermodynamicTemperatureFunction muFunction; + /* specific heat*/ + eos::ThermodynamicTemperatureFunction specificHeat; + /* density */ + eos::ThermodynamicTemperatureFunction density; + + }; + DiffusionTimeStepData diffusionTimeStepData; + +public: + explicit CompactCompressibleTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, + std::shared_ptr baseTransport = {}, std::shared_ptr = {}); + /** + * public function to link this process with the flow + * @param flow + */ + void Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) override; + + /** + * This Computes the Advective Flow for rho, rhoE, and rhoVel, rhoYi, and rhoEV. + * u = {"euler"} or {"euler", "densityYi"} if species are tracked + * a = {} + * ctx = FlowData_CompressibleFlow + * @return + */ + static PetscErrorCode AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscScalar fieldL[], const PetscScalar fieldR[], const PetscInt aOff[], + const PetscScalar auxL[], const PetscScalar auxR[], PetscScalar* flux, void* ctx); + +}; + +} //end namespace + +#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H From ef6cb932e4f72ae167986c9e7885d02e1b038489 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 4 Oct 2024 10:17:30 -0400 Subject: [PATCH 07/19] Few debug fixes --- src/finiteVolume/compressibleFlowSolver.cpp | 2 +- src/finiteVolume/processes/CMakeLists.txt | 2 + .../CompactCompressibleTransport.cpp | 251 ------ .../compactCompressibleTransport.cpp | 778 ++++++++++++++++++ ...t.hpp => compactCompressibleTransport.hpp} | 69 ++ .../processes/navierStokesTransport.cpp | 8 +- 6 files changed, 855 insertions(+), 255 deletions(-) delete mode 100644 src/finiteVolume/processes/CompactCompressibleTransport.cpp create mode 100644 src/finiteVolume/processes/compactCompressibleTransport.cpp rename src/finiteVolume/processes/{CompactCompressibleTransport.hpp => compactCompressibleTransport.hpp} (57%) diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index 2b11e952b..aec1b1fb0 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -4,7 +4,7 @@ #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" -#include "finiteVolume/processes/CompactCompressibleTransport.hpp" +#include "finiteVolume/processes/compactCompressibleTransport.hpp" #include "utilities/vectorUtilities.hpp" ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, diff --git a/src/finiteVolume/processes/CMakeLists.txt b/src/finiteVolume/processes/CMakeLists.txt index b84779afd..048385cfd 100644 --- a/src/finiteVolume/processes/CMakeLists.txt +++ b/src/finiteVolume/processes/CMakeLists.txt @@ -16,6 +16,7 @@ target_sources(ablateLibrary thermophoreticDiffusion.cpp surfaceForce.cpp soot.cpp + compactCompressibleTransport.cpp PUBLIC process.hpp @@ -35,4 +36,5 @@ target_sources(ablateLibrary thermophoreticDiffusion.hpp surfaceForce.hpp soot.hpp + compactCompressibleTransport.hpp ) diff --git a/src/finiteVolume/processes/CompactCompressibleTransport.cpp b/src/finiteVolume/processes/CompactCompressibleTransport.cpp deleted file mode 100644 index 28b4dcde5..000000000 --- a/src/finiteVolume/processes/CompactCompressibleTransport.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "CompactCompressibleTransport.hpp" -#include -#include "finiteVolume/compressibleFlowFields.hpp" -#include "finiteVolume/fluxCalculator/ausm.hpp" -#include "finiteVolume/processes/navierStokesTransport.hpp" -#include "finiteVolume/processes/speciesTransport.hpp" -#include "parameters/emptyParameters.hpp" -#include "utilities/constants.hpp" -#include "utilities/mathUtilities.hpp" -#include "utilities/petscUtilities.hpp" - -ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressibleTransport( - const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, - std::shared_ptr baseTransport, std::shared_ptr pgs) - : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { - auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); - if(fluxCalculator) { - // cfl - advectionData.cfl = parameters->Get("cfl", 0.5); - - // extract the difference function from fluxDifferencer object - advectionData.fluxCalculatorFunction = fluxCalculator->GetFluxCalculatorFunction(); - advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); - } - advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); - timeStepData.advectionData = &advectionData; - timeStepData.pgs = std::move(pgs); - if(baseTransport) { - // Add in the time stepping - diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); - diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); - diffusionTimeStepData.diffusiveStabilityFactor = parameters->Get("speciesStabilityFactor", 0.0); - diffusionTimeStepData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); - - diffusionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); - diffusionData.speciesSpeciesSensibleEnthalpy.resize(eos->GetSpeciesVariables().size()); - diffusionData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); - } -} - -void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { - // Register the euler,eulerYi, and species source terms - if (fluxCalculator) { - //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better - //If it is worse for perfect gas's, going to need to add in an option switch -klb - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); - - //Set the ComputeCFLTimestepFrom flow Process through - flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeCflTimeStep, &timeStepData, "cfl"); - - advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); - advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); - advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); - advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - } - - // if there are any coefficients for diffusion, compute diffusion, for here we will follow suit in allowing multiple diffusion functions - - if (transportModel) { - // Store the required data for the low level c functions - diffusionData.muFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Viscosity, flow.GetSubDomain().GetFields()); - diffusionData.kFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Conductivity, flow.GetSubDomain().GetFields()); - diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); - diffusionData.computeSpeciesSensibleEnthalpyFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeciesSensibleEnthalpy, flow.GetSubDomain().GetFields()); - - /* For now we will do 3 different diffusive flux calls just since it doesn't seem like their splitting costs too much time in redundant calculations */ - if (diffusionData.muFunction.function || diffusionData.kFunction.function) { - // Register the Diffusion Source term - flow.RegisterRHSFunction(ablate::finiteVolume::processes::NavierStokesTransport::DiffusionFlux, - &diffusionData, - {CompressibleFlowFields::EULER_FIELD}, - {CompressibleFlowFields::EULER_FIELD}, - {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); - } - if (diffusionData.diffFunction.function) { - // Specify a different rhs function depending on if the diffusion flux is constant - if (diffusionData.diffFunction.propertySize == 1) { - flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionEnergyFlux, - &diffusionData, - {CompressibleFlowFields::EULER_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionSpeciesFlux, - &diffusionData, - {CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { - flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionEnergyFluxVariableDiffusionCoefficient, - &diffusionData, - {CompressibleFlowFields::EULER_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - flow.RegisterRHSFunction(ablate::finiteVolume::processes::SpeciesTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient, - &diffusionData, - {CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else { - throw std::invalid_argument("The diffusion property size must be 1 or number of species in ablate::finiteVolume::processes::SpeciesTransport."); - } - } - - // Check to see if time step calculations should be added for viscosity or conduction - if (diffusionTimeStepData.conductionStabilityFactor > 0 || diffusionTimeStepData.viscousStabilityFactor > 0) { - diffusionTimeStepData.kFunction = diffusionData.kFunction; - diffusionTimeStepData.muFunction = diffusionData.muFunction; - diffusionTimeStepData.specificHeat = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpecificHeatConstantVolume, flow.GetSubDomain().GetFields()); - diffusionTimeStepData.density = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Density, flow.GetSubDomain().GetFields()); - - if (diffusionTimeStepData.conductionStabilityFactor > 0) { - flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeConductionTimeStep, &diffusionTimeStepData, "cond"); - } - if (diffusionTimeStepData.viscousStabilityFactor > 0) { - flow.RegisterComputeTimeStepFunction(ablate::finiteVolume::processes::NavierStokesTransport::ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); - } - } - } - - //Setup up aux updates and normalizations - if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); - } - if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { - computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); - } - if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { - computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); - } - if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::YI_FIELD)) { - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &numberSpecies, {CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); - // clean up the species - flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); - } -} - -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, - const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, - PetscScalar* flux, void* ctx) { - PetscFunctionBeginUser; - - auto advectionData = (AdvectionData*)ctx; - - const int EULER_FIELD = 0; - const int RHOYI_FIELD = 1; - - // Compute the norm - PetscReal norm[3]; - utilities::MathUtilities::NormVector(dim, fg->normal, norm); - const PetscReal areaMag = utilities::MathUtilities::MagVector(dim, fg->normal); - - // Decode the left and right states - PetscReal densityL; - PetscReal normalVelocityL; - PetscReal velocityL[3]; - PetscReal internalEnergyL; - PetscReal aL; - PetscReal pL; - - // decode the left side - { - densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - PetscReal temperatureL; - //grab Temperature from aux field somehow and use that here, probably just auxL[0] and auxR[0] //I want to see how different tempL and it's calculated temperature are - // If the same perfect, get rid of this step -klb - PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.66+.34*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); - // Get the velocity in this direction - normalVelocityL = 0.0; - for (PetscInt d = 0; d < dim; d++) { - velocityL[d] = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityL; - normalVelocityL += velocityL[d] * norm[d]; - } - PetscCall(advectionData->computeInternalEnergy.function(fieldL, temperatureL, &internalEnergyL, advectionData->computeInternalEnergy.context.get())); - PetscCall(advectionData->computeSpeedOfSound.function(fieldL, temperatureL, &aL, advectionData->computeSpeedOfSound.context.get())); - PetscCall(advectionData->computePressure.function(fieldL, temperatureL, &pL, advectionData->computePressure.context.get())); - } - - PetscReal densityR; - PetscReal normalVelocityR; - PetscReal velocityR[3]; - PetscReal internalEnergyR; - PetscReal aR; - PetscReal pR; - - { // decode right state - densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - PetscReal temperatureR; - - PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.66+.34*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); - - // Get the velocity in this direction - normalVelocityR = 0.0; - for (PetscInt d = 0; d < dim; d++) { - velocityR[d] = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityR; - normalVelocityR += velocityR[d] * norm[d]; - } - - PetscCall(advectionData->computeInternalEnergy.function(fieldR, temperatureR, &internalEnergyR, advectionData->computeInternalEnergy.context.get())); - PetscCall(advectionData->computeSpeedOfSound.function(fieldR, temperatureR, &aR, advectionData->computeSpeedOfSound.context.get())); - PetscCall(advectionData->computePressure.function(fieldR, temperatureR, &pR, advectionData->computePressure.context.get())); - } - - // get the face values - PetscReal massFlux; - PetscReal p12; - - fluxCalculator::Direction direction = - advectionData->fluxCalculatorFunction(advectionData->fluxCalculatorCtx, normalVelocityL, aL, densityL, pL, normalVelocityR, aR, densityR, pR, &massFlux, &p12); - - if (direction == fluxCalculator::LEFT) { - flux[CompressibleFlowFields::RHO] = massFlux * areaMag; - PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); - PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; - flux[CompressibleFlowFields::RHOE] = HL * massFlux * areaMag; - for (PetscInt n = 0; n < dim; n++) { - flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; - } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; - } else if (direction == fluxCalculator::RIGHT) { - flux[CompressibleFlowFields::RHO] = massFlux * areaMag; - PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); - PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; - flux[CompressibleFlowFields::RHOE] = HR * massFlux * areaMag; - for (PetscInt n = 0; n < dim; n++) { - flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; - } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; - } else { - flux[CompressibleFlowFields::RHO] = massFlux * areaMag; - - PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); - PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; - - PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); - PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; - - flux[CompressibleFlowFields::RHOE] = 0.5 * (HL + HR) * massFlux * areaMag; - for (PetscInt n = 0; n < dim; n++) { - flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; - } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; - } - - PetscFunctionReturn(0); -} diff --git a/src/finiteVolume/processes/compactCompressibleTransport.cpp b/src/finiteVolume/processes/compactCompressibleTransport.cpp new file mode 100644 index 000000000..4da634b43 --- /dev/null +++ b/src/finiteVolume/processes/compactCompressibleTransport.cpp @@ -0,0 +1,778 @@ +#include "compactCompressibleTransport.hpp" +#include +#include "finiteVolume/compressibleFlowFields.hpp" +#include "finiteVolume/fluxCalculator/ausm.hpp" +#include "finiteVolume/processes/navierStokesTransport.hpp" +#include "finiteVolume/processes/speciesTransport.hpp" +#include "parameters/emptyParameters.hpp" +#include "utilities/constants.hpp" +#include "utilities/mathUtilities.hpp" +#include "utilities/petscUtilities.hpp" + +ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressibleTransport( + const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { + auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); + if(fluxCalculator) { + // cfl + advectionData.cfl = parameters->Get("cfl", 0.5); + + // extract the difference function from fluxDifferencer object + advectionData.fluxCalculatorFunction = fluxCalculator->GetFluxCalculatorFunction(); + advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); + } + advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + timeStepData.advectionData = &advectionData; + timeStepData.pgs = std::move(pgs); + if(transportModel) { + // Add in the time stepping + diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); + diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); + diffusionTimeStepData.diffusiveStabilityFactor = parameters->Get("speciesStabilityFactor", 0.0); + diffusionTimeStepData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + + diffusionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + diffusionData.speciesSpeciesSensibleEnthalpy.resize(eos->GetSpeciesVariables().size()); + diffusionData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + } +} + +void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { + // Register the euler,eulerYi, and species source terms + if (fluxCalculator) { + //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + //If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); + + //Set the ComputeCFLTimestepFrom flow Process through + flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); + + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); + advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); + advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + } + + // if there are any coefficients for diffusion, compute diffusion, for here we will follow suit in allowing multiple diffusion functions + + if (transportModel) { + // Store the required data for the low level c functions + diffusionData.muFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Viscosity, flow.GetSubDomain().GetFields()); + diffusionData.kFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Conductivity, flow.GetSubDomain().GetFields()); + diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + diffusionData.computeSpeciesSensibleEnthalpyFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeciesSensibleEnthalpy, flow.GetSubDomain().GetFields()); + + /* For now we will do 3 different diffusive flux calls just since it doesn't seem like their splitting costs too much time in redundant calculations */ + if (diffusionData.muFunction.function || diffusionData.kFunction.function) { + // Register the Diffusion Source term + flow.RegisterRHSFunction(DiffusionFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); + } + if (diffusionData.diffFunction.function) { + // Specify a different rhs function depending on if the diffusion flux is constant + if (diffusionData.diffFunction.propertySize == 1) { + flow.RegisterRHSFunction(DiffusionEnergyFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(DiffusionSpeciesFlux, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { + flow.RegisterRHSFunction(DiffusionEnergyFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(DiffusionSpeciesFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else { + throw std::invalid_argument("The diffusion property size must be 1 or number of species in ablate::finiteVolume::processes::SpeciesTransport."); + } + } + + // Check to see if time step calculations should be added for viscosity or conduction + if (diffusionTimeStepData.conductionStabilityFactor > 0 || diffusionTimeStepData.viscousStabilityFactor > 0) { + diffusionTimeStepData.kFunction = diffusionData.kFunction; + diffusionTimeStepData.muFunction = diffusionData.muFunction; + diffusionTimeStepData.specificHeat = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpecificHeatConstantVolume, flow.GetSubDomain().GetFields()); + diffusionTimeStepData.density = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Density, flow.GetSubDomain().GetFields()); + diffusionTimeStepData.numberSpecies = eos->GetSpeciesVariables().size(); + + if (diffusionTimeStepData.conductionStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ComputeConductionTimeStep, &diffusionTimeStepData, "cond"); + } + if (diffusionTimeStepData.viscousStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); + } + } + if (diffusionTimeStepData.diffusiveStabilityFactor > 0){ + diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; + diffusionTimeStepData.diffFunction = diffusionData.diffFunction; + flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); + } + } + + //Setup up aux updates and normalizations + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { + computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { + computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::YI_FIELD)) { + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, {CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + // clean up the species + flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); + } +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, + const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, + PetscScalar* flux, void* ctx) { + PetscFunctionBeginUser; + + auto advectionData = (AdvectionData*)ctx; + + const int EULER_FIELD = 0; + const int RHOYI_FIELD = 1; + + // Compute the norm + PetscReal norm[3]; + utilities::MathUtilities::NormVector(dim, fg->normal, norm); + const PetscReal areaMag = utilities::MathUtilities::MagVector(dim, fg->normal); + + // Decode the left and right states + PetscReal densityL; + PetscReal normalVelocityL; + PetscReal velocityL[3]; + PetscReal internalEnergyL; + PetscReal aL; + PetscReal pL; + + // decode the left side + { + densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureL; + //grab Temperature from aux field somehow and use that here, probably just auxL[0] and auxR[0] //I want to see how different tempL and it's calculated temperature are + // If the same perfect, get rid of this step -klb + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.66+.34*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + // Get the velocity in this direction + normalVelocityL = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityL[d] = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityL; + normalVelocityL += velocityL[d] * norm[d]; + } + PetscCall(advectionData->computeInternalEnergy.function(fieldL, temperatureL, &internalEnergyL, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldL, temperatureL, &aL, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldL, temperatureL, &pL, advectionData->computePressure.context.get())); + } + + PetscReal densityR; + PetscReal normalVelocityR; + PetscReal velocityR[3]; + PetscReal internalEnergyR; + PetscReal aR; + PetscReal pR; + + { // decode right state + densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureR; + + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.66+.34*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + + // Get the velocity in this direction + normalVelocityR = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityR[d] = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityR; + normalVelocityR += velocityR[d] * norm[d]; + } + + PetscCall(advectionData->computeInternalEnergy.function(fieldR, temperatureR, &internalEnergyR, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldR, temperatureR, &aR, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldR, temperatureR, &pR, advectionData->computePressure.context.get())); + } + + // get the face values + PetscReal massFlux; + PetscReal p12; + + fluxCalculator::Direction direction = + advectionData->fluxCalculatorFunction(advectionData->fluxCalculatorCtx, normalVelocityL, aL, densityL, pL, normalVelocityR, aR, densityR, pR, &massFlux, &p12); + + if (direction == fluxCalculator::LEFT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + flux[CompressibleFlowFields::RHOE] = HL * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; + } else if (direction == fluxCalculator::RIGHT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + flux[CompressibleFlowFields::RHOE] = HR * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; + } else { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + + flux[CompressibleFlowFields::RHOE] = 0.5 * (HL + HR) * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; + } + + PetscFunctionReturn(0); +} + + +double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto timeStepData = (CflTimeStepData*)ctx; + auto advectionData = timeStepData->advectionData; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for euler and densityYi + auto eulerId = flow.GetSubDomain().GetField("euler").id; + + // Get alpha if provided + PetscReal pgsAlpha = 1.0; + if (timeStepData->pgs) { + pgsAlpha = timeStepData->pgs->GetAlpha(); + } + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* euler; + const PetscReal* conserved = NULL; + const PetscReal* cellCharacteristics = NULL; + DMPlexPointGlobalFieldRead(dm, cell, eulerId, x, &euler) >> utilities::PetscUtilities::checkError; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (euler) { // must be real cell and not ghost + PetscReal rho = euler[CompressibleFlowFields::RHO]; + + // Get the speed of sound from the eos + //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) + PetscReal temperature; + advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; + PetscReal a; + advectionData->computeSpeedOfSound.function(conserved, temperature, &a, advectionData->computeSpeedOfSound.context.get()) >> utilities::PetscUtilities::checkError; + + PetscReal dx = 2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]; + + PetscReal velSum = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velSum += PetscAbsReal(euler[CompressibleFlowFields::RHOU + d]) / rho; + } + PetscReal dt = advectionData->cfl * dx / (a / pgsAlpha + velSum); + + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + return dtMin; +} + +double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData*)ctx; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar* aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto kFunction = diffusionData->kFunction.function; + auto kFunctionContext = diffusionData->kFunction.context.get(); + auto cvFunction = diffusionData->specificHeat.function; + auto cvFunctionContext = diffusionData->specificHeat.context.get(); + auto density = diffusionData->density.function; + auto densityContext = diffusionData->density.context.get(); + auto stabFactor = diffusionData->conductionStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal* temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + const PetscReal* cellCharacteristics = NULL; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal k; + kFunction(conserved, *temperature, &k, kFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal cv; + cvFunction(conserved, *temperature, &cv, cvFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal rho; + density(conserved, *temperature, &rho, densityContext) >> utilities::PetscUtilities::checkError; + + // Compute alpha + PetscReal alpha = k / (rho * cv); + + PetscReal dx2 = PetscSqr(2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]); + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / alpha); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + + return dtMin; +} + +double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData*)ctx; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar* aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto muFunction = diffusionData->muFunction.function; + auto muFunctionContext = diffusionData->muFunction.context.get(); + auto density = diffusionData->density.function; + auto densityContext = diffusionData->density.context.get(); + auto stabFactor = diffusionData->viscousStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal* temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + const PetscReal* cellCharacteristics = NULL; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal mu; + muFunction(conserved, *temperature, &mu, muFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal rho; + density(conserved, *temperature, &rho, densityContext) >> utilities::PetscUtilities::checkError; + + // Compute nu + PetscReal nu = mu / rho; + + PetscReal dx2 = PetscSqr(2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]); + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / nu); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + return dtMin; +} +double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData *)ctx; + + // Get the fv geom + PetscReal minCellRadius; + DMPlexGetGeometryFVM(dm, NULL, NULL, &minCellRadius) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar *x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar *aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // assume the smallest cell is the limiting factor for now + const PetscReal dx2 = PetscSqr(2.0 * minCellRadius); + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto diffFunction = diffusionData->diffFunction.function; + auto diffFunctionContext = diffusionData->diffFunction.context.get(); + auto stabFactor = diffusionData->diffusiveStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal *conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal *temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal diff; + diffFunction(conserved, *temperature, &diff, diffFunctionContext) >> utilities::PetscUtilities::checkError; + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / diff); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + return dtMin; +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int T = 0; + const int VEL = 1; + + auto flowParameters = (DiffusionData*)ctx; + + // Compute mu and k + PetscReal mu = 0.0; + flowParameters->muFunction.function(field, aux[aOff[T]], &mu, flowParameters->muFunction.context.get()); + PetscReal k = 0.0; + flowParameters->kFunction.function(field, aux[aOff[T]], &k, flowParameters->kFunction.context.get()); + + // Compute the stress tensor tau + PetscReal tau[9]; // Maximum size without symmetry + PetscCall(ablate::finiteVolume::processes::NavierStokesTransport::CompressibleFlowComputeStressTensor(dim, mu, gradAux + aOff_x[VEL], tau)); + + // for each velocity component + for (PetscInt c = 0; c < dim; ++c) { + PetscReal viscousFlux = 0.0; + + // March over each direction + for (PetscInt d = 0; d < dim; ++d) { + viscousFlux += -fg->normal[d] * tau[c * dim + d]; // This is tau[c][d] + } + + // add in the contribution + flux[CompressibleFlowFields::RHOU + c] = viscousFlux; + } + + // energy equation + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; ++d) { + PetscReal heatFlux = 0.0; + // add in the contributions for this viscous terms + for (PetscInt c = 0; c < dim; ++c) { + heatFlux += aux[aOff[VEL] + c] * tau[d * dim + c]; + } + + // heat conduction (-k dT/dx - k dT/dy - k dT/dz) . n A + heatFlux += k * gradAux[aOff_x[T] + d]; + + // Multiply by the area normal + heatFlux *= -fg->normal[d]; + + flux[CompressibleFlowFields::RHOE] += heatFlux; + } + + // zero out the density flux + flux[CompressibleFlowFields::RHO] = 0.0; + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + // compute the temperature in this volume + const PetscReal temperature = aux[aOff[temp]]; + PetscCall(flowParameters->computeSpeciesSensibleEnthalpyFunction.function( + field, temperature, flowParameters->speciesSpeciesSensibleEnthalpy.data(), flowParameters->computeSpeciesSensibleEnthalpyFunction.context.get())); + + // set the non rho E fluxes to zero + flux[CompressibleFlowFields::RHO] = 0.0; + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; d++) { + flux[CompressibleFlowFields::RHOU + d] = 0.0; + } + + // compute diff, this can be constant or variable + PetscReal diff = 0.0; + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * diff * flowParameters->speciesSpeciesSensibleEnthalpy[sp] * gradAux[offset]; + flux[CompressibleFlowFields::RHOE] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + // compute the temperature in this volume + const PetscReal temperature = aux[aOff[temp]]; + PetscCall(flowParameters->computeSpeciesSensibleEnthalpyFunction.function( + field, temperature, flowParameters->speciesSpeciesSensibleEnthalpy.data(), flowParameters->computeSpeciesSensibleEnthalpyFunction.context.get())); + + // set the non rho E fluxes to zero + flux[CompressibleFlowFields::RHO] = 0.0; + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; d++) { + flux[CompressibleFlowFields::RHOU + d] = 0.0; + } + + // compute diff, this can be constant or variable + flowParameters->diffFunction.function(field, temperature, flowParameters->speciesDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * flowParameters->speciesDiffusionCoefficient[sp] * flowParameters->speciesSpeciesSensibleEnthalpy[sp] * gradAux[offset]; + flux[CompressibleFlowFields::RHOE] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + const PetscReal temperature = aux[aOff[temp]]; + + // compute diff + PetscReal diff = 0.0; + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + flux[sp] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * diff * gradAux[offset]; + flux[sp] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + const PetscReal temperature = aux[aOff[temp]]; + + // compute diff + flowParameters->diffFunction.function(field, temperature, flowParameters->speciesDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + flux[sp] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * flowParameters->speciesDiffusionCoefficient[sp] * gradAux[offset]; + flux[sp] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + diff --git a/src/finiteVolume/processes/CompactCompressibleTransport.hpp b/src/finiteVolume/processes/compactCompressibleTransport.hpp similarity index 57% rename from src/finiteVolume/processes/CompactCompressibleTransport.hpp rename to src/finiteVolume/processes/compactCompressibleTransport.hpp index 205ae3e2d..e1923b66a 100644 --- a/src/finiteVolume/processes/CompactCompressibleTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleTransport.hpp @@ -114,6 +114,75 @@ class CompactCompressibleTransport : public FlowProcess { static PetscErrorCode AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscScalar fieldL[], const PetscScalar fieldR[], const PetscInt aOff[], const PetscScalar auxL[], const PetscScalar auxR[], PetscScalar* flux, void* ctx); + + /** + * This Computes the diffusion flux for euler rhoE, rhoVel + * u = {"euler", "densityYi"} + * a = {"temperature", "velocity"} + * ctx = FlowData_CompressibleFlow + * @return + */ + static PetscErrorCode DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the energy transfer for species diffusion flux for rhoE + * f = "euler" + * u = {"euler", "densityYi"} + * a = {"yi"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the energy transfer for species diffusion flux for rhoE for variable diffusion coefficient + * f = "euler" + * u = {"euler", "densityYi"} + * a = {"yi"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the species transfer for species diffusion flux + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the species transfer for species diffusion flux for variable diffusion coefficient + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + + + + // static function to compute time step for euler advection + static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + }; } //end namespace diff --git a/src/finiteVolume/processes/navierStokesTransport.cpp b/src/finiteVolume/processes/navierStokesTransport.cpp index 54d79f579..b38c37885 100644 --- a/src/finiteVolume/processes/navierStokesTransport.cpp +++ b/src/finiteVolume/processes/navierStokesTransport.cpp @@ -104,7 +104,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection auto eulerAdvectionData = (AdvectionData*)ctx; const int EULER_FIELD = 0; - const int TEMP_FIELD = 0; +// const int TEMP_FIELD = 0; // Compute the norm PetscReal norm[3]; @@ -124,7 +124,8 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); +// PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, 300, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -149,7 +150,8 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); +// PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, 300, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; From e6db88a9a2591d71ce1229b020aea87109f0b76b Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 4 Oct 2024 13:17:05 -0400 Subject: [PATCH 08/19] More debugging --- src/finiteVolume/cellInterpolant.cpp | 9 ++++++--- src/finiteVolume/faceInterpolant.cpp | 7 ++++--- .../compactCompressibleTransport.cpp | 19 +++++++++++-------- .../compactCompressibleTransport.hpp | 15 +++++++-------- .../processes/navierStokesTransport.cpp | 8 +++----- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/finiteVolume/cellInterpolant.cpp b/src/finiteVolume/cellInterpolant.cpp index bf0782177..c9fc53b4e 100644 --- a/src/finiteVolume/cellInterpolant.cpp +++ b/src/finiteVolume/cellInterpolant.cpp @@ -579,8 +579,10 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD DMPlexPointLocalRead(dmAux, faceCells[0], auxArray, &auxL) >> utilities::PetscUtilities::checkError; DMPlexPointLocalRead(dmAux, faceCells[1], auxArray, &auxR) >> utilities::PetscUtilities::checkError; } + // March over each source function for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { + PetscInt fluxOffset = 0; //Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) PetscArrayzero(flux, totDim) >> utilities::PetscUtilities::checkError; const auto& rhsFluxFunctionDescription = rhsFunctions[fun]; rhsFluxFunctionDescription.function(dim, fg, uOff[fun].data(), uL, uR, aOff[fun].data(), auxL, auxR, flux, rhsFluxFunctionDescription.context) >> utilities::PetscUtilities::checkError; @@ -605,10 +607,11 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD DMPlexPointLocalFieldRef(dm, faceCells[1], fluxId[fun][updateFieldIdx], locFArray, &fR) >> utilities::PetscUtilities::checkError; } - for (PetscInt d = 0; d < fluxComponentSize[fun][updateFieldIdx]; ++d) { - if (fL) fL[d] -= flux[d] / cgL->volume; - if (fR) fR[d] += flux[d] / cgR->volume; + for (PetscInt d = 0; d < (fluxComponentSize[fun][updateFieldIdx]); ++d) { + if (fL) fL[d] -= flux[fluxOffset+d] / cgL->volume; + if (fR) fR[d] += flux[fluxOffset+d] / cgR->volume; } + fluxOffset += fluxComponentSize[fun][updateFieldIdx]; } } } diff --git a/src/finiteVolume/faceInterpolant.cpp b/src/finiteVolume/faceInterpolant.cpp index 9ea4b442a..aff388bd3 100644 --- a/src/finiteVolume/faceInterpolant.cpp +++ b/src/finiteVolume/faceInterpolant.cpp @@ -389,7 +389,7 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV // March over each source function for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { PetscArrayzero(flux.data(), totDim) >> utilities::PetscUtilities::checkError; - + PetscInt fluxOffset = 0; //Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) const auto& rhsFluxFunctionDescription = rhsFunctions[fun]; rhsFluxFunctionDescription.function(dim, fg, @@ -426,9 +426,10 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV } for (PetscInt d = 0; d < fluxComponentSize[fun][updateFieldIdx]; ++d) { - if (fL) fL[d] -= flux[d] / cgL->volume; - if (fR) fR[d] += flux[d] / cgR->volume; + if (fL) fL[d] -= flux[d+fluxOffset] / cgL->volume; + if (fR) fR[d] += flux[d+fluxOffset] / cgR->volume; } + fluxOffset += fluxComponentSize[fun][updateFieldIdx]; } } } diff --git a/src/finiteVolume/processes/compactCompressibleTransport.cpp b/src/finiteVolume/processes/compactCompressibleTransport.cpp index 4da634b43..79ff0abee 100644 --- a/src/finiteVolume/processes/compactCompressibleTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleTransport.cpp @@ -14,6 +14,7 @@ ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressib std::shared_ptr baseTransport, std::shared_ptr pgs) : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); + if(fluxCalculator) { // cfl advectionData.cfl = parameters->Get("cfl", 0.5); @@ -21,10 +22,13 @@ ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressib // extract the difference function from fluxDifferencer object advectionData.fluxCalculatorFunction = fluxCalculator->GetFluxCalculatorFunction(); advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); + + advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); } - advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + timeStepData.advectionData = &advectionData; timeStepData.pgs = std::move(pgs); + if(transportModel) { // Add in the time stepping diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); @@ -108,6 +112,7 @@ void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate diffusionTimeStepData.muFunction = diffusionData.muFunction; diffusionTimeStepData.specificHeat = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpecificHeatConstantVolume, flow.GetSubDomain().GetFields()); diffusionTimeStepData.density = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Density, flow.GetSubDomain().GetFields()); + diffusionTimeStepData.numberSpecies = eos->GetSpeciesVariables().size(); if (diffusionTimeStepData.conductionStabilityFactor > 0) { @@ -136,11 +141,9 @@ void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); } - if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::YI_FIELD)) { - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, {CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); - // clean up the species - flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); - } + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, std::vector{CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + // clean up the species + flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); } PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, @@ -170,9 +173,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Ad { densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - //grab Temperature from aux field somehow and use that here, probably just auxL[0] and auxR[0] //I want to see how different tempL and it's calculated temperature are - // If the same perfect, get rid of this step -klb + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.66+.34*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + // Get the velocity in this direction normalVelocityL = 0.0; for (PetscInt d = 0; d < dim; d++) { diff --git a/src/finiteVolume/processes/compactCompressibleTransport.hpp b/src/finiteVolume/processes/compactCompressibleTransport.hpp index e1923b66a..a1a242eaa 100644 --- a/src/finiteVolume/processes/compactCompressibleTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleTransport.hpp @@ -50,14 +50,6 @@ class CompactCompressibleTransport : public FlowProcess { }; DiffusionData diffusionData; - const std::shared_ptr fluxCalculator; - const std::shared_ptr eos; - const std::shared_ptr transportModel; - - - eos::ThermodynamicTemperatureFunction computeTemperatureFunction; - eos::ThermodynamicFunction computePressureFunction; - // Store the required ctx for time stepping struct CflTimeStepData { /* thermal conductivity*/ @@ -95,6 +87,13 @@ class CompactCompressibleTransport : public FlowProcess { }; DiffusionTimeStepData diffusionTimeStepData; + const std::shared_ptr fluxCalculator; + const std::shared_ptr eos; + const std::shared_ptr transportModel; + + eos::ThermodynamicTemperatureFunction computeTemperatureFunction; + eos::ThermodynamicFunction computePressureFunction; + public: explicit CompactCompressibleTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, std::shared_ptr baseTransport = {}, std::shared_ptr = {}); diff --git a/src/finiteVolume/processes/navierStokesTransport.cpp b/src/finiteVolume/processes/navierStokesTransport.cpp index b38c37885..54d79f579 100644 --- a/src/finiteVolume/processes/navierStokesTransport.cpp +++ b/src/finiteVolume/processes/navierStokesTransport.cpp @@ -104,7 +104,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection auto eulerAdvectionData = (AdvectionData*)ctx; const int EULER_FIELD = 0; -// const int TEMP_FIELD = 0; + const int TEMP_FIELD = 0; // Compute the norm PetscReal norm[3]; @@ -124,8 +124,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; -// PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, 300, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -150,8 +149,7 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; -// PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, 300, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; From 07a50529e7f9f95804cbe3b7e038df14b5293b90 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 4 Oct 2024 15:14:26 -0400 Subject: [PATCH 09/19] More debugging, This one works fine --- src/finiteVolume/processes/compactCompressibleTransport.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/finiteVolume/processes/compactCompressibleTransport.cpp b/src/finiteVolume/processes/compactCompressibleTransport.cpp index 79ff0abee..c7fd5a6a0 100644 --- a/src/finiteVolume/processes/compactCompressibleTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleTransport.cpp @@ -174,7 +174,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Ad densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.66+.34*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67+.33*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -198,7 +198,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Ad densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.66+.34*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.67+.33*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; From fc33153b9489f5493d18bb1819c407d6462986b7 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 4 Oct 2024 15:26:09 -0400 Subject: [PATCH 10/19] Rename in preperation for the one including the EV transport --- src/finiteVolume/compressibleFlowSolver.cpp | 4 +-- src/finiteVolume/processes/CMakeLists.txt | 4 +-- ...compactCompressibleNSSpeciesTransport.cpp} | 26 +++++++++---------- ...compactCompressibleNSSpeciesTransport.hpp} | 10 +++---- 4 files changed, 22 insertions(+), 22 deletions(-) rename src/finiteVolume/processes/{compactCompressibleTransport.cpp => compactCompressibleNSSpeciesTransport.cpp} (95%) rename src/finiteVolume/processes/{compactCompressibleTransport.hpp => compactCompressibleNSSpeciesTransport.hpp} (95%) diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index aec1b1fb0..8966f3321 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -1,10 +1,10 @@ #include "compressibleFlowSolver.hpp" #include #include "compressibleFlowFields.hpp" +#include "finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp" #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" -#include "finiteVolume/processes/compactCompressibleTransport.hpp" #include "utilities/vectorUtilities.hpp" ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, @@ -15,7 +15,7 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string std::vector> boundaryConditions, const std::shared_ptr& evTransport, PetscInt compact) : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? - utilities::VectorUtilities::Merge( {std::make_shared( + utilities::VectorUtilities::Merge( {std::make_shared( parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ) }, additionalProcesses) : utilities::VectorUtilities::Merge( diff --git a/src/finiteVolume/processes/CMakeLists.txt b/src/finiteVolume/processes/CMakeLists.txt index 048385cfd..f545e8f38 100644 --- a/src/finiteVolume/processes/CMakeLists.txt +++ b/src/finiteVolume/processes/CMakeLists.txt @@ -16,7 +16,7 @@ target_sources(ablateLibrary thermophoreticDiffusion.cpp surfaceForce.cpp soot.cpp - compactCompressibleTransport.cpp + compactCompressibleNSSpeciesTransport.cpp PUBLIC process.hpp @@ -36,5 +36,5 @@ target_sources(ablateLibrary thermophoreticDiffusion.hpp surfaceForce.hpp soot.hpp - compactCompressibleTransport.hpp + compactCompressibleNSSpeciesTransport.hpp ) diff --git a/src/finiteVolume/processes/compactCompressibleTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp similarity index 95% rename from src/finiteVolume/processes/compactCompressibleTransport.cpp rename to src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp index c7fd5a6a0..639c9ad97 100644 --- a/src/finiteVolume/processes/compactCompressibleTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp @@ -1,4 +1,4 @@ -#include "compactCompressibleTransport.hpp" +#include "compactCompressibleNSSpeciesTransport.hpp" #include #include "finiteVolume/compressibleFlowFields.hpp" #include "finiteVolume/fluxCalculator/ausm.hpp" @@ -9,7 +9,7 @@ #include "utilities/mathUtilities.hpp" #include "utilities/petscUtilities.hpp" -ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressibleTransport( +ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::CompactCompressibleNSSpeciesTransport( const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, std::shared_ptr baseTransport, std::shared_ptr pgs) : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { @@ -42,7 +42,7 @@ ablate::finiteVolume::processes::CompactCompressibleTransport::CompactCompressib } } -void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { +void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { // Register the euler,eulerYi, and species source terms if (fluxCalculator) { //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better @@ -146,7 +146,7 @@ void ablate::finiteVolume::processes::CompactCompressibleTransport::Setup(ablate flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, PetscScalar* flux, void* ctx) { PetscFunctionBeginUser; @@ -260,7 +260,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Ad } -double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -338,7 +338,7 @@ double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeCfl return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -424,7 +424,7 @@ double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeCon return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -504,7 +504,7 @@ double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeVis flow.RestoreRange(cellRange); return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -572,7 +572,7 @@ double ablate::finiteVolume::processes::CompactCompressibleTransport::ComputeVis return dtMin; } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { PetscFunctionBeginUser; @@ -628,7 +628,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Di PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; @@ -670,7 +670,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Di PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { @@ -712,7 +712,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Di PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; @@ -746,7 +746,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::Di PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { diff --git a/src/finiteVolume/processes/compactCompressibleTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp similarity index 95% rename from src/finiteVolume/processes/compactCompressibleTransport.hpp rename to src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp index a1a242eaa..2a19c19b4 100644 --- a/src/finiteVolume/processes/compactCompressibleTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp @@ -1,5 +1,5 @@ -#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H -#define ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H +#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESTRANSPORT_H +#define ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESTRANSPORT_H #include #include "eos/transport/transportModel.hpp" @@ -9,7 +9,7 @@ namespace ablate::finiteVolume::processes { -class CompactCompressibleTransport : public FlowProcess { +class CompactCompressibleNSSpeciesTransport : public FlowProcess { private: // store ctx needed for function advection function that is passed into Petsc struct AdvectionData { @@ -95,7 +95,7 @@ class CompactCompressibleTransport : public FlowProcess { eos::ThermodynamicFunction computePressureFunction; public: - explicit CompactCompressibleTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, + explicit CompactCompressibleNSSpeciesTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, std::shared_ptr baseTransport = {}, std::shared_ptr = {}); /** * public function to link this process with the flow @@ -186,4 +186,4 @@ class CompactCompressibleTransport : public FlowProcess { } //end namespace -#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLETRANSPORT_H +#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESTRANSPORT_H From 5fec0ec4e173a41528cf4f7d5cc04d493f3d3176 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Mon, 7 Oct 2024 11:00:50 -0400 Subject: [PATCH 11/19] change PetscInt to int because for some reason on lassen the compiler doesn't like to convert the shared pointer for a long int --- src/finiteVolume/compressibleFlowSolver.cpp | 6 +++--- src/finiteVolume/compressibleFlowSolver.hpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index 8966f3321..cf64b9202 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -13,7 +13,7 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string const std::shared_ptr& fluxCalculatorIn, std::vector> additionalProcesses, std::vector> boundaryConditions, - const std::shared_ptr& evTransport, PetscInt compact) + const std::shared_ptr& evTransport, int compact) : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? utilities::VectorUtilities::Merge( {std::make_shared( parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ) @@ -34,7 +34,7 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string const std::shared_ptr& transport, const std::shared_ptr& fluxCalculatorIn, std::vector> boundaryConditions, - const std::shared_ptr& evTransport, PetscInt compact) + const std::shared_ptr& evTransport, int compact) : CompressibleFlowSolver(std::move(solverId), std::move(region), std::move(options), eosIn, parameters, transport, fluxCalculatorIn, {}, std::move(boundaryConditions), evTransport, compact) {} #include "registrar.hpp" @@ -46,4 +46,4 @@ REGISTER(ablate::solver::Solver, ablate::finiteVolume::CompressibleFlowSolver, " OPT(std::vector, "additionalProcesses", "any additional processes besides euler/yi/ev transport"), OPT(std::vector, "boundaryConditions", "the boundary conditions for the flow field"), OPT(ablate::eos::transport::TransportModel, "evTransport", "when provided, this model will be used for ev transport instead of default"), - OPT(PetscInt, "compact", "")); \ No newline at end of file + OPT(int, "compact", "")); \ No newline at end of file diff --git a/src/finiteVolume/compressibleFlowSolver.hpp b/src/finiteVolume/compressibleFlowSolver.hpp index 59335bfc2..78b0dd0d8 100644 --- a/src/finiteVolume/compressibleFlowSolver.hpp +++ b/src/finiteVolume/compressibleFlowSolver.hpp @@ -31,7 +31,7 @@ class CompressibleFlowSolver : public FiniteVolumeSolver { CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eos, const std::shared_ptr& parameters, const std::shared_ptr& transport, const std::shared_ptr& = {}, std::vector> additionalProcesses = {}, - std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}, PetscInt compact = 0); + std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}, int compact = 0); /** * Constructor without ev or additional processes @@ -48,7 +48,7 @@ class CompressibleFlowSolver : public FiniteVolumeSolver { CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eos, const std::shared_ptr& parameters, const std::shared_ptr& transport, const std::shared_ptr& = {}, std::vector> boundaryConditions = {}, - const std::shared_ptr& evTransport = {}, PetscInt compact = 0); + const std::shared_ptr& evTransport = {}, int compact = 0); ~CompressibleFlowSolver() override = default; }; } // namespace ablate::finiteVolume From 8e8dea57bc57b44911014c92a39a3f6681fb263d Mon Sep 17 00:00:00 2001 From: klbudzin Date: Tue, 8 Oct 2024 09:24:32 -0400 Subject: [PATCH 12/19] Finished the compacting of the Compressible flow fields transport --- src/finiteVolume/compressibleFlowSolver.cpp | 22 +- src/finiteVolume/processes/CMakeLists.txt | 2 + ...mpactCompressibleNSSpeciesNDDTransport.cpp | 899 ++++++++++++++++++ ...mpactCompressibleNSSpeciesNDDTransport.hpp | 217 +++++ .../compactCompressibleNSSpeciesTransport.hpp | 3 - src/finiteVolume/processes/evTransport.cpp | 1 + 6 files changed, 1136 insertions(+), 8 deletions(-) create mode 100644 src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp create mode 100644 src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index cf64b9202..db6d3a0e5 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -2,11 +2,18 @@ #include #include "compressibleFlowFields.hpp" #include "finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp" +#include "finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp" #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" #include "utilities/vectorUtilities.hpp" +/** + * The compact argument in this constructor is used to define whether we use seperate processes for the Euler (NS) transport, species transport, and EV transport. + * a value of 0, is all seperate + * a value of 1, is combined Euler and species transport, with seperate EV transport + * a value of 2, is combined Euler and species and The single field Progress EV transport (soot number density in this case) + */ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eosIn, const std::shared_ptr& parameters, const std::shared_ptr& transport, @@ -14,10 +21,15 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string std::vector> additionalProcesses, std::vector> boundaryConditions, const std::shared_ptr& evTransport, int compact) - : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? - utilities::VectorUtilities::Merge( {std::make_shared( - parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ) - }, additionalProcesses) : + : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? ( compact == 1 ? + utilities::VectorUtilities::Merge( { + std::make_shared( + parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ), + std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport) }, + additionalProcesses) : + utilities::VectorUtilities::Merge( {std::make_shared ( + parameters, eosIn, fluxCalculatorIn, transport, evTransport ? evTransport : transport, utilities::VectorUtilities::Find(additionalProcesses) ) + }, additionalProcesses) ): utilities::VectorUtilities::Merge( { // create assumed processes for compressible flow @@ -46,4 +58,4 @@ REGISTER(ablate::solver::Solver, ablate::finiteVolume::CompressibleFlowSolver, " OPT(std::vector, "additionalProcesses", "any additional processes besides euler/yi/ev transport"), OPT(std::vector, "boundaryConditions", "the boundary conditions for the flow field"), OPT(ablate::eos::transport::TransportModel, "evTransport", "when provided, this model will be used for ev transport instead of default"), - OPT(int, "compact", "")); \ No newline at end of file + OPT(int, "compact", "Integer value describing whether to treat all the transport seperately, partially combined, or fully combined (see commented code above constructor for values)")); \ No newline at end of file diff --git a/src/finiteVolume/processes/CMakeLists.txt b/src/finiteVolume/processes/CMakeLists.txt index f545e8f38..9b47aa5f2 100644 --- a/src/finiteVolume/processes/CMakeLists.txt +++ b/src/finiteVolume/processes/CMakeLists.txt @@ -17,6 +17,7 @@ target_sources(ablateLibrary surfaceForce.cpp soot.cpp compactCompressibleNSSpeciesTransport.cpp + compactCompressibleNSSpeciesNDDTransport.cpp PUBLIC process.hpp @@ -37,4 +38,5 @@ target_sources(ablateLibrary surfaceForce.hpp soot.hpp compactCompressibleNSSpeciesTransport.hpp + compactCompressibleNSSpeciesNDDTransport.hpp ) diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp new file mode 100644 index 000000000..6f31f79bc --- /dev/null +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp @@ -0,0 +1,899 @@ +#include "compactCompressibleNSSpeciesNDDTransport.hpp" +#include +#include "finiteVolume/compressibleFlowFields.hpp" +#include "finiteVolume/fluxCalculator/ausm.hpp" +#include "finiteVolume/processes/navierStokesTransport.hpp" +#include "finiteVolume/processes/speciesTransport.hpp" +#include "finiteVolume/processes/evTransport.hpp" +#include "parameters/emptyParameters.hpp" +#include "utilities/constants.hpp" +#include "utilities/mathUtilities.hpp" +#include "utilities/petscUtilities.hpp" + +ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::CompactCompressibleNSSpeciesNDDTransport( + const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, std::shared_ptr evTransport, std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)), NDDTransportModel(std::move(evTransport)) { + auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); + + if(fluxCalculator) { + // cfl + advectionData.cfl = parameters->Get("cfl", 0.5); + + // extract the difference function from fluxDifferencer object + advectionData.fluxCalculatorFunction = fluxCalculator->GetFluxCalculatorFunction(); + advectionData.fluxCalculatorCtx = fluxCalculator->GetFluxCalculatorContext(); + + advectionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + } + + timeStepData.advectionData = &advectionData; + timeStepData.pgs = std::move(pgs); + + if(transportModel) { + // Add in the time stepping + diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); + diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); + diffusionTimeStepData.diffusiveStabilityFactor = parameters->Get("speciesStabilityFactor", 0.0); + diffusionTimeStepData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + + diffusionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + diffusionData.speciesSpeciesSensibleEnthalpy.resize(eos->GetSpeciesVariables().size()); + diffusionData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); + } +} + +void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { + // loop over convserved EV's and pull out NDD, if it's not there error out or ignore it? + const auto &evConservedFields = flow.GetSubDomain().GetFields(domain::FieldLocation::SOL, CompressibleFlowFields::EV_TAG); + for (auto &evConservedField: evConservedFields) { + + if(evConservedField.name != CompressibleFlowFields::DENSITY_PROGRESS_FIELD) continue; + // set up the progress Extra Variables and the euler/species transport + auto nonConservedName = evConservedField.name.substr(CompressibleFlowFields::CONSERVED.length()); //non Conserved form just removes density prefix + if (!flow.GetSubDomain().ContainsField(nonConservedName)) { + throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport process expects the conserved (" + evConservedField.name + ") and non-conserved (" + nonConservedName + + ") extra variables to be in the flow."); + } + // Register the euler,eulerYi, and species source terms + if (fluxCalculator) { + //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + //If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD,evConservedField.name}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD,evConservedField.name}, {CompressibleFlowFields::TEMPERATURE_FIELD}); + + //Set the ComputeCFLTimestepFrom flow Process through + flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); + + advectionData.numberEV = evConservedField.numberComponents; + advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); + advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); + advectionData.computePressure = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + } + + // if there are any coefficients for diffusion, compute diffusion, for here we will follow suit in allowing multiple diffusion functions + if (transportModel) { + // Store the required data for the low level c functions + diffusionData.muFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Viscosity, flow.GetSubDomain().GetFields()); + diffusionData.kFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Conductivity, flow.GetSubDomain().GetFields()); + diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + diffusionData.computeSpeciesSensibleEnthalpyFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeciesSensibleEnthalpy, flow.GetSubDomain().GetFields()); + + /* For now we will do 3 different diffusive flux calls just since it doesn't seem like their splitting costs too much time in redundant calculations */ + if (diffusionData.muFunction.function || diffusionData.kFunction.function) { + // Register the Diffusion Source term + flow.RegisterRHSFunction(DiffusionFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); + } + //Species + if (diffusionData.diffFunction.function) { + // Specify a different rhs function depending on if the diffusion flux is constant + if (diffusionData.diffFunction.propertySize == 1) { + flow.RegisterRHSFunction(DiffusionEnergyFlux, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(DiffusionSpeciesFlux, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { + flow.RegisterRHSFunction(DiffusionEnergyFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::EULER_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(DiffusionSpeciesFluxVariableDiffusionCoefficient, + &diffusionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else { + throw std::invalid_argument("The diffusion property size must be 1 or number of species in ablate::finiteVolume::processes::SpeciesTransport."); + } + } + + + // Check to see if time step calculations should be added for viscosity or conduction + if (diffusionTimeStepData.conductionStabilityFactor > 0 || diffusionTimeStepData.viscousStabilityFactor > 0) { + diffusionTimeStepData.kFunction = diffusionData.kFunction; + diffusionTimeStepData.muFunction = diffusionData.muFunction; + diffusionTimeStepData.specificHeat = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpecificHeatConstantVolume, flow.GetSubDomain().GetFields()); + diffusionTimeStepData.density = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Density, flow.GetSubDomain().GetFields()); + + diffusionTimeStepData.numberSpecies = eos->GetSpeciesVariables().size(); + + if (diffusionTimeStepData.conductionStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ComputeConductionTimeStep, &diffusionTimeStepData, "cond"); + } + if (diffusionTimeStepData.viscousStabilityFactor > 0) { + flow.RegisterComputeTimeStepFunction(ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); + } + } + if (diffusionTimeStepData.diffusiveStabilityFactor > 0){ + diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; + diffusionTimeStepData.diffFunction = diffusionData.diffFunction; + flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); + } + } + + if(NDDTransportModel) { + diffusionData.numberEV = evConservedField.numberComponents; + diffusionData.evDiffusionCoefficient.resize(diffusionData.numberEV); + diffusionData.evDiffFunction = NDDTransportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + //ExtraVariable + if (diffusionData.evDiffFunction.function) { + if (diffusionData.evDiffFunction.propertySize == 1) { + flow.RegisterRHSFunction(DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName,CompressibleFlowFields::TEMPERATURE_FIELD}); + } else if (diffusionData.evDiffFunction.propertySize == diffusionData.numberEV) { + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName}); + } else throw std::invalid_argument("The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesNDDTransport!"); + } + } + + //Setup up aux updates and normalizations + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { + computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); + } + if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { + computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); + } + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, std::vector{CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + // clean up the species + flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); + //limit the EV's + if (evConservedField.Tagged(CompressibleFlowFields::PositiveRange)) { + const auto &conservedFieldName = evConservedField.name; + flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::PositiveExtraVariables(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdatePositiveEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + } else if (evConservedField.Tagged(CompressibleFlowFields::BoundRange)) { + const auto &conservedFieldName = evConservedField.name; + flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariables(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateBoundEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + } else if (evConservedField.Tagged(CompressibleFlowFields::MinusOneToOneRange)) { + const auto &conservedFieldName = evConservedField.name; + flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariablesMinusOneToOne(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateMinusOneToOneBoundEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + } else { + // Allow for the entire range + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + } + } //End EV loop +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, + const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, + PetscScalar* flux, void* ctx) { + PetscFunctionBeginUser; + + auto advectionData = (AdvectionData*)ctx; + + const int EULER_FIELD = 0; + const int RHOYI_FIELD = 1; + const int RHOEV_FIELD = 2; + + // Compute the norm + PetscReal norm[3]; + utilities::MathUtilities::NormVector(dim, fg->normal, norm); + const PetscReal areaMag = utilities::MathUtilities::MagVector(dim, fg->normal); + + // Decode the left and right states + PetscReal densityL; + PetscReal normalVelocityL; + PetscReal velocityL[3]; + PetscReal internalEnergyL; + PetscReal aL; + PetscReal pL; + + // decode the left side + { + densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureL; + + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67+.33*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + + // Get the velocity in this direction + normalVelocityL = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityL[d] = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityL; + normalVelocityL += velocityL[d] * norm[d]; + } + PetscCall(advectionData->computeInternalEnergy.function(fieldL, temperatureL, &internalEnergyL, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldL, temperatureL, &aL, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldL, temperatureL, &pL, advectionData->computePressure.context.get())); + } + + PetscReal densityR; + PetscReal normalVelocityR; + PetscReal velocityR[3]; + PetscReal internalEnergyR; + PetscReal aR; + PetscReal pR; + + { // decode right state + densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + PetscReal temperatureR; + + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.67+.33*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + + // Get the velocity in this direction + normalVelocityR = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velocityR[d] = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHOU + d] / densityR; + normalVelocityR += velocityR[d] * norm[d]; + } + + PetscCall(advectionData->computeInternalEnergy.function(fieldR, temperatureR, &internalEnergyR, advectionData->computeInternalEnergy.context.get())); + PetscCall(advectionData->computeSpeedOfSound.function(fieldR, temperatureR, &aR, advectionData->computeSpeedOfSound.context.get())); + PetscCall(advectionData->computePressure.function(fieldR, temperatureR, &pR, advectionData->computePressure.context.get())); + } + + // get the face values + PetscReal massFlux; + PetscReal p12; + + fluxCalculator::Direction direction = + advectionData->fluxCalculatorFunction(advectionData->fluxCalculatorCtx, normalVelocityL, aL, densityL, pL, normalVelocityR, aR, densityR, pR, &massFlux, &p12); + + if (direction == fluxCalculator::LEFT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + flux[CompressibleFlowFields::RHOE] = HL * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; + //EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) + flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldL[uOff[RHOEV_FIELD] + ev] / densityL) * areaMag; + } else if (direction == fluxCalculator::RIGHT) { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + flux[CompressibleFlowFields::RHOE] = HR * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; + //EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) + flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; + } else { + flux[CompressibleFlowFields::RHO] = massFlux * areaMag; + + PetscReal velMagL = utilities::MathUtilities::MagVector(dim, velocityL); + PetscReal HL = internalEnergyL + velMagL * velMagL / 2.0 + pL / densityL; + + PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); + PetscReal HR = internalEnergyR + velMagR * velMagR / 2.0 + pR / densityR; + + flux[CompressibleFlowFields::RHOE] = 0.5 * (HL + HR) * massFlux * areaMag; + for (PetscInt n = 0; n < dim; n++) { + flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; + } + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) + flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; + //EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) + flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; +// flux[uOff[RHOEV_FIELD]+ev] = massFlux * 0.5 * (fieldR[uOff[RHOEV_FIELD] + ev] + fieldL[uOff[RHOEV_FIELD] + ev] ) / ( 0.5 * (densityR + densityL)) * areaMag; + } + + PetscFunctionReturn(0); +} + + +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto timeStepData = (CflTimeStepData*)ctx; + auto advectionData = timeStepData->advectionData; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for euler and densityYi + auto eulerId = flow.GetSubDomain().GetField("euler").id; + + // Get alpha if provided + PetscReal pgsAlpha = 1.0; + if (timeStepData->pgs) { + pgsAlpha = timeStepData->pgs->GetAlpha(); + } + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* euler; + const PetscReal* conserved = NULL; + const PetscReal* cellCharacteristics = NULL; + DMPlexPointGlobalFieldRead(dm, cell, eulerId, x, &euler) >> utilities::PetscUtilities::checkError; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (euler) { // must be real cell and not ghost + PetscReal rho = euler[CompressibleFlowFields::RHO]; + + // Get the speed of sound from the eos + //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) + PetscReal temperature; + advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; + PetscReal a; + advectionData->computeSpeedOfSound.function(conserved, temperature, &a, advectionData->computeSpeedOfSound.context.get()) >> utilities::PetscUtilities::checkError; + + PetscReal dx = 2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]; + + PetscReal velSum = 0.0; + for (PetscInt d = 0; d < dim; d++) { + velSum += PetscAbsReal(euler[CompressibleFlowFields::RHOU + d]) / rho; + } + PetscReal dt = advectionData->cfl * dx / (a / pgsAlpha + velSum); + + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + return dtMin; +} + +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData*)ctx; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar* aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto kFunction = diffusionData->kFunction.function; + auto kFunctionContext = diffusionData->kFunction.context.get(); + auto cvFunction = diffusionData->specificHeat.function; + auto cvFunctionContext = diffusionData->specificHeat.context.get(); + auto density = diffusionData->density.function; + auto densityContext = diffusionData->density.context.get(); + auto stabFactor = diffusionData->conductionStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal* temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + const PetscReal* cellCharacteristics = NULL; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal k; + kFunction(conserved, *temperature, &k, kFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal cv; + cvFunction(conserved, *temperature, &cv, cvFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal rho; + density(conserved, *temperature, &rho, densityContext) >> utilities::PetscUtilities::checkError; + + // Compute alpha + PetscReal alpha = k / (rho * cv); + + PetscReal dx2 = PetscSqr(2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]); + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / alpha); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + + return dtMin; +} + +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData*)ctx; + + // Get the fv geom + Vec locCharacteristicsVec; + DM characteristicsDm; + const PetscScalar* locCharacteristicsArray; + flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); + VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar* x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar* aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto muFunction = diffusionData->muFunction.function; + auto muFunctionContext = diffusionData->muFunction.context.get(); + auto density = diffusionData->density.function; + auto densityContext = diffusionData->density.context.get(); + auto stabFactor = diffusionData->viscousStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal* conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal* temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + const PetscReal* cellCharacteristics = NULL; + DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal mu; + muFunction(conserved, *temperature, &mu, muFunctionContext) >> utilities::PetscUtilities::checkError; + PetscReal rho; + density(conserved, *temperature, &rho, densityContext) >> utilities::PetscUtilities::checkError; + + // Compute nu + PetscReal nu = mu / rho; + + PetscReal dx2 = PetscSqr(2.0 * cellCharacteristics[FiniteVolumeSolver::MIN_CELL_RADIUS]); + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / nu); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + return dtMin; +} +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { + // Get the dm and current solution vector + DM dm; + TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; + Vec v; + TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; + + // Get the flow param + auto diffusionData = (DiffusionTimeStepData *)ctx; + + // Get the fv geom + PetscReal minCellRadius; + DMPlexGetGeometryFVM(dm, NULL, NULL, &minCellRadius) >> utilities::PetscUtilities::checkError; + + // Get the valid cell range over this region + ablate::domain::Range cellRange; + flow.GetCellRangeWithoutGhost(cellRange); + + // Get the solution data + const PetscScalar *x; + VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + + // Get the auxData + const PetscScalar *aux; + const DM auxDM = flow.GetSubDomain().GetAuxDM(); + VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + + // Get the dim from the dm + PetscInt dim; + DMGetDimension(dm, &dim) >> utilities::PetscUtilities::checkError; + + // assume the smallest cell is the limiting factor for now + const PetscReal dx2 = PetscSqr(2.0 * minCellRadius); + + // Get field location for temperature + auto temperatureField = flow.GetSubDomain().GetField(finiteVolume::CompressibleFlowFields::TEMPERATURE_FIELD).id; + + // get functions + auto diffFunction = diffusionData->diffFunction.function; + auto diffFunctionContext = diffusionData->diffFunction.context.get(); + auto stabFactor = diffusionData->diffusiveStabilityFactor; + + // March over each cell + PetscReal dtMin = ablate::utilities::Constants::large; + for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { + auto cell = cellRange.GetPoint(c); + + const PetscReal *conserved = NULL; + DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; + + const PetscReal *temperature = NULL; + DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; + + if (conserved) { // must be real cell and not ghost + PetscReal diff; + diffFunction(conserved, *temperature, &diff, diffFunctionContext) >> utilities::PetscUtilities::checkError; + + // compute dt + double dt = PetscAbs(stabFactor * dx2 / diff); + dtMin = PetscMin(dtMin, dt); + } + } + VecRestoreArrayRead(v, &x) >> utilities::PetscUtilities::checkError; + VecRestoreArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; + flow.RestoreRange(cellRange); + return dtMin; +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int T = 0; + const int VEL = 1; + + auto flowParameters = (DiffusionData*)ctx; + + // Compute mu and k + PetscReal mu = 0.0; + flowParameters->muFunction.function(field, aux[aOff[T]], &mu, flowParameters->muFunction.context.get()); + PetscReal k = 0.0; + flowParameters->kFunction.function(field, aux[aOff[T]], &k, flowParameters->kFunction.context.get()); + + // Compute the stress tensor tau + PetscReal tau[9]; // Maximum size without symmetry + PetscCall(ablate::finiteVolume::processes::NavierStokesTransport::CompressibleFlowComputeStressTensor(dim, mu, gradAux + aOff_x[VEL], tau)); + + // for each velocity component + for (PetscInt c = 0; c < dim; ++c) { + PetscReal viscousFlux = 0.0; + + // March over each direction + for (PetscInt d = 0; d < dim; ++d) { + viscousFlux += -fg->normal[d] * tau[c * dim + d]; // This is tau[c][d] + } + + // add in the contribution + flux[CompressibleFlowFields::RHOU + c] = viscousFlux; + } + + // energy equation + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; ++d) { + PetscReal heatFlux = 0.0; + // add in the contributions for this viscous terms + for (PetscInt c = 0; c < dim; ++c) { + heatFlux += aux[aOff[VEL] + c] * tau[d * dim + c]; + } + + // heat conduction (-k dT/dx - k dT/dy - k dT/dz) . n A + heatFlux += k * gradAux[aOff_x[T] + d]; + + // Multiply by the area normal + heatFlux *= -fg->normal[d]; + + flux[CompressibleFlowFields::RHOE] += heatFlux; + } + + // zero out the density flux + flux[CompressibleFlowFields::RHO] = 0.0; + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + // compute the temperature in this volume + const PetscReal temperature = aux[aOff[temp]]; + PetscCall(flowParameters->computeSpeciesSensibleEnthalpyFunction.function( + field, temperature, flowParameters->speciesSpeciesSensibleEnthalpy.data(), flowParameters->computeSpeciesSensibleEnthalpyFunction.context.get())); + + // set the non rho E fluxes to zero + flux[CompressibleFlowFields::RHO] = 0.0; + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; d++) { + flux[CompressibleFlowFields::RHOU + d] = 0.0; + } + + // compute diff, this can be constant or variable + PetscReal diff = 0.0; + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * diff * flowParameters->speciesSpeciesSensibleEnthalpy[sp] * gradAux[offset]; + flux[CompressibleFlowFields::RHOE] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + // compute the temperature in this volume + const PetscReal temperature = aux[aOff[temp]]; + PetscCall(flowParameters->computeSpeciesSensibleEnthalpyFunction.function( + field, temperature, flowParameters->speciesSpeciesSensibleEnthalpy.data(), flowParameters->computeSpeciesSensibleEnthalpyFunction.context.get())); + + // set the non rho E fluxes to zero + flux[CompressibleFlowFields::RHO] = 0.0; + flux[CompressibleFlowFields::RHOE] = 0.0; + for (PetscInt d = 0; d < dim; d++) { + flux[CompressibleFlowFields::RHOU + d] = 0.0; + } + + // compute diff, this can be constant or variable + flowParameters->diffFunction.function(field, temperature, flowParameters->speciesDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * flowParameters->speciesDiffusionCoefficient[sp] * flowParameters->speciesSpeciesSensibleEnthalpy[sp] * gradAux[offset]; + flux[CompressibleFlowFields::RHOE] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + + const PetscReal temperature = aux[aOff[temp]]; + + // compute diff + PetscReal diff = 0.0; + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + flux[sp] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * diff * gradAux[offset]; + flux[sp] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int yi = 0; + const int euler = 0; + const int temp = 1; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; + const PetscReal temperature = aux[aOff[temp]]; + + // compute diff + flowParameters->diffFunction.function(field, temperature, flowParameters->speciesDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt sp = 0; sp < flowParameters->numberSpecies; ++sp) { + flux[sp] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[yi] + (sp * dim) + d; + PetscReal speciesFlux = -fg->normal[d] * density * flowParameters->speciesDiffusionCoefficient[sp] * gradAux[offset]; + flux[sp] += speciesFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int EULER_FIELD = 0; + const int EV_FIELD = 0; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + // compute diff + PetscReal diff = 0.0; + flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt ev = 0; ev < flowParameters->numberEV; ++ev) { + flux[ev] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[EV_FIELD] + (ev * dim) + d; + PetscReal evFlux = -fg->normal[d] * density * diff * gradAux[offset]; + flux[ev] += evFlux; + } + } + + PetscFunctionReturn(0); +} + +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void *ctx) { + PetscFunctionBeginUser; + // this order is based upon the order that they are passed into RegisterRHSFunction + const int EULER_FIELD = 0; + const int EV_FIELD = 0; + + auto flowParameters = (DiffusionData *)ctx; + + // get the current density from euler + const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; + const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + // compute diff + flowParameters->diffFunction.function(field, temperature, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); + + // species equations + for (PetscInt ev = 0; ev < flowParameters->numberEV; ++ev) { + flux[ev] = 0; + for (PetscInt d = 0; d < dim; ++d) { + // speciesFlux(-rho Di dYi/dx - rho Di dYi/dy - rho Di dYi//dz) . n A + const int offset = aOff_x[EV_FIELD] + (ev * dim) + d; + PetscReal evFlux = -fg->normal[d] * density * flowParameters->evDiffusionCoefficient[ev] * gradAux[offset]; + flux[ev] += evFlux; + } + } + PetscFunctionReturn(0); +} + diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp new file mode 100644 index 000000000..e14b18e68 --- /dev/null +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp @@ -0,0 +1,217 @@ +#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H +#define ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H + +#include +#include "eos/transport/transportModel.hpp" +#include "finiteVolume/fluxCalculator/fluxCalculator.hpp" +#include "flowProcess.hpp" +#include "pressureGradientScaling.hpp" + +namespace ablate::finiteVolume::processes { + +class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { +private: + // store ctx needed for function advection function that is passed into Petsc + struct AdvectionData { + //flow CFL + PetscReal cfl; + + /* number of gas species and extra species */ + PetscInt numberSpecies; + PetscInt numberEV; + + // EOS function calls (For Temperature it's better to just use the TemperatureTemperature function so we can guess Temperature from t + eos::ThermodynamicTemperatureFunction computeTemperature; + eos::ThermodynamicTemperatureFunction computeInternalEnergy; + eos::ThermodynamicTemperatureFunction computeSpeedOfSound; + eos::ThermodynamicTemperatureFunction computePressure; + + /* store method used for flux calculator */ + ablate::finiteVolume::fluxCalculator::FluxCalculatorFunction fluxCalculatorFunction; + void* fluxCalculatorCtx; + }; + AdvectionData advectionData; + + struct DiffusionData { + /* thermal conductivity Diffusivity, and Dynamic Viscosity*/ + eos::ThermodynamicTemperatureFunction kFunction; + eos::ThermodynamicTemperatureFunction muFunction; + eos::ThermodynamicTemperatureFunction diffFunction; + eos::ThermodynamicTemperatureFunction evDiffFunction; + + /* number of gas species and progress variables (NDD) */ + PetscInt numberSpecies; + PetscInt numberEV; + + /* functions to compute species enthalpy */ + eos::ThermodynamicTemperatureFunction computeSpeciesSensibleEnthalpyFunction; + /* store a scratch space for speciesSpeciesSensibleEnthalpy */ + std::vector speciesSpeciesSensibleEnthalpy; + /* store an optional scratch space for individual species diffusion */ + std::vector speciesDiffusionCoefficient; + /* store a scratch space for evDiffusionCoefficient */ + std::vector evDiffusionCoefficient; + }; + DiffusionData diffusionData; + + // Store the required ctx for time stepping + struct CflTimeStepData { + /* thermal conductivity*/ + AdvectionData* advectionData; + /* pressure gradient scaling */ + std::shared_ptr pgs; + }; + CflTimeStepData timeStepData; + + //! methods and functions to compute diffusion based time stepping + struct DiffusionTimeStepData { + /* number of gas species */ + PetscInt numberSpecies; + /* store an optional scratch space for individual species diffusion */ + std::vector speciesDiffusionCoefficient; + PetscReal NDDDiffusionCoefficient; + + //! stability factor for condition time step. 0 (default) does not compute factor + PetscReal diffusiveStabilityFactor; + //! stability factor for condition time step. 0 (default) does not compute factor + PetscReal conductionStabilityFactor; + //! stability factor for viscous diffusion time step. 0 (default) does not compute factor + PetscReal viscousStabilityFactor; + + /* diffusivity */ + eos::ThermodynamicTemperatureFunction diffFunction; + /* thermal conductivity*/ + eos::ThermodynamicTemperatureFunction kFunction; + /* dynamic viscosity*/ + eos::ThermodynamicTemperatureFunction muFunction; + /* specific heat*/ + eos::ThermodynamicTemperatureFunction specificHeat; + /* density */ + eos::ThermodynamicTemperatureFunction density; + + }; + DiffusionTimeStepData diffusionTimeStepData; + + const std::shared_ptr fluxCalculator; + const std::shared_ptr eos; + const std::shared_ptr transportModel; + const std::shared_ptr NDDTransportModel; + + eos::ThermodynamicTemperatureFunction computeTemperatureFunction; + eos::ThermodynamicFunction computePressureFunction; + +public: + explicit CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, + std::shared_ptr baseTransport = {}, std::shared_ptr evTransport = {}, std::shared_ptr = {}); + /** + * public function to link this process with the flow + * @param flow + */ + void Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) override; + + /** + * This Computes the Advective Flow for rho, rhoE, and rhoVel, rhoYi, and rhoEV. + * u = {"euler"} or {"euler", "densityYi"} if species are tracked + * a = {} + * ctx = FlowData_CompressibleFlow + * @return + */ + static PetscErrorCode AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscScalar fieldL[], const PetscScalar fieldR[], const PetscInt aOff[], + const PetscScalar auxL[], const PetscScalar auxR[], PetscScalar* flux, void* ctx); + + + /** + * This Computes the diffusion flux for euler rhoE, rhoVel + * u = {"euler", "densityYi"} + * a = {"temperature", "velocity"} + * ctx = FlowData_CompressibleFlow + * @return + */ + static PetscErrorCode DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the energy transfer for species diffusion flux for rhoE + * f = "euler" + * u = {"euler", "densityYi"} + * a = {"yi"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the energy transfer for species diffusion flux for rhoE for variable diffusion coefficient + * f = "euler" + * u = {"euler", "densityYi"} + * a = {"yi"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the species transfer for species diffusion flux + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the species transfer for species diffusion flux for variable diffusion coefficient + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + /** + * This computes the species transfer for species diffusion flux + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); + + /** + * This computes the species transfer for species diffusion flux for variable diffusion coefficient + * f = "densityYi" + * u = {"euler"} + * a = {"yi", "T"} + * ctx = SpeciesDiffusionData + * @return + */ + static PetscErrorCode DiffusionEVFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void* ctx); + + + + + // static function to compute time step for euler advection + static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute the conduction based time step + static double ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + +}; + +} //end namespace + +#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp index 2a19c19b4..af54d966b 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp @@ -18,7 +18,6 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { /* number of gas species and extra species */ PetscInt numberSpecies; - PetscInt numberEV; // EOS function calls (For Temperature it's better to just use the TemperatureTemperature function so we can guess Temperature from t eos::ThermodynamicTemperatureFunction computeTemperature; @@ -45,8 +44,6 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { std::vector speciesSpeciesSensibleEnthalpy; /* store an optional scratch space for individual species diffusion */ std::vector speciesDiffusionCoefficient; - /* store a scratch space for evDiffusionCoefficient */ - std::vector evDiffusionCoefficient; }; DiffusionData diffusionData; diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index 560b22eb2..b8c40bec2 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -149,6 +149,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc const int EULER_FIELD = 0; const int DENSITY_EV_FIELD = 1; + // Decode the left and right states PetscReal densityL; PetscReal normalVelocityL; From 642d5c2d3bc2bcabdd71512adef2004aa05ed3c2 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Wed, 9 Oct 2024 15:59:32 -0400 Subject: [PATCH 13/19] Forgot to remove the timers I added. --- src/finiteVolume/cellInterpolant.cpp | 10 +--------- src/finiteVolume/cellInterpolant.hpp | 2 +- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/finiteVolume/cellInterpolant.cpp b/src/finiteVolume/cellInterpolant.cpp index c9fc53b4e..e6f82ab92 100644 --- a/src/finiteVolume/cellInterpolant.cpp +++ b/src/finiteVolume/cellInterpolant.cpp @@ -42,7 +42,6 @@ ablate::finiteVolume::CellInterpolant::~CellInterpolant() { void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXVec, Vec locAuxVec, Vec locFVec, const std::shared_ptr& solverRegion, std::vector& rhsFunctions, const ablate::domain::Range& faceRange, const ablate::domain::Range& cellRange, Vec cellGeomVec, Vec faceGeomVec) { - StartEvent("CellInterpolant:ComputeRHS_Setup"); auto dm = subDomain->GetDM(); auto dmAux = subDomain->GetAuxDM(); @@ -85,9 +84,6 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV PetscScalar* locFArray; VecGetArray(locFVec, &locFArray) >> utilities::PetscUtilities::checkError; - EndEvent(); - StartEvent("CellInterpolant:ComputeRHS_ComputeGradients"); - // there must be a separate gradient vector/dm for field because they can be different sizes std::vector locGradVecs(nf, nullptr); @@ -103,8 +99,6 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV VecGetArrayRead(locGradVecs[field.subId], &locGradArrays[field.subId]) >> utilities::PetscUtilities::checkError; } } - EndEvent(); - StartEvent("CellInterpolant:ComputeRHS_ComputeFluxes"); ComputeFluxSourceTerms(dm, ds, totDim, @@ -124,8 +118,7 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV rhsFunctions, faceRange, cellRange); - EndEvent(); - StartEvent("CellInterpolant:ComputeRHS_Cleanup"); + // clean up cell grads for (const auto& field : subDomain->GetFields()) { if (locGradVecs[field.subId]) { @@ -143,7 +136,6 @@ void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXV VecRestoreArray(locFVec, &locFArray) >> utilities::PetscUtilities::checkError; VecRestoreArrayRead(faceGeomVec, (const PetscScalar**)&faceGeomArray) >> utilities::PetscUtilities::checkError; VecRestoreArrayRead(cellGeomVec, (const PetscScalar**)&cellGeomArray) >> utilities::PetscUtilities::checkError; - EndEvent(); } void ablate::finiteVolume::CellInterpolant::ComputeRHS(PetscReal time, Vec locXVec, Vec locAuxVec, Vec locFVec, const std::shared_ptr& solverRegion, diff --git a/src/finiteVolume/cellInterpolant.hpp b/src/finiteVolume/cellInterpolant.hpp index e497bc0bd..6bfbdc7c9 100644 --- a/src/finiteVolume/cellInterpolant.hpp +++ b/src/finiteVolume/cellInterpolant.hpp @@ -8,7 +8,7 @@ #include "domain/subDomain.hpp" namespace ablate::finiteVolume { -class CellInterpolant : private utilities::Loggable{ +class CellInterpolant { public: /** * Function assumes that the left/right solution and aux variables are discontinuous across the interface From d63d3187c35c1604e05dadbfc012191170257279 Mon Sep 17 00:00:00 2001 From: Kenneth Lawrence Budzinski Date: Mon, 14 Oct 2024 15:01:32 -0700 Subject: [PATCH 14/19] Formatting --- src/finiteVolume/cellInterpolant.cpp | 8 +- src/finiteVolume/compressibleFlowSolver.cpp | 42 +-- src/finiteVolume/compressibleFlowSolver.hpp | 3 +- src/finiteVolume/faceInterpolant.cpp | 6 +- src/finiteVolume/finiteVolumeSolver.cpp | 7 +- ...mpactCompressibleNSSpeciesNDDTransport.cpp | 257 ++++++++++-------- ...mpactCompressibleNSSpeciesNDDTransport.hpp | 29 +- .../compactCompressibleNSSpeciesTransport.cpp | 136 ++++----- .../compactCompressibleNSSpeciesTransport.hpp | 29 +- src/finiteVolume/processes/evTransport.cpp | 12 +- .../processes/navierStokesTransport.cpp | 12 +- .../processes/navierStokesTransport.hpp | 8 +- .../processes/speciesTransport.cpp | 10 +- .../processes/navierStokesTransportTests.cpp | 3 +- 14 files changed, 300 insertions(+), 262 deletions(-) diff --git a/src/finiteVolume/cellInterpolant.cpp b/src/finiteVolume/cellInterpolant.cpp index e6f82ab92..9f9702f5c 100644 --- a/src/finiteVolume/cellInterpolant.cpp +++ b/src/finiteVolume/cellInterpolant.cpp @@ -574,7 +574,7 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD // March over each source function for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { - PetscInt fluxOffset = 0; //Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) + PetscInt fluxOffset = 0; // Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) PetscArrayzero(flux, totDim) >> utilities::PetscUtilities::checkError; const auto& rhsFluxFunctionDescription = rhsFunctions[fun]; rhsFluxFunctionDescription.function(dim, fg, uOff[fun].data(), uL, uR, aOff[fun].data(), auxL, auxR, flux, rhsFluxFunctionDescription.context) >> utilities::PetscUtilities::checkError; @@ -587,7 +587,7 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD DMLabelGetValue(regionLabel, faceCells[0], &cellLabelValue) >> utilities::PetscUtilities::checkError; } if (ghost <= 0 && regionValue == cellLabelValue) { - DMPlexPointLocalFieldRef(dm, faceCells[0], fluxId[fun][updateFieldIdx], locFArray, &fL) >> utilities::PetscUtilities::checkError; + DMPlexPointLocalFieldRef(dm, faceCells[0], fluxId[fun][updateFieldIdx], locFArray, &fL) >> utilities::PetscUtilities::checkError; } cellLabelValue = regionValue; @@ -600,8 +600,8 @@ void ablate::finiteVolume::CellInterpolant::ComputeFluxSourceTerms(DM dm, PetscD } for (PetscInt d = 0; d < (fluxComponentSize[fun][updateFieldIdx]); ++d) { - if (fL) fL[d] -= flux[fluxOffset+d] / cgL->volume; - if (fR) fR[d] += flux[fluxOffset+d] / cgR->volume; + if (fL) fL[d] -= flux[fluxOffset + d] / cgL->volume; + if (fR) fR[d] += flux[fluxOffset + d] / cgR->volume; } fluxOffset += fluxComponentSize[fun][updateFieldIdx]; } diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index db6d3a0e5..ec8ee35bb 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -1,8 +1,8 @@ #include "compressibleFlowSolver.hpp" #include #include "compressibleFlowFields.hpp" -#include "finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp" #include "finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp" +#include "finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp" #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" @@ -21,25 +21,27 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string std::vector> additionalProcesses, std::vector> boundaryConditions, const std::shared_ptr& evTransport, int compact) - : FiniteVolumeSolver(std::move(solverId), std::move(region), std::move(options), compact ? ( compact == 1 ? - utilities::VectorUtilities::Merge( { - std::make_shared( - parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses) ), - std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport) }, - additionalProcesses) : - utilities::VectorUtilities::Merge( {std::make_shared ( - parameters, eosIn, fluxCalculatorIn, transport, evTransport ? evTransport : transport, utilities::VectorUtilities::Find(additionalProcesses) ) - }, additionalProcesses) ): - utilities::VectorUtilities::Merge( - { - // create assumed processes for compressible flow - std::make_shared( - parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses)), - std::make_shared(eosIn, fluxCalculatorIn, transport, parameters), - std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport), - }, - additionalProcesses), - std::move(boundaryConditions)) {} + : FiniteVolumeSolver( + std::move(solverId), std::move(region), std::move(options), + compact ? (compact == 1 ? utilities::VectorUtilities::Merge({std::make_shared( + parameters, eosIn, fluxCalculatorIn, transport, + utilities::VectorUtilities::Find(additionalProcesses)), + std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport)}, + additionalProcesses) + : utilities::VectorUtilities::Merge({std::make_shared( + parameters, eosIn, fluxCalculatorIn, transport, evTransport ? evTransport : transport, + utilities::VectorUtilities::Find(additionalProcesses))}, + additionalProcesses)) + : utilities::VectorUtilities::Merge( + { + // create assumed processes for compressible flow + std::make_shared( + parameters, eosIn, fluxCalculatorIn, transport, utilities::VectorUtilities::Find(additionalProcesses)), + std::make_shared(eosIn, fluxCalculatorIn, transport, parameters), + std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport), + }, + additionalProcesses), + std::move(boundaryConditions)) {} ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eosIn, const std::shared_ptr& parameters, diff --git a/src/finiteVolume/compressibleFlowSolver.hpp b/src/finiteVolume/compressibleFlowSolver.hpp index 78b0dd0d8..696e70765 100644 --- a/src/finiteVolume/compressibleFlowSolver.hpp +++ b/src/finiteVolume/compressibleFlowSolver.hpp @@ -31,7 +31,8 @@ class CompressibleFlowSolver : public FiniteVolumeSolver { CompressibleFlowSolver(std::string solverId, std::shared_ptr region, std::shared_ptr options, const std::shared_ptr& eos, const std::shared_ptr& parameters, const std::shared_ptr& transport, const std::shared_ptr& = {}, std::vector> additionalProcesses = {}, - std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}, int compact = 0); + std::vector> boundaryConditions = {}, const std::shared_ptr& evTransport = {}, + int compact = 0); /** * Constructor without ev or additional processes diff --git a/src/finiteVolume/faceInterpolant.cpp b/src/finiteVolume/faceInterpolant.cpp index aff388bd3..b9680e25c 100644 --- a/src/finiteVolume/faceInterpolant.cpp +++ b/src/finiteVolume/faceInterpolant.cpp @@ -389,7 +389,7 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV // March over each source function for (std::size_t fun = 0; fun < rhsFunctions.size(); fun++) { PetscArrayzero(flux.data(), totDim) >> utilities::PetscUtilities::checkError; - PetscInt fluxOffset = 0; //Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) + PetscInt fluxOffset = 0; // Flux offset for the function ( Currently calculated by just adding the number of components of the previous fields) const auto& rhsFluxFunctionDescription = rhsFunctions[fun]; rhsFluxFunctionDescription.function(dim, fg, @@ -426,8 +426,8 @@ void ablate::finiteVolume::FaceInterpolant::ComputeRHS(PetscReal time, Vec locXV } for (PetscInt d = 0; d < fluxComponentSize[fun][updateFieldIdx]; ++d) { - if (fL) fL[d] -= flux[d+fluxOffset] / cgL->volume; - if (fR) fR[d] += flux[d+fluxOffset] / cgR->volume; + if (fL) fL[d] -= flux[d + fluxOffset] / cgL->volume; + if (fR) fR[d] += flux[d + fluxOffset] / cgR->volume; } fluxOffset += fluxComponentSize[fun][updateFieldIdx]; } diff --git a/src/finiteVolume/finiteVolumeSolver.cpp b/src/finiteVolume/finiteVolumeSolver.cpp index 11a2f116a..9883e0e42 100644 --- a/src/finiteVolume/finiteVolumeSolver.cpp +++ b/src/finiteVolume/finiteVolumeSolver.cpp @@ -290,13 +290,12 @@ PetscErrorCode ablate::finiteVolume::FiniteVolumeSolver::ComputeRHSFunction(Pets PetscFunctionReturn(0); } - void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(CellInterpolant::DiscontinuousFluxFunction function, void* context, const std::vector& fields, const std::vector& inputFields, const std::vector& auxFields) { CellInterpolant::DiscontinuousFluxFunctionDescription functionDescription{.function = function, .context = context}; // map the field, inputFields, and auxFields to locations - for (auto& field : fields){ + for (auto& field : fields) { auto& fieldId = subDomain->GetField(field); functionDescription.updateFields.push_back(fieldId.id); } @@ -314,19 +313,17 @@ void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(CellInterpola discontinuousFluxFunctionDescriptions.push_back(functionDescription); } - void ablate::finiteVolume::FiniteVolumeSolver::RegisterRHSFunction(ablate::finiteVolume::FaceInterpolant::ContinuousFluxFunction function, void* context, const std::vector& updateFields, const std::vector& inputFields, const std::vector& auxFields) { // map the field, inputFields, and auxFields to locations FaceInterpolant::ContinuousFluxFunctionDescription functionDescription{.function = function, .context = context}; - for (auto& field: updateFields) { + for (auto& field : updateFields) { auto& fieldId = subDomain->GetField(field); functionDescription.updateFields.push_back(fieldId.id); } // Create the FVMRHS Function - for (auto& inputField : inputFields) { auto& inputFieldId = subDomain->GetField(inputField); functionDescription.inputFields.push_back(inputFieldId.id); diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp index 6f31f79bc..abe4aabef 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp @@ -2,21 +2,24 @@ #include #include "finiteVolume/compressibleFlowFields.hpp" #include "finiteVolume/fluxCalculator/ausm.hpp" +#include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" #include "finiteVolume/processes/speciesTransport.hpp" -#include "finiteVolume/processes/evTransport.hpp" #include "parameters/emptyParameters.hpp" #include "utilities/constants.hpp" #include "utilities/mathUtilities.hpp" #include "utilities/petscUtilities.hpp" -ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::CompactCompressibleNSSpeciesNDDTransport( - const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, - std::shared_ptr baseTransport, std::shared_ptr evTransport, std::shared_ptr pgs) - : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)), NDDTransportModel(std::move(evTransport)) { +ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr ¶metersIn, + std::shared_ptr eosIn, + std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, + std::shared_ptr evTransport, + std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)), NDDTransportModel(std::move(evTransport)) { auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); - if(fluxCalculator) { + if (fluxCalculator) { // cfl advectionData.cfl = parameters->Get("cfl", 0.5); @@ -30,7 +33,7 @@ ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Compa timeStepData.advectionData = &advectionData; timeStepData.pgs = std::move(pgs); - if(transportModel) { + if (transportModel) { // Add in the time stepping diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); @@ -46,23 +49,25 @@ ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Compa void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { // loop over convserved EV's and pull out NDD, if it's not there error out or ignore it? const auto &evConservedFields = flow.GetSubDomain().GetFields(domain::FieldLocation::SOL, CompressibleFlowFields::EV_TAG); - for (auto &evConservedField: evConservedFields) { - - if(evConservedField.name != CompressibleFlowFields::DENSITY_PROGRESS_FIELD) continue; + for (auto &evConservedField : evConservedFields) { + if (evConservedField.name != CompressibleFlowFields::DENSITY_PROGRESS_FIELD) continue; // set up the progress Extra Variables and the euler/species transport - auto nonConservedName = evConservedField.name.substr(CompressibleFlowFields::CONSERVED.length()); //non Conserved form just removes density prefix + auto nonConservedName = evConservedField.name.substr(CompressibleFlowFields::CONSERVED.length()); // non Conserved form just removes density prefix if (!flow.GetSubDomain().ContainsField(nonConservedName)) { - throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport process expects the conserved (" + evConservedField.name + ") and non-conserved (" + nonConservedName + - ") extra variables to be in the flow."); + throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport process expects the conserved (" + evConservedField.name + + ") and non-conserved (" + nonConservedName + ") extra variables to be in the flow."); } // Register the euler,eulerYi, and species source terms if (fluxCalculator) { - //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better - //If it is worse for perfect gas's, going to need to add in an option switch -klb - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD,evConservedField.name}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD,evConservedField.name}, {CompressibleFlowFields::TEMPERATURE_FIELD}); - - //Set the ComputeCFLTimestepFrom flow Process through + // I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + // If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, + &advectionData, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD, evConservedField.name}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD, evConservedField.name}, + {CompressibleFlowFields::TEMPERATURE_FIELD}); + + // Set the ComputeCFLTimestepFrom flow Process through flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); advectionData.numberEV = evConservedField.numberComponents; @@ -89,7 +94,7 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD, CompressibleFlowFields::VELOCITY_FIELD}); } - //Species + // Species if (diffusionData.diffFunction.function) { // Specify a different rhs function depending on if the diffusion flux is constant if (diffusionData.diffFunction.propertySize == 1) { @@ -119,7 +124,6 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: } } - // Check to see if time step calculations should be added for viscosity or conduction if (diffusionTimeStepData.conductionStabilityFactor > 0 || diffusionTimeStepData.viscousStabilityFactor > 0) { diffusionTimeStepData.kFunction = diffusionData.kFunction; @@ -136,68 +140,95 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: flow.RegisterComputeTimeStepFunction(ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); } } - if (diffusionTimeStepData.diffusiveStabilityFactor > 0){ - diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; - diffusionTimeStepData.diffFunction = diffusionData.diffFunction; - flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); + if (diffusionTimeStepData.diffusiveStabilityFactor > 0) { + diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; + diffusionTimeStepData.diffFunction = diffusionData.diffFunction; + flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); } } - if(NDDTransportModel) { + if (NDDTransportModel) { diffusionData.numberEV = evConservedField.numberComponents; diffusionData.evDiffusionCoefficient.resize(diffusionData.numberEV); diffusionData.evDiffFunction = NDDTransportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); - //ExtraVariable + // ExtraVariable if (diffusionData.evDiffFunction.function) { if (diffusionData.evDiffFunction.propertySize == 1) { - flow.RegisterRHSFunction(DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName,CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction( + DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.evDiffFunction.propertySize == diffusionData.numberEV) { flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName}); - } else throw std::invalid_argument("The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesNDDTransport!"); + } else + throw std::invalid_argument("The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesNDDTransport!"); } } - //Setup up aux updates and normalizations + // Setup up aux updates and normalizations if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, + nullptr, + std::vector{CompressibleFlowFields::VELOCITY_FIELD}, + {CompressibleFlowFields::EULER_FIELD}); } if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, + &computeTemperatureFunction, + std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, + {}); } if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); + flow.RegisterAuxFieldUpdate( + ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); } - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, std::vector{CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, + &advectionData.numberSpecies, + std::vector{CompressibleFlowFields::YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); // clean up the species flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); - //limit the EV's + // limit the EV's if (evConservedField.Tagged(CompressibleFlowFields::PositiveRange)) { const auto &conservedFieldName = evConservedField.name; - flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::PositiveExtraVariables(ts, solver, conservedFieldName); }); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdatePositiveEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + flow.RegisterPostEvaluate( + [conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::PositiveExtraVariables(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdatePositiveEVField, + &advectionData.numberEV, + std::vector{nonConservedName}, + {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); } else if (evConservedField.Tagged(CompressibleFlowFields::BoundRange)) { const auto &conservedFieldName = evConservedField.name; - flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariables(ts, solver, conservedFieldName); }); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateBoundEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + flow.RegisterPostEvaluate( + [conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariables(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateBoundEVField, + &advectionData.numberEV, + std::vector{nonConservedName}, + {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); } else if (evConservedField.Tagged(CompressibleFlowFields::MinusOneToOneRange)) { const auto &conservedFieldName = evConservedField.name; - flow.RegisterPostEvaluate([conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariablesMinusOneToOne(ts, solver, conservedFieldName); }); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateMinusOneToOneBoundEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + flow.RegisterPostEvaluate( + [conservedFieldName](TS ts, ablate::solver::Solver &solver) { ablate::finiteVolume::processes::EVTransport::BoundExtraVariablesMinusOneToOne(ts, solver, conservedFieldName); }); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateMinusOneToOneBoundEVField, + &advectionData.numberEV, + std::vector{nonConservedName}, + {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); } else { // Allow for the entire range - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateEVField, &advectionData.numberEV, std::vector{nonConservedName}, {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::EVTransport::UpdateEVField, + &advectionData.numberEV, + std::vector{nonConservedName}, + {CompressibleFlowFields::EULER_FIELD, evConservedField.name}); } - } //End EV loop + } // End EV loop } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, - const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, - PetscScalar* flux, void* ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt *uOff, const PetscScalar *fieldL, + const PetscScalar *fieldR, const PetscInt *aOff, const PetscScalar *auxL, + const PetscScalar *auxR, PetscScalar *flux, void *ctx) { PetscFunctionBeginUser; - auto advectionData = (AdvectionData*)ctx; + auto advectionData = (AdvectionData *)ctx; const int EULER_FIELD = 0; const int RHOYI_FIELD = 1; @@ -221,7 +252,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67+.33*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]] * .67 + .33 * auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -245,7 +276,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.67+.33*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]] * .67 + .33 * auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -274,11 +305,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT for (PetscInt n = 0; n < dim; n++) { flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; - //EV's - for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) - flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldL[uOff[RHOEV_FIELD] + ev] / densityL) * areaMag; + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) flux[uOff[RHOYI_FIELD] + ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; + // EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++) flux[uOff[RHOEV_FIELD] + ev] = (massFlux * fieldL[uOff[RHOEV_FIELD] + ev] / densityL) * areaMag; } else if (direction == fluxCalculator::RIGHT) { flux[CompressibleFlowFields::RHO] = massFlux * areaMag; PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); @@ -287,11 +316,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT for (PetscInt n = 0; n < dim; n++) { flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; - //EV's - for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) - flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) flux[uOff[RHOYI_FIELD] + ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; + // EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++) flux[uOff[RHOEV_FIELD] + ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; } else { flux[CompressibleFlowFields::RHO] = massFlux * areaMag; @@ -306,18 +333,16 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; } for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; - //EV's - for (PetscInt ev = 0; ev < advectionData->numberEV; ev++ ) - flux[uOff[RHOEV_FIELD]+ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; -// flux[uOff[RHOEV_FIELD]+ev] = massFlux * 0.5 * (fieldR[uOff[RHOEV_FIELD] + ev] + fieldL[uOff[RHOEV_FIELD] + ev] ) / ( 0.5 * (densityR + densityL)) * areaMag; + flux[uOff[RHOYI_FIELD] + ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns]) / (0.5 * (densityL + densityR)) * areaMag; + // EV's + for (PetscInt ev = 0; ev < advectionData->numberEV; ev++) flux[uOff[RHOEV_FIELD] + ev] = (massFlux * fieldR[uOff[RHOEV_FIELD] + ev] / densityR) * areaMag; + // flux[uOff[RHOEV_FIELD]+ev] = massFlux * 0.5 * (fieldR[uOff[RHOEV_FIELD] + ev] + fieldL[uOff[RHOEV_FIELD] + ev] ) / ( 0.5 * (densityR + densityL)) * areaMag; } PetscFunctionReturn(0); } - -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -325,13 +350,13 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; // Get the flow param - auto timeStepData = (CflTimeStepData*)ctx; + auto timeStepData = (CflTimeStepData *)ctx; auto advectionData = timeStepData->advectionData; // Get the fv geom Vec locCharacteristicsVec; DM characteristicsDm; - const PetscScalar* locCharacteristicsArray; + const PetscScalar *locCharacteristicsArray; flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; @@ -339,7 +364,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport ablate::domain::Range cellRange; flow.GetCellRangeWithoutGhost(cellRange); - const PetscScalar* x; + const PetscScalar *x; VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; // Get the dim from the dm @@ -360,9 +385,9 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { auto cell = cellRange.GetPoint(c); - const PetscReal* euler; - const PetscReal* conserved = NULL; - const PetscReal* cellCharacteristics = NULL; + const PetscReal *euler; + const PetscReal *conserved = NULL; + const PetscReal *cellCharacteristics = NULL; DMPlexPointGlobalFieldRead(dm, cell, eulerId, x, &euler) >> utilities::PetscUtilities::checkError; DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; @@ -371,7 +396,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport PetscReal rho = euler[CompressibleFlowFields::RHO]; // Get the speed of sound from the eos - //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) + // TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) PetscReal temperature; advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; PetscReal a; @@ -395,7 +420,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -403,12 +428,12 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; // Get the flow param - auto diffusionData = (DiffusionTimeStepData*)ctx; + auto diffusionData = (DiffusionTimeStepData *)ctx; // Get the fv geom Vec locCharacteristicsVec; DM characteristicsDm; - const PetscScalar* locCharacteristicsArray; + const PetscScalar *locCharacteristicsArray; flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; @@ -417,11 +442,11 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport flow.GetCellRangeWithoutGhost(cellRange); // Get the solution data - const PetscScalar* x; + const PetscScalar *x; VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; // Get the auxData - const PetscScalar* aux; + const PetscScalar *aux; const DM auxDM = flow.GetSubDomain().GetAuxDM(); VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; @@ -446,13 +471,13 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { auto cell = cellRange.GetPoint(c); - const PetscReal* conserved = NULL; + const PetscReal *conserved = NULL; DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; - const PetscReal* temperature = NULL; + const PetscReal *temperature = NULL; DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; - const PetscReal* cellCharacteristics = NULL; + const PetscReal *cellCharacteristics = NULL; DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; if (conserved) { // must be real cell and not ghost @@ -481,7 +506,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -489,12 +514,12 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; // Get the flow param - auto diffusionData = (DiffusionTimeStepData*)ctx; + auto diffusionData = (DiffusionTimeStepData *)ctx; // Get the fv geom Vec locCharacteristicsVec; DM characteristicsDm; - const PetscScalar* locCharacteristicsArray; + const PetscScalar *locCharacteristicsArray; flow.GetMeshCharacteristics(characteristicsDm, locCharacteristicsVec); VecGetArrayRead(locCharacteristicsVec, &locCharacteristicsArray) >> utilities::PetscUtilities::checkError; @@ -503,11 +528,11 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport flow.GetCellRangeWithoutGhost(cellRange); // Get the solution data - const PetscScalar* x; + const PetscScalar *x; VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; // Get the auxData - const PetscScalar* aux; + const PetscScalar *aux; const DM auxDM = flow.GetSubDomain().GetAuxDM(); VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; @@ -530,13 +555,13 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { auto cell = cellRange.GetPoint(c); - const PetscReal* conserved = NULL; + const PetscReal *conserved = NULL; DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; - const PetscReal* temperature = NULL; + const PetscReal *temperature = NULL; DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; - const PetscReal* cellCharacteristics = NULL; + const PetscReal *cellCharacteristics = NULL; DMPlexPointLocalRead(characteristicsDm, cell, locCharacteristicsArray, &cellCharacteristics) >> utilities::PetscUtilities::checkError; if (conserved) { // must be real cell and not ghost @@ -629,15 +654,16 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], - const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int T = 0; const int VEL = 1; - auto flowParameters = (DiffusionData*)ctx; + auto flowParameters = (DiffusionData *)ctx; // Compute mu and k PetscReal mu = 0.0; @@ -686,8 +712,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT } PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], - const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -727,10 +754,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], - const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], - const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFluxVariableDiffusionCoefficient( + PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -770,8 +796,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT } PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], - const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -803,10 +830,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], - const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], - const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient( + PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -836,9 +862,10 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], - const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int EULER_FIELD = 0; @@ -848,7 +875,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; // Temperature is second aux in // compute diff PetscReal diff = 0.0; flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); @@ -867,10 +894,11 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], - PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int EULER_FIELD = 0; @@ -880,7 +908,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; // Temperature is second aux in // compute diff flowParameters->diffFunction.function(field, temperature, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); @@ -896,4 +924,3 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT } PetscFunctionReturn(0); } - diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp index e14b18e68..9473233ab 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp @@ -10,10 +10,10 @@ namespace ablate::finiteVolume::processes { class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { -private: + private: // store ctx needed for function advection function that is passed into Petsc struct AdvectionData { - //flow CFL + // flow CFL PetscReal cfl; /* number of gas species and extra species */ @@ -63,7 +63,7 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { }; CflTimeStepData timeStepData; - //! methods and functions to compute diffusion based time stepping + //! methods and functions to compute diffusion based time stepping struct DiffusionTimeStepData { /* number of gas species */ PetscInt numberSpecies; @@ -80,7 +80,7 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { /* diffusivity */ eos::ThermodynamicTemperatureFunction diffFunction; - /* thermal conductivity*/ + /* thermal conductivity*/ eos::ThermodynamicTemperatureFunction kFunction; /* dynamic viscosity*/ eos::ThermodynamicTemperatureFunction muFunction; @@ -88,7 +88,6 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction specificHeat; /* density */ eos::ThermodynamicTemperatureFunction density; - }; DiffusionTimeStepData diffusionTimeStepData; @@ -100,16 +99,17 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction computeTemperatureFunction; eos::ThermodynamicFunction computePressureFunction; -public: - explicit CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, - std::shared_ptr baseTransport = {}, std::shared_ptr evTransport = {}, std::shared_ptr = {}); + public: + explicit CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr& parameters, std::shared_ptr eos, + std::shared_ptr fluxCalcIn = {}, std::shared_ptr baseTransport = {}, + std::shared_ptr evTransport = {}, std::shared_ptr = {}); /** * public function to link this process with the flow * @param flow */ void Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) override; - /** + /** * This Computes the Advective Flow for rho, rhoE, and rhoVel, rhoYi, and rhoEV. * u = {"euler"} or {"euler", "densityYi"} if species are tracked * a = {} @@ -119,7 +119,6 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { static PetscErrorCode AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscScalar fieldL[], const PetscScalar fieldR[], const PetscInt aOff[], const PetscScalar auxL[], const PetscScalar auxR[], PetscScalar* flux, void* ctx); - /** * This Computes the diffusion flux for euler rhoE, rhoVel * u = {"euler", "densityYi"} @@ -130,7 +129,7 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { static PetscErrorCode DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); - /** + /** * This computes the energy transfer for species diffusion flux for rhoE * f = "euler" * u = {"euler", "densityYi"} @@ -198,9 +197,6 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); - - - // static function to compute time step for euler advection static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step @@ -209,9 +205,8 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step static double ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); - }; -} //end namespace +} // namespace ablate::finiteVolume::processes -#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H +#endif // ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp index 639c9ad97..a7087ef8f 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp @@ -9,13 +9,15 @@ #include "utilities/mathUtilities.hpp" #include "utilities/petscUtilities.hpp" -ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::CompactCompressibleNSSpeciesTransport( - const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, - std::shared_ptr baseTransport, std::shared_ptr pgs) - : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)),transportModel(std::move(baseTransport)) { +ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::CompactCompressibleNSSpeciesTransport(const std::shared_ptr& parametersIn, + std::shared_ptr eosIn, + std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, + std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)) { auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); - if(fluxCalculator) { + if (fluxCalculator) { // cfl advectionData.cfl = parameters->Get("cfl", 0.5); @@ -29,7 +31,7 @@ ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::CompactC timeStepData.advectionData = &advectionData; timeStepData.pgs = std::move(pgs); - if(transportModel) { + if (transportModel) { // Add in the time stepping diffusionTimeStepData.conductionStabilityFactor = parameters->Get("conductionStabilityFactor", 0.0); diffusionTimeStepData.viscousStabilityFactor = parameters->Get("viscousStabilityFactor", 0.0); @@ -42,15 +44,18 @@ ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::CompactC } } -void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { +void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) { // Register the euler,eulerYi, and species source terms if (fluxCalculator) { - //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better - //If it is worse for perfect gas's, going to need to add in an option switch -klb - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD,CompressibleFlowFields::DENSITY_YI_FIELD}, - {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); - - //Set the ComputeCFLTimestepFrom flow Process through + // I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + // If it is worse for perfect gas's, going to need to add in an option switch -klb + flow.RegisterRHSFunction(AdvectionFlux, + &advectionData, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::TEMPERATURE_FIELD}); + + // Set the ComputeCFLTimestepFrom flow Process through flow.RegisterComputeTimeStepFunction(ComputeCflTimeStep, &timeStepData, "cfl"); advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); @@ -122,33 +127,41 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::Set flow.RegisterComputeTimeStepFunction(ComputeViscousDiffusionTimeStep, &diffusionTimeStepData, "visc"); } } - if (diffusionTimeStepData.diffusiveStabilityFactor > 0){ - diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; - diffusionTimeStepData.diffFunction = diffusionData.diffFunction; - flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); + if (diffusionTimeStepData.diffusiveStabilityFactor > 0) { + diffusionTimeStepData.numberSpecies = diffusionData.numberSpecies; + diffusionTimeStepData.diffFunction = diffusionData.diffFunction; + flow.RegisterComputeTimeStepFunction(ComputeViscousSpeciesDiffusionTimeStep, &diffusionTimeStepData, "spec"); } } - //Setup up aux updates and normalizations + // Setup up aux updates and normalizations if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, nullptr, std::vector{CompressibleFlowFields::VELOCITY_FIELD}, {CompressibleFlowFields::EULER_FIELD}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, + nullptr, + std::vector{CompressibleFlowFields::VELOCITY_FIELD}, + {CompressibleFlowFields::EULER_FIELD}); } if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::TEMPERATURE_FIELD)) { computeTemperatureFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); + flow.RegisterAuxFieldUpdate( + ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxTemperatureField, &computeTemperatureFunction, std::vector{CompressibleFlowFields::TEMPERATURE_FIELD}, {}); } if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::PRESSURE_FIELD)) { computePressureFunction = eos->GetThermodynamicFunction(eos::ThermodynamicProperty::Pressure, flow.GetSubDomain().GetFields()); - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); + flow.RegisterAuxFieldUpdate( + ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxPressureField, &computePressureFunction, std::vector{CompressibleFlowFields::PRESSURE_FIELD}, {}); } - flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, &advectionData.numberSpecies, std::vector{CompressibleFlowFields::YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); + flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::SpeciesTransport::UpdateAuxMassFractionField, + &advectionData.numberSpecies, + std::vector{CompressibleFlowFields::YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}); // clean up the species flow.RegisterPostEvaluate(ablate::finiteVolume::processes::SpeciesTransport::NormalizeSpecies); } PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt* uOff, const PetscScalar* fieldL, - const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, - PetscScalar* flux, void* ctx) { + const PetscScalar* fieldR, const PetscInt* aOff, const PetscScalar* auxL, const PetscScalar* auxR, + PetscScalar* flux, void* ctx) { PetscFunctionBeginUser; auto advectionData = (AdvectionData*)ctx; @@ -174,7 +187,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67+.33*auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldL, auxL[aOff[0]] * .67 + .33 * auxR[aOff[0]], &temperatureL, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -198,7 +211,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]]*.67+.33*auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); + PetscCall(advectionData->computeTemperature.function(fieldR, auxR[aOff[0]] * .67 + .33 * auxL[aOff[0]], &temperatureR, advectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -227,8 +240,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran for (PetscInt n = 0; n < dim; n++) { flux[CompressibleFlowFields::RHOU + n] = velocityL[n] * massFlux * areaMag + p12 * fg->normal[n]; } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) flux[uOff[RHOYI_FIELD] + ns] = massFlux * fieldL[uOff[RHOYI_FIELD] + ns] / densityL * areaMag; } else if (direction == fluxCalculator::RIGHT) { flux[CompressibleFlowFields::RHO] = massFlux * areaMag; PetscReal velMagR = utilities::MathUtilities::MagVector(dim, velocityR); @@ -237,8 +249,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran for (PetscInt n = 0; n < dim; n++) { flux[CompressibleFlowFields::RHOU + n] = velocityR[n] * massFlux * areaMag + p12 * fg->normal[n]; } - for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; + for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) flux[uOff[RHOYI_FIELD] + ns] = massFlux * fieldR[uOff[RHOYI_FIELD] + ns] / densityR * areaMag; } else { flux[CompressibleFlowFields::RHO] = massFlux * areaMag; @@ -253,13 +264,12 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran flux[CompressibleFlowFields::RHOU + n] = 0.5 * (velocityL[n] + velocityR[n]) * massFlux * areaMag + p12 * fg->normal[n]; } for (PetscInt ns = 0; ns < advectionData->numberSpecies; ns++) - flux[uOff[RHOYI_FIELD]+ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns] ) / ( 0.5 * (densityL + densityR)) * areaMag; + flux[uOff[RHOYI_FIELD] + ns] = massFlux * 0.5 * (fieldR[uOff[RHOYI_FIELD] + ns] + fieldL[uOff[RHOYI_FIELD] + ns]) / (0.5 * (densityL + densityR)) * areaMag; } PetscFunctionReturn(0); } - double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { // Get the dm and current solution vector DM dm; @@ -314,7 +324,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C PetscReal rho = euler[CompressibleFlowFields::RHO]; // Get the speed of sound from the eos - //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) + // TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) PetscReal temperature; advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; PetscReal a; @@ -504,7 +514,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C flow.RestoreRange(cellRange); return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -512,7 +522,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C TSGetSolution(ts, &v) >> utilities::PetscUtilities::checkError; // Get the flow param - auto diffusionData = (DiffusionTimeStepData *)ctx; + auto diffusionData = (DiffusionTimeStepData*)ctx; // Get the fv geom PetscReal minCellRadius; @@ -523,11 +533,11 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C flow.GetCellRangeWithoutGhost(cellRange); // Get the solution data - const PetscScalar *x; + const PetscScalar* x; VecGetArrayRead(v, &x) >> utilities::PetscUtilities::checkError; // Get the auxData - const PetscScalar *aux; + const PetscScalar* aux; const DM auxDM = flow.GetSubDomain().GetAuxDM(); VecGetArrayRead(flow.GetSubDomain().GetAuxGlobalVector(), &aux) >> utilities::PetscUtilities::checkError; @@ -551,10 +561,10 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C for (PetscInt c = cellRange.start; c < cellRange.end; ++c) { auto cell = cellRange.GetPoint(c); - const PetscReal *conserved = NULL; + const PetscReal* conserved = NULL; DMPlexPointGlobalRead(dm, cell, x, &conserved) >> utilities::PetscUtilities::checkError; - const PetscReal *temperature = NULL; + const PetscReal* temperature = NULL; DMPlexPointLocalFieldRead(auxDM, cell, temperatureField, aux, &temperature) >> utilities::PetscUtilities::checkError; if (conserved) { // must be real cell and not ghost @@ -572,9 +582,10 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::C return dtMin; } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], - const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], + void* ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int T = 0; @@ -628,16 +639,17 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], - const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void* ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; const int euler = 0; const int temp = 1; - auto flowParameters = (DiffusionData *)ctx; + auto flowParameters = (DiffusionData*)ctx; // get the current density from euler const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; @@ -670,17 +682,18 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], - const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], - const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionEnergyFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; const int euler = 0; const int temp = 1; - auto flowParameters = (DiffusionData *)ctx; + auto flowParameters = (DiffusionData*)ctx; // get the current density from euler const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; @@ -712,16 +725,17 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], - const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], + const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], + PetscScalar flux[], void* ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; const int euler = 0; const int temp = 1; - auto flowParameters = (DiffusionData *)ctx; + auto flowParameters = (DiffusionData*)ctx; // get the current density from euler const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; @@ -746,17 +760,18 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], - const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], - const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], + const PetscScalar grad[], const PetscInt aOff[], + const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void* ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; const int euler = 0; const int temp = 1; - auto flowParameters = (DiffusionData *)ctx; + auto flowParameters = (DiffusionData*)ctx; // get the current density from euler const PetscReal density = field[uOff[euler] + CompressibleFlowFields::RHO]; @@ -778,4 +793,3 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTran PetscFunctionReturn(0); } - diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp index af54d966b..91cdb47ac 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp @@ -10,10 +10,10 @@ namespace ablate::finiteVolume::processes { class CompactCompressibleNSSpeciesTransport : public FlowProcess { -private: + private: // store ctx needed for function advection function that is passed into Petsc struct AdvectionData { - //flow CFL + // flow CFL PetscReal cfl; /* number of gas species and extra species */ @@ -56,7 +56,7 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { }; CflTimeStepData timeStepData; - //! methods and functions to compute diffusion based time stepping + //! methods and functions to compute diffusion based time stepping struct DiffusionTimeStepData { /* number of gas species */ PetscInt numberSpecies; @@ -72,7 +72,7 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { /* diffusivity */ eos::ThermodynamicTemperatureFunction diffFunction; - /* thermal conductivity*/ + /* thermal conductivity*/ eos::ThermodynamicTemperatureFunction kFunction; /* dynamic viscosity*/ eos::ThermodynamicTemperatureFunction muFunction; @@ -80,7 +80,6 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction specificHeat; /* density */ eos::ThermodynamicTemperatureFunction density; - }; DiffusionTimeStepData diffusionTimeStepData; @@ -91,16 +90,17 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction computeTemperatureFunction; eos::ThermodynamicFunction computePressureFunction; -public: - explicit CompactCompressibleNSSpeciesTransport(const std::shared_ptr& parameters, std::shared_ptr eos, std::shared_ptr fluxCalcIn={}, - std::shared_ptr baseTransport = {}, std::shared_ptr = {}); + public: + explicit CompactCompressibleNSSpeciesTransport(const std::shared_ptr& parameters, std::shared_ptr eos, + std::shared_ptr fluxCalcIn = {}, std::shared_ptr baseTransport = {}, + std::shared_ptr = {}); /** * public function to link this process with the flow * @param flow */ void Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) override; - /** + /** * This Computes the Advective Flow for rho, rhoE, and rhoVel, rhoYi, and rhoEV. * u = {"euler"} or {"euler", "densityYi"} if species are tracked * a = {} @@ -110,7 +110,6 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { static PetscErrorCode AdvectionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscScalar fieldL[], const PetscScalar fieldR[], const PetscInt aOff[], const PetscScalar auxL[], const PetscScalar auxR[], PetscScalar* flux, void* ctx); - /** * This Computes the diffusion flux for euler rhoE, rhoVel * u = {"euler", "densityYi"} @@ -121,7 +120,7 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { static PetscErrorCode DiffusionFlux(PetscInt dim, const PetscFVFaceGeom* fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); - /** + /** * This computes the energy transfer for species diffusion flux for rhoE * f = "euler" * u = {"euler", "densityYi"} @@ -167,9 +166,6 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void* ctx); - - - // static function to compute time step for euler advection static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step @@ -178,9 +174,8 @@ class CompactCompressibleNSSpeciesTransport : public FlowProcess { static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step static double ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); - }; -} //end namespace +} // namespace ablate::finiteVolume::processes -#endif //ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESTRANSPORT_H +#endif // ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESTRANSPORT_H diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index b8c40bec2..e2e43c2f2 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -49,7 +49,8 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F if (diffusionData.diffFunction.function) { if (diffusionData.diffFunction.propertySize == 1) { - flow.RegisterRHSFunction(DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved,CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction( + DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.diffFunction.propertySize == diffusionData.numberEV) { flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved}); } else { @@ -149,7 +150,6 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc const int EULER_FIELD = 0; const int DENSITY_EV_FIELD = 1; - // Decode the left and right states PetscReal densityL; PetscReal normalVelocityL; @@ -161,7 +161,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67 + auxR[aOff[0]]*.33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]] * .67 + auxR[aOff[0]] * .33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -185,7 +185,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::AdvectionFlux(Petsc densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]]*.33 + auxR[aOff[0]]*.67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]] * .33 + auxR[aOff[0]] * .67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -232,7 +232,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFlux(Pet // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; // Temperature is second aux in // compute diff PetscReal diff = 0.0; flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); @@ -264,7 +264,7 @@ PetscErrorCode ablate::finiteVolume::processes::EVTransport::DiffusionEVFluxVari // get the current density from euler const PetscReal density = field[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; - const PetscReal temperature = aux[aOff[1]]; //Temperature is second aux in + const PetscReal temperature = aux[aOff[1]]; // Temperature is second aux in // compute diff flowParameters->diffFunction.function(field, temperature, flowParameters->evDiffusionCoefficient.data(), flowParameters->diffFunction.context.get()); diff --git a/src/finiteVolume/processes/navierStokesTransport.cpp b/src/finiteVolume/processes/navierStokesTransport.cpp index 54d79f579..185600be2 100644 --- a/src/finiteVolume/processes/navierStokesTransport.cpp +++ b/src/finiteVolume/processes/navierStokesTransport.cpp @@ -35,8 +35,8 @@ ablate::finiteVolume::processes::NavierStokesTransport::NavierStokesTransport(co void ablate::finiteVolume::processes::NavierStokesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver& flow) { // Register the euler source terms if (fluxCalculator) { - //I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better - //If it is worse for perfect gas's, going to need to add in an option switch -klb + // I don't know why we wouldn't push through the old temperature fields, maybe slower for perfect gas/idealized gas's but when there is a temperature iterative method this should be better + // If it is worse for perfect gas's, going to need to add in an option switch -klb flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::EULER_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); // PetscErrorCode PetscOptionsGetBool(PetscOptions options,const char pre[],const char name[],PetscBool *ivalue,PetscBool *set) @@ -124,7 +124,8 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]]*.67 + .33*auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall( + eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[TEMP_FIELD]] * .67 + .33 * auxR[aOff[TEMP_FIELD]], &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -149,7 +150,8 @@ PetscErrorCode ablate::finiteVolume::processes::NavierStokesTransport::Advection densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]]*.33 + .67*auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall( + eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[TEMP_FIELD]] * .33 + .67 * auxR[aOff[TEMP_FIELD]], &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; @@ -258,7 +260,7 @@ double ablate::finiteVolume::processes::NavierStokesTransport::ComputeCflTimeSte PetscReal rho = euler[CompressibleFlowFields::RHO]; // Get the speed of sound from the eos - //TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) + // TODO:: Replace this with a better temperature guess (see compute conduction Time Step below) PetscReal temperature; advectionData->computeTemperature.function(conserved, 300, &temperature, advectionData->computeTemperature.context.get()) >> utilities::PetscUtilities::checkError; PetscReal a; diff --git a/src/finiteVolume/processes/navierStokesTransport.hpp b/src/finiteVolume/processes/navierStokesTransport.hpp index 58478e663..abdfa9355 100644 --- a/src/finiteVolume/processes/navierStokesTransport.hpp +++ b/src/finiteVolume/processes/navierStokesTransport.hpp @@ -38,14 +38,14 @@ class NavierStokesTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction muFunction; }; - // static function to compute time step for euler advection - static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); + // static function to compute time step for euler advection + static double ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step static double ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); // static function to compute the conduction based time step static double ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver& flow, void* ctx); -private: + private: const std::shared_ptr fluxCalculator; const std::shared_ptr eos; const std::shared_ptr transportModel; @@ -88,7 +88,7 @@ class NavierStokesTransport : public FlowProcess { }; DiffusionTimeStepData diffusionTimeStepData; - public: + public: /** * Function to compute the temperature field. This function assumes that the input values will be {"euler", "densityYi"} */ diff --git a/src/finiteVolume/processes/speciesTransport.cpp b/src/finiteVolume/processes/speciesTransport.cpp index 6bae73fe1..911ca6b95 100644 --- a/src/finiteVolume/processes/speciesTransport.cpp +++ b/src/finiteVolume/processes/speciesTransport.cpp @@ -35,7 +35,11 @@ ablate::finiteVolume::processes::SpeciesTransport::SpeciesTransport(std::shared_ void ablate::finiteVolume::processes::SpeciesTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { if (!eos->GetSpeciesVariables().empty()) { if (fluxCalculator) { - flow.RegisterRHSFunction(AdvectionFlux, &advectionData, {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(AdvectionFlux, + &advectionData, + {CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, + {CompressibleFlowFields::TEMPERATURE_FIELD}); advectionData.computeTemperature = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::Temperature, flow.GetSubDomain().GetFields()); advectionData.computeInternalEnergy = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::InternalSensibleEnergy, flow.GetSubDomain().GetFields()); advectionData.computeSpeedOfSound = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeedOfSound, flow.GetSubDomain().GetFields()); @@ -280,7 +284,7 @@ PetscErrorCode ablate::finiteVolume::processes::SpeciesTransport::AdvectionFlux( densityL = fieldL[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureL; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]]*.67 + auxR[aOff[0]]*.33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldL, auxL[aOff[0]] * .67 + auxR[aOff[0]] * .33, &temperatureL, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityL = 0.0; @@ -302,7 +306,7 @@ PetscErrorCode ablate::finiteVolume::processes::SpeciesTransport::AdvectionFlux( densityR = fieldR[uOff[EULER_FIELD] + CompressibleFlowFields::RHO]; PetscReal temperatureR; - PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]]*.33 + auxR[aOff[0]]*.67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); + PetscCall(eulerAdvectionData->computeTemperature.function(fieldR, auxL[aOff[0]] * .33 + auxR[aOff[0]] * .67, &temperatureR, eulerAdvectionData->computeTemperature.context.get())); // Get the velocity in this direction normalVelocityR = 0.0; diff --git a/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp b/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp index 32c049315..10c160b9b 100644 --- a/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp +++ b/tests/unitTests/finiteVolume/processes/navierStokesTransportTests.cpp @@ -44,7 +44,8 @@ TEST_P(NavierStokesTransportFluxTestFixture, ShouldComputeCorrectFlux) { PetscInt uOff[1] = {0}; PetscInt aOff[1] = {0}; PetscReal TempGuess[1] = {300}; - ablate::finiteVolume::processes::NavierStokesTransport::AdvectionFlux(params.area.size(), &faceGeom, uOff, ¶ms.xLeft[0], ¶ms.xRight[0], aOff, TempGuess, TempGuess, &computedFlux[0], &eulerFlowData); + ablate::finiteVolume::processes::NavierStokesTransport::AdvectionFlux( + params.area.size(), &faceGeom, uOff, ¶ms.xLeft[0], ¶ms.xRight[0], aOff, TempGuess, TempGuess, &computedFlux[0], &eulerFlowData); // assert for (std::size_t i = 0; i < params.expectedFlux.size(); i++) { From 71a0c02fa3a646bbc91fce858a4da2c6015c358c Mon Sep 17 00:00:00 2001 From: klbudzin Date: Tue, 15 Oct 2024 12:06:20 -0400 Subject: [PATCH 15/19] Missed a aux field input --- .../processes/compactCompressibleNSSpeciesNDDTransport.cpp | 2 +- src/finiteVolume/processes/evTransport.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp index abe4aabef..00ff889e0 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp @@ -157,7 +157,7 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: flow.RegisterRHSFunction( DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.evDiffFunction.propertySize == diffusionData.numberEV) { - flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName}); + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); } else throw std::invalid_argument("The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesNDDTransport!"); } diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index e2e43c2f2..a61645fc2 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -52,7 +52,7 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F flow.RegisterRHSFunction( DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.diffFunction.propertySize == diffusionData.numberEV) { - flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved}); + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); } else { throw std::invalid_argument("The diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::EVTransport."); } From 66eb05b5e0773dfb6a693de329c097cc6fa4f906 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Mon, 3 Mar 2025 16:18:32 -0500 Subject: [PATCH 16/19] My local presets snuck in to my last PR and were never caught. --- CMakePresets.json | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/CMakePresets.json b/CMakePresets.json index 6fe2a08e9..723987490 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -34,36 +34,6 @@ "PKG_CONFIG_PATH": "$env{PETSC_DIR}/arch-ablate-opt/lib/pkgconfig:$penv{PKG_CONFIG_PATH}" } }, - { - "name": "OptMainPetsc", - "displayName": "CLion Opt Config", - "description": "Default build for ABLATE in CLion", - "binaryDir": "${sourceDir}/cmake-build-MainPetsc", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "COMPILE_MPI_COMMAND": "$env{PETSC_DIR}/arch-ablate-opt/bin/mpirun" - }, - "environment": { - "PETSC_DIR": "/home/klbud/Software/PetscUpdating/petsc", - "PETSC_ARCH": "arch-ablate-opt", - "PKG_CONFIG_PATH": "$env{PETSC_DIR}/arch-ablate-opt/lib/pkgconfig:$penv{PKG_CONFIG_PATH}" - } - }, - { - "name": "OptFluentPetsc", - "displayName": "CLion Opt Config", - "description": "Default build for ABLATE in CLion", - "binaryDir": "${sourceDir}/cmake-build-FluentPetsc", - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Release", - "COMPILE_MPI_COMMAND": "$env{PETSC_DIR}/arch-ablate-opt/bin/mpirun" - }, - "environment": { - "PETSC_DIR": "/home/klbud/Software/PetscUpdating/petscW", - "PETSC_ARCH": "arch-ablate-opt", - "PKG_CONFIG_PATH": "$env{PETSC_DIR}/arch-ablate-opt/lib/pkgconfig:$penv{PKG_CONFIG_PATH}" - } - }, { "name": "local-ablate-opt-info", "displayName": "CLion RelWithDebugInfo Config", From 8b345ddc2d5f5fa1ee97b7d118c980e26e5acaa2 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 7 Mar 2025 18:59:30 -0500 Subject: [PATCH 17/19] Test additions and formatting issues --- src/finiteVolume/compressibleFlowSolver.cpp | 4 +- src/finiteVolume/processes/CMakeLists.txt | 4 +- ...sibleNSSpeciesSingleProgressTransport.cpp} | 123 ++++++++-------- ...sibleNSSpeciesSingleProgressTransport.hpp} | 21 +-- .../compactCompressibleNSSpeciesTransport.cpp | 2 +- src/finiteVolume/processes/evTransport.cpp | 6 +- .../sampleSootDiffusionFlameCompact2.yaml | 132 ++++++++++++++++++ .../simpleReactingFlow_zerork_Compact.yaml | 73 ++++++++++ 8 files changed, 289 insertions(+), 76 deletions(-) rename src/finiteVolume/processes/{compactCompressibleNSSpeciesNDDTransport.cpp => compactCompressibleNSSpeciesSingleProgressTransport.cpp} (87%) rename src/finiteVolume/processes/{compactCompressibleNSSpeciesNDDTransport.hpp => compactCompressibleNSSpeciesSingleProgressTransport.hpp} (89%) create mode 100644 tests/integrationTests/inputs/reactingFlow/sampleSootDiffusionFlameCompact2.yaml create mode 100644 tests/integrationTests/inputs/reactingFlow/simpleReactingFlow_zerork_Compact.yaml diff --git a/src/finiteVolume/compressibleFlowSolver.cpp b/src/finiteVolume/compressibleFlowSolver.cpp index ec8ee35bb..f5607d6a4 100644 --- a/src/finiteVolume/compressibleFlowSolver.cpp +++ b/src/finiteVolume/compressibleFlowSolver.cpp @@ -1,7 +1,7 @@ #include "compressibleFlowSolver.hpp" #include #include "compressibleFlowFields.hpp" -#include "finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp" +#include "finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.hpp" #include "finiteVolume/processes/compactCompressibleNSSpeciesTransport.hpp" #include "finiteVolume/processes/evTransport.hpp" #include "finiteVolume/processes/navierStokesTransport.hpp" @@ -28,7 +28,7 @@ ablate::finiteVolume::CompressibleFlowSolver::CompressibleFlowSolver(std::string utilities::VectorUtilities::Find(additionalProcesses)), std::make_shared(eosIn, fluxCalculatorIn, evTransport ? evTransport : transport)}, additionalProcesses) - : utilities::VectorUtilities::Merge({std::make_shared( + : utilities::VectorUtilities::Merge({std::make_shared( parameters, eosIn, fluxCalculatorIn, transport, evTransport ? evTransport : transport, utilities::VectorUtilities::Find(additionalProcesses))}, additionalProcesses)) diff --git a/src/finiteVolume/processes/CMakeLists.txt b/src/finiteVolume/processes/CMakeLists.txt index 9b47aa5f2..f2a6239c4 100644 --- a/src/finiteVolume/processes/CMakeLists.txt +++ b/src/finiteVolume/processes/CMakeLists.txt @@ -17,7 +17,7 @@ target_sources(ablateLibrary surfaceForce.cpp soot.cpp compactCompressibleNSSpeciesTransport.cpp - compactCompressibleNSSpeciesNDDTransport.cpp + compactCompressibleNSSpeciesSingleProgressTransport.cpp PUBLIC process.hpp @@ -38,5 +38,5 @@ target_sources(ablateLibrary surfaceForce.hpp soot.hpp compactCompressibleNSSpeciesTransport.hpp - compactCompressibleNSSpeciesNDDTransport.hpp + compactCompressibleNSSpeciesSingleProgressTransport.hpp ) diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.cpp similarity index 87% rename from src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp rename to src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.cpp index 00ff889e0..4a9fb3d3f 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.cpp @@ -1,4 +1,4 @@ -#include "compactCompressibleNSSpeciesNDDTransport.hpp" +#include "compactCompressibleNSSpeciesSingleProgressTransport.hpp" #include #include "finiteVolume/compressibleFlowFields.hpp" #include "finiteVolume/fluxCalculator/ausm.hpp" @@ -10,13 +10,11 @@ #include "utilities/mathUtilities.hpp" #include "utilities/petscUtilities.hpp" -ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr ¶metersIn, - std::shared_ptr eosIn, - std::shared_ptr fluxCalcIn, - std::shared_ptr baseTransport, - std::shared_ptr evTransport, - std::shared_ptr pgs) - : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)), NDDTransportModel(std::move(evTransport)) { +ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::CompactCompressibleNSSpeciesSingleProgressTransport( + const std::shared_ptr ¶metersIn, std::shared_ptr eosIn, std::shared_ptr fluxCalcIn, + std::shared_ptr baseTransport, std::shared_ptr evTransport, + std::shared_ptr pgs) + : advectionData(), fluxCalculator(fluxCalcIn), eos(std::move(eosIn)), transportModel(std::move(baseTransport)), SingleProgressTransportModel(std::move(evTransport)) { auto parameters = ablate::parameters::EmptyParameters::Check(parametersIn); if (fluxCalculator) { @@ -41,20 +39,23 @@ ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Compa diffusionTimeStepData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); diffusionData.numberSpecies = (PetscInt)eos->GetSpeciesVariables().size(); + diffusionData.numberEV = 1; diffusionData.speciesSpeciesSensibleEnthalpy.resize(eos->GetSpeciesVariables().size()); diffusionData.speciesDiffusionCoefficient.resize(eos->GetSpeciesVariables().size()); } } -void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { - // loop over convserved EV's and pull out NDD, if it's not there error out or ignore it? +void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::Setup(ablate::finiteVolume::FiniteVolumeSolver &flow) { + // loop over convserved EV's and pull out SingleProgress, if there's someething there other than it, error out. const auto &evConservedFields = flow.GetSubDomain().GetFields(domain::FieldLocation::SOL, CompressibleFlowFields::EV_TAG); for (auto &evConservedField : evConservedFields) { - if (evConservedField.name != CompressibleFlowFields::DENSITY_PROGRESS_FIELD) continue; + if (evConservedField.name != CompressibleFlowFields::DENSITY_PROGRESS_FIELD) { + throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport process expects only the progress extra variable."); + } // set up the progress Extra Variables and the euler/species transport auto nonConservedName = evConservedField.name.substr(CompressibleFlowFields::CONSERVED.length()); // non Conserved form just removes density prefix if (!flow.GetSubDomain().ContainsField(nonConservedName)) { - throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport process expects the conserved (" + evConservedField.name + + throw std::invalid_argument("The ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport process expects the conserved (" + evConservedField.name + ") and non-conserved (" + nonConservedName + ") extra variables to be in the flow."); } // Register the euler,eulerYi, and species source terms @@ -84,6 +85,26 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: diffusionData.kFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Conductivity, flow.GetSubDomain().GetFields()); diffusionData.diffFunction = transportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); diffusionData.computeSpeciesSensibleEnthalpyFunction = eos->GetThermodynamicTemperatureFunction(eos::ThermodynamicProperty::SpeciesSensibleEnthalpy, flow.GetSubDomain().GetFields()); + if (SingleProgressTransportModel) { + diffusionData.numberEV = evConservedField.numberComponents; + diffusionData.evDiffusionCoefficient.resize(diffusionData.numberEV); + diffusionData.evDiffFunction = SingleProgressTransportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); + // ExtraVariable + if (diffusionData.evDiffFunction.function) { + if (diffusionData.evDiffFunction.propertySize == 1) { + flow.RegisterRHSFunction( + DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else if (diffusionData.evDiffFunction.propertySize == diffusionData.numberEV) { + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, + &diffusionData, + {evConservedField.name}, + {CompressibleFlowFields::EULER_FIELD}, + {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); + } else + throw std::invalid_argument( + "The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesSingleProgressTransport!"); + } + } /* For now we will do 3 different diffusive flux calls just since it doesn't seem like their splitting costs too much time in redundant calculations */ if (diffusionData.muFunction.function || diffusionData.kFunction.function) { @@ -108,7 +129,7 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { + } else if (diffusionData.diffFunction.propertySize == diffusionData.numberSpecies) { flow.RegisterRHSFunction(DiffusionEnergyFluxVariableDiffusionCoefficient, &diffusionData, {CompressibleFlowFields::EULER_FIELD}, @@ -147,22 +168,6 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: } } - if (NDDTransportModel) { - diffusionData.numberEV = evConservedField.numberComponents; - diffusionData.evDiffusionCoefficient.resize(diffusionData.numberEV); - diffusionData.evDiffFunction = NDDTransportModel->GetTransportTemperatureFunction(eos::transport::TransportProperty::Diffusivity, flow.GetSubDomain().GetFields()); - // ExtraVariable - if (diffusionData.evDiffFunction.function) { - if (diffusionData.evDiffFunction.propertySize == 1) { - flow.RegisterRHSFunction( - DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else if (diffusionData.evDiffFunction.propertySize == diffusionData.numberEV) { - flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConservedName, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else - throw std::invalid_argument("The ev diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::CompatcCompressibleNSSpeciesNDDTransport!"); - } - } - // Setup up aux updates and normalizations if (flow.GetSubDomain().ContainsField(CompressibleFlowFields::VELOCITY_FIELD)) { flow.RegisterAuxFieldUpdate(ablate::finiteVolume::processes::NavierStokesTransport::UpdateAuxVelocityField, @@ -223,9 +228,9 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport:: } // End EV loop } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt *uOff, const PetscScalar *fieldL, - const PetscScalar *fieldR, const PetscInt *aOff, const PetscScalar *auxL, - const PetscScalar *auxR, PetscScalar *flux, void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::AdvectionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt *uOff, + const PetscScalar *fieldL, const PetscScalar *fieldR, const PetscInt *aOff, + const PetscScalar *auxL, const PetscScalar *auxR, PetscScalar *flux, void *ctx) { PetscFunctionBeginUser; auto advectionData = (AdvectionData *)ctx; @@ -342,7 +347,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::ComputeCflTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -420,7 +425,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::ComputeConductionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -506,7 +511,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::ComputeViscousDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -586,7 +591,7 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport flow.RestoreRange(cellRange); return dtMin; } -double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { +double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::ComputeViscousSpeciesDiffusionTimeStep(TS ts, ablate::finiteVolume::FiniteVolumeSolver &flow, void *ctx) { // Get the dm and current solution vector DM dm; TSGetDM(ts, &dm) >> utilities::PetscUtilities::checkError; @@ -654,10 +659,10 @@ double ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport return dtMin; } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], - PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int T = 0; @@ -711,10 +716,10 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], - PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionEnergyFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -754,7 +759,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEnergyFluxVariableDiffusionCoefficient( +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionEnergyFluxVariableDiffusionCoefficient( PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; @@ -795,10 +800,10 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], - PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionSpeciesFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int yi = 0; @@ -830,7 +835,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient( +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionSpeciesFluxVariableDiffusionCoefficient( PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; @@ -862,10 +867,10 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], - const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], const PetscScalar gradAux[], - PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionEVFlux(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], + const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], + const PetscInt aOff[], const PetscInt aOff_x[], const PetscScalar aux[], + const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int EULER_FIELD = 0; @@ -878,7 +883,7 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT const PetscReal temperature = aux[aOff[1]]; // Temperature is second aux in // compute diff PetscReal diff = 0.0; - flowParameters->diffFunction.function(field, temperature, &diff, flowParameters->diffFunction.context.get()); + flowParameters->evDiffFunction.function(field, temperature, &diff, flowParameters->evDiffFunction.context.get()); // species equations for (PetscInt ev = 0; ev < flowParameters->numberEV; ++ev) { @@ -894,11 +899,9 @@ PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDT PetscFunctionReturn(0); } -PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesNDDTransport::DiffusionEVFluxVariableDiffusionCoefficient(PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], - const PetscInt uOff_x[], const PetscScalar field[], - const PetscScalar grad[], const PetscInt aOff[], - const PetscInt aOff_x[], const PetscScalar aux[], - const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { +PetscErrorCode ablate::finiteVolume::processes::CompactCompressibleNSSpeciesSingleProgressTransport::DiffusionEVFluxVariableDiffusionCoefficient( + PetscInt dim, const PetscFVFaceGeom *fg, const PetscInt uOff[], const PetscInt uOff_x[], const PetscScalar field[], const PetscScalar grad[], const PetscInt aOff[], const PetscInt aOff_x[], + const PetscScalar aux[], const PetscScalar gradAux[], PetscScalar flux[], void *ctx) { PetscFunctionBeginUser; // this order is based upon the order that they are passed into RegisterRHSFunction const int EULER_FIELD = 0; diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.hpp similarity index 89% rename from src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp rename to src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.hpp index 9473233ab..56d674705 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesNDDTransport.hpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesSingleProgressTransport.hpp @@ -1,5 +1,5 @@ -#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H -#define ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H +#ifndef ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESSingleProgressTRANSPORT_H +#define ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESSingleProgressTRANSPORT_H #include #include "eos/transport/transportModel.hpp" @@ -9,7 +9,7 @@ namespace ablate::finiteVolume::processes { -class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { +class CompactCompressibleNSSpeciesSingleProgressTransport : public FlowProcess { private: // store ctx needed for function advection function that is passed into Petsc struct AdvectionData { @@ -39,7 +39,7 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { eos::ThermodynamicTemperatureFunction diffFunction; eos::ThermodynamicTemperatureFunction evDiffFunction; - /* number of gas species and progress variables (NDD) */ + /* number of gas species and components in the SingleProgress */ PetscInt numberSpecies; PetscInt numberEV; @@ -69,7 +69,7 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { PetscInt numberSpecies; /* store an optional scratch space for individual species diffusion */ std::vector speciesDiffusionCoefficient; - PetscReal NDDDiffusionCoefficient; + PetscReal SingleProgressDiffusionCoefficient; //! stability factor for condition time step. 0 (default) does not compute factor PetscReal diffusiveStabilityFactor; @@ -94,15 +94,16 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { const std::shared_ptr fluxCalculator; const std::shared_ptr eos; const std::shared_ptr transportModel; - const std::shared_ptr NDDTransportModel; + const std::shared_ptr SingleProgressTransportModel; eos::ThermodynamicTemperatureFunction computeTemperatureFunction; eos::ThermodynamicFunction computePressureFunction; public: - explicit CompactCompressibleNSSpeciesNDDTransport(const std::shared_ptr& parameters, std::shared_ptr eos, - std::shared_ptr fluxCalcIn = {}, std::shared_ptr baseTransport = {}, - std::shared_ptr evTransport = {}, std::shared_ptr = {}); + explicit CompactCompressibleNSSpeciesSingleProgressTransport(const std::shared_ptr& parameters, std::shared_ptr eos, + std::shared_ptr fluxCalcIn = {}, std::shared_ptr baseTransport = {}, + std::shared_ptr evTransport = {}, + std::shared_ptr = {}); /** * public function to link this process with the flow * @param flow @@ -209,4 +210,4 @@ class CompactCompressibleNSSpeciesNDDTransport : public FlowProcess { } // namespace ablate::finiteVolume::processes -#endif // ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESNDDTRANSPORT_H +#endif // ABLATELIBRARY_COMPACTCOMPRESSIBLENSSPECIESSingleProgressTRANSPORT_H diff --git a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp index a7087ef8f..bff9a76a2 100644 --- a/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp +++ b/src/finiteVolume/processes/compactCompressibleNSSpeciesTransport.cpp @@ -95,7 +95,7 @@ void ablate::finiteVolume::processes::CompactCompressibleNSSpeciesTransport::Set {CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::EULER_FIELD, CompressibleFlowFields::DENSITY_YI_FIELD}, {CompressibleFlowFields::YI_FIELD, CompressibleFlowFields::TEMPERATURE_FIELD}); - } else if (diffusionData.diffFunction.propertySize == advectionData.numberSpecies) { + } else if (diffusionData.diffFunction.propertySize == diffusionData.numberSpecies) { flow.RegisterRHSFunction(DiffusionEnergyFluxVariableDiffusionCoefficient, &diffusionData, {CompressibleFlowFields::EULER_FIELD}, diff --git a/src/finiteVolume/processes/evTransport.cpp b/src/finiteVolume/processes/evTransport.cpp index a61645fc2..03dee5d3a 100644 --- a/src/finiteVolume/processes/evTransport.cpp +++ b/src/finiteVolume/processes/evTransport.cpp @@ -52,7 +52,11 @@ void ablate::finiteVolume::processes::EVTransport::Setup(ablate::finiteVolume::F flow.RegisterRHSFunction( DiffusionEVFlux, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); } else if (diffusionData.diffFunction.propertySize == diffusionData.numberEV) { - flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, &diffusionData, {evConservedField.name}, {CompressibleFlowFields::EULER_FIELD}, {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); + flow.RegisterRHSFunction(DiffusionEVFluxVariableDiffusionCoefficient, + &diffusionData, + {evConservedField.name}, + {CompressibleFlowFields::EULER_FIELD}, + {nonConserved, CompressibleFlowFields::TEMPERATURE_FIELD}); } else { throw std::invalid_argument("The diffusion property size must be 1 or number of ev in ablate::finiteVolume::processes::EVTransport."); } diff --git a/tests/integrationTests/inputs/reactingFlow/sampleSootDiffusionFlameCompact2.yaml b/tests/integrationTests/inputs/reactingFlow/sampleSootDiffusionFlameCompact2.yaml new file mode 100644 index 000000000..47becb47c --- /dev/null +++ b/tests/integrationTests/inputs/reactingFlow/sampleSootDiffusionFlameCompact2.yaml @@ -0,0 +1,132 @@ +# Example 1D diffusion flame with soot and thermophoretic diffusion. The diffusion flame only uses +# the transport processes of the Navier–Stokes equations. +--- +test: + # a unique test name for this integration tests + name: sampleSootDiffusionFlameCompact2 + # create a default assert that compares the log file + assert: "inputs/reactingFlow/sampleSootDiffusionFlame.txt" + +environment: + title: _1DSampleSootDiffusionFlameTchemCompact + tagDirectory: false +arguments: { } +timestepper: + arguments: + ts_type: rk + ts_max_time: 1 + ts_max_steps: 50 + ts_dt: 1.0e-10 + ts_adapt_safety: 0.95 + ts_adapt_type: physicsConstrained + domain: !ablate::domain::BoxMeshBoundaryCells + name: simpleBoxField + faces: [ 50 ] + lower: [ 0.0 ] + upper: [ 0.01 ] + options: + dm_plex_hash_location: true + preModifiers: + # distribute the mesh across the mpi rank with ghost cells + - !ablate::domain::modifiers::DistributeWithGhostCells + ghostCellDepth: 2 + postModifiers: + - !ablate::domain::modifiers::GhostBoundaryCells + fields: + - !ablate::finiteVolume::CompressibleFlowFields + eos: !ablate::eos::TChemSoot &eos + mechFile: ../mechanisms/gri30.yml + options: + # set a minimum temperature for the chemical kinetics ode integration + thresholdTemperature: 560 + conservedFieldOptions: + petscfv_type: leastsquares + region: + name: domain + - !ablate::domain::FieldDescription + name: pressure + type: FV + location: aux + region: + name: domain + initialization: + - !ablate::finiteVolume::fieldFunctions::Euler + state: &flowFieldState + eos: *eos + temperature: !ablate::mathFunctions::Peak + startValues: [ 300 ] + peakValues: [ 2710 ] + endValues: [ 300 ] + start: 0.0 + peak: 0.007 + end: 0.01 + pressure: 101325.0 + velocity: "0.0" + other: !ablate::finiteVolume::fieldFunctions::MassFractions + &massFracs + eos: *eos + values: + - fieldName: O2 + field: !ablate::mathFunctions::Linear + startValues: [ 0.0 ] + endValues: [ 1.0 ] + end: .01 + - fieldName: C2H4 + field: !ablate::mathFunctions::Linear + startValues: [ 1.0 ] + endValues: [ 0.0 ] + end: .01 + - !ablate::finiteVolume::fieldFunctions::DensityMassFractions + state: *flowFieldState + + # Set the number density to zero + - fieldName: densityProgress + field: "0.0" + + +solvers: + - !ablate::finiteVolume::CompressibleFlowSolver + id: flowField + compact: 2 + region: + name: interiorCells + eos: *eos + transport: !ablate::eos::tChemSoot::SootSpeciesTransportModel + transport: !ablate::eos::transport::Sutherland + eos: *eos + evTransport: !ablate::eos::tChemSoot::SootProgressTransportModel + transport: !ablate::eos::transport::Sutherland + eos: *eos + monitors: + - !ablate::monitors::TimeStepMonitor + interval: 10 + - !ablate::monitors::CurveMonitor + interval: 25 + additionalProcesses: + - !ablate::finiteVolume::processes::Chemistry + eos: *eos + - !ablate::finiteVolume::processes::ConstantPressureFix + eos: *eos + pressure: 101325.0 + - !ablate::finiteVolume::processes::ThermophoreticDiffusion + transport: !ablate::eos::transport::Sutherland + eos: *eos + - !ablate::boundarySolver::BoundarySolver + id: walls + region: + name: boundaryCellsRight + fieldBoundary: + name: boundaryFaces + mergeFaces: true + processes: + - !ablate::boundarySolver::lodi::Inlet + eos: *eos + - !ablate::boundarySolver::BoundarySolver + id: slab boundary + region: + name: boundaryCellsLeft + fieldBoundary: + name: boundaryFaces + processes: + - !ablate::boundarySolver::lodi::Inlet + eos: *eos diff --git a/tests/integrationTests/inputs/reactingFlow/simpleReactingFlow_zerork_Compact.yaml b/tests/integrationTests/inputs/reactingFlow/simpleReactingFlow_zerork_Compact.yaml new file mode 100644 index 000000000..917122d70 --- /dev/null +++ b/tests/integrationTests/inputs/reactingFlow/simpleReactingFlow_zerork_Compact.yaml @@ -0,0 +1,73 @@ +--- +test: + # a unique test name for this integration tests + name: simpleReactingFlowZerorkCompact1 + # create a default assert that compares the log file + assert: "inputs/reactingFlow/simpleReactingFlow.zerork.txt" + +environment: + title: _simpleReactingFlowZerorkCompact + tagDirectory: false +arguments: + dm_plex_separate_marker: "" +timestepper: + name: theMainTimeStepper + io: + interval: 0 + arguments: + ts_type: rk + ts_max_time: 0.2 + ts_max_steps: 25 + ts_dt: 1E-6 + ts_adapt_type: none + domain: !ablate::domain::BoxMesh + name: simpleBoxField + faces: [ 10, 10 ] + lower: [ -0.1, -0.1 ] + upper: [ .1, .1 ] + boundary: [ "NONE", "NONE" ] + simplex: false + modifiers: + - !ablate::domain::modifiers::GhostBoundaryCells + - !ablate::domain::modifiers::DistributeWithGhostCells + fields: + - !ablate::finiteVolume::CompressibleFlowFields + eos: !ablate::eos::zerorkEOS &eos + reactionFile: ../mechanisms/gri30.inp + thermoFile: ../mechanisms/gri30.dat + options: + reactorType: ConstantPressure #zerork deafult is constant volume + initialization: + - &eulerField + fieldName: "euler" #for euler all components are in a single field + field: >- + 1.0, + sqrt(x*x+y*y) <.05 ? 1498029.067485712: -58970.06564527616, + 0.0, + 0.0 + - &densityYiField + fieldName: "densityYi" #H2,H,O,O2,OH,H2O,HO2,H2O2,C,CH,CH2,CH2(S),CH3,CH4,CO,CO2,HCO,CH2O,CH2OH,CH3O,CH3OH,C2H,C2H2,C2H3,C2H4,C2H5,C2H6,HCCO,CH2CO,HCCOH,N,NH,NH2,NH3,NNH,NO,NO2,N2O,HNO,CN,HCN,H2CN,HCNN,HCNO,HOCN,HNCO,NCO,N2,AR,C3H7,C3H8,CH2CHO,CH3CHO + field: 0,0,0,0.2,0,0,0,0,0,0,0,0,0,0.2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0.6,0,0,0,0,0 +solver: !ablate::finiteVolume::CompressibleFlowSolver + id: vortexFlowField + compact: 1 + parameters: {} + transport: + k: 0.0 + mu: 0.0 + additionalProcesses: + # add in the reaction processes + - !ablate::finiteVolume::processes::Chemistry + eos: *eos + boundaryConditions: + - !ablate::finiteVolume::boundaryConditions::EssentialGhost + boundaryName: "walls" + labelIds: [1, 2, 3, 4] + boundaryValue: *eulerField + - !ablate::finiteVolume::boundaryConditions::EssentialGhost + boundaryName: "walls" + labelIds: [1, 2, 3, 4] + boundaryValue: *densityYiField + monitors: + - !ablate::monitors::TimeStepMonitor + eos: *eos From 9571c13d39c943a4add0ba90c76b3b7cc8e21f3d Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 7 Mar 2025 19:06:31 -0500 Subject: [PATCH 18/19] Revert "Change to vector output for solution/aux field. Something got messed up with mixed cells as well that I have to wait to be adressed" This reverts commit 43fc1c0a5573ce1db3df3eb77666385e634dd417. --- .../tracerParticles2DHDF5Monitor/domain.xmf | 512 ++++++++++++++---- 1 file changed, 416 insertions(+), 96 deletions(-) diff --git a/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf b/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf index ff517f8c9..a4219e7f6 100644 --- a/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf +++ b/tests/integrationTests/inputs/particles/tracerParticles2DHDF5Monitor/domain.xmf @@ -39,10 +39,20 @@ - - + + + + 0 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 0 0 0 1 1 1 1 25 2 + 0 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -69,10 +79,20 @@ - - + + + + 0 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 0 0 0 1 1 1 1 25 2 + 0 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -111,10 +131,20 @@ - - + + + + 1 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 1 0 0 1 1 1 1 25 2 + 1 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -141,10 +171,20 @@ - - + + + + 1 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 1 0 0 1 1 1 1 25 2 + 1 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -183,10 +223,20 @@ - - + + + + 2 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 2 0 0 1 1 1 1 25 2 + 2 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -213,10 +263,20 @@ - - + + + + 2 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 2 0 0 1 1 1 1 25 2 + 2 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -255,10 +315,20 @@ - - + + + + 3 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 3 0 0 1 1 1 1 25 2 + 3 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -285,10 +355,20 @@ - - + + + + 3 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 3 0 0 1 1 1 1 25 2 + 3 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -327,10 +407,20 @@ - - + + + + 4 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 4 0 0 1 1 1 1 25 2 + 4 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -357,10 +447,20 @@ - - + + + + 4 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 4 0 0 1 1 1 1 25 2 + 4 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -399,10 +499,20 @@ - - + + + + 5 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 5 0 0 1 1 1 1 25 2 + 5 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -429,10 +539,20 @@ - - + + + + 5 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 5 0 0 1 1 1 1 25 2 + 5 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -471,10 +591,20 @@ - - + + + + 6 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 6 0 0 1 1 1 1 25 2 + 6 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -501,10 +631,20 @@ - - + + + + 6 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 6 0 0 1 1 1 1 25 2 + 6 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -543,10 +683,20 @@ - - + + + + 7 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 7 0 0 1 1 1 1 25 2 + 7 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -573,10 +723,20 @@ - - + + + + 7 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 7 0 0 1 1 1 1 25 2 + 7 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -615,10 +775,20 @@ - - + + + + 8 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 8 0 0 1 1 1 1 25 2 + 8 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -645,10 +815,20 @@ - - + + + + 8 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 8 0 0 1 1 1 1 25 2 + 8 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -687,10 +867,20 @@ - - + + + + 9 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 9 0 0 1 1 1 1 25 2 + 9 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -717,10 +907,20 @@ - - + + + + 9 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 9 0 0 1 1 1 1 25 2 + 9 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -759,10 +959,20 @@ - - + + + + 10 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 10 0 0 1 1 1 1 25 2 + 10 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -789,10 +999,20 @@ - - + + + + 10 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 10 0 0 1 1 1 1 25 2 + 10 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -831,10 +1051,20 @@ - - + + + + 11 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 11 0 0 1 1 1 1 25 2 + 11 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -861,10 +1091,20 @@ - - + + + + 11 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 11 0 0 1 1 1 1 25 2 + 11 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -903,10 +1143,20 @@ - - + + + + 12 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 12 0 0 1 1 1 1 25 2 + 12 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -933,10 +1183,20 @@ - - + + + + 12 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 12 0 0 1 1 1 1 25 2 + 12 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -975,10 +1235,20 @@ - - + + + + 13 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 13 0 0 1 1 1 1 25 2 + 13 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -1005,10 +1275,20 @@ - - + + + + 13 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 13 0 0 1 1 1 1 25 2 + 13 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -1047,10 +1327,20 @@ - - + + + + 14 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 14 0 0 1 1 1 1 25 2 + 14 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -1077,10 +1367,20 @@ - - + + + + 14 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 14 0 0 1 1 1 1 25 2 + 14 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity @@ -1119,10 +1419,20 @@ - - + + + + 15 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/exact_velocity + + + + + - 15 0 0 1 1 1 1 25 2 + 15 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/exact_velocity @@ -1149,10 +1459,20 @@ - - + + + + 15 0 0 1 1 2 1 25 1 + + + domain.hdf5:/vertex_fields/solution_velocity + + + + + - 15 0 0 1 1 1 1 25 2 + 15 0 1 1 1 2 1 25 1 domain.hdf5:/vertex_fields/solution_velocity From ef9b497c4925f51f77fe5927cace700503ad27e4 Mon Sep 17 00:00:00 2001 From: klbudzin Date: Fri, 7 Mar 2025 19:19:49 -0500 Subject: [PATCH 19/19] Version Bump, will also want to figure out the .dev deploy before pushing to main --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a9faa7801..d3e7a48c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ cmake_minimum_required(VERSION 3.18.4) include(config/petscCompilers.cmake) # Set the project details -project(ablateLibrary VERSION 0.13.01) +project(ablateLibrary VERSION 0.13.02) # Load the Required 3rd Party Libaries pkg_check_modules(PETSc REQUIRED IMPORTED_TARGET GLOBAL PETSc)