|
[Sponsors] |
September 24, 2016, 18:14 |
Error in the solver does not make sense
|
#1 |
New Member
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 10 |
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 19:23. |
|
September 24, 2016, 18:43 |
|
#2 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
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. |
|
September 24, 2016, 18:51 |
|
#3 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
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)
|
|
September 24, 2016, 19:06 |
|
#4 |
Senior Member
Join Date: Jul 2009
Posts: 358
Rep Power: 19 |
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?
|
|
September 24, 2016, 19:11 |
|
#5 |
New Member
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 10 |
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. |
|
September 24, 2016, 19:16 |
|
#6 |
New Member
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 10 |
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.
|
|
September 24, 2016, 19:37 |
|
#7 |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
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 |
|
September 24, 2016, 19:38 |
|
#8 | |
Senior Member
Filippo Maria Denaro
Join Date: Jul 2010
Posts: 6,896
Rep Power: 73 |
Quote:
yes, it is var() |
||
September 24, 2016, 19:44 |
|
#9 | |
New Member
Pawan Kerkar
Join Date: Sep 2016
Posts: 29
Rep Power: 10 |
Quote:
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.. |
||
September 25, 2016, 06:04 |
|
#10 |
Senior Member
|
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).
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Population Balance Modeling (PBM) - Ansys Fluent | chittipo | FLUENT | 164 | November 18, 2023 12:54 |
compiling firefoam | Farshad_Noravesh | OpenFOAM | 27 | December 24, 2012 05:21 |
OpenFOAM 1.7.1 installation problem on OpenSUSE 11.3 | flakid | OpenFOAM Installation | 16 | December 28, 2010 09:48 |
in - pressure, out pressure, is that make sense? | Marteusz | CFX | 6 | July 15, 2009 15:33 |
Setting a B.C using UserFortran in 4.3 | tokai | CFX | 10 | July 17, 2001 17:25 |