EQE038 – Simulação e Otimização de Processos Químicos – Aula 2 – Concepts of modeling and simulation. Object-oriented modeling in EMSO. Argimiro R. Secchi EQ/UFRJ 30 de agosto de 2013 1 Applications of Process Modeling applications tools 2 Some questions that could be answered with these applications • Market: if the price of a product increases, what will be the reduction of demand and what should be the new scheduling of production? • Production planning: having several sources of raw material and several manufacturing plants, how to distribute the raw material among these plants and what products each plant has to produce? • Synthesis: what process should be used for manufacturing a given product? • Design: what type and size of equipment are necessary to produce a given product? • Operation: what operating condition will maximize the production of a product? • Control: how a process input can be manipulated to keep a measured process output at its desired value? • Safety: if an equipment failure occur, what will be the impact over the operators and other equipments? • Environment: how long will take to biodegrade a contaminated soil by dangerous waste? 3 Difficulties in Dynamic Simulation • Reliable models • High-Index DAE systems • Large-Scale systems • Model consistency: - Degree of Freedom (DoF) - Dynamic Degree of Freedom (DDoF) - Units of measurement - Structural non-singularity - Consistent initial condition 4 Concepts of Modeling and Simulation Modeling in Latin: modus = a measure, a small representation of a designed or existing object. from dictionary: a mathematical or physical system, obeying certain specified conditions, whose behavior is used for understanding a physical, biological or social system, with analogy in some aspects. Is only an approximate representation of a real system. Process model: a set a equations and specifications that allows to predict the behavior of a process. first principles or mechanistic model empirical relations 5 Model Building A mathematical model has: • A set of model parameters (reaction order, valve constant, etc.) • A set of variables (temperatures, pressures, flow rates, etc.) • A set of equations (algebraic and differential) relating the variables Problems in model building: • Number of equations and variables do not match (DoF 0) • Equations of the model are inconsistent (linear dependence, UOM, etc.) • The number of initial conditions and DDoF do not match 6 Modeling Tools The available tools for process modeling may be classified into: • Block-Oriented focus on the flowsheet topology using standardized unit models and streams to link these unit models • Equation-Oriented rely purely on mathematical rather than phenomena-based descriptions, making difficult to customize and reuse existing models • Object-Oriented Models are recursively decomposed into a hierarchy of sub-models and inheritance concepts are used to refine previously defined models into new models (Bogusch and Marquardt, 1997) 7 Object-Oriented Modeling A process flowsheet model can be hierarchically decomposed: Plant Column Linked Trays Reaction System Separation System Condenser Tray Splitter Linked Trays Pump Tray Pretreat. System Tray Feed Tray Separation System Column 3 Column 2 Column 1 Tray Linked Trays Rebolier 8 energy balance thermodynamic equilibrium mol fraction normalization liquid flow model vapor flow model concrete model (real tray) mass balance concrete model (ideal tray) Tray abstract model Object-Oriented Modeling efficiency model 9 Object-Oriented Modeling Model types Abstract models: are models that embody coherent and cohesive, but incomplete concepts, and in turn, make these characteristics available to their specializations via inheritance. While we would never create instances (devices) of abstract models, we most certainly would make their individual characteristics available to more specialized models via inheritance. Concrete models: are complete models, usually derived from abstract models, ready to be instantiated, i.e., we can create devices (e.g., equipments) of concrete models. 10 Object-Oriented Modeling OOM main concepts Inheritance: is the process whereby one object acquires (gets, receives) characteristics from one or more other objects. Aggregation: is the process of creating a new object from two or more other objects, or an object that is composed of two or more other objects. Condenser Splitter Linked Trays Pump Feed Tray Column model = Condenser + Splitter + Pump + Linked Trays + Feed Tray + Reboiler Linked Trays Rebolier 11 Object-Oriented Modeling Examples of general-purpose object-oriented modeling languages: • ABACUSS II (Barton, 1999) • ASCEND (Piela, 1989) • Dymola (Elmqvist, 1978) • EcosimPro (EA Int. & ESA, 1999) • EMSO (Soares and Secchi, 2003) • gPROMS/Speedup (Barton and Pantelides, 1994) • Modelica (Modelica Association, 1996) • ModKit (Bogusch et al., 2001) • MPROSIM (Rao et al., 2004) • Omola (Andersson, 1994) • ProMoT (Tränkle et al., 1997) 12 Object-Oriented Modeling A simpler example source sink Level Tank >>> >>> Streams Inlet Material stream feeding the tank Outlet Material stream leaving the tank Parameters k Valve constant D Hydraulic diameter of the tank Variables A Tank cross section area V Tank volume h Tank level Devices: source, tank, sink Available model of the tank Model with circular cross section Model with square cross section 13 Object-Oriented Modeling Inheritance Model equations mass balance: Fin Fout Fin dV dt valve equation: Fout k h liquid volume: V A h Fin Fin Fout Fout Fout 14 Object-Oriented Modeling EMSO: Abstract model using "types"; Model Tank_Basic Fin PARAMETERS k as Real (Brief=“Valve constant", Unit=’m^2.5/h’, Default = 12); D as length (Brief=“Tank hydraulic diameter", Default = 4); VARIABLES in Fin as flow_vol (Brief=“Feed flow rate"); out Fout as flow_vol (Brief =“Output flow rate"); A as area (Brief=“Cross section area"); Fout V as volume (Brief=“Liquid volume"); mass balance: Fin Fout dV dt valve equation: Fout k h liquid volume: V A h h as length (Brief=“Tank level"); EQUATIONS “Mass balance“ Fin - Fout = diff(V); “Valve equation“ Fout = k * sqrt(h); “Liquid volume“ V = A * h; end 15 Object-Oriented Modeling Concrete models Fin Fin Fout Fout Inheritance Model Tank_Circular as Tank_Basic Model Tank_Square as Tank_Basic PARAMETERS Pi as Real (Default = 3.1416); EQUATIONS “Cross section area" A = (Pi * D^2) / 4; EMSO EQUATIONS “Cross section area“ A = D^2; end end 16 Object-Oriented Modeling Flowsheet source Fin Fout Fout sink EMSO: using "tank_oom"; FlowSheet Tanks DEVICES source as Feed; T_c as Tank_Circular; T_sq as Tank_Square; sink as Sink; CONNECTIONS source.F to T_c.Fin; T_c.Fout to T_sq.Fin; T_sq.Fout to sink.F; SET T_c.D = 3 * ’m’; T_sq.D = 3 * ’m’; SPECIFY source.F = 20 * ’m^3/h’; INITIAL T_c.h = 1 * ’m’; T_sq.h = 2 * ’m’; OPTIONS TimeStart = 0; TimeEnd = 20; TimeStep = 0.5; TimeUnit = ’h’; end 17 Object-Oriented Modeling Model switching Model Tank_Section as Tank_Basic PARAMETERS Pi as Real (Default = 3.1416); Section as Switcher (Valid = ["Circular", "Square"], Default = "Circular"); EQUATIONS switch Section case "Circular": “Cross section area" A = (Pi * D^2)/4; case "Square": “Cross section area" A = D^2; end end using "tank_oom"; FlowSheet Tanks2 DEVICES source as Feed; T_c as Tank_Section; T_sq as Tank_Section; sink as Sink; CONNECTIONS source.F to T_c.Fin; T_c.Fout to T_sq.Fin; T_sq.Fout to sink.F; SET T_c.D = 3 * ’m’; T_sq.D = 3 * ’m’; T_c.Section = ”Circular”; T_sq.Section = ”Square”; SPECIFY source.F = 20 * ’m^3/h’; INITIAL T_c.h = 1 * ’m’; T_sq.h = 2 * ’m’; OPTIONS TimeStart = 0; TimeEnd = 20; TimeStep = 0.5; TimeUnit = ’h’; end 18 Object-Oriented Modeling Aggregation source Tank model mass balance: Fin Fout P0 dV dt liquid volume: V A h P0 P sink Level Tank outlet pressure: P P0 g h Valve model mass balance: Fin Fout valve equation: Fout k pressure drop: P g P Pin Pout 19 Object-Oriented Modeling Tank model with valve using "types"; Model Tank_Basic PARAMETERS D as length (Brief=“Tank hydraulic diameter", Default = 4); rg as Real (Brief=“rho * g", Unit =’kg/(m*s)^2’, Default = 1e4); Valve model using "types"; Model Valve PARAMETERS k as Real (Brief=“Valve constant", Unit=’m^2.5/h’, Default = 12); VARIABLES in Sin as stream (Brief=“Inlet stream"); rg as Real (Brief=“rho * g", out Sout as stream (Brief =“Outlet stream"); A as area (Brief=“Cross section area"); V as volume (Brief=“Liquid volume"); h as length (Brief=“Tank level"); valve as Valve (Brief=“Valve model"); CONNECTIONS Sout to valve.Sin; EQUATIONS “Mass balance“ Sin.F – Sout.F = diff(V); “Liquid volume“ V = A * h; “Outlet pressure“ Sout.P = Sin.P + rg * h; end Unit =’kg/(m*s)^2’, Default = 1e4); VARIABLES in Sin as stream (Brief=“Inlet stream"); out Sout as stream (Brief =“Outlet stream"); DP as press_delta (Brief=“Pressure drop"); EQUATIONS “Mass balance“ Sin.F = Sout.F; “Valve equation“ Sout.F = k * sqrt(DP/rg); “Pressure drop“ DP = Sin.P – Sout.P; end 20 Object-Oriented Modeling Flowsheet using "tank_valve_oom"; FlowSheet Tanks DEVICES source as Feed; T_c as Tank_Circular; T_sq as Tank_Square; sink as Sink; CONNECTIONS source.Sout to T_c.Sin; T_c.valve.Sout to T_sq.Sin; T_sq.valve.Sout to sink.Sin; SET T_c.D = 3 * ’m’; T_sq.D = 3 * ’m’; SPECIFY source.Sout.F = 20 * ’m^3/h’; source.Sout.P = 1 * ’atm’; T_c.valve.Sout.P = 1 * ’atm’; sink.Sin.P = 1 * ’atm’; INITIAL T_c.h = 1 * ’m’; T_sq.h = 2 * ’m’; OPTIONS TimeStart = 0; TimeEnd = 20; TimeStep = 0.5; TimeUnit = ’h’; end 21 Modeling workshop Model equations mass balance: Fin Fout Fin dV dt valve equation: Fout k h Fin Fin Fout liquid volume: V Ah A = h (D h) Fout Fout Fin D h V h 2 3 2 h Fout 22 Modeling workshop Flowsheet source Fi = 20 m3/h n D=3m h(0) = 1 m Fout D=3m h(0) = 2 m Fout D=3m h(0) = 2.5 m h Fout Fo ut sink 23 Elementos Básicos na Modelagem 1. Descrição do processo e definição do problema Definir o Modelo Construir o Modelo 2. Teoria e aplicação das leis fundamentais 3. Hipóteses e considerações simplificadoras 4. Equacionamento 5. Análise de Consistência 6. Solução desejada Validar o Modelo 7. Matemática e computação 8. Solução e validação 24 Modeling 1. Process Description and Problem Definition • Process Description – Process objectives – Process flowsheet – Process operation • unit operations and control • Problem Definition – Simulation objectives – Simulation applications 25 Modeling Process Description Example: level tank Fin V h Fout A liquid flows in and out of a tank due to gravitational forces. We wish to analyze the volume, height and flowrate variations in the tank (system response) as function of feed disturbances. 26 Modeling 2. Fundamental Laws: Theory and Applications • Bases to be used in the modeling - mass conservation ( . v ) t - momentum conservation ( v) t [. v v] P [.] g advection pressure forces viscous forces gravitational forces - energy conservation t ˆ 1 2 U 2 v 1 . v Uˆ v 2 2 (.q ) g .v (.P v) (.[.v]) advection conduction gravit. forces work pressure forces work viscous forces work 27 Modeling Levels 28 Modeling Levels Modelo Microscópico Modelo de Gradientes Múltiplos Modelo de Máximo Gradiente Modelo de Macroscópico 29 Modeling 3. Simplifying Assumptions • Establish the assumptions and simplifications • Define the model limitations - constant specific mass - isothermal - perfect mixture - Fout k h 30 Modeling 4. Mathematical Model • Data mining for simulation – Collect data and information of the studied system – Identify the engineering unit of measurements – Specify operating procedures – Specify the operating regions of the variables • Memory of Calculation – Mathematical model – Define unit of measurements of variables and parameters – Define and specify free variables – Define and determine values of parameters – Define and establish initial conditions 31 Mathematical Model Conservation laws First Principles Models Hybrid Models dV F dt dX F μ X dt V dT F UA (Te T) (T Tc ) dt V ρVCp Parametric A(q) y(t) B(q) C(q) u(t) e(t) F(q) D(q) Neural Nets Empirical Models Fuzzy Logic 32 Modeling Mathematical Model In the simulator • Build process equipment models – Identify and create abstract and concrete models – Declare variables and parameters – Write model equations – Compose the equipment model via inheritance and aggregation • Build process flowsheet – Declare flowsheet devices – Define process connections – Set process parameters values – Specify process free variables – Establish initial conditions – Establish simulation options 33 Mathematical Model mass balance: Fin Fout Fin dV dt valve equation: Fout k h liquid volume: V A h (1) (2) (3) Fin Fin Fout (4) Fout Fout 34 Modeling 5. Consistency Analysis • Model consistency analysis for unit of measurements (UOM) • Degree of freedom analysis • Dynamic degree of freedom analysis variable Fin, Fout V A h, D k t UOM m3 h-1 m3 m2 m m2.5 h-1 h equations (1): [m3 h-1] – [m3 h-1] = [m3] / [h] (2): [m3 h-1] = [m2.5 h-1] ([h])0.5 (3): [m3] = [m2] [m] (4): [m2] = ([m])2 35 Modeling Consistency Analysis variables: Fin, Fout, V, A, h, D, k, t 8 constants: k, D 2 specifications: t 1 driving forces: Fin 1 unknown variables: V, h, A, Fout 4 equations: 4 Degree of Freedom = variables – constants – specification – driving forces – equations = unknown variables – equations = 8 – 2 – 1 – 1 – 4 = 0 Dynamic Degree of freedom (index < 2) = differential equations = 1 Needs 1 initial condition: h(0) 1 36 Modeling 6. Desired Solution • Plan case studies • Define: – Objectives of the study – Problems to be solved – Evaluation criteria For the given example and initial condition (h0 or V0), we wish to analyze h(Fin), V(Fin) and Fout(Fin). 37 Modeling 7. Computation • Define the desired accuracy • Specify the simulation time and reporting interval • Verify the necessity of specialized solvers (high-index problems) 38 Modeling 8. Solution and Validation • Analyze simulation results • Analyze state variables dynamics • Test model fitting with plant data hexp – Compare simulation x plant hcalc 39 Modeling Solution and Validation • Check output sensitivity to input disturbances • Carry out parametric sensitivity analysis • Analyze output data with statistical techniques • Verify results coherence • Document obtained results 40 Modeling Remarks • Start with a simple model and gradually increase complexity when necessary; • The model should have sufficient details to capture the essence of the studied system; • It is not necessary to reproduce each element of the system; • Models with excessive details are expensive, difficult to implement and to solve; • Interact with people that operate the equipment; • Deeply understand the process behavior. 41 – A simple in EMSO – Starting EMSO 42 43 Model 44 Model Language – Equation-based system Equations The order the equations appear in the model do not matter Equivalent Equations Can be written in any user desired form 45 Model Language – Object-Oriented Modeling The modeling and simulation of complex systems is facilitated by the use of the Object-Oriented concept Equipment Component System The system can be decomposed in several components, each one described separately using its constitutive equations The components of the system exchange information through the connecting ports 46 Model Components Including submodels and types Automatic model documentation Symbol of variable in LaTeX command for documentation Basic sections to create a math. model Port location to draw a flowsheet connection Input and output connections 47 Basic Variable Types in a Model Parameters and variables are declared within their valid domains and units using types created based on the built-in types: Real, Integer, Switcher, Plugin 48 Building a Model: A simple example – level tank Streams Inlet Material stream feeding the tank Outlet Material stream leaving the tank Parameters k Valve constant D Hydraulic diameter of the tank Variables A Tank cross section area V Tank volume h Tank level Devices: source, tank, sink >>> >>> Available model of the tank Model with circular cross section Model with square cross section 49 Material Stream Modeling The material stream carries the information entering and leaving the equipment VARIABLES F T P volumetric flowrate temperature pressure Source - component that has a feed material stream. It has an output connection Source Sink Sink - component that receives an output material stream. It has an input connection 50 Level Tank Modeling Mass balance dV Fin Fout dt Valve equation Fout k h Inlet Feed material stream to the tank Fin inlet volumetric flowrate Tin inlet temperature Pin inlet pressure Outlet Output material stream from the tank Fout outlet volumetric flowrate Tout outlet temperature Pout outlet pressure Thermal equilibrium Tin Tout Mechanical equilibrium Pin Pout Area D2 A 4 D2 if circular if square 51 Level Tank: Inheritance Fin Basic tank Fin Fin Fout Fout Circular tank Fout Square tank 52 Creating a MSO file for Model Menu New Model Destination File Name 53 Creating a Model using the template using including references to other files. Model a new model is declared with the keyword Model and its name. a model contains a few basic sections: PARAMETERS section which defines the parameters of the model. VARIABLES section which defines the variables of the model. EQUATIONS section which describes the model equations. 54 Creating a Material Stream Model Including predefined types of EMSO Symbol of variable are LaTeX commands Model Documentation Using the types defined in the file “types.mso” selecting the desired unit of measure 55 Creating a Source Stream Model Using the same file Model Documentation Output Connection 56 Creating a Sink Stream Model Using the same file Model Documentation Input Connection 57 Creating a Basic Tank Model Reference Creating new UOM Model Ports EMSO Built-In Function EMSOquickRef.pdf 58 Creating the Circular Tank Model Using the same file Inheritance Model inherits all the attributes of the class from which it derives Equation Writing the particular equations model SET Defining values for parameters 59 Creating the Square Tank Model Using the same file Inheritance Model inherits all the attributes of the class from which it derives Equation Writing the particular equations model 60 FlowSheet 61 Process Diagram – FlowSheet The equipment are called DEVICES In EMSO the user can manipulate various FlowSheets at same time A FlowSheet consists of a series of unit operations or equipment connected to each other 62 FlowSheet Language – Component-based system streamPH The system modeling is made by the use, configuration and connection of pre-existing components 63 FlowSheet Components Parameters of DEVICES Degree of Freedom Simulation options Dynamic Degree of Freedom 64 Creating a MSO file for FlowSheet Menu New FlowSheet File Name Destination 65 Creating a FlowSheet using the template using including references to other files. FlowSheet A process diagram is declared with the keyword FlowSheet and its name. A FlowSheet contains some basic sections: PARAMETERS DEVICES CONNECTIONS SET SPECIFY INITIAL OPTIONS ... 66 FlowSheet for the Level Tank Parameters of DEVICES Degree of Freedom Simulation options Dynamic Degree of Freedom 67 Consistency Analysis of the Process EMSO analyzes the consistency of the system created in the FlowSheet 68 Simulation of the Level Tank Process Simulation details 69 Level Tank Results double-click Horizontal axis is always the independent variable (usually time) 70 Series of Level Tanks Building a system consisting of three tanks connected in series 71 Series of Level Tanks - FlowSheet Degrees of freedom increases 72 Series of Level Tanks - Results 73 Building a more interesting Model: CSTR with Van der Vusse reaction Variables V Reactor volume r1, r2, r3 Reaction rates Ca, Cb, Cc, Cd Molar concentrations h Reactor level tau Residence time Streams Inlet Feed material stream with molar concentration Outlet Output material stream with molar concentration Parameters Cv Valve constant k1 Constant of reaction rate 1 k2 Constant of reaction rate 2 k3 Constant of reaction rate 3 A Cross-section area 74 Van der Vusse Reactor – Modeling Overall mass balance dV Fin Fout dt Valve equation Fout CV Component mass balances h Thermal equilibrium Tin Tout Mechanical equilibrium Pin Pout Volume V Ah Reaction rates Residence time Perfect mixing 75 Van der Vusse Reactor – Stream Model Adding molar concentration in the material stream 76 Van der Vusse Reactor – Attributes 77 Van der Vusse Reactor Model 78 Van der Vusse Reactor – Model Equations 79 Van der Vusse Reactor – FlowSheet 80 Van der Vusse Reactor – Results 81 Exercises 1) Simulate the CSTR example for different values of the valve constant to find the one that maximizes the concentration of component B at the outlet of the reactor at steady state. Comment the results; 2) Modify the reactor model by adding an opening fraction on the outlet valve: Fs xCv h and make this fraction vary sinusoidally x = (1 + sin (t)) / 2, where t is given in hours. Use a Cv value of 20 m2,5/h. Comment the results for a 20 h simulation; 3) Build a block diagram to simulate the CSTR process. 82 References • Himmelblau, D. M. & Bischoff, K. B., "Process Analysis and Simulation - Deterministic Systems", John Wiley & Sons, 1968. • Felder, R. M. & Rousseau, R. W., "Elementary Principles of Chemical Processes", John Wiley & Sons, 1978. • Denn, M., "Process Modeling", Longman, New York, 1986. • Luyben, W. L., "Process Modeling, Simulation, and Control for Chemical Engineers", McGraw-Hill, 1990. • Silebi, C.A. & Schiesser, W.E., “Dynamic Modeling of Transport Process Systems”, Academic Press, Inc., 1992. • Ogunnaike, B.A. & Ray, W.H., “Process Dynamics, Modeling, and Control”, Oxford Univ. Press, New York, 1994. • Rice, R.G. & Do, D.D., “Applied Mathematics and Modeling for Chemical Engineers”, John Wiley & Sons, 1995. • Bequette, B.W., “Process Dynamics: Modeling, Analysis, and Simulation”, Prentice Hall, 1998. • Engell, S. E Klatt, K.-U. Nonlinear Control of a Non-Minimum-Phase CSTR, Proc. of American Control Conference, Los Angeles, 2041 – 2045 (1993). • Rodrigues, R., R.P. Soares and A.R Secchi. Teaching Chemical Reaction Engineering Using EMSO Simulator. Computer Applications in Engineering Education, Wiley (2008). • Soares, R.P. and A.R. Secchi. EMSO: A New Environment for Modeling, Simulation and Optimization. ESCAPE 13, Lappeenranta, Finlândia, 947 – 952 (2003). 83 Special thanks to Prof. Rafael de Pelegrini Soares, D.Sc. Eng. Gerson Balbueno Bicca, M.Sc. Eng. Euclides Almeida Neto, D.Sc. Eng. Eduardo Moreira de Lemos, D.Sc. Eng. Marco Antônio Müller For helping in the preparation of this material For supporting the ALSOC Project. 84 EP 2013 ... thank you for your attention! http://www.enq.ufrgs.br/alsoc Solutions for Process Control and Optimization Process Modeling, Simulation and Control Lab • Prof. Argimiro Resende Secchi, D.Sc. • Phone: +55-21-2562-8307 • E-mail: arge@peq.coppe.ufrj.br • http://www.peq.coppe.ufrj.br/Areas/Modelagem_e_simulacao.html 85