-
Notifications
You must be signed in to change notification settings - Fork 49
adding fiber generation codes #480
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
javijv4
wants to merge
20
commits into
SimVascular:main
Choose a base branch
from
javijv4:dev_#479
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b010f79
adding fiber generation codes
javijv4 c36a6b8
increasing linear solver max iterations
javijv4 c401a9a
changing paths and README.md
javijv4 f15a136
adding .pngs for fiber, sheet, sheetnormal directions
javijv4 6fd7d15
updating README.md
javijv4 6941248
Merge branch 'main' into dev_#479
aabrown100-git 63d5e7c
Merge branch 'main' into dev_#479
javijv4 b5dde5c
object oriented implementation; updated documentation; added validation
javijv4 f86777e
updating surfaces names;
javijv4 fc2a7fd
Merge branch 'main' into dev_#479
aabrown100-git 065cd44
changing svfsi to svmultiphysics
javijv4 1380666
setting coherent convention; fixing vectorized rodrigues
javijv4 ff5ae3f
cleaning up and updating paraview files
javijv4 9f19ff2
changing names of example folders; modifying Doste to assign 2/3 of t…
javijv4 aeacf6c
Merge branch 'main' into dev_#479
aabrown100-git a71e017
package is working; renaming scripts
javijv4 bdf7183
moving rescaling outside gradient function
javijv4 d9aa81c
forcing paraview to use white background
javijv4 fe67a44
accidentally deleted paraview scripts are back
javijv4 c6d5405
adding license
javijv4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # SV-fibergen | ||
| Python + SVmultiphysics codes for fiber generation. Two methods are implemented: | ||
| * Bayer et al. (2012). [link](https://doi.org/10.1007/s10439-012-0593-5) | ||
aabrown100-git marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * Doste et al. (2018). [link](https://doi.org/10.1002/cnm.3185) | ||
|
|
||
| ### Examples | ||
| The `main_bayer.py` and `main_doste.py` are scripts to run both methods in the geometry described in the `example/truncated` and `example/ot` folders respectively. | ||
|
|
||
| <img src="example/truncated/bayer.png" alt="Results for truncated BiV (Bayer)" width="640" /> | ||
| <img src="example/ot/doste.png" alt="Results for BiV w/ outflow tracts (Doste)" width="640" /> | ||
|
|
||
| Note that the Doste methods needs a geometry with outflow tracts to be run (each valve needs to be defined as a separated surface). Bayer can be run in any biventricular geometry. | ||
|
|
||
|
|
||
| ### Updates to the old code | ||
| * All operations are vectorized now. | ||
| * The SVmultiphysics solver now solves a Laplace equation. | ||
javijv4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
javijv4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * In Bayer: For the bislerp interpolation, instead of using the correction described in Bayer et al. (that returns a discontinuity), the basis are flipped to maintain a coherent fiber direction (see function `generate_fibers_BiV_Bayer_cells` in `FibGen.py`). | ||
aabrown100-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * In Bayer: The beta angles were not being included correctly. The second rotation was being applied respect the first vector (circumferential) when it should be respect to the second vector (longitudinal) (see function `generate_fibers_BiV_Bayer_cells` in `FibGen.py`). | ||
aabrown100-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Notes on SVmultiphysics solver | ||
|
|
||
| To solve a Laplace equation directly from the transient HEAT solver in SVmultiphysics, in `<GeneralSimulationParameters>` we need to set, | ||
| ``` | ||
| <Number_of_time_steps> 1 </Number_of_time_steps> | ||
| <Time_step_size> 1 </Time_step_size> | ||
| <Spectral_radius_of_infinite_time_step> 0. </Spectral_radius_of_infinite_time_step> | ||
| ``` | ||
| and in `<Add_equation type="heatS" >`, | ||
| ``` | ||
| <Conductivity> 1.0 </Conductivity> | ||
| <Source_term> 0.0 </Source_term> | ||
| <Density> 0.0 </Density> | ||
| ``` | ||
| This will allow us to solve the Laplace equation directly in 1 timestep and 1 iteration. | ||
aabrown100-git marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/ot/mesh-surfaces/EPI_APEX.vtp
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/ot/mesh-surfaces/endo_lv.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/ot/mesh-surfaces/endo_rv.vtp
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/BASE.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/EPI.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/EPI_APEX.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/EPI_APEX2.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/EPI_MID.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/LV.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/RV.vtp
Git LFS file not shown
3 changes: 3 additions & 0 deletions
3
utilities/fiber_generation/example/truncated/mesh-surfaces/exterior.vtp
Git LFS file not shown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| #!/usr/bin/env python | ||
| # -*-coding:utf-8 -*- | ||
| ''' | ||
| Created on 2025/11/21 20:38:14 | ||
|
|
||
| @author: Javiera Jilberto Vallejos | ||
| ''' | ||
javijv4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import os | ||
| import src.FibGen as fg | ||
| from time import time | ||
|
|
||
| ########################################################### | ||
| ############ USER INPUTS ################################ | ||
| ########################################################### | ||
|
|
||
| run_flag = True | ||
| svfsi_exec = "svmultiphysics " | ||
|
|
||
| mesh_path = "example/truncated/VOLUME.vtu" | ||
| surfaces_dir = f"example/truncated/mesh-surfaces" | ||
| outdir = "example/truncated/output_b" | ||
|
|
||
| surface_names = {'epi': 'EPI.vtp', | ||
| 'epi_apex': 'EPI_APEX.vtp', # New surface | ||
| 'base': 'BASE.vtp', | ||
| 'endo_lv': 'LV.vtp', | ||
| 'endo_rv': 'RV.vtp'} | ||
|
|
||
| # Parameters for the Bayer et al. method https://doi.org/10.1007/s10439-012-0593-5. | ||
| params = { | ||
| "ALFA_END": 60.0, | ||
| "ALFA_EPI": -60.0, | ||
| "BETA_END": 20.0, | ||
| "BETA_EPI": -20.0, | ||
| } | ||
|
|
||
|
|
||
| ########################################################### | ||
| ############ FIBER GENERATION ########################### | ||
| ########################################################### | ||
|
|
||
| # Make sure the paths are full paths | ||
| mesh_path = os.path.abspath(mesh_path) | ||
| surfaces_dir = os.path.abspath(surfaces_dir) | ||
| outdir = os.path.abspath(outdir) | ||
|
|
||
| start = time() | ||
| fg.generate_epi_apex(mesh_path, surfaces_dir, surface_names) | ||
|
|
||
| # Run the Laplace solver | ||
| if run_flag: | ||
| template_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src", "templates", "solver_bayer.xml") | ||
| laplace_results_file = fg.runLaplaceSolver(mesh_path, surfaces_dir, mesh_path, svfsi_exec, template_file, outdir, surface_names) | ||
| laplace_results_file = outdir + '/result_001.vtu' | ||
|
|
||
| # Generate the fiber directions | ||
| result_mesh = fg.generate_fibers_BiV_Bayer_cells(outdir, laplace_results_file, params, return_angles=True, return_intermediate=True) | ||
|
|
||
| print(f"generate fibers (Bayer method) elapsed time: {time() - start:.3f} s") | ||
|
|
||
| # Optional, save the result mesh with intermediate field and angles for checking | ||
| result_mesh_path = os.path.join(outdir, "results_bayer.vtu") | ||
| result_mesh.save(result_mesh_path) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| #!/usr/bin/env python | ||
| # -*-coding:utf-8 -*- | ||
| ''' | ||
| Created on 2025/11/21 20:38:14 | ||
|
|
||
| @author: Javiera Jilberto Vallejos | ||
| ''' | ||
javijv4 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| import os | ||
| import src.FibGen as fg | ||
| from time import time | ||
|
|
||
| ########################################################### | ||
| ############ USER INPUTS ################################ | ||
| ########################################################### | ||
|
|
||
| run_flag = True | ||
| method = 'doste' | ||
| svfsi_exec = "svmultiphysics " | ||
|
|
||
| mesh_path = "example/ot/mesh-complete.mesh.vtu" | ||
| surfaces_dir = f"example/ot/mesh-surfaces" | ||
| outdir = "example/ot/output_d" | ||
|
|
||
| surface_names = {'epi': 'epi.vtp', | ||
| 'epi_apex': 'epi_apex.vtp', # New surface | ||
| 'av': 'av.vtp', | ||
| 'mv': 'mv.vtp', | ||
| 'tv': 'tv.vtp', | ||
| 'pv': 'pv.vtp', | ||
| 'base': 'top.vtp', # This is all the valves together, it is used to find the apex. | ||
| 'endo_lv': 'endo_lv.vtp', | ||
| 'endo_rv': 'endo_rv.vtp'} | ||
|
|
||
| # Parameters from the Doste paper https://doi.org/10.1002/cnm.3185 | ||
| params = { | ||
| # A = alpha angle | ||
| 'AENDORV' : 90, | ||
| 'AEPIRV' : -25, | ||
| 'AENDOLV' : 60, | ||
| 'AEPILV' : -60, | ||
|
|
||
| 'AOTENDOLV' : 90, | ||
| 'AOTENDORV' : 90, | ||
| 'AOTEPILV' : 0, | ||
| 'AOTEPIRV' : 0, | ||
|
|
||
| # B = beta angle (this have an opposite sign to the Doste paper, | ||
| # but it's because the longitudinal direction is opposite) | ||
| 'BENDORV' : 20, | ||
| 'BEPIRV' : -20, | ||
| 'BENDOLV' : 20, | ||
| 'BEPILV' : -20, | ||
| } | ||
|
|
||
|
|
||
| ########################################################### | ||
| ############ FIBER GENERATION ########################### | ||
| ########################################################### | ||
|
|
||
| # Make sure the paths are full paths | ||
| mesh_path = os.path.abspath(mesh_path) | ||
| surfaces_dir = os.path.abspath(surfaces_dir) | ||
| outdir = os.path.abspath(outdir) | ||
|
|
||
| # Generate the apex surface | ||
| start = time() | ||
|
|
||
| start = time() | ||
| fg.generate_epi_apex(mesh_path, surfaces_dir, surface_names) | ||
|
|
||
| # Run the Laplace solver | ||
| if run_flag: | ||
| template_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), "src", "templates", "solver_doste.xml") | ||
| laplace_results_file = fg.runLaplaceSolver(mesh_path, surfaces_dir, mesh_path, svfsi_exec, template_file, outdir, surface_names) | ||
| laplace_results_file = outdir + '/result_001.vtu' | ||
|
|
||
| # Generate the fiber directions | ||
| result_mesh = fg.generate_fibers_BiV_Doste_cells(outdir, laplace_results_file, params, return_angles=True, return_intermediate=False) | ||
|
|
||
| print(f"generate fibers (Doste method) elapsed time: {time() - start:.3f} s") | ||
|
|
||
| # Optional, save the result mesh with intermediate field and angles for checking | ||
| result_mesh_path = os.path.join(outdir, "results_doste.vtu") | ||
| result_mesh.save(result_mesh_path) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.