diff --git a/docs/src/Internal.md b/docs/src/Internal.md index 0ab708f..4565ada 100644 --- a/docs/src/Internal.md +++ b/docs/src/Internal.md @@ -70,7 +70,7 @@ CurrentModule = Modia ``` ```@docs -SimulationModel +InstantiatedModel generate_getDerivatives! init! outputs! diff --git a/docs/src/index.md b/docs/src/index.md index 84548cc..705e3e1 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -471,7 +471,7 @@ Bug fixes - @reexport using Unitful - @reexport using DifferentialEquations - Cleanup of test files (besides ModiaLang, no other package needed in the environment to run the tests). -- Change `SimulationModel{FloatType,ParType,EvaluatedParType,TimeType}` to `SimulationModel{FloatType,TimeType}` +- Change `InstantiatedModel{FloatType,ParType,EvaluatedParType,TimeType}` to `InstantiatedModel{FloatType,TimeType}` #### Version 0.9.1 diff --git a/docs/src/tutorial/Modeling.md b/docs/src/tutorial/Modeling.md index 2ef549a..62bc0b4 100644 --- a/docs/src/tutorial/Modeling.md +++ b/docs/src/tutorial/Modeling.md @@ -528,7 +528,7 @@ testArray1 = @instantiateModel(TestArray1, logCode=true) Note, the generated code is shown in the REPL if `logCode=true` is defined: ```julia -function getDerivatives(_x, _m::Modia.SimulationModel{_FloatType,_TimeType} ... +function getDerivatives(_x, _m::Modia.InstantiatedModel{_FloatType,_TimeType} ... ... v::ModiaBase.SVector{3,_FloatType} = ModiaBase.SVector{3,_FloatType}(_x[1:3]) var"der(v)" = -v diff --git a/docs/src/tutorial/Simulation.md b/docs/src/tutorial/Simulation.md index b1896e8..42bd93d 100644 --- a/docs/src/tutorial/Simulation.md +++ b/docs/src/tutorial/Simulation.md @@ -24,7 +24,7 @@ modelInstance = @instantiateModel(model; FloatType = Float64, aliasReduction=tru The macro performs structural and symbolic transformations, generates a function for calculation of derivatives suitable for use with [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl) -and returns [`SimulationModel`](@ref) that can be used in other functions, +and returns [`InstantiatedModel`](@ref) that can be used in other functions, for example to simulate or plot results. Explanation of the arguments: * `model`: model (declarations and equations) diff --git a/examples/Pendulum.jl b/examples/Pendulum.jl index e0c6197..72a1841 100644 --- a/examples/Pendulum.jl +++ b/examples/Pendulum.jl @@ -41,7 +41,7 @@ println("\n... Numerically linearize at stopTime = 10 with Float64 and Double64: #= DoubleFloats is not necessarily defined in the environment using Modia.DoubleFloats -pendulum3 = SimulationModel{Measurement{Double64}}(pendulum2) +pendulum3 = InstantiatedModel{Measurement{Double64}}(pendulum2) (A_10_Double64, x_10_Double64) = linearize!(pendulum3, stopTime=10) =# diff --git a/models/HeatTransfer/InsulatedRod2.jl b/models/HeatTransfer/InsulatedRod2.jl index e9007fa..796b5e1 100644 --- a/models/HeatTransfer/InsulatedRod2.jl +++ b/models/HeatTransfer/InsulatedRod2.jl @@ -84,7 +84,7 @@ end # Called once before initialization of a new simulation segment -function initSegment_InsulatedRod2!(instantiatedModel::SimulationModel{FloatType,TimeType}, path::String, ID, +function initSegment_InsulatedRod2!(instantiatedModel::InstantiatedModel{FloatType,TimeType}, path::String, ID, parameters::AbstractDict; log=false)::Nothing where {FloatType,TimeType} obj::InsulatedRodStruct{FloatType} = Modia.get_instantiatedSubmodel(instantiatedModel, ID) @@ -99,7 +99,7 @@ end # Open an initialized InsulatedRod2 model and return a reference to it -function openInsulatedRod!(instantiatedModel::SimulationModel{FloatType,TimeType}, ID)::InsulatedRodStruct{FloatType} where {FloatType,TimeType} +function openInsulatedRod!(instantiatedModel::InstantiatedModel{FloatType,TimeType}, ID)::InsulatedRodStruct{FloatType} where {FloatType,TimeType} obj::InsulatedRodStruct{FloatType} = Modia.get_instantiatedSubmodel(instantiatedModel, ID) Modia.copy_Vector_x_segmented_value_from_state(instantiatedModel, obj.T_startIndex, obj.T) return obj diff --git a/src/CodeGeneration.jl b/src/CodeGeneration.jl index e7016c0..52a1d99 100644 --- a/src/CodeGeneration.jl +++ b/src/CodeGeneration.jl @@ -249,7 +249,7 @@ end """ - simulationModel = SimulationModel{FloatType,TimeType}( + simulationModel = InstantiatedModel{FloatType,TimeType}( modelModule, modelName, getDerivatives!, equationInfo, x_startValues, parameters, timeName, w_invariant_names; vSolvedWithInitValuesAndUnit::OrderedDict{String,Any}(), @@ -271,7 +271,7 @@ end - `timeName`: Name of time (as Symbol) - `w_invariant_names`: A vector of variable names (as vector of symbols or Expr) """ -mutable struct SimulationModel{FloatType,TimeType} +mutable struct InstantiatedModel{FloatType,TimeType} # Available before propagateEvaluateAndInstantiate!(..) called (= partiallyInstantedModel) modelModule::Module modelName::String @@ -327,7 +327,7 @@ mutable struct SimulationModel{FloatType,TimeType} var_name::Function result::Union{Result,Missing} # Result data structure upto current time instant - parameters::OrderedDict{Symbol,Any} # Parameters as provided to SimulationModel constructor + parameters::OrderedDict{Symbol,Any} # Parameters as provided to InstantiatedModelconstructor equationInfo::Modia.EquationInfo # Invariant part of equations are available x_terminate::Vector{FloatType} # States x used at the last terminate!(..) call or [], if terminate!(..) not yet called. @@ -358,7 +358,7 @@ mutable struct SimulationModel{FloatType,TimeType} der_x::Vector{FloatType} # Derivatives of states x - function SimulationModel{FloatType,TimeType}(modelModule, modelName, buildDict, getDerivatives!, equationInfo, + function InstantiatedModel{FloatType,TimeType}(modelModule, modelName, buildDict, getDerivatives!, equationInfo, previousVars, preVars, holdVars, parameterDefinition, timeName, w_invariant_names, hideResult_names; unitless::Bool=true, @@ -428,7 +428,7 @@ mutable struct SimulationModel{FloatType,TimeType} end #= - function SimulationModel{FloatType,TimeType}(m::SimulationModel) where {FloatType,TimeType} + function InstantiatedModel{FloatType,TimeType}(m::InstantiatedModel) where {FloatType,TimeType} # Construct data structure for linear equations linearEquations = Modia.LinearEquations{FloatType}[] for leq in m.equationInfo.linearEquations @@ -483,26 +483,26 @@ end # Default constructors -SimulationModel{FloatType}(args...; kwargs...) where {FloatType} = SimulationModel{FloatType,FloatType}(args...; kwargs...) +InstantiatedModel{FloatType}(args...; kwargs...) where {FloatType} = InstantiatedModel{FloatType,FloatType}(args...; kwargs...) -SimulationModel{Measurements.Measurement{T},}(args...; kwargs...) where {T} = SimulationModel{Measurements.Measurement{T},T}(args...; kwargs...) -SimulationModel{MonteCarloMeasurements.Particles{T,N}}(args...; kwargs...) where {T,N,} = SimulationModel{MonteCarloMeasurements.Particles{T,N},T}(args...; kwargs...) -SimulationModel{MonteCarloMeasurements.StaticParticles{T,N}}(args...; kwargs...) where {T,N} = SimulationModel{MonteCarloMeasurements.StaticParticles{T,N},T}(args...; kwargs...) +InstantiatedModel{Measurements.Measurement{T},}(args...; kwargs...) where {T} = InstantiatedModel{Measurements.Measurement{T},T}(args...; kwargs...) +InstantiatedModel{MonteCarloMeasurements.Particles{T,N}}(args...; kwargs...) where {T,N,} = InstantiatedModel{MonteCarloMeasurements.Particles{T,N},T}(args...; kwargs...) +InstantiatedModel{MonteCarloMeasurements.StaticParticles{T,N}}(args...; kwargs...) where {T,N} = InstantiatedModel{MonteCarloMeasurements.StaticParticles{T,N},T}(args...; kwargs...) -timeType(m::SimulationModel{FloatType,TimeType}) where {FloatType,TimeType} = TimeType +timeType(m::InstantiatedModel{FloatType,TimeType}) where {FloatType,TimeType} = TimeType # The following rule is important for DiffEqBase version 6.91.6 and later # (https://github.com/SciML/DiffEqBase.jl/issues/791) if Base.isdefined(DiffEqBase, :anyeltypedual) - DiffEqBase.anyeltypedual(::SimulationModel) = Any + DiffEqBase.anyeltypedual(::InstantiatedModel) = Any end -positive(m::SimulationModel, args...; kwargs...) = Modia.positive!(m.eventHandler, args...; kwargs...) -negative(m::SimulationModel, args...; kwargs...) = Modia.negative!(m.eventHandler, args...; kwargs...) -change( m::SimulationModel, args...; kwargs...) = Modia.change!( m.eventHandler, args...; kwargs...) -edge( m::SimulationModel, args...; kwargs...) = Modia.edge!( m.eventHandler, args...; kwargs...) -after( m::SimulationModel, args...; kwargs...) = Modia.after!( m.eventHandler, args...; kwargs...) -pre( m::SimulationModel, i) = m.pre[i] +positive(m::InstantiatedModel, args...; kwargs...) = Modia.positive!(m.eventHandler, args...; kwargs...) +negative(m::InstantiatedModel, args...; kwargs...) = Modia.negative!(m.eventHandler, args...; kwargs...) +change( m::InstantiatedModel, args...; kwargs...) = Modia.change!( m.eventHandler, args...; kwargs...) +edge( m::InstantiatedModel, args...; kwargs...) = Modia.edge!( m.eventHandler, args...; kwargs...) +after( m::InstantiatedModel, args...; kwargs...) = Modia.after!( m.eventHandler, args...; kwargs...) +pre( m::InstantiatedModel, i) = m.pre[i] """ @@ -524,7 +524,7 @@ With reinit, instantiatedModel.eventHandler.newEventIteration = true is set, to event iteration. At the next event iteration, the new value v_new is copied from _x and therefore has then an effect. """ -function reinit(m::SimulationModel, x, j, v_new, leqMode; v_threshold=0.01) +function reinit(m::InstantiatedModel, x, j, v_new, leqMode; v_threshold=0.01) if leqMode >= 0 error("reinit(..) of model ", m.modelName, " is called when solving a linear equation system (this is not supported)") elseif !isEvent(m) @@ -553,12 +553,12 @@ end """ - floatType = getFloatType(simulationModel::SimulationModel) + floatType = getFloatType(simulationModel::InstantiatedModel) Return the floating point type with which `simulationModel` is parameterized (for example returns: `Float64, Float32, DoubleFloat, Measurements.Measurement{Float64}`). """ -getFloatType(m::SimulationModel{FloatType,TimeType}) where {FloatType,TimeType} = FloatType +getFloatType(m::InstantiatedModel{FloatType,TimeType}) where {FloatType,TimeType} = FloatType """ @@ -652,7 +652,7 @@ end """ - getLastValue(model::SimulationModel, name::String; unit=true) + getLastValue(model::InstantiatedModel, name::String; unit=true) Return the last stored value of variable `name` from `model`. If `unit=true` return the value with its unit, otherwise with stripped unit. @@ -662,7 +662,7 @@ and the function returns `nothing`. `name` can be a time-varying variable or a parameter. """ -function getLastValue(m::SimulationModel{FloatType,TimeType}, name::String; unit::Bool=true) where {FloatType,TimeType} +function getLastValue(m::InstantiatedModel{FloatType,TimeType}, name::String; unit::Bool=true) where {FloatType,TimeType} if isnothing(m) || ismissing(m.result) @info "getLastValue(model,\"$name\"): No results yet available." return nothing @@ -763,7 +763,7 @@ get_lastValue(m, name; unit=true) = getLastValue(m, name, unit=unit) Return the dictionary, in which extra keyword arguments of the last `simulate!(instantiatedModel,...)` call are stored. """ -get_extraSimulateKeywordArgumentsDict(m::SimulationModel) = m.options.extra_kwargs +get_extraSimulateKeywordArgumentsDict(m::InstantiatedModel) = m.options.extra_kwargs @@ -798,7 +798,7 @@ Note This flag is true during the first iteration directly at the time event after initialization (at simulation startTime). """ -function terminateEventIteration!(m::SimulationModel)::Bool +function terminateEventIteration!(m::InstantiatedModel)::Bool h = m.eventHandler h.firstInitialOfAllSegments = false h.firstEventIteration = false @@ -839,7 +839,7 @@ function terminateEventIteration!(m::SimulationModel)::Bool end -function eventIteration!(m::SimulationModel, x, t_event)::Nothing +function eventIteration!(m::InstantiatedModel, x, t_event)::Nothing eh = m.eventHandler # Initialize event iteration @@ -879,7 +879,7 @@ end Return the names of the elements of the x-vector in a Vector{String}. """ -get_xNames(m::SimulationModel) = Modia.get_xNames(m.equationInfo) +get_xNames(m::InstantiatedModel) = Modia.get_xNames(m.equationInfo) """ @@ -888,8 +888,8 @@ get_xNames(m::SimulationModel) = Modia.get_xNames(m.equationInfo) Return true, if **initialization phase** of simulation (of the current segment of a segmented simulation). """ -isInitial(m::SimulationModel) = m.eventHandler.initial -initial( m::SimulationModel) = m.eventHandler.initial +isInitial(m::InstantiatedModel) = m.eventHandler.initial +initial( m::InstantiatedModel) = m.eventHandler.initial """ @@ -898,7 +898,7 @@ initial( m::SimulationModel) = m.eventHandler.initial Return true, if **initialization phase** of simulation of the **first segment** of a segmented simulation. """ -isFirstInitialOfAllSegments(m::SimulationModel) = m.eventHandler.firstInitialOfAllSegments +isFirstInitialOfAllSegments(m::InstantiatedModel) = m.eventHandler.firstInitialOfAllSegments """ @@ -907,8 +907,8 @@ isFirstInitialOfAllSegments(m::SimulationModel) = m.eventHandler.firstInitialOfA Return true, if **terminal phase** of simulation (of the current segment of a segmented simulation). """ -isTerminal(m::SimulationModel) = m.eventHandler.terminal -terminal( m::SimulationModel) = m.eventHandler.terminal +isTerminal(m::InstantiatedModel) = m.eventHandler.terminal +terminal( m::InstantiatedModel) = m.eventHandler.terminal """ @@ -917,7 +917,7 @@ terminal( m::SimulationModel) = m.eventHandler.terminal Return true, if **terminal phase** of simulation of the **last segment** of a segmented simulation. """ -isTerminalOfAllSegments(m::SimulationModel) = m.eventHandler.terminalOfAllSegments +isTerminalOfAllSegments(m::InstantiatedModel) = m.eventHandler.terminalOfAllSegments """ @@ -925,7 +925,7 @@ isTerminalOfAllSegments(m::SimulationModel) = m.eventHandler.terminalOfAllSegmen Return true, if **event phase** of simulation (including initialization). """ -isEvent(m::SimulationModel) = m.eventHandler.event +isEvent(m::InstantiatedModel) = m.eventHandler.event """ @@ -934,7 +934,7 @@ isEvent(m::SimulationModel) = m.eventHandler.event Return true, if **event phase** of simulation (including initialization) and during the first iteration of the event iteration. """ -isFirstEventIteration(m::SimulationModel) = m.eventHandler.firstEventIteration +isFirstEventIteration(m::InstantiatedModel) = m.eventHandler.firstEventIteration """ @@ -943,7 +943,7 @@ isFirstEventIteration(m::SimulationModel) = m.eventHandler.firstEventIteration Return true, if first iteration directly after initialization where initial=true (so at the startTime of the simulation). """ -isFirstEventIterationDirectlyAfterInitial(m::SimulationModel) = m.eventHandler.firstEventIterationDirectlyAfterInitial +isFirstEventIterationDirectlyAfterInitial(m::InstantiatedModel) = m.eventHandler.firstEventIterationDirectlyAfterInitial """ @@ -951,7 +951,7 @@ isFirstEventIterationDirectlyAfterInitial(m::SimulationModel) = m.eventHandler.f Return true, if **FullRestart event** of a segmented simulation. """ -isFullRestart(m::SimulationModel) = m.eventHandler.fullRestart +isFullRestart(m::InstantiatedModel) = m.eventHandler.fullRestart """ @@ -959,7 +959,7 @@ isFullRestart(m::SimulationModel) = m.eventHandler.fullRestart Return true, if **after start of simulation** (returns false during initialization). """ -isAfterSimulationStart(m::SimulationModel) = m.eventHandler.afterSimulationStart +isAfterSimulationStart(m::InstantiatedModel) = m.eventHandler.afterSimulationStart """ @@ -967,7 +967,7 @@ isAfterSimulationStart(m::SimulationModel) = m.eventHandler.afterSimulationStart Return true, if **event indicators (zero crossings) shall be computed**. """ -isZeroCrossing(m::SimulationModel) = m.eventHandler.crossing +isZeroCrossing(m::InstantiatedModel) = m.eventHandler.crossing """ @@ -975,7 +975,7 @@ isZeroCrossing(m::SimulationModel) = m.eventHandler.crossing Return true, if **results shall be stored**. """ -storeResults(m::SimulationModel) = m.storeResult +storeResults(m::InstantiatedModel) = m.storeResult """ @@ -983,11 +983,11 @@ storeResults(m::SimulationModel) = m.storeResult At an event instant, set the next time event to `nextEventTime`. """ -setNextEvent!(m::SimulationModel{FloatType,TimeType}, nextEventTime) where {FloatType,TimeType} = +setNextEvent!(m::InstantiatedModel{FloatType,TimeType}, nextEventTime) where {FloatType,TimeType} = setNextEvent!(m.eventHandler, convert(TimeType,nextEventTime)) -function setFullRestartEvent!(m::SimulationModel) +function setFullRestartEvent!(m::InstantiatedModel) m.eventHandler.restart = FullRestart return nothing end @@ -998,7 +998,7 @@ end Return current simulation time. """ -getTime(m::SimulationModel) = m.time +getTime(m::InstantiatedModel) = m.time get_xe(x, xe_info) = xe_info.length == 1 ? x[xe_info.startIndex] : x[xe_info.startIndex:xe_info.startIndex + xe_info.length-1] @@ -1047,7 +1047,7 @@ end """ success = init!(simulationModel) -Initialize `simulationModel::SimulationModel` at `startTime`. In particular: +Initialize `simulationModel::InstantiatedModel` at `startTime`. In particular: - Empty result data structure. @@ -1064,7 +1064,7 @@ Initialize `simulationModel::SimulationModel` at `startTime`. In particular: If initialization is successful return true, otherwise false. """ -function init!(m::SimulationModel{FloatType,TimeType})::Bool where {FloatType,TimeType} +function init!(m::InstantiatedModel{FloatType,TimeType})::Bool where {FloatType,TimeType} # Initialize model, linearEquations and compute and store all variables at the initial time if m.options.log println(" Initialization at time = ", m.options.startTime, " s") @@ -1165,7 +1165,7 @@ end Re-initialize `instantiatedModel` after a `FullRestart` event. """ -function initFullRestart!(m::SimulationModel{FloatType,TimeType})::Nothing where {FloatType,TimeType} +function initFullRestart!(m::InstantiatedModel{FloatType,TimeType})::Nothing where {FloatType,TimeType} if m.options.logEvents println(" Reinitialization due to FullRestart at time = ", m.time, " s") end @@ -1251,12 +1251,12 @@ end """ - success = check_vSolvedWithInitValuesAndUnit(m::SimulationModel) + success = check_vSolvedWithInitValuesAndUnit(m::InstantiatedModel) Check that m.vSolvedWithInitValuesAndUnit is consistent to calculated values. If this is not the case, print an error message and return false. """ -function check_vSolvedWithInitValuesAndUnit(m::SimulationModel)::Bool +function check_vSolvedWithInitValuesAndUnit(m::InstantiatedModel)::Bool # Check vSolvedWithInitValuesAndUnit if length(m.vSolvedWithInitValuesAndUnit) > 0 names = String[] @@ -1297,11 +1297,11 @@ end """ - terminate!(m::SimulationModel, x, time) + terminate!(m::InstantiatedModel, x, time) Terminate model. """ -function terminate!(m::SimulationModel, x, t)::Nothing +function terminate!(m::InstantiatedModel, x, t)::Nothing #println("... terminate! called at time = $t") eh = m.eventHandler eh.terminal = true @@ -1318,7 +1318,7 @@ approxTime(t1,t2) = eps(typeof(t1)) """ outputs!(x, t, integrator) -DifferentialEquations FunctionCallingCallback function for `SimulationModel` +DifferentialEquations FunctionCallingCallback function for `InstantiatedModel` that is used to store results at communication points. """ function outputs!(x, t, integrator)::Nothing @@ -1362,7 +1362,7 @@ end """ affect_outputs!(integrator) -DifferentialEquations PresetTimeCallback function for `SimulationModel` +DifferentialEquations PresetTimeCallback function for `InstantiatedModel` that is used to store results at communication points. """ function affect_outputs!(integrator)::Nothing @@ -1595,12 +1595,12 @@ affectTimeEvent!(integrator) = affectEvent!(integrator, false, 0) """ - leq = initLinearEquationsIteration!(m::SimulationModel, leq_index::Int) + leq = initLinearEquationsIteration!(m::InstantiatedModel, leq_index::Int) Initialize iteration over linear equations system of index `leq_index` and return a reference to it that can be used in the while-loop to construct and solve the linear equation system. """ -initLinearEquationsIteration!(m::SimulationModel, leq_index::Int) = begin +initLinearEquationsIteration!(m::InstantiatedModel, leq_index::Int) = begin leq = m.linearEquations[leq_index] leq.mode = -3 return leq @@ -1614,7 +1614,7 @@ Inspect all linear equations inside the instantiatedModel and resize the internal storage, of the length of vector-valued elements of the iteration variables has changed due to changed parameter values. """ -function resizeLinearEquations!(m::SimulationModel{FloatType,TimeType}, evaluatedParameters, log::Bool)::Nothing where {FloatType,TimeType} +function resizeLinearEquations!(m::InstantiatedModel{FloatType,TimeType}, evaluatedParameters, log::Bool)::Nothing where {FloatType,TimeType} for (i,leq) in enumerate(m.linearEquations) nx_vec = length(leq.x_names) - leq.nx_fixedLength if nx_vec > 0 @@ -1657,7 +1657,7 @@ end Add result of current time instant (`time, x, der_x, w_invariant, w_segmented`) to `instantiatedModel`. """ -function addToResult!(m::SimulationModel{FloatType,TimeType}, x, time, w_invariant...)::Nothing where {FloatType,TimeType} +function addToResult!(m::InstantiatedModel{FloatType,TimeType}, x, time, w_invariant...)::Nothing where {FloatType,TimeType} @assert(length(w_invariant) == m.result.n_w_invariant) copyDerivatives!(m.der_x, m.der_x_invariant, m.der_x_segmented) result::Result = m.result @@ -1681,7 +1681,7 @@ get_instantiatedSubmodel(instantiatedModel, ID) = instantiatedModel.buildDict[ID """ startIndex = new_x_segmented_variable!( - partiallyInstantiatedModel::SimulationModel, + partiallyInstantiatedModel::InstantiatedModel, x_name::String, der_x_name::String, startOrInit, x_unit::String=""; nominal::Float64 = NaN, unbounded::Bool = false)::Int @@ -1697,7 +1697,7 @@ Actual values of these new variables are stored in: Value `startOrInit` is the start/init value used during re-initialization of the new segment with `initFullRestart!(..)`. """ -function new_x_segmented_variable!(m::SimulationModel{FloatType,TimeType}, x_name::String, der_x_name::String, startOrInit, x_unit::String=""; +function new_x_segmented_variable!(m::InstantiatedModel{FloatType,TimeType}, x_name::String, der_x_name::String, startOrInit, x_unit::String=""; nominal::Float64 = NaN, unbounded::Bool = false)::Int where {FloatType,TimeType} eqInfo = m.equationInfo result = m.result @@ -1763,18 +1763,18 @@ end """ x_startIndex = get_x_startIndex_from_x_segmented_startIndex( - instantiatedModel::SimulationModel, x_segmented_startIndex) + instantiatedModel::InstantiatedModel, x_segmented_startIndex) Return the startindex of an `x_segmented` state with respect to the `x`-vector, given the startIndex with respect to the `x_segmented` vector (`x_segmented_startIndex` is the return value of `new_x_segmented_variable!(..)`). """ -get_x_startIndex_from_x_segmented_startIndex(m::SimulationModel, x_segmented_startIndex::Int) = m.equationInfo.nxInvariant + x_segmented_startIndex +get_x_startIndex_from_x_segmented_startIndex(m::InstantiatedModel, x_segmented_startIndex::Int) = m.equationInfo.nxInvariant + x_segmented_startIndex """ index = new_w_segmented_variable!( - partiallyInstantiatedModel::SimulationModel, name::String, + partiallyInstantiatedModel::InstantiatedModel, name::String, w_segmented_default, unit::String="")::Int Generate new local variable (`w_segmented` variable) and return the `index` of the variable @@ -1783,7 +1783,7 @@ New values of `w_segmented` variables need only to be computed at communication Value w_segmented_default is stored as default value and defines type and (fixed) size of the variable in this simulation segment. """ -function new_w_segmented_variable!(m::SimulationModel, name::String, w_segmented_default, unit::String="")::Int +function new_w_segmented_variable!(m::InstantiatedModel, name::String, w_segmented_default, unit::String="")::Int result = m.result w_size = size(w_segmented_default) push!(result.w_segmented_names, name) @@ -1815,12 +1815,12 @@ end """ - new_alias_segmented_variable!(partiallyInstantiatedModel::SimulationModel, + new_alias_segmented_variable!(partiallyInstantiatedModel::InstantiatedModel, name, aliasName, aliasNegate=false) Define new alias variable. """ -function new_alias_segmented_variable!(m::SimulationModel, name::String, aliasName::String, aliasNegate::Bool=false)::Int +function new_alias_segmented_variable!(m::InstantiatedModel, name::String, aliasName::String, aliasNegate::Bool=false)::Int result = m.result w_size = size(w_segmented_default) @@ -1841,7 +1841,7 @@ end Generate `nz` new zero crossing variables and return the startIndex to of the variables in order that actual values can be copied into the vector of zero crossings. """ -function new_z_segmented_variable!(m::SimulationModel{F,TimeType}, nz::Int)::Int where {F,TimeType} +function new_z_segmented_variable!(m::InstantiatedModel{F,TimeType}, nz::Int)::Int where {F,TimeType} eh = m.eventHandler zStartIndex = eh.nz + 1 eh.nz += nz @@ -1861,7 +1861,7 @@ end Return value of scalar x_segmented variable from state vector `x` by providing its `startIndex` (returned from `new_x_segmented_variable!(..)`). """ -copy_scalar_x_segmented_value_from_state(m::SimulationModel, startIndex::Int) = m.x_segmented[startIndex] +copy_scalar_x_segmented_value_from_state(m::InstantiatedModel, startIndex::Int) = m.x_segmented[startIndex] """ @@ -1870,18 +1870,18 @@ copy_scalar_x_segmented_value_from_state(m::SimulationModel, startIndex::Int) = Return value of `SVector{3,FloatType}` x_segmented variable from state vector `x` by providing its `startIndex` (returned from `new_x_segmented_variable!(..)`). """ -@inline copy_SVector3_x_segmented_value_from_state(m::SimulationModel{FloatType,TimeType}, startIndex::Int) where {FloatType,TimeType} = begin +@inline copy_SVector3_x_segmented_value_from_state(m::InstantiatedModel{FloatType,TimeType}, startIndex::Int) where {FloatType,TimeType} = begin x_segmented = m.x_segmented return SVector{3,FloatType}(x_segmented[startIndex], x_segmented[startIndex+1], x_segmented[startIndex+2]) end """ - Modia.copy_Vector_x_segmented_value_from_state(instantiatedModel::SimulationModel, startIndex, xi::Vector{FloatType})::Nothing + Modia.copy_Vector_x_segmented_value_from_state(instantiatedModel::InstantiatedModel, startIndex, xi::Vector{FloatType})::Nothing Return value of `Vector{FloatType}` x_segmented variable from state vector `x` by providing its `startIndex` (returned from `new_x_segmented_variable!(..)`) and copying it into the pre-allocated vector `xi`. """ -@inline function copy_Vector_x_segmented_value_from_state(m::SimulationModel{FloatType,TimeType}, startIndex::Int, xi::Vector{FloatType})::Nothing where {FloatType,TimeType} +@inline function copy_Vector_x_segmented_value_from_state(m::InstantiatedModel{FloatType,TimeType}, startIndex::Int, xi::Vector{FloatType})::Nothing where {FloatType,TimeType} copyto!(xi, 1, m.x_segmented, startIndex, length(xi)) return nothing end @@ -1893,23 +1893,23 @@ end Copy `der_x_segmented_value` to state derivative vector `der(x)` by providing its `startIndex` (returned from `new_x_segmented_variable!(..)`) and copying it into the pre-allocated vector `der_x_segmented_value`. """ -@inline function copy_der_x_segmented_value_to_state(m::SimulationModel{FloatType,TimeType}, startIndex::Int, der_x_segmented_value::FloatType)::Nothing where {FloatType,TimeType} +@inline function copy_der_x_segmented_value_to_state(m::InstantiatedModel{FloatType,TimeType}, startIndex::Int, der_x_segmented_value::FloatType)::Nothing where {FloatType,TimeType} m.der_x_segmented[startIndex] = der_x_segmented_value return nothing end -@inline function copy_der_x_segmented_value_to_state(m::SimulationModel{FloatType,TimeType}, startIndex::Int, der_x_segmented_value::Vector{FloatType})::Nothing where {FloatType,TimeType} +@inline function copy_der_x_segmented_value_to_state(m::InstantiatedModel{FloatType,TimeType}, startIndex::Int, der_x_segmented_value::Vector{FloatType})::Nothing where {FloatType,TimeType} copyto!(m.der_x_segmented, startIndex, der_x_segmented_value, 1, length(der_x_segmented_value)) return nothing end """ - Modia.copy_w_segmented_value_to_result(instantiatedModel::SimulationModel, index::Int, w_segmented_value)::Nothing + Modia.copy_w_segmented_value_to_result(instantiatedModel::InstantiatedModel, index::Int, w_segmented_value)::Nothing Copy value of local variable (`w-segmented`) to result by providing its `index` (returned from `new_w_segmented_variable!`), """ -@inline function copy_w_segmented_value_to_result(m::SimulationModel, index::Int, w_segmented_value)::Nothing +@inline function copy_w_segmented_value_to_result(m::InstantiatedModel, index::Int, w_segmented_value)::Nothing w_segmented_temp = m.result.w_segmented_temp @assert(typeof(w_segmented_value) == typeof(w_segmented_temp[index])) @assert(size( w_segmented_value) == size( w_segmented_temp[index])) @@ -1918,7 +1918,7 @@ Copy value of local variable (`w-segmented`) to result by providing its `index` end -function initialStateVector!(m::SimulationModel{FloatType,TimeType})::Vector{FloatType} where {FloatType,TimeType} +function initialStateVector!(m::InstantiatedModel{FloatType,TimeType})::Vector{FloatType} where {FloatType,TimeType} if length(m.equationInfo.x_info) == 0 # Handle systems with only algebraic variables, by introducing a dummy # differential equation der_x[1] = -x[1], with state name _dummy_x @@ -2059,7 +2059,7 @@ function generate_getDerivatives!(FloatType, TimeType, AST::Vector{Expr}, equati # Generate code of the function # temporarily removed: _m.time = $TimeType(Modia.getValueOnly(_time)) code = quote - function $functionName(_x, _m::Modia.SimulationModel{$FloatType,$TimeType}, _time::$TimeType)::Nothing + function $functionName(_x, _m::Modia.InstantiatedModel{$FloatType,$TimeType}, _time::$TimeType)::Nothing _FloatType = $FloatType _TimeType = $TimeType _m.time = _time diff --git a/src/EvaluateParameters.jl b/src/EvaluateParameters.jl index bba3f09..6887cc2 100644 --- a/src/EvaluateParameters.jl +++ b/src/EvaluateParameters.jl @@ -84,7 +84,7 @@ appendKey(path, key) = path == "" ? string(key) : path * "." * string(key) """ - map = propagateEvaluateAndInstantiate!(partiallyInstantiatedModel::SimulationModel; log=false) + map = propagateEvaluateAndInstantiate!(partiallyInstantiatedModel::InstantiatedModel; log=false) Recursively traverse the hierarchical collection `partiallyInstantiatedModel.parameters` and perform the following actions: @@ -94,7 +94,7 @@ Recursively traverse the hierarchical collection `partiallyInstantiatedModel.par - Return the evaluated `parameters` if successfully evaluated, and otherwise return nothing, if an error occurred (an error message was printed). """ -function propagateEvaluateAndInstantiate!(m::SimulationModel{FloatType,TimeType}; log=false) where {FloatType,TimeType} +function propagateEvaluateAndInstantiate!(m::InstantiatedModel{FloatType,TimeType}; log=false) where {FloatType,TimeType} x_found = fill(false, length(m.equationInfo.x_info)) map = propagateEvaluateAndInstantiate2!(m, m.parameters, x_found, [], ""; log=log) @@ -203,7 +203,7 @@ function changeDotToRef(ex) end -function propagateEvaluateAndInstantiate2!(m::SimulationModel{FloatType,TimeType}, parameters, x_found::Vector{Bool}, +function propagateEvaluateAndInstantiate2!(m::InstantiatedModel{FloatType,TimeType}, parameters, x_found::Vector{Bool}, environment, path::String; log=false) where {FloatType,TimeType} if log println("\n 1: !!! instantiate objects of $path: ", parameters) diff --git a/src/Modia.jl b/src/Modia.jl index 7028f63..4cb8b36 100644 --- a/src/Modia.jl +++ b/src/Modia.jl @@ -110,7 +110,7 @@ export simulate!, linearize!, get_result export hasParameter, getParameter, getEvaluatedParameter export showParameters, showEvaluatedParameters -export SimulationModel, measurementToString, get_lastValue, getLastValue, getStateNames +export InstantiatedModel, measurementToString, get_lastValue, getLastValue, getStateNames export positive, negative, previous, edge, after, reinit, pre export initial, terminal, isInitial, isTerminal, initLinearEquationsIteration! export get_xNames diff --git a/src/ModiaLang.jl b/src/ModiaLang.jl index a62c606..bc82495 100644 --- a/src/ModiaLang.jl +++ b/src/ModiaLang.jl @@ -766,9 +766,9 @@ function stateSelectionAndCodeGeneration(modStructure, Gexplicit, name, modelMod # convertedStartValues = convert(Vector{FloatType}, [ustrip(v) for v in startValues]) # ustrip.(value) does not work for MonteCarloMeasurements # @show mappedParameters -# println("Build SimulationModel") +# println("Build InstantiatedModel") hideResult_names = [string(h) for h in hideResults] - model = @timeit to "build SimulationModel" SimulationModel{FloatType,TimeType}(modelModule, name, buildDict, getDerivatives, equationInfo, previousVars, preVars, holdVars, + model = @timeit to "build InstantiatedModel" InstantiatedModel{FloatType,TimeType}(modelModule, name, buildDict, getDerivatives, equationInfo, previousVars, preVars, holdVars, mappedParameters, timeName, w_invariant_names, hideResult_names; vSolvedWithInitValuesAndUnit, vEliminated, vProperty, var_name = (v)->string(unknownsWithEliminated[v]), @@ -856,7 +856,7 @@ The arguments of ``are: - `updatedSubmodel`: A potentially new reference to the updated `submodel` - `modelModule`: Module in which the model is defined -- `FloatType`, `TimeType`: Types used when instantiating `SimulationModel{FloatType,TimeType}` +- `FloatType`, `TimeType`: Types used when instantiating `InstantiatedModel{FloatType,TimeType}` - `instantiateModelOptions`: Optional arguments of `@instantiateModel` provided as `OrderedDict{Symbol,Any}`. - `ID`: Unique ID to identify the generated submodel (to be used in the code merged into the submodel) - `pathAST`: Path upto `` as Abstract Syntax Tree, such as: `:( a.b.c )` diff --git a/src/ReverseDiffInterface.jl b/src/ReverseDiffInterface.jl index 640aa1a..ec863c8 100644 --- a/src/ReverseDiffInterface.jl +++ b/src/ReverseDiffInterface.jl @@ -1,7 +1,7 @@ export ModiaProblem, ModiaSolve -function ModiaProblem(m1::Modia.SimulationModel{FloatType1,FloatType1}, - m2::Modia.SimulationModel{FloatType2,FloatType2}; +function ModiaProblem(m1::Modia.InstantiatedModel{FloatType1,FloatType1}, + m2::Modia.InstantiatedModel{FloatType2,FloatType2}; p, merge=nothing, kwargs...) where {FloatType1,FloatType2} TimeType1 = FloatType1 @@ -29,7 +29,7 @@ function ModiaProblem(m1::Modia.SimulationModel{FloatType1,FloatType1}, tspan = (options1.startTime, options1.stopTime) tspan_outputs = options1.startTime:options1.interval:options1.stopTime - # Initialize/re-initialize SimulationModel + # Initialize/re-initialize InstantiatedModel if options1.log || options1.logParameters || options1.logEvaluatedParameters || options1.logStates println("... Construct simulation problem of DifferentialEquations.jl for ", m.modelName) end diff --git a/src/SignalTablesInterface.jl b/src/SignalTablesInterface.jl index 68146b1..a437a23 100644 --- a/src/SignalTablesInterface.jl +++ b/src/SignalTablesInterface.jl @@ -2,10 +2,10 @@ # Copyright 2022, DLR Institute of System Dynamics and Control #-------------------------------------------------------------------------------------------------- -# Provide the overloaded Abstract Signal Tables Interface for the results of SimulationModel +# Provide the overloaded Abstract Signal Tables Interface for the results of InstantiatedModel #-------------------------------------------------------------------------------------------------- -@inline function checkMissingResult(m::SimulationModel, name::String)::Bool +@inline function checkMissingResult(m::InstantiatedModel, name::String)::Bool if isnothing(m) || ismissing(m) || ismissing(m.result) error("$name: No simulation results available.") end @@ -13,16 +13,16 @@ end SignalTables.isSignalTable(r::Result) = true -SignalTables.isSignalTable(m::SimulationModel) = true +SignalTables.isSignalTable(m::InstantiatedModel) = true """ - getIndependentSignalNames(instantiatedModel::Modia.SimulationModel|result::Modia.Result)::Vector{String} + getIndependentSignalNames(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result)::Vector{String} Return the name of the independent variable of the result stored in instantiatedModel or in result. """ SignalTables.getIndependentSignalNames(result::Result) = [result.timeName] -SignalTables.getIndependentSignalNames(m::SimulationModel) = begin +SignalTables.getIndependentSignalNames(m::InstantiatedModel) = begin if ismissing(m.result) error("independentSignalName(..): No simulation results available in instantiated model of $(m.modelName)") end @@ -63,7 +63,7 @@ end """ - getSignalNames(instantiatedModel::Modia.SimulationModel; + getSignalNames(instantiatedModel::Modia.InstantiatedModel; getVar=true, getPar=true, getMap=true)::Vector{String} Returns a string vector of the variables of an @@ -72,7 +72,7 @@ Returns a string vector of the variables of an - If getPar=true, Par(..) variables are included. - If getMap=true, Map(..) variables are included. """ -function SignalTables.getSignalNames(m::SimulationModel; getVar=true, getPar=true, getMap=true, +function SignalTables.getSignalNames(m::InstantiatedModel; getVar=true, getPar=true, getMap=true, var=nothing, par=nothing)::Vector{String} # backwards compatibility # For backwards compatibility if !isnothing(var) @@ -108,11 +108,11 @@ SignalTables.getSignalNames(result::Result; getVar=true, getPar=true, getMap=tru """ - getStateNames(instantiatedModel::Modia.SimulationModel)::Vector{String} + getStateNames(instantiatedModel::Modia.InstantiatedModel)::Vector{String} Returns a string vector of the states that are present in [`@instantiateModel`](@ref) """ -function getStateNames(m::SimulationModel)::Vector{String} +function getStateNames(m::InstantiatedModel)::Vector{String} if ismissing(m.result) return collect(keys(m.equationInfo.x_dict)) else @@ -130,11 +130,11 @@ end """ - getIndependentSignalsSize(instantiatedModel::Modia.SimulationModel|result::Modia.Result)::Dims + getIndependentSignalsSize(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result)::Dims Returns the lengths of the independent signal of the result as (len,). """ -SignalTables.getIndependentSignalsSize(m::SimulationModel) = SignalTables.getIndependentSignalsSize(m.result) +SignalTables.getIndependentSignalsSize(m::InstantiatedModel) = SignalTables.getIndependentSignalsSize(m.result) SignalTables.getIndependentSignalsSize(result::Result) = (sum(length(sk) for sk in result.t), ) #= @@ -152,13 +152,13 @@ end """ - getSignal(instantiatedModel::Modia.SimulationModel|result::Modia.Result, name::String) + getSignal(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result, name::String) Returns signal `name` of the result present in instantiatedModel (that is a [`SignalTables.Var`](@ref), [`SignalTables.Par`](@ref)) or [`SignalTables.Map`](@ref)) If `name` does not exist, an error is raised. """ -function SignalTables.getSignal(m::SimulationModel, name::String) +function SignalTables.getSignal(m::InstantiatedModel, name::String) checkMissingResult(m, name) result = m.result @@ -274,11 +274,11 @@ end """ - hasSignal(instantiatedModel::Modia.SimulationModel, name::String) + hasSignal(instantiatedModel::Modia.InstantiatedModel, name::String) Returns `true` if signal `name` is present in the instantiatedModel result or in the evaluated parameters. """ -SignalTables.hasSignal(m::SimulationModel, name::String) = begin +SignalTables.hasSignal(m::InstantiatedModel, name::String) = begin if isnothing(m) || ismissing(m) || ismissing(m.result) return false end @@ -300,11 +300,11 @@ end """ - getSignalInfo(instantiatedModel::Modia.SimulationModel, name::String) + getSignalInfo(instantiatedModel::Modia.InstantiatedModel, name::String) Returns signal info of variables stored in the result and of parameters. """ -function SignalTables.getSignalInfo(m::SimulationModel, name::String) +function SignalTables.getSignalInfo(m::InstantiatedModel, name::String) result = m.result if haskey(result.info, name) # name is a result variable (time-varying variable stored in m.result) @@ -362,16 +362,16 @@ end #= """ - getSignalInfo(instantiatedModel::Modia.SimulationModel|result::Modia.Result, name::String) + getSignalInfo(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result, name::String) """ -function getSignalInfo(instantiatedModel::Modia.SimulationModel|result::Modia.Result, name::String) +function getSignalInfo(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result, name::String) end -function getSignalInfo(instantiatedModel::Modia.SimulationModel|result::Modia.Result, name::String) +function getSignalInfo(instantiatedModel::Modia.InstantiatedModel|result::Modia.Result, name::String) end =# -function get_algorithmName_for_heading(m::SimulationModel)::String +function get_algorithmName_for_heading(m::InstantiatedModel)::String if ismissing(m.algorithmName) algorithmName = "???" else @@ -420,11 +420,11 @@ get_leaveName(pathName::String) = """ - SignalTables.getDefaultHeading(instantiatedModel::Modia.SimulationModel) + SignalTables.getDefaultHeading(instantiatedModel::Modia.InstantiatedModel) Return default heading of instantiatedModel as a string. """ -function SignalTables.getDefaultHeading(m::SimulationModel{FloatType,TimeType}) where {FloatType,TimeType} +function SignalTables.getDefaultHeading(m::InstantiatedModel{FloatType,TimeType}) where {FloatType,TimeType} if isnothing(m) || ismissing(m) || ismissing(m.result) return "" end @@ -492,9 +492,9 @@ reference = get_result(pendulum, onlyStates=true) println("Check results: success = $success") ``` """ -get_result(m::SimulationModel, name::AbstractString; unit=true) = unit ? getValuesWithUnit(m,name) : getValues(m,name) +get_result(m::InstantiatedModel, name::AbstractString; unit=true) = unit ? getValuesWithUnit(m,name) : getValues(m,name) -function get_result(m::SimulationModel; onlyStates=false, extraNames=missing) +function get_result(m::InstantiatedModel; onlyStates=false, extraNames=missing) dataFrame = DataFrames.DataFrame() dataFrame[!,"time"] = getValues(m, "time") @@ -520,7 +520,7 @@ function get_result(m::SimulationModel; onlyStates=false, extraNames=missing) return dataFrame end -timeSignalName( m::SimulationModel) = "time" -hasOneTimeSignal(m::SimulationModel) = true -signalNames(m::SimulationModel) = sort!( getSignalNames(m) ) -printResultInfo(m::SimulationModel) = showInfo(m) +timeSignalName( m::InstantiatedModel) = "time" +hasOneTimeSignal(m::InstantiatedModel) = true +signalNames(m::InstantiatedModel) = sort!( getSignalNames(m) ) +printResultInfo(m::InstantiatedModel) = showInfo(m) diff --git a/src/SimulateAndPlot.jl b/src/SimulateAndPlot.jl index ffc9833..c09a07a 100644 --- a/src/SimulateAndPlot.jl +++ b/src/SimulateAndPlot.jl @@ -51,7 +51,7 @@ end requiredFinalStates_atol = 0.0, useRecursiveFactorizationUptoSize = 0) -Simulate `instantiatedModel::SimulationModel` with `algorithm` +Simulate `instantiatedModel::InstantiatedModel` with `algorithm` (= `alg` of [ODE Solvers of DifferentialEquations.jl](https://diffeq.sciml.ai/stable/solvers/ode_solve/) or [DAE Solvers of DifferentialEquations.jl](https://diffeq.sciml.ai/stable/solvers/dae_solve/)). @@ -184,7 +184,7 @@ function simulate!(m::Nothing, args...; kwargs...) return nothing end -function simulate!(m::SimulationModel{FloatType,TimeType}, algorithm=missing; merge=nothing, kwargs...) where {FloatType,TimeType} +function simulate!(m::InstantiatedModel{FloatType,TimeType}, algorithm=missing; merge=nothing, kwargs...) where {FloatType,TimeType} options = SimulationOptions{FloatType,TimeType}(merge; kwargs...) if isnothing(options) @test false @@ -204,7 +204,7 @@ function simulate!(m::SimulationModel{FloatType,TimeType}, algorithm=missing; me m.addEventPointsDueToDEBug = m.sundials m.odeIntegrator = !(typeof(algorithm) <: DifferentialEquations.DiffEqBase.AbstractDAEAlgorithm) - # Initialize/re-initialize SimulationModel + # Initialize/re-initialize InstantiatedModel if m.options.log || m.options.logEvaluatedParameters || m.options.logStates println("\n... Simulate model ", m.modelName) end @@ -385,7 +385,7 @@ function simulate!(m::SimulationModel{FloatType,TimeType}, algorithm=missing; me end -function simulateSegment!(m::SimulationModel{FloatType,TimeType}, algorithm=missing; kwargs...) where {FloatType,TimeType} +function simulateSegment!(m::InstantiatedModel{FloatType,TimeType}, algorithm=missing; kwargs...) where {FloatType,TimeType} solution = nothing options = m.options @@ -627,7 +627,7 @@ firstOrder1 = @instantiateModel(FirstOrder, FloatType = Measurement{Float64}) (A1, finalStates1) = linearize!(firstOrder1) # Higher precision -firstOrder2 = SimulationModel{Measurement{Double64}}(firstOrder1) +firstOrder2 = InstantiatedModel{Measurement{Double64}}(firstOrder1) (A2, finalStates2) = linearize!(firstOrder2) # Show results with 15 digits (default print with Measurements shows 3 digits) @@ -640,7 +640,7 @@ function linearize!(m::Nothing, args...; kwargs...) return nothing end -function linearize!(m::SimulationModel{FloatType,TimeType}, algorithm=missing; +function linearize!(m::InstantiatedModel{FloatType,TimeType}, algorithm=missing; merge = nothing, stopTime = 0.0, analytic = false, kwargs...) where {FloatType,TimeType} if analytic @info "linearize!(.., analytic=true) of model $(m.modelName) \nis modified to analytic=false, because analytic=true is currently not supported!" @@ -676,7 +676,7 @@ end Return true if parameter `name` (for example `name = "a.b.c"`) is defined in the instantiateModel. """ -hasParameter(m::SimulationModel, name::AbstractString) = begin +hasParameter(m::InstantiatedModel, name::AbstractString) = begin if isnothing(m) || ismissing(m) || ismissing(m.result) return false end @@ -690,7 +690,7 @@ end Return the value of parameter or init/start value `name` (for example `name = "a.b.c"`). If `name` is not known, `missing` is returned. """ -getParameter(m::SimulationModel, name::AbstractString) = get_value(m.parameters, name) +getParameter(m::InstantiatedModel, name::AbstractString) = get_value(m.parameters, name) """ @@ -699,7 +699,7 @@ getParameter(m::SimulationModel, name::AbstractString) = get_value(m.parameters, Return the value of evaluated parameter or init/start value `name` (for example `name = "a.b.c"`). If `name` is not known, `missing` is returned. """ -getEvaluatedParameter(m::SimulationModel, name::AbstractString) = get_value(m.evaluatedParameters, name) +getEvaluatedParameter(m::InstantiatedModel, name::AbstractString) = get_value(m.evaluatedParameters, name) """ @@ -707,7 +707,7 @@ getEvaluatedParameter(m::SimulationModel, name::AbstractString) = get_value(m.ev Print the parameters and the init/start values. """ -function showParameters(m::SimulationModel)::Nothing +function showParameters(m::InstantiatedModel)::Nothing parameters = m.parameters @showModel parameters return nothing @@ -719,7 +719,7 @@ end Print the evaluated parameters and the evaluated init/start values. """ -function showEvaluatedParameters(m::SimulationModel)::Nothing +function showEvaluatedParameters(m::InstantiatedModel)::Nothing evaluatedParameters = m.evaluatedParameters @showModel evaluatedParameters return nothing diff --git a/src/Synchronous.jl b/src/Synchronous.jl index 3735ce0..20c6f9f 100644 --- a/src/Synchronous.jl +++ b/src/Synchronous.jl @@ -28,10 +28,10 @@ interval(u) export Clock, sample, hold, previous -Clock(interval, m::SimulationModel, nr::Int) = Clock(m.options.startTime, interval, m, nr) +Clock(interval, m::InstantiatedModel, nr::Int) = Clock(m.options.startTime, interval, m, nr) -function Clock(startTime, interval, m::SimulationModel{FloatType,TimeType}, nr::Int)::Bool where {FloatType,TimeType} +function Clock(startTime, interval, m::InstantiatedModel{FloatType,TimeType}, nr::Int)::Bool where {FloatType,TimeType} # Clock ticks at startTime, startTime + interval, startTime + 2*interval, ... # This is independent of the starTime of the simulation. Example: # if startTime = -3, interval = 1.5, m.options.startTime = 1.0 then @@ -71,7 +71,7 @@ function Clock(startTime, interval, m::SimulationModel{FloatType,TimeType}, nr:: end -@inline function sample(v, clock::Bool, m::SimulationModel{FloatType,TimeType}, nr::Int) where {FloatType,TimeType} +@inline function sample(v, clock::Bool, m::InstantiatedModel{FloatType,TimeType}, nr::Int) where {FloatType,TimeType} eh = m.eventHandler if isInitial(m) || clock eh.sample[nr] = v @@ -80,7 +80,7 @@ end end -@inline function previous(clock::Bool, m::SimulationModel, nr::Int) +@inline function previous(clock::Bool, m::InstantiatedModel, nr::Int) # m.previous[nr] is initialized with the start/init value of v before the first model evaluation if clock m.previous[nr] = m.nextPrevious[nr] @@ -92,7 +92,7 @@ end hold(v) = v -@inline function hold(v, clock::Bool, m::SimulationModel, nr::Int) +@inline function hold(v, clock::Bool, m::InstantiatedModel, nr::Int) # m.hold[nr] is initialized with the start/init value of v before the first model evaluation if clock m.hold[nr] = v diff --git a/test/TestBouncingBall.jl b/test/TestBouncingBall.jl index 757f757..8f15050 100644 --- a/test/TestBouncingBall.jl +++ b/test/TestBouncingBall.jl @@ -10,7 +10,7 @@ BouncingBall = Model( g = 9.81, h = Var(init = 1.0), v = Var(init = 0.0), - flying = Var(start = true), # due to pre(flying) -> SimulationModel(....; pre_startValues = [true], ....) + flying = Var(start = true), # due to pre(flying) -> InstantiatedModel(....; pre_startValues = [true], ....) equations = :[ # desired: # flying = edge(-h) ? reinit(v, -e*v) : pre(flying) diff --git a/test/TestLinearSystems.jl b/test/TestLinearSystems.jl index 9a6c929..0eb9c3c 100644 --- a/test/TestLinearSystems.jl +++ b/test/TestLinearSystems.jl @@ -149,7 +149,7 @@ function build_LinearStateSpace!(model::AbstractDict, modelModule, FloatType::Ty end -function initSegment_LinearStateSpace!(partiallyInstantiatedModel::SimulationModel{FloatType,TimeType}, path::String, ID, +function initSegment_LinearStateSpace!(partiallyInstantiatedModel::InstantiatedModel{FloatType,TimeType}, path::String, ID, parameters::AbstractDict; log=false)::Nothing where {FloatType,TimeType} # Called during evaluation of the parameters (before initialization) if log @@ -168,7 +168,7 @@ function initSegment_LinearStateSpace!(partiallyInstantiatedModel::SimulationMod end -function openLinearStateSpace!(instantiatedModel::SimulationModel{FloatType,TimeType}, ID)::LinearStateSpaceStruct{FloatType} where {FloatType,TimeType} +function openLinearStateSpace!(instantiatedModel::InstantiatedModel{FloatType,TimeType}, ID)::LinearStateSpaceStruct{FloatType} where {FloatType,TimeType} ls = Modia.get_instantiatedSubmodel(instantiatedModel,ID).ls Modia.copy_Vector_x_segmented_value_from_state(instantiatedModel, ls.x_startIndex, ls.x) if Modia.storeResults(instantiatedModel) && length(ls.W) > 0 diff --git a/test/TestMechanics.jl b/test/TestMechanics.jl index 384cb45..ba98422 100644 --- a/test/TestMechanics.jl +++ b/test/TestMechanics.jl @@ -23,18 +23,18 @@ RevoluteStub = Model( # Generic Modia3D definitions (always available) -mutable struct SimulationModel3D +mutable struct InstantiatedModel3D # Internal memory of 3D model initial::Bool - SimulationModel3D() = new(true) + InstantiatedModel3D() = new(true) end # Function ..._f1 for 3D mechanics -# function Pendulum_f1(_m::SimulationModel3D, phi::Float64, w::Float64, tau::Float64, +# function Pendulum_f1(_m::InstantiatedModel3D, phi::Float64, w::Float64, tau::Float64, # m::Float64, L::Float64, g::Float64) -function Pendulum_f1(_m::TestMechanics.SimulationModel3D, phi, w, tau, m, L, g) +function Pendulum_f1(_m::TestMechanics.InstantiatedModel3D, phi, w, tau, m, L, g) #function Pendulum_f1(phi, w, tau, m, L, g) #= @@ -50,7 +50,7 @@ end # Modia model for the system Pendulum = Model( - model3D = SimulationModel3D(), + model3D = InstantiatedModel3D(), # Parameters m = 1.0u"kg", diff --git a/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl b/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl index 1a40b00..d475dd8 100644 --- a/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl +++ b/test/TestTwoInertiasAndIdealGearWithUnitsAndUncertainties.jl @@ -53,7 +53,7 @@ println(IOContext(stdout, :error_digits=>15), "A2 = ", A2, ", x2 = ", x2) using Modia.Test println("\n... Numeric linearization with Double64") using DoubleFloats -twoInertiasAndIdealGear2 = SimulationModel{Measurement{Double64}}(twoInertiasAndIdealGear) +twoInertiasAndIdealGear2 = InstantiatedModel{Measurement{Double64}}(twoInertiasAndIdealGear) (A3, x3) = linearize!(twoInertiasAndIdealGear2, stopTime=3, analytic=false) println(IOContext(stdout, :error_digits=>15), "A3 = ", A3, ", x3 = ", x3) =#