13.07.2015 Views

Elements of MATLAB and Simulink - Lecture 7 - PERCRO

Elements of MATLAB and Simulink - Lecture 7 - PERCRO

Elements of MATLAB and Simulink - Lecture 7 - PERCRO

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>Elements</strong> <strong>of</strong>Matlab <strong>and</strong> <strong>Simulink</strong><strong>Lecture</strong> 7Emanuele Ruffaldi12th May 2009Copyright 2009,Emanuele Ruffaldi. This work is licensed under the Creative Commons Attribution-ShareAlikeLicense.


PARTIAL DIFFERENTIALEQUATIONS


Introducing PDEOrdinary Differential Equation• Derivatives respect a single independent variable• Solution is a function with arbitrary constantsPartial Differential Equation• Differential relationship <strong>of</strong> multiple variables• Solution is an arbitrary function• Solution determined by fixing boundary conditionsNotation


<strong>Elements</strong> <strong>of</strong> a PDEEquationDomainBoundaryConditions


Heat EquationHeat (or diffusion) equation: models the diffusion <strong>of</strong> temperaturefrom an initially concentrated distributionu_t = u_xxExample <strong>of</strong> solution is:u(x,t) = 1/sqrt(t) exp(-x^2/4*t)Verify using <strong>MATLAB</strong> Symbolic Toolbox>> Example lecture7_diffuse


Boundary ProblemThe Dirichlet problem is the general problem <strong>of</strong> finding a function uwhich solves a PDE for which the values are known on theboundary <strong>of</strong> a given region• Given a PDE over R N• Given a function f that has values over a boundary region <strong>of</strong> Ω• Find a function u solving PDE that is differentiable twice in theinterior <strong>and</strong> once on the boundary <strong>and</strong> assumes the values <strong>of</strong> f onthe boundaryThe Neumann problem involves a boundary condition relative to aderivative <strong>of</strong> the target functionExpressed as u_n


Heat Equation 2DHeat Equation 2D: diffusion <strong>of</strong> a quantity along the space <strong>and</strong> timeu_t = u_xx + u_yyThe general formulation isu_t = div grad uExampleMetal block with a rectangular crack. The left side is heated at 100degrees, the right side heat is flowing to air at constant rate. Theothers sides are insulatedu = 100 (Dirichlet condition)u_n = -10 on the right side (Neumann condition)u_n = 0 on the other boundaries (Neumann condition)


Linear Advection EquationLinear advection equation: models the constant movement <strong>of</strong> aninitial distribution <strong>of</strong> u with a speed <strong>of</strong> –c along x axis. Shape ispreservedu_t = c u_xFor any function q a solution is q(w) where w = x+ctu(x,t) = q(w) = q(x+ct)>> Example lecture7_advection


Wave EquationLinear Waveu_tt = c^2 u_xxA typical solution is u(x,t)=sin(x+ct)Spherical Waveu_tt = c^2 (u_rr + 2/r u_r)If we put in evidence (ur) the solution is the same as aboveu(t,r) = 1/r [F(r-ct)+G(r+ct)]>> Example lecture7_wave


Laplace EquationLaplace Equationu_xx + u_yy = 0Poisson Equationu_xx + u_yy = g(x,y,z)Helmholt’s Equationu_xx + u_yy + f(x,y) u = g(x,y,z)Require boundary conditions for resolution


Basics <strong>of</strong> FEMHow we can solve PDE numerically when no analytical solution isavailable?The Finite Element Method is the most common solution1. Decompose the Domain in subspaces2. Approximate the Function with piecewise linear function definedinside each subspace3. Find the numerical solution for every subspace given theconditionsFDM is the Finite Difference Method is possible but it works betterwith rectangular domains


FEM 1DSpace discretizationInterpolation Function Linear Combination (Basis)


FEM 2DAirSiliconGeneralized approach by decomposingthe domain in unit elements


Families <strong>of</strong> PDE <strong>and</strong> use• Elliptic <strong>and</strong> Parabolic• Steady <strong>and</strong> unsteady heat transferin solids• Flows in porous media <strong>and</strong>diffusion problems• Electrostatics <strong>of</strong> dielectric <strong>and</strong>conductive media• Potential flow• Hyperbolic• Transient <strong>and</strong> harmonic wavepropagation in acoustics <strong>and</strong>electromagnetics• Transverse motions <strong>of</strong> membranes• Eigenvalue• Determining natural vibrationstates in membranes <strong>and</strong>structural mechanics problems


<strong>MATLAB</strong> Partial Differential Equation ToolboxSolves some families <strong>of</strong> PDE: elliptics, parabolic, hyperbolic <strong>and</strong>eigenvaluePDE Toolbox works in the easiest way with 2D BoundaryUser Interface (pdetool) <strong>and</strong> Comm<strong>and</strong> lineSteps1. Define the Domain2. Define the Boundary function3. Solve4. Plot results


Expressing the GeometryThe boundary is expressed by Constructive Solid GeometrySet composition <strong>of</strong> fundamental entitiesThe CSG allows to compose basic entities1 32 4-Graphical editing (pdetool)-initmesh <strong>and</strong> decsg-Underst<strong>and</strong> CSG expression


Geometry as Mesh• The FEM resolution uses a triangular mesh for the spatialdiscretization <strong>of</strong> the problem• The Constructive Geometry produces a closed surface that is latertransformed in Mesh• Refine mesh for improving details on borders or surfacefeatures (number <strong>of</strong> triangles increases)• Jiggle mesh (quality improves)Draw ModeMesh Mode


Expressing the Boundary Conditions• Two types <strong>of</strong> Boundary Conditions• Dirichlet• h u=r• Neumann• n c grad(u) + qu = g• e.g. n c grad(u) = 0 means no flux• Coefficients in bold can be specified with PDE tool• Export Decomposed geometry <strong>and</strong> Boundary into Workspacevariables


Resolution <strong>of</strong> PDE• Solver function depend on the type <strong>of</strong> problem• u1=parabolic(u0,tlist,b,p,e,t,c,a,f,d)• u0 is the initial condition (sized as size(p,2))• tlist is the time in which let system evolve• b boundary• p,e,t geometry• [c,a,f,d] parameters <strong>of</strong>• Automatic Refinement <strong>of</strong> problem• [u,p,e,t]=adaptmesh(g,b,c,a,f,options)• The parabolic equation can be solved keeping time fixed <strong>and</strong>starting at given condition• Time Discretization (stages)• Method <strong>of</strong> lines• Allows PDEs in <strong>Simulink</strong>


Heat Equation 2DExampleMetal block with a rectangular crack. The left side is heated at 100degrees, the right side heat is flowing to air at constant rate. Theothers sides are insulatedu = 100 (left side)u_n = -10 on the right sideu_n = 0 on the other boundariesu_t = u_xx + u_yyCreate DomainSet Boundary conditionsSet PDESolveTest>> Example lecture7_heat2d_pde.m with pdetool


PDE for <strong>Simulink</strong>• <strong>Simulink</strong> Solves ODE equations• Use Method <strong>of</strong> Line for making the PDE an ODE problem• We are interested in using the dynamic resolution <strong>of</strong> a PDE as part<strong>of</strong> our simulation• Update the PDE parameters <strong>and</strong> inputs along time• Integration performed by <strong>Simulink</strong>• If using Discrete simulation we can let <strong>MATLAB</strong> do the mathStatesOne for every nodePDEProblem<strong>Simulink</strong>BlockInputTime dependingOutputsStatitsics (max/min)Value at node


PDE in <strong>Simulink</strong> PracticalWe use S-Functions Level-2Block InitializationThe output is the state <strong>of</strong> the PDE that depends on the number <strong>of</strong>nodes <strong>of</strong> the GeometryDerivativesUpdate the Derivatives from the Method <strong>of</strong> LinesOutput ComputationReturn statistics about the states, <strong>and</strong> eventually return sampledvalues from some nodes


Matrix Form <strong>of</strong> the FEMBasic Matrix FormulationDirichletNeumannIntegrated Equation


Thermal Regulation Problem• If the diffusion is fast there is noneed for space information• What if we want to use the exactposition <strong>of</strong> the Thermostat?PDE is Parabolic<strong>Simulink</strong> just needs the Elliptic


Thermal Regulation PDE• Geometry• Boundary• Walls: n grad(T)=0• Glass: n grad(T)=q (u(1)-T)• Where u(1) is exterior temperature, T is the internal temperature <strong>and</strong> q is the thermal conductivity• Equation• T' = div( K grad(T) ) + Th u(2)• u(2) is the heater on or <strong>of</strong>f• Th is the function <strong>of</strong> heat flow from the heater based on its position


Thermal Regulation <strong>Simulink</strong>The solution for this integration is an S-Function written as M-fileParameters• Coordinates <strong>of</strong> Heater xh,yh <strong>and</strong> Radius• Node <strong>of</strong> the Thermostat• Initial Temperature T0• Heater Temperature ThInput• State <strong>of</strong> the Heater• External TemperatureOutput• State <strong>of</strong> the Heater• Maximum Temperature in Room• Temperature at Thermostat


References• Books• An Introduction to Partial Differential Equations with<strong>MATLAB</strong>,Coleman M., CRC Press, 2005• Introduction to Partial Differential Equations with <strong>MATLAB</strong>,Cooper J.M., Birkhause, 1998• Beginners Guide to Simulation for Physical Engineering:Practical Usage <strong>of</strong> <strong>MATLAB</strong> <strong>and</strong> PDEase, Yutaka Abe, 1999• Courses• Introduction to Partial Differential Equations, Doug Moore,2003• Introduction to Partial Differential Equations, Showalter,Oregon State University• MAE502 Partial Differential Equations in Engineering,ASU,2009

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!