diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H2.gz new file mode 100644 index 000000000..047158fa4 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H3.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H3.gz new file mode 100644 index 000000000..aba3aec19 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H3.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H4.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H4.gz new file mode 100644 index 000000000..5722c23f2 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H4.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H5.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H5.gz new file mode 100644 index 000000000..601cc8f08 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/C2H5.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CHO.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CHO.gz new file mode 100644 index 000000000..3d5d6fdff Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CHO.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CO.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CO.gz new file mode 100644 index 000000000..0aa1702ad Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2O.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2O.gz new file mode 100644 index 000000000..ed393d11d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2OH.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2OH.gz new file mode 100644 index 000000000..6f546f266 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH2OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH3.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH3.gz new file mode 100644 index 000000000..6a04b1062 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH3.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH4.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH4.gz new file mode 100644 index 000000000..ef98bec12 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CH4.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO.gz new file mode 100644 index 000000000..7bd0e75a4 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO2.gz new file mode 100644 index 000000000..d13b9cc62 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/CO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H.gz new file mode 100644 index 000000000..83bcd8d0c Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2.gz new file mode 100644 index 000000000..80f26527b Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2O.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2O.gz new file mode 100644 index 000000000..2e2cb0d91 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/H2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCCO.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCCO.gz new file mode 100644 index 000000000..96d375ef0 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCO.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCO.gz new file mode 100644 index 000000000..79fc4866c Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HO2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HO2.gz new file mode 100644 index 000000000..3a2d32e5b Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/HO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/N2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/N2.gz new file mode 100644 index 000000000..844c9c0ac Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/N2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O.gz new file mode 100644 index 000000000..fcdf12ab2 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O2.gz new file mode 100644 index 000000000..563bc5192 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/OH.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/OH.gz new file mode 100644 index 000000000..a88b84d2d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/S-CH2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/S-CH2.gz new file mode 100644 index 000000000..272b49fc1 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/S-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T-CH2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T-CH2.gz new file mode 100644 index 000000000..1971fe964 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T.gz new file mode 100644 index 000000000..1dc9948ed Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/T.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/U b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/U new file mode 100644 index 000000000..cc3898af6 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/U @@ -0,0 +1,40 @@ +/*--------------------------------*- 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 volVectorField; + location "0"; + object U; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 1 -1 0 0 0 0]; + +internalField uniform (1.62 0 0); + +boundaryField +{ + boundary + { + type empty; + } + inlet + { + type fixedValue; + value uniform (1.62 0 0); + } + outlet + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/Ydefault b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/Ydefault new file mode 100644 index 000000000..9920d1092 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/Ydefault @@ -0,0 +1,40 @@ +/*--------------------------------*- 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 volScalarField; + location "0"; + object Ydefault; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [0 0 0 0 0 0 0]; + +internalField uniform 0; + +boundaryField +{ + boundary + { + type empty; + } + inlet + { + type fixedValue; + value uniform 0; + } + outlet + { + type zeroGradient; + } +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/p b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/p new file mode 100644 index 000000000..06f5c5cac --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/0/p @@ -0,0 +1,41 @@ +/*--------------------------------*- 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 volScalarField; + location "0"; + object p; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +dimensions [1 -1 -2 0 0 0 0]; + +internalField uniform 101325; + +boundaryField +{ + boundary + { + type empty; + } + inlet + { + type zeroGradient; + } + outlet + { + type waveTransmissive; + gamma 1.4; + value uniform 101325; + } +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allclean b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allclean new file mode 100644 index 000000000..2cd9e2246 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning log.*" +rm log.* +echo "Cleaning processor*" +rm -r processor* +echo "Cleaning polyMesh/" +rm -r constant/polyMesh diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allrun b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allrun new file mode 100644 index 000000000..732e7a9ba --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +if [ -e DNN_model.pt ] +then + echo "DNN_model.pt exists. Make sure correct DNN model has been used!" +else + echo "DNN_model.pt not exist. Downloading ..." + wget https://store.aissquare.com/models/5e1232cd-c23f-489f-9db4-ee09592beeb1/DNN_model.zip + unzip DNN_model.zip + cp ./DNN_model/C2H4/DNN_model.pt . + cp ./DNN_model/C2H4/Wu24sp.yaml . +fi + +# Source tutorial run functions +. $WM_PROJECT_DIR/bin/tools/RunFunctions + +application=dfLowMachFoam + +runApplication blockMesh +runApplication decomposePar +runApplication mpirun -np 4 --allow-run-as-root $application -parallel diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/CanteraTorchProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/CanteraTorchProperties new file mode 100644 index 000000000..e869f12ec --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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 "Wu24sp.yaml"; + +transportModel "Mix"; + +odeCoeffs +{ + "relTol" 1e-6; + "absTol" 1e-10; +} + +inertSpecie "N2"; + +splittingStrategy off; + +TorchSettings +{ + torch on; + GPU on; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-7; + coresPerNode 4; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/combustionProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/combustionProperties new file mode 100644 index 000000000..7418500d0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/thermophysicalProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/thermophysicalProperties new file mode 100644 index 000000000..7f207bb77 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/turbulenceProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/constant/turbulenceProperties new file mode 100644 index 000000000..ab70e94d3 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/inference.py b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/inference.py new file mode 100644 index 000000000..6c3754da9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/inference.py @@ -0,0 +1,153 @@ +import paddle +import paddle.nn as nn +import numpy as np +import time +import os +import cantera as ct + +device_main = "gpu:0" +device_list = range(paddle.device.cuda.device_count()) +paddle.set_printoptions(precision=10) + +class NN_MLP(nn.Layer): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = paddle.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_sublayer('linear_layer_%d' % (i), nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_sublayer('gelu_layer_%d' % (i), nn.GELU()) + self.net.add_sublayer('linear_layer_%d' % (n - 1), 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: + paddle.device.set_device(device_main) + device_ids = device_list + # paddle.set_device(device_main) + elif switch_GPU in switch_off: + paddle.device.set_device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = paddle.load(modelName) + 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 = paddle.to_tensor(Xmu0).unsqueeze(0).astype('float32') + Xstd0 = paddle.to_tensor(Xstd0).unsqueeze(0).astype('float32') + Ymu0 = paddle.to_tensor(Ymu0).unsqueeze(0).astype('float32') + Ystd0 = paddle.to_tensor(Ystd0).unsqueeze(0).astype('float32') + + 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].set_state_dict(state_dict[f'net{i}']) + + for i in range(n_species - 1): + model0list[i].eval() + model0list[i] = paddle.DataParallel(model0list[i]) if len(device_list) > 1 else model0list[i] + +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 paddle.no_grad(): + input0_ = paddle.to_tensor(vec0_input).astype('float32') + + # 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 + input0_normalized = input0_normalized.astype('float32') + + output0_normalized = [] + for i in range(n_species - 1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = paddle.concat(output0_normalized, axis=1) + + 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] / paddle.sum(output0_Y[:, :-1], axis=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.numpy() + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/blockMeshDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/blockMeshDict new file mode 100644 index 000000000..6ca6fc6c6 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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) + (20 1 1) + (20 1 0) + (0 1 0) + (0 0 1) + (20 0 1) + (20 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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/controlDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/controlDict new file mode 100644 index 000000000..112640927 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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-7; + +maxDeltaT 1e-04; + +adjustTimeStep off; + +writeControl adjustableRunTime; + +writeInterval 0.0001; + +purgeWrite 0; + +writeFormat ascii; + +// writePrecision 6; + +writeCompression on; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + +adjustTimeStep no; + +// maxCo 0.8; + +// maxDeltaT 1e-4; + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/decomposeParDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/decomposeParDict new file mode 100644 index 000000000..45c7f859f --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/fvSchemes b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/fvSchemes new file mode 100644 index 000000000..c841b36e1 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/fvSolution b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/fvSolution new file mode 100644 index 000000000..c13c246bb --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/sample b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/sample new file mode 100644 index 000000000..d91b9125f --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/C2H4/system/sample @@ -0,0 +1,40 @@ +/*--------------------------------*- 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.00103 0 0); + end (0.0014 0 0); + nPoints 15; + } + +); + +fields ( T OH C2H4 CO2 H2O); + +// ************************************************************************* // + diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H.gz new file mode 100644 index 000000000..d713b87df Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2.gz new file mode 100644 index 000000000..87d09e26c Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O.gz new file mode 100644 index 000000000..866d73f7e Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O2.gz new file mode 100644 index 000000000..3c9aba5fd Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/H2O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/HO2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/HO2.gz new file mode 100644 index 000000000..f6dbcc225 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/HO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/N2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/N2.gz new file mode 100644 index 000000000..c33019290 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/N2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O.gz new file mode 100644 index 000000000..06f3e86cc Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O2.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O2.gz new file mode 100644 index 000000000..4a19afa76 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/OH.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/OH.gz new file mode 100644 index 000000000..5cbcb0908 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/T.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/T.gz new file mode 100644 index 000000000..d964f9d05 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/T.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/U.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/U.gz new file mode 100644 index 000000000..0f8b5ee1d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/U.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/p.gz b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/p.gz new file mode 100644 index 000000000..c434a5e83 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/0/p.gz differ diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allclean b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allclean new file mode 100644 index 000000000..2cd9e2246 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning log.*" +rm log.* +echo "Cleaning processor*" +rm -r processor* +echo "Cleaning polyMesh/" +rm -r constant/polyMesh diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allrun b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allrun new file mode 100644 index 000000000..c4fa56f05 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +if [ -e DNN_model.pt ] +then + echo "DNN_model.pt exists. Make sure correct DNN model has been used!" +else + echo "DNN_model.pt not exist. Downloading ..." + wget https://store.aissquare.com/models/5e1232cd-c23f-489f-9db4-ee09592beeb1/DNN_model.zip + unzip DNN_model.zip + cp ./DNN_model/H2/DNN_model.pt . + cp ./DNN_model/H2/Burke2012_s9r23.yaml . +fi + +# Source tutorial run functions +. $WM_PROJECT_DIR/bin/tools/RunFunctions + +application=dfLowMachFoam + +runApplication blockMesh +runApplication decomposePar +runApplication mpirun -np 4 --allow-run-as-root $application -parallel diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/CanteraTorchProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/CanteraTorchProperties new file mode 100644 index 000000000..b0a32440e --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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 on; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-6; + coresPerNode 4; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/combustionProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/combustionProperties new file mode 100644 index 000000000..7418500d0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/thermophysicalProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/thermophysicalProperties new file mode 100644 index 000000000..7f207bb77 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/turbulenceProperties b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/constant/turbulenceProperties new file mode 100644 index 000000000..ab70e94d3 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/inference.py b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/inference.py new file mode 100644 index 000000000..6c3754da9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/inference.py @@ -0,0 +1,153 @@ +import paddle +import paddle.nn as nn +import numpy as np +import time +import os +import cantera as ct + +device_main = "gpu:0" +device_list = range(paddle.device.cuda.device_count()) +paddle.set_printoptions(precision=10) + +class NN_MLP(nn.Layer): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = paddle.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_sublayer('linear_layer_%d' % (i), nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_sublayer('gelu_layer_%d' % (i), nn.GELU()) + self.net.add_sublayer('linear_layer_%d' % (n - 1), 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: + paddle.device.set_device(device_main) + device_ids = device_list + # paddle.set_device(device_main) + elif switch_GPU in switch_off: + paddle.device.set_device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = paddle.load(modelName) + 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 = paddle.to_tensor(Xmu0).unsqueeze(0).astype('float32') + Xstd0 = paddle.to_tensor(Xstd0).unsqueeze(0).astype('float32') + Ymu0 = paddle.to_tensor(Ymu0).unsqueeze(0).astype('float32') + Ystd0 = paddle.to_tensor(Ystd0).unsqueeze(0).astype('float32') + + 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].set_state_dict(state_dict[f'net{i}']) + + for i in range(n_species - 1): + model0list[i].eval() + model0list[i] = paddle.DataParallel(model0list[i]) if len(device_list) > 1 else model0list[i] + +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 paddle.no_grad(): + input0_ = paddle.to_tensor(vec0_input).astype('float32') + + # 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 + input0_normalized = input0_normalized.astype('float32') + + output0_normalized = [] + for i in range(n_species - 1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = paddle.concat(output0_normalized, axis=1) + + 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] / paddle.sum(output0_Y[:, :-1], axis=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.numpy() + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) diff --git a/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/blockMeshDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/blockMeshDict new file mode 100644 index 000000000..f6299b00b --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/controlDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/controlDict new file mode 100644 index 000000000..31e5f977b --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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.0001; + +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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/decomposeParDict b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/decomposeParDict new file mode 100644 index 000000000..45c7f859f --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/fvSchemes b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/fvSchemes new file mode 100644 index 000000000..c841b36e1 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/fvSolution b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/fvSolution new file mode 100644 index 000000000..c13c246bb --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/sample b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/system/sample new file mode 100644 index 000000000..747b58c43 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/oneD_freelyPropagation/H2/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H2.gz new file mode 100644 index 000000000..4e25f9469 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H3.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H3.gz new file mode 100644 index 000000000..af77b65ea Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H3.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H4.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H4.gz new file mode 100644 index 000000000..6421149b9 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H4.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H5.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H5.gz new file mode 100644 index 000000000..ba48d2e54 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/C2H5.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CHO.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CHO.gz new file mode 100644 index 000000000..729b558e1 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CHO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CO.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CO.gz new file mode 100644 index 000000000..21fc7812f Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2O.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2O.gz new file mode 100644 index 000000000..e29a4389c Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2OH.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2OH.gz new file mode 100644 index 000000000..a586f677d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH2OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH3.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH3.gz new file mode 100644 index 000000000..f86abb030 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH3.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH4.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH4.gz new file mode 100644 index 000000000..869d5b8e3 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CH4.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO.gz new file mode 100644 index 000000000..5b4755672 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO2.gz new file mode 100644 index 000000000..a3fd0f773 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/CO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H.gz new file mode 100644 index 000000000..b03ebe796 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2.gz new file mode 100644 index 000000000..f967128ea Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2O.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2O.gz new file mode 100644 index 000000000..22ef19334 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/H2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCCO.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCCO.gz new file mode 100644 index 000000000..43f866c8c Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCO.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCO.gz new file mode 100644 index 000000000..389a7b346 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HO2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HO2.gz new file mode 100644 index 000000000..c8e9292ee Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/HO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/N2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/N2.gz new file mode 100644 index 000000000..5b7450c38 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/N2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O.gz new file mode 100644 index 000000000..4da4a62f0 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O2.gz new file mode 100644 index 000000000..aa4f200ac Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/OH.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/OH.gz new file mode 100644 index 000000000..c35862057 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/S-CH2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/S-CH2.gz new file mode 100644 index 000000000..1a5f872c9 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/S-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T-CH2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T-CH2.gz new file mode 100644 index 000000000..efbe2ac81 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T.gz new file mode 100644 index 000000000..9a7a825b6 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/T.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/U.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/U.gz new file mode 100644 index 000000000..a5fd9584e Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/U.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/p.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/p.gz new file mode 100644 index 000000000..7bde1e5ad Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/0/p.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allclean b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allclean new file mode 100644 index 000000000..2cd9e2246 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning log.*" +rm log.* +echo "Cleaning processor*" +rm -r processor* +echo "Cleaning polyMesh/" +rm -r constant/polyMesh diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allrun b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allrun new file mode 100644 index 000000000..218486df6 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +if [ -e DNN_model.pt ] +then + echo "DNN_model.pt exists. Make sure correct DNN model has been used!" +else + echo "DNN_model.pt not exist. Downloading ..." + wget https://store.aissquare.com/models/5e1232cd-c23f-489f-9db4-ee09592beeb1/DNN_model.zip + unzip DNN_model.zip + cp ./DNN_model/C2H4/DNN_model.pt . + cp ./DNN_model/C2H4/Wu24sp.yaml . +fi + +# Source tutorial run functions +. $WM_PROJECT_DIR/bin/tools/RunFunctions + +application=dfLowMachFoam + +runApplication blockMesh +runApplication decomposePar +runApplication mpirun -np 8 --allow-run-as-root $application -parallel diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/CanteraTorchProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/CanteraTorchProperties new file mode 100644 index 000000000..6bac716f7 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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 "Wu24sp.yaml"; + +transportModel "Mix"; + +odeCoeffs +{ + "relTol" 1e-6; + "absTol" 1e-10; +} + +inertSpecie "N2"; + +splittingStrategy off; + +TorchSettings +{ + torch on; + GPU on; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-7; + coresPerNode 8; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/combustionProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/combustionProperties new file mode 100644 index 000000000..7418500d0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/thermophysicalProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/thermophysicalProperties new file mode 100644 index 000000000..7f207bb77 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/turbulenceProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/constant/turbulenceProperties new file mode 100644 index 000000000..ab70e94d3 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/inference.py b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/inference.py new file mode 100644 index 000000000..6c3754da9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/inference.py @@ -0,0 +1,153 @@ +import paddle +import paddle.nn as nn +import numpy as np +import time +import os +import cantera as ct + +device_main = "gpu:0" +device_list = range(paddle.device.cuda.device_count()) +paddle.set_printoptions(precision=10) + +class NN_MLP(nn.Layer): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = paddle.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_sublayer('linear_layer_%d' % (i), nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_sublayer('gelu_layer_%d' % (i), nn.GELU()) + self.net.add_sublayer('linear_layer_%d' % (n - 1), 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: + paddle.device.set_device(device_main) + device_ids = device_list + # paddle.set_device(device_main) + elif switch_GPU in switch_off: + paddle.device.set_device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = paddle.load(modelName) + 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 = paddle.to_tensor(Xmu0).unsqueeze(0).astype('float32') + Xstd0 = paddle.to_tensor(Xstd0).unsqueeze(0).astype('float32') + Ymu0 = paddle.to_tensor(Ymu0).unsqueeze(0).astype('float32') + Ystd0 = paddle.to_tensor(Ystd0).unsqueeze(0).astype('float32') + + 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].set_state_dict(state_dict[f'net{i}']) + + for i in range(n_species - 1): + model0list[i].eval() + model0list[i] = paddle.DataParallel(model0list[i]) if len(device_list) > 1 else model0list[i] + +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 paddle.no_grad(): + input0_ = paddle.to_tensor(vec0_input).astype('float32') + + # 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 + input0_normalized = input0_normalized.astype('float32') + + output0_normalized = [] + for i in range(n_species - 1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = paddle.concat(output0_normalized, axis=1) + + 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] / paddle.sum(output0_Y[:, :-1], axis=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.numpy() + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/blockMeshDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/blockMeshDict new file mode 100644 index 000000000..2625f1b3f --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/blockMeshDict @@ -0,0 +1,101 @@ +/*--------------------------------*- 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.01; + +vertices +( + (0 0 0) + (3.1415926 0 0) + (3.1415926 3.1415926 0) + (0 3.1415926 0) + (0 0 3.1415926) + (3.1415926 0 3.1415926) + (3.1415926 3.1415926 3.1415926) + (0 3.1415926 3.1415926) +); + + +blocks +( + hex (0 1 2 3 4 5 6 7) (1024 1024 1) simpleGrading (1 1 1) +); + +edges +( +); + +boundary +( + front + { + type empty; + faces + ( + (4 5 6 7) + ); + } + back + { + type empty; + faces + ( + (0 3 2 1) + ); + } + left + { + type patch; + neighbourPatch right; + faces + ( + (0 4 7 3) + ); + } + right + { + type patch; + neighbourPatch left; + faces + ( + (2 6 5 1) + ); + } + top + { + type patch; + neighbourPatch down; + faces + ( + (3 7 6 2) + ); + } + down + { + type patch; + neighbourPatch top; + faces + ( + (1 5 4 0) + ); + } +); + +// mergePatchPairs +// ( +// ); + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/controlDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/controlDict new file mode 100644 index 000000000..519859b27 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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 latestTime; + +startTime 0; + +stopAt endTime; + +endTime 0.0015; + +deltaT 1e-7; + +maxDeltaT 1e-04; + +adjustTimeStep off; + +writeControl adjustableRunTime; + +writeInterval 0.0001; + +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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/decomposeParDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/decomposeParDict new file mode 100644 index 000000000..66e942761 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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 8; + +method simple; + +simpleCoeffs +{ + n (4 2 1); + delta 0.001; +} + +hierarchicalCoeffs +{ + n (1 1 1); + delta 0.001; + order xyz; +} + +manualCoeffs +{ + dataFile ""; +} + +distributed no; + +roots ( ); + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/fvSchemes b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/fvSchemes new file mode 100644 index 000000000..c5c9136e5 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/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 linear; + 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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/fvSolution b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/fvSolution new file mode 100644 index 000000000..7ca84e9bd --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/fvSolution @@ -0,0 +1,89 @@ +/*--------------------------------*- 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 GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + pFinal + { + solver GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + "(U|ha|k|epsilon)" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + + "(U|ha|k|epsilon)Final" + { + $U; + tolerance 1e-5; + relTol 0; + } + + "Yi" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + "YiFinal" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-5; + relTol 0; + } +} + +PIMPLE +{ + momentumPredictor yes; + nOuterCorrectors 1; + nCorrectors 2; + nNonOrthogonalCorrectors 0; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/setFieldsDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/setFieldsDict new file mode 100644 index 000000000..a82e4100d --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/C2H4/system/setFieldsDict @@ -0,0 +1,60 @@ +/*--------------------------------*- 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 setFieldsDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +defaultFieldValues +( + volScalarFieldValue T 300 + volScalarFieldValue CH4 0.055167 + volScalarFieldValue O2 0.22006 + volScalarFieldValue N2 0.724773 +); + +regions +( + cylinderToCell + { + p1 (0.015707963 0.015707963 0); + p2 (0.015707963 0.015707963 0.031415926); + radius 0.0031415926; + fieldValues + ( + volScalarFieldValue T 2230.9 + volScalarFieldValue H2 0.000255 + volScalarFieldValue H 0.000015 + volScalarFieldValue O 0.000139 + volScalarFieldValue O2 0.006197 + volScalarFieldValue OH 0.001885 + volScalarFieldValue H2 0.120486 + volScalarFieldValue HO 0.000001 + volScalarFieldValue CH 0 + volScalarFieldValue CH2(S) 0 + volScalarFieldValue CH3 0 + volScalarFieldValue CH4 0 + volScalarFieldValue CO 0.008899 + volScalarFieldValue CO2 0.13735 + volScalarFieldValue HCO 0 + volScalarFieldValue CH2O 0 + volScalarFieldValue CH3O 0 + volScalarFieldValue C2H4 0 + volScalarFieldValue C2H5 0 + volScalarFieldValue C2H6 0 + volScalarFieldValue N2 0.724773 + ); + } +); + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H.gz new file mode 100644 index 000000000..614f4078e Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2.gz new file mode 100644 index 000000000..3c82d951d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O.gz new file mode 100644 index 000000000..1be7d2a8f Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O2.gz new file mode 100644 index 000000000..ddf0a6f1f Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/H2O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/HO2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/HO2.gz new file mode 100644 index 000000000..47767375d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/HO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/N2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/N2.gz new file mode 100644 index 000000000..22b050aeb Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/N2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O.gz new file mode 100644 index 000000000..fb8f8868d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O2.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O2.gz new file mode 100644 index 000000000..b2369e2af Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/OH.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/OH.gz new file mode 100644 index 000000000..49d4c454d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/T.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/T.gz new file mode 100644 index 000000000..5b3313649 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/T.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/U.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/U.gz new file mode 100644 index 000000000..d8a982d10 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/U.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/p.gz b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/p.gz new file mode 100644 index 000000000..c13481107 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/0/p.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allclean b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allclean new file mode 100644 index 000000000..2cd9e2246 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning log.*" +rm log.* +echo "Cleaning processor*" +rm -r processor* +echo "Cleaning polyMesh/" +rm -r constant/polyMesh diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allrun b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allrun new file mode 100644 index 000000000..de7c5c422 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +if [ -e DNN_model.pt ] +then + echo "DNN_model.pt exists. Make sure correct DNN model has been used!" +else + echo "DNN_model.pt not exist. Downloading ..." + wget https://store.aissquare.com/models/5e1232cd-c23f-489f-9db4-ee09592beeb1/DNN_model.zip + unzip DNN_model.zip + cp ./DNN_model/H2/DNN_model.pt . + cp ./DNN_model/H2/Burke2012_s9r23.yaml . +fi + +# Source tutorial run functions +. $WM_PROJECT_DIR/bin/tools/RunFunctions + +application=dfLowMachFoam + +runApplication blockMesh +runApplication decomposePar +runApplication mpirun -np 8 --allow-run-as-root $application -parallel diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Burke2012_s9r23.yaml b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/Burke2012_s9r23.yaml new file mode 100644 index 000000000..d77a77bbf --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/CanteraTorchProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/CanteraTorchProperties new file mode 100644 index 000000000..d0ab70b27 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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 on; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-6; + coresPerNode 8; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/combustionProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/combustionProperties new file mode 100644 index 000000000..7418500d0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/thermophysicalProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/thermophysicalProperties new file mode 100644 index 000000000..7f207bb77 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/turbulenceProperties b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/constant/turbulenceProperties new file mode 100644 index 000000000..ab70e94d3 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/inference.py b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/inference.py new file mode 100644 index 000000000..6c3754da9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/inference.py @@ -0,0 +1,153 @@ +import paddle +import paddle.nn as nn +import numpy as np +import time +import os +import cantera as ct + +device_main = "gpu:0" +device_list = range(paddle.device.cuda.device_count()) +paddle.set_printoptions(precision=10) + +class NN_MLP(nn.Layer): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = paddle.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_sublayer('linear_layer_%d' % (i), nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_sublayer('gelu_layer_%d' % (i), nn.GELU()) + self.net.add_sublayer('linear_layer_%d' % (n - 1), 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: + paddle.device.set_device(device_main) + device_ids = device_list + # paddle.set_device(device_main) + elif switch_GPU in switch_off: + paddle.device.set_device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = paddle.load(modelName) + 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 = paddle.to_tensor(Xmu0).unsqueeze(0).astype('float32') + Xstd0 = paddle.to_tensor(Xstd0).unsqueeze(0).astype('float32') + Ymu0 = paddle.to_tensor(Ymu0).unsqueeze(0).astype('float32') + Ystd0 = paddle.to_tensor(Ystd0).unsqueeze(0).astype('float32') + + 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].set_state_dict(state_dict[f'net{i}']) + + for i in range(n_species - 1): + model0list[i].eval() + model0list[i] = paddle.DataParallel(model0list[i]) if len(device_list) > 1 else model0list[i] + +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 paddle.no_grad(): + input0_ = paddle.to_tensor(vec0_input).astype('float32') + + # 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 + input0_normalized = input0_normalized.astype('float32') + + output0_normalized = [] + for i in range(n_species - 1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = paddle.concat(output0_normalized, axis=1) + + 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] / paddle.sum(output0_Y[:, :-1], axis=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.numpy() + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/blockMeshDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/blockMeshDict new file mode 100644 index 000000000..c9bc57caa --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/blockMeshDict @@ -0,0 +1,101 @@ +/*--------------------------------*- 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.01; + +vertices +( + (0 0 0) + (5.026548245743669 0 0) + (5.026548245743669 5.026548245743669 0) + (0 5.026548245743669 0) + (0 0 5.026548245743669) + (5.026548245743669 0 5.026548245743669) + (5.026548245743669 5.026548245743669 5.026548245743669) + (0 5.026548245743669 5.026548245743669) +); + + +blocks +( + hex (0 1 2 3 4 5 6 7) (1024 1024 1) simpleGrading (1 1 1) +); + +edges +( +); + +boundary +( + front + { + type empty; + faces + ( + (4 5 6 7) + ); + } + back + { + type empty; + faces + ( + (0 3 2 1) + ); + } + left + { + type patch; + neighbourPatch right; + faces + ( + (0 4 7 3) + ); + } + right + { + type patch; + neighbourPatch left; + faces + ( + (2 6 5 1) + ); + } + top + { + type patch; + neighbourPatch down; + faces + ( + (3 7 6 2) + ); + } + down + { + type patch; + neighbourPatch top; + faces + ( + (1 5 4 0) + ); + } +); + +// mergePatchPairs +// ( +// ); + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/controlDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/controlDict new file mode 100644 index 000000000..6f5f8a7b0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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 latestTime; + +startTime 0; + +stopAt endTime; + +endTime 0.001; + +deltaT 1e-6; + +maxDeltaT 1e-04; + +adjustTimeStep off; + +writeControl adjustableRunTime; + +writeInterval 0.0001; + +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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/decomposeParDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/decomposeParDict new file mode 100644 index 000000000..66e942761 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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 8; + +method simple; + +simpleCoeffs +{ + n (4 2 1); + delta 0.001; +} + +hierarchicalCoeffs +{ + n (1 1 1); + delta 0.001; + order xyz; +} + +manualCoeffs +{ + dataFile ""; +} + +distributed no; + +roots ( ); + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/fvSchemes b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/fvSchemes new file mode 100644 index 000000000..c5c9136e5 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/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 linear; + 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/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/fvSolution b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/fvSolution new file mode 100644 index 000000000..7ca84e9bd --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/fvSolution @@ -0,0 +1,89 @@ +/*--------------------------------*- 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 GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + pFinal + { + solver GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + "(U|ha|k|epsilon)" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + + "(U|ha|k|epsilon)Final" + { + $U; + tolerance 1e-5; + relTol 0; + } + + "Yi" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + "YiFinal" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-5; + relTol 0; + } +} + +PIMPLE +{ + momentumPredictor yes; + nOuterCorrectors 1; + nCorrectors 2; + nNonOrthogonalCorrectors 0; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/setFieldsDict b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/setFieldsDict new file mode 100644 index 000000000..5d7c6c907 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_HIT_flame/H2/system/setFieldsDict @@ -0,0 +1,55 @@ +/*--------------------------------*- 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 setFieldsDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +defaultFieldValues +( + volScalarFieldValue T 500 + volScalarFieldValue H 0.0 + volScalarFieldValue H2 0.028522 + volScalarFieldValue O 0.0 + volScalarFieldValue OH 0.0 + volScalarFieldValue H2O 0.0 + volScalarFieldValue O2 0.226354 + volScalarFieldValue HO2 0.0 + volScalarFieldValue H2O2 0.0 + volScalarFieldValue N2 0.745124 +); + +regions +( + cylinderToCell + { + p1 (0.025132741 0.025132741 0); + p2 (0.025132741 0.025132741 0.050265482); + radius 0.0025132741; + fieldValues + ( + volScalarFieldValue T 2485.8 + volScalarFieldValue H 0.000139 + volScalarFieldValue H2 0.001688 + volScalarFieldValue O 0.000763 + volScalarFieldValue OH 0.008357 + volScalarFieldValue H2O 0.234122 + volScalarFieldValue O2 0.009804 + volScalarFieldValue HO2 0.000003 + volScalarFieldValue H2O2 0 + volScalarFieldValue N2 0.745124 + ); + } +); + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H2.gz new file mode 100644 index 000000000..d706b5b72 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H3.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H3.gz new file mode 100644 index 000000000..2f446a0ca Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H3.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H4.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H4.gz new file mode 100644 index 000000000..fc3b06749 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H4.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H5.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H5.gz new file mode 100644 index 000000000..bcd51c7c3 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/C2H5.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CHO.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CHO.gz new file mode 100644 index 000000000..0be043ec0 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CHO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CO.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CO.gz new file mode 100644 index 000000000..2d984ffb5 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2O.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2O.gz new file mode 100644 index 000000000..a3a05ab56 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2OH.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2OH.gz new file mode 100644 index 000000000..461fa2233 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH2OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH3.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH3.gz new file mode 100644 index 000000000..2284d2771 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH3.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH4.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH4.gz new file mode 100644 index 000000000..85c4ffe80 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CH4.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO.gz new file mode 100644 index 000000000..17fbdc6a0 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO2.gz new file mode 100644 index 000000000..293b718c6 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/CO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H.gz new file mode 100644 index 000000000..99f51b266 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2.gz new file mode 100644 index 000000000..497a9e6d2 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2O.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2O.gz new file mode 100644 index 000000000..4d70b9d03 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/H2O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCCO.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCCO.gz new file mode 100644 index 000000000..b927da73e Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCO.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCO.gz new file mode 100644 index 000000000..b8c6ed1dd Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HCO.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HO2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HO2.gz new file mode 100644 index 000000000..c2c6d6216 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/HO2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/N2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/N2.gz new file mode 100644 index 000000000..da5a42a10 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/N2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O.gz new file mode 100644 index 000000000..a391115b2 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O2.gz new file mode 100644 index 000000000..38379dad2 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/O2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/OH.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/OH.gz new file mode 100644 index 000000000..2dfe5ae63 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/OH.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/S-CH2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/S-CH2.gz new file mode 100644 index 000000000..13368927d Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/S-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T-CH2.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T-CH2.gz new file mode 100644 index 000000000..bd0f585c9 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T-CH2.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T.gz new file mode 100644 index 000000000..b8a422581 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/T.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/U.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/U.gz new file mode 100644 index 000000000..2d0bb80cb Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/U.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/p.gz b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/p.gz new file mode 100644 index 000000000..3b942b940 Binary files /dev/null and b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/0/p.gz differ diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allclean b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allclean new file mode 100644 index 000000000..2cd9e2246 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allclean @@ -0,0 +1,9 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +echo "Cleaning log.*" +rm log.* +echo "Cleaning processor*" +rm -r processor* +echo "Cleaning polyMesh/" +rm -r constant/polyMesh diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allrun b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allrun new file mode 100644 index 000000000..218486df6 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/Allrun @@ -0,0 +1,22 @@ +#!/bin/sh +cd ${0%/*} || exit 1 # Run from this directory + +if [ -e DNN_model.pt ] +then + echo "DNN_model.pt exists. Make sure correct DNN model has been used!" +else + echo "DNN_model.pt not exist. Downloading ..." + wget https://store.aissquare.com/models/5e1232cd-c23f-489f-9db4-ee09592beeb1/DNN_model.zip + unzip DNN_model.zip + cp ./DNN_model/C2H4/DNN_model.pt . + cp ./DNN_model/C2H4/Wu24sp.yaml . +fi + +# Source tutorial run functions +. $WM_PROJECT_DIR/bin/tools/RunFunctions + +application=dfLowMachFoam + +runApplication blockMesh +runApplication decomposePar +runApplication mpirun -np 8 --allow-run-as-root $application -parallel diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/CanteraTorchProperties b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/CanteraTorchProperties new file mode 100644 index 000000000..6bac716f7 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/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 "Wu24sp.yaml"; + +transportModel "Mix"; + +odeCoeffs +{ + "relTol" 1e-6; + "absTol" 1e-10; +} + +inertSpecie "N2"; + +splittingStrategy off; + +TorchSettings +{ + torch on; + GPU on; + log on; + torchModel "DNN_model.pt"; + frozenTemperature 510; + inferenceDeltaTime 1e-7; + coresPerNode 8; +} + +loadbalancing +{ + active true; + log false; + algorithm allAverage;//headTail; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/combustionProperties b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/combustionProperties new file mode 100644 index 000000000..7418500d0 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/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/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/thermophysicalProperties b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/thermophysicalProperties new file mode 100644 index 000000000..f82ee9785 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/thermophysicalProperties @@ -0,0 +1,18 @@ +/*--------------------------------*- C++ -*----------------------------------*\ +| ========= | | +| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox | +| \\ / O peration | Version: 2.4.0 | +| \\ / A nd | Web: www.OpenFOAM.org | +| \\/ M anipulation | | +\*---------------------------------------------------------------------------*/ +FoamFile +{ + version 2.0; + format ascii; + class dictionary; + location "constant"; + object thermophysicalProperties; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/turbulenceProperties b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/constant/turbulenceProperties new file mode 100644 index 000000000..ab70e94d3 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/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/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/inference.py b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/inference.py new file mode 100644 index 000000000..6c3754da9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/inference.py @@ -0,0 +1,153 @@ +import paddle +import paddle.nn as nn +import numpy as np +import time +import os +import cantera as ct + +device_main = "gpu:0" +device_list = range(paddle.device.cuda.device_count()) +paddle.set_printoptions(precision=10) + +class NN_MLP(nn.Layer): + def __init__(self, layer_info): + super(NN_MLP, self).__init__() + self.net = paddle.nn.Sequential() + n = len(layer_info) - 1 + for i in range(n - 1): + self.net.add_sublayer('linear_layer_%d' % (i), nn.Linear(layer_info[i], layer_info[i + 1])) + self.net.add_sublayer('gelu_layer_%d' % (i), nn.GELU()) + self.net.add_sublayer('linear_layer_%d' % (n - 1), 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: + paddle.device.set_device(device_main) + device_ids = device_list + # paddle.set_device(device_main) + elif switch_GPU in switch_off: + paddle.device.set_device("cpu") + device_ids = [0] + else: + print("invalid setting!") + os._exit(0) + + lamda = 0.1 + dim = 9 + + state_dict = paddle.load(modelName) + 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 = paddle.to_tensor(Xmu0).unsqueeze(0).astype('float32') + Xstd0 = paddle.to_tensor(Xstd0).unsqueeze(0).astype('float32') + Ymu0 = paddle.to_tensor(Ymu0).unsqueeze(0).astype('float32') + Ystd0 = paddle.to_tensor(Ystd0).unsqueeze(0).astype('float32') + + 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].set_state_dict(state_dict[f'net{i}']) + + for i in range(n_species - 1): + model0list[i].eval() + model0list[i] = paddle.DataParallel(model0list[i]) if len(device_list) > 1 else model0list[i] + +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 paddle.no_grad(): + input0_ = paddle.to_tensor(vec0_input).astype('float32') + + # 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 + input0_normalized = input0_normalized.astype('float32') + + output0_normalized = [] + for i in range(n_species - 1): + output0_normalized.append(model0list[i](input0_normalized)) + output0_normalized = paddle.concat(output0_normalized, axis=1) + + 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] / paddle.sum(output0_Y[:, :-1], axis=1, keepdim=True) * (1 - output0_Y[:, -1:]) + output0 = (output0_Y - input0_Y) * rho0 / delta_t + output0 = output0.numpy() + + result = np.zeros((vec0.shape[0], n_species)) + result[mask, :] = output0 + return result + except Exception as e: + print(e.args) diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/blockMeshDict b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/blockMeshDict new file mode 100644 index 000000000..38710de65 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/blockMeshDict @@ -0,0 +1,126 @@ +/*--------------------------------*- 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 #codeStream +{ + codeInclude + #{ + #include "pointField.H" + #}; + + code + #{ + pointField points(8); + points[0] = point(0, 0, -0.5); + points[1] = point(16, 0, -0.5); + points[2] = point(16, 7.5, -0.5); + points[3] = point(0, 7.5, -0.5); + points[4] = point(0, 8.5, -0.5); + points[5] = point(16, 8.5, -0.5); + points[6] = point(16, 16, -0.5); + points[7] = point(0, 16, -0.5); + + // Duplicate z points + label sz = points.size(); + points.setSize(2*sz); + for (label i = 0; i < sz; i++) + { + const point& pt = points[i]; + points[i+sz] = point(pt.x(), pt.y(), -pt.z()); + } + + os << points; + #}; +}; + +blocks +( + hex (0 1 2 3 8 9 10 11) (800 250 1) + simpleGrading + ( + 1 + ( + (0.6 0.4 0.25) + (0.4 0.6 1) + ) + 1 + ) + hex (3 2 5 4 11 10 13 12) (800 50 1) simpleGrading (1 1 1) + hex (4 5 6 7 12 13 14 15) (800 250 1) + simpleGrading + ( + 1 + ( + (0.4 0.6 1) + (0.6 0.4 4) + ) + 1 + ) +); + +edges +( +); + +boundary +( + left + { + type cyclic; + neighbourPatch right; + faces + ( + (0 3 11 8) + (3 4 12 11) + (4 7 15 12) + ); + } + right + { + type cyclic; + neighbourPatch left; + faces + ( + (1 2 10 9) + (2 5 13 10) + (5 6 14 13) + ); + } + top + { + type patch; + faces + ( + (7 6 14 15) + ); + } + down + { + type patch; + faces + ( + (0 1 9 8) + ); + } +); + +// mergePatchPairs +// ( +// ); + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/controlDict b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/controlDict new file mode 100644 index 000000000..6e20a7723 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/controlDict @@ -0,0 +1,55 @@ +/*--------------------------------*- 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 latestTime; + +startTime 0; + +stopAt endTime; + +endTime 1.6e-4; + +deltaT 1e-7; + +writeControl adjustableRunTime; + +writeInterval 1e-5; + +purgeWrite 0; + +writeFormat ascii; + +// writePrecision 6; + +writeCompression on; + +timeFormat general; + +timePrecision 6; + +runTimeModifiable true; + +adjustTimeStep no; + +maxCo 0.6; + +maxDeltaT 1e-4; + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/decomposeParDict b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/decomposeParDict new file mode 100644 index 000000000..66e942761 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/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 8; + +method simple; + +simpleCoeffs +{ + n (4 2 1); + delta 0.001; +} + +hierarchicalCoeffs +{ + n (1 1 1); + delta 0.001; + order xyz; +} + +manualCoeffs +{ + dataFile ""; +} + +distributed no; + +roots ( ); + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSchemes b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSchemes new file mode 100644 index 000000000..2f2cf3dd9 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSchemes @@ -0,0 +1,60 @@ +/*--------------------------------*- 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 linear; + 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/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSolution b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSolution new file mode 100644 index 000000000..2ff9eac58 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/fvSolution @@ -0,0 +1,89 @@ +/*--------------------------------*- 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 GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + pFinal + { + solver GAMG; + tolerance 1e-7; + relTol 0.01; + smoother GaussSeidel; + cacheAgglomeration true; + nCellsInCoarsestLevel 20; + agglomerator faceAreaPair; + mergeLevels 1; + } + + "(U|ha|k|epsilon)" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + + "(U|ha|k|epsilon)Final" + { + $U; + tolerance 1e-7; + relTol 0.01; + } + + "Yi" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } + "YiFinal" + { + solver PBiCGStab; + preconditioner DILU; + tolerance 1e-7; + relTol 0.01; + } +} + +PIMPLE +{ + momentumPredictor yes; + nOuterCorrectors 1; + nCorrectors 2; + nNonOrthogonalCorrectors 0; +} + + +// ************************************************************************* // diff --git a/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/setFieldsDict b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/setFieldsDict new file mode 100644 index 000000000..cd6f8efe2 --- /dev/null +++ b/examples/dfLowMachFoam/paddle/twoD_temporally_evolving_jet/C2H4/system/setFieldsDict @@ -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; + location "system"; + object setFieldsDict; +} +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + +defaultFieldValues +( + volScalarFieldValue T 2458.6 + volScalarFieldValue H 0.000053 + volScalarFieldValue O2 0.01511 + volScalarFieldValue OH 0.004558 + volScalarFieldValue O 0.00077 + volScalarFieldValue H2 0.000356 + volScalarFieldValue H2O 0.075807 + volScalarFieldValue HO2 0.000002 + volScalarFieldValue CO 0.025874 + volScalarFieldValue CO2 0.159367 + volScalarFieldValue HCO 0.0 + volScalarFieldValue CH3 0.0 + volScalarFieldValue CH4 0.0 + volScalarFieldValue CH2O 0.0 + volScalarFieldValue T-CH2 0.0 + volScalarFieldValue S-CH2 0.0 + volScalarFieldValue C2H4 0.0 + volScalarFieldValue C2H5 0.0 + volScalarFieldValue C2H2 0.0 + volScalarFieldValue C2H3 0.0 + volScalarFieldValue CH2CHO 0.0 + volScalarFieldValue HCCO 0.0 + volScalarFieldValue CH2CO 0.0 + volScalarFieldValue CH2OH 0.0 + volScalarFieldValue N2 0.718103 +); + +regions +( + boxToCell + { + box (0 0.0075 -0.0005) (0.016 0.0085 0.0005); + fieldValues + ( + volScalarFieldValue T 500 + volScalarFieldValue H 0.0 + volScalarFieldValue O2 0.218145 + volScalarFieldValue OH 0.0 + volScalarFieldValue O 0.0 + volScalarFieldValue H2 0.0 + volScalarFieldValue H2O 0.0 + volScalarFieldValue HO2 0.0 + volScalarFieldValue CO 0.0 + volScalarFieldValue CO2 0.0 + volScalarFieldValue HCO 0.0 + volScalarFieldValue CH3 0.0 + volScalarFieldValue CH4 0.0 + volScalarFieldValue CH2O 0.0 + volScalarFieldValue T-CH2 0.0 + volScalarFieldValue S-CH2 0.0 + volScalarFieldValue C2H4 0.063752 + volScalarFieldValue C2H5 0.0 + volScalarFieldValue C2H2 0.0 + volScalarFieldValue C2H3 0.0 + volScalarFieldValue CH2CHO 0.0 + volScalarFieldValue HCCO 0.0 + volScalarFieldValue CH2CO 0.0 + volScalarFieldValue CH2OH 0.0 + volScalarFieldValue N2 0.718103 + + ); + } +); +// ************************************************************************* //