-
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.
Example for using multiple states of a system in parallel
- Loading branch information
Showing
8 changed files
with
95 additions
and
6 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,57 @@ | ||
#= | ||
# 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