Training
Hands-on computational modeling
Hands-on computational modeling
Hands-on Modeling and Simulation using MatLab, SimuLink and Comsol
What is (computational) Modeling?
You master and simplify geometries and physics into equations, implemented in a computational tool such as MatLab, SimuLink or Comsol.
How?
'in der Beschränkung zeigt sich erst der Meister' [Goethe ca. 1800], mastery reveals itself in limitation.
Start with a geometry and physics. From the geometry create a network of nodes. Derive for each node all equations. Implement the system into lumped or PDE software. Simulate the model. Check the results by verification and validation:
Verification : Are the equations implemented right, i.e. does it do what is must do.
Validation: Do we have the right equations, i.e must it do what it does...
Why MatLab, SimuLink and Comsol (MSC)?
MatLab, SimuLink, Comsol (MSC) is the most complete and efficient modeling and simulation environment there is. MSC is integrated modeling software and is therefore superior to co-simulation. Furthermore MSC can compile all models into (royalty-free) standalone apps. This is not only very handy but also shows that MSC is in full control of its own code.
This page presents a generic guide on how to create a (physics-based) computational tool from scratch using MatLab, SimuLink and Comsol (MSC). The best way to learn is by the doing the hands-on modules. For the examples, heat transfer is selected as physics because temperature is probably the most common parameter in engineering. After finishing all modules, you are really computoolable!
Step 0: Basic skills and knowledge
The following modules are important before you can start creating modeling tools:
Tip: use artificial intelligence (ai) to guide you through all steps
0.1 Learn to work with a programming language MatLab (or Python)
You need this for basic calculations, visualization of your results and creating lumped modeling tools.
0.2 State-space systems
State-space models are based on ordinary differential equations (ODEs) and matrices. You need to have some basic understanding on these mathematical topics and learn how to work with them
0.3 Using flow-effort analogies for lumped multi-physics modeling
As explained above we will use heat transfer in our examples. To extend to other physics learn flow-effort analogies and apply to lumped multi-physics modeling. Start here:
Wiki Mechanical–electrical analogies
Step 1: Make a sketch of what you want to model
What should be the outcome of the simulation tool?
Sketch the geometry
Show domains and boundary conditions including the physics
Include (a summary of) input, parameters, output
If you have all key output parameters the way you want, does it solve your problem? If yes go to the next step, if start over.
Example: Room Heating Part 1
The outcome of the simulation tool is the temperature inside the room during a winter period and the corresponding energy needed for heating.
Sketch of the geometry
Domains: Room air, floor, wall, window, radiator. Boundary conditions: Air- and water flows at the domain interfaces. Solar heat load. Physics: heat transfer conduction and convection (radiation is ignored ). T is temperature [oC], Q is power [W]
Input : Te(t), Qsolar(t), T(hot)water(t);
Parameters Material properties, air infiltration rate
Output : T roomair (t) , Heating power (t)
T roomair (t) provides the thermal comfort performance, Heating power (t) the corresponding energy usage
Step 2: Select between basic calculation, lumped or FEM
This step is by far the most important step for creating a successful modeling tool.
If a rough estimation (on a simple geometry in steady state) is good enough then go for basic calculation.
The choice between lumped vs FEM is based on your experience and software availability. Lumped modeling is always possible to implement in free software(Python/Octave). If you have access to Comsol this would be the best choice for multi-physics modeling.
Step 3 Basic Calculation
Use hand calculation for estimating the steady-state situation.
Example heated room Part2:
Take: Values for T room air , Te and Qsolar. Calculate the total heat resistances Rtot [K/W] of the wall, window and air infiltration. The heating power to maintain the room air Rtot*(T room air - Te) - Qsolar [W].
Step 4 Lumped using MatLab
Proceed with the Sketch and add:
Nodes with potential variables (Temperature, force, voltage, etc.) for each domain at least one. It is handy to number the nodes starting with 1
All these nodes should have some kind of corresponding capacity (heat capacity, reciproke spring constant, electric capacity)
Connect nodes with resistances (heat resistance, damping, electric resistances)
If present in your physics add inductances (inertia)
Add sources
Example heated room Part 3
Using the above steps the heated room is updated in red:
Equations:
Use the Sketch to derive all equations using power [W] balances
Example heated room Part 4
For each heat capacity C1 - C8, there is one corresponding heat power [W] balance equation
Implement in MatLab
Make 2 files: (1) A mfile with numerical values for all parameters, calling the ode solver and plot the results (2) A mfile with the equations inside the ode function.
Example heated room Part 5
Download this zipfile and study how it is done. This the result:
The left part shows the equations inside the ODEfun. Please note the similarity with the equations of Part4.
The right part presents the temperatures T1 - T8 of the corresponding nodes 1-8. To verify the (implementation) of the model, you can enter T1 -T8 and the numerical values into the equations of Part4. All equations should be zero.
Step 5 Lumped using SimuLink
In SimuLink there are two distinct methods to create lumped models: (1) Graphical using SimScape (2) Equation-based using S-Functions.
(1) SimScape: Use ai to learn about this Tool. You can make the same model of the heated room using SimScape components. Find out which (physics-based) equation is implemented in each used SimScape component. This is necessary for verification of the model.
(2) S-Functions: A ode-based model in MatLab, like above, is easy to implement in SimuLink using a S-Function. The S-Function is one of the basic functionalities of the very beginning of SimuLink (since 1995) for including discrete and continuous systems.
Example heated room Part 6
Download this zipfile and study how it is done. This is the result:
The screenshot shows the SimuLink model with the S-Function, input and output. The Scope temperatures are identical to the above presented MatLab results.
Step 6 FEM using Comsol
This page is under construction