Skip to content

Conversation

@jleonqu
Copy link
Contributor

@jleonqu jleonqu commented May 14, 2025

This PR updates the random number generation in setWavePhase in the waveClass to use RandStream with Substream, instead of rng(phaseSeed). The change ensures deterministic and reproducible wave elevation profiles across both serial (wecSim) and parallel (wecSimPCT) simulations when phaseSeed is specified. This resolves the issue where parallel runs with the same seed could produce different results due to independent worker streams (see Issue #1329 ). The new approach uses the Threefry generator, which supports substreams and is recommended by MathWorks for parallel reproducibility.

This PR can be tested using the MCR example available here: WEC-Sim_Applications/Multiple_Condition_Runs/RM3_MCROPT3 running the attached script.
irregularWaveGenerationExample.zip

The wave profiles generated with wecSim and wecSimPCT should be identical when using the same seed value.

…ve spectrum is generated for all the parallel workers when using wecSimPCT
@jleonqu jleonqu requested a review from kmruehl May 14, 2025 20:02
@jleonqu jleonqu added the Bug bug in WEC-Sim source, high priority label May 14, 2025
@kmruehl kmruehl self-assigned this May 14, 2025
@kmruehl kmruehl added the Wave Class Wave Classs (waveClass.m) label May 14, 2025
@jleonqu jleonqu changed the title Fix wave generation with phaseSeed in waveClass to ensure the same wa… Fix wave generation with phaseSeed in waveClass for PCT May 15, 2025
@kmruehl
Copy link
Collaborator

kmruehl commented May 15, 2025

This is great! Thank you @jleonqu!

I also added another PCT run for the same case and confirmed that both wecSimPCT seeds match the wecSim seed.

@kmruehl kmruehl merged commit ed295fc into WEC-Sim:main May 15, 2025
10 checks passed
@kmruehl kmruehl added the MCR/PCT multiple condition runs (wecSimMCR) and/or parallel computing toolbox (wecSimPCT) label May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug bug in WEC-Sim source, high priority MCR/PCT multiple condition runs (wecSimMCR) and/or parallel computing toolbox (wecSimPCT) Wave Class Wave Classs (waveClass.m)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants