Opened 7 years ago

Closed 7 years ago

#4747 closed enhancement (fixed)

Treatment of singular equation systems in source code FMUs

Reported by: Rüdiger Franke Owned by: Martin Sjölund
Priority: high Milestone: 1.13.0
Component: Build Environment Version: v1.13.0-dev-nightly
Keywords: Cc:

Description

OMCompiler comes with the LAPACK solver 3rdParty/dgesv that "is based on https://github.com/sjoelund/dgesv"

This enables the solution of linear equation systems with a call of the form:

  dgesv_(&_dimSys, &dimRHS, _A, &_dimSys, _ihelpArray, _b, &_dimSys, &irtrn);

  if (irtrn != 0) {
    throw ModelicaSimulationError(ALGLOOP_SOLVER, "error solving linear system (dgesv info: " + to_string(irtrn) + ")");
  }

Solvers of the simulation runtimes are able to treat such errors. This is useful in cases where equation systems become singular due to switches inside a model, if parts of the model disappear and the respective variables shall become zero.

FMUs should also treat such errors. LAPACK offers the additional functions dgetc2 and dgesc2 for this:

    dgesv_(&_dimSys, &dimRHS, _A, &_dimSys, _ihelpArray, _b, &_dimSys, &irtrn);

    if  (irtrn != 0) {
      dgetc2_(&_dimSys, _A, &_dimSys, _ihelpArray, _jhelpArray, &irtrn);
      dgesc2_(&_dimSys, _A, &_dimSys, _b, _ihelpArray, _jhelpArray, _scale);
      LOGGER_WRITE("LinearSolver: Linear system singular, using perturbed system matrix.", LC_LS, LL_DEBUG);
    }

Please extend 3rdParty/dgesv with the the functions dgetc2 and dgesc2.

Attachments (1)

all-symbols.txt (720.3 KB ) - added by Adrian Pop 7 years ago.
all symbols in all the lib/omc/cpp/*.a

Download all attachments as: .zip

Change History (21)

comment:1 by Martin Sjölund, 7 years ago

https://github.com/sjoelund/dgesv/pull/1 adds the required files for dgetc2, dgesc2. I don't have time to test if it works with the FMUs so I won't merge it though.

comment:2 by Rüdiger Franke, 7 years ago

Looks good!

I replaced my local directory OpenModelica/OMCompiler/3rdParty/dgesv with the branch ticket4747 of https://github.com/sjoelund/dgesv. Additionally I added the code of the ticket opener to the linear solver embedded with the FMU (OMCompiler/SimulationRuntime/cpp/Solvers/Dgesv).

Compilation of OpenModelica and the FMU export worked without problem. An example that failed before does simulate now -- showing the LOGGER_WRITE message to prove that dgetc2/dgesc2 are used.

Can you merge your pull request, so that I can push my extension of the linear solver?

Last edited 7 years ago by Rüdiger Franke (previous) (diff)

comment:3 by Martin Sjölund, 7 years ago

ad98b03 now has the files added. I guess it would be good if the C runtime would also call dgetc2/dgesc2.

comment:4 by Rüdiger Franke, 7 years ago

The link ad98b03 appears broken. Moreover, git pull does not add the new files. A synchronization issue with github?

Last edited 7 years ago by Rüdiger Franke (previous) (diff)

comment:5 by Martin Sjölund, 7 years ago

I think just a Trac issue. The tooltip gives the commit message :)

comment:6 by Martin Sjölund, 7 years ago

0a2708a better? Seems Hudson messed up the 3rdParty commit hash so it pointed to something broken... But Trac didn't seem to update based on the changes. I guess after the next PR.

comment:7 by Rüdiger Franke, 7 years ago

Hudson does neither get the new files, see missing symbols during FMI export:
https://test.openmodelica.org/hudson/job/OpenModelica_TEST_PULL_REQUEST/5269/

comment:8 by Martin Sjölund, 7 years ago

Were they added to the cmake project in the Cpp runtime? libOMCppDgesvSolver_static.a?

comment:9 by Rüdiger Franke, 7 years ago

Implicitly yes (libOMCppDgesvSolver_static.a contains everything from the 3rdParty dgesv folder). It works as soon as I copy the new files in there.

comment:10 by Adrian Pop, 7 years ago

Seems not to be the case somehow:

hudson@asap:~/slave/workspace/OpenModelica_TEST_PULL_REQUEST/OpenModelica/build/lib/x86_64-linux-gnu/omc/cpp$ nm libOMCppDgesvSolver_static.a | grep dge
                 U dgesv_

by Adrian Pop, 7 years ago

Attachment: all-symbols.txt added

all symbols in all the lib/omc/cpp/*.a

comment:11 by Rüdiger Franke, 7 years ago

This is because the source files are missing. Invoke ls OpenModelica/OMCompiler/3rdParty/dgesv/lapack. This should result in:

dgesc2.c  dgetc2.c  dgetrf.c  dlabad.c  dlaswp.c  ilaenv.c  xerbla.c
dgesv.c   dgetf2.c  dgetrs.c  dlamch.c  ieeeck.c  iparmq.c

including dgesc2.c and dgetc2.c.

comment:12 by Adrian Pop, 7 years ago

Yes, that seems to be the case, in the PR job they are not there:
https://test.openmodelica.org/hudson/view/PullRequestTesting/job/OpenModelica_TEST_PULL_REQUEST/ws/OpenModelica/OMCompiler/3rdParty/dgesv/lapack/
Note that only some people have access to Job workspace.
These are the files in OMCompiler / 3rdParty / dgesv / lapack

	dgesv.c	
	dgetf2.c
	dgetrf.c
	dgetrs.c
	dlamch.c
	dlaswp.c
	ieeeck.c
	ilaenv.c
	iparmq.c
	xerbla.c

comment:13 by Adrian Pop, 7 years ago

Strangely the 3rdParty checked out for the PR job has hash: changeset:ad6075ab4a22aebdee753cfdeea3f2f51455ae62/OMCompiler-3rdParty which is an old one.

comment:14 by Adrian Pop, 7 years ago

I wiped out the PR job workspace and restarted the PR.

comment:15 by Adrian Pop, 7 years ago

Found the issue: Martin fixed the 3rdParty hash in OMCompiler but we need to update also the OpenModelica qlue project.

comment:16 by Adrian Pop, 7 years ago

Resolution: fixed
Status: newclosed

comment:17 by Adrian Pop, 7 years ago

Resolution: fixed
Status: closedreopened

Funny, I ran some other PR which happened in the meantime.
I'm re-running yours now.

comment:18 by Adrian Pop, 7 years ago

Ok. This is weird. Martin added the files in 3rdParty/lapack but I think that they should be in 3rdParty/dgesv/lapack. What is going on here? :)

comment:19 by Adrian Pop, 7 years ago

I will move them to where they should be.

comment:20 by Adrian Pop, 7 years ago

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.