1 / 16

Procedures and Functions

Procedures and Functions. Inputs Outputs. Inputs (only one output!). PROCEDURE TEST( A,B,C :X,Y) ... ... X :=... Y :=... END. FUNCTION Smallest( X,Y,Z ) if (X<Y) then S:=X else S:=Y if (S<Z) then goto 10 S:=Z 10: Smallest:=S; END. End-marker. End-marker.

perdy
Download Presentation

Procedures and Functions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Procedures and Functions Inputs Outputs Inputs (only one output!) PROCEDURE TEST(A,B,C:X,Y) ... ... X :=... Y :=... END FUNCTION Smallest(X,Y,Z) if (X<Y) then S:=X else S:=Y if (S<Z) then goto 10 S:=Z 10: Smallest:=S; END End-marker End-marker Calling from main equation set: Calling from main equation set: • x=smallest(1,2,3) CALL TEST(1,2,3:X,Y) Functions and procedures must be placed before equations! (Note that English EES notation has been used) Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  2. Loops and Logical Operators (Within Procedures and Functions!) Logical (or comparison) operators (IF - THEN - ELSE or REPEAT – UNTIL): < (less than) > (greater than) = (equal) <= (less than or equal) >= (greater than or equal) and (logical and) or (logical or) Repeat-Until j:=0 repeat j:=j+1; A[j]:=j+1 until (j>=1000) IF-THEN-ELSE IF {logical expression} THEN {Operation} ELSE {Operation} Ex: IF (X<Y) and (Y>2) THEN A:=3 ELSE A:=X*Y Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  3. Logical Expressions in Equation Set ARG=IF(A, B, X, Y, Z) If A<B ARG=X If A=B ARG=Y If A>B ARG=Z Be cautious with discontinuities!!! Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  4. ”Loops” in the Equation Set The Duplicate Function: Duplicate j=1,5 A[j]=h[j]-T*s[j] End is equivalent to: A[1]=h[1]-T*s[1] A[2]=h[2]-T*s[2] A[3]=h[3]-T*s[3] A[4]=h[4]-T*s[4] A[5]=h[5]-T*s[5] Warning! This can introduce gigantic equation sets! Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  5. Solving Integrals Numerically Intergral Function: F = INTEGRAL(Integrand, VarName, LowerLimit, UpperLimit, StepSize) or F = INTEGRAL(Integrand, VarName, LowerLimit, UpperLimit) {automatic step size} Differential Equations Using Integral Function: y=y0 + INT{ f(x,y) dx} Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  6. Modules & Subprograms Are called using a CALL statement just like procedures! MODULE TEST(A, B : X, Y) . . {Equations} . END SUBPROGRAM TEST(A, B : X, Y) . . {Equations} . END (Equations are solved internally in subprograms where after the program iterates between the subprograms and main programs until a solution is reached) (Equations are solved simultaneously) Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  7. Fundamental laws of thermodynamics Zeroth law: If two bodies are each in equilibrium with a third body, they are in thermal equilibrium with each other. First law:The energy is conserved ~ you can’t win! Second law:If a process occurs in a closed system, the entropy increases for irreversible processes and remains constant for reversible processes (S0) ~ you can’t break even! Third law:The entropy of a system goes to zero as the temperature goes to 0K, no matter the values of parameters as pressure, volume, electric fields etc. ~there is no point in trying! Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  8. Interpretation of 2nd law 2nd lw. (altI):No series of processes is possible whose sole result is the absorption of heat from a thermal reservoir and the complete conversion of this energy to work: There are no perfect engines! 2nd lw. (altII):No series of processes is possible whose sole result is the transfer of heat from a reservoir at a given temperature to a reservoir at a higher temperature: There are no perfect refrigerators! Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  9. Properties used in thermal modelling: Thermodynamic properties Temperature T, pressure p, specific volume v and density . Calorimetric properties Specific enthalpy h, specific entropy s, specific internal energy u. Material & transport properties Specific heat capacity cp (at constant pressure) & cv (at constant volume), kinematic viscosity , dynamic viscosity . Physical & derived properties Dimension, shape, efficiency, mass flow, heat transfer coefficients etc. Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  10. Conservation equations Most of the systems we consider are OPEN SYSTEMS! 1st law: Continuity: Momentum: Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  11. Steady State (Stationary conditions) If we neglect variations in kinetic energy, potential energy and momentum losses (pressure losses): Keep in mind: Energy and mass are always conserved! There are no exceptions! Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  12. Molar fractions and Mass fractions Dalton’s Law: The total pressure equals the sum of the partial pressures. The partial pressures are the pressures the single components in the gas (i.e. species) would have if they were present alone in the system. Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  13. Mixture Enthalpy Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  14. Mixture Entropy Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  15. Mixture Transport Properties Wilke’s formula: Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

  16. Procedure for using Wilke’s Formula viscosity=0 lambda_gas=0 for i=1:NS interaction_sum=0 for j=1:NS int(i,j)=(1+sqrt(my(i)/my(j))*(M(j)/M(i))^(1/4))^2/(sqrt(8)*sqrt(1+(M(i)/M(j)))) interaction_sum=interaction_sum+x(j)*int(i,j) end my_gas=my_gas+x(i)*my(i)/interaction_sum lambda_gas=lambda_gas+x(i)*lambda(i)/interaction_sum end Analysis, Modelling and Simulation of Energy Systems, SEE-T9 Mads Pagh Nielsen

More Related