Skip to content

Commit

Permalink
92 erik paper branch (#197)
Browse files Browse the repository at this point in the history
* split macros and bib file for paper to reduce conflicts

* fix py_macros files

* add resulting py macros to git ignore

* small changes

* fix some warnings

* working on homogenization plots

* homogenization figure in doit

* more changes to homogenization appendix

* working on beam model

* changing beam design output WIP

* working on beam design

* new beam design working in snakemake

* add GWP of steel

* add beam figure to dodo file

* update workflow graph

* more changes for beam in paper

* beam design is working in doit

* changes to input values

* adding conversion of steel gwp input

* added computation paste specific heat capacity

* improved sc input to mass fraction

* fix sc value

* fixed test files

* fixed name of bending beam

* delete test temp files

* remove some temp files with gitignore

* update parameters

* working on function for calibraton of material model

* add json package

* e and fc over time is working

* add test for E and fc over time

* adding alpha_t28d to workflow

* added macros for optimization input

* add inits to include untested files in coverage

* simplifed computation sc volume fraction and added test

* fixed computation specific heat paste

* small fixes mainly comments

* imporve coverage

* improve coverage

* fixed tests

* renaming volume content to mass per cubic meter concrete

* add dummy test for dummy script

* add safety factors

* add loads to workflow

* write test to check output keys of workflow

* fix link to files

* fix link to files

* improve temp constraint

* continue to write paper section on beam and fem

* fix tests

* improve beam design mixed constraint

* improve beam appendix

* working on paper

* continue FEM

* working on heat of hydration figure

* working on introduction

* working on introduction

* working on introduction

* build script for design approach graph

* wip

* workign on paper

* include design approach in doit

* improving doit workflow

* improve doit output

* imporving doit paths

* improving dodo

* working on introduction

* update for analyze kpi

* update for analyze kpi

* fixed beam plot

* working on introduction

* improve introduction

* create heat release figure

* working on FEM section

* create evolution figure

* write evolution plot script

* add evolution to tex

* modify dummy script

* fix dummy script units and test

* integrate computation alpha 28 days to snakemake

* Update usecases/optimization_paper/tex/tex_sections/appendix_fem_model.tex

Co-authored-by: Sjard Mathis Rosenbusch <[email protected]>

* Update usecases/optimization_paper/tex/tex_sections/appendix_fem_model.tex

Co-authored-by: Sjard Mathis Rosenbusch <[email protected]>

* Update usecases/optimization_paper/tex/tex_sections/concrete_model.tex

Co-authored-by: Sjard Mathis Rosenbusch <[email protected]>

* Update usecases/optimization_paper/tex/tex_sections/introduction.tex

Co-authored-by: Sjard Mathis Rosenbusch <[email protected]>

---------

Co-authored-by: Sjard Mathis Rosenbusch <[email protected]>
  • Loading branch information
eriktamsen and srosenbu authored Aug 29, 2023
1 parent a061d07 commit 9094ce3
Show file tree
Hide file tree
Showing 21 changed files with 452 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def dummy_hydration_parameters(slag_ratio, phi_hydration):
maximum potential hydration parameter
"""

B1 = 2.916e-4 * ureg("1/s") # in 1/s
B1_min = 1.5e-4
B1_max = 2.916e-4
B1 = (B1_max - (B1_max - B1_min) * slag_ratio) * ureg("1/s")
B2 = 0.0024229 * ureg("") # -
eta = 5.554 * ureg("") # something about diffusion
E_act = 5653 * 8.3145 * ureg("J/mol") # activation energy in Jmol^-1
Expand Down
12 changes: 7 additions & 5 deletions tests/demonstrator_scripts/test_dummy_scripts.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import pytest

from lebedigital.demonstrator_scripts.dummy_hydration_parameters import dummy_hydration_parameters
from lebedigital.demonstrator_scripts.dummy_paste_strength_stiffness import dummy_paste_strength_stiffness
from lebedigital.demonstrator_scripts.dummy_hydration_parameters import \
dummy_hydration_parameters
from lebedigital.demonstrator_scripts.dummy_paste_strength_stiffness import \
dummy_paste_strength_stiffness


def test_dummy_scripts():
# just to fix the coverage
B1, B2, eta, E_act, Q_pot, T_ref = dummy_hydration_parameters(1, 10)
assert B1.magnitude == pytest.approx(2.916e-4)
B1, B2, eta, E_act, Q_pot, T_ref = dummy_hydration_parameters(0.5, 10)
assert B1.magnitude == pytest.approx(0.0002208)
assert B2.magnitude == pytest.approx(0.0024229)
assert eta.magnitude == pytest.approx(5.554)
assert E_act.magnitude == pytest.approx(5653 * 8.3145)
assert Q_pot.magnitude == pytest.approx(100000)
assert Q_pot.magnitude == pytest.approx(200000)
assert T_ref.magnitude == pytest.approx(25)

E, fc = dummy_paste_strength_stiffness(0, 10)
Expand Down
3 changes: 2 additions & 1 deletion tests/demonstrator_scripts/test_kpi_from_fem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import pint
import pint_pandas
import pytest
from pint.testsuite.helpers import assert_quantity_almost_equal as assert_approx
from pint.testsuite.helpers import \
assert_quantity_almost_equal as assert_approx

from lebedigital.demonstrator_scripts.kpi_from_fem import kpi_from_fem
from lebedigital.unit_registry import ureg
Expand Down
6 changes: 4 additions & 2 deletions usecases/optimization_paper/bam_figures/beam_design_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_plot_lists(order_list, values_dict, input_parameter):
A_errors[i][j] = out["constraint_max_steel_area"]
constraint[i][j] = out["constraint_beam_design"]

if constraint[i][j] >= 0:
if constraint[i][j] <= 0:
if max_admissable_area < crosssections[i][j]:
max_admissable_area = crosssections[i][j]

Expand All @@ -118,7 +118,7 @@ def plot_contour(ax, x, y, Z, color, linewidth, linestyle="solid"):
def plot_contour_filled_white(ax, x, y, Z):
max = np.nanmax(Z)
min = np.nanmin(Z)
levels = [min - 1, 0.0]
levels = [0.0, max]

X, Y = np.meshgrid(y, x)
ax.contourf(X.magnitude, Y.magnitude, Z, colors="white", levels=levels)
Expand Down Expand Up @@ -173,6 +173,8 @@ def plot_contour_filled(ax, x, y, Z, xlabel, ylabel, title, colorbar=False, max=
constraint_plots = [0] * len(chosen_plots)
plot_values = {}
max_plot_area = 0.0

# loop over all three plots
for i, plot in enumerate(chosen_plots):
(
crosssection_plots[i],
Expand Down
109 changes: 61 additions & 48 deletions usecases/optimization_paper/bam_figures/create_heat_release_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,35 @@
from lebedigital.unit_registry import ureg


def create_heat_release_figure():
# todo add units for the input, convert to correct untis
# add units for the output
# change time to hours our days in plot
# add legend
# add title
# add axis labels
def create_heat_release_figure(parameter: dict, fig_path: str = "test_heat_realease_plot.pdf"):
# add figure to tex file and snakemake workflow

T = 20 # temperature...
dt = 60 # dt
time_total = 100000
parameter["B1"] = parameter["heatExBOne"]
parameter["B2"] = parameter["heatExBTwo"]
parameter["eta"] = parameter["heatExEta"]
parameter["alpha_max"] = parameter["heatExAlphaMax"]
parameter["E_act"] = parameter["heatExEAct"]
parameter["T_ref"] = parameter["heatExTRef"]
parameter["Q_pot"] = parameter["heatExQPot"]

T = parameter["heatExT"] # temperature...
dt = parameter["heatExDt"] # dt
time_total = parameter["heatExTimeTotal"]
# what does T and dt do???

time_list = np.arange(0, time_total, dt)
parameter = {}
parameter["B1"] = 3e-4
parameter["B2"] = 0.001
parameter["eta"] = 6
parameter["alpha_max"] = 0.875
parameter["E_act"] = 47002
parameter["T_ref"] = 25
parameter["Q_pot"] = 500e3

variation_dict = {
"B1": [parameter["B1"], 2.0e-4, 3.7e-4],
"B2": [parameter["B2"], 0.0001, 0.01],
"eta": [parameter["eta"], 9, 4.5],
"Q_pot": [parameter["Q_pot"], 350e3, 650e3],
}

material_problem = fenics_concrete.ConcreteThermoMechanical()
hydration_fkt = material_problem.get_heat_of_hydration_ftk()

fig, axs = plt.subplots(1, len(variation_dict), figsize=(15, 3))
fig, axs = plt.subplots(2, len(variation_dict), figsize=(20, 7))
ureg.setup_matplotlib()

i = 0
Expand All @@ -56,42 +51,60 @@ def create_heat_release_figure():

delta_heat = np.diff(heat_list) / dt
plot_time = time_list[:-1]

axs[i].set_ylim([0, 0.006])
axs[i].plot(plot_time, delta_heat)
# add pint units to plot_time and delta_heat
plot_time = plot_time * ureg.second
# time_list = time_list * ureg.second
delta_heat = delta_heat * ureg.watt / ureg.kg
heat_list = heat_list * ureg.joule / ureg.kg

# convert plot_time to hours
plot_time = plot_time.to(ureg.hour)
# time_list = time_list.to(ureg.hour)
# convert delta_heat to mW/kg
delta_heat = delta_heat.to(ureg.mW / ureg.kg)
# heat_list = heat_list.to(ureg.mW / ureg.kg)

axs[0][i].set_ylim([0, 6])
axs[0][i].set_xlim([0, 24])
# plot delta heat over time with a legend
axs[0][i].plot(plot_time, delta_heat, label=key + " = " + str(value))

# cummulative heat release
axs[1][i].set_ylim([0, 400])
axs[1][i].set_xlim([0, 24 * 4])
axs[1][i].plot(plot_time, heat_list[:-1], label=key + " = " + str(value))

# plt.plot(time_list, heat_list, label=parameter + " = " + str(value))
axs[0][i].legend()
# set legend to lower right corner
axs[1][i].legend()
axs[1][i].legend(loc="lower right")

axs[0][i].set_ylabel(f"Heat release rate in {delta_heat.units}")
axs[0][i].set_xlabel(f"time in {plot_time.units}")
axs[1][i].set_ylabel(f"Cumulated heat release in {heat_list.units}")
axs[1][i].set_xlabel(f"time in {plot_time.units}")

i += 1

# initiate material problem
# get the respective function
#
# heat_list, doh_list = hydration_fkt(T, time_list, dt, parameter)
# print(heat_list)
# print(doh_list)
# print(time_list)

# #ureg.setup_matplotlib(enable=False)
# ureg2 = pint.UnitRegistry(auto_reduce_dimensions=True)

# fig.suptitle('Influence of aggregate ratio on effective concrete properties')
# axs[0].plot(time_list, heat_list)
# # axs[0].set_ylabel(f"Young's modulus in {E_list.units}")
# # axs[0].set_xlabel('aggregate volume fraction')
# axs[1].plot(time_list, doh_list)
# # axs[1].set_ylabel(f"Poission's ratio")
# # axs[1].set_xlabel('aggregate volume fraction')
# axs[2].plot(time_list, delta_heat)
# axs[2].set_ylabel(f"compressive strength {fc_list.units}")
# axs[2].set_xlabel('aggregate volume fraction')

# plt.subplots_adjust(wspace=0.4)
fig.tight_layout()
plt.show()
# plt.show()

# fig.savefig(fig_path)
fig.savefig(fig_path)


if __name__ == "__main__":
create_heat_release_figure()
parameter = {
"heatExBOne": 3e-4,
"heatExBTwo": 0.001,
"heatExEta": 6,
"heatExAlphaMax": 0.875,
"heatExEAct": 47002,
"heatExTRef": 25,
"heatExQPot": 500e3,
"heatExT": 20,
"heatExDt": 60,
"heatExTimeTotal": 60 * 60 * 24 * 4,
}

create_heat_release_figure(parameter)
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import copy

import fenics_concrete
import matplotlib.pyplot as plt
import numpy as np
import pint
import pytest
from pint.testsuite.helpers import assert_quantity_almost_equal as assert_approx

from lebedigital.simulation.concrete_homogenization import concrete_homogenization
from lebedigital.unit_registry import ureg


def create_mechanics_evolution_figure(input_parameter: dict, fig_path: str = "test_mechanics_evolution_plot.pdf"):
# add figure to tex file and snakemake workflow

material_problem = fenics_concrete.ConcreteThermoMechanical()
e_fkt = material_problem.mechanics_problem.E_fkt
fc_fkt = material_problem.mechanics_problem.general_hydration_fkt

# general parameters
parameter = {
"alpha_t": input_parameter["evoExAlphaT"],
"alpha_tx": input_parameter["evoExAlphaTx"],
"alpha_0": 0.0,
"a_E": input_parameter["evoExaE"],
"a_X": input_parameter["evoExafc"],
"E": input_parameter["evoExE"],
"X": input_parameter["evoExfc"],
}

alpha_list = np.arange(0, 1, 0.005)

variation_dict = {
"alpha_t": {
"params": [parameter["alpha_t"], 0.0, 0.6],
"fkt": e_fkt,
"ylabel": "Elastic modulus $E$ [GPa ???]",
"ylim": 60,
},
"a_E": {
"params": [parameter["a_E"], 0.2, 1.3],
"fkt": e_fkt,
"ylabel": "Elastic modulus $E$ [GPa ???]",
"ylim": 60,
},
"a_X": {
"params": [parameter["a_X"], 0.2, 1.3],
"fkt": fc_fkt,
"ylabel": "Compressive strength $f_c$ [MPa ???]",
"ylim": 40,
},
}

# setup plot
fig, axs = plt.subplots(1, len(variation_dict), figsize=(5 * len(variation_dict), 4))
ureg.setup_matplotlib()

i = 0
for key in variation_dict.keys():
p = copy.deepcopy(parameter)
var_par_list = variation_dict[key]["params"]
fkt = variation_dict[key]["fkt"]

for value in var_par_list:
p[key] = value
y_list = []
for alpha in alpha_list:
y_list.append(fkt(alpha, p))
axs[i].plot(alpha_list, y_list, label=key + " = " + str(value))

axs[i].legend()
axs[i].set_xlabel(f"Degree of hydration $\\alpha$")
axs[i].set_ylabel(variation_dict[key]["ylabel"])
axs[i].set_xlim([0, 1])
axs[i].set_ylim([0, variation_dict[key]["ylim"]])

i += 1

fig.tight_layout()
# plt.show()
fig.savefig(fig_path)


if __name__ == "__main__":
parameter = {
"evoExAlphaT": 0.2,
"evoExAlphaTx": 0.8,
"evoExaE": 0.5,
"evoExafc": 0.5,
"evoExE": 50,
"evoExfc": 30,
}

create_mechanics_evolution_figure(parameter)
50 changes: 48 additions & 2 deletions usecases/optimization_paper/dodo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import yaml
from bam_figures.beam_design_plot import beam_design_plot
from bam_figures.create_heat_release_figure import create_heat_release_figure
from bam_figures.create_homogenization_figure import create_homogenization_figure
from bam_figures.create_mechanics_evolution_figure import create_mechanics_evolution_figure
from bam_figures.design_approach import design_approach_graph
from bam_figures.paper_workflow_graph import paper_workflow_graph
from doit import get_var
Expand Down Expand Up @@ -142,7 +144,7 @@ def task_build_homogenization_figure():
target = paper_plot_target(homogenization_plot_name)

return {
"file_dep": [homogenization_plot_script],
"file_dep": [homogenization_plot_script, py_macros_file_BAM.with_suffix(".yaml")],
"actions": [
(
create_homogenization_figure,
Expand All @@ -154,6 +156,50 @@ def task_build_homogenization_figure():
}


def task_build_heat_release_figure():
"""build homogenization figure"""
# homogenization figure
heat_release_plot_name = data["file_names"]["heatReleasePlot"] # name of pdf file defined in macros yaml
heat_release_plot_script = ROOT / BAM_PLOT_DIR / "create_heat_release_figure.py"
heat_release_plot_output_file = ROOT / FIGURES_DIR / heat_release_plot_name

target = paper_plot_target(heat_release_plot_name)

return {
"file_dep": [heat_release_plot_script, py_macros_file_BAM.with_suffix(".yaml")],
"actions": [
(
create_heat_release_figure,
[data["heat_release_example_parameters"], heat_release_plot_output_file],
)
],
"targets": [target],
"clean": True,
}


def task_build_evolution_figure():
"""build evolution figure"""
# evolution figure
evolution_plot_name = data["file_names"]["evolutionPlot"] # name of pdf file defined in macros yaml
evolution_plot_script = ROOT / BAM_PLOT_DIR / "create_mechanics_evolution_figure.py"
evolution_plot_output_file = ROOT / FIGURES_DIR / evolution_plot_name

target = paper_plot_target(evolution_plot_name)

return {
"file_dep": [evolution_plot_script, py_macros_file_BAM.with_suffix(".yaml")],
"actions": [
(
create_mechanics_evolution_figure,
[data["evolution_example_parameters"], evolution_plot_output_file],
)
],
"targets": [target],
"clean": True,
}


def task_build_beam_design_figure():
"""build beam design figure"""
beam_design_plot_name = data["file_names"]["beamDesignPlot"] # name of output pdf file as defined in macros yaml
Expand All @@ -170,7 +216,7 @@ def task_build_beam_design_figure():
raise ValueError("Unknown mode")

return {
"file_dep": [beam_design_plot_script],
"file_dep": [beam_design_plot_script, py_macros_file_BAM.with_suffix(".yaml")],
"actions": [(beam_design_plot, [data["beam_design_example_parameters"], n, beam_design_plot_output_file])],
"targets": [target],
"clean": True,
Expand Down
Loading

0 comments on commit 9094ce3

Please sign in to comment.