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

OMJulia.API.simulate how to know that the simulation was successful #126

Closed
olivleno opened this issue May 29, 2024 · 6 comments
Closed
Assignees

Comments

@olivleno
Copy link

olivleno commented May 29, 2024

The scripting API simulate
has a record as return value.
The OMJulia.API.simulate documentation doesn't mention the return values.

I expected to get a boolean in the sense of simulation failed vs. successful,
and an error message if it failed.

In some cases the console is dumped with endless warnings.
Is there a way to control the debug level and log output (verbose=false)?

@AnHeuermann
Copy link
Member

OMJulia.API.simulate will return a record containing the same element as the record returned by the OpenModelica simulate function. The documentation is referencing the scripting API which documents the output type as

  output SimulationResult simulationResults;
  record SimulationResult
    String resultFile;
    String simulationOptions;
    String messages;
    Real timeFrontend;
    Real timeBackend;
    Real timeSimCode;
    Real timeTemplates;
    Real timeCompile;
    Real timeSimulation;
    Real timeTotal;
  end SimulationResult;

OMJulia will throw an error if:

  • nothing is returned
  • the result file is missing from the record

In all other cases you can assume the simulation was successful. If I missed a case where the simulation failed but no error is thrown please provide a way to reproduce.

@AnHeuermann
Copy link
Member

In some cases the console is dumped with endless warnings.
Is there a way to control the debug level and log output (verbose=false)?

Can you provide an example and what does the output look like? All output should be stored in SimulationResult.messages.

@AnHeuermann AnHeuermann self-assigned this Jun 3, 2024
@olivleno
Copy link
Author

olivleno commented Jun 3, 2024

| debug   | Model error: Argument of sqrt(jetPump.JetPump.suctionFlow.k * jetPump.JetPump.suctionFlow.R_s * jetPump.JetPump.suctionFlow.T) was -8.63432e+06 should be >= 0\nLOG_ASSERT        | warning | The following assertion has been violated during initialization at time 0.000000\nLOG_ASSERT        | debug 
  | Model error: Argument of sqrt(jetPump.JetPump.suctionFlow.k * jetPump.JetPump.suctionFlow.R_s * jetPump.JetPump.suctionFlow.T) was -588687 should be >= 0\nLOG_ASSERT        | warning | The 
following assertion has been violated during initialization at time 0.000000\nLOG_ASSERT        | debug   | Model error: Argument of sqrt(jetPump.JetPump.mixFlow.k * jetPump.JetPump.mixFlow.R_s * jetPump._T_dis) was -2.39141e+06 should be >= 0\nLOG_ASSERT        | warning | The following assertion has been violated during initialization at time 0.000000\nLOG_ASSERT        | debug   | Model error: Argument of sqrt(jetPump.JetPump.suctionFlow.k * jetPump.JetPump.suctionFlow.R_s * jetPump.JetPump.suctionFlow.T) was -8.63432e+06 should be >= 0\nLOG_ASSERT        | warning | The following assertion has been violated during initialization at time 0.000000\nLOG_ASSERT        | debug   | Model error: Argument of sqrt(jetPump.JetPump.suctionFlow.k * jetPump.JetPump.suctionFlow.R_s * jetPump.JetPump.suctionFlow.T) was -8.63432e+06 should be >= 0\nLOG_ASSERT        | debug   | Solving non-linear system 144 failed at time=0.\n|                 | |       | For more information please use -lv LOG_NLS.\nLOG_ASSERT        | info    | simulation terminated by an assertion at initialization\n", "[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:3:3-6:58:writable] Warning: Connector _p_0_mot is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:7:3-9:58:writable] Warning: Connector _T_0_mot is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:10:3-12:58:writable] Warning: 
Connector _mflow_mot is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:13:3-16:36:writable] Warning: Connector _Xi_mot is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:18:3-21:60:writable] Warning: Connector _p_0_suc is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:22:3-24:60:writable] Warning: 
Connector _T_0_suc is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:25:3-27:60:writable] Warning: Connector _mflow_suc is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:28:3-31:26:writable] Warning: Connector _Xi_suc is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:33:3-35:41:writable] Warning: 
Connector _p_0_dis is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:36:3-38:59:writable] Warning: Connector _T_dis is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:39:3-41:59:writable] Warning: Connector _mflow_dis is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Systems/JetPump_acausal.mo:42:3-45:36:writable] Warning: Connector _Xi_dis is not balanced: The number of potential variables (1) is not equal to the number of flow variables (0).\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Components/EQS_H2Valve.mo:20:3-20:111:writable] Warning: Parameter jetPump.HGI.c_c has no value, and is fixed during initialization (fixed=true), using available start value (start=0.0) as default value.\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Components/EQS_H2Valve.mo:19:3-19:126:writable] Warning: Parameter jetPump.HGI.c_m has no value, and 
is fixed during initialization (fixed=true), using available start value (start=0.0) as default value.\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Components/EQS_H2Valve.mo:16:3-16:100:writable] Warning: Parameter jetPump.HGI.m_c has no value, and is fixed during initialization (fixed=true), using available start value (start=0.0) as default value.\n[C:/Users/leo2rng/Work/PHyMoS/internal/fuelcellmodels/modelica/JetPumpTool/Components/EQS_H2Valve.mo:15:3-15:122:writable] Warning: Parameter jetPump.HGI.m_m has no value, and is fixed during initialization (fixed=true), using available start value (start=0.0) as default value.\nWarning: There are nonlinear iteration variables with default zero start attribute found in NLSJac128. For more information set -d=initialization. In OMEdit Tools->Options->Simulation->Show additional information from the initialization process, in OMNotebook call setCommandLineOptions(\"-d=initialization\").")

@olivleno
Copy link
Author

olivleno commented Jun 3, 2024

The above is just a small part of the full dump.
It is dumped into the julia console while executing OMJulia.API.simulate(...)

Seems like the warnings of the not balanced connector are repeated during simulation.
For the asserts it should be possible to ignore them.
Relevant is to know whether the simulation was successful or not and at which time step it was terminated.

@olivleno
Copy link
Author

olivleno commented Jun 3, 2024

Should I use some simulation option to suppress these outputs?

@AnHeuermann
Copy link
Member

You can try or use some Julia way to suppress outputs, e.g. by redirecting stdout/stderr. But in my experience this can have unwanted side effects because of the zeroMQ instance we are running.
You can also try to disable some of the logging of OpenModelica, e.g. LOG_ASSERT. But if your model is throwing errors it's a better approach to fix them than to ignore them.

Closing this issue, since the original question is answered in #126 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants