Comments (2)
Yes, I know. There are also other situations where analytic=true does not work. I spent some time on it, but did not find a solution. I have documented this in the description of linearize (analytic=true might not work) and used analytic=false (numeric linearization) as a default - which should always work. A workaround is to perform linearization numerically with Double64, which should give an even higher precision as analytic linearization with Float64.
model2 = SimulationModel{Double64}(model1) # transform instantiated model1 from Float64 to Double64
(A,x0) = linearize!(model2)
from modia.jl.
below my proposal for linearize!(model, analytic=true)
. Not perfect, but it works
Modification of file ModiaBase...EquationAndStateInfo.jl
structure: mutable struct LinearEquations{FloatType <: Real}
For Vectors/Matrix: A,x,b,residuals,luA , I changed the type from FloatType
to Union{FloatType,Any}
mutable struct LinearEquations{FloatType <: Real}
odeMode::Bool # Set from the calling function after LinearEquations was instantiated (default: true)
# = true (standard mode): Compute "x" from equation "residuals = A*x - b"
# = false (DAE solver): During events (including initialization)
# compute "x" as for odeMode=true. Outside of events:
# (1) "x" is set from the outside (= der(x_dae) provided by DAE solver)
# (2) Compute "residuals" from "residuals := A*x - b"
# (3) From the outside copy "residuals" into "residuals_dae" of the DAE solver.
A_is_constant::Bool # = true, if A-matrix is constant
x_names::Vector{String} # Names of the x-variables
x_lengths::Vector{Int} # Lengths of the x-variables (sum(x_lengths) = length(x))
x::Vector{Union{FloatType,Any}} # Values of iteration variables
nResiduals::Int # Number of residual variables
A::Matrix{Union{FloatType,Any}}
b::Vector{Union{FloatType,Any}}
pivots::Vector{Int} # Pivot vector if recursiveFactorization = true
residuals::Vector{Union{FloatType,Any}} # Values of the residuals FloatType vector; length(residuals) = sum(residuals_length) = sum(x_lengths)
residual_value::AbstractVector # Values of the residual variables ::Vector{Any}, length(residual_values) = nResiduals
# Iteration status of for-loop
mode::Int # Operational mode (see function LinearEquationsIteration)
niter::Int # Current number of iterations in the fix point iteration scheme
niter_max::Int # Maximum number of iterations
success::Bool # = true, if solution of A*x = b is successfully computed
# = false, if solution is not computed; continue with fix point iteration
# For warning message if niter > niter_max
inconsistentPositive::Vector{String}
inconsistentNegative::Vector{String}
# Constructed during initialization
residual_unitRanges::Vector{UnitRange{Int}} # residuals[residual_unitRanges[i]] = residual_value[i], if residual is a vector
residual_indices::Vector{Int} # residuals[residual_indices[i]] = residual_value[i], if residual is a scalar
recursiveFactorization::Bool # = true, if RecursiveFactorization.jl shall be used to solve the linear equation system
luA::LU{Union{FloatType,Any},Array{Union{FloatType,Any},2}} # lu-Decomposition of A
...
This works for nx==1
, but not for nx>1
when lu!
is called.
additional modification in RecursiveFactorization...lu.jl
zero()
function for type Dual
does not exist. So I changed to convert()
function _generic_lufact!(A, ::Val{Pivot}, ipiv, info) where Pivot
m, n = size(A)
minmn = length(ipiv)
@inbounds begin
for k = 1:minmn
# find index max
kp = k
if Pivot
# =====>>>> amax = abs(zero(eltype(A))) <<<<====
amax = convert(eltype(A),0)
for i = k:m
absi = abs(A[i,k])
if absi > amax
kp = i
...
version
name = "ModiaBase"
version = "0.8.0-dev"
from modia.jl.
Related Issues (20)
- numerical constant and spaces in equation HOT 1
- Problem with ModiaPlot dependencies
- I am studying this product, but it is incredibly problematic with the version compatibility of other very common libraries, such as JuliaDB. HOT 1
- I would like to use Modia in real-time applications ... does it make sense, is it possible? HOT 2
- equations = :[ ] ... observation
- dead-time function HOT 1
- ModiaLang v0.8.2 - missing feature in main branch HOT 1
- issue with "m.x_init" HOT 3
- Modia.jl 0.6.1 instantiatemodel fails HOT 4
- Bool parameter converted to Float64 HOT 1
- error when using SVector and SMatrix HOT 1
- Modia crashing "using Modia" HOT 4
- time consuming function "addToResult!"
- docs: How to describe the Map function? HOT 1
- Link to documentation broken HOT 1
- [help] Implementing a basic NPN BJT model HOT 2
- Precompilation fails HOT 3
- issue with algebraic loop (nonlinear)
- issue with new version of Sundials v4.20.1 HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from modia.jl.