Challenge

Week 8 - Simulation of a backward facing step in OpenFOAM

close all
clear all
clc
%Declaring the constants
b = 0.05;% Damping coefficient
m=1;% mass of Bob
L=1; %Length of string
g=9.81;% Acceleration due to Gravity

% initial conditions
theta_0 = [0 3];
%time span for the simulation
t_span = linspace(0,20,500);

% Solution for ode
[t, theta] = ode45(@(t,theta) [theta(2); -(((b/m)*theta(2)) + ((g/L)*sin(theta(1))))],t_span, theta_0);
plot(t,theta);

grid on;

% animation
X0=0;
Y0=0;

ct=1;
videofile=VideoWriter('simple_pendulum','uncompressed AVI');
videofile.FrameRate=60;
open(videofile);

for i=1:length(t)
X1=L*sin(theta(i,1));
Y1=-L*cos(theta(i,1));

figure(1)
plot([-1 1],[0 0],'linewidth',6,'color','g');
axis([-2 2 -2 2]);
line([X0 X1],[Y0 Y1],'linewidth',2,'color','b');
hold on;
plot(X0,Y0,'O','markerSize',3,'markerfacecolor','y');
plot(X1,Y1,'O','markerSize',20,'markerfacecolor','r');
title('daming of simple pendulum');
legend('support rod','length of pendulum','fixed point','bod of pendulum');
grid on;
hold off;
M=getframe(gcf);
writeVideo(videofile,M);

end

% videofile=VideoWriter('simple_pendulum','uncompressed AVI');
% open(videofile);
%writeVideo(videofile,m);
close(videofile);


Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.