diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..58085d0 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,41 @@ +name: Run tests + +env: + JULIA_NUM_THREADS: 4 +on: + pull_request: + branches: + - main +jobs: + test: + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + version: + - '1.7.2' + os: + - ubuntu-latest + - windows-latest + - macos-latest + arch: + - x64 + steps: + - uses: actions/checkout@v2 + - uses: julia-actions/setup-julia@v1 + with: + version: ${{ matrix.version }} + arch: ${{ matrix.arch }} + - uses: actions/cache@v1 + env: + cache-name: cache-artifacts + with: + path: ~/.julia/artifacts + key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} + restore-keys: | + ${{ runner.os }}-test-${{ env.cache-name }}- + ${{ runner.os }}-test- + ${{ runner.os }}- + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-runtest@v1 diff --git a/Project.toml b/Project.toml index 91d0559..6220fa2 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ModiaBase" uuid = "ec7bf1ca-419d-4510-bbab-199861c55244" authors = ["Hilding Elmqvist ", "Martin Otter "] -version = "0.10.0" +version = "0.11.0" [deps] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" diff --git a/docs/src/TransformationToODEs.md b/docs/src/TransformationToODEs.md index 69e88ed..53178ee 100644 --- a/docs/src/TransformationToODEs.md +++ b/docs/src/TransformationToODEs.md @@ -1,6 +1,6 @@ # Transformation to ODE System -This section provides functions to **transform DAE to ODE systems**. In particular, +This section provides utility functions to **transform DAE to ODE systems**. In particular, - to find equations that need to be differentiated, in order to transform a Differential Algebraic Equations (DAEs) agebraically to @@ -8,8 +8,6 @@ This section provides functions to **transform DAE to ODE systems**. In particul - to differentiate relevant equations analytically, -- to statically select ODE states and transform to ODE form. - ## Main Functions @@ -30,29 +28,3 @@ CurrentModule = ModiaBase.Differentiate derivative ``` - -```@meta -CurrentModule = ModiaBase -``` - -```@docs -StateSelectionFunctions -getSortedAndSolvedAST -``` - - -## Utility Functions - - -```@meta -CurrentModule = ModiaBase -``` - -```@docs -StateCategory -ResidualCategory -LinearEquations -LinearEquationsIteration! -EquationInfo -StateElementInfo -``` diff --git a/docs/src/Tutorial.md b/docs/src/Tutorial.md index 12f2039..2b3ed36 100644 --- a/docs/src/Tutorial.md +++ b/docs/src/Tutorial.md @@ -202,7 +202,7 @@ is linear in the iteration variable (`C.i`) and an AST is generated to build-up a linear equation system `A*C.i = b` and solve this system numerically with an LU decomposition whenever the AST is called (if the equation system has size 1, a simple division is used instead of calling a linear equation solver). Applying -[`ModiaBase.getSortedAndSolvedAST`](@ref) results basically in a function +`Modia.getSortedAndSolvedAST` results basically in a function `getDerivatives` that can be solved with the many ODE integrators of [DifferentialEquations.jl](https://github.com/SciML/DifferentialEquations.jl): diff --git a/docs/src/index.md b/docs/src/index.md index 7eef6b6..a1ffc5c 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -77,6 +77,12 @@ julia> ]add ModiaBase ## Release Notes +### Version 0.11.0 + +- Moved ModiaBase.Symbolic.makeDerVar to Modia (because makeDerVar needs FloatType for + generating type-stable code and FloatType is available in Modia but not in ModiaBase). + + ### Version 0.10.0 **Non-backwards** compatible changes diff --git a/src/ModiaBase.jl b/src/ModiaBase.jl index c8b4dfa..8ea48fb 100644 --- a/src/ModiaBase.jl +++ b/src/ModiaBase.jl @@ -9,8 +9,8 @@ Main module of ModiaBase. module ModiaBase const path = dirname(dirname(@__FILE__)) # Absolute path of package directory -const Version = "0.10.0" -const Date = "2022-03-01" +const Version = "0.11.0" +const Date = "2022-03-08" #println("\nImporting ModiaBase Version $Version ($Date)") diff --git a/src/Symbolic.jl b/src/Symbolic.jl index 7711f5c..512888d 100644 --- a/src/Symbolic.jl +++ b/src/Symbolic.jl @@ -56,95 +56,6 @@ function removeQuoteNode(ex::Expr) Expr(ex.head, [removeQuoteNode(arg) for arg in ex.args]...) end -prependPar(ex, prefix, parameters=[], inputs=[]) = ex - -function prependPar(ex::Symbol, prefix, parameters=[], inputs=[]) - if prefix == nothing; ex elseif ex in [:time, :instantiatedModel, :_leq_mode, :_x]; ex else Expr(:ref, prefix, QuoteNode(ex)) end -end - -function prependPar(ex::Expr, prefix, parameters=[], inputs=[]) - if isexpr(ex, :.) - Expr(:ref, prependPar(ex.args[1], prefix, parameters, inputs), QuoteNode(ex.args[2].value)) - else - Expr(ex.head, [prependPar(arg, prefix, parameters, inputs) for arg in ex.args]...) - end -end - -""" - e = castToFloatType(ex,value) - -If manageable, cast `ex` to FloatType, if this is an `AbstractFloat` (`typeof(value) <: AbstractFloat`) -and define it to be FloatType (called _FloatType in getDerivatives), so `FloatType(ex)::FloatType`. - -If this is not manageable, cast `ex` to `valueType = typeof(value)` if this is a numeric data datatype -(`eltype(value) <: Number`), and define it to be `valueType`, so `valueType(ex)::valueType`. - -As a result, the generated code of `ex` will have the correct type instead of `Any`, -so will be more efficient and no unnecessary memory will be calculated at run-time. - -Note, this function should only be used on parameter, init, or start values. -""" -function castToFloatType(ex,value) - if eltype(value) <: Number - valueType = typeof(value) - if valueType <: AbstractFloat && !(valueType <: Unitful.AbstractQuantity || - valueType <: Measurements.Measurement || - valueType <: MonteCarloMeasurements.AbstractParticles) - :( _FloatType($ex)::_FloatType ) - else - :( $valueType($ex)::$valueType ) - end - else - ex - end -end - -""" - e = makeDerVar(ex) - -Recursively converts der(x) to Symbol(:(der(x))) in expression `ex` - -* `ex`: Expression or array of expressions -* `return `e`: ex with der(x) converted -""" -function makeDerVar(ex, parameters, inputs, evaluateParameters=false) - if typeof(ex) in [Symbol, Expr] - if ex in keys(parameters) - castToFloatType( prependPar(ex, :(_p), parameters, inputs), parameters[ex] ) - elseif ex in keys(inputs) - prependPar(ex, :(_p), parameters, inputs) - else - ex - end - else - ex - end -end - -function makeDerVar(ex::Expr, parameters, inputs, evaluateParameters=false) - if ex.head == :call && ex.args[1] == :der - Symbol(ex) - elseif isexpr(ex, :.) && ex in keys(parameters) - if evaluateParameters - parameters[ex] - else - castToFloatType( prependPar(ex, :(_p), parameters, inputs), parameters[ex] ) - end - elseif isexpr(ex, :.) && ex in keys(inputs) - if evaluateParameters - inputs[ex] - else - prependPar(ex, :(_p), parameters, inputs) - end - elseif ex.head == :. - Symbol(ex) - elseif ex.head == :call # Don't change dot-notation for function calls - Expr(ex.head, ex.args[1], [makeDerVar(arg, parameters, inputs, evaluateParameters) for arg in ex.args[2:end]]...) - else - Expr(ex.head, [makeDerVar(arg, parameters, inputs, evaluateParameters) for arg in ex.args]...) - end -end - removeUnits(ex) = if typeof(ex) <: Unitful.Quantity; @show ex; ustrip(ex) else ex end removeUnits(ex::Expr) = if ex.head == :macrocall && ex.args[1] == Symbol("@u_str"); 1 else Expr(ex.head, [removeUnits(arg) for arg in ex.args]...) end