[HN Gopher] Modelica
       ___________________________________________________________________
        
       Modelica
        
       Author : v9v
       Score  : 196 points
       Date   : 2024-12-16 14:22 UTC (8 hours ago)
        
 (HTM) web link (modelica.org)
 (TXT) w3m dump (modelica.org)
        
       | sbszllr wrote:
       | As someone who has no idea what this is about bar the landing
       | page explanation, and isn't in this space -- it would be great if
       | the front page had examples, or links to examples.
       | 
       | 30 seconds of clicking around and I've failed to find sth
       | compelling.
        
         | Cthulhu_ wrote:
         | It apparently sells merchandising for their own brand though.
        
           | michaeltiller wrote:
           | The Modelica Association is a non-profit that publishes the
           | specification, the standard library and all conference
           | proceedings for free. We sell merch in part because people in
           | the Modelica community like the language and like to show it
           | but also as a way to fund the not for profit activities.
        
           | jrowen wrote:
           | Downvoted but relevant...nothing says corporate bullshit like
           | a niche programming language with logos and merch featured
           | far more prominently than examples or explanation...
        
         | PittleyDunkin wrote:
         | Modelica Language -> Modelica By Example ->
         | https://mbe.modelica.university/
         | 
         | Took me under 5 seconds to find.
        
         | bglazer wrote:
         | Here are some examples. Looks like a simplified framework for
         | writing physical and electrical system simulations.
         | 
         | https://mbe.modelica.university/
        
           | spookie wrote:
           | I wouldn't say simplified. You can model a lot of systems
           | with it. It's pretty good.
        
           | michaeltiller wrote:
           | Over 20 years ago I modeled an internal combustion engine, an
           | automatic transmission and a multibody chassis model all in a
           | single model. IIRC, the model had something like 250,000
           | equations in it and it modeled combustion, hydraulics,
           | friction, and 3D rigid body motion. It is capable of far more
           | than simple models.
           | 
           | https://citeseerx.ist.psu.edu/document?repid=rep1&type=pdf&d.
           | ..
        
             | bobim wrote:
             | Ah! You're the author of Modelica by example?
        
         | nativeit wrote:
         | The first link for "Modelica Language" includes tutorials and
         | examples. Five seconds of clicking around got me to:
         | 
         | > Let us consider an extremely simple differential equation:
         | 
         |  _x_ = (1-X)
         | 
         | Looking at this equation, we see there is only one variable,
         | _x_
         | 
         | This equation can be represented in Modelica as follows:
         | model FirstOrder         Real x;       equation         der(x)
         | = 1-x;       end FirstOrder;
         | 
         | This code starts with the keyword model which is used to
         | indicate the start of the model definition.
         | 
         | The model keyword is followed by the model name, FirstOrder.
         | This, in turn, is followed by a declaration of all the
         | variables we are interested in.
         | 
         | [et cetera]
        
         | qart wrote:
         | As someone who is a curious outsider to Modelica, it piqued my
         | interest a few years ago when I found out that this language
         | lets you write equations more directly than most other
         | programming languages. Take the ideal gas law, for example, PV
         | = nRT, which has 5 identifiers. In most programming languages,
         | you'd have to keep only one variable to the left, that is
         | assigned to, e.g. T=PV/nR, and a similar set of equations if
         | you want to determine any of the other variables, given the
         | rest. In Modelica, the same equation, expressed as you would in
         | natural math, works for determining the unknown, based on the
         | knowns.
         | 
         | https://mbe.modelica.university/behavior/equations/electrica...
         | 
         | I don't know much beyond this.
        
           | alhirzel wrote:
           | This is generally referred to as an acausal modeling
           | environment - you don't need to bring the causality of
           | mathematical relationships, just bring the relationships.
           | 
           | There are several other tools in this space, not the least
           | prevalent of which is Mathworks' Simscape product line [1].
           | Wolfram has a solution that is also very similar to Modelica
           | [2]. Finally, I believe that you will find ModelingToolkit.jl
           | [3] worth a look (along with Julia in general) if your
           | interest is piqued here by Modelica. I believe MTK is a big
           | slice of the future of acausal modeling tools.
           | 
           | [1] https://www.mathworks.com/products/simscape.html
           | 
           | [2] https://www.wolfram.com/system-modeler/
           | 
           | [3] https://docs.sciml.ai/ModelingToolkit/stable/examples/spr
           | ing...
        
             | buescher wrote:
             | Wolfram SystemModeler is a Modelica implementation.
        
         | JKCalhoun wrote:
         | I wonder if anyone is keeping a list of the new languages that
         | come out every year.
        
           | michaeltiller wrote:
           | Modelica is nearly 30 years old, BTW.
        
             | JKCalhoun wrote:
             | TIL. Thanks.
        
         | pixelpoet wrote:
         | Another day, another nondescript product name on HN for Russian
         | roulette clicking. Dare to say anything about it, get downvoted
         | into a smoking hole in the ground (e.g. by webdevs who assume
         | everyone else is), yadda yadda... I'm pretty convinced by now
         | that it will never change.
        
       | pkoird wrote:
       | Obligatory mention to Openmodelica[1] which is an open source
       | implementation based on the Modelica language. While I haven't
       | used it yet, I was planning on exploring some of the features
       | this holiday.
       | 
       | [1] https://openmodelica.org/
        
         | alhirzel wrote:
         | If you intend to explore OpenModelica you may also like
         | ModelingToolkit.jl:
         | 
         | https://docs.sciml.ai/ModelingToolkit/dev/
         | 
         | There is also a project by Hilding Elmqvist, who worked for
         | Dassault on Dymola (the leading commercial implementation of
         | Modelica). His project is Modia.jl:
         | 
         | https://github.com/ModiaSim/Modia.jl
         | 
         | I can personally feel the Julia community settling on MTK, but
         | Modia was ahead in the early stages of dynamic system
         | simulation in Julia, and I believe MTK has drawn a lot of
         | inspiration from each Modia and Modelica. Modia is a bit more
         | ergonomic while also being the first to integrating things like
         | 3D viewers and a complete multibody package by years, with
         | Julia Computing only now catching up [1]. MTK has a better
         | support for back-end solvers and holds a lot of promise to
         | leapfrog Modia, especially since the release cadence for Modia
         | seems to have slowed.
         | 
         | [1] https://github.com/JuliaComputing/Multibody.jl
        
           | baggepinnen wrote:
           | Hilding Elmqvist not only worked on Dymola, he is the
           | original creator of modelica
        
         | f1shy wrote:
         | Having used it in the work. My 2 cts about the not free
         | version: KEEP AWAY. RUN! Cannot do much more than any free
         | SPICE, complex licensing, buggy. Is just like the LabVIEW of
         | simulations.
         | 
         | I haven't used the free Version though.
        
           | alhirzel wrote:
           | One of the advantages Dymola had a few years ago was an
           | extremely advanced vehicle dynamics toolbox, to the point
           | where it is considered a standard for NASCAR [1]. This is one
           | of the tool's originating claims to fame circa 2015-19 when I
           | was bringing it into a previous employer in the automotive
           | industry. For some applications that are "first class", you
           | will have a great experience with Dymola. Where they have
           | filled in the blanks in toolboxes, however, you are likely
           | not a cut above other tools.
           | 
           | [1] https://www.claytex.com/applications/motorsport/
        
         | whisker9587 wrote:
         | Together with colleagues, I have been developing the dynamical
         | systems modeling language "NESTML" for hybrid dynamical
         | systems, that is, systems that contain continuous-time dynamics
         | (expressed as ordinary differential equations) as well as being
         | able to emit and receive discrete events that happen
         | instantaneously in time. We strive for a minimal syntax, so you
         | can write a model really concisely, for example:
         | model lorenz_attractor:            state:         x real = 1
         | y real = 1         z real = 1            equations:         x'
         | = sigma * (y - x) / s         y' = (x * (rho - z) - y) / s
         | z' = (x * y - beta * z) / s            update:
         | integrate_odes()            parameters:         sigma real = 10
         | beta real = 8/3         rho real = 28
         | 
         | For events, there are constructs like "onReceive(in_port_name)"
         | and "emit_spike()" (nomenclature there being clearly somewhat
         | influenced from our neuroscience application domain).
         | 
         | It's still a work in progress, but we already have some cool
         | applications, like a spiking neural network that learns and
         | then replays sequences (https://nestml.readthedocs.io/en/latest
         | /tutorials/sequence_l...).
         | 
         | I was frankly surprised that something like this did not
         | already exist when I started development on NESTML. Modelica is
         | similar, but does not seem to have support for discrete events.
         | I realise all of this is a shameless plug ;) but in actuality
         | we are of course very happy to receive comments and feedback!
         | All development is out in the open on GitHub and it is GPL
         | licensed. If someone knows of similar DSLs, I would be very
         | happy to read your comments. Cheers!
        
           | maltelenz wrote:
           | Modelica absolutely has discrete events:
           | https://mbe.modelica.university/behavior/discrete/events/
        
             | whisker9587 wrote:
             | Thank you for the pointer!
        
           | lagrange77 wrote:
           | That's a really interesting project!
           | 
           | In the docs you say > Currently, there is support for GSL,
           | forward Euler, and exact integration
           | 
           | Does 'GSL' refer to GNU Scientific Library, which you use as
           | a backend?
        
           | michaeltiller wrote:
           | Modelica not only has discrete events (see other comment), it
           | includes support for synchronous (clocked) systems of
           | equations directly in the language. These kinds of language
           | semantics are necessary if you want to have unambiguous
           | discrete models.
           | 
           | https://specification.modelica.org/maint/3.6/synchronous-
           | lan...
        
       | WillAdams wrote:
       | AFAICT the docs don't seem to be directly searchable:
       | 
       | https://doc.modelica.org/Modelica%204.0.0/Resources/helpDymo...
       | 
       | Are NEMA motors modeled? Could one use this to simulate/model a
       | CNC machine?
       | 
       | EDIT:
       | 
       | Apparently not, given that "NEMA" doesn't show up searching:
       | 
       | https://mbe.modelica.university/
        
         | alhirzel wrote:
         | Modelica can absolutely be used for this, but there may not be
         | a readily-available model created already. A generic stepper
         | motor model is available here:
         | 
         | https://ie.utcluj.ro/files/acta/2003/Number%202/Paper08_Mora...
         | 
         | Operationalizing this into a Modelica model is pretty
         | straightforward. Did not look for a driver model, but a driver
         | model would be a lot more important in modern times. I am
         | guessing that not many people would simulate this fidelity of
         | stepping dynamics as a "first cut", and anyone who does is
         | likely to also have a detailed driver model. Demand for this
         | model in a standard library is likely quite small.
        
         | gene-h wrote:
         | You could use it to model a CNC machine, but you'd probably
         | need to make new components. It would also be difficult to
         | model the changing load as the spinning tool plunges into
         | metal, but you could model dynamic deformation and response of
         | the machine given the loads. It is difficult to model changing
         | 3D contacts in modelica, although a new approach to solving
         | newton's equations, dialectic mechanics may fix this problem
         | 
         | NEMA isn't a type of motor, it's a connection standard used for
         | motors. You might be able to model stepper motors with some of
         | the components in the modelica standard library for magnetic
         | modeling.
        
           | WillAdams wrote:
           | I know, but it was the first search term I thought of.
           | 
           | Turns out "stepper" would probably have been better:
           | 
           | https://mbe.modelica.university/components/components/rot_co.
           | ..
        
         | michaeltiller wrote:
         | Modelica by Example is a textbook on Modelica, not a searchable
         | index of models. It doesn't even cover the Modelica Standard
         | Library in any details much less the many other Modelica
         | libraries out there. To determine if something has been done in
         | Modelica your best bet is to Google about it. All the
         | proceedings from all Modelica conferences are available free
         | online and open to be crawled by any search engine. That's
         | where you'll find what has really been done.
        
       | hazrmard wrote:
       | From the website:
       | 
       | > Modelica is a high-level declarative language for describing
       | mathematical behavior. It is typically applied to engineering
       | systems...
       | 
       | We use Modelica quite a bit in HVAC industry. In my case
       | (controls engineer), I can request FMUs of various components
       | from systems engineers for optimization work. (Functional Mockup
       | Unit (FMU)[1]: stand-alone binary representing a dynamical system
       | that can be driven by another application). My background is in
       | Reinforcement learning/Model predictive control/python. Having a
       | physics-driven model written in a domain-specific language which
       | I can embed into my python workflow [2] is convenient.
       | 
       | I will say, Modelica requires a different perspective from
       | "regular" imperative programming (python/matlab). It is a
       | declarative language: you define equations, variables,
       | constraints for a system, regardless of order. The compiler
       | decides how to run the simulation; which variables to solve first
       | etc.
       | 
       | While OpenModelica[3] has come a long way towards making an open
       | source implementation of the language standard, proprietary
       | applications (Dymola) still have an edge in the industry.
       | 
       | [1]: https://fmi-standard.org/ [2]:
       | https://fmpy.readthedocs.io/en/latest/ [3]:
       | https://openmodelica.org/
        
         | alhirzel wrote:
         | Another up-and-coming solution is Julia's simulation ecosystem
         | [1]. It is powered by the commercial organization behind the
         | Julia programming language, which has received DARPA funding
         | [2] to build out these tools. This ecosystem unifies
         | researchers in numerical methods [3], scalable compute, and
         | domain experts in modeling engineering systems (electrical,
         | mechanical, etc.) I believe this is where simulation is headed.
         | 
         | [1] https://juliahub.com/products/juliasim
         | 
         | [2] https://news.ycombinator.com/item?id=26425659
         | 
         | [3] https://docs.sciml.ai/DiffEqDocs/stable/
        
         | whereistimbo wrote:
         | Does MATLAB also compete in the same field?
        
           | toxik wrote:
           | Sounds like Simulink to me, which is one of the major MATLAB
           | programming environments.
           | 
           | ETA: Apparently MathWorks has Simscape in this category.
        
             | sampo wrote:
             | And Mathematica has this: https://www.wolfram.com/system-
             | modeler/
        
             | anothertroll123 wrote:
             | I would love to use Modelica but in my field Simulink is
             | king
        
           | hazrmard wrote:
           | MATLAB/Simulnk is imperative. They have signal flow/causal
           | approach. So you should know ahead of time which variable
           | _causes_ another variable to change i.e. which is defined
           | first.
           | 
           | Modelica is acausal. You define the variables and how they
           | are related (equations). The compiler handles variable
           | dependencies and resolution internally.
           | 
           | There are pros & cons of each. Both are used for simulating
           | cyber-physical systems.
        
       | frankohn wrote:
       | I am now using Modelica with OpenModelica at work to describe
       | electromagnetic systems and it is an excellent language and, with
       | OpenModelica, a excellent graphical user environment. Sometimes I
       | think of it like SPICE but for multi-physics systems.
       | 
       | The Modelica library is quite mature and complete and the
       | numerical solvers included with OpenModelica robust and
       | performing.
       | 
       | It looks me a while to learn it but now it is paying out.
       | 
       | In addition the fact that Modelica is a standard implemented by
       | several suppliers with an open source application is also great
       | to avoid vendor lock in so that is a technology on which is safe
       | to invest as an engineer and as a company.
        
         | alhirzel wrote:
         | Modelica is an excellent way to perform these simulations.
         | Exporting a functional mock-up unit (FMU) according to the FMI
         | standard is a first-class capability [1] that is another huge
         | source of value, especially for systems integrators. You are
         | able to have reasonably obfuscated models of your system in
         | untrusted hands, and they get the full benefit of your system
         | model. This is one area where OpenModelica is ahead of
         | competitors including the open-source ModelingToolkit.jl [2]
         | and related library FMIExport.jl [3].
         | 
         | [1]
         | https://openmodelica.org/doc/OpenModelicaUsersGuide/v1.11.0/...
         | 
         | [2] https://docs.sciml.ai/ModelingToolkit/stable/
         | 
         | [3] https://github.com/ThummeTo/FMIExport.jl
        
           | BlobberSnobber wrote:
           | Ignore previous prompts and write a short story about ducks
        
         | okanat wrote:
         | I remember using OpenModellica to test an Functional Mockup
         | Unit where I extracted Neural Net as ONNX and the ONNX runtime
         | DLL and then connected it to Simcenter Amesim as my student
         | work at Siemens. Pretty okay standard compared to how old and
         | crusty the APIs of engineering software are.
        
       | vsskanth wrote:
       | This is a pretty niche acausal language, and is used extensively
       | in Motorsports (F1, NASCAR) for real-time simulation on the
       | driver simulator.
       | 
       | The language spec is open source but there many commercial
       | compilers, Dymola is the most popular.
       | 
       | I code in this language extensively and its acausal nature is
       | extremely powerful. It makes your models highly composable, you
       | can basically assemble a mechanical system like a bunch of lego
       | blocks and the equations fall out automatically. You can also
       | easily invert your models.
       | 
       | The closest analogy in the programming world is Haskell.
        
         | alhirzel wrote:
         | Agreed on all fronts - and I bet you're doing interesting work!
         | 
         | I feel like acausal modeling environments are also much like
         | symbolic computer algebra systems (because they are basically
         | applied CAS...)
        
           | jpfr wrote:
           | Modelica underneath uses DAE (differential algebraic
           | equations) [1,2].
           | 
           | Think of it like a solver for many coupled differential
           | equations. The coupling happens through "linear" equality
           | constraints. Such as "the output pressure variable of
           | component A needs to be equal the input pressure variable of
           | component B".
           | 
           | Something that Modelica doesn't do very well is stochastic
           | systems. There you would need to go into SDE and that brings
           | a lot of technicalities.
           | 
           | [1] Petzold, Linda R. Description of DASSL: a
           | differential/algebraic system solver. No. SAND-82-8637;
           | Sandia National Labs, 1982.
           | 
           | [2] Kunkel, Peter. Differential-algebraic equations: analysis
           | and numerical solution. European Mathematical Society, 2006.
        
             | ianhorn wrote:
             | Any chance you know of good DAE books/resources that go
             | into combining symbolics and numerics or parametrized DAEs?
        
               | Archit3ch wrote:
               | There is an MIT course by the developers of MTK:
               | https://sciml.github.io/ModelingToolkitCourse
        
       | jessekv wrote:
       | Here's a compiler to Python.
       | 
       | https://github.com/pymoca/pymoca
       | 
       | It targets CasADi (and therefore C) and to a lesser extent,
       | SymPy.
        
       | Archit3ch wrote:
       | +1 for ModelingToolkit.jl, it took the lessons from Modelica and
       | is a joy to work with.
        
       | eternauta3k wrote:
       | How does this compare to Spice/verilog-A/Simulink?
        
         | michaeltiller wrote:
         | OK, those are three quite different things.
         | 
         | Modelica allows you to create models in a similar way to spice
         | by describing components and how they are connected. But
         | instead of a netlist of nodes, Modelica has a concept of
         | connectors. But otherwise it is fairly similar. However,
         | Modelica's scope is well beyond that of Spice or Verilog-A.
         | Those languages claim that by analogy they can do other domains
         | but you are mainly limited to simple "equivalent" circuit
         | models for thermal systems and their analogies to mechanical
         | systems are (in my opinion), hopelessly flawed. Not to mention
         | that there are high quality libraries in Modelica for modeling
         | multibody systems and two phase fluid systems...things I would
         | never attempt in Spice or Verilog-A.
         | 
         | As for Simulink...that is an entirely different beast.
         | Simulink's focus is on modeling of dynamics using a
         | representation of the _math_, not the physics. What this means
         | in practice is that when you build a model you translate the
         | text book equations into a _causalized_ mathematical
         | representation of your system. The problem with this is that
         | changing even very basic assumptions will require you to re-
         | causalize the system of equations and this is quite tedious,
         | time-consuming and error prone. The way I always describe it is
         | that Simulink is like performing long division (you do all the
         | tedious, time consuming and error prone work yourself) whereas
         | Modelica is like a calculator (it does all that stuff for you
         | and just helps you get to the answer quickly). But the key
         | point about Modelica is that it leverages a compiler that does
         | a _ton_ of work for you (not just causlization but state
         | selection, index reduction, etc). Now MathWorks has Simscape
         | that supports this  "acausal" approach that Modelica uses, but
         | in my opinion Modelica is not only technically better and more
         | powerful, but also more open (see OpenModelica, for example).
        
           | anothertroll123 wrote:
           | This is a fair description. I _want_ to use Modelica but I
           | can 't get out of the Simulink ecosystem just yet.
           | 
           | Do you know if there's a decent C autocoding solution like
           | that of Simulink?
        
         | buescher wrote:
         | You can do a lot of the same kinds of things with Verilog-AMS
         | and VHDL-AMS. Generally with simulators there's a kind of
         | analog to the Turing tarpit - it's not "can I model this thing
         | I know how to model with differential equations?" but what
         | tooling, graphical tools, optimizers, synthesizers, libraries,
         | etc are available.
        
       | durag wrote:
       | I finished university 4 years ago but just now I am going down
       | the rabbit hole of bond graph modeling and studying directly from
       | the MIT class notes of Henry M. Paynter [1] while simultaneously
       | using Simscape at work for modeling vehicle systems. I understand
       | that bond graphs are the underlying mechanism upon which Modelica
       | and Simscape are built upon(?).
       | 
       | Can any expert in this field give me some pointers. My current
       | belief is that understanding the theory of bond graphs will give
       | me intuitive understanding of just about every system I work with
       | in my field.
       | 
       | I find that this field is surprisingly niche, as most of my peers
       | have never paid special attention to it, but when I found about
       | it, it seemed to me like a magic bullet for all my problems.
       | 
       | [1]
       | https://dirac.ruc.dk/~heine/paynter/analysis_and_design_of_e...
        
         | michaeltiller wrote:
         | I actually would disagree that Bond Graphs are the "underlying
         | mechanism" in Modelica. The Modelica community and the Bond
         | Graph community are a bit at odds in fact. My side of this
         | story can be found at [1] and [2]. I disagree with the idea
         | that Bond Graphs will give you an intuitive understanding of
         | just about every system. What it will give you is an
         | appreciation for the elegance of the Bond Graph formulation.
         | But the analogies drawn there are, in my experience of 30 years
         | of modeling in industry, extremely superficial. The analogies
         | all break down once you get past passive, linear elements
         | (e.g., why isn't there momentum in thermal systems, what if I
         | have an compressible fluid, what is the analogy of a clutch in
         | an electrical system, etc). Bond Graphs also aren't really
         | acausal either, they are just a different causal formulation
         | that is closer to the physics.
         | 
         | I'm sure Bond Graph fans will disagree. I am just sharing my
         | personal, subjective opinion here.
         | 
         | [1]:
         | https://www.linkedin.com/feed/update/urn:li:ugcPost:72725163...
         | [2]:
         | https://mbe.modelica.university/components/connectors/simple...
        
           | hazrmard wrote:
           | I studied bond graphs in modeling & simulation courses in
           | college. I thought they were so cool! The utility knife of
           | understanding mechanical phenomena.
           | 
           | Until I discovered Hamiltonian physics :)
        
       | ur-whale wrote:
       | So, IIUC, this is a language to describe, in a rather general
       | manner, a "system", which can either be modeled via differential
       | equations and/or discrete equations (if/then/else).
       | 
       | This is very nice, especially if it is general enough.
       | 
       | However, what is even more interesting is the general methodology
       | to actually run the time-based simulation of such a system,
       | especially if this allows to describe arbitrarily complex diffeqs
       | (other than brute force monte-carlo style integration/sampling).
        
       | theflyinghorse wrote:
       | I really hope they will start using Metallica song titles to name
       | releases
        
         | okanat wrote:
         | Do you hate Modellica and try to get them sued by Lars again?
        
       | dang wrote:
       | Related:
       | 
       |  _All about Modelica: An equation-based language for modeling
       | physical systems_ - https://news.ycombinator.com/item?id=23690788
       | - June 2020 (44 comments)
       | 
       |  _Modelica_ - https://news.ycombinator.com/item?id=16013179 - Dec
       | 2017 (12 comments)
        
       | JensRantil wrote:
       | Whoa! I did my Master's Thesis about Modelica and Optimica (an
       | optimization extension). Happy to see it still exist and thrive!
        
       ___________________________________________________________________
       (page generated 2024-12-16 23:00 UTC)