-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from j-fu/state-example
Example for using multiple states of a system in parallel
- Loading branch information
Showing
9 changed files
with
99 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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,58 @@ | ||
#= | ||
# 440: Parallel solves | ||
([source code](@__SOURCE_URL__)) | ||
Demonstrate how to solve one system with different data in parallel using the SystemState (new in v2.0). | ||
=# | ||
|
||
module Example440_ParallelState | ||
|
||
|
||
using VoronoiFVM, ExtendableGrids | ||
using GridVisualize | ||
using ChunkSplitters | ||
|
||
function flux(y,u,node,data) | ||
y[1]=u[1,1]^2-u[1,2]^2 | ||
end | ||
|
||
function bcondition(y,u,node,data) | ||
boundary_dirichlet!(y,u,node, species=1, region=1, value=0.1) | ||
boundary_neumann!(y,u,node,species=1,region=2,value=data.influx) | ||
end | ||
|
||
function main(;nref=5, Plotter=nothing) | ||
grid=simplexgrid(range(0,1,length=10*2^nref+1)) | ||
sys=VoronoiFVM.System(grid;flux,bcondition, species=[1], data=(influx=0.0,)) | ||
|
||
## Initial state. First solution creates the matrix | ||
state0=VoronoiFVM.SystemState(sys) | ||
sol=solve!(state0;inival=0.1) | ||
|
||
## Prepare parameter and result data | ||
influxes=range(0.0,10.0, length=100) | ||
masses=similar(influxes) | ||
|
||
## Split the index range in as many chunks as threads | ||
Threads.@threads for indexes in chunks(influxes;n=Threads.nthreads()) | ||
## Create a new state sharing the system - one for each chunk | ||
state=similar(state0) | ||
## Solve for all data values in chunk | ||
for iflux in indexes | ||
data=(influx=influxes[iflux],) | ||
sol=solve!(state;data, inival=0.1, verbose="") | ||
masses[iflux]=integrate(sys,sol)[1,1] | ||
end | ||
end | ||
scalarplot(influxes, masses;Plotter, xlabel="influx", ylabel="mass") | ||
sum(masses) | ||
end | ||
|
||
using Test | ||
function runtests() | ||
testval=140.79872772042577 | ||
@test main() ≈ testval | ||
end | ||
|
||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
dae2c6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
dae2c6b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/115396
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: