Skip to content

Commit

Permalink
Component-wise training example for linear elasticity (#29)
Browse files Browse the repository at this point in the history
* Added config generation for componentwise training

* Added parameterized problem

* updated yaml

* Update linelast_comp.py

Distances were wrong for horizontal rods

* New component training procedure

* Componentwise training efficiency improved

* Added "optimized" component meshes

* Correct mesh size

* copy config

* New mesh

* added fespace

* fixed training

* Component generation

* Sinusoidal BCs

* changed config

* Added componentwise training files

* removed complicated meshes

* Updated component wise training

* Removed unecessary copies

* removed unnecessary config

* Refactored python scripts

* Removed unnecessary function definition

* Renamed confusing variables

* Gitignore was wrong

---------

Co-authored-by: Axel Larsson <[email protected]>
  • Loading branch information
larsson4 and axla-io authored Mar 25, 2024
1 parent 47cf861 commit 8f0e7ec
Show file tree
Hide file tree
Showing 10 changed files with 870 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ENV LIBROM_DIR=$LIB_DIR/libROM

# install python
RUN sudo apt-get update && sudo apt-get install -yq python3 python3-pip
RUN sudo pip3 install --upgrade pip && sudo pip3 install numpy scipy argparse tables PyYAML h5py
RUN sudo pip3 install --upgrade pip && sudo pip3 install numpy scipy argparse tables PyYAML h5py matplotlib

# install h5dump and gmsh
RUN sudo apt-get install -yq hdf5-tools gmsh
Expand Down
4 changes: 3 additions & 1 deletion examples/linelast/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ file(COPY config/linelast.simpleL.h5 DESTINATION ${CMAKE_BINARY_DIR}/examples/li
file(COPY linelast.lattice.yml DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast)
file(COPY config/linelast.lattice.h5 DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/config)
file(COPY linelast.force_cantilever.yml DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast)
file(COPY linelast.comp_train.yml DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast)
file(COPY config/linelast.comp_train.h5 DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/config)

file(COPY meshes/beam-tri.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
file(COPY meshes/beam-tet.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
file(COPY meshes/joint2D.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
file(COPY meshes/rod2D_H.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
file(COPY meshes/rod2D_V.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
file(COPY meshes/rod2D_V.mesh DESTINATION ${CMAKE_BINARY_DIR}/examples/linelast/meshes)
Binary file added examples/linelast/config/linelast.comp_train.h5
Binary file not shown.
Binary file modified examples/linelast/config/linelast.lattice.h5
Binary file not shown.
227 changes: 227 additions & 0 deletions examples/linelast/linelast.comp_train.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
main:
mode: single_run
use_rom: true
solver: linelast

mesh:
type: component-wise
component-wise:
global_config: "config/linelast.comp_train.h5"
components:
- name: "joint2D"
file: "meshes/joint2D.mesh"
- name: "rod2D_H"
file: "meshes/rod2D_H.mesh"
- name: "rod2D_V"
file: "meshes/rod2D_V.mesh"
uniform_refinement: 0

domain-decomposition:
type: interior_penalty

solver:
direct_solve: true

discretization:
order: 1
full-discrete-galerkin: true

visualization:
enabled: false
unified_paraview: true
file_path:
prefix: paraview_output

parameterized_problem:
name: linelast_cwtrain

single_run:
linelast_cwtrain:
l_ux: 0.0
l_uy: 0.0
r_fx: 0.0
r_fy: -2.0e-2
u_fx: 0.0
u_fy: 0.0
d_fx: 0.0
d_fy: 0.0
lx: 0.5
ly: 0.5
rx: 0.0
ry: 0.5
dx: 0.0
dy: 0.0
ux: 0.0
uy: 0.0
xu_amp: 1.0
xu_freq: 1.0
xu_offset: 0.0
xf_amp: 1.0
xf_freq: 1.0
xf_offset: 0.0
yu_amp: 1.0
yu_freq: 1.0
yu_offset: 0.0
yf_amp: 1.0
yf_freq: 1.0
yf_offset: 0.0

sample_generation:
maximum_number_of_snapshots: 70000
component_sampling: true
type: random
random_sample_generator:
number_of_samples: 100
file_path:
prefix: "linelast_cwtrain"
parameters:
- key: single_run/linelast_cwtrain/l_ux
type: double
minimum: 0.0
maximum: 10.0
- key: single_run/linelast_cwtrain/l_uy
type: double
minimum: 0.0
maximum: 10.0
- key: single_run/linelast_cwtrain/r_fx
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/r_fy
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/u_fx
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/u_fy
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/d_fx
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/d_fy
type: double
minimum: -20.0
maximum: 20.0
- key: single_run/linelast_cwtrain/rx
type: double
minimum: 0.2
maximum: 1.0
- key: single_run/linelast_cwtrain/ry
type: double
minimum: 0.2
maximum: 1.0
- key: single_run/linelast_cwtrain/lx
type: double
minimum: 0.5
maximum: 1.0
- key: single_run/linelast_cwtrain/ly
type: double
minimum: 0.5
maximum: 1.0
- key: single_run/linelast_cwtrain/dx
type: double
minimum: 0.3
maximum: 1.0
- key: single_run/linelast_cwtrain/dy
type: double
minimum: 0.3
maximum: 1.0
- key: single_run/linelast_cwtrain/ux
type: double
minimum: 0.3
maximum: 1.0
- key: single_run/linelast_cwtrain/uy
type: double
minimum: 0.3
maximum: 1.0
- key: single_run/linelast_cwtrain/xu_offset
type: double
minimum: 0.0
maximum: 1.0
- key: single_run/linelast_cwtrain/yu_offset
type: double
minimum: 0.0
maximum: 1.0
- key: single_run/linelast_cwtrain/xf_offset
type: double
minimum: 0.0
maximum: 1.0
- key: single_run/linelast_cwtrain/yf_offset
type: double
minimum: 0.0
maximum: 1.0
- key: single_run/linelast_cwtrain/xu_amp
type: double
minimum: -10.0
maximum: 10.0
- key: single_run/linelast_cwtrain/yu_amp
type: double
minimum: -10.0
maximum: 10.0
- key: single_run/linelast_cwtrain/xf_amp
type: double
minimum: -10.0
maximum: 10.0
- key: single_run/linelast_cwtrain/yf_amp
type: double
minimum: -10.0
maximum: 10.0
- key: single_run/linelast_cwtrain/xu_freq
type: double
minimum: 0.1
maximum: 1.0
- key: single_run/linelast_cwtrain/yu_freq
type: double
minimum: 0.1
maximum: 1.0
- key: single_run/linelast_cwtrain/xf_freq
type: double
minimum: 0.1
maximum: 1.0
- key: single_run/linelast_cwtrain/yf_freq
type: double
minimum: 0.1
maximum: 1.0

basis:
prefix: "linelast_cwtrain"
number_of_basis: 16
tags:
- name: "joint2D"
number_of_basis: 16
snapshot_format:
minimum: 0
maximum: 3
format: "linelast_cwtrain_sample_joint2D_snapshot%01d"
- name: "rod2D_H"
number_of_basis: 64
snapshot_format:
minimum: 0
maximum: 3
format: "linelast_cwtrain_sample_rod2D_H_snapshot%01d"
- name: "rod2D_V"
number_of_basis: 64
snapshot_format:
minimum: 0
maximum: 3
format: "linelast_cwtrain_sample_rod2D_V_snapshot%01d"
svd:
save_spectrum: true
update_right_sv: false
visualization:
enabled: false

model_reduction:
rom_handler_type: mfem
subdomain_training: universal
linear_solver_type: direct
save_operator:
level: component
prefix: "linelast_cw.rom_elem"
compare_solution:
enabled: true
2 changes: 1 addition & 1 deletion examples/linelast/linelast.lattice.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ visualization:
enabled: false
unified_paraview: true
file_path:
prefix: lattice_output
prefix: paraview_output

parameterized_problem:
name: linelast_disp_lattice
Expand Down
47 changes: 47 additions & 0 deletions include/parameterized_problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,47 @@ extern double rforce_f;
void tip_force(const Vector &x, Vector &u);
}

namespace linelast_cwtrain
{
extern double l_ux;
extern double l_uy;
extern double r_fx;
extern double r_fy;
extern double u_fx;
extern double u_fy;
extern double d_fx;
extern double d_fy;

extern double lx;
extern double ly;
extern double rx;
extern double ry;
extern double dx;
extern double dy;
extern double ux;
extern double uy;

extern double xu_amp;
extern double xu_freq;
extern double xu_offset;
extern double xf_amp;
extern double xf_freq;
extern double xf_offset;
extern double yu_amp;
extern double yu_freq;
extern double yu_offset;
extern double yf_amp;
extern double yf_freq;
extern double yf_offset;

double perturb_func(const double x, const double amp, const double freq, const double offset);
void left_disp(const Vector &x, Vector &u);
void up_disp(const Vector &x, Vector &u);
void down_disp(const Vector &x, Vector &u);
void right_disp(const Vector &x, Vector &u);

}

namespace advdiff_problem
{

Expand Down Expand Up @@ -305,6 +346,12 @@ class AdvDiffFlowPastArray : public StokesFlowPastArray
}
};

class LinElastComponentWiseTrain : public LinElastProblem
{
public:
LinElastComponentWiseTrain();
};

ParameterizedProblem* InitParameterizedProblem();

#endif
Loading

0 comments on commit 8f0e7ec

Please sign in to comment.