CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > General Forums > Main CFD Forum

Square wave lax wendroff fortran.f90

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 2 Post By FMDenaro
  • 1 Post By selig5576
  • 1 Post By FMDenaro

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 18, 2017, 12:08
Question Square wave lax wendroff fortran.f90
  #1
Disabled
 
Join Date: Apr 2017
Posts: 8
Rep Power: 9
anon_o is on a distinguished road

Dear friends,
How can I write a program code (Fortran .f90) that solves square wave with lax wendroff method?
Thank you very much.
Best,
Armin😉
Attached Images
File Type: jpg IMG_20170418_180848_1.jpg (32.1 KB, 27 views)
anon_o is offline   Reply With Quote

Old   April 18, 2017, 12:53
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
This is a homework you can find developed in many textbooks...
FMDenaro is online now   Reply With Quote

Old   April 18, 2017, 15:40
Default
  #3
Disabled
 
Join Date: Apr 2017
Posts: 8
Rep Power: 9
anon_o is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
This is a homework you can find developed in many textbooks...
Could not find it or a sample of it in lax wendroff. That is why I asked it here.

Sent from my P024 using CFD Online Forum mobile app
anon_o is offline   Reply With Quote

Old   April 18, 2017, 15:47
Default
  #4
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by Arminsamadi View Post
Could not find it or a sample of it in lax wendroff. That is why I asked it here.

Sent from my P024 using CFD Online Forum mobile app

http://mathcenter.hust.edu.cn/Upload...98740d59f8.pdf
selig5576 and anon_o like this.
FMDenaro is online now   Reply With Quote

Old   April 18, 2017, 20:07
Default Problem
  #5
Senior Member
 
Selig
Join Date: Jul 2016
Posts: 213
Rep Power: 11
selig5576 is on a distinguished road
This is a very straight forward problem and should take about 5 minutes given a the Lax-Wendroff article on wikipedia.

Code:
nx = 51;
x = zeros(nx,1);
u = zeros(nx,1);
a = 0.5
unew = zeros(nx,1)
dx = 300/nx;


for i=1:nx
x(i) = (i-1)*dx
end

for i=1:nx
if (x(i) > 0 && x(i) <= 50)
u(i) = 0;
else if (x(i) > 50 && x(i) <= 100)
u(i) = 3;
else if (x(i) > 100 && x(i) <= 300)
u(i) = 0
end

t = 0.0
while (t < tMax)
for i=2:nx-1
unew(i) = u(i) - (dt/2*dx)*a*(u(i+1) - u(i-1)) + (dt^2)/(2*dx.^2)*a^2*(u(i+1) - 2*u(i) + u(i-1))
end

u = unew
t = t + dt
end

plot(x,u,'-o')
The code I wrote for you is in Matlab, but can be ported to Fortran in a matter of minutes. You will need to satisfy boundary conditions. As a side note, you can also reformulate the Lax-Wendroff method as a 2 step method which you will need to do if you were to solve a nonlinear problem.
anon_o likes this.
selig5576 is offline   Reply With Quote

Old   April 20, 2017, 02:26
Default
  #6
Disabled
 
Join Date: Apr 2017
Posts: 8
Rep Power: 9
anon_o is on a distinguished road
Quote:
Originally Posted by selig5576 View Post
This is a very straight forward problem and should take about 5 minutes given a the Lax-Wendroff article on wikipedia.

Code:
nx = 51;
x = zeros(nx,1);
u = zeros(nx,1);
a = 0.5
unew = zeros(nx,1)
dx = 300/nx;


for i=1:nx
x(i) = (i-1)*dx
end

for i=1:nx
if (x(i) > 0 && x(i) <= 50)
u(i) = 0;
else if (x(i) > 50 && x(i) <= 100)
u(i) = 3;
else if (x(i) > 100 && x(i) <= 300)
u(i) = 0
end

t = 0.0
while (t < tMax)
for i=2:nx-1
unew(i) = u(i) - (dt/2*dx)*a*(u(i+1) - u(i-1)) + (dt^2)/(2*dx.^2)*a^2*(u(i+1) - 2*u(i) + u(i-1))
end

u = unew
t = t + dt
end

plot(x,u,'-o')
The code I wrote for you is in Matlab, but can be ported to Fortran in a matter of minutes. You will need to satisfy boundary conditions. As a side note, you can also reformulate the Lax-Wendroff method as a 2 step method which you will need to do if you were to solve a nonlinear problem.
Your code was not working, I wrote this:
CLC

CLEAR ALL

L=300;

DT=2;

DX=2;

A=0.05;

C=A*DT/DX;

M=L/DX;

T=1000;

N=ROUND(T/DT);

E=0.01

FOR I=1:M

IF (I
-.5)*DX<=50
U(I,1)=0;

ELSE IF (I-.5)*DX<=110

U(I,1)=3;

ELSE

U(I,1)=0;

END

END

END

FOR J=2:N

FOR I=2:M-1

U(I,J)=U(I,J-1)-.5*C*(U(I+1,J-1)-U(I-1,J-1))+(E+.5*C^2)*(U(I+1,J-1)-2*U(I,J-1)+U(I-1,J-1));

END

END

FOR I=1:M

X(I)=(I-.5)*DX;

END

PLOT(X,U(:,N))

Sent from my P024 using CFD Online Forum mobile app
anon_o is offline   Reply With Quote

Old   April 20, 2017, 04:35
Default
  #7
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I suggest to see the implementation of the L-W scheme both in non-conservative and conservative form. See the book of Leveque.
anon_o likes this.
FMDenaro is online now   Reply With Quote

Old   April 20, 2017, 10:59
Default LW
  #8
Senior Member
 
Selig
Join Date: Jul 2016
Posts: 213
Rep Power: 11
selig5576 is on a distinguished road
A. It is helpful if you post your code around code tags.
B. You need to be specific on whats not working.
C. I don't see any boundary conditions. Your problem is not posed well with only an initial condition given you have spatial and temporal variables in your problem.

You are looping through the interior domain, but you are not specifying what is happening on the boundary. For example Dirichlet boundary conditions will mean unew(1) = ua, unew(nx) = ub. ua and ub are values that the equation attains at the boundary of your domain. If you have periodic boundary conditions you will have unew(1) = unew(nx).
selig5576 is offline   Reply With Quote

Reply

Tags
fortran, lax wendroff, square wave


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[waves2Foam] Waves2Foam Related Topics ngj OpenFOAM Community Contributions 660 August 20, 2018 13:39
Square wave function/expression in CFX Johndm CFX 2 November 18, 2016 20:22
Periodic B.C for right moving square wave mihirmakwana6 Main CFD Forum 19 January 6, 2016 16:50
square wave air supply condition e.m.sabry Fluent UDF and Scheme Programming 0 January 4, 2015 03:03
UDF for Square Wave Emmanuel FLUENT 2 March 13, 2010 09:36


All times are GMT -4. The time now is 12:58.