Non-liner solver couldn't converge during the initialization in Dymola - modelica

I met an error during initialization when using ThermoSysPro library.
It seems like the Turbine5.Pe is larger than Turbine2.Pe, so the result is negative. but I checked my parameters, there shouldn't be such a problem.
Is this because the nonlinear solver couldn't solve the equation in the following picture?

There is not enough information and I would recommend to set Details and/or Nonlinear iterations in Simulation setup>Debug>Nonlinear solver diagnostics to get more information.
The full expression causing the problem is sqrt((Turbine2.Pe^2-Turbine5.Pe^2)/(Turbine2.Cst*Turbine2.proe.T))
Since the two Pe-values have fixed=true it seems unlikely that they are wrong, but it is impossible to see without the complete model.
However, it is also possible that either Cst or proe.T is negative, or computed to a negative value based on other values.
Without a complete model that is impossible to tell.

According to the comparison between ThermoSysPro(Open source library from EDF https://github.com/alex19941215/ThermoSysPro ) and ThermalPower(Commercial library from Modelon https://www.modelon.com/library/thermal-power-library ), there should be some inspiration for people faced with the same situation.
Here is the code form ThermoSysPro library:
Connectors.FluidInlet Ce
Connectors.FluidOutlet Cs
Here is a type code from Thermal Power library:
Interfaces.FlowPort feed(
h_outflow(start=hstartin))
Interfaces.FlowPort drain(
p(start=pstart),
h_outflow(start=hstartout))
From the code, we can see that in the Thermal Power library each connector's attribute is assigned values according to the parameters, but in the ThermoSysPro library, the connector is using default values, probably zero. So that's why the Thermal Power library has better performance in the term of initialization convergence

Related

MTPA Reference block settings (Simulink)?

I am failrly recent to MATLAB and SIMULINK. I am trying to use to Motor Control blockset in Simulink to implement an FOC algorithm. I am using the MTPA Reference block for Simulink to calculate the Id and Iq currents for me but there are parameters in the block I don't understand. What is the difference between max current and base current ? How do you calculate stator d-axis inductance ? Is this given in the motor datasheet or do we have to calculate it ? And if so, how do I do it ? What is the per-unit (PU) in I/P singal units ? Why would you choose this rather than SI units ? Also is the permanent magnet flux linkage meant to be in the motor datasheet ? I am modelling the iPower Gimbal motor GBM2804H-100T. Please your help would be really appreciated.
MTPA Reference Documentation link: https://www.mathworks.com/help/mcb/ref/mtpacontrolreference.html
I stumbled upon your question today.
Request you to try posting on MATLAB Central for faster response.
Anyway, apologies for delayed response. Pl find your answers below.
What is the difference between max current and base current ?
Max current is motor's rated current. This is also explained in the parameters tab here.
Base current is reference value used while working with PU System. This is usually higher than motor's rated current. Usually, we consider peak ac current as measured by ADCs, to be base value. But you're free to change it to any reference value. It may be same as Max current, may also be different.
How do you calculate stator d-axis inductance ?
For starters, Ld = Ls (total stator inductance) for Surface PMSMs. It's different for IPMSMs.
Is this given in the motor datasheet or do we have to calculate it ? And if so, how do I do it ?
It's usually specified by manufacturers. However, the real motor may have variation w.r.to. design specifications. Hence, you need to run some tests and measure it.
We have a tool to measure the motor parameters. See this link for more details.
What is the per-unit (PU) in I/P signal units ?
You can choose to work with SI units or PU system in the algorithm. We recommend working with PU System for efficient code generation.
For more details, refer to this page.
Try simulation/code-generation of this example. Type the variable name 'PU_System' at MATLAB Command Prompt for details related to base values.
Why would you choose this rather than SI units ?
Computational efficiency for embedded systems.
Scalability.
This is also answered on this page.
Also is the permanent magnet flux linkage meant to be in the motor datasheet ?
No. This is also measured via the parameter estimation tool.
You can also compute the PM flux linkage from backEMF constant or torque constant using the equations mentioned on this page.
I hope this was useful.
Stay safe!
--
Darshan Pandit | MathWorks
For more resources see: MATLAB Central

Is Matlab incorrect for mnrfit?

It seems Matlab is giving incorrect results for multinomial logistic regression.
In their example documentation using Fisher's Iris dataset [link], they give coefficients for the model which can be used on the same data set itself to get the modeled probabilities.
load fisheriris
sp = categorical(species);
[B,dev,stats] = mnrfit(meas,sp);
PHAT=mnrval(B,meas);
However, none of the expected value aggregates match the population aggregates which is a requirement for a MaxEnt classifer (See slide 35 [here], or Eq 14 [here], or Agresti "Categorical Data Analysis" pg 298, etc.)
For example
>> sum(PHAT)
>> 49.9828 49.8715 50.1456
should all equal 50 (population values), likewise for other aggregations
If the parameters
B=[36.9450 42.6378
12.2641 2.4653
14.4401 6.6809
-30.5885 -9.4294
-39.3232 -18.2862]
were used instead then all aggregated sufficient statistics match.
Additionally it seems odd that Matlab is solving it with likelihoods, which can produce an error,
Warning: Maximum likelihood estimation did not converge. Iteration
limit exceeded. You may need to merge categories to increase observed
counts
where the only requirement, proved by MLE consideration, is that the expected values match and no likelihood evaluation is needed.
It would be a nice feature that if instead of true classes are given we can give an option for including just the aggregate information.
Submitted a technical error review within Mathworks website. Their reply:
Hello [----],
I am writing in reference to your Technical Support Case #01820504
regarding 'mnrfit'.
Thanks a lot for your patience and reporting this issue. This appears
to be unexpected behavior. It appears to be related to an existing
issue we have in our records, that "mnrfit" does not give correct
maximum likelihood estimates in certain cases. Since the "mnrfit"
function is not finding the maximum likelihood estimates for the
coefficients, we calculated the actual MLEs. When we use these
estimates, we get the desired result of all 50s in this case.
The issue is that, for this particular dataset in our example, the
classes can be separated perfectly. This means that the logistic
function, in order to get exact zero or one probabilities, needs to
have infinite coefficients. The "mnrfit" function carries out an
iterative procedure with the coefficients getting larger, but it stops
at a point where the results have the issue that you have found. We
certainly agree that "mnrfit" could be made to do better. Our
development team is working on it.
At this stage, I am not able to suggest a workaround other than to
write a custom implementation as my colleague and I had tried. For
now, I will be closing this request as I have already forwarded it to
our records. However, if you have any additional questions related to
this case, please do not hesitate to reach me.
Sincerely,
[----]
MathWorks Technical Support Department

Matlab/Simulink Build error: Unable to honor user-specified priorities

I try to generate code with the embedded matlab coder from a Simulink model.
Then this error occurs: Unable to honor user-specified priorities.
It seems to me that this algebraic loop triggers this error. As you can see in the picture below, there are a higher execution-order at the sum as at the integrator.
I changed the continuous block integrator to an discrete, I put a memory block in the back-path, also an unit-delay-block. But nothing lead to success.
I hope you can give me some approaches to find out a workaround.
Regards
Alex

Modelica.Media.R134a Error

In the Modelica Standard Library 3.2.1 a model for the refrigerant R134a was included, but it seems not to work properly with Modelica.Fluid. In a simple example with one DynamicPipe, it results in the following error:
A calculation of two-phase properties with input of pressure and temperature is not possible.
Please use setState_dTX or setState_phX instead.
The stack of functions is:
setState_pTX_Unique15
setState_pTX_Unique15(101325, 293.15, {1.0}, 0)
use_T_start is false. What is the problem here? How can it be solved?
TIA
Update:
The selected states are h and p, as it should be. The parameters of the pTX call seem to be the default values for the chosen medium.
PartialStaggeredFlowModel uses Medium.density_pTX and Medium.setState_pTX, but changing these to the respective phX-functions does not solve the problem.
The issue here is your choice of thermodynamic states. As the message indicates, you cannot use a two-phase medium with pressure and temperature as the thermodynamic states.
As a simple example, consider water/ice. If you measure the temperature as it is freezing, you'll see that when the mixture is "slushy" (contains both liquid and solid), the temperature will remain constant. So knowing the temperature is not sufficient to know the true (thermodynamic) state of the system because we cannot compute the relative fractions of liquid and solid with that information. The solution is to use pressure and enthalpy (as the error message suggests) as the thermodynamic states.
I don't know enough about the Modelica.Media and Modelica.Fluid libraries to tell you how to change your selection of thermodynamic states. But I suspect you'll find the answer in the documentation of one of those libraries.
The solution is already in my update. PartialStaggeredFlowModel uses Medium.density_pTX and Medium.setState_pTX. Replacing these with Medium.density_phX and Medium.setState_phX avoids the pT-problem. The reason why it did not work at first was one reference to the unmodified class I forgot to change.
Other Modelica.Fluid-components have the same problem, e.g. the pump-models are based on PartialPump, which also uses Medium.density_pTX.
Thank you for your contributions.

Input connector problems in custom modelica models with custom media

I am currently working with a Modelica model in Dymola to simulate a chemical process. The reactor modeling itself is done to a satisfying extent, but I'm having a hard time implementing these models into Modelica, especially with respect to getting the various Media definitions to interconnect and communicate, so to speak. This is also the key achievement of the Modelica implementation of the model.
At the moment I'm struggling with a specific type of error which, even though it appears quite obvious and straight-forward, I find relatively hard to solve. The errors are of the type:
Note: The input connector p of coopolReactor_2706_1.medium is not connected from the outside.
It is likely that it should have been connected, and recursive check will assume this.
The missing connection is a likely cause of errors in the model.
Note: The input connector h of coopolReactor_2706_1.medium is not connected from the outside.
It is likely that it should have been connected, and recursive check will assume this.
The missing connection is a likely cause of errors in the model.
The model has the same number of unknowns and equations.
The model has the same number of unknowns and equations.
The model EmulsionPolymerizationToolbox.Test.Test_2706 component coopolReactor_2706_1 is structurally singular.
when assuming the most generic outside couplings to all the flow variables of its connectors.
In the specific code which gave this error message, I've mimic'ed a simple lumped volume extending base classes from the Modelica Standard Library, but the error is still the same as for my complete reactor models. That's why understanding and solving this problem is vital to the progress of my assignment.
I've been searching a bit online to find out more about what could cause this problem, without much luck. Could someone please elaborate a bit on these kind of errors, and maybe even suggest solutions? Any inputs from this board will be useful to me.
Thanks in advance.
Regards, Fredrik.
It's possible this is actually a Red Herring. It appears as though this message is generated because of an imbalance in equations. Dymola then searches for the source. It may be that when it seems an imbalance in your component, it also notices that you have an unconnected input and reports that, even if that may not be your problem.
Another thing to keep in mind is that one of the new features in Modelica 3.x was the addition of rules about local balancing of equations and unknowns. One impact of these rules was that for medium models to be balanced, it was necessary to mark some of the variables as inputs (implying they would be specified from the outside). This use of the input qualifier isn't meant to indicate that these variables need to be connected to (or even specified via equations or modifications). Instead, it is really just a way of indicating how many equations are provided by the media model and how many are provided outside.
So where does this leave you. Well, I could be completely wrong (let's not overlook that possibility). But if I'm right, this indicates that you have an imbalance that has nothing to do "unconnected inputs". I suppose the only real help my answer gives is to encourage you to look for other "missing" equations.
If you actually posted code of your simple case, someone might be able to spot the missing equation.