Skip to content

SimulationMetaData: use typed float defaults and add typed keyword constructor#188

Open
AhmedSalih3d wants to merge 1 commit into
BeforeLidDrivenCavityExamplefrom
codex/update-simulationmetadataconfiguration.jl
Open

SimulationMetaData: use typed float defaults and add typed keyword constructor#188
AhmedSalih3d wants to merge 1 commit into
BeforeLidDrivenCavityExamplefrom
codex/update-simulationmetadataconfiguration.jl

Conversation

@AhmedSalih3d

Copy link
Copy Markdown
Owner

Motivation

  • Ensure float-like defaults in SimulationMetaData are explicitly typed to the FloatType parameter to avoid unintended promotion or ambiguity.
  • Allow users to construct SimulationMetaData{D,T,...} with Real literals (e.g., Float64) while coercing numeric fields to the declared T to make typed usage ergonomic and safer.

Description

  • Replace float-like default literals with typed forms: OutputEach = FloatType(0.02), CurrentTimeStep/TotalTime/SimulationTime = zero(FloatType), and TimeSteps = FloatType[] in src/SimulationMetaDataConfiguration.jl.
  • Add an outer keyword constructor 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 to T using ConvertMetaDataFloat helpers.
  • Provide ConvertMetaDataFloat inline helpers to convert Real scalars and vectors into the target floating type T while leaving other values untouched.
  • Add tests in test/runtests.jl (SimulationMetaData Float32 keyword conversion) that construct SimulationMetaData{2,Float32} from Float64 literals and assert that OutputEach, OutputTimes, CurrentTimeStep, TotalTime, SimulationTime, TimeSteps, and Δx use Float32.

Testing

  • Ran a quick runtime check with 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 to Float32 as expected.
  • Ran the full test suite with julia --project=. -e 'using Pkg; Pkg.test()', which errored in a pre-existing time stepping test due to MethodError: no method matching Δt(..., ::SimulationConstants{Float64}, ::SPHKernelInstance{...}) before the new metadata tests executed.
  • Added the unit test SimulationMetaData Float32 keyword conversion to test/runtests.jl; the manual checks above confirm the constructor behavior passes for the exercised cases.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant