1 | #*--------------------------------------------------------------------- |
---|
2 | * EMSO Model Library (EML) Copyright (C) 2004 - 2016 ALSOC. |
---|
3 | * |
---|
4 | * This LIBRARY is free software; you can distribute it and/or modify |
---|
5 | * it under the therms of the ALSOC FREE LICENSE as available at |
---|
6 | * http://www.enq.ufrgs.br/alsoc. |
---|
7 | * |
---|
8 | * EMSO Copyright (C) 2004 - 2016 ALSOC, original code |
---|
9 | * from http://www.rps.eng.br Copyright (C) 2002-2004. |
---|
10 | * All rights reserved. |
---|
11 | * |
---|
12 | * EMSO is distributed under the therms of the ALSOC LICENSE as |
---|
13 | * available at http://www.enq.ufrgs.br/alsoc. |
---|
14 | * |
---|
15 | *---------------------------------------------------------------------- |
---|
16 | * Author: Argimiro R. Secchi |
---|
17 | * COPPE/UFRJ - Group of Modeling, Simulation, Control, |
---|
18 | * and Optimization of Processes |
---|
19 | * $Id$ |
---|
20 | *--------------------------------------------------------------------*# |
---|
21 | |
---|
22 | using "types"; |
---|
23 | |
---|
24 | Model MDF |
---|
25 | |
---|
26 | PARAMETERS |
---|
27 | opcao as Switcher (Valid=["MDF1"],Default="MDF1"); |
---|
28 | N as Integer (Brief="Number of discretization points"); |
---|
29 | xi as Real(Brief="Lower boundary"); |
---|
30 | xf as Real(Brief="Uppper boundary"); |
---|
31 | |
---|
32 | VARIABLES |
---|
33 | x(N+1) as Real(Brief="mesh points"); |
---|
34 | dx as Real(Brief="mesh interval"); |
---|
35 | |
---|
36 | y(N+1) as Real(Brief="Dependent variable"); |
---|
37 | dif1x(N+1) as Real(Brief="First derivative of y"); |
---|
38 | dif2x(N) as Real(Brief="Second derivative of y"); |
---|
39 | |
---|
40 | EQUATIONS |
---|
41 | |
---|
42 | #mesh uniform interval |
---|
43 | dx=(xf-xi)/N; |
---|
44 | |
---|
45 | #mesh points |
---|
46 | for i in [1:N+1] do |
---|
47 | |
---|
48 | x(i) = xi + (i-1)*dx; |
---|
49 | |
---|
50 | end |
---|
51 | |
---|
52 | switch opcao |
---|
53 | |
---|
54 | case "MDF1": |
---|
55 | #First derivative approximation at boundary x=x0 |
---|
56 | dif1x(1)=(y(2)-y(1))/(dx); |
---|
57 | |
---|
58 | #First derivative approximation at boundary x=xf |
---|
59 | dif1x(N+1)=(y(N+1)-y(N))/(dx); |
---|
60 | |
---|
61 | #First derivative approximation at internal points |
---|
62 | for i in [2:N] do |
---|
63 | dif1x(i)=(y(i+1)-y(i-1))/(2*(dx)); |
---|
64 | end |
---|
65 | |
---|
66 | dif2x(1) = 0; # dummy |
---|
67 | #Second derivative approximation at internal points |
---|
68 | for i in [2:N] do |
---|
69 | dif2x(i)=(y(i+1) - 2*y(i) + y(i-1))/((dx)^2); |
---|
70 | end |
---|
71 | |
---|
72 | #case "MDF2": |
---|
73 | |
---|
74 | #ADD OTHER SCHEMES |
---|
75 | |
---|
76 | end |
---|
77 | |
---|
78 | end |
---|