Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bashrc.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export PYTHON_LIB_DIR="PYTORCH_LIB"
export CANTERA_ROOT=LIBCANTERA_DIR
export CANTERA_DATA=$CANTERA_ROOT/share/cantera/data
export LD_LIBRARY_PATH=$LIBTORCH_ROOT/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$CANTERA_ROOT/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$CANTERA_ROOT/lib:$LD_LIBRARY_PATH
export FOAM_USER_LIBBIN=pwd/platforms/lib
export FOAM_USER_APPBIN=pwd/platforms/bin
export LD_LIBRARY_PATH=$FOAM_USER_LIBBIN:$LD_LIBRARY_PATH
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

torch.set_printoptions(precision=10)
print('position 0 in inference.py')
device = torch.device("cuda")
device_ids = range(torch.cuda.device_count())



class MyGELU(torch.nn.Module):
Expand Down Expand Up @@ -51,11 +48,49 @@ def forward(self, x):
x = self.fc(x)
return 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('torchModel1')
a = data.index('"',i)
b = data.index('.',a+1)
moduleName1 = data[a+1:b]

i = data.index('torchModel2')
a = data.index('"',i)
b = data.index('.',a+1)
moduleName2 = data[a+1:b]

i = data.index('torchModel3')
a = data.index('"',i)
b = data.index('.',a+1)
moduleName3 = data[a+1:b]

i = data.index('GPU')
a = data.index(';',i)
switch_GPU = data[i+4:a]

#load OpenFOAM switch
switch_on = ["True", "on", "yes", "y", "t", "any"]
switch_off = ["False", "off", "no", "n", "f", "none"]
if switch_GPU in switch_on:
device = torch.device("cuda")
device_ids = range(torch.cuda.device_count())
elif switch_GPU in switch_off:
device = torch.device("cpu")
device_ids = [0]
else:
print("invalid setting!")
os._exit(0)



#glbal variable will only init once when called interperter
#load parameters from json
setting0 = json2Parser('pytorchDNN/settings1.json')
setting1 = json2Parser('pytorchDNN/settings2.json')
setting2 = json2Parser('pytorchDNN/settings3.json')
setting0 = json2Parser(str("pytorchDNN/"+moduleName1+".json"))
setting1 = json2Parser(str("pytorchDNN/"+moduleName2+".json"))
setting2 = json2Parser(str("pytorchDNN/"+moduleName3+".json"))

lamda = setting0.power_transform
delta_t = setting0.delta_t
Expand All @@ -82,9 +117,9 @@ def forward(self, x):
model0 = Net()
model1 = Net()
model2 = Net()
check_point0 = torch.load('pytorchDNN/ESH2-sub1.pt')
check_point1 = torch.load('pytorchDNN/ESH2-sub2.pt')
check_point2 = torch.load('pytorchDNN/ESH2-sub3.pt')
check_point0 = torch.load(str("pytorchDNN/"+moduleName1+".pt"))
check_point1 = torch.load(str("pytorchDNN/"+moduleName2+".pt"))
check_point2 = torch.load(str("pytorchDNN/"+moduleName3+".pt"))
model0.load_state_dict(check_point0)
model1.load_state_dict(check_point1)
model2.load_state_dict(check_point2)
Expand Down
6 changes: 4 additions & 2 deletions src/dfChemistryModel/dfChemistryModel.C
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_CVODE
const DeltaTType& deltaT
)
{
Info<<"=== begin DLB-solve === "<<endl;
Info<<"=== begin solve_CVODE === "<<endl;
// CPU time analysis
clockTime timer;
scalar t_getProblems(0);
Expand All @@ -1119,6 +1119,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_CVODE

if(balancer_.active())
{
Info<<"Now use DLB algorithm!!"<<endl;
timer.timeIncrement();
balancer_.updateState(allProblems);
t_updateState = timer.timeIncrement();
Expand All @@ -1140,6 +1141,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_CVODE
}
else
{
Info<<"Now do not use DLB algorithm!!"<<endl;
timer.timeIncrement();
incomingSolutions.append(solveList(allProblems));
t_solveBuffer = timer.timeIncrement();
Expand All @@ -1159,7 +1161,7 @@ Foam::scalar Foam::dfChemistryModel<ThermoType>::solve_CVODE
<< endl;
}

Info<<"=== end DLB-solve === "<<endl;
Info<<"=== end solve_CVODE === "<<endl;
return updateReactionRates(incomingSolutions);
}

Expand Down