|
[Sponsors] |
April 18, 2017, 12:08 |
Square wave lax wendroff fortran.f90
|
#1 |
Disabled
Join Date: Apr 2017
Posts: 8
Rep Power: 9 |
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😉 |
|
April 18, 2017, 12:53 |
|
#2 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
This is a homework you can find developed in many textbooks...
|
|
April 18, 2017, 15:40 |
|
#3 |
Disabled
Join Date: Apr 2017
Posts: 8
Rep Power: 9 |
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 |
|
April 18, 2017, 15:47 |
|
#4 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
Quote:
http://mathcenter.hust.edu.cn/Upload...98740d59f8.pdf |
||
April 18, 2017, 20:07 |
Problem
|
#5 |
Senior Member
Selig
Join Date: Jul 2016
Posts: 213
Rep Power: 11 |
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') |
|
April 20, 2017, 02:26 |
|
#6 | |
Disabled
Join Date: Apr 2017
Posts: 8
Rep Power: 9 |
Quote:
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 |
||
April 20, 2017, 04:35 |
|
#7 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
I suggest to see the implementation of the L-W scheme both in non-conservative and conservative form. See the book of Leveque.
|
|
April 20, 2017, 10:59 |
LW
|
#8 |
Senior Member
Selig
Join Date: Jul 2016
Posts: 213
Rep Power: 11 |
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). |
|
Tags |
fortran, lax wendroff, square wave |
|
|
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 |