CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Post-Processing

Compute fluid accellaration

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 3, 2017, 10:06
Default Compute fluid accellaration
  #1
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
Hi all,

How can I compute the fluid acceleration from the velocity field? Or in other words I want to calculate the material derivative of the velocity vector field.
kmargaris is offline   Reply With Quote

Old   March 3, 2017, 15:45
Default
  #2
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

For example, there is fvc::DDt (https://cpp.openfoam.org/v4/a10924.h...6817560484a801).
alexeym is offline   Reply With Quote

Old   March 6, 2017, 09:37
Default
  #3
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
Hi Alexey,

Thanks for you quick reply. I take it from your answer that one has to write a custom application to compute the material derivative. I am not really familiar with OpenFOAM programming. Is there no way to calculate the material derivative with probe functions or in Paraview?
kmargaris is offline   Reply With Quote

Old   March 6, 2017, 10:41
Default
  #4
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

There is codedFunctionObject and in your case it could be as simple as

Code:
    acceleration
    {
        libs ("libutilityFunctionObjects.so");

        type coded;
        // Name of on-the-fly generated functionObject
        name calculateDDt;
        codeWrite
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
        #}
    }
Maybe somebody else knows how to calculate it in ParaView (yet, guess, it is more complicated).
alexeym is offline   Reply With Quote

Old   March 6, 2017, 11:56
Default
  #5
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
Hi Alexey,

Thanks for the code. I added the code to my controlDict in the functions section.

With OF3.0+ I got a fatal error:

Code:
--> FOAM FATAL ERROR: 
Unknown function type coded

Valid functions are : 

4
(
patchProbes
probes
sets
surfaces
)
I tried OF1612+ and it works, but during solution only the material derivative is been written in the result directories. All other fields like U are not.

Any thoughts on these issues will be much appreciated.
kmargaris is offline   Reply With Quote

Old   March 6, 2017, 12:13
Default
  #6
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
A further update. I managed to run the code with OF3+. Some changes were necessary.

Code:
acceleration
    {
        functionObjectLibs ("libutilityFunctionObjects.so"); // This needed changing from libs to functionObjectLibs

        type coded;
        // Name of on-the-fly generated functionObject
	redirectType banana; //average; // needed to add redirectType, but the name doesn't seem to affect anything
        name calculateDDt;
	//outputControl runTime;
        code//Write // had to be changed from codeWrite to code
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
        #};
    }
Now the behaviour during solution is the same as OF1612+. Only the material derivative is written as a result.
kmargaris is offline   Reply With Quote

Old   March 6, 2017, 13:49
Default
  #7
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Is DDt(U) written on every time step? Add this:

Code:
writeControl    writeTime;
Here's configuration, tested on OpenFOAM 4.x:

Code:
    acceleration
    {
        libs ("libutilityFunctionObjects.so");

        type coded;
        name            calculateDDt;
	writeControl    writeTime;
        codeWrite
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
        #};
    }
alexeym is offline   Reply With Quote

Old   March 7, 2017, 05:41
Default
  #8
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
Hi Alexey,

I tried to compile OF4.1 but run into errors, so I couldn't test your code. However, I managed to get a solution in OF3+ and OF1612+.

For OF3+ this is my controlDict:

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


FoamFile
{
    version         3.0;
    format          ascii;
    class           dictionary;
    object          controlDict;
    location        "system";
}

libs            ( "libwaveAbsorption.so" "libwaveGeneration.so" );

write	0.5; // create a variable with the desired output interval

allowSystemOperations 1;

application     interFoam;

startFrom       latestTime;

startTime       0;

stopAt          endTime;

endTime         100.0;

deltaT          1e-05;

writeControl    runTime;

writeInterval   $write; // use the variable declared above here

purgeWrite      0;

writeFormat     ascii;

writePrecision  8;

writeCompression uncompressed;

timeFormat      general;

timePrecision   8;

runTimeModifiable true;

adjustTimeStep  yes;

maxCo           1;

maxAlphaCo      1;

maxDeltaT       0.05;


functions
{
    #include        "ProbeData"

    acceleration // The code was tested in OF3+ running serial and parallel case
    {
        functionObjectLibs ("libutilityFunctionObjects.so");

        type coded;
        // Name of on-the-fly generated functionObject
	redirectType DDtU;
        name calculateDDt;
	writeInterval $write; // Re-use the write variable. This statement must be repeated here so that the output of all fields occurs at the same interval
	outputControl runTime; // This is also necessary in OF3+
        code//codeWrite does not work here in OF3+
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
        #};
    } 
    
}
For OF1612+ the controlDict is this:

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


FoamFile
{
    version         3.0;
    format          ascii;
    class           dictionary;
    object          controlDict;
    location        "system";
}

libs            ( "libwaveAbsorption.so" "libwaveGeneration.so" );

write	0.5;

allowSystemOperations 1;

application     interFoam;

startFrom       latestTime;

startTime       0;

stopAt          endTime;

endTime         100.0;

deltaT          1e-05;

writeControl    runTime;

writeInterval   $write;

purgeWrite      0;

writeFormat     ascii;

writePrecision  8;

writeCompression uncompressed;

timeFormat      general;

timePrecision   8;

runTimeModifiable true;

adjustTimeStep  yes;

maxCo           1;

maxAlphaCo      1;

maxDeltaT       0.05;


functions
{
    #include        "ProbeData"

    acceleration // The code was tested in OF1612+ running serial and parallel case
    {
        functionObjectLibs ("libutilityFunctionObjects.so");

        type coded;
        // Name of on-the-fly generated functionObject
	redirectType DDtU;
        name calculateDDt;
	writeControl    runTime; //For OF1612+ writeControl is required not outputControl
	writeInterval   $write;
        codeWrite //For OF1612 the correct statement is codeWrite not code
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
        #};
    } 
    
}
There are some small differences in the code for OF3+ and OF1612+. In both cases I found it necessary to use a variable "write" so I can write all fields at the same time interval. I tested the code in serial an parallel cases.

I am wondering if it is possible to write DDtU for a probe location?
kmargaris is offline   Reply With Quote

Old   March 7, 2017, 05:59
Default
  #9
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
You can:

1. Use probes function object. I think with correct order in functions dictionary it is possible to first write DDt(U) field and then probe it.

2. Use probes object directly in your coded function object. Though this way requires a little be more code, than just to write DDt(U).
alexeym is offline   Reply With Quote

Old   March 7, 2017, 15:26
Default
  #10
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

I ended up with the following implementation: https://github.com/mrklein/foam-case...ontrolDict#L43. I have tested it on OF 4.x, so maybe it needs adaptation for OF+3.0 and OF+1602.
alexeym is offline   Reply With Quote

Old   March 9, 2017, 11:22
Default
  #11
New Member
 
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12
kmargaris is on a distinguished road
Hi Alexey,

I managed to install OF4.1 and your code works very well. It also works in OF1612+ as is.

Now I tried to read the probe locations from a file in the system subfolder. I used the following code, but results in errors.

Code:
acceleration
    {
        libs ("libutilityFunctionObjects.so" "db.so");
        

        type            coded;
        name            calculateDDt;

        writeControl    writeTime; //timeStep;//
        writeInterval   1;
	

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

        codeLibs
        #{
            -lsampling
        #};

        codeInclude
        #{
            #include "probes.H"
	    #include "labelListIOList.H"
	    #include "fvMesh.H"
	    #include "fvCFD.H"
            #include "createTime.H"
	    #include "readTimeControls.H"
        #};

        codeData
        #{
            autoPtr<probes> probes_;
        #};

        codeRead
        #{
            List<word> fields;
            fields.append("DDt(U)");
            List<vector> locations;
            // Locations to probe, could be refactored into reading dictionary
            // instead of constructing it by hand

            locations.append(vector(1e-3, 1e-3, 5e-3));
	    locations.append(vector(  60,   -5.5,   -4.19  ));
	    locations.append(vector(  60,   -5.5,   -3.966  ));
	    locations.append(vector(  60,   -5.5,  -3.94  ));
	    locations.append(vector(  60,   -5.5, -3.69  ));
	    locations.append(vector(  60,   -5.5,   -3.44  ));
	    locations.append(vector(  60,   -5.5,   -3.19  ));
	    
            IOdictionary probes
	    (
		IOobject
		(
		    "probeLocations",
		    runTime.system(),
		    mesh,
		    IOobject::MUST_READ,
		    IOobject::NO_WRITE
		)
	    );
	    dictionary conf;
            conf.add("fields", fields);
            conf.add("probeLocations", locations);

            // Initial acceleration field
            volVectorField t(
                IOobject("DDt(U)", time_.timeName(), mesh()),
                mesh(),
                dimensionedVector("0", dimVelocity/dimTime, Zero));
            t.write();

            probes_.reset(
                new probes(
                    "DDt(U)", time_, conf));
            // Probe and write for time = 0
            probes_->write();
        #};

        codeWrite
        #{
            // Lookup U and phi
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            // Write
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
            // Write probes values
            probes_->write();
        #};

        codeEnd
        #{
            // To have probed value at the last time step
            const volVectorField& U = mesh().lookupObject<volVectorField>("U");
            const surfaceScalarField& phi = mesh().lookupObject<surfaceScalarField>("phi");
            volVectorField t("DDt(U)", fvc::DDt(phi, U));
            t.write();
            probes_->write();
        #};
    }
}
The dictionary file in the system subfolder is:

Code:
probeLocations
		(
				(  60   -5.5   -4.19  )
				(  60   -5.5   -3.966  )
				(  60   -5.5   -3.94  )
				(  60   -5.5   -3.69  )
				(  60   -5.5   -3.44  )
				(  60   -5.5   -3.19  )
		);
A second question; is it actually possible to write output to probes every time step, but write field data less frequently, say every 0.5 seconds?
kmargaris is offline   Reply With Quote

Old   March 10, 2017, 16:02
Default
  #12
Senior Member
 
Alexey Matveichev
Join Date: Aug 2011
Location: Nancy, France
Posts: 1,930
Rep Power: 38
alexeym has a spectacular aura aboutalexeym has a spectacular aura about
Send a message via Skype™ to alexeym
Hi,

I have updated example (https://github.com/mrklein/foam-case...e-acceleration) with the following additions:

1. Added examples for creation of probes from probesDict file and probes sub-dictionary of controlDict.
2. To be able to probe acceleration field every time step and to write it every write time, I have moved probing code to execute method. So now write frequency is controlled by writeControl and probe frequency with executeControl.
3. Got rid of field lookups on every write/execute method call.

Tested it on OpenFOAM 4.x, do not know if it works on other FOAMs.
alexeym is offline   Reply With Quote

Old   June 18, 2023, 01:58
Default
  #13
New Member
 
Ahmadreza Ebadati
Join Date: Apr 2020
Posts: 6
Rep Power: 6
aeba402 is on a distinguished road
Quote:
Originally Posted by alexeym View Post
Hi,

I have updated example (https://github.com/mrklein/foam-case...e-acceleration) with the following additions:

1. Added examples for creation of probes from probesDict file and probes sub-dictionary of controlDict.
2. To be able to probe acceleration field every time step and to write it every write time, I have moved probing code to execute method. So now write frequency is controlled by writeControl and probe frequency with executeControl.
3. Got rid of field lookups on every write/execute method call.

Tested it on OpenFOAM 4.x, do not know if it works on other FOAMs.
Hello,


I am looking for a function object so that I can calculate the acceleration field when running OpenFOAM as well. To me, it doesn't look like the code in the github link calculates the material derivative. Where is the dot product of the velocity and velocity gradient in the code? I also ran the code with some updates to suit OpenFOAM 1912 but it doesn't save anything in the postProcessing folder. It doesn't save anything in the time folders as well. Is someone able to help me with these please? This is the code I have used in my controlDict file.



Code:
    acceleration
    {
        libs ("libutilityFunctionObjects.so");

        type            coded;
        name            calculateDDt;

        executeControl  timeStep;
        executeInterval 1;
        writeControl    writeTime;

        codeOptions
        #{
            -I$FOAM_SRC/sampling/lnInclude
        #};

        codeLibs
        #{
            -lsampling
        #};

        codeInclude
        #{
            #include "probes.H"
        #};

        codeData
        #{
            autoPtr<probes> probes_;
            autoPtr<volVectorField> DDtU_;
            const volVectorField* UPtr_;
            const surfaceScalarField* phiPtr_;
        #};

        read
        #{
        /*
            // Constructing probes dictionary
            List<word> fields;
            fields.append("DDt(U)");
            List<vector> locations;
            locations.append(vector(1e-3, 1e-3, 5e-3));

            dictionary conf;
            conf.add("fields", fields);
            conf.add("probeLocations", locations);
        */
        /*
            // Reading probes dictionary, let's assume it is
            // system/probesDict
            IOdictionary conf(
                IOobject("probesDict", time_.system(), mesh(),
                         IOobject::MUST_READ));
        */
            // Getting probes dictionary from system/controlDict's
            // probes sub-dictionary.
            const dictionary& conf(time_.controlDict().subDict("probes"));

            UPtr_ = &(mesh().lookupObject<volVectorField>("U"));
            phiPtr_ = &(mesh().lookupObject<surfaceScalarField>("phi"));

            // Initial acceleration field
            DDtU_.reset(
                new volVectorField(
                    IOobject("DDt(U)", time_.timeName(), mesh()),
                    mesh(),
                    dimensionedVector("0", dimVelocity/dimTime, Zero)));
            DDtU_->checkIn();
            DDtU_->write();

            probes_.reset(
                new probes(
                    "DDt(U)", mesh(), conf));
            // Probe and write for time = 0
            probes_->write();
        #};

        execute
        #{
            // Write probes values
            DDtU_() = fvc::DDt(*phiPtr_, *UPtr_);
            probes_->write();
        #};

        write
        #{
            // Write
            DDtU_() = fvc::DDt(*phiPtr_, *UPtr_);
            DDtU_->write();
        #};

        end
        #{
            DDtU_() = fvc::DDt(*phiPtr_, *UPtr_);
            DDtU_->write();

            probes_->write();
        #};
    }

Also I have added the probe locations as per below.

Code:
probes
{
    fields
    (
        DDt(U)
    );

    probeLocations
    (
            ( 11 0.370 0 )
            ( 11 0.405 0 )
    );
}
Thanks in advance. Cheers
aeba402 is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Wrong multiphase flow at rotating interface Sanyo CFX 14 February 7, 2017 17:19
Compute Cluster with diskless compute nodes Pauli Hardware 0 October 6, 2015 16:48
Multiphase simulation of bubble rising Niru CFX 5 November 25, 2014 13:57
My Revised "Time Vs Energy" Article For Review Abhi Main CFD Forum 2 July 9, 2002 09:08
Terrible Mistake In Fluid Dynamics History Abhi Main CFD Forum 12 July 8, 2002 09:11


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