Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
autopep8 formatting
  • Loading branch information
IshaanDesai committed Dec 28, 2025
commit 53d9b2b9066bdc823565e00ad3d6a3e8cd78311d
12 changes: 8 additions & 4 deletions two-scale-heat-conduction/micro-dumux-mada/mada_switcher.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this directory, and how is it related to the micro-dumux-surrogate/?
What does mada stand for?
Why is there no run.sh and clean.sh, if this is a case directory?

Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ def switching_function(resolution, location, t, input, prev_output):
result = 0
# in the beginning we only want FOM
if t == 0.0:
if resolution > 0: result = -1
else: result = 0
if resolution > 0:
result = -1
else:
result = 0
# after small init phase, we want dynamic model selection
# for test purposes we say ROM is accurate in range
else:
concentration = input['concentration']
is_valid_range = 0.45 < concentration < 0.55
is_fom = resolution == 0

if is_fom and is_valid_range: result = 1
if not is_fom and not is_valid_range: result = -1
if is_fom and is_valid_range:
result = 1
if not is_fom and not is_valid_range:
result = -1

return result
7 changes: 2 additions & 5 deletions two-scale-heat-conduction/micro-dumux-mada/micro_sim_sur.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, sim_id):
"""
self._sim_id = sim_id
self._state = None

self._model = None
with open('micro-dumux-surrogate.pkl', 'rb') as input:
self._model = joblib.load(input)
Expand All @@ -38,7 +38,7 @@ def initialize(self):
return output_data

def get_state(self):
return self._state;
return self._state

def set_state(self, state):
self._state = state
Expand All @@ -54,6 +54,3 @@ def solve(self, macro_data, dt):
output_data["grain_size"] = math.sqrt((1 - model_eval["porosity"][0][0]) / math.pi)

return output_data



Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __init__(self, sim_id):
"""
self._sim_id = sim_id
self._state = None

self._model = None
with open('micro-dumux-surrogate.pkl', 'rb') as input:
self._model = joblib.load(input)
Expand All @@ -38,7 +38,7 @@ def initialize(self):
return output_data

def get_state(self):
return self._state;
return self._state

def set_state(self, state):
self._state = state
Expand All @@ -54,6 +54,3 @@ def solve(self, macro_data, dt):
output_data["grain_size"] = math.sqrt((1 - model_eval["porosity"][0][0]) / math.pi)

return output_data



Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def create_surrogate(snapshots_dir: str) -> tuple:
# Split the samples into training and validation sets
n_valid = 200
x_train, y_train, x_valid, y_valid = split_samples(x, y, n_valid)

inputs = Input()
inputs.add_marginals(name="concentration", dist_type="unif", parameters=[0, 0.5])

Expand Down Expand Up @@ -182,6 +182,7 @@ def validate_surrogate(x_valid, y_valid, model_name="micro-dumux-surrogate.pkl")
plt.title("IO: con to poro")
plt.show()


def main():
snapshots_dir = "output"
if not os.path.exists(snapshots_dir):
Expand Down