From 526e2db78251dd69301006cff4a6ef18900c41eb Mon Sep 17 00:00:00 2001 From: ac133718 Date: Thu, 22 Aug 2024 19:12:24 +0200 Subject: [PATCH] removed marimo_inputs --- .gitignore | 3 + test/input_files/generate_load_paths.py | 116 -------- .../marimo_inputs/fans_input.grid.json | 77 ----- test/input_files/marimo_inputs/fans_input.py | 269 ------------------ .../marimo_inputs/fans_input.slides.json | 4 - .../layouts/fans_input.grid.json | 77 ----- .../layouts/fans_input.slides.json | 4 - 7 files changed, 3 insertions(+), 547 deletions(-) delete mode 100644 test/input_files/generate_load_paths.py delete mode 100644 test/input_files/marimo_inputs/fans_input.grid.json delete mode 100644 test/input_files/marimo_inputs/fans_input.py delete mode 100644 test/input_files/marimo_inputs/fans_input.slides.json delete mode 100644 test/input_files/marimo_inputs/layouts/fans_input.grid.json delete mode 100644 test/input_files/marimo_inputs/layouts/fans_input.slides.json diff --git a/.gitignore b/.gitignore index 557275d..4b23465 100644 --- a/.gitignore +++ b/.gitignore @@ -194,6 +194,9 @@ data_gen/ test/input_files/*.json test/input_files/**/*.json +# Dedicated folder for personal projects +**/scratch/ + # Test microstructure files !sphere.h5 diff --git a/test/input_files/generate_load_paths.py b/test/input_files/generate_load_paths.py deleted file mode 100644 index a767e19..0000000 --- a/test/input_files/generate_load_paths.py +++ /dev/null @@ -1,116 +0,0 @@ -import numpy as np - - -def generate_strain_path(steps): - """ - Generate a strain path with smooth transitions based on user-defined steps, - without repeating strain values at the transition points. - - Parameters: - steps (list of dict): Each dictionary contains: - - 'final_strain': A list of length 6 specifying the final strain position to reach - - 'n_steps': The number of time steps for this loading segment - - Returns: - strain_path (np.ndarray): An array of shape (total_timesteps, 6) representing the strain path. - """ - - strain_path = [] - current_strain = np.zeros(6) # Start from zero strain - - for step in steps: - final_strain = np.array(step["final_strain"]) - n_steps = step["n_steps"] - - # Generate incremental steps excluding the start point - step_strain = np.linspace( - current_strain, final_strain, n_steps + 1, endpoint=True - )[1:] - - # Append the step strain path - strain_path.append(step_strain) - - # Update current strain to the last value of this step - current_strain = final_strain - - # Concatenate all steps to form the complete strain path - strain_path = np.vstack(strain_path) - - return strain_path - - -def generate_random_walk_path(n_steps, step_config, initial_strain=None): - """ - Generate a strain path based on a random walk. - - Parameters: - n_steps (int): The total number of time steps for the random walk. - step_config (list of dict): A list of dictionaries for each strain component (length 6). - Each dictionary can contain: - - 'range': A tuple (min_step, max_step) indicating the range of random step sizes for this component. - - OR 'fixed_step': A fixed step size for this component. - initial_strain (list or np.ndarray): The starting strain position. If None, starts from zero. - - Returns: - random_walk_path (np.ndarray): An array of shape (n_steps, 6) representing the random walk strain path. - """ - - if initial_strain is None: - current_strain = np.zeros(6) - else: - current_strain = np.array(initial_strain) - - random_walk_path = [current_strain] - - for _ in range(n_steps): - step = np.zeros(6) - for i, config in enumerate(step_config): - if "range" in config: - # Generate a random step within the specified range - step[i] = np.random.uniform(config["range"][0], config["range"][1]) - elif "fixed_step" in config: - # Use the fixed step size - step[i] = config["fixed_step"] - # Randomly decide whether to add or subtract the step - step[i] *= np.random.choice([-1, 1]) - - # Update the current strain - current_strain = current_strain + step - random_walk_path.append(current_strain) - - random_walk_path = np.array(random_walk_path) - - return random_walk_path - - -def print_formatted_strain_path(strain_path): - formatted_strain = ",\n".join( - [f"[{', '.join(f'{v:.4g}' for v in strain)}]" for strain in strain_path] - ) - print(formatted_strain) - - -# Example usage for regular strain path -steps = [ - {"final_strain": [0.005, 0, 0, 0, 0, 0], "n_steps": 50}, - {"final_strain": [-0.005, 0, 0, 0, 0, 0], "n_steps": 50}, - {"final_strain": [0.005, 0, 0, 0, 0, 0], "n_steps": 50}, -] -strain_path = generate_strain_path(steps) -print("Generated strain path:") -print_formatted_strain_path(strain_path) - - -# # Example usage for random walk strain path -# step_config = [ -# {'range': (-0.001, 0.001)}, # Component 1 with a range -# {'range': (-0.001, 0.001)}, # Component 2 with a fixed step size -# {'range': (-0.001, 0.001)},# Component 3 with a different range -# {'range': (-0.0001, 0.0001)},# Component 4 with another range -# {'range': (-0.0001, 0.0001)}, # Component 5 with a fixed step size -# {'range': (-0.0001, 0.0001)} # Component 6 with another range -# ] - -# random_walk_path = generate_random_walk_path(n_steps=100, step_config=step_config) -# print("\nGenerated random walk strain path:") -# print_formatted_strain_path(random_walk_path) diff --git a/test/input_files/marimo_inputs/fans_input.grid.json b/test/input_files/marimo_inputs/fans_input.grid.json deleted file mode 100644 index bdcb68f..0000000 --- a/test/input_files/marimo_inputs/fans_input.grid.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "type": "grid", - "data": { - "columns": 24, - "rowHeight": 20, - "maxWidth": 1400, - "bordered": true, - "cells": [ - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": [ - 2, - 2, - 9, - 53 - ] - }, - { - "position": [ - 13, - 2, - 10, - 48 - ] - }, - { - "position": [ - 16, - 51, - 6, - 4 - ] - }, - { - "position": null - } - ] - } -} diff --git a/test/input_files/marimo_inputs/fans_input.py b/test/input_files/marimo_inputs/fans_input.py deleted file mode 100644 index 1bcadf4..0000000 --- a/test/input_files/marimo_inputs/fans_input.py +++ /dev/null @@ -1,269 +0,0 @@ -import marimo - -__generated_with = "0.7.20" -app = marimo.App(width="medium", layout_file="fans_input.grid.json") - - -@app.cell -def __(): - import marimo as mo - - return (mo,) - - -@app.cell -def __(): - import json - - return (json,) - - -@app.cell -def __(get_fans_input, set_fans_input): - # General methods to change the state of fans_input via methods, for giving to ui elements - def change_input(key): - def f(val): - temp = get_fans_input() - temp[key] = val - set_fans_input(temp) - - return f - - def get_input_value(key): - try: - return get_fans_input()[key] - except: - return None - - return change_input, get_input_value - - -@app.cell -def __(change_input, mo): - # Function to create an array input of numbers - def create_array_input( - name, length, values, start=-1e5, stop=1e5, on_change=None, **kwargs - ): - t = [] - vals = {} - for i in range(length): - try: - vals[i] = values[i] - except: - vals[i] = 0 - # print(f"Creating array input {name} with length {length} and {values}, currently {i} and value {vals[i]}") - t.append(mo.ui.number(start, stop, value=vals[i], **kwargs)) - if on_change: - # take custom function (for subfields) - out = mo.ui.array(t, label=name, on_change=on_change) - # print(f"{on_change=}") - # on_change(vals) # DANGER! breaks the notebook! needs to restart session! manual on_change trigger - return out - else: - # take general function (for general json fields) - return mo.ui.array(t, label=name, on_change=change_input(name)) - - return (create_array_input,) - - -@app.cell -def __(create_array_input, mo, ui_number_of_phases): - # Function to create a nested array input, such as material_properties: creates a ui array holding ui_arrays. - def create_nested_array_input( - name, subnames, values, on_change, start=-1e5, stop=1e5, **kwargs - ): - t = [] - for i, subname in enumerate(subnames): - # print(f"Creating array for {name}, with {subname}, current value:{values[subname]}") - t1 = create_array_input( - subname, - ui_number_of_phases.value, - values[subname], - on_change=on_change(subname), - ) - t.append(t1) - out = mo.ui.array(t, label=name) - return out - - return (create_nested_array_input,) - - -@app.cell -def __(): - # Standard input: could also be done by reading in a file, which then gets changed, or clean this out to sth more general... - input_standard = { - "comment": "This field is ignored and can be used to describe the format. 'problem_type' can be 'thermal' or 'mechanical'. 'method' can be 'fp' or 'cg'. 'matmodel' can be 'ThermalLinear', 'MechLinear' or 'HyperElastic'. g0 is the macroscale loading vectors - each row is a new loading condition", - "ms_filename": "microstructures/sphere32.h5", - "ms_datasetname": "/sphere/32x32x32/ms", - "ms_L": [1.0, 1.0, 1.0], - "problem_type": "mechanical", - "matmodel": "HyperElastic", - "material_properties": { - "bulk_modulus": [62.5000, 222.222], - "shear_modulus": [28.8462, 166.6667], - "critical_stress": [0.1, 10000], - "hardening_parameter": [0.0, 0.0], - }, - "method": "cg", - "TOL": 1e-10, - "n_it": 500, - "g0": [0.010, -0.010, 0, 0.0, 0, 0], - "results": [], - } - return (input_standard,) - - -@app.cell -def __(input_standard): - # Generate starter dictionary by updating the reference with a comment -> not really needed, but already there... - input_dict = {"comment": "This is auto-generated by a marimo-notebook!"} - input_dict.update(input_standard) - return (input_dict,) - - -@app.cell -def __(input_dict, mo): - # Create the state of the fans input - get_fans_input, set_fans_input = mo.state(input_dict) - return get_fans_input, set_fans_input - - -@app.cell -def __(get_fans_input, json, mo): - # Create download button - download_txt = mo.download( - data=json.dumps(get_fans_input(), indent=5), - filename="test.json", - # mimetype="text/plain", - ) - return (download_txt,) - - -@app.cell -def __(mo): - # Needs to be in separate cell to other ui elements -> they get refreshed with state - ui_number_of_phases = mo.ui.number( - start=2, stop=6, value=2, label="Number of Phases" - ) - return (ui_number_of_phases,) - - -@app.cell -def __(change_input, create_array_input, get_input_value, mo): - # General ui elements - ui_ms_filename = mo.ui.text( - value=get_input_value("ms_filename"), - label="ms_filename", - on_change=change_input("ms_filename"), - max_length=100, - ) - ui_problem_dropdown = mo.ui.dropdown( - options=["mechanical", "thermal"], - value=get_input_value("problem_type"), - label="Problem type:", - on_change=change_input("problem_type"), - ) - ui_ms_L = create_array_input("ms_L", 3, values=get_input_value("ms_L")) - return ui_ms_L, ui_ms_filename, ui_problem_dropdown - - -@app.cell -def __(change_input, get_input_value, mo, ui_problem_dropdown): - # Problem changer -> changes the dropdown for selecting the material model - match ui_problem_dropdown.value: - case "mechanical": - ui_matmodel_dropdown = mo.ui.dropdown( - options=["MechLinear", "HyperElastic"], - value=get_input_value("matmodel"), - label="Material Model:", - on_change=change_input("matmodel"), - ) - case "thermal": - ui_matmodel_dropdown = mo.md("Not defined yet!") - return (ui_matmodel_dropdown,) - - -@app.cell -def __( - create_nested_array_input, - get_fans_input, - get_input_value, - mo, - set_fans_input, -): - # cell which creates the ui to select material parameters - # currently no distingishing between problem types -> need of unique names for material laws! - # New function to just alter material_properties: basically goes down one level in the dict/json - # TODO: could be wrapped in another function, varyiing the indentation key - def change_material(key): - def f(val): - temp = get_fans_input() - temp["material_properties"][key] = val - set_fans_input(temp) - - return f - - ui_matmodel_parameters = mo.md("Material parameters not prepared!") - match get_fans_input()["matmodel"]: - case "MechLinear": - subnames = [ - "bulk_modulus", - "shear_modulus", - "critical_stress", - "hardening_parameter", - ] - ui_matmodel_parameters = create_nested_array_input( - "material_properties", - subnames, - values=get_input_value("material_properties"), - on_change=change_material, - ) - case "HyperElastic": - pass - return change_material, subnames, ui_matmodel_parameters - - -@app.cell -def __( - mo, - ui_matmodel_dropdown, - ui_matmodel_parameters, - ui_ms_L, - ui_ms_filename, - ui_number_of_phases, - ui_problem_dropdown, -): - # General form - # could also be done as "form", so a button press would be needed to change all the values - mo.vstack( - [ - ui_ms_filename, - ui_number_of_phases, - ui_ms_L, - ui_problem_dropdown, - ui_matmodel_dropdown, - ui_matmodel_parameters, - ] - ) - return - - -@app.cell -def __(get_fans_input, json): - json.dumps(get_fans_input(), indent=5) - return - - -@app.cell -def __(download_txt): - download_txt - return - - -@app.cell -def __(): - return - - -if __name__ == "__main__": - app.run() diff --git a/test/input_files/marimo_inputs/fans_input.slides.json b/test/input_files/marimo_inputs/fans_input.slides.json deleted file mode 100644 index 3bcd0f5..0000000 --- a/test/input_files/marimo_inputs/fans_input.slides.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "slides", - "data": {} -} diff --git a/test/input_files/marimo_inputs/layouts/fans_input.grid.json b/test/input_files/marimo_inputs/layouts/fans_input.grid.json deleted file mode 100644 index bdcb68f..0000000 --- a/test/input_files/marimo_inputs/layouts/fans_input.grid.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "type": "grid", - "data": { - "columns": 24, - "rowHeight": 20, - "maxWidth": 1400, - "bordered": true, - "cells": [ - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": null - }, - { - "position": [ - 2, - 2, - 9, - 53 - ] - }, - { - "position": [ - 13, - 2, - 10, - 48 - ] - }, - { - "position": [ - 16, - 51, - 6, - 4 - ] - }, - { - "position": null - } - ] - } -} diff --git a/test/input_files/marimo_inputs/layouts/fans_input.slides.json b/test/input_files/marimo_inputs/layouts/fans_input.slides.json deleted file mode 100644 index 3bcd0f5..0000000 --- a/test/input_files/marimo_inputs/layouts/fans_input.slides.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "type": "slides", - "data": {} -}