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/)
-   -   Adding side force to forceCoeffs.C (https://www.cfd-online.com/Forums/openfoam-programming-development/92884-adding-side-force-forcecoeffs-c.html)

drrbradford September 28, 2011 08:53

Adding side force to forceCoeffs.C
 
I have edited forceCoeffs.C to include side forces by basically copying the dragDig, dragForce etc entries and adding an additional line with sfDir and sideForce. When I have recompiled forceCoeffs and added a sfDir option to my controlDict it gives no output for lift, drag nor side force.

An example of how I have edited the forceCoeffs.C:

Code:

        scalar liftForce = totForce & liftDir_;
        scalar dragForce = totForce & dragDir_;
        scalar sideForce = totForce & sfDir_;
        scalar pitchMoment = totMoment & pitchAxis_;

        scalar Cl = liftForce/(Aref_*pDyn);
        scalar Cd = dragForce/(Aref_*pDyn);
        scalar Cy = sideForce/(Aref_*pDyn);
        scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);

forceCoeffs works based on the totForce value so I don't need to edit the forces function, right? I take it I need to make some changes in the included .H files but I can't see any references to lift or drag except in forceCoeffs.C.

Any help is appreciated,
Daniel.

drrbradford September 28, 2011 10:24

I made a typo in the .C file which I have corrected and now it works. Sorry about that.

For anyone interested, the new forceCoeffs.C is below and all you have to do is add a sfDir specification in the functions subdict of the controlDict file.

Code:

/*---------------------------------------------------------------------------*\
  =========                |
  \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox
  \\    /  O peration    |
    \\  /    A nd          | Copyright (C) 2004-2010 OpenCFD Ltd.
    \\/    M anipulation  |
-------------------------------------------------------------------------------
License
    This file is part of OpenFOAM.

    OpenFOAM is free software: you can redistribute it and/or modify it
    under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    for more details.

    You should have received a copy of the GNU General Public License
    along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "forceCoeffs.H"
#include "dictionary.H"
#include "Time.H"
#include "Pstream.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

defineTypeNameAndDebug(Foam::forceCoeffs, 0);


// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::forceCoeffs::forceCoeffs
(
    const word& name,
    const objectRegistry& obr,
    const dictionary& dict,
    const bool loadFromFiles
)
:
    forces(name, obr, dict, loadFromFiles),
    liftDir_(vector::zero),
    dragDir_(vector::zero),
    sfDir_(vector::zero),
    pitchAxis_(vector::zero),
    magUInf_(0.0),
    lRef_(0.0),
    Aref_(0.0)
{
    read(dict);
}


// * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //

Foam::forceCoeffs::~forceCoeffs()
{}


// * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //

void Foam::forceCoeffs::read(const dictionary& dict)
{
    if (active_)
    {
        forces::read(dict);

        // Directions for lift and drag forces, and pitch moment
        dict.lookup("liftDir") >> liftDir_;
        dict.lookup("dragDir") >> dragDir_;
        dict.lookup("sfDir") >> sfDir_;
        dict.lookup("pitchAxis") >> pitchAxis_;

        // Free stream velocity magnitude
        dict.lookup("magUInf") >> magUInf_;

        // Reference length and area scales
        dict.lookup("lRef") >> lRef_;
        dict.lookup("Aref") >> Aref_;
    }
}


void Foam::forceCoeffs::writeFileHeader()
{
    if (forcesFilePtr_.valid())
    {
        forcesFilePtr_()
            << "# Time" << tab << "Cd" << tab << "Cl" << tab << "Cy" << tab << "Cm" << endl;
    }
}


void Foam::forceCoeffs::execute()
{
    // Do nothing - only valid on write
}


void Foam::forceCoeffs::end()
{
    // Do nothing - only valid on write
}


void Foam::forceCoeffs::write()
{
    if (active_)
    {
        // Create the forces file if not already created
        makeFile();

        forcesMoments fm = forces::calcForcesMoment();

        scalar pDyn = 0.5*rhoRef_*magUInf_*magUInf_;

        vector totForce = fm.first().first() + fm.first().second();
        vector totMoment = fm.second().first() + fm.second().second();

        scalar liftForce = totForce & liftDir_;
        scalar dragForce = totForce & dragDir_;
        scalar sideForce = totForce & sfDir_;
        scalar pitchMoment = totMoment & pitchAxis_;

        scalar Cl = liftForce/(Aref_*pDyn);
        scalar Cd = dragForce/(Aref_*pDyn);
        scalar Cy = sideForce/(Aref_*pDyn);
        scalar Cm = pitchMoment/(Aref_*lRef_*pDyn);

        if (Pstream::master())
        {
            forcesFilePtr_()
                << obr_.time().value() << tab
                << Cd << tab << Cl << tab << Cy << tab << Cm << endl;

            if (log_)
            {
                Info<< "forceCoeffs output:" << nl
                    << "    Cd = " << Cd << nl
                    << "    Cl = " << Cl << nl
                    << "    Cy = " << Cy << nl
                    << "    Cm = " << Cm << nl
                    << endl;
            }
        }
    }
}


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


Rider October 29, 2012 02:12

Hi all,

I'm interested by the new forceCoeffs.C file.

I try to test it but it don't works.

I updated the forceCoeffs.C, then I added sfDir line in the forceCoeffs file. Finally, I recompile OpenFOAM. What is wrong with the method?

Thanks for your explanation ;)

Rider October 30, 2012 03:21

No suggestion ?

wyldckat November 4, 2012 05:49

1 Attachment(s)
Hi Rider,

Attached is the adapted code based on drrbradford's modifications. The main difference is only how the modifications were made:
  1. I first made a copy of the library "$FOAM_SRC/postProcessing/functionObjects/forces" onto my personal user folder:
    Code:

    cd $FOAM_RUN
    cd ..
    cp -r $FOAM_SRC/postProcessing/functionObjects/forces forceDirCoeffs

  2. Removed the excess folders in this new folder "forceDirCoeffs" and renamed "forceCoeffs" folder inside it, leaving this way only two folders:
    Code:

    forceDirCoeffs
    Make

  3. Edited "Make/files" and this is what's inside it now:
    Code:

    forceDirCoeffs/forceDirCoeffs.C
    forceDirCoeffs/forceDirCoeffsFunctionObject.C

    LIB = $(FOAM_USER_LIBBIN)/libforceDirCoeffs

  4. Edited "Make/options" and made it depend/include the original function object library, since there are things we need from it (I think...):
    Code:

    EXE_INC = \
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude \
        -I$(LIB_SRC)/sampling/lnInclude \
        -I$(LIB_SRC)/transportModels \
        -I$(LIB_SRC)/turbulenceModels \
        -I$(LIB_SRC)/turbulenceModels/LES/LESdeltas/lnInclude \
        -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
        -I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude

    LIB_LIBS = \
        -lincompressibleTransportModels \
        -lincompressibleRASModels \
        -lincompressibleLESModels \
        -lbasicThermophysicalModels \
        -lspecie \
        -lcompressibleRASModels \
        -lcompressibleLESModels \
        -lfiniteVolume \
        -lmeshTools \
        -lsampling \
        -lforces

  5. Renamed all files inside the sub-folder "forceDirCoeffs", adding "Dir" after "force".
  6. Edited all of the renamed files and did the same search and replace of "forceCoeffs" to "forceDirCoeffs".
  7. Finally added the modifications described in the first two posts.
To build it:
Code:

wmake libso
To use it:
  1. Instead of referring to the library "libforces.so", you now refer to "libforceDirCoeffs.so".
  2. Instead of "forceCoeffs" in the case's "controlDict" file, you now use "forceDirCoeffs". Keep in mind that you now also have a vector entry named "sfDir".
I haven't tested this, so I can only assume that it works :D


Best regards,
Bruno

Rider November 5, 2012 03:48

Thank you for this work and your time.

When I used "wmake" or "sudo bash ./Allmake" in the directory "functionObjects", I had this error message "wmake : command not found"

What is the problem ?

Thanks all.

wyldckat November 5, 2012 03:54

Hi Rider,

Unpack the package in a user folder of yours, not in OpenFOAM's source code folder!

And use:
Code:

wmake libso
for building the contents of the previously attached package!

To get a better understanding of what I'm talking/writing about, perhaps you should study a bit this tutorial: http://openfoamwiki.net/index.php/Ho...ure_to_icoFoam

Best regards,
Bruno

Rider November 5, 2012 05:19

Hi Bruno,

I had misunderstood the structure of the modification ... It works.

I will test it now ;)

Thanks a lot !

himanshu28 September 30, 2013 06:22

Error in compiling utility
 
Quote:

Originally Posted by wyldckat (Post 390138)
Hi Rider,

Attached is the adapted code based on drrbradford's modifications. The main difference is only how the modifications were made:
  1. I first made a copy of the library "$FOAM_SRC/postProcessing/functionObjects/forces" onto my personal user folder:
    Code:

    cd $FOAM_RUN
    cd ..
    cp -r $FOAM_SRC/postProcessing/functionObjects/forces forceDirCoeffs

  2. Removed the excess folders in this new folder "forceDirCoeffs" and renamed "forceCoeffs" folder inside it, leaving this way only two folders:
    Code:

    forceDirCoeffs
    Make

  3. Edited "Make/files" and this is what's inside it now:
    Code:

    forceDirCoeffs/forceDirCoeffs.C
    forceDirCoeffs/forceDirCoeffsFunctionObject.C

    LIB = $(FOAM_USER_LIBBIN)/libforceDirCoeffs

  4. Edited "Make/options" and made it depend/include the original function object library, since there are things we need from it (I think...):
    Code:

    EXE_INC = \
        -I$(LIB_SRC)/finiteVolume/lnInclude \
        -I$(LIB_SRC)/meshTools/lnInclude \
        -I$(LIB_SRC)/sampling/lnInclude \
        -I$(LIB_SRC)/transportModels \
        -I$(LIB_SRC)/turbulenceModels \
        -I$(LIB_SRC)/turbulenceModels/LES/LESdeltas/lnInclude \
        -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
        -I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude

    LIB_LIBS = \
        -lincompressibleTransportModels \
        -lincompressibleRASModels \
        -lincompressibleLESModels \
        -lbasicThermophysicalModels \
        -lspecie \
        -lcompressibleRASModels \
        -lcompressibleLESModels \
        -lfiniteVolume \
        -lmeshTools \
        -lsampling \
        -lforces

  5. Renamed all files inside the sub-folder "forceDirCoeffs", adding "Dir" after "force".
  6. Edited all of the renamed files and did the same search and replace of "forceCoeffs" to "forceDirCoeffs".
  7. Finally added the modifications described in the first two posts.
To build it:
Code:

wmake libso
To use it:
  1. Instead of referring to the library "libforces.so", you now refer to "libforceDirCoeffs.so".
  2. Instead of "forceCoeffs" in the case's "controlDict" file, you now use "forceDirCoeffs". Keep in mind that you now also have a vector entry named "sfDir".
I haven't tested this, so I can only assume that it works :D


Best regards,
Bruno

Hi Bruno ,

First off all thanks for the utility, But i am not able to build it properly on my system i am following quoted steps you have provided but its giving me some error. given below.

Code:

wmakeLnInclude: linking include files to ./lnInclude
Making dependency list for source file forceDirCoeffs/forceDirCoeffs.C
could not open file writer.H for source file forceDirCoeffs/forceDirCoeffs.C
Making dependency list for source file forceDirCoeffs/forceDirCoeffsFunctionObject.C
could not open file writer.H for source file forceDirCoeffs/forceDirCoeffsFunctionObject.C
SOURCE=forceDirCoeffs/forceDirCoeffs.C ;  g++ -m64 -Dlinux64 -DWM_DP -Wall -Wextra -Wno-unused-parameter -Wold-style-cast -Wnon-virtual-dtor -O3  -DNoRepository -ftemplate-depth-100 -I/opt/openfoam221/src/finiteVolume/lnInclude -I/opt/openfoam221/src/meshTools/lnInclude -I/opt/openfoam221/src/sampling/lnInclude -I/opt/openfoam221/src/transportModels -I/opt/openfoam221/src/turbulenceModels -I/opt/openfoam221/src/turbulenceModels/LES/LESdeltas/lnInclude -I/opt/openfoam221/src/thermophysicalModels/basic/lnInclude -I/opt/openfoam221/src/postProcessing/functionObjects/forces/lnInclude -IlnInclude -I. -I/opt/openfoam221/src/OpenFOAM/lnInclude -I/opt/openfoam221/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64GccDPOpt/forceDirCoeffs.o
In file included from forceDirCoeffs/forceDirCoeffs.H:40:0,
                from forceDirCoeffs/forceDirCoeffs.C:26:
/opt/openfoam221/src/postProcessing/functionObjects/forces/lnInclude/forces.H:115:20: fatal error: writer.H: No such file or directory
compilation terminated.
make: *** [Make/linux64GccDPOpt/forceDirCoeffs.o] Error 1

Since i am new to OpenFoam please help me with that. i tried to locate the writer.H and found it in "src/fileFormate/lnInclude" i tried to copy that to the lnInclude provided inside your provide utility. so the error posted above was removed but. a new error came posted below
Code:

Making dependency list for source file forceDirCoeffs/forceDirCoeffs.C
Making dependency list for source file forceDirCoeffs/forceDirCoeffsFunctionObject.C
SOURCE=forceDirCoeffs/forceDirCoeffs.C ;  icpc -std=c++0x -Dlinux64 -DWM_DP -wd327,654,819,1125,1476,1505,1572 -O2 -no-prec-div  -DNoRepository -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/finiteVolume/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/meshTools/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/sampling/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/transportModels -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/turbulenceModels -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/turbulenceModels/LES/LESdeltas/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/thermophysicalModels/basic/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/postProcessing/functionObjects/forces/lnInclude -IlnInclude -I. -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/OpenFOAM/lnInclude -I/opt/app/OpenFOAM/OpenFOAM-2.2.1/src/OSspecific/POSIX/lnInclude  -fPIC -c $SOURCE -o Make/linux64IccDPOpt/forceDirCoeffs.o
forceDirCoeffs/forceDirCoeffs.C(33): error: name followed by "::" must be a class or namespace name
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(33): error: name followed by "::" must be a class or namespace name
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(33): error #303: explicit type is missing ("int" assumed)
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(33): error: expected a ";"
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(33): error: name followed by "::" must be a class or namespace name
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(33): error: name followed by "::" must be a class or namespace name
  defineTypeNameAndDebug(Foam::forceDirCoeffs, 0);
  ^

forceDirCoeffs/forceDirCoeffs.C(91): error: identifier "forcesFilePtr_" is undefined
      if (forcesFilePtr_.valid())
          ^

forceDirCoeffs/forceDirCoeffs.C(116): error: identifier "makeFile" is undefined
          makeFile();
          ^

forceDirCoeffs/forceDirCoeffs.C(118): error: identifier "forcesMoments" is undefined
          forcesMoments fm = forces::calcForcesMoment();
          ^

forceDirCoeffs/forceDirCoeffs.C(137): error: identifier "forcesFilePtr_" is undefined
              forcesFilePtr_()
              ^

compilation aborted for forceDirCoeffs/forceDirCoeffs.C (code 2)
make: *** [Make/linux64IccDPOpt/forceDirCoeffs.o] Error 2

So i am not able to figure out how to debug this error it will be helpful if you can give some advice.
Thank you
Regards
Himanshu Sharma:confused:

luuhoangthien October 1, 2013 06:32

Hi himanshu28

I Know this error, in the terminal you go to this folder and type follow me:

Quote:

wclean
it will delete deb file
and now you type:

Quote:

wmake libso
don't miss libso :P

Thien

himanshu28 October 2, 2013 03:46

Thanks
 
Quote:

Originally Posted by luuhoangthien (Post 454429)
Hi himanshu28

I Know this error, in the terminal you go to this folder and type follow me:

if will delete deb file
and now you type:

don't miss libso :P

Thien

Thanks for the reply luuhoangthien it now worked..

Regards
Himanshu :)

Rider January 13, 2014 10:58

Hi Bruno,

I try to add the modification to the OF V222, but i don't succeed.

I always have this error : "unknown function type force DirCoeffs".

When I add the modification like the previous OF version, I don't have error message, but the modification seems to not be affect.

Thank you in advance !

wyldckat January 13, 2014 16:33

Hi Rider,

I won't have much time to look deeper into this before the weekend.

But one question: did you also try in OpenFOAM 2.2.1?

Either way, OpenFOAM 2.2 has been evolving on the function objects topic quite a bit, adding new features to them for 2.2.1, 2.2.2 and 2.2.x, so things have continued to change.
So it really depends on what was the starting point you've used to make the code modifications.

Best regards,
Bruno

Rider January 14, 2014 03:46

Hi Bruno,

Thanks for your quick reply.

Yes, I have tried with the OF V221. The problem is the same.
I used your methode with the forceDirCoeff file.


Best regards.

wyldckat January 26, 2014 12:28

Hi Rider,

OK, things did change considerably in OpenFOAM 2.2. It has got binning and all!

This time I've gone through the somewhat correct steps in sharing modified code, which is provided here: https://github.com/wyldckat/forceDirCoeffs

The instructions are provided there and make sure you replace all references to "21x" to "22x", when following the installation steps.

Let me know if you have any problems following the steps or any problems using the modified library.

Best regards,
Bruno

gsingle February 5, 2014 23:09

Good day Bruno,

I have followed your most recent directions in the github site. I am running simpleFoam and it seems that the program is not picking up my forceDirCoeffs directory I have compiled. In my controlDict file I have placed #include "forceDirCoeffs" into the functions.

Below is found in my simpleFoam.log file. I think there must be a problem with the functionObject.C file in the OpenFOAM222 directory but do not know how to resolve it. Any help here would be much appreciated.

Thanks,
Geoff
[6] --> FOAM FATAL ERROR:
[6] Unknown function type forceDirCoeffs

Valid functions are :

20
(
cellSource
faceSource
fieldAverage
fieldCoordinateSystemTransform
fieldMinMax
fieldValueDelta
forceCoeffs
forces
nearWallFields
patchProbes
probes
processorField
readFields
regionSizeDistribution
sets
streamLine
surfaceInterpolateFields
surfaces
turbulenceFields
wallBoundedStreamLine
)


wyldckat February 6, 2014 16:57

Greetings Geoff,

Quote:

Originally Posted by gsingle (Post 473657)
In my controlDict file I have placed #include "forceDirCoeffs" into the functions.

Mmm... I see that I need to provide clearer instructions on the README file...

The idea is that you should add the following line to the "controlDict" file:
Code:

libs (libforceDirCoeffs.so);
In case you already have a line that starts with "libs", then add the library name to the list, for example:
If you have this:
Code:

libs (
    libforces.so
);

It becomes this:
Code:

libs (
    libforces.so
    libforceDirCoeffs.so
);

Best regards,
Bruno

gsingle February 8, 2014 16:45

Thanks again for the help. I am running OpenFOAM 2.2.2. I did have to do one additional thing to the files I cloned from your github. Before the wmake command, I had to add lforces to the Make/options file, as seen below.

EXE_INC = \
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/transportModels \
-I$(LIB_SRC)/turbulenceModels \
-I$(LIB_SRC)/turbulenceModels/LES/LESdeltas/lnInclude \
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/postProcessing/functionObjects/forces/lnInclude

LIB_LIBS = \
-lincompressibleTransportModels \
-lincompressibleRASModels \
-lincompressibleLESModels \
-lfluidThermophysicalModels \
-lspecie \
-lcompressibleRASModels \
-lcompressibleLESModels \
-lfiniteVolume \
-lmeshTools \
-lforces \
-lfileFormats

Works great now, I actually added a few terms, to give coefficients in all three directions in global coordinates as well as all three directions of local coordinates to the body being analysed.

wyldckat February 16, 2014 12:43

Hi Geoff,

I've updated the repository, regarding the README file and the linking to "libforces" as you indicated.
Do feel free to clone the repository and publish your modifications to it!

Best regards,
Bruno

gsingle March 27, 2014 09:13

Let me finish my masters project first, then I will be more than happy to tidy up and post the updates. Just three more weeks!


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