CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   interfoam - maximal velocity in water phase (https://www.cfd-online.com/Forums/openfoam-programming-development/161746-interfoam-maximal-velocity-water-phase.html)

matejmuller October 27, 2015 21:47

interfoam - maximal velocity in water phase
 
Hi!

I want to get the maximal velocities for each velocity component in the water phase in each time step and get them in the log file. I've tried:

Code:

scalar maxUx_water=0
forAll(U,celli)
{
    if (alpha1[celli]>0.5)
        {
              if (U[celli].x() > maxUx_water)
          {
              maxUx_water = U[celli].x();
          }
        }
}
Info<< "maxUx_water= "<< maxUx_water << endl;

but something is not working correctly. The values are not right (they are too small). Any ideas how to solve this?

Thanks!

Matej

demichie October 28, 2015 03:25

I think you need the absolute value here:

maxUx_water = U[celli].x()



Mattia

akidess October 28, 2015 03:52

Code:

Info << "maxU: " << pos(alpha1-0.5)*max(U) << endl;
or, if you want just a component:
Code:

Info << "maxU: " << pos(alpha1-0.5)*max(U.component(0)) << endl;
(as Mattia already pointed out you may want to also print the minimum or use absolute values)

How do you know your values are too small?

matejmuller October 28, 2015 08:26

Hi!

Thanks for the responses.

Mattia, I need the minimal component values too, so I thought I'd use the
same code as for the maximal.

Anton, with my approach the given velocity values are smaller than obtained in postprocessing in paraView.

I don't know what the code pos(alpha1-0.5) does exactly, but the whole line

Code:

Info << "maxU: " << pos(alpha1-0.5)*max(U.component(0)) << endl;
gives a list of velocities for all cells. Weirdly, the values are eather 0, or the same value as max(U.component(0)).

regards, matej

akidess October 28, 2015 10:14

Are you looking at cell values or interpolated values in Paraview?

I made a mistake in my code - pos() will return 1 whenever the expression in the brackets is positive, otherwise negative. And it does so for every cell, which is why you got what you got. So how to fix this?


.
.
.

Info << "maxU: " << max(pos(alpha1-0.5)*U.component(0)) << endl;

Too bad I couldn't hide the answer behind a spoiler tag ;)

matejmuller October 28, 2015 10:48

I'm looking the cell values in paraView, and now they are correct! Thank you.

Although, the line above gives:

Code:

maxU: max((pos((alpha.water-0.5))*U.component(0))) [0 1 -1 0 0 0 0] 0.549513
and I need only the values like:

Code:

maxU: 0.549513
Any ideas?

Matej

akidess October 30, 2015 01:41

Yes, what you want is the value. Hence
Code:

max((pos((alpha.water-0.5))*U.component(0))).value()
should do the trick.

JM27 November 6, 2020 06:49

does this work in parallel?
 
Hi,

Thanks for the interesting post. I have tested this code on the depthCharge tutorial and it works perfectly when running in serial. However it does not work in parallel, and crashes after the first time-step without writing the max velocity in the liquid. I am using scotch for decomposition.

Have you also tried this code in parallel and has it worked for you?

matejmuller November 6, 2020 07:42

Hi, for me it works also in parallel (I also use scotch):

for max Ux:

Code:

max(pos(alpha1-0.5)*U.component(0)).value()
best regards, Matej

JM27 November 6, 2020 08:45

Hi Matej,

Thanks for the response especially on a not so recent post. May I ask which OF version you are using?

I am using v5. Just trying to understand what could be causing the issue as I never had trouble with coded function objects in parallel until now.

This is the error I get when running in parallel:

Code:

maxU: Fatal error in MPI_Recv: Message truncated, error stack:
MPI_Recv(224).....................: MPI_Recv(buf=0x7ffd14e0b6b0, count=8, MPI_BYTE, src=1, tag=1, MPI_COMM_WORLD, status=0x7ffd14e0b620) failed
MPIDI_CH3U_Receive_data_found(131): Message from rank 1 and tag 1 truncated; 5816 bytes received but buffer size is 8

I suspect max might be causing the issue in parallel, but still testing.

matejmuller November 6, 2020 09:08

I actually didn't use this in the coded function object (i don't think that was an option back then). I've compiled a new solver and put the code somewhere at the end of interFoam.C

best regards, m

JM27 November 6, 2020 11:57

resolved
 
Hi Matej,

That must explain why you did not run into this issue when running in parallel.

As I suspected, the MPI error arises due to the max keyword inside Pstream (for those using coded function object). For others who might encounter this issue: I have resolved this by rewriting some of the code, similar to that described in this post:

https://www.cfd-online.com/Forums/op...tml#post719879

Thanks again Matej for your input :)

JM27 November 12, 2020 08:24

Hi,

I am now trying to use a similar code to calculate the largest negative value of Uy in the liquid phase. However, I have so far been unable to do this.

I have tried replacing max with min, but this will print the minimum positive/absolute value rather than the largest negative value of Uy:

Code:

min(pos(alpha1-0.5)*U.component(1)).value()
using the above code, the minimum value is not the largest negative value I can see in paraview.

Any ideas of how to do this?

p.s. I've also tried changing pos with neg but I understand this would mean that the maximum being calculated is that of alpha2 and not alpha1.


All times are GMT -4. The time now is 04:17.