SimulationMetaData: use typed float defaults and add typed keyword constructor#188
Open
AhmedSalih3d wants to merge 1 commit into
Open
Conversation
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
SimulationMetaDataare explicitly typed to theFloatTypeparameter to avoid unintended promotion or ambiguity.SimulationMetaData{D,T,...}withRealliterals (e.g.,Float64) while coercing numeric fields to the declaredTto make typed usage ergonomic and safer.Description
OutputEach = FloatType(0.02),CurrentTimeStep/TotalTime/SimulationTime = zero(FloatType), andTimeSteps = FloatType[]insrc/SimulationMetaDataConfiguration.jl.SimulationMetaData{D,T,S,K,B,L}(; kwargs...)that validates allowed keyword names, preserves non-numeric fields, and converts numeric scalar and vector metadata fields toTusingConvertMetaDataFloathelpers.ConvertMetaDataFloatinline helpers to convertRealscalars and vectors into the target floating typeTwhile leaving other values untouched.test/runtests.jl(SimulationMetaData Float32 keyword conversion) that constructSimulationMetaData{2,Float32}fromFloat64literals and assert thatOutputEach,OutputTimes,CurrentTimeStep,TotalTime,SimulationTime,TimeSteps, andΔxuseFloat32.Testing
julia --project=. -e 'using SPHExample; m=SimulationMetaData{2,Float32}(SimulationName="x",SaveLocation=".",OutputEach=0.05,OutputTimes=[0.05,0.1],CurrentTimeStep=0.001,TotalTime=1.0,SimulationTime=2.0,TimeSteps=[0.001,0.002],Δx=0.01); @show typeof(m) typeof(m.OutputEach) typeof(m.OutputTimes) typeof(m.TimeSteps) typeof(m.Δx); m2=SimulationMetaData{2,Float32}(SimulationName="x",SaveLocation=".",OutputTimes=0.2); @show typeof(m2.OutputTimes) typeof(m2.TimeSteps)'which showed the fields were converted toFloat32as expected.julia --project=. -e 'using Pkg; Pkg.test()', which errored in a pre-existingtime steppingtest due toMethodError: no method matching Δt(..., ::SimulationConstants{Float64}, ::SPHKernelInstance{...})before the new metadata tests executed.SimulationMetaData Float32 keyword conversiontotest/runtests.jl; the manual checks above confirm the constructor behavior passes for the exercised cases.Codex Task