diff --git a/Allwmake b/Allwmake index 68accb90..687baad6 100755 --- a/Allwmake +++ b/Allwmake @@ -25,3 +25,4 @@ wmake applications/solvers/dfHighSpeedFoam wmake applications/solvers/dfSprayFoam wmake applications/utilities/flameSpeed +wmake applications/utilities/flameSpeed1 diff --git a/applications/utilities/flameSpeed/Make/files b/applications/utilities/flameSpeed/Make/files index 33ff698a..f08bcaf0 100644 --- a/applications/utilities/flameSpeed/Make/files +++ b/applications/utilities/flameSpeed/Make/files @@ -1,3 +1,3 @@ flameSpeed.C -EXE = $(DF_APPBIN)/flameSpeed +EXE = $(DF_APPBIN)/flameSpeed \ No newline at end of file diff --git a/applications/utilities/flameSpeed/Make/options b/applications/utilities/flameSpeed/Make/options index f9fc54cc..75680ff8 100644 --- a/applications/utilities/flameSpeed/Make/options +++ b/applications/utilities/flameSpeed/Make/options @@ -1,4 +1,4 @@ -EXE_INC = -std=c++14\ +EXE_INC = -std=c++17\ -Wno-unused-variable \ -Wno-unused-but-set-variable \ -Wno-old-style-cast \ @@ -8,4 +8,4 @@ EXE_INC = -std=c++14\ EXE_LIBS = \ -lfiniteVolume \ - -lmeshTools + -lmeshTools \ No newline at end of file diff --git a/applications/utilities/flameSpeed/flameSpeed.C b/applications/utilities/flameSpeed/flameSpeed.C index a8b69058..b2709f80 100644 --- a/applications/utilities/flameSpeed/flameSpeed.C +++ b/applications/utilities/flameSpeed/flameSpeed.C @@ -22,11 +22,35 @@ Application Description \*---------------------------------------------------------------------------*/ #include "fvCFD.H" +#include // 添加这个头文件以便进行文件操作 +#include // 添加这个头文件以便进行字符串流操作 + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // int main(int argc, char *argv[]) { #include "setRootCase.H" #include "createTime.H" + + // 读取 control 文件中的 wr 行 + std::ifstream controlFile("./system/controlDict"); // 打开 control 文件 + std::string line; + scalar a = 0.0; // 初始化 a + while (std::getline(controlFile, line)) // 逐行读取文件 + { + if (line.find("writeInterval") != std::string::npos) // 查找包含 "wr" 的行 + { + std::istringstream iss(line); + std::string key; + iss >> key; // 读取行的第一个单词(即 "wr") + iss >> a; // 读取下一个数字到 a + break; // 找到后退出循环 + } + } + controlFile.close(); // 关闭文件 + + // 输出读取的值 + // Info << "Value of writeInterval (from controlDict file) = " << a << endl; + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // instantList timeDirs = timeSelector::select0(runTime, args); #include "createMesh.H" @@ -34,7 +58,7 @@ int main(int argc, char *argv[]) forAll(timeDirs, timeI) { runTime.setTime(timeDirs[timeI], timeI); - Info<< "Time = " << runTime.timeName() << endl; + Info << "Time = " << runTime.timeName() << endl; volScalarField T ( IOobject @@ -65,17 +89,17 @@ int main(int argc, char *argv[]) { gradT[cellI] = gradT_[cellI].x(); } - const scalar flameThickness= (max(T).value() - min(T).value())/max(gradT); - Info<< "flameThickness = " << flameThickness << " m" << endl; - Info<< "flamePoint.x (max T gradient) = " << mesh.C()[findMax(gradT)].x() << endl; - Info<< "flamePropagationSpeed = " << (mesh.C()[findMax(gradT)].x() - flamePosition)/0.001 << " m/s" << endl; - Info<< "flameSpeed = " << U[0][0] - (mesh.C()[findMax(gradT)].x() - flamePosition)/0.001 << " m/s" << endl; + const scalar flameThickness = (max(T).value() - min(T).value()) / max(gradT); + Info << "Value of writeInterval (from controlDict file) = " << a << endl; + Info << "flameThickness = " << flameThickness << " m" << endl; + Info << "flamePoint.x (max T gradient) = " << mesh.C()[findMax(gradT)].x() << endl; + Info << "flamePropagationSpeed = " << (mesh.C()[findMax(gradT)].x() - flamePosition) / a << " m/s" << endl; + Info << "flameSpeed = " << U[0][0] - (mesh.C()[findMax(gradT)].x() - flamePosition) / a << " m/s" << endl; flamePosition = mesh.C()[findMax(gradT)].x(); } - Info<< nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" - << " ClockTime = " << runTime.elapsedClockTime() << " s" - << nl << endl; - Info<< "End\n" << endl; + Info << nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" + << " ClockTime = " << runTime.elapsedClockTime() << " s" + << nl << endl; + Info << "End\n" << endl; return 0; -} -// ************************************************************************* // \ No newline at end of file +} \ No newline at end of file diff --git a/applications/utilities/flameSpeed1/Make/files b/applications/utilities/flameSpeed1/Make/files new file mode 100644 index 00000000..084d42f5 --- /dev/null +++ b/applications/utilities/flameSpeed1/Make/files @@ -0,0 +1,3 @@ +flameSpeed1.C + +EXE = $(DF_APPBIN)/flameSpeed1 \ No newline at end of file diff --git a/applications/utilities/flameSpeed1/Make/options b/applications/utilities/flameSpeed1/Make/options new file mode 100644 index 00000000..75680ff8 --- /dev/null +++ b/applications/utilities/flameSpeed1/Make/options @@ -0,0 +1,11 @@ +EXE_INC = -std=c++17\ + -Wno-unused-variable \ + -Wno-unused-but-set-variable \ + -Wno-old-style-cast \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude + +EXE_LIBS = \ + -lfiniteVolume \ + -lmeshTools \ No newline at end of file diff --git a/applications/utilities/flameSpeed1/flameSpeed1.C b/applications/utilities/flameSpeed1/flameSpeed1.C new file mode 100644 index 00000000..18080c3b --- /dev/null +++ b/applications/utilities/flameSpeed1/flameSpeed1.C @@ -0,0 +1,89 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Copyright (C) 2021 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see . +Application + flameThickness +Description +\*---------------------------------------------------------------------------*/ +#include "fvCFD.H" +#include // 添加头文件以便进行输入输出 + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +int main(int argc, char *argv[]) +{ + #include "setRootCase.H" + #include "createTime.H" + + // 手动输入 time_step + scalar time_step; + std::cout << "请输入时间步长 (time_step): "; + std::cin >> time_step; // 从标准输入读取时间步长 + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + instantList timeDirs = timeSelector::select0(runTime, args); + #include "createMesh.H" + scalar flamePosition = 0.0211; + + forAll(timeDirs, timeI) + { + runTime.setTime(timeDirs[timeI], timeI); + Info << "Time = " << runTime.timeName() << endl; + volScalarField T + ( + IOobject + ( + "T", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + mesh + ); + volVectorField U + ( + IOobject + ( + "U", + "0", + mesh, + IOobject::MUST_READ, + IOobject::NO_WRITE + ), + mesh + ); + const auto gradT_ = fvc::grad(T)(); + scalarList gradT(mesh.nCells()); + forAll(gradT, cellI) + { + gradT[cellI] = gradT_[cellI].x(); + } + const scalar flameThickness = (max(T).value() - min(T).value()) / max(gradT); + Info << "flameThickness = " << flameThickness << " m" << endl; + Info << "flamePoint.x (max T gradient) = " << mesh.C()[findMax(gradT)].x() << endl; + Info << "flamePropagationSpeed = " << (mesh.C()[findMax(gradT)].x() - flamePosition) / time_step << " m/s" << endl; + Info << "flameSpeed = " << U[0][0] - (mesh.C()[findMax(gradT)].x() - flamePosition) / time_step << " m/s" << endl; + flamePosition = mesh.C()[findMax(gradT)].x(); + } + Info << nl << "ExecutionTime = " << runTime.elapsedCpuTime() << " s" + << " ClockTime = " << runTime.elapsedClockTime() << " s" + << nl << endl; + Info << "End\n" << endl; + return 0; +} \ No newline at end of file diff --git a/src/dfChemistryModel/dfChemistryModel.C b/src/dfChemistryModel/dfChemistryModel.C index 1cf15006..64fd5c2c 100644 --- a/src/dfChemistryModel/dfChemistryModel.C +++ b/src/dfChemistryModel/dfChemistryModel.C @@ -142,6 +142,8 @@ Foam::dfChemistryModel::dfChemistryModel gpu_ = this->subDict("TorchSettings").lookupOrDefault("GPU", false), gpulog_ = this->subDict("TorchSettings").lookupOrDefault("log", false), + Tem = this->subDict("TorchSettings").lookupOrDefault("frozenTemperature", 310); + time_allsolve_ = 0; time_submaster_ = 0; time_sendProblem_ = 0; diff --git a/src/dfChemistryModel/dfChemistryModel.H b/src/dfChemistryModel/dfChemistryModel.H index 4e8850e5..5c652ffe 100644 --- a/src/dfChemistryModel/dfChemistryModel.H +++ b/src/dfChemistryModel/dfChemistryModel.H @@ -142,7 +142,7 @@ public IOdictionary Switch gpulog_; label cvodeComm; - + double Tem; // profiling double time_allsolve_; double time_submaster_; diff --git a/src/dfChemistryModel/torchFunctions.H b/src/dfChemistryModel/torchFunctions.H index 8b525254..10164b20 100644 --- a/src/dfChemistryModel/torchFunctions.H +++ b/src/dfChemistryModel/torchFunctions.H @@ -12,11 +12,38 @@ void Foam::dfChemistryModel::getGPUProblems // get cuda problemList, for all cell // each get problem + // std::ifstream controlFile("./constant/CanteraTorchProperties"); // 打开 control 文件 + // std::string line; + // scalar Tem = 0.0; // 初始化 Tem + // while (std::getline(controlFile, line)) // 逐行读取文件 + // { + // if (line.find("frozenTemperature") != std::string::npos) // 查找包含 "wr" 的行 + // { + // std::istringstream iss(line); + // std::string key; + // iss >> key; // 读取行的第一个单词(即 "wr") + // iss >> Tem; // 读取下一个数字到 a + // break; // 找到后退出循环 + // } + // } + + forAll(T_, cellI) { scalar Ti = T_[cellI]; scalar pi = p_[cellI]; scalar rhoi = rho_[cellI]; + + if (T_[cellI] < Tem) + { + Qdot_[cellI] = 0; + for (int i = 0; i < mixture_.nSpecies(); i++) + { + RR_[i][cellI] = 0.0; + } + continue; + } + // set problems GpuProblem problem(mixture_.nSpecies());