GithubHelp home page GithubHelp logo

Comments (2)

MartinOtter avatar MartinOtter commented on August 22, 2024

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.

johhell avatar johhell commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.