% Numerical Modelling in Geosciences % by Manuele Faccenda, Università di Padova % % Practice 1 % % Use of functions for,while,if % Produce/plot 1D data %Better to clear any previous results/data and plot clear all; clf; %% Vertical flow of a fluid in a half-pipe is described by the following function: % % vz(x) = vz0 - x^2 * 50; % % in the range 0 < x < 0.1 m, where vz0 = 1 m/s. %Min/Max dimensions Xmin = 0; Xmax = 1e-1; %Number of nodes Xnum = 101; %Nodes distance dx = (Xmax-Xmin)/(Xnum-1); %Initialize x-coordinate array of dimensions (Xnum x 1) X = zeros(Xnum,1); %Calculate nodes coordinates for i = 1 : Xnum if i == 1 X(i) = Xmin; else X(i)= X(i-1) + dx; end end %Set v0 vz0 = 1; %Initialize velocity array of dimensions (xnum x 1) vz = zeros(Xnum,1); %"for" loop to calculate v(x) for i = 1 : Xnum vz(i) = vz0 - X(i)^2 * 50; end %Plot result figure(1) plot(X,vz,'r','LineWidth',3) axis tight %% Next, assume that the fluid vertical velocity increases every hour by: % % dvz(x) = dvz0 - x * 0.25 (m/s) % % until one of the nodes velocity reaches vz = 2 m/s, after which becomes % steady-state (i.e., time-independent). % Set dvz0 = 0.05 m/s. %Set dv0,vmax and time variables dvz0 = 0.05; vzmax = 2; time=0; tstp=3600; %seconds %Flag VZ0 = 1; %Iterate acceleration while VZ0 > 0 for i = 1: Xnum dvz = dvz0 - X(i) * 0.25; vz(i) = vz(i) + dvz; if(vz(i) >= vzmax) VZ0 = 0; end end %Time increase time = time + tstp; hold on plot(X,vz) axis tight title(['Time: ',num2str(time),' seconds']) xlabel('Pipe radius') ylabel('Fluid velocity') pause(0.1) end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%% %%% %%% Homework %%% %%% %%% %%% %%% %%% Please, exercise at home with all the above functions and algorithms. %%% %%% %%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%