|
| 1 | +/*---------------------------------------------------------------------------*\ |
| 2 | + ========= | |
| 3 | + \\ / F ield | DeepFlame: a]deep learning [empowered open-source |
| 4 | + \\ / O peration | platform for reacting flow simulations |
| 5 | + \\ / A nd | Copyright (C) 2023-2025 DeepFlame Contributors |
| 6 | + \\/ M anipulation | |
| 7 | +------------------------------------------------------------------------------- |
| 8 | +License |
| 9 | + This file is part of DeepFlame. |
| 10 | +
|
| 11 | + DeepFlame is free software: you can redistribute it and/or modify it |
| 12 | + under the terms of the GNU General Public License as published by |
| 13 | + the Free Software Foundation, either version 3 of the License, or |
| 14 | + (at your option) any later version. |
| 15 | +
|
| 16 | + DeepFlame is distributed in the hope that it will be useful, but WITHOUT |
| 17 | + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 18 | + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 19 | + for more details. |
| 20 | +
|
| 21 | + You should have received a copy of the GNU General Public License |
| 22 | + along with DeepFlame. If not, see <http://www.gnu.org/licenses/>. |
| 23 | +
|
| 24 | +Application |
| 25 | + dfHybridFoam |
| 26 | +
|
| 27 | +Copyright |
| 28 | + Author: Teng Zhang @ AISI |
| 29 | + Date: 2026-03-05 |
| 30 | +
|
| 31 | +Description |
| 32 | + Multi-region hybrid solver combining dfLowMachFoam (pressure-based PIMPLE) |
| 33 | + for low-Mach regions (e.g. combustor without laval nozzle) and |
| 34 | + dfHighSpeedFoam (density-based central-upwind) for high-speed regions |
| 35 | + (e.g. Laval nozzle, plume flow region). |
| 36 | +
|
| 37 | + Region coupling is handled via inter-region boundary conditions on the |
| 38 | + shared interface, transferring T, p, U, Yi between the two solver domains. |
| 39 | + See dfHybridBoundaryConditions for details on the implemented BCs. |
| 40 | +
|
| 41 | + The multi-region architecture follows the chtMultiRegionFoam pattern from |
| 42 | + OpenFOAM-7: |
| 43 | + - regionProperties defines the region names and types |
| 44 | + - Separate meshes and fields are created for each region |
| 45 | + - A time loop iterates over all regions, solving each with its |
| 46 | + appropriate algorithm |
| 47 | +
|
| 48 | +\*---------------------------------------------------------------------------*/ |
| 49 | + |
| 50 | +#include "dfChemistryModel.H" |
| 51 | +#include "CanteraMixture.H" |
| 52 | +#include "heRhoThermo.H" |
| 53 | + |
| 54 | +#ifdef USE_PYTORCH |
| 55 | +#include <pybind11/embed.h> |
| 56 | +#include <pybind11/numpy.h> |
| 57 | +#include <pybind11/stl.h> |
| 58 | +#endif |
| 59 | + |
| 60 | +#ifdef USE_LIBTORCH |
| 61 | +#include <torch/script.h> |
| 62 | +#include "DNNInferencer.H" |
| 63 | +#endif |
| 64 | + |
| 65 | +#include "fvCFD.H" |
| 66 | +#include "dynamicFvMesh.H" |
| 67 | +#include "rhoThermo.H" |
| 68 | +#include "fluidThermo.H" |
| 69 | +#include "turbulentFluidThermoModel.H" |
| 70 | +#include "CombustionModel.H" |
| 71 | +#include "pimpleControl.H" |
| 72 | +#include "pressureControl.H" |
| 73 | +#include "localEulerDdtScheme.H" |
| 74 | +#include "fvcSmooth.H" |
| 75 | +#include "PstreamGlobals.H" |
| 76 | +#include "basicThermo.H" |
| 77 | + |
| 78 | +#include "basicSprayCloud.H" |
| 79 | +#include "SLGThermo.H" |
| 80 | + |
| 81 | +// For high-speed region (density-based) |
| 82 | +#include "fixedRhoFvPatchScalarField.H" |
| 83 | +#include "include/directionInterpolate.H" |
| 84 | +#include "fluxScheme.H" |
| 85 | + |
| 86 | +// For multi-region support |
| 87 | +#include "regionProperties.H" |
| 88 | +#include "fixedGradientFvPatchFields.H" |
| 89 | + |
| 90 | +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
| 91 | + |
| 92 | +int main(int argc, char *argv[]) |
| 93 | +{ |
| 94 | +#ifdef USE_PYTORCH |
| 95 | + pybind11::scoped_interpreter guard{}; |
| 96 | +#endif |
| 97 | + |
| 98 | + #define NO_CONTROL |
| 99 | + #define CREATE_MESH createMeshesPostProcess.H |
| 100 | + #include "postProcess.H" |
| 101 | + |
| 102 | + #include "listOptions.H" |
| 103 | + #include "setRootCase2.H" |
| 104 | + #include "listOutput.H" |
| 105 | + |
| 106 | + #include "createTime.H" |
| 107 | + |
| 108 | + // ---- Multi-region mesh creation ---- |
| 109 | + // Read regionProperties from constant/regionProperties |
| 110 | + // which defines "lowMach" and "highSpeed" region lists |
| 111 | + #include "createMeshes.H" |
| 112 | + |
| 113 | + // ---- Create fields for each region type ---- |
| 114 | + #include "createFields.H" |
| 115 | + |
| 116 | + #include "initContinuityErrs.H" |
| 117 | + |
| 118 | + // ---- Read time controls ---- |
| 119 | + #include "include/readMultiRegionTimeControls.H" |
| 120 | + |
| 121 | + // ---- Compute initial Courant numbers ---- |
| 122 | + #include "include/computeMultiRegionCourantNo.H" |
| 123 | + |
| 124 | + // ---- Set initial deltaT ---- |
| 125 | + #include "include/setInitialMultiRegionDeltaT.H" |
| 126 | + |
| 127 | + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // |
| 128 | + |
| 129 | + Info<< "\nStarting time loop\n" << endl; |
| 130 | + |
| 131 | + label timeIndex = 0; |
| 132 | + |
| 133 | + while (runTime.run()) |
| 134 | + { |
| 135 | + timeIndex++; |
| 136 | + |
| 137 | + // ---- Read time controls ---- |
| 138 | + #include "include/readMultiRegionTimeControls.H" |
| 139 | + |
| 140 | + // ---- Compute Courant numbers from all regions ---- |
| 141 | + #include "include/computeMultiRegionCourantNo.H" |
| 142 | + |
| 143 | + // ---- Adjust deltaT based on both regions ---- |
| 144 | + #include "include/setMultiRegionDeltaT.H" |
| 145 | + |
| 146 | + runTime++; |
| 147 | + |
| 148 | + Info<< "Time = " << runTime.timeName() << nl << endl; |
| 149 | + |
| 150 | + // ===================================================================== |
| 151 | + // Solve low-Mach regions (pressure-based PIMPLE) |
| 152 | + // ===================================================================== |
| 153 | + forAll(lowMachRegions, i) |
| 154 | + { |
| 155 | + Info<< "\nSolving for lowMach region " |
| 156 | + << lowMachRegions[i].name() << endl; |
| 157 | + |
| 158 | + #include "lowMach/setRegionLowMachFields.H" |
| 159 | + #include "lowMach/solveLowMach.H" |
| 160 | + } |
| 161 | + |
| 162 | + // ===================================================================== |
| 163 | + // Solve high-speed regions (density-based central-upwind) |
| 164 | + // ===================================================================== |
| 165 | + forAll(highSpeedRegions, i) |
| 166 | + { |
| 167 | + Info<< "\nSolving for highSpeed region " |
| 168 | + << highSpeedRegions[i].name() << endl; |
| 169 | + |
| 170 | + #include "highSpeed/setRegionHighSpeedFields.H" |
| 171 | + #include "highSpeed/solveHighSpeed.H" |
| 172 | + } |
| 173 | + |
| 174 | + runTime.write(); |
| 175 | + |
| 176 | + Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" |
| 177 | + << " ClockTime = " << runTime.elapsedClockTime() << " s" |
| 178 | + << nl << endl; |
| 179 | + } |
| 180 | + |
| 181 | + Info<< "End\n" << endl; |
| 182 | + |
| 183 | + return 0; |
| 184 | +} |
| 185 | + |
| 186 | +// ************************************************************************* // |
0 commit comments