I am trying to understand the process of solving DAEs in Dymola. According to Chapter 13.8 of Dymola's help document, Dymola would first use an index reduction algorithm to transform the original DAE into ODE, then get a BLT form after partitioning and tearing, so Dymola could solve ODE with BDF method like DASSL.
Here is the screenshot of Dymola's help document.
I also found some material about how to solve DAE from Wolfram mathematica, as shown in the following screenshot, there could be different strategies in different phases, I marked the method I think adopted in Dymola. My question is:
Does Dymola just adopt the method as I marked?
Or Dymola also adopt the method as Wolfram Mathematica, which is using different methods in different phases? If so, how does Dymola determine using which method?
Dymola does something resembling that red line, and ignoring many of the choices in that flow-chart as they are not relevant and there many equally important choices hidden.
E.g.,
The index reduction algorithm will work even if the index is 1 or 0 - it will just not do anything.
The dummy derivatives method can be seen as a projection method. (I did my master's thesis on implementing it a long time ago.)
IDAS is one of the solvers in the sundials suite. Dymola can use sundials solvers for integration, as well as a number of other solvers; and both have the model as ODE or as index 1 DAE for suitable solvers - but that's handled in the generated C-code, and doesn't influence other parts.
Related
Here is the link of the model:https://mbe.modelica.university/behavior/discrete/decay/#chattering
The simulation result for the following result in Dymola 2021 would be:
model WithChatter(stopTime=1.001s)
model WithChatter(stopTime=1.5s)
As we could see, noEvent operator does decrease the CPUTime, but it also causes the system stiff, it would be easier to understand with more explanation about why noEvent would cause the system stiff.
Based on the event logging of model WithChatter, the simulation process actually uses the minimum time step because the der(x) is not a continuous function. But why doesn't this approach suit the model WithNoEvents?(https://mbe.modelica.university/behavior/discrete/decay/#speed-vs-accuracy)
If noEvent operator means using the integrator directly, it might require the functions in the equation system have to be continuous? So Does this mean that the model used in the Chattering example(https://mbe.modelica.university/behavior/discrete/decay/#chattering) isn't appropriate, since the function in this model is not continuous?
The model used in the chattering example isn't appropriate since it is not continuous, and the error message from dassl is just a boiler-plate message, so the model isn't stiff but discontinuous as you found.
Markus A has a good point in the related question When to use noEvent operator in Modelica language? that using noEvent to avoid chattering is in general not a good idea, and one should normally try to rewrite the model instead of adding noEvent.
This specific model is sort of similar to a friction model where you would have
der(v)=(if v>=0 then -1 else 1)+f_other/m;
The solution for friction is not to introduce noEvent, but to add a stuck mode as in Modelica.Mechanics.Rotational.Components.BearingFriction.
Has anyone tried to implement the Navier Stokes Partial Differential Equations (PDE) in Modelica?
I found the method of the spatial basis functions (SBF) which by means of numerical modifications gets Ordinary Differential Equations (ODE) that could be handled by Dymola.
Regards,
Victor
The aim of the method I was saying before is to convert PDEs in ODEs, so the issues with the CFL coefficient would disappear, the problem is that the Modelica.Fluids elements just define the equations in function of the variables in both ends of each component.
i.e dp=port_a.p-port_b.p
but with that sort of methodology, the variables such as pressure, density, mass flow... would be function also of the surrounding components... it would be a kind of massive interaction between all the components,
I would like to see an example in Modelica, because I hardly haven't found information about that topic linked to Modelica.
Modelica is a language for modeling behavior described by DAEs. As such, as long as you can create a system of ODEs, you should be able to express your problem in Modelica.
However, if your PDEs are hyperbolic, the wave dynamics in the equations might cause some issues with simulation. This is because the CFL condition imposes limits on time steps that an ordinary differential equation solver will be unaware of. If the solver includes error control, it will probably manage to get a solutions but may run quite slow because it won't know how to explicitly limit the simulation step size. If it doesn't include error control and it violates the CFL condition, the system will go unstable. Note, this only applies to systems where the CFL condition applies.
I'm building a Media-Library in Dymola similar to Helmholtz-Media but for Ammonia+Water, a mixture.
You get a lot of not explicitly solvable equations.
Because of the structure of the Media and Fluid libraries in Modelica I need to be able to get my thermodynamic state from p, h and x. The state-vector consists of d, T, and x.
This is a simple example how to get the state-vector:
model getState_phX
parameter AbsolutePressure p = 500000 "pressure";
parameter SpecificEnthalpy h = 2500000 "enthalpy";
parameter SI.MassFraction x = 0.7 "mole fraction of amonia";
parameter Real[2] start = getStart_Td_phx(p,h,xL);
output ThermodynamicState state(d(start=start[2]),T(start=start[1]),X={(1 - xL),xL});
DerivateFull f = Derivates(state);
equation
p = (1 + f.delta*f.phirdelta)*R*state.T*state.d/molarMass(state);
h = state.T*R*(1 + f.delta*f.phirdelta + f.tau*f.phirtau + f.tau0*f.phi0tau0)/molarMass(state);
end getState_phX;
Please don't mind the parts of the equations. They consist of many parts (sums and log) dependent on the state-vector.
This is solved by the solver in Dymola with good start values.
But I don't really need all of the 'time-dependent' solving capabilities of Dassl.
Are there build in libraries for solving such stationary equation systems without the solver?
Is it possible to make a Function out of this Model using these?
I know I could write a simple solver by hand but for other parts of the Media-Model (VLE) I need highly reliable stationary solver too (but with 4 nonlinear independent equations)
Please tell me if I didn't explain myself clearly. Thank you for the help.
The basis of your fluid properties library is a forward part, that is the actual Helmholtz energy equation of state (EoS). It takes d,T,X as input. That part is more or less straigthforward to implement.
If you want to specify the thermodynamic state using p,h,X or if you want to find the equilibrium between multiple phases, you will usually set up a system of resdiual functions and try to find the root of your system of equations using some iterative procedures. Span (2000) writes
"the formulation of reliable iterative procedures [for root finding]
is often the most crucial problem when setting up program packages for
the evaluation of equations of state".
Re-using existing solvers has advantages and disadvantages, they are usually very well tested, writing them takes a lot of effort, but if you write your own solver, you have more control about what it does. As far as I know, Dassl has various strength, but solving that kind of equations is not its original objective.
Olson, Tummescheit and Elmqvist (2005) tried to use the Dymola solver to find the VLE, see section 3.2 of the linked pdf. Sounds like it works, but not very reliable.
The MSL already includes a non-linear solver, based on the Brent algorithm, which works with one unknown only, see Modelica.Math.Nolinear.solveOneNonlinearEquation. You could, if you want, add additional generic solvers.
Before writing your own solver, you should get in touch with the developers of the Modelica.Media interface (it will be extended in future versions of the MSL to include multi-component, multi-phase mixtures) and also consider re-using existing fluid properties libraries like RefProp, CoolProp, FluidProp or MultiFlash, to name just a few.
I am constructing a finite volume model in Dymola which evolves in time and space. The spatial discretization is hard coded in the equations section, the time evolution is implemented with a term consisting of der(phi).
Is the time integration of Dymola always numerically stable when using a variable step size algorithm? If not, can I do something about that?
Is the Euler integration algorithm from Dymola the explicit or implicit Euler method?
The Dymola Euler solver by default is explicit (if an in-line sovler is not selected).
The stability of time integration is going to depend on your integrator. Generally speaking, implicit methods are going to be much better than explicit ones.
But since you mention spatial and time discretization, I think it is worth pointing out that for certain classes of problems things can get pretty sticky. In general, I think elliptic and parabolic PDEs are pretty safe to solve in this way. But hyperbolic PDEs can get very tricky.
For example, the Courant-Friedrichs-Lewy condition will affect the overall stability of the solution method. But by discretizing in space first, you leave the solver with information only regarding time and it cannot check or conform to the CFL condition. My guess is that a variable time step integrator will detect the error being introduced by not following the CFL condition but that it will struggle to identify the proper time step and probably also end up permitting an unacceptably unstable solution.
I have to solve a multiobjective problem but I don't know if I should use CPLEX or Matlab. Can you explain the advantage and disadvantage of both tools.
Thank you very much!
This is really a question about choosing the most suitable modeling approach in the presence of multiple objectives, rather than deciding between CPLEX or MATLAB.
Multi-criteria Decision making is a whole sub-field in itself. Take a look at: http://en.wikipedia.org/wiki/Multi-objective_optimization.
Once you have decided on the approach and formulated your problem (either by collapsing your multiple objectives into a weighted one, or as series of linear programs) either tool will do the job for you.
Since you are familiar with MATLAB, you can start by using it to solve a series of linear programs (a goal programming approach). This page by Mathworks has a few examples with step-by-step details: http://www.mathworks.com/discovery/multiobjective-optimization.html to get you started.
Probably this question is not a matter of your current concern. However my answer is rather universal, so let me post it here.
If solving a multiobjective problem means deriving a specific Pareto optimal solution, then you need to solve a single-objective problem obtained by scalarizing (aggregating) the objectives. The type of scalarization and values of its parameters (if any) depend on decision maker's preferences, e.g. how he/she/you want(s) to prioritize different objectives when they conflict with each other. Weighted sum, achievement scalarization (a.k.a. weighted Chebyshev), and lexicographic optimization are the most widespread types. They have different advantages and disadvantages, so there is no universal recommendation here.
CPLEX is preferred in the case, where (A) your scalarized problem belongs to the class solved by CPLEX (obviously), e.g. it is a [mixed integer] linear/quadratic problem, and (B) the problem is complex enough for computational time to be essential. CPLEX is specialized in the narrow class of problems, and should be much faster than Matlab in complex cases.
You do not have to limit the choice of multiobjective methods to the ones offered by Matlab/CPLEX or other solvers (which are usually narrow). It is easy to formulate a scalarized problem by yourself, and then run appropriate single-objective optimization (source: it is one of my main research fields, see e.g. implementation for the class of knapsack problems). The issue boils down to finding a suitable single-objective solver.
If you want to obtain some general information about the whole Pareto optimal set, I recommend to start with deriving the nadir and the ideal objective vectors.
If you want to derive a representation of the Pareto optimal set, besides the mentioned population based-heuristics such as GAs, there are exact methods developed for specific classes of problems. Examples: a library implemented in Julia, a recently published method.
All concepts mentioned here are described in the comprehensive book by Miettinen (1999).
Can cplex solve a pareto type multiobjective one? All i know is that it can solve a simple goal programming by defining the lexicographical objs, or it uses the weighted sum to change weights gradually with sensitivity information and "enumerate" the pareto front, which highly depends on the weights and looks very subjective.
You can refer here as how cplex solves the bi-objetive one, which seems not good.
For a true pareto way which includes the ranking, i only know some GA variants can do like NSGA-II.
A different approach would be to use a domain-specific modeling language for mathematical optimization like YALMIP (or JUMP.jl if you like to give Julia a try). There you can write your optimization problem with Matlab with some extra YALMIP functionalities and use CPLEX (or any other supported solver as a backend) without restricting to one solver.