Input data for main simulation with ParallelStencil.jl


I have a question regarding the use of ParallelStencil.jl. I would like to initialize a simulation or load a previous solution and assign these input fields like temperature or so to the ParallelStencil Arrays before solving further in time.

Once the fields are correctly, loaded, I would like to move to the time loop where I don’t intend to have any input only an output for saving the solution.

Below is a small script that shows what I’m trying to do. This works fine with USE_GPU = false (i.e. cpu) but doesn’t work with USE_GPU = true.

How can I load fields into the main simulation loop from outside?

Thank you very much in advance and best regards,

const USE_GPU = true
using ParallelStencil
using ParallelStencil.FiniteDifferences2D
@static if USE_GPU
    @init_parallel_stencil(CUDA, Float64, 2)
    @init_parallel_stencil(Threads, Float64, 2)

using Plots, Printf, Statistics, LinearAlgebra

function simulation(input_data, nx, ny)
    # initialize simulation with input data
    T = @zeros(nx, ny)
    T .= input_data
    # time loop 
    print("I reached the time loop")

function load_old_data(filename)
    # load data

    # for simplicity, just created an array to return
    input_data = zeros(10, 10)
    return input_data

filename = "..."
input_data = load_old_data(filename)
simulation(input_data, size(input_data, 1), size(input_data, 2))

Can you try something like

# initialize simulation with input data
T .= Data.Array(input_data)

Thank you very much for the fast reply! That answered my question :slight_smile:

1 Like

My pleasure !

I hope that we can publish soon a simple 3D wave simulation package based on ParallelStencil.jl and ImplicitGlobalGrid.jl.
I think that it adds some pedagogical value to the docs of the PS.jl and IGG.jl showing how to use them in a more practical context (like your original question).