CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   About extracting the normals to faces on a patch (https://www.cfd-online.com/Forums/openfoam/131424-about-extracting-normals-faces-patch.html)

samiam1000 March 14, 2014 09:32

About extracting the normals to faces on a patch
 
Dear All,

I am studying the flow around an airfoil. The point is that I am interested in saving a file containing the normal vectors to the faces on the patch "airfoil". Do you know how I can get this?

Thanks a lot,
Samuele

Hannes_Kiel March 14, 2014 13:07

You could modify writeCellCentres to write Sf() instead of magSf().

samiam1000 March 17, 2014 10:44

Dear Hannes,

thanks for writing.

Actually, I was thinking to compute cell normals run-time and not as post-processing.

I opened the elbow tutorial and I modified the controlDict as follows:

Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      controlDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
libs
(
    "libOpenFOAM.so"
);

application    icoFoam;

startFrom      latestTime;

startTime      0;

stopAt          endTime;

endTime        10;

deltaT          0.05;

writeControl    timeStep;

writeInterval  20;

purgeWrite      0;

writeFormat    ascii;

writePrecision  6;

writeCompression off;

timeFormat      general;

timePrecision  6;

runTimeModifiable true;

functions
{
    #include "computeNormals"
}

// ************************************************************************* //

where the computNormals is:
Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/

computeNormals
{
        functionObjectLibs ("libutilityFunctionObjects.so");
        type coded;
        redirectType computeNormals;
        outputControl outputTime;
        code
        #{
                polyPatch velocity-inlet-5;
                const vectorField::subField normals = patch.faceAreas();
        #};
}

Nevertheless, it does not work and I get the following error:
Code:

lab@labPC:~/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow$ icoFoam
/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.2.2                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 2.2.2-9739c53ec43f
Exec  : icoFoam
Date  : Mar 17 2014
Time  : 16:44:05
Host  : "labPC"
PID    : 9593
Case  : /home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Allowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time

Create mesh for time = 0

Reading transportProperties

Reading field p

Reading field U

Reading/calculating face flux field phi


Starting time loop

Using dynamicCode for functionObject computeNormals at line 13 in "/home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals"
Creating new library in "dynamicCode/computeNormals/platforms/linux64GccDPOpt/lib/libcomputeNormals_f9d5dbd87ebb60fe8eb22f95db6cc5f67e8f26a7.so"
Invoking "wmake -s libso /home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/dynamicCode/computeNormals"
wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file functionObjectTemplate.C
Making dependency list for source file FilterFunctionObjectTemplate.C
/home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals: In member function ‘virtual void Foam::computeNormalsFunctionObject::write()’:
/home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals:19:19: error: expected initializer before ‘-’ token
/home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals:20:41: error: ‘patch’ was not declared in this scope
/home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals:20:31: warning: unused variable ‘normals’ [-Wunused-variable]
make: *** [Make/linux64GccDPOpt/functionObjectTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/computeNormals/platforms/linux64GccDPOpt/lib/libcomputeNormals_f9d5dbd87ebb60fe8eb22f95db6cc5f67e8f26a7.so"


file: /home/lab/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow/system/controlDict.functions.computeNormals from line 13 to line 18.

    From function codedBase::createLibrary(..)
    in file db/dynamicLibrary/codedBase/codedBase.C at line 202.

FOAM exiting

lab@labPC:~/OpenFOAM/OpenFOAM-2.2.2/tutorials/incompressible/icoFoam/elbow$

Any idea?

Thanks a lot,
Samuele

Hannes_Kiel March 17, 2014 12:58

Hi Samuele,

first of all the compiler does not like your patch name. If you need to have it in the code, you might want to try something like velocityInlet5 instead.

Regarding the coded function object this is just a wild guess as I haven't used it:
code
#{
// get normals

const surfaceVectorField& normals = mesh().Sf();
// Write
normals.write();
#}

possibly: normals.boundaryField().write()

Good Luck
Hannes

samiam1000 March 19, 2014 08:15

1 Attachment(s)
Dear Hannes,

thanks a lot.

What you suggested works pretty well and I have a file names "S" in the constant/polyMesh dir. That's very nice.
Nevertheless, I am not completely satisfied, yet. I would need 2 improvements:

1. computing the normals on a patch only;
2. rescale the normals in order to have magnitude 1;

Could you help in doing this?

Thanks a lot,
Samuele

PS: attached a case. If you run blockMesh and icoFoam (it's the cavity case), you can get what I wrote above.

Héctor Lodoso August 9, 2018 06:53

Progress??
 
Hi Samuele,


Did you make any progress in this regard? I am dealing with the same issue...


Many thanks!
Héctor



Quote:

Originally Posted by samiam1000 (Post 480866)
Dear Hannes,

thanks a lot.

What you suggested works pretty well and I have a file names "S" in the constant/polyMesh dir. That's very nice.
Nevertheless, I am not completely satisfied, yet. I would need 2 improvements:

1. computing the normals on a patch only;
2. rescale the normals in order to have magnitude 1;

Could you help in doing this?


Thanks a lot,
Samuele

PS: attached a case. If you run blockMesh and icoFoam (it's the cavity case), you can get what I wrote above.



All times are GMT -4. The time now is 18:50.