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

Crank-Nicolson help request

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 3, 2012, 17:40
Default Crank-Nicolson help request
  #1
New Member
 
Join Date: Nov 2012
Posts: 2
Rep Power: 0
sezo85 is on a distinguished road
Hi everyone,

I am a fresher in numerical techniques and I am developing a code to simulate a compressor. I am using FORTRAN 95, my code will be a quasi-1D solver. I am using common Euler equations, with an additional equation to solve the tangential momentum.
Till now I have been using the MacCormark scheme for the time integration together with a finite difference approach.
Now I am stuck since I am dealing with a compressor characterized by a very long domain and very low mach numbers...to fix the convergence problem I implemented Crank Nicolson ..and for the moment it doesn't want to work..
Could anyone give me any advice??? To implement this scheme I followed the book by Anderson..I reported my code below..

ADDITIONAL INFORMATION:
-my equations are written in the conservative form;
-DF are the derivatives of the fluxes respect to U;
-1,2,3,4 correspond to mass conservation, axial momentum, tangential momentum and energy equation;
-S terms collect all the sources to simulate a compressor and changes in cross section;
-D is what is know at every timestep..as explained in Anderson book.

Please If anyone can spot an error..it would be great

Thank you very much.

SUBROUTINE CrankNicolson

USE Var_Declar
USE BASIS_R
IMPLICIT NONE

DT(PP)=0.0000005d0

!ARTIFICIAL VISCOSITY
DO j=2,SIZE_ST-1

VIS1(j,PP)=0.8D0*ABS(P(j+1,PP)-2.0D0*P(j,PP)+P(j-1,PP))/(P(j+1,PP)+2.0D0*P(j,PP)+P(j-1,PP))*(U1(j+1,PP)-2.0D0*U1(j,PP)+U1(j-1,PP))
VIS2(j,PP)=0.8D0*ABS(P(j+1,PP)-2.0D0*P(j,PP)+P(j-1,PP))/(P(j+1,PP)+2.0D0*P(j,PP)+P(j-1,PP))*(U2(j+1,PP)-2.0D0*U2(j,PP)+U2(j-1,PP))
VIS3(j,PP)=0.8D0*ABS(P(j+1,PP)-2.0D0*P(j,PP)+P(j-1,PP))/(P(j+1,PP)+2.0D0*P(j,PP)+P(j-1,PP))*(U3(j+1,PP)-2.0D0*U3(j,PP)+U3(j-1,PP))
VIS4(j,PP)=0.8D0*ABS(P(j+1,PP)-2.0D0*P(j,PP)+P(j-1,PP))/(P(j+1,PP)+2.0D0*P(j,PP)+P(j-1,PP))*(U4(j+1,PP)-2.0D0*U4(j,PP)+U4(j-1,PP))

END DO

DO j=1,SIZE_ST
!Evaluation DF matrix of known terms at the previous timestep
!DF_1(j,PP)=(F1(J+1,pp)-F1(J-1,pp))/(2*(U1(J+1,pp)-U1(J-1,pp)))!0.0D0
!
!DF_2(j,PP)=(F2(J+1,pp)-F2(J-1,pp))/(2*(U2(J+1,pp)-U2(J-1,pp)))!(3-GAMMA)*U2(j,PP)/U1(j,PP)
!
!DF_3(j,PP)=(F3(J+1,pp)-F3(J-1,pp))/(2*(U3(J+1,pp)-U3(J-1,pp)))!(U2(j,PP)/U1(j,PP))
!
!DF_4(j,PP)=(F4(J+1,pp)-F4(J-1,pp))/(2*(U4(J+1,pp)-U4(J-1,pp)))!U2(j,PP)/U1(j,PP)*GAMMA

DF_1(j,PP)=0.0D0

DF_2(j,PP)=(3-GAMMA)*U2(j,PP)/U1(j,PP)

DF_3(j,PP)=(U2(j,PP)/U1(j,PP))

DF_4(j,PP)=U2(j,PP)/U1(j,PP)*GAMMA
ENDDO

DO j=2,SIZE_ST-1

!Evaluation source terms
S_1(j,PP)=0.0D0

S_2(j,PP)=J2_STAR(j,PP)*(LOG(SAREA(j+1,PP))-LOG(SAREA(j-1,PP)))/(2.0d0*DX(j,PP))+F_Z(j,PP)+J2_THETA(j,PP)*(MEAN_RA DIUS(j+1,PP)-MEAN_RADIUS(j-1,PP))/(2*DX(j,PP))

S_3(j,PP)=F_T(j,PP)/mean_radius(j,PP)+F_K(j,PP)*(MEAN_RADIUS(j+1,PP)-MEAN_RADIUS(j-1,PP))/(2.0d0*DX(j,PP))

S_4(j,PP)=W(j,PP)

! Evaluation vector D

D_1(j,PP)=U1(j,PP)-DT(PP)/(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),DIAG_B(:,CN),DIAG_C(:,CN),VEC T_R(:,CN),SOL(:,CN),SIZE_ST-2,CODE)



END DO
DO j=2,SIZE_ST-1
!U1(J,PP)=SOL(SIZE_ST-2-(J-2),1)+VIS1(J,PP)
!U2(J,PP)=SOL(SIZE_ST-2-(J-2),2)+VIS2(J,PP)
!U3(J,PP)=SOL(SIZE_ST-2-(J-2),3)+VIS3(J,PP)
!U4(J,PP)=SOL(SIZE_ST-2-(J-2),4)+VIS4(J,PP)

U1(J,PP)=SOL(J-1,1)+VIS1(J,PP)
U2(J,PP)=SOL(J-1,2)+VIS2(J,PP)
U3(J,PP)=SOL(J-1,3)+VIS3(J,PP)
U4(J,PP)=SOL(J-1,4)+VIS4(J,PP)

END DO
CALL BOUNDARY_CONDITIONS

DO J=1,SIZE_ST

F1(j,PP)=U2(j,PP)

F2(j,PP)=U2(j,PP)**2/U1(j,PP)+GAMONE*(U4(j,PP)-(U1(j,PP)/2.0D0)*((U2(j,PP)/U1(j,PP))**2+(U3(j,PP)/U1(j,PP))**2))

F3(j,PP)=U2(j,PP)*U3(j,PP)/U1(j,PP)

F4(j,PP)=U2(j,PP)*U4(j,PP)/U1(j,PP)+U2(j,PP)*GAMONE*(U4(j,PP)/U1(j,PP)-0.50D0*((U2(j,PP)/U1(j,PP))**2+(U3(j,PP)/U1(j,PP))**2))

J2_STAR(j,PP)= GAMONE*(U4(j,PP)-(U1(j,PP)/2.0D0)*((U2(j,PP)/U1(j,PP))**2+(U3(j,PP)/U1(j,PP))**2))

J2_THETA(j,PP)=((U3(j,PP))**2)/U1(j,PP)*(1/MEAN_RADIUS(j,PP))

F_K(j,PP)=-U2(j,PP)*U3(j,PP)/U1(j,PP)*(1/MEAN_RADIUS(j,PP))

END DO

END SUBROUTINE CrankNicolson
sezo85 is offline   Reply With Quote

Reply


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
[OpenFOAM] Saving ParaFoam views and case sail ParaView 9 November 25, 2011 15:46
Crank Nicolson scheme msrinath80 OpenFOAM Running, Solving & CFD 6 November 14, 2010 13:59
[OpenFOAM] Xwindows crash with paraview save srinath ParaView 1 October 15, 2008 09:37
Crank Nicolson. ! Main CFD Forum 0 September 5, 2005 12:52
Convergence problem using crank nicolson method Carlos Gonzalez CFX 1 September 24, 2002 16:52


All times are GMT -4. The time now is 09:49.