Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes related to "flameSpeed" and "dfChemistryModel" #529

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Allwmake
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ wmake applications/solvers/dfHighSpeedFoam
wmake applications/solvers/dfSprayFoam

wmake applications/utilities/flameSpeed
wmake applications/utilities/flameSpeed1
2 changes: 1 addition & 1 deletion applications/utilities/flameSpeed/Make/files
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flameSpeed.C

EXE = $(DF_APPBIN)/flameSpeed
EXE = $(DF_APPBIN)/flameSpeed
4 changes: 2 additions & 2 deletions applications/utilities/flameSpeed/Make/options
Original file line number Diff line number Diff line change
@@ -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 \
Expand All @@ -8,4 +8,4 @@ EXE_INC = -std=c++14\

EXE_LIBS = \
-lfiniteVolume \
-lmeshTools
-lmeshTools
48 changes: 36 additions & 12 deletions applications/utilities/flameSpeed/flameSpeed.C
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,43 @@ Application
Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include <fstream> // 添加这个头文件以便进行文件操作
#include <sstream> // 添加这个头文件以便进行字符串流操作

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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"
scalar flamePosition = 0.0211;
forAll(timeDirs, timeI)
{
runTime.setTime(timeDirs[timeI], timeI);
Info<< "Time = " << runTime.timeName() << endl;
Info << "Time = " << runTime.timeName() << endl;
volScalarField T
(
IOobject
Expand Down Expand Up @@ -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;
}
// ************************************************************************* //
}
3 changes: 3 additions & 0 deletions applications/utilities/flameSpeed1/Make/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flameSpeed1.C

EXE = $(DF_APPBIN)/flameSpeed1
11 changes: 11 additions & 0 deletions applications/utilities/flameSpeed1/Make/options
Original file line number Diff line number Diff line change
@@ -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
89 changes: 89 additions & 0 deletions applications/utilities/flameSpeed1/flameSpeed1.C
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
Application
flameThickness
Description
\*---------------------------------------------------------------------------*/
#include "fvCFD.H"
#include <iostream> // 添加头文件以便进行输入输出

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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;
}
2 changes: 2 additions & 0 deletions src/dfChemistryModel/dfChemistryModel.C
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ Foam::dfChemistryModel<ThermoType>::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;
Expand Down
2 changes: 1 addition & 1 deletion src/dfChemistryModel/dfChemistryModel.H
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public IOdictionary
Switch gpulog_;

label cvodeComm;

double Tem;
// profiling
double time_allsolve_;
double time_submaster_;
Expand Down
27 changes: 27 additions & 0 deletions src/dfChemistryModel/torchFunctions.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,38 @@ void Foam::dfChemistryModel<ThermoType>::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());
Expand Down