Skip to content

Commit

Permalink
add to streamlit postprocessing
Browse files Browse the repository at this point in the history
  • Loading branch information
ACea15 committed Nov 15, 2024
1 parent 3a4887a commit b59a44d
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/BUG/Streamlit/pages/7_Shards.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import streamlit as st
import importlib
# importlib.reload(sti)
importlib.reload(sti)

st.set_page_config(
page_title="Shards systems",
Expand Down Expand Up @@ -41,7 +41,7 @@
config = configuration.Config.from_file(f"{si}/config.yaml")
Csol[si.name] = sol
Cconfig[si.name] = config
st.session_state['Csol'] = Csol
st.session_state['Csol'] = Csol
st.session_state['Cconfig'] = Cconfig

sti.systems_shard(st.session_state['Csolshard'],
Expand Down
103 changes: 102 additions & 1 deletion examples/BUG/modelgeneration.org
Original file line number Diff line number Diff line change
Expand Up @@ -1940,7 +1940,6 @@ Running Nastran using the tailored functions in run_nastra.sh which moves output
ra_movie=None)
#+end_src


** Gust
*** Run
#+begin_src python :tangle settings_gust1.py
Expand Down Expand Up @@ -2126,6 +2125,108 @@ Running Nastran using the tailored functions in run_nastra.sh which moves output

#+RESULTS:


** Sharding

*** Discrete loads

*** Discrete loads Montecarlo
#+begin_src python :tangle settings_DiscreteLoadsMC.py
import pathlib
import jax.numpy as jnp
import feniax.preprocessor.configuration as configuration # import Config, dump_to_yaml
from feniax.preprocessor.inputs import Inputs
import feniax.feniax_main
import feniax.plotools.reconstruction as reconstruction

label_gaf = "<<parameters_gafs(output="label_gaf")>>"
num_poles = 5
Dhj_file = f"D{label_gaf}p{num_poles}"
Ahh_file = f"A{label_gaf}p{num_poles}"
Poles_file = f"Poles{label_gaf}p{num_poles}"

inp = Inputs()
inp.engine = "intrinsicmodal"
inp.fem.eig_type = "inputs"

inp.fem.connectivity = dict(# FusWing=['RWing',
# 'LWing'],
FusBack=['FusTail',
'VTP'],
FusFront=None,
RWing=None,
LWing=None,
FusTail=None,
VTP=['HTP', 'VTPTail'],
HTP=['RHTP', 'LHTP'],
VTPTail=None,
RHTP=None,
LHTP=None,
)

inp.fem.grid = f"./FEM/structuralGrid_{sol[:-1]}"
#inp.fem.folder = pathlib.Path('./FEM/')
inp.fem.Ka_name = f"./FEM/Ka_{sol[:-1]}.npy"
inp.fem.Ma_name = f"./FEM/Ma_{sol[:-1]}.npy"
inp.fem.eig_names = [f"./FEM/eigenvals_{sol}{num_modes}.npy",
f"./FEM/eigenvecs_{sol}{num_modes}.npy"]
inp.fem.num_modes = 50
inp.driver.typeof = "intrinsic"

#inp.driver.sol_path = pathlib.Path(
# f"./results_{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}")
inp.driver.sol_path = pathlib.Path(
"./results1gust")

inp.simulation.typeof = "single"
inp.system.name = "sh1"
inp.system.solution = "static"
inp.system.solver_library = "diffrax"
inp.system.solver_function = "newton"
inp.system.solver_settings = dict(rtol=1e-6,
atol=1e-6,
max_steps=50,
norm="linalg_norm",
kappa=0.01)
inp.system.xloads.follower_forces = True

inp.system.xloads.x = [0, 1, 2, 3, 4, 5, 6]
inp.system.t = [1, 2, 3, 4, 5, 6]
# rwing: 14-35
# lwing: 40-61
points = []
interpolation = [0.,2e5,2.5e5,3.e5,4.e5,4.8e5,5.3e5]
for ri,li in zip(range(14, 36),range(40,62)):
points.append(ri)
points.append(li)
[interpolation for pi in points]

inputforces = dict(follower_points=[[[25, 2], [48, 2]],
[[20, 2], [43, 2]],
[[15, 2], [38, 2]],
[[10, 2], [33, 2]],
[[25, 5], [48, 5]],
[[20, 5], [43, 5]],
[[15, 5], [38, 5]],
[[10, 5], [33, 5]],
],
follower_interpolation= [[[0.,2e5,2.5e5,3.e5,4.e5,4.8e5,5.3e5],
[0.,2e5,2.5e5,3.e5,4.e5,4.8e5,5.3e5]
]
]*8
)
inp.system.shard = dict(input_type="pointforces",
inputs=inputforces)

sol = feniax.feniax_shardmain.main(input_dict=inp, device_count=8)


#+end_src

*** Manoeuvre

*** Gust

* Gust solution (146)
:PROPERTIES:
:header-args: :session *pybug* :comments yes :noweb yes
Expand Down
12 changes: 6 additions & 6 deletions examples/BUG/settings_gust1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
#inp.driver.sol_path = pathlib.Path(
# f"./results_{datetime.datetime.now().strftime('%Y-%m-%d_%H:%M:%S')}")
inp.driver.sol_path = pathlib.Path(
"./results1gust")
"./resultsgust3")
inp.simulation.typeof = "single"
inp.system.name = "s1"
inp.system.solution = "dynamic"
inp.system.t1 = 7.5
inp.system.tn = 4001
inp.system.t1 = 2.5
inp.system.tn = 2001
inp.system.solver_library = "runge_kutta"
inp.system.solver_function = "ode"
inp.system.solver_settings = dict(solver_name="rk4")
Expand All @@ -57,9 +57,9 @@
inp.system.aero.A = f"./AERO/{Ahh_file}.npy"
inp.system.aero.D = f"./AERO/{Dhj_file}.npy"
inp.system.aero.gust_profile = "mc"
inp.system.aero.gust.intensity = 0.01 # 14.0732311562*0.001
inp.system.aero.gust.length = 30.
inp.system.aero.gust.step = 0.05
inp.system.aero.gust.intensity = 0.2 # 14.0732311562*0.001
inp.system.aero.gust.length = 67
inp.system.aero.gust.step = 0.5
inp.system.aero.gust.shift = 0.
inp.system.aero.gust.panels_dihedral = jnp.load("./AERO/Dihedral_d1c7.npy")
inp.system.aero.gust.collocation_points = "./AERO/Collocation_d1c7.npy"
Expand Down
6 changes: 3 additions & 3 deletions examples/BUG/settings_gust1shard.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
inp.simulation.typeof = "single"
inp.system.name = "s1"
inp.system.solution = "dynamic"
inp.system.t1 = 7.5
inp.system.tn = 4001
inp.system.t1 = 2.5
inp.system.tn = 2001
inp.system.solver_library = "runge_kutta"
inp.system.solver_function = "ode"
inp.system.solver_settings = dict(solver_name="rk4")
Expand All @@ -59,7 +59,7 @@
#inp.system.aero.gust.intensity = 14.0732311562*0.001
inp.system.aero.gust.fixed_discretisation = [50, 180]
#inp.system.aero.gust.length = 67.
inp.system.aero.gust.step = 1
inp.system.aero.gust.step = 0.5
inp.system.aero.gust.shift = 0.
inp.system.aero.gust.panels_dihedral = "./AERO/Dihedral_d1c7.npy"
inp.system.aero.gust.collocation_points = "./AERO/Collocation_d1c7.npy"
Expand Down
46 changes: 37 additions & 9 deletions feniax/plotools/streamlit/intrinsic.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ def show_vtu(vtu_folder, stream_out="streamlit"):
def df_geometry(fem):
st.header("Geometry and FE Models")
st.subheader("Condensed model")
st.table(fem.df_grid)

with st.expander("See dataframe with geometry nodes"):
st.table(fem.df_grid)

def fe_matrices(fem):
st.subheader("Ka and Ma input matrices")
Expand Down Expand Up @@ -134,7 +134,8 @@ def df_modes(sol, config):
df = pd.DataFrame(
mvalue[mnumber].T * scale, columns=["x", "y", "z", "rx", "ry", "rz"]
)
st.table(df)
with st.expander("See Modes data-frame"):
st.table(df)
st.divider()
fig = modes_3Dconfiguration(
mode=mvalue[mnumber] * scale, config=config, mode_label=mname, settings=None
Expand Down Expand Up @@ -323,7 +324,7 @@ def sys_X_comparison(X, t, labels, ylabel, mode="lines"):
componenti = None
col1, col2 = st.columns(2)
ntimes, ncomponents, nnodes = X[0].shape

dashstyle = [None, 'dash', 'dot', 'dashdot']*10
nodei = col1.selectbox("Select a node", options=range(nnodes))
componenti = col2.selectbox("Select a component", options=range(ncomponents))
# breakpoint()
Expand All @@ -335,7 +336,7 @@ def sys_X_comparison(X, t, labels, ylabel, mode="lines"):
fig,
dict(
name=labels[i],
# line=dict(color="navy"),
line=dict(dash=dashstyle[i]),
mode=mode,
),
dict(title="Time evolution"),
Expand All @@ -355,15 +356,34 @@ def sys_displacements_comp(solsys, config):
t = [list(range(len(qi))) for qi in Xvs[0].q]
mode = "lines+markers"

ra = [x.ra - config[labels[i]].fem.X.T for i, x in enumerate(Xvs)]
sys_X_comparison(ra, t, labels, "Displacements", mode)
try:
ua = [x.ra - config[labels[i]].fem.X.T for i, x in enumerate(Xvs)]
except KeyError:
label0 = list(config.keys())[0]
ua = [x.ra - config[label0].fem.X.T for i, x in enumerate(Xvs)]
sys_X_comparison(ua, t, labels, "Displacements", mode)

def sys_positions_comp(solsys):
labels = list(solsys.keys())
Xvs = list(solsys.values())
if hasattr(Xvs[0], "t"):
t = [x.t for x in Xvs]
mode = "lines"
else:
t = [list(range(len(qi))) for qi in Xvs[0].q]
mode = "lines+markers"

ra = [x.ra for i, x in enumerate(Xvs)]
sys_X_comparison(ra, t, labels, "Positions", mode)

def sys_displacements(solsys, config):
sys_X(solsys.ra - config.fem.X.T, solsys, label="Displacements")


def sys_positions(solsys):
sys_X(solsys.ra, solsys, label="Positions")

def sys_velocities_comp(solsys):

Xvs = list(solsys.values())
if hasattr(Xvs[0], "X1"):
labels = list(solsys.keys())
Expand All @@ -373,7 +393,6 @@ def sys_velocities_comp(solsys):
else:
st.text("Static solution!! All velocities are 0")


def sys_velocities(solsys):
if hasattr(solsys, "X1"):
sys_X(solsys.X1, solsys, label="X1")
Expand Down Expand Up @@ -604,6 +623,7 @@ def systems(sol, config):
[
"STATES",
"DISPLACEMENTS",
"POSITIONS",
"VELOCITIES",
"STRAINS",
"INTERNALFORCES",
Expand All @@ -630,6 +650,8 @@ def systems(sol, config):
sys_states(solsys)
case show.DISPLACEMENTS.name:
sys_displacements(solsys, config)
case show.POSITIONS.name:
sys_positions(solsys)
case show.VELOCITIES.name:
sys_velocities(solsys)
case show.STRAINS.name:
Expand All @@ -653,6 +675,7 @@ def systems_comparison(sol, config):
[
"STATES",
"DISPLACEMENTS",
"POSITIONS",
"VELOCITIES",
"STRAINS",
"INTERNALFORCES",
Expand Down Expand Up @@ -684,6 +707,8 @@ def systems_comparison(sol, config):
sys_states_comparison(solsys)
case show.DISPLACEMENTS.name:
sys_displacements_comp(solsys, config)
case show.POSITIONS.name:
sys_positions(solsys)
case show.VELOCITIES.name:
sys_velocities_comp(solsys)
case show.STRAINS.name:
Expand Down Expand Up @@ -733,6 +758,7 @@ def systems_shard(sol_shard, config_shard, sol=None, config=None):
[
"STATES",
"DISPLACEMENTS",
"POSITIONS",
"VELOCITIES",
"STRAINS",
"INTERNALFORCES",
Expand Down Expand Up @@ -792,6 +818,8 @@ def systems_shard(sol_shard, config_shard, sol=None, config=None):
sys_states_comparison(selected_solsys)
case show.DISPLACEMENTS.name:
sys_displacements_comp(selected_solsys, config_shard)
case show.POSITIONS.name:
sys_positions_comp(selected_solsys)
case show.VELOCITIES.name:
sys_velocities_comp(selected_solsys)
case show.STRAINS.name:
Expand Down
4 changes: 4 additions & 0 deletions feniax/plotools/streamlit/pages/Geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
import streamlit as st
import feniax.plotools.streamlit.theory as stt

import importlib
importlib.reload(sti)

st.set_page_config(
page_title="Initial model geometry",
page_icon="🛫",
Expand All @@ -19,3 +22,4 @@
if left.button("Click to see FE matrices", use_container_width=True):

sti.fe_matrices(st.session_state.config.fem)

0 comments on commit b59a44d

Please sign in to comment.