diff --git a/.github/workflows/CPU_inferencce_validation.yml b/.github/workflows/CPU_inferencce_validation.yml index 22ed1873e..d3efd2a4b 100644 --- a/.github/workflows/CPU_inferencce_validation.yml +++ b/.github/workflows/CPU_inferencce_validation.yml @@ -33,6 +33,7 @@ jobs: conda create -n libcantera python=3.8 conda activate libcantera conda install -c cantera libcantera-devel=2.6 + conda install -c cantera cantera conda install pytorch pybind11 conda install pkg-config conda install --channel https://conda.anaconda.org/zhaofeng-shu33 easydict @@ -51,8 +52,7 @@ jobs: && unzip flare_CH4_SandiaD_4D.zip && ls $PWD && cp -r flare_CH4_SandiaD_4D.tbl examples/dfLowMachFoam/2DSandiaD_flareFGM/ - && git clone https://github.com/intelligent-algorithm-team/intelligent-combustion.git - && cp -r intelligent-combustion/DeePCK/Model/HE04_Hydrogen_ESH2_GMS_sub_20221101/ mechanisms/ && source ~/miniconda3/etc/profile.d/conda.sh && conda activate libcantera && source /opt/openfoam7/etc/bashrc + && source ~/miniconda3/etc/profile.d/conda.sh && conda activate libcantera && source /opt/openfoam7/etc/bashrc && . configure.sh --use_pytorch&& source ./bashrc && . install.sh && cd test && ./Allrun && conda deactivate " diff --git a/README.md b/README.md index 2e03ad1a9..d7764af39 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ DeepFlame is a deep learning empowered computational fluid dynamics package for single or multiphase, laminar or turbulent, reacting flows at all speeds. It aims to provide an open-source platform to combine the individual strengths of [OpenFOAM](https://openfoam.org), [Cantera](https://cantera.org), and [PyTorch](https://pytorch.org/) libraries for deep learning assisted reacting flow simulations. It also has the scope to leverage the next-generation heterogenous supercomputing and AI acceleration infrastructures such as GPU and FPGA. -The deep learning algorithms and models used in the DeepFlame tutorial examples are developed and trained independently by our collaborators team – [Intelligent Combustion](https://github.com/intelligent-algorithm-team/intelligent-combustion.git). Please refer to their website for detailed information. +The neural network models used in the tutorial examples can be found at– [AIS Square](https://www.aissquare.com/). To run DeepFlame with DNN, download the DNN model [dfODENet](https://www.aissquare.com/models/detail?pageType=models&name=dfODENet_DNNmodel_V0.1&id=181) into the case folder you would like to run. ## Documentation Detailed guide for installation and tutorials is available on [our documentation website](https://deepflame.deepmodeling.com). diff --git a/docs/source/qs/download_dnn_models.rst b/docs/source/qs/download_dnn_models.rst index 854b99801..b843e8744 100644 --- a/docs/source/qs/download_dnn_models.rst +++ b/docs/source/qs/download_dnn_models.rst @@ -1,18 +1,6 @@ Download DNN Models ====================================== -The neural network models used in the tutorial examples are indepentently trained -by our collaborators team – `Intelligent Combustion `_. -To run DeepFlame with DNN, first download the DeepCombustion repository into ``deepflame-dev/``: - -.. code-block:: bash - - cd $DF_ROOT - git clone https://github.com/intelligent-algorithm-team/intelligent-combustion.git.git +The neural network models used in the tutorial examples can be found at– `AIS Square `_. +To run DeepFlame with DNN, download the DNN model `dfODENet `_ into the case folder you would like to run. -Then copy the required DNN model into ``mechanisms/``, for example: -.. code-block:: bash - - cp -r intelligent-combustion/DeePCK/Model/HE04_Hydrogen_ESH2_GMS_sub_20221101/ mechanisms/ - -.. Note:: Here ``HE04_Hydrogen_ESH2_GMS_sub_20221101`` is the default DNN model for all the tutorial cases in ``$DF_ROOT/examples/``. diff --git a/docs/source/qs/install.rst b/docs/source/qs/install.rst index eac531ed1..5ea4a9087 100644 --- a/docs/source/qs/install.rst +++ b/docs/source/qs/install.rst @@ -43,10 +43,9 @@ Alternatively, one can `compile OpenFOAM-7 from source code log.fs +sed -n 's/.*flameSpeed = \([0-9]*\(\.[0-9]*\)\?\).*/\1/p' log.fs > fs + + diff --git a/test/Tu500K-Phi1/Burke2012_s9r23.yaml b/test/Tu500K-Phi1/Burke2012_s9r23.yaml new file mode 100755 index 000000000..d77a77bbf --- /dev/null +++ b/test/Tu500K-Phi1/Burke2012_s9r23.yaml @@ -0,0 +1,242 @@ +generator: cti2yaml +cantera-version: 2.5.1 +date: Tue, 24 Oct 2023 17:09:01 +0800 +input-files: [Burke2012_s9s.cti] + +units: {length: cm, quantity: mol, activation-energy: cal/mol} + +phases: +- name: gas + thermo: ideal-gas + elements: [H, O, N] + species: [H, H2, O, OH, H2O, O2, HO2, H2O2, N2] + kinetics: gas + reactions: all + transport: mixture-averaged + state: + T: 300.0 + P: 1.01325e+05 + +species: +- name: H + composition: {H: 1} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [2.5, 0.0, 0.0, 0.0, 0.0, 2.547163e+04, -0.4601176] + - [2.5, 0.0, 0.0, 0.0, 0.0, 2.547163e+04, -0.4601176] + transport: + model: gas + geometry: atom + diameter: 2.05 + well-depth: 145.0 + note: '120186' +- name: H2 + composition: {H: 2} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [3.298124, 8.249442e-04, -8.143015e-07, -9.475434e-11, 4.134872e-13, + -1012.521, -3.294094] + - [2.991423, 7.000644e-04, -5.633829e-08, -9.231578e-12, 1.582752e-15, + -835.034, -1.35511] + transport: + model: gas + geometry: linear + diameter: 2.92 + well-depth: 38.0 + polarizability: 0.79 + rotational-relaxation: 280.0 + note: '121286' +- name: O + composition: {O: 1} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [2.946429, -1.638166e-03, 2.421032e-06, -1.602843e-09, 3.890696e-13, + 2.914764e+04, 2.963995] + - [2.54206, -2.755062e-05, -3.102803e-09, 4.551067e-12, -4.368052e-16, + 2.92308e+04, 4.920308] + transport: + model: gas + geometry: atom + diameter: 2.75 + well-depth: 80.0 + note: '120186' +- name: OH + composition: {H: 1, O: 1} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0, 6000.0] + data: + - [4.12530561, -3.22544939e-03, 6.52764691e-06, -5.79853643e-09, 2.06237379e-12, + 3346.30913, -0.69043296] + - [2.86472886, 1.05650448e-03, -2.59082758e-07, 3.05218674e-11, -1.33195876e-15, + 3683.62875, 5.70164073] + transport: + model: gas + geometry: linear + diameter: 2.75 + well-depth: 80.0 + note: S9/01 +- name: H2O + composition: {H: 2, O: 1} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [3.386842, 3.474982e-03, -6.354696e-06, 6.968581e-09, -2.506588e-12, + -3.020811e+04, 2.590233] + - [2.672146, 3.056293e-03, -8.73026e-07, 1.200996e-10, -6.391618e-15, + -2.989921e+04, 6.862817] + transport: + model: gas + geometry: nonlinear + diameter: 2.605 + well-depth: 572.4 + dipole: 1.844 + rotational-relaxation: 4.0 + note: '20387' +- name: O2 + composition: {O: 2} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [3.212936, 1.127486e-03, -5.75615e-07, 1.313877e-09, -8.768554e-13, + -1005.249, 6.034738] + - [3.697578, 6.135197e-04, -1.258842e-07, 1.775281e-11, -1.136435e-15, + -1233.93, 3.189166] + transport: + model: gas + geometry: linear + diameter: 3.458 + well-depth: 107.4 + polarizability: 1.6 + rotational-relaxation: 3.8 + note: '121386' +- name: HO2 + composition: {H: 1, O: 2} + thermo: + model: NASA7 + temperature-ranges: [200.0, 1000.0, 3500.0] + data: + - [4.30179801, -4.74912051e-03, 2.11582891e-05, -2.42763894e-08, 9.29225124e-12, + 294.80804, 3.71666245] + - [4.0172109, 2.23982013e-03, -6.3365815e-07, 1.1424637e-10, -1.07908535e-14, + 111.856713, 3.78510215] + transport: + model: gas + geometry: nonlinear + diameter: 3.458 + well-depth: 107.4 + rotational-relaxation: 1.0 + note: L5/89 +- name: H2O2 + composition: {H: 2, O: 2} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [3.388754, 6.569226e-03, -1.485013e-07, -4.625806e-09, 2.471515e-12, + -1.766315e+04, 6.785363] + - [4.573167, 4.336136e-03, -1.474689e-06, 2.348904e-10, -1.431654e-14, + -1.800696e+04, 0.501137] + transport: + model: gas + geometry: nonlinear + diameter: 3.458 + well-depth: 107.4 + rotational-relaxation: 3.8 + note: '120186' +- name: N2 + composition: {N: 2} + thermo: + model: NASA7 + temperature-ranges: [300.0, 1000.0, 5000.0] + data: + - [3.298677, 1.40824e-03, -3.963222e-06, 5.641515e-09, -2.444855e-12, + -1020.9, 3.950372] + - [2.92664, 1.487977e-03, -5.684761e-07, 1.009704e-10, -6.753351e-15, + -922.7977, 5.980528] + transport: + model: gas + geometry: linear + diameter: 3.621 + well-depth: 97.53 + polarizability: 1.76 + rotational-relaxation: 4.0 + note: '121286' + +reactions: +- equation: H + O2 <=> O + OH # Reaction 1 + rate-constant: {A: 1.04e+14, b: 0.0, Ea: 1.5286e+04} +- equation: O + H2 <=> H + OH # Reaction 2 + rate-constant: {A: 3.818e+12, b: 0.0, Ea: 7948.0} + duplicate: true +- equation: O + H2 <=> H + OH # Reaction 3 + rate-constant: {A: 8.792e+14, b: 0.0, Ea: 1.917e+04} + duplicate: true +- equation: H2 + OH <=> H2O + H # Reaction 4 + rate-constant: {A: 2.16e+08, b: 1.51, Ea: 3430.0} +- equation: OH + OH <=> O + H2O # Reaction 5 + rate-constant: {A: 3.34e+04, b: 2.42, Ea: -1930.0} +- equation: H2 + M <=> H + H + M # Reaction 6 + type: three-body + rate-constant: {A: 4.577e+19, b: -1.4, Ea: 1.0438e+05} + efficiencies: {H2: 2.5, H2O: 12.0} +- equation: O + O + M <=> O2 + M # Reaction 7 + type: three-body + rate-constant: {A: 6.165e+15, b: -0.5, Ea: 0.0} + efficiencies: {H2: 2.5, H2O: 12.0} +- equation: O + H + M <=> OH + M # Reaction 8 + type: three-body + rate-constant: {A: 4.714e+18, b: -1.0, Ea: 0.0} + efficiencies: {H2: 2.5, H2O: 12.0} +- equation: H2O + M <=> H + OH + M # Reaction 9 + type: three-body + rate-constant: {A: 6.064e+27, b: -3.322, Ea: 1.2079e+05} + efficiencies: {H2: 3.0, H2O: 0.0, N2: 2.0, O2: 1.5} +- equation: H2O + H2O <=> H + OH + H2O # Reaction 10 + rate-constant: {A: 1.006e+26, b: -2.44, Ea: 1.2018e+05} +- equation: H + O2 (+ M) <=> HO2 (+ M) # Reaction 11 + type: falloff + low-P-rate-constant: {A: 6.366e+20, b: -1.72, Ea: 524.8} + high-P-rate-constant: {A: 4.65084e+12, b: 0.44, Ea: 0.0} + Troe: {A: 0.5, T3: 1.0e-30, T1: 1.0e+30} + efficiencies: {H2: 2.0, H2O: 14.0, O2: 0.78} +- equation: HO2 + H <=> H2 + O2 # Reaction 12 + rate-constant: {A: 2.75e+06, b: 2.09, Ea: -1451.0} +- equation: HO2 + H <=> OH + OH # Reaction 13 + rate-constant: {A: 7.079e+13, b: 0.0, Ea: 295.0} +- equation: HO2 + O <=> O2 + OH # Reaction 14 + rate-constant: {A: 2.85e+10, b: 1.0, Ea: -723.93} +- equation: HO2 + OH <=> H2O + O2 # Reaction 15 + rate-constant: {A: 2.89e+13, b: 0.0, Ea: -497.0} +- equation: HO2 + HO2 <=> H2O2 + O2 # Reaction 16 + rate-constant: {A: 4.2e+14, b: 0.0, Ea: 1.1982e+04} + duplicate: true +- equation: HO2 + HO2 <=> H2O2 + O2 # Reaction 17 + rate-constant: {A: 1.3e+11, b: 0.0, Ea: -1629.3} + duplicate: true +- equation: H2O2 (+ M) <=> OH + OH (+ M) # Reaction 18 + type: falloff + low-P-rate-constant: {A: 2.49e+24, b: -2.3, Ea: 4.8749e+04} + high-P-rate-constant: {A: 2.0e+12, b: 0.9, Ea: 4.8749e+04} + Troe: {A: 0.43, T3: 1.0e-30, T1: 1.0e+30} + efficiencies: {H2: 3.7, H2O: 7.5, H2O2: 7.7, N2: 1.5, O2: 1.2} +- equation: H2O2 + H <=> H2O + OH # Reaction 19 + rate-constant: {A: 2.41e+13, b: 0.0, Ea: 3970.0} +- equation: H2O2 + H <=> HO2 + H2 # Reaction 20 + rate-constant: {A: 4.82e+13, b: 0.0, Ea: 7950.0} +- equation: H2O2 + O <=> OH + HO2 # Reaction 21 + rate-constant: {A: 9.55e+06, b: 2.0, Ea: 3970.0} +- equation: H2O2 + OH <=> HO2 + H2O # Reaction 22 + rate-constant: {A: 1.74e+12, b: 0.0, Ea: 318.0} + duplicate: true +- equation: H2O2 + OH <=> HO2 + H2O # Reaction 23 + rate-constant: {A: 7.59e+13, b: 0.0, Ea: 7270.0} + duplicate: true diff --git a/test/Tu500K-Phi1/DNN_model.pt b/test/Tu500K-Phi1/DNN_model.pt new file mode 100755 index 000000000..010992009 Binary files /dev/null and b/test/Tu500K-Phi1/DNN_model.pt differ diff --git a/test/Tu500K-Phi1/constant/CanteraTorchProperties b/test/Tu500K-Phi1/constant/CanteraTorchProperties new file mode 100755 index 000000000..52babe801 --- /dev/null +++ b/test/Tu500K-Phi1/constant/CanteraTorchProperties @@ -0,0 +1,53 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object CanteraTorchProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +chemistry on; + +CanteraMechanismFile "Burke2012_s9r23.yaml"; + +transportModel "Mix"; + +odeCoeffs +{ + "relTol" 1e-6; + "absTol" 1e-10; +} + +inertSpecie "N2"; + +splittingStrategy off; + +TorchSettings +{ + torch on; + GPU off; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-6; + coresPerNode 4; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/constant/combustionProperties b/test/Tu500K-Phi1/constant/combustionProperties new file mode 100755 index 000000000..7418500d0 --- /dev/null +++ b/test/Tu500K-Phi1/constant/combustionProperties @@ -0,0 +1,20 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object combustionProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +combustionModel laminar; + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/constant/thermophysicalProperties b/test/Tu500K-Phi1/constant/thermophysicalProperties new file mode 100755 index 000000000..7f207bb77 --- /dev/null +++ b/test/Tu500K-Phi1/constant/thermophysicalProperties @@ -0,0 +1,18 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object thermophysicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/constant/turbulenceProperties b/test/Tu500K-Phi1/constant/turbulenceProperties new file mode 100755 index 000000000..ab70e94d3 --- /dev/null +++ b/test/Tu500K-Phi1/constant/turbulenceProperties @@ -0,0 +1,21 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object turbulenceProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +simulationType laminar; + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/inference.py b/test/Tu500K-Phi1/inference.py new file mode 100755 index 000000000..5034809cd --- /dev/null +++ b/test/Tu500K-Phi1/inference.py @@ -0,0 +1,169 @@ +import torch +import numpy as np +import time +import os +import cantera as ct + +device_main = "cuda:0" +device_list = range(torch.cuda.device_count()) + +torch.set_printoptions(precision=10) + +class NN_MLP(torch.nn.Module): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = torch.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_module('linear_layer_%d' %(i), torch.nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_module('gelu_layer_%d' %(i), torch.nn.GELU()) + #if i <= 2: + # self.net.add_module('batch_norm_%d' %(i), torch.nn.BatchNorm1d(layer_info[i + 1])) + self.net.add_module('linear_layer_%d' %(n - 1), torch.nn.Linear(layer_info[n - 1], layer_info[n])) + + def forward(self, x): + return self.net(x) + +try: + #load variables from constant/CanteraTorchProperties + path_r = r"./constant/CanteraTorchProperties" + with open(path_r, "r") as f: + data = f.read() + i = data.index('torchModel') + a = data.index('"',i) + b = data.index('"',a+1) + modelName = data[a+1:b] + + i = data.index('frozenTemperature') + a = data.index(';', i) + b = data.rfind(' ',i+1,a) + frozenTemperature = float(data[b+1:a]) + + i = data.index('inferenceDeltaTime') + a = data.index(';', i) + b = data.rfind(' ',i+1,a) + delta_t = float(data[b+1:a]) + + i = data.index('CanteraMechanismFile') + a = data.index('"',i) + b = data.index('"',a+1) + mechanismName = data[a+1:b] + + i = data.index('GPU') + a = data.index(';', i) + b = data.rfind(' ',i+1,a) + switch_GPU = data[b+1:a] + + #read mechanism species number + gas = ct.Solution(mechanismName) + n_species = gas.n_species + #load OpenFOAM switch + switch_on = ["true", "True", "on", "yes", "y", "t", "any"] + switch_off = ["false", "False", "off", "no", "n", "f", "none"] + if switch_GPU in switch_on: + device = torch.device(device_main) + device_ids = device_list + elif switch_GPU in switch_off: + device = torch.device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = torch.load(modelName,map_location='cpu') + Xmu0 = state_dict['data_in_mean'] + Xstd0 = state_dict['data_in_std'] + Ymu0 = state_dict['data_target_mean'] + Ystd0 = state_dict['data_target_std'] + + + Xmu0 = torch.tensor(Xmu0).unsqueeze(0).to(device=device) + Xstd0 = torch.tensor(Xstd0).unsqueeze(0).to(device=device) + Ymu0 = torch.tensor(Ymu0).unsqueeze(0).to(device=device) + Ystd0 = torch.tensor(Ystd0).unsqueeze(0).to(device=device) + + Xmu1 = Xmu0 + Xstd1 = Xstd0 + Ymu1 = Ymu0 + Ystd1 = Ystd0 + + Xmu2 = Xmu0 + Xstd2 = Xstd0 + Ymu2 = Ymu0 + Ystd2 = Ystd0 + + #load model + layers = [n_species +2, 1600, 800, 400, 1] + + model0list = [] + for i in range(n_species-1): + model0list.append(NN_MLP(layers)) + + for i in range(n_species-1): + model0list[i].load_state_dict(state_dict[f'net{i}']) + + + for i in range(n_species-1): + model0list[i].eval() + model0list[i].to(device=device) + + if len(device_ids) > 1: + for i in range(n_species-1): + model0list[i] = torch.nn.DataParallel(model0list[i], device_ids=device_ids) + +except Exception as e: + print(e.args) + + + + +def inference(vec0): + ''' + use model to inference + ''' + vec0 = np.abs(np.reshape(vec0, (-1, 3+n_species))) # T, P, Yi(7), Rho + vec0[:,1] *= 101325 + mask = vec0[:,0] > frozenTemperature + vec0_input = vec0[mask, :] + print(f'real inference points number: {vec0_input.shape[0]}') + + try: + with torch.no_grad(): + input0_ = torch.from_numpy(vec0_input).double().to(device=device) #cast ndarray to torch tensor + + + # pre_processing + rho0 = input0_[:, -1].unsqueeze(1) + input0_Y = input0_[:, 2:-1].clone() + input0_bct = input0_[:, 0:-1] + input0_bct[:, 2:] = (input0_bct[:, 2:]**(lamda) - 1) / lamda #BCT + input0_normalized = (input0_bct - Xmu0) / Xstd0 #DimXmu0 = 9, DimXstd0 = 9, input0_bct = + # input0_normalized[:, -1] = 0 #set Y_AR to 0 + input0_normalized = input0_normalized.float() + input0_normalized = input0_normalized.to(device=device) + + #inference + + output0_normalized = [] + for i in range(n_species-1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = torch.cat(output0_normalized, dim=1) + + # post_processing + output0_bct = output0_normalized * Ystd0 + Ymu0 + input0_bct[:, 2:-1] + output0_Y = input0_Y.clone() + output0_Y[:, :-1] = (lamda * output0_bct + 1)**(1 / lamda) + output0_Y[:, :-1] = output0_Y[:, :-1] / torch.sum(input=output0_Y[:, :-1], dim=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.cpu().numpy() + + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) + diff --git a/test/Tu500K-Phi1/system/blockMeshDict b/test/Tu500K-Phi1/system/blockMeshDict new file mode 100755 index 000000000..f6299b00b --- /dev/null +++ b/test/Tu500K-Phi1/system/blockMeshDict @@ -0,0 +1,84 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + object blockMeshDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +convertToMeters 0.001; + +vertices +( + (0 1 1) + (40 1 1) + (40 1 0) + (0 1 0) + (0 0 1) + (40 0 1) + (40 0 0) + (0 0 0) +); + +blocks +( + hex (4 5 6 7 0 1 2 3) (880 1 1) + simpleGrading + ( + ( + (0.55 0.625 1) + (0.45 0.375 2) + ) + 1 + 1 + ) +); + +edges +( +); + +boundary +( + boundary + { + type empty; + faces + ( + (0 3 2 1) + (4 5 6 7) + (0 1 5 4) + (3 2 6 7) + ); + } + inlet + { + type patch; + faces + ( + (0 4 7 3) + ); + } + outlet + { + type patch; + faces + ( + (1 2 6 5) + ); + } +); + +// mergePatchPairs +// ( +// ); + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/system/controlDict b/test/Tu500K-Phi1/system/controlDict new file mode 100755 index 000000000..596ff3307 --- /dev/null +++ b/test/Tu500K-Phi1/system/controlDict @@ -0,0 +1,59 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object controlDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +application dfLowMachFoam; + +startFrom startTime; + +startTime 0; + +stopAt endTime; + +endTime 0.002; + +deltaT 1e-6; + +maxDeltaT 1e-04; + +adjustTimeStep off; + +writeControl adjustableRunTime; + +writeInterval 0.001; + +purgeWrite 0; + +writeFormat ascii; + +// writePrecision 6; + +writeCompression on; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + +// adjustTimeStep yes; + +// maxCo 0.8; + +// maxDeltaT 1e-4; + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/system/decomposeParDict b/test/Tu500K-Phi1/system/decomposeParDict new file mode 100755 index 000000000..45c7f859f --- /dev/null +++ b/test/Tu500K-Phi1/system/decomposeParDict @@ -0,0 +1,45 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object decomposeParDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +numberOfSubdomains 4; + +method scotch; + +simpleCoeffs +{ + n (4 1 1); + delta 0.001; +} + +hierarchicalCoeffs +{ + n (1 1 1); + delta 0.001; + order xyz; +} + +manualCoeffs +{ + dataFile ""; +} + +distributed no; + +roots ( ); + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/system/fvSchemes b/test/Tu500K-Phi1/system/fvSchemes new file mode 100755 index 000000000..c841b36e1 --- /dev/null +++ b/test/Tu500K-Phi1/system/fvSchemes @@ -0,0 +1,61 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSchemes; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +ddtSchemes +{ + default Euler; +} + +gradSchemes +{ + default Gauss linear; +} + +divSchemes +{ + default none; + + div(phi,U) Gauss limitedLinearV 1; + div(phi,Yi) Gauss limitedLinear01 1; + div(phi,h) Gauss limitedLinear 1; + div(phi,ha) Gauss limitedLinear 1; + div(phi,K) Gauss limitedLinear 1; + div(phid,p) Gauss limitedLinear 1; + div(phi,epsilon) Gauss limitedLinear 1; + div(phi,Yi_h) Gauss limitedLinear01 1; + div(phi,k) Gauss limitedLinear 1; + div(hDiffCorrFlux) Gauss cubic; + div(((rho*nuEff)*dev2(T(grad(U))))) Gauss linear; +} + +laplacianSchemes +{ + default Gauss linear orthogonal; +} + +interpolationSchemes +{ + default linear; +} + +snGradSchemes +{ + default orthogonal; +} + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/system/fvSolution b/test/Tu500K-Phi1/system/fvSolution new file mode 100755 index 000000000..c13c246bb --- /dev/null +++ b/test/Tu500K-Phi1/system/fvSolution @@ -0,0 +1,78 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "system"; + object fvSolution; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +solvers +{ + "rho.*" + { + solver diagonal; + } + + p + { + solver PCG; + preconditioner DIC; + tolerance 1e-6; + relTol 0.01; + } + + pFinal + { + $p; + relTol 0; + } + + "(U|ha|k|epsilon)" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-6; + relTol 0.1; + } + + "(U|ha|k|epsilon)Final" + { + $U; + relTol 0; + } + + "Yi" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-6; + relTol 0.1; + } + "YiFinal" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0; + } +} + +PIMPLE +{ + momentumPredictor yes; + nOuterCorrectors 1; + nCorrectors 2; + nNonOrthogonalCorrectors 0; +} + + +// ************************************************************************* // diff --git a/test/Tu500K-Phi1/system/sample b/test/Tu500K-Phi1/system/sample new file mode 100755 index 000000000..747b58c43 --- /dev/null +++ b/test/Tu500K-Phi1/system/sample @@ -0,0 +1,38 @@ +/*--------------------------------*- C++ -*----------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | Website: https://openfoam.org + \\ / A nd | Version: 7 + \\/ M anipulation | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + format ascii; + class dictionary; + location "system"; + object sample; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +type sets; +libs ("libsampling.so"); + +interpolationScheme cellPoint; + +setFormat raw; + +sets +( + data + { + type lineUniform; + axis x; + start (0 0 0); + end (0.04 0 0); + nPoints 1000; + } +); + +fields ( T ); + +// ************************************************************************* // diff --git a/test/corrtest.cpp b/test/corrtest.cpp index 5ce84f6cc..bac1fc202 100644 --- a/test/corrtest.cpp +++ b/test/corrtest.cpp @@ -37,23 +37,6 @@ float T9 = readSandia(9,"2DSandia/data_T.xy"); float T10 = readSandia(10,"2DSandia/data_T.xy"); float T11 = readSandia(11,"2DSandia/data_T.xy"); -// TEST(corrtest,df0DFoam_H2){ -// EXPECT_FLOAT_EQ(H2maxT,2588.48); // compare the maximum temperature of H2 case -// EXPECT_FLOAT_EQ(H2midT,1021.41); // compare the temperature of H2 case at the maximum gradient when t = 0.000245s -// //EXPECT_FLOAT_EQ(H2maxT,2586.21); // compare the maximum temperature of H2 case -// //EXPECT_FLOAT_EQ(H2midT,1020.71); // compare the temperature of H2 case at the maximum gradient when t = 0.000245s -// } - - - -//TEST(corrtest,dfLowMachFoam_TGV){ -// EXPECT_FLOAT_EQ(TGV500,1533.48); // compare the maximum temperature along y direction in 2D TGV after 500 time steps -// EXPECT_FLOAT_EQ(TGV400,1296.99); // ..........400 time steps -// EXPECT_FLOAT_EQ(TGV300,878.07); -// EXPECT_FLOAT_EQ(TGV200,545.818); -// EXPECT_FLOAT_EQ(TGV100,364.018); -//} - TEST(corrtest,dfHighSpeedFoam){ @@ -237,3 +220,38 @@ float readSandia(int k, string file){ return b; } + +float readflameSpeed(int k, string file); +float fs = readflameSpeed(3,"flameSpeed/fs"); + + +TEST(corrtest,flameSpeed){ + EXPECT_FLOAT_EQ(fs,6); // compare the maximum temperature along y direction in 2D TGV after 500 time steps +} + +float readflameSpeed(int k, string file){ + + float fs; + float b; + int i = 0; + + string inFileName = file; + ifstream inFile; + inFile.open(inFileName.c_str()); + + if (inFile.is_open()) + { + while (inFile >> fs){ + i ++ ; + if (i == k){ + b = fs; + } + } + + } + else { //Error message + cerr << "Can't find input file " << inFileName << endl; + } + + return b; +}