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

Error in the solver does not make sense

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By sbaffini

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   September 24, 2016, 17:14
Default Error in the solver does not make sense
  #1
New Member
 
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 9
pawank is on a distinguished road
Maybe this is not the right place to post this question, but I came across this when debugging my solver, and I think it can be related to FD approximations, so posted it here.

I have shared links at the end of this post where you can see the screenshots of my code, the run, etc.

My code is a serial, f90 code, a solver for for compressible N-S equations. I am using Intel compiler. I have a function in the code which calculates derivatives in the z direction using finite difference approximation. I have separate functions, one gives a 4th order approximation, and another gives 2nd order approximation for the kth point in z direction. k goes from 1 to sz(=102 in this case). If k=sz then the derivative is calculated using backward difference, so in the code, the line if k=sz is

if(k==sz) then
ddz = -(-var(i,j,k-2)+4*var(i,j,k-1)-3*var(i,j,k))/(2*dz)

ddz is the name given for derivative and this is 2nd order approximation. Both the 2nd order and 4th order approximation run fine. But or some reason(not important) I copied a line from the 4th order code for same k(i.e. k=sz) and changed the above line to:

if(k==sz) then
ddz = -(-3*var(i,j,k-4)+16*var(i,j,k-3)-36*var(i,j,k-2)+48*var(i,j,k-1)-25*var(i,j,k))/(12*dz)

Just by this change, and everything else in the code remains exactly the same, the code runs but does nothing, that is when I run it, it finishes in less than a second, and does not print anything on the screen like it does before the modification of that line.

point i,j,k-4 exists and thus var(i,j,k-4) has a value. I don't understand why this should not work. And not only this, if i make slight change to the modified line, something like removing the -3 multiplied to the first term(obviously this then becomes wrong expression for approximating the derivative, but i tried out of curiosity) :

if(k==sz) then
ddz = -(var(i,j,k-4)+16*var(i,j,k-3)-36*var(i,j,k-2)+48*var(i,j,k-1)-25*var(i,j,k))/(12*dz)

this code runs. Yes, it will not give correct approximation but still, the code runs, but in case of the prior case, nothing happens.

Note that there is a separate function where everything is 4th order(I uncomment it, and comment the 2nd order function when i want to use 4th order), and ,the 4th order has this same line(line which made the code not do anything) for k=sz , but there there is no issue.

All this does not make sense to me, what am I missing here?

Thanks a lot everyone for your help

Links for screenshots:
Original 2nd order function: https://drive.google.com/open?id=0B7...lpjblRJbUQ4ZjA
Changing one line(code does not do anything with this modification): https://drive.google.com/open?id=0B7...Ec5OTZ2ZHc3VkU
Just removing a constant coefficient in the expression makes the code run: https://drive.google.com/open?id=0B7...XVScjlzeXZ1Q1E
Sample run when it works: https://drive.google.com/open?id=0B7...0FhWnRWaTBoQ2M
Screenshot where the code runs but does not do anything at all: https://drive.google.com/open?id=0B7...VVHLVZrYm5aQVU

Last edited by pawank; September 24, 2016 at 18:23.
pawank is offline   Reply With Quote

Old   September 24, 2016, 17:43
Default
  #2
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
I have not read in details your post but before to read it into all the details, I suggest to use the compiler with all the debug options (array bounds check, type mysmatch and so on) and without any optimization.
Then perform only the first time step and debug online.
FMDenaro is online now   Reply With Quote

Old   September 24, 2016, 17:51
Default
  #3
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
last doubt (maybe stupid), check the Intel Fortran language to see if val() is already an implicit function ... in such a case you cannot use as var(i,j,k)
FMDenaro is online now   Reply With Quote

Old   September 24, 2016, 18:06
Default
  #4
agd
Senior Member
 
Join Date: Jul 2009
Posts: 357
Rep Power: 18
agd is on a distinguished road
Maybe I am misunderstanding, but for any finite difference approximation the coefficients have to sum to zero to ensure that a uniform field possesses no spurious gradients. It looks like you are violating that. Am I missing something?
agd is offline   Reply With Quote

Old   September 24, 2016, 18:11
Default
  #5
New Member
 
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 9
pawank is on a distinguished road
Actually It's var(). and if it was indeed some implicit function, it shouldn't have been working for other cases too. And in that case, just multiplying by a constant also shouldn't have made it work.

And the code compiles fine, shows no errors. It also runs fine. But it does not do anything at all. Runs as normal but finishes as if it had encountered a stop statement at the start itself. But i have no stop statements in the code.

An even weird thing is that if i put a write(write statement to print 'Hello' on the screen) or read statement just before the line where the function ddz is first called in the code, the code runs.
pawank is offline   Reply With Quote

Old   September 24, 2016, 18:16
Default
  #6
New Member
 
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 9
pawank is on a distinguished road
Quote:
Originally Posted by agd View Post
Maybe I am misunderstanding, but for any finite difference approximation the coefficients have to sum to zero to ensure that a uniform field possesses no spurious gradients. It looks like you are violating that. Am I missing something?
You are correct. If you look carefully, there are three Statements. First one is second order, and sum of coefficients is zero. For second which is fourth order, also sum of coefficients are zero, but this line is what creates the problem. the third one in which i change the coefficient of a term of the second statement, which then becomes wrong formulation. But by doing this code runs, obviously the code diverges after a few iterations, but at least it runs.
pawank is offline   Reply With Quote

Old   September 24, 2016, 18:37
Default
  #7
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Just as further idea...have you transferred the code by means of FTP or by other media? I suspect you have some hidden character that usually stems from trasfering of the files.
I got similar problem passing from unix system to others and using different compilers. I fixed that by using a batch file:

#!/bin/csh

foreach a ($*)
tr -d "\r" < $a > _tmp_$a
ls -l $a _tmp_$a
mv _tmp_$a $a
end
FMDenaro is online now   Reply With Quote

Old   September 24, 2016, 18:38
Default
  #8
Senior Member
 
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,773
Rep Power: 71
FMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura aboutFMDenaro has a spectacular aura about
Quote:
Originally Posted by pawank View Post
Actually It's var(). and if it was indeed some implicit function, it shouldn't have been working for other cases too. And in that case, just multiplying by a constant also shouldn't have made it work.

And the code compiles fine, shows no errors. It also runs fine. But it does not do anything at all. Runs as normal but finishes as if it had encountered a stop statement at the start itself. But i have no stop statements in the code.

An even weird thing is that if i put a write(write statement to print 'Hello' on the screen) or read statement just before the line where the function ddz is first called in the code, the code runs.

yes, it is var()
FMDenaro is online now   Reply With Quote

Old   September 24, 2016, 18:44
Default
  #9
New Member
 
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 9
pawank is on a distinguished road
Quote:
Originally Posted by FMDenaro View Post
Just as further idea...have you transferred the code by means of FTP or by other media? I suspect you have some hidden character that usually stems from trasfering of the files.
I got similar problem passing from unix system to others and using different compilers. I fixed that by using a batch file:

#!/bin/csh

foreach a ($*)
tr -d "\r" < $a > _tmp_$a
ls -l $a _tmp_$a
mv _tmp_$a $a
end

No actually. All work has been done on my lab computer. I sometimes work remotely from my dorm room, but i don't transfer anything.
But thanks anyway may be useful in other cases..
pawank is offline   Reply With Quote

Old   September 25, 2016, 05:04
Default
  #10
Senior Member
 
sbaffini's Avatar
 
Paolo Lampitella
Join Date: Mar 2009
Location: Italy
Posts: 2,151
Blog Entries: 29
Rep Power: 39
sbaffini will become famous soon enoughsbaffini will become famous soon enough
Send a message via Skype™ to sbaffini
The way to proceed is always to shrink the problem down to a minimum (not) working example. This is important because you cannot exclude a compiler error (even if it's extremely rare).
kaya likes this.
sbaffini 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
Population Balance Modeling (PBM) - Ansys Fluent chittipo FLUENT 164 November 18, 2023 11:54
compiling firefoam Farshad_Noravesh OpenFOAM 27 December 24, 2012 04:21
OpenFOAM 1.7.1 installation problem on OpenSUSE 11.3 flakid OpenFOAM Installation 16 December 28, 2010 08:48
in - pressure, out pressure, is that make sense? Marteusz CFX 6 July 15, 2009 14:33
Setting a B.C using UserFortran in 4.3 tokai CFX 10 July 17, 2001 16:25


All times are GMT -4. The time now is 02:51.