440: Parallel solves

(source code)

Demonstrate how to solve one system with different data in parallel using the SystemState (new in v2.0).

module Example440_ParallelStateusing VoronoiFVM, ExtendableGridsusing GridVisualizeusing ChunkSplittersfunction flux(y, u, node, data)    y[1] = u[1, 1]^2 - u[1, 2]^2    return nothingendfunction 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)    return nothingendfunction 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,))    # 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(1:length(influxes); n = Threads.nthreads())        # Create a new state sharing the system - one for each chunk        state = VoronoiFVM.SystemState(sys)        # Solve for all data values in chunk        for iflux in indexes            data = (influx = influxes[iflux],)            sol = solve!(state; data, inival = 0.1, verbose = "", abstol = 1.0e-15, reltol = 1.0e-20)            masses[iflux] = integrate(sys, sol; data)[1, 1]        end    end    scalarplot(influxes, masses; Plotter, xlabel = "influx", ylabel = "mass")    return sum(masses)endusing Testfunction runtests()    testval = 140.79872772042577    @test main() ≈ testval    return nothingendend

This page was generated using Literate.jl.