Skip to content

Commit

Permalink
use work toolbox and remove redundant functions
Browse files Browse the repository at this point in the history
  • Loading branch information
malihass committed Nov 22, 2023
1 parent 2b8c4b6 commit 48e0dcf
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 267 deletions.
1 change: 0 additions & 1 deletion BayesianCalibration_spm/makeData.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
# from forwardPass import from_param_list_to_dict, from_param_list_to_str
from forwardPass import from_param_list_to_str
from plotsUtil_batt import *
from prettyPlot.plotsUtil import pretty_labels

# Read command line arguments
args_spm = argument.initArg()
Expand Down
32 changes: 17 additions & 15 deletions pinn_spm_param/integration_spm/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import argument
import numpy as np
from plotsUtil_batt import *
from prettyPlot.plotsUtil import pretty_labels, pretty_legend
from thermo import grad_ds_a_cs_a, grad_ds_c_cs_c

# Read command line arguments
Expand Down Expand Up @@ -135,25 +134,28 @@


# Plot cs
plotData(
[config["r_a"], config["r_c"]],
[sol["cs_a"] / params["csanmax"], sol["cs_c"] / params["cscamax"]],
params["tmax"],
[r"", r""],
[r"$c_{s,an}/c_{s,an,max}$", r"$c_{s,ca}/c_{s,ca,max}$"],
["r [m]", "r [m]"],
pretty_multi_contour(
listDatax=[config["r_a"], config["r_c"]],
listData=[
sol["cs_a"] / params["csanmax"],
sol["cs_c"] / params["cscamax"],
],
ybound=[0, params["tmax"]],
listCBLabel=[r"", r""],
listTitle=[r"$c_{s,an}/c_{s,an,max}$", r"$c_{s,ca}/c_{s,ca,max}$"],
listXAxisName=["r [m]", "r [m]"],
vminList=[0, 0],
vmaxList=[1, 1],
)

# Plot cs
plotData(
[config["r_a"], config["r_c"]],
[sol["cs_a"], sol["cs_c"]],
params["tmax"],
[r"", r""],
[r"$c_{s,an}$", r"$c_{s,ca}$"],
["r [m]", "r [m]"],
pretty_multi_contour(
listDatax=[config["r_a"], config["r_c"]],
listData=[sol["cs_a"], sol["cs_c"]],
ybound=[0, params["tmax"]],
listCBLabel=[r"", r""],
listTitle=[r"$c_{s,an}$", r"$c_{s,ca}$"],
listXAxisName=["r [m]", "r [m]"],
)

if args.verbose:
Expand Down
11 changes: 4 additions & 7 deletions pinn_spm_param/integration_spm/spm_int.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import sys

import numpy as np

sys.path.append("../util")
import time

from myProgressBar import printProgressBar
import numpy as np
from prettyPlot.progressBar import print_progress_bar


def get_r_domain(n_r, params):
Expand Down Expand Up @@ -188,7 +185,7 @@ def integration(
dR_c = config["dR_c"]

if verbose:
printProgressBar(
print_progress_bar(
0,
n_t,
prefix=f"Step= {0} / {n_t}",
Expand Down Expand Up @@ -429,7 +426,7 @@ def integration(
)

if verbose:
printProgressBar(
print_progress_bar(
i_t,
n_t - 1,
prefix=f"Step= {i_t} / {n_t}",
Expand Down
2 changes: 0 additions & 2 deletions pinn_spm_param/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
initialize_params_from_inpt,
)
from myNN import *
from myparser import parseInputFile
from myProgressBar import printProgressBar


def do_training_only(input_params, nn):
Expand Down
2 changes: 1 addition & 1 deletion pinn_spm_param/postProcess/computeManyMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import argument
from computeError import *
from prettyPlot.plotsUtil import plt, pretty_labels, pretty_legend
from plotsUtil_batt import *
from scipy import stats

print("\n\nINFO: COMPUTING MANY METRICS\n\n")
Expand Down
2 changes: 1 addition & 1 deletion pinn_spm_param/postProcess/plotCorrelationPINNvsData.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import argument
import tensorflow as tf
from myNN import *
from prettyPlot.plotsUtil import plt, pretty_labels, pretty_legend
from plotsUtil_batt import *
from tensorflow import keras
from tensorflow.keras import layers, regularizers

Expand Down
14 changes: 7 additions & 7 deletions pinn_spm_param/postProcess/plotData.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ def plot_pde_data(args):
plt.savefig(os.path.join(figureFolder, "PhiData.png"))

# Plot cs
plotData(
[r_a, r_c],
[cs_a, cs_c],
params["tmax"],
[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
[r"$c_{s,an}$", r"$c_{s,ca}$"],
["r [m]", "r [m]"],
pretty_multi_contour(
listDatax=[r_a, r_c],
listData=[cs_a, cs_c],
ybound=[0, params["tmax"]],
listCBLabel=[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
listTitle=[r"$c_{s,an}$", r"$c_{s,ca}$"],
listXAxisName=["r [m]", "r [m]"],
)
if not args.verbose:
plt.savefig(os.path.join(figureFolder, "csData.png"))
Expand Down
2 changes: 1 addition & 1 deletion pinn_spm_param/postProcess/plotManyLosses.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

sys.path.append("../util")
import argument
from prettyPlot.plotsUtil import plt, pretty_labels, pretty_legend
from plotsUtil_batt import *

print("\n\nINFO: PLOTTING MANY LOSSES\n\n")

Expand Down
14 changes: 7 additions & 7 deletions pinn_spm_param/postProcess/plotPINNResult.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,13 @@ def plot_pinn_result(args):
field_dat=field_dat,
verbose=args.verbose,
)
plotData(
[r_test_a[:, :, 0, 0], r_test_c[:, :, 0, 0]],
[cs_a[:, :, 0, 0], cs_c[:, :, 0, 0]],
tmax,
[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
[r"$c_{s,an}$", r"$c_{s,ca}$"],
["r [m]", "r [m]"],
pretty_multi_contour(
listDatax=[r_test_a[:, :, 0, 0], r_test_c[:, :, 0, 0]],
listData=[cs_a[:, :, 0, 0], cs_c[:, :, 0, 0]],
ybound=[0, tmax],
listCBLabel=[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
listTitle=[r"$c_{s,an}$", r"$c_{s,ca}$"],
listXAxisName=["r [m]", "r [m]"],
)
if not args.verbose:
plt.savefig(
Expand Down
14 changes: 7 additions & 7 deletions pinn_spm_param/postProcess/plotPINNResult_movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ def makePlot(movieDir, solDict, params_list, indMov, stepID, data_dict=None):
field_dat=field_dat,
verbose=False,
)
plotData(
[r_test_a[:, :, 0, 0], r_test_c[:, :, 0, 0]],
[cs_a[:, :, 0, 0], cs_c[:, :, 0, 0]],
tmax,
[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
[r"$c_{s,an}$", r"$c_{s,ca}$"],
["r [m]", "r [m]"],
pretty_multi_contour(
listDatax=[r_test_a[:, :, 0, 0], r_test_c[:, :, 0, 0]],
listData=[cs_a[:, :, 0, 0], cs_c[:, :, 0, 0]],
ybound=[0, tmax],
listCBLabel=[r"$[kmol/m^3]$", r"$[kmol/m^3]$"],
listTitle=[r"$c_{s,an}$", r"$c_{s,ca}$"],
listXAxisName=["r [m]", "r [m]"],
)
plt.savefig(
os.path.join(figureFolder, f"cs2D{string_params}_{indMov}.png")
Expand Down
2 changes: 1 addition & 1 deletion pinn_spm_param/postProcess/plotResidualVariation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

sys.path.append("../util")
import argument
from prettyPlot.plotsUtil import plt, pretty_labels, pretty_legend
from plotsUtil_batt import *

print("\n\nINFO: PLOTTING LOSSES\n\n")

Expand Down
6 changes: 3 additions & 3 deletions pinn_spm_param/util/generateOCP_poly_mon.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pandas as pd
import tf_lineInterp as tfli
from myProgressBar import printProgressBar
from prettyPlot.progressBar import print_progress_bar
from scipy import odr
from scipy.optimize import minimize

Expand Down Expand Up @@ -47,7 +47,7 @@ def polyOpt(order, xd, yd):

def iterativeOpt(order_list, xd, yd):
error = []
printProgressBar(
print_progress_bar(
0,
len(order_list) - 1,
prefix=f"Poly Order = {0} / {len(order_list)-1}",
Expand All @@ -59,7 +59,7 @@ def iterativeOpt(order_list, xd, yd):
pars = res.x
poly = np.poly1d(pars)
error.append(np.sum(abs(poly(xd) - yd)))
printProgressBar(
print_progress_bar(
order,
len(order_list) - 1,
prefix=f"Poly Order = {order} / {len(order_list)-1}",
Expand Down
5 changes: 2 additions & 3 deletions pinn_spm_param/util/init_pinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
import tensorflow as tf
from myNN import *
from myparser import parseInputFile
from myProgressBar import printProgressBar
from prettyPlot.parser import parse_input_file


def absolute_path_check(path):
Expand Down Expand Up @@ -289,7 +288,7 @@ def initialize_params_from_inpt(inpt):


def initialize_params(args):
inpt = parseInputFile(args.input_file)
inpt = parse_input_file(args.input_file)
return initialize_params_from_inpt(inpt)


Expand Down
8 changes: 4 additions & 4 deletions pinn_spm_param/util/myNN.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from custom_activations import swish_activation
from dataTools import checkDataShape, completeDataset
from eager_lbfgs import Struct, lbfgs
from myProgressBar import printProgressBar
from prettyPlot.progressBar import print_progress_bar
from tensorflow.keras import backend as K
from tensorflow.keras import (
initializers,
Expand Down Expand Up @@ -2313,7 +2313,7 @@ def train(
print("Using collocation points: " + self.collocationMode)

# Train
printProgressBar(
print_progress_bar(
0,
self.nEpochs,
prefix="Loss=%s Epoch= %d / %d " % ("?", 0, self.nEpochs),
Expand Down Expand Up @@ -2776,7 +2776,7 @@ def train(
) / (step + 1)

if not optimized and step % self.freq == 0:
printProgressBar(
print_progress_bar(
step,
self.n_batch,
prefix="Loss=%.2f i=%.2f b=%.2f d=%.2f r=%.2f, t/step=%.2g ms, Epoch= %d / %d "
Expand Down Expand Up @@ -2828,7 +2828,7 @@ def train(
self.reg_col_weights,
)

printProgressBar(
print_progress_bar(
epoch + 1,
self.nEpochs,
prefix="Loss=%.2f i=%.2f b=%.2f d=%.2f r=%.2f, t/step=%.2g ms, Epoch= %d / %d "
Expand Down
40 changes: 0 additions & 40 deletions pinn_spm_param/util/myProgressBar.py

This file was deleted.

20 changes: 0 additions & 20 deletions pinn_spm_param/util/myparser.py

This file was deleted.

Loading

0 comments on commit 48e0dcf

Please sign in to comment.