Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring non-linear solvers #9065

Merged
merged 19 commits into from Jun 10, 2022

Conversation

AnHeuermann
Copy link
Member

@AnHeuermann AnHeuermann commented Jun 7, 2022

Purpose

Make solveNLS more generic, so it can work for any given nonlinear systems, not only for those saved in data->simulationInfo->nonlinearSystemData[sysNumber].

Progress

  • KINSOL
  • Newton
  • Hybrid
  • Homotopy
  • Mixed
  • solveNLS accepting NONLINEAR_SYSTEM_DATA* nonlinsys

Changes

Unified user data structs for all non-linear solvers:

typedef struct NLS_USERDATA {
  DATA *data;
  threadData_t *threadData;

  int sysNumber;                        /* System index, for print messages only */
  NONLINEAR_SYSTEM_DATA* nlsData;       /* Pointer to nonlinear system data */
  ANALYTIC_JACOBIAN* analyticJacobian;  /* Pointer to analytic Jacobian */
} NLS_USERDATA;

Contains pointer to nlsData that contains this user data. Used to hide omc internal data from 3rdParty function calls.
userData will be passed to residual and Jacobian functions.

Use initNlsUserData and freeNlsUserData for memory management.

Simplify NLS functions interface

  • int allocateNewtonData(int size, void** voiddata) --> DATA_NEWTON* allocateNewtonData(int size, NLS_USERDATA* userData)
  • int nlsKinsolFree(void **solverData) --> void freeNewtonData(DATA_NEWTON* newtonData)
  • int solveNLS(DATA *data, threadData_t *threadData, int sysNumber) --> modelica_boolean solveNLS(DATA *data, threadData_t *threadData, NONLINEAR_SYSTEM_DATA* nonlinsys)
  • int _omc_newton(int(*f)(int*, double*, double*, void*, int), DATA_NEWTON* solverData, void* userdata); --> int _omc_newton(genericResidualFunc f, DATA_NEWTON* solverData, void* userData);
  • void printNonLinearSystemSolvingStatistics(DATA *data, int sysNumber, int logLevel) --> void printNonLinearSystemSolvingStatistics(NONLINEAR_SYSTEM_DATA* nonlinsys, enum LOG_STREAM stream)

Other

  • Added more documentation.
  • Fixed memory leaks while freeing NLS data.
  • Removed unused currentNonlinearSystemIndex from NONLINEAR_SYSTEM_DATA.
  • Added TRUE and FALSE to openmodelcia_types.h, next to definition of type modelica_boolean.
  • typedef genericResidualFunc function pointer.

@AnHeuermann AnHeuermann added the COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime). label Jun 7, 2022
@AnHeuermann AnHeuermann self-assigned this Jun 7, 2022
@AnHeuermann
Copy link
Member Author

@bernhardbachmann KINSOL and Newton are already refactored.

We can try to merge the current state into a copy of https://github.com/bernhardbachmann/OpenModelica/tree/01-ESDIRK_integrator and see if this is working for your gbode solver.

If that is working I'll finish this for the other non-linear solvers and we can merge this into the master.

@AnHeuermann
Copy link
Member Author

Merging is not straight forward.
I will cherry-pick some commits from bernhardbachmann/01-ESDIRK_integrator that I made a while ago to improve the NLS solver.

@AnHeuermann
Copy link
Member Author

716f148 broke some tests. Now I need to figure out why.

@bernhardbachmann
Copy link
Contributor

The gbode development branch has been renamed to 01-GBODE_development. Please use this for merging your NLS changes

@AnHeuermann AnHeuermann marked this pull request as ready for review June 9, 2022 10:02
Copy link
Contributor

@phannebohm phannebohm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, except some small typos.

@AnHeuermann AnHeuermann merged commit a983f48 into OpenModelica:master Jun 10, 2022
@AnHeuermann AnHeuermann deleted the genericNlsDataPointer branch June 13, 2022 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
COMP/OMC/Runtime Issues and pull requests related to the runtime for OMC (not simulation runtime).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants