Skip to content

Commit d386402

Browse files
committed
Some fixes
1 parent a8b581d commit d386402

File tree

3 files changed

+57
-13
lines changed

3 files changed

+57
-13
lines changed

Tubular_reactor_2D.m

+27-13
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
dz = L/(Nz-1);
4545
r = linspace(0,R,Nr)';
4646
z = linspace(0,L,Nz)';
47+
n = Nr*Nz;
4748

4849
% Operational parameters (play around)
4950
vmax = 1;
@@ -54,42 +55,55 @@
5455
Cf = ones(Nr,1); % Feed concentration
5556

5657
% The initial condition
57-
y0 = zeros(Nr*Nz,1);
58-
yp0 = model(0,y0,zeros(Nr*Nz,1));
58+
y0 = zeros(n,1);
59+
zz = zeros(n,1);
60+
yp0 = model(0,y0,zz);
5961

6062
% Auto generate the sparsity pattern (don't try to run without it if Nr > 30 and/or Nz > 30)
6163
% Try to build manually and compare with the auto-generated ;)
62-
Jp = zeros(Nr*Nz);
63-
yr = rand(Nr*Nz,1);
64-
zz = zeros(Nr*Nz,1);
64+
%
65+
tic
66+
Jp = spalloc(n,n,3*n);
67+
yr = rand(n,1);
6568
delta = 1e-4;
66-
for ii = 1:Nr*Nz
67-
per = zeros(Nr*Nz,1);
69+
per = zeros(n,1);
70+
for ii = 1:n
6871
per(ii) = 1;
6972
f0 = model(0,yr,zz);
7073
f1 = model(0,yr+per*delta,zz);
71-
Jp(:,ii) = (f1 - f0)/delta ~= 0;
74+
Jp(:,ii) = (f1 - f0)/delta ~= 0; %#ok<SPRIX>
75+
per(ii) = 0;
7276
end
7377

74-
Jp = sparse(Jp);
75-
Jyp = speye(Nr*Nz);
78+
Jyp = speye(n);
79+
etime = toc;
80+
81+
fprintf('Elapsed time building the sparsity pattern = %2.4f s\n',etime);
82+
7683

7784
% The solution
78-
tf = 25;
85+
tf = 20;
7986
frames = 2000;
8087
tspan = linspace(0,tf,frames);
8188
op = odeset('AbsTol',1e-6,'RelTol',1e-4,'JPattern',{Jp,Jyp});
8289

8390
tic
8491
[t,y] = ode15i(@model,tspan,y0,yp0,op);
85-
toc
92+
etime = toc;
93+
94+
fprintf('Elapsed time integrating the system = %2.4f s\n',etime);
95+
8696

8797
% Parse the solution matrix
98+
tic
8899
Nt = length(t);
89100
Csol = zeros(Nr,Nz,Nt);
90101
for ii = 1:Nt
91102
Csol(:,:,ii) = reshape(y(ii,:)',Nr,Nz);
92103
end
104+
etime = toc;
105+
106+
fprintf('Elapsed time parsing the solution = %2.4f s\n',etime);
93107

94108
% Plot the data (to stop the animation, press CTRL+C on command window)
95109
close all
@@ -137,7 +151,7 @@
137151
% In z = L and r = 2:Nr-1
138152
res(2:Nr-1,Nz) = C(2:Nr-1,Nz) - C(2:Nr-1,Nz-1);
139153

140-
res = reshape(res,Nr*Nz,1);
154+
res = reshape(res,n,1);
141155

142156
end
143157

license.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) [2018] [Ataíde Souza Andrade Neto]
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

readme.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CHEMical ENGineering Problems solved!
2+
3+
This is a repository with classical chemical engineering problems solved in MatLab.
4+
(IN PROGRESS)
5+
6+
## Author
7+
8+
* **Ataíde Neto** - ataide@peq.coppe.ufrj.br
9+

0 commit comments

Comments
 (0)