CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Pre-Processing (https://www.cfd-online.com/Forums/openfoam-pre-processing/)
-   -   How to get coordinate of maxpressure on patch surface (https://www.cfd-online.com/Forums/openfoam-pre-processing/201934-how-get-coordinate-maxpressure-patch-surface.html)

terry@man May 16, 2018 00:01

How to get coordinate of maxpressure on patch surface
 
Hello Formers,

I want to get coordinate of maxpressure on patch surface.

Because I am trying cavitaion and erosion analysis and want to know which area(point) happened big pressure , critical erosion.

But fuction object(fieldminmax,facesource) doesn't match my needs.

If you have any ideas, please teach me.

Thank you

simrego May 16, 2018 04:15

Hi!

What if you use codedFunctionObject?
You just have to go through all of your faces on a given patch. And it will give the face center where you have the bigest pressure.

terry@man May 16, 2018 19:30

Thank you for your answer

I study it and try.

peyman.davvalo.khongar May 29, 2018 03:41

Quote:

Originally Posted by terry@man (Post 692453)
Hello Formers,

I want to get coordinate of maxpressure on patch surface.

Because I am trying cavitaion and erosion analysis and want to know which area(point) happened big pressure , critical erosion.

But fuction object(fieldminmax,facesource) doesn't match my needs.

If you have any ideas, please teach me.

Thank you


Moi!

Here is a simple code using codedFunctionObject. It is tested with OpenFOAM dev version. defaultFaces is the name of the patch you want to get the max of pressure. The result will be shown in the terminal, although you can work with IO to write it in a file.


Code:

    minMaxPatch
    {
        functionObjectLibs ( "libutilityFunctionObjects.so" );
        enabled        true;
        type            coded;
        executeControl      writeTime;
        executeInterval 1;
        redirectType    minMaxPatch;
        writeControl  writeTime;
        writeInterval 1;

        codeOptions
        #{
            -I$(LIB_SRC)/meshTools/lnInclude
        #};

        codeExecute
        #{
       
                label patchID = mesh().boundaryMesh().findPatchID("defaultFaces");
 
                       
                const volScalarField& p
                (
                    mesh().lookupObject<volScalarField>("p")
                );

                scalar maxP = max(p.boundaryField()[patchID]);
                scalar xmax = 0;
                scalar ymax = 0;
                scalar zmax = 0;
                forAll(p.boundaryField()[patchID], faceI)
                    {
                      if (p.boundaryField()[patchID][faceI]==maxP)
                      {
                          xmax = mesh().Cf().boundaryField()[patchID][faceI].x();
                          ymax = mesh().Cf().boundaryField()[patchID][faceI].y();
                          zmax = mesh().Cf().boundaryField()[patchID][faceI].z();
                            } 
               
                }

                Info << "Max pressure is: " << maxP << "at location "<<"("<<xmax <<","<< ymax<<","<<zmax<<")"<<endl;

      #};
    }

Moikka,

Peyman

terry@man June 4, 2018 22:13

Hi peyman

Thank you your code!
I confirmed that it works good.

By the way , I migth as well introdude my wrong code.

It operates properly with only single core, but When I choose parallel, It outputs wrong data.

peyman's code uses boudaryfield
my code uses boundaryMesh

func
{
type coded;
redirectType test;
code
#{
const volScalarField& p = mesh().lookupObject<volScalarField>("p");
label pieceID = mesh().boundaryMesh().findPatchID("piece");
const polyPatch &pp =mesh().boundaryMesh()[pieceID];
const scalarField& patchPressure =p.boundaryField()[pieceID];
const scalar &pmax = max(patchPressure);
float py;
float pz;
for(int i=0; i<patchPressure.size(); i++){
if(patchPressure[i]==pmax){
py = pp.faceCentres()[i].y();
pz = pp.faceCentres()[i].z();
break;
}
}
Info << "py = " <<py <<endl;
Info << "pz = " <<pz <<endl;
#};
outputControl timeStep;
outputInterval 1;
}

thanks,

terry@man June 6, 2018 01:56

Hi peyman

May I ask you question?

Your code operates properly with single core, but when I choose parallel ,your code output wrong maxpressure and coordinte just like my code.

I output follow data for checking the cause of this situation.

---------------p.boundaryField()[patchID]------------------------

Single:
piece
{
type fixedFluxPressure;
gradient uniform 0;
value nonuniform List<scalar>
10640
(
500000
500000
.
.
.

Parallel:
piece
{
type fixedFluxPressure;
gradient nonuniform 0();
value nonuniform 0();
}
---------------------------------------------------

As a result, If I choose parallel , patch(piece) faces are divided and distributed to each processor(Example↓).

Therefore, in the situation of parallel, p.boundaryField()[patchID] accesses no data .

Do you know the solution of this situation or anybody knows?

Example)
procBoundary0to1
{
type processor;
value nonuniform List<scalar>
5816
(
500014
.
.


All times are GMT -4. The time now is 23:35.