Skip to content
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

Download meshes for tutorials #1037

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions docs/download_resources.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@ const directory = joinpath(@__DIR__, "src", "tutorials")
mkpath(directory)

for (file, url) in [
"periodic-rve.msh" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/periodic-rve.msh",
"periodic-rve-coarse.msh" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/periodic-rve-coarse.msh",
"transient_heat.gif" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/transient_heat.gif",
"transient_heat_colorbar.svg" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/transient_heat_colorbar.svg",
"porous_media.gif" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/porous_media.gif",
"porous_media_0p25.inp" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/porous_media_0p25.inp",
"reactive_surface.gif" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/reactive_surface.gif",
"nsdiffeq.gif" => "https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/nsdiffeq.gif",
]
Expand Down
24 changes: 14 additions & 10 deletions docs/src/literate-tutorials/computational_homogenization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#-
#md # !!! tip
#md # This example is also available as a Jupyter notebook:
#md # [`computational_homogenization.ipynb`](@__NBVIEWER_ROOT_URL__/examples/computational_homogenization.ipynb).
#md # [`computational_homogenization.ipynb`](@__NBVIEWER_ROOT_URL__/tutorials/computational_homogenization.ipynb).
#-
#
# ## Introduction
Expand Down Expand Up @@ -197,17 +197,21 @@ using FerriteGmsh
#src notebook: use coarse mesh to decrease build time
#src script: use the fine mesh
#src markdown: use the coarse mesh to decrease build time, but make it look like the fine
#nb ## grid = togrid("periodic-rve.msh")
#nb grid = togrid("periodic-rve-coarse.msh")
#jl ## grid = togrid("periodic-rve-coarse.msh")
#jl grid = togrid("periodic-rve.msh")
#md grid = togrid("periodic-rve.msh")
#-
import Downloads #hide
meshfile = "periodic-rve.msh" #src
#jl meshfile = "periodic-rve.msh"
#md meshfile = "periodic-rve-coarse.msh" #hide
#nb meshfile = "periodic-rve-coarse.msh"
isfile(meshfile) || Downloads.download( #hide
string("https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/", meshfile), #hide
meshfile) #hide
grid = togrid(meshfile) #src
#nb grid = togrid(meshfile)
Comment on lines +201 to +210
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be easier to add docs for the download file (i.e. docs/download_resources) instead of moving the download logic into the tutorial files? I think having a central point where the external resources are defined for the download is easier to maintain in the long run than splitting it apart like this,.

Copy link
Member Author

@KnutAM KnutAM Aug 2, 2024

Choose a reason for hiding this comment

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

I was thinking about it, but for a user who copies the tutorial, it is nice to be able to copy the code and run directly I suppose?

Or did you mean to include via literate, so that the shown case (in cases we actually show the downloads in the docs) will include (part of) the code in docs/download_resources? (ref)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think having a central point where the external resources are defined for the download is easier to maintain in the long run than splitting it apart like this,.

These are tutorials that should be able to be runnable by someone reading them so whatever is done it should be visible from the source code itself.

Copy link
Member Author

@KnutAM KnutAM Aug 2, 2024

Choose a reason for hiding this comment

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

One solution would be to add a non-exported function

asset_url(file) = string("https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/", file)

to Ferrite itself, which would at least allow using

isfile(meshfile) || Downloads.download(Ferrite.asset_url(meshfile), meshfile)

above, which looks prettier at least, and would allow changing the location of the assets easily in the future. But feels ugly to add such things to the base package?

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, this is only used in two places, so I suggest to do it this "distributed" way for now, to solve #1033. Would be great with a nice solution including a "central point" in the future though.

#md grid = redirect_stdout(devnull) do #hide
#md togrid("periodic-rve-coarse.msh") #hide
#md end #hide

grid = togrid("periodic-rve.msh") #src
#md togrid(meshfile) #hide
#md end #hide
#md grid

# Next we construct the interpolation and quadrature rule, and combining them into
# cellvalues as usual:
Expand Down
10 changes: 8 additions & 2 deletions docs/src/literate-tutorials/porous_media.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
#md # the final [section](@ref porous-media-plain-program)
#
# Required packages
using Ferrite, FerriteMeshParser, Tensors
using Ferrite, FerriteMeshParser, Tensors, Downloads

# ### Elasticity
# We start by defining the elastic material type, containing the elastic stiffness,
Expand Down Expand Up @@ -249,8 +249,14 @@ end;
# `get_ferrite_grid` function. We then create one cellset for each phase (solid and porous)
# for each element type. These 4 sets will later be used in their own `SubDofHandler`
function get_grid()
## Try downloading the grid if not available already
gridfile = "porous_media_0p25.inp"
isfile(gridfile) || Downloads.download(
string("https://raw.githubusercontent.com/Ferrite-FEM/Ferrite.jl/gh-pages/assets/", gridfile),
gridfile)

## Import grid from abaqus mesh
grid = get_ferrite_grid(joinpath(@__DIR__, "porous_media_0p25.inp"))
grid = get_ferrite_grid(gridfile)

## Create cellsets for each fieldhandler
addcellset!(grid, "solid3", intersect(getcellset(grid, "solid"), getcellset(grid, "CPS3")))
Expand Down
7 changes: 3 additions & 4 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ end
# end

module TestComputationalHomogenization
include(joinpath(@__DIR__, "../docs/download_resources.jl"))
mktempdir() do dir
cd(dir) do
cp(joinpath(@__DIR__, "../docs/src/tutorials/periodic-rve.msh"),
joinpath(dir, "periodic-rve.msh")
)
# Add already downloaded file to allow running test suite offline
mesh_file = joinpath(@__DIR__, "../docs/src/tutorials/periodic-rve.msh")
isfile(mesh_file) && cp(mesh_file, joinpath(dir, basename(mesh_file)))
include(joinpath(@__DIR__, "../docs/src/literate-tutorials/computational_homogenization.jl"))
end
end
Expand Down