#*------------------------------------------------------------------- * EMSO Model Library (EML) Copyright (C) 2004 - 2007 ALSOC. * * This LIBRARY is free software; you can distribute it and/or modify * it under the therms of the ALSOC FREE LICENSE as available at * http://www.enq.ufrgs.br/alsoc. * * EMSO Copyright (C) 2004 - 2007 ALSOC, original code * from http://www.rps.eng.br Copyright (C) 2002-2004. * All rights reserved. * * EMSO is distributed under the therms of the ALSOC LICENSE as * available at http://www.enq.ufrgs.br/alsoc. * *-------------------------------------------------------------------- * FlowSheet showing how to use the 'if' conditional. * Ref: M.B. Carver (1978). Mathematics and Computers in Simulation * v.20, pp.190-196 *-------------------------------------------------------------------- * Author: Arge * $Id: $ *--------------------------------------------------------------------*# FlowSheet Carver1 VARIABLES x as Real; u as Real; EQUATIONS u = sin(8*asin(1)*time*'rad/s'); if u > 0 then diff(x) * 's' = x^2; else diff(x) * 's' = 0; end INITIAL x = 0.1; OPTIONS # TimeStep = 0.9; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 0.9; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-6, # RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end FlowSheet Carver2 PARAMETERS eps as Real (Default=1e-5); VARIABLES x as Real; u as Real; n as Real; EQUATIONS u = sin(8*asin(1)*time*'rad/s'); n = 0.5 * (1 + tanh(-u/eps)); # regularization function diff(x) * 's' = x^2 * (1-n); INITIAL x = 0.1; OPTIONS # TimeStep = 0.9; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 0.9; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-6, # RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end FlowSheet Carver3 PARAMETERS eps as Real (Default=1e-5); VARIABLES x as Real; u as Real; n as Real; EQUATIONS u = sin(8*asin(1)*time*'rad/s'); n = 0.5 * (1-(u/eps)/(sqrt(1+(u/eps)^2))); # regularization function diff(x) * 's' = x^2 * (1-n); INITIAL x = 0.1; OPTIONS # TimeStep = 0.9; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 0.9; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-6, # RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end FlowSheet Carver4 VARIABLES x as Real; u as Real; EQUATIONS if x > 0.5 then u = 0.5; else if x < -0.5 then u = 0.2; else u = 1.0; end end diff(x) * 's' = -u*x + sin(time*'rad/s'); INITIAL x = 0.0; OPTIONS TimeStart = 3.1415/4; # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 12.5; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end FlowSheet Carver5 PARAMETERS eps as Real (Default=1e-5); VARIABLES x as Real; u as Real; n1 as Real; n2 as Real; EQUATIONS n1 = 0.5 * (1 + tanh((x-0.5)/eps)); # regularization function n2 = 0.5 * (1 + tanh(-(0.5+x)/eps)); # regularization function u = n1*(1-n2)*0.5+n2*(1-n1)*0.2+(1-n1)*(1-n2); diff(x) * 's' = -u*x + sin(time*'rad/s'); INITIAL x = 0.0; OPTIONS TimeStart = 3.1415/4; # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 12.5; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end FlowSheet Carver6 PARAMETERS eps as Real (Default=1e-5); VARIABLES x as Real; u as Real; n1 as Real; n2 as Real; EQUATIONS n1 = 0.5 * (1+((x-0.5)/eps)/(sqrt(1+((x-0.5)/eps)^2))); # regularization function n2 = 0.5 * (1-((0.5+x)/eps)/(sqrt(1+((0.5+x)/eps)^2))); # regularization function u = n1*(1-n2)*0.5+n2*(1-n1)*0.2+(1-n1)*(1-n2); diff(x) * 's' = -u*x + sin(time*'rad/s'); INITIAL x = 0.0; OPTIONS TimeStart = 3.1415/4; # TimeStep = 12.5-3.1415/4; # for statistical purpose (Detailed Output) TimeStep = 0.01; # for graphical purpose TimeEnd = 12.5; TimeUnit = 's'; DAESolver (File = "dasslc", RelativeAccuracy = 1e-4, AbsoluteAccuracy = 1e-6); end