|
[Sponsors] |
March 3, 2017, 10:06 |
Compute fluid accellaration
|
#1 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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. |
|
March 3, 2017, 15:45 |
|
#2 |
Senior Member
|
||
March 6, 2017, 09:37 |
|
#3 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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? |
|
March 6, 2017, 10:41 |
|
#4 |
Senior Member
|
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(); #} } |
|
March 6, 2017, 11:56 |
|
#5 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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 ) Any thoughts on these issues will be much appreciated. |
|
March 6, 2017, 12:13 |
|
#6 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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(); #}; } |
|
March 6, 2017, 13:49 |
|
#7 |
Senior Member
|
Is DDt(U) written on every time step? Add this:
Code:
writeControl writeTime; 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(); #}; } |
|
March 7, 2017, 05:41 |
|
#8 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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(); #}; } } 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(); #}; } } I am wondering if it is possible to write DDtU for a probe location? |
|
March 7, 2017, 05:59 |
|
#9 |
Senior Member
|
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). |
|
March 7, 2017, 15:26 |
|
#10 |
Senior Member
|
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. |
|
March 9, 2017, 11:22 |
|
#11 |
New Member
Kostas Margaris
Join Date: Feb 2014
Posts: 15
Rep Power: 12 |
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(); #}; } } 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 ) ); |
|
March 10, 2017, 16:02 |
|
#12 |
Senior Member
|
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. |
|
June 18, 2023, 01:58 |
|
#13 | |
New Member
Ahmadreza Ebadati
Join Date: Apr 2020
Posts: 6
Rep Power: 6 |
Quote:
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 ) ); } |
||
|
|
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 |