CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Running, Solving & CFD

wallDist

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 2 Post By s1291
  • 1 Post By louisgag

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 29, 2018, 11:14
Default wallDist
  #1
New Member
 
Join Date: Mar 2015
Posts: 10
Rep Power: 11
Researcher23 is on a distinguished road
Dear Forum,

I would like to get (and use) the information about the distance to the next wall within fvOptions. I've seen that there is something called wallDist in the OpenFoam code:

https://github.com/OpenFOAM/OpenFOAM...ist/wallDist.H

My code within fvOptions was the following:

volScalarField WallDistant
(
IOobject
(
"WallDistant",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("WallDistant", dimensionSet(0,1,0,0,0,0,0), 0)
);


WallDistant = wallDist(mesh).y();

But my attempt was not successful. I got the following error message:

/manni/data/stw/OpenFoamRuns/TH2_42/constant/fvOptions.massSource.scalarCodedSourceCoeffs: In member function ‘virtual void Foam::fv::sourceMassFvOptionscalarSource::addSup(F oam::fvMatrix<double>&, Foam::label)’:
/manni/data/stw/OpenFoamRuns/TH2_42/constant/fvOptions.massSource.scalarCodedSourceCoeffs:100:3 0: error: invalid use of non-static member function
/manni/data/stw/OpenFoamRuns/TH2_42/constant/fvOptions.massSource.scalarCodedSourceCoeffs: In member function ‘virtual void Foam::fv::sourceMassFvOptionscalarSource::addSup(c onst volScalarField&, Foam::fvMatrix<double>&, Foam::label)’:
/manni/data/stw/OpenFoamRuns/TH2_42/constant/fvOptions.massSource.scalarCodedSourceCoeffs:100:3 0: error: invalid use of non-static member function
make: *** [Make/linux64GccDPInt32Opt/codedFvOptionTemplate.o] Error 1


--> FOAM FATAL IO ERROR:
Failed wmake "dynamicCode/sourceMass/platforms/linux64GccDPInt32Opt/lib/libsourceMass_3da197f3cc357d741f1a55ea5ea42bbaf0e3 83a5.so"

Could someone please give me a hint how to get the wall distance information within my fvOptions code?

Thanks,
R.
Researcher23 is offline   Reply With Quote

Old   January 29, 2018, 23:59
Default
  #2
New Member
 
Yuncheng Xu (Cloud)
Join Date: May 2011
Location: State College, PA
Posts: 20
Rep Power: 15
luther1990 is on a distinguished road
try
Code:
WallDistant = wallDist(mesh_).y();
luther1990 is offline   Reply With Quote

Old   January 30, 2018, 06:28
Default
  #3
New Member
 
Join Date: Mar 2015
Posts: 10
Rep Power: 11
Researcher23 is on a distinguished road
Dear Luther,

thanks for your answer! It works now with your solution. But first I have to include

#include "wallDist.H"

in my code.

Regards,
R.
Researcher23 is offline   Reply With Quote

Old   June 2, 2019, 01:27
Default
  #4
Member
 
Join Date: Oct 2015
Posts: 63
Rep Power: 11
Scram_1 is on a distinguished road
Hi,
I see that you want the nearest distance from the wall for each cell in the mesh.
Is it possible to get the distance from a particular cell in the mesh to the wall using wallDist() without computing this distance for other cells? I have the cellID for the cell. But wallDist(mesh_(celli)).y() gives an error. Is there a way to get this distance for a particular cell?

Thanks!

Best,
Scram_1
Scram_1 is offline   Reply With Quote

Old   July 16, 2019, 19:05
Default
  #5
Senior Member
 
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16
Andrea1984 is on a distinguished road
Hi Researcher23,

could you share a complete example with your solution? Where exactly did you include "wallDist.H" in your code?

Many thanks,
Andrea
Andrea1984 is offline   Reply With Quote

Old   July 17, 2019, 04:12
Default Hi Andrea
  #6
New Member
 
Join Date: Mar 2015
Posts: 10
Rep Power: 11
Researcher23 is on a distinguished road
I used it in fvOptions as a scalarCodedSource.

The code in fvOptions was:

#include "wallDist.H"

volScalarField WallDistance
(
IOobject
(
"WallDistance",
mesh_.time().timeName(),
mesh_,
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("WallDistance", dimensionSet(0,1,0,0,0,0,0), 0)
);


WallDistance = wallDist(mesh_).y();

I have to add in fvSchemes:

wallDist
{
method meshWave;
}
Researcher23 is offline   Reply With Quote

Old   July 17, 2019, 14:25
Default
  #7
Senior Member
 
Andrea
Join Date: Feb 2012
Location: Leeds, UK
Posts: 179
Rep Power: 16
Andrea1984 is on a distinguished road
Thanks for the quick reply.

This is what I have been trying to do but I have just realised I was mispelling the name of the header file
Andrea1984 is offline   Reply With Quote

Old   November 10, 2021, 13:28
Default errors using wallDist
  #8
DJF
New Member
 
Join Date: Jan 2019
Posts: 12
Rep Power: 7
DJF is on a distinguished road
I want to use wallDist to create a velocity profile on a non-planar surface. I copied this solution to my fvOptions file and get the following errors:
1) Cannot open include file ".../wallDist.H" while reading dictionary ".../fvOptions"

2) if I comment #include wallDist.H I get:
"ill defined primitiveEntry starting at keyword 'volScalarField' on line 19 and ending at line 35"
[0]
[0] file: .../fvOptions at line 35.
[0]
[0] From void Foam:rimitiveEntry::readEntry(const Foam::dictionary&, Foam::Istream&)
[0] in file db/dictionary/primitiveEntry/primitiveEntryIO.C at line 236.

Any suggestions?
DJF is offline   Reply With Quote

Old   November 10, 2021, 13:51
Default
  #9
Member
 
s1291's Avatar
 
Join Date: Aug 2017
Location: Algeria
Posts: 98
Rep Power: 9
s1291 is on a distinguished road
If you are using OpenFOAM ESI version (e.g. v2106) no need to compile any code or use the fvOptions framework. You simply run:

Code:
checkMesh -writeAllFields
Among the output fields, you will find wallDistance volScalarField under 0 directory.
David* and allanZHONG like this.
s1291 is offline   Reply With Quote

Old   November 10, 2021, 15:52
Default
  #10
DJF
New Member
 
Join Date: Jan 2019
Posts: 12
Rep Power: 7
DJF is on a distinguished road
Thanks for the quick reply. I have now in 0/wallDistance and want to use it for the inlet boundary in U as an expression:

expression
#{
vector(Uref/log(zRef/z0)*log(wallDistance/z0), 0, 0)
#};

but Object wallDistance does not exist

Any Ideas how to use the new volScalarField?
DJF is offline   Reply With Quote

Old   November 5, 2022, 12:28
Default
  #11
Senior Member
 
louisgag's Avatar
 
Louis Gagnon
Join Date: Mar 2009
Location: Stuttgart, Germany
Posts: 338
Rep Power: 18
louisgag is on a distinguished road
Send a message via ICQ to louisgag
In case someone is still looking for a simple solution, here's an example function object to put in the functions{...} section of your controlDict:


Code:
wallDist1
{
    type                coded;
    libs                (utilityFunctionObjects);
    name                wallDistance;
    executeControl      timeStep;
    executeInterval     4;
    writeControl        none;

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

    codeExecute
    #{
    auto* wallDistancePtr =
                mesh().getObjectPtr<volScalarField>("wallDistance");
    if (!wallDistancePtr)
    {
        Info<< "Create wallDistance field" << nl;
              wallDistancePtr = new volScalarField
        (
        IOobject
        (
        "wallDistance",
        mesh().time().timeName(),
        mesh(),
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
        ),
        mesh(),
        dimensionedScalar("wallDistance", dimensionSet(0,1,0,0,0,0,0), 0)
        );
    }
    regIOobject::store(wallDistancePtr);
    auto& wallDistance = *wallDistancePtr;
    Info<< "Computing wallDistance field\n" << endl;
    wallDistance = wallDist::New(mesh()).y();
    #};
}
armitatz likes this.
louisgag is offline   Reply With Quote

Old   January 17, 2023, 15:59
Default
  #12
New Member
 
andrew
Join Date: Oct 2015
Posts: 11
Rep Power: 11
armitatz is on a distinguished road
Quote:
Originally Posted by louisgag View Post
In case someone is still looking for a simple solution, here's an example function object to put in the functions{...} section of your controlDict:


Code:
wallDist1
{
    type                coded;
    libs                (utilityFunctionObjects);
    name                wallDistance;
    executeControl      timeStep;
    executeInterval     4;
    writeControl        none;

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

    codeExecute
    #{
    auto* wallDistancePtr =
                mesh().getObjectPtr<volScalarField>("wallDistance");
    if (!wallDistancePtr)
    {
        Info<< "Create wallDistance field" << nl;
              wallDistancePtr = new volScalarField
        (
        IOobject
        (
        "wallDistance",
        mesh().time().timeName(),
        mesh(),
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
        ),
        mesh(),
        dimensionedScalar("wallDistance", dimensionSet(0,1,0,0,0,0,0), 0)
        );
    }
    regIOobject::store(wallDistancePtr);
    auto& wallDistance = *wallDistancePtr;
    Info<< "Computing wallDistance field\n" << endl;
    wallDistance = wallDist::New(mesh()).y();
    #};
}

Excellent code... But
#1 There seems to be a quirk (or a bug). In cyclic BC it seems to give up.
bug.jpg
In this case left and right are cyclicAMI bc's. In the left the distance seems to be 0. It should not be 0 and even better it should wrap around. Probably it is because of the computation of the walldistance method...
#2 Can this code be implemented in a solver directly? I tried to implement it to openFoam2112 and laplacianFoam but I get errors. Obviously a copy/paste would not work. Can you point to a way to implement it?
Andrew
armitatz is offline   Reply With Quote

Old   January 17, 2023, 16:05
Default
  #13
Senior Member
 
louisgag's Avatar
 
Louis Gagnon
Join Date: Mar 2009
Location: Stuttgart, Germany
Posts: 338
Rep Power: 18
louisgag is on a distinguished road
Send a message via ICQ to louisgag
Hi,
whether it works or not depends on which function you used to compute the wall distance, (fvSchemes), I used meshWave
you may be able to implement that in a solver, but you may have to access the pointer from the turbulence model which in turn gives you the distance.. i don't recommend trying this unless you know c++ and OpenFOAM or have a lot of time to try around
louisgag is offline   Reply With Quote

Old   January 17, 2023, 16:48
Default
  #14
New Member
 
andrew
Join Date: Oct 2015
Posts: 11
Rep Power: 11
armitatz is on a distinguished road
I used meshwave in fvSchemes


C++ well ok but not that much...


Well my guess was that meshWave can calculate distances regardless of turbulence etc. That it is a piece of code that can be used independently. Therefore it could be used for creating a distance field for any other use.


bug2.jpg
In this case left and right are patches (not cyclicAMI). The distance is calculated correctly and is not 0 at the left border. There seems to be a bug here in the presence of cyclic borders.
armitatz is offline   Reply With Quote

Old   January 18, 2023, 03:43
Default
  #15
Senior Member
 
louisgag's Avatar
 
Louis Gagnon
Join Date: Mar 2009
Location: Stuttgart, Germany
Posts: 338
Rep Power: 18
louisgag is on a distinguished road
Send a message via ICQ to louisgag
the patches are walls?
louisgag is offline   Reply With Quote

Old   January 18, 2023, 11:53
Default
  #16
New Member
 
andrew
Join Date: Oct 2015
Posts: 11
Rep Power: 11
armitatz is on a distinguished road
The internal boundaries are set as walls. The distance does not work with common patches. It needs walls because it is used in turbulence and turbulence needs walls to work.

Meshwave does not make the cut. I switched to Poisson and since it uses a solver the cyclic boundaries are respected. So problem solved! (https://www.openfoam.com/documentati...e-poisson.html)


bug4.jpg


I would like to ask two more things.
#1. How can I make the field at the beginning of the simulation before any other iteration? right now I use these settings in controlDict


Code:
    startFrom       startTime;
startTime       0;
stopAt          endTime;
endTime         30;
deltaT          1;
writeControl    adjustableRunTime;
writeInterval   1;
....


executeControl      timeStep;
     executeInterval     1000;
    writeControl        timeStep;
    timeStart           0;
and it shows in the second iteration.
#2 After the #1 how can I use it inside the solver? My plan is to use this field to calculate a coefficient based on distance.
Any help would be greatly appreciated
armitatz is offline   Reply With Quote

Old   January 18, 2023, 15:51
Default
  #17
New Member
 
andrew
Join Date: Oct 2015
Posts: 11
Rep Power: 11
armitatz is on a distinguished road
ok. Finally I made it


Based on the above code from louisgag I added it as a field in a solver (laplacianFoam)
first a new field was added: TDist in createFields.H. This will be a new field and it will be used as a variable coefficient taking the place of the old fixed coefficient DT. It will be calculated as a value*distance instead of a fixed value before the change. The distance will be the distance from the walls and the value will be defined in transportProperties with the name DDT. It will have the same units of the old coefficient DT in the code so its units are [0 2 -1 0 ...]

Code:
volScalarField TDist
(
    IOobject
    (
        "TDist",
        runTime.timeName(),
        mesh,
        IOobject::NO_READ,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar(dimensionSet(0,2,-1,0,0,0,0), 0)
);
Then I changed DT to DDT (I recycled the entry)
Code:
volScalarField DDT
 (
    IOobject
    (
        "DDT",
        runTime.timeName(),
        mesh,
        IOobject::READ_IF_PRESENT,
        IOobject::AUTO_WRITE
    ),
    mesh,
    dimensionedScalar(dimensionSet(0,1,-1,0,0,0,0), Zero)
);
I changed the dimensions because I want to multiply it with the distance from the walls which has dimensions [m]. So the original DT [0 2 -1 ... ] has to become [0 1 -1 ...] since it will be multiplied with distance of units [0 1 0 ...]

After that I changed the rest of DT to DDT in createfields.H

Then in laplacianFoam.C the #include section becomes

Code:
#include "wallDist.H" // added line
 #include "fvCFD.H"
#include "fvOptions.H"
 #include "simpleControl.H"
and then


Code:
       TDist = DDT*wallDist::New(mesh).y();

        while (simple.correctNonOrthogonal())
        {
            fvScalarMatrix TEqn
            (
                fvm::ddt(T) - fvm::laplacian(TDist, T)
             ==
                fvOptions(T)
            );

            fvOptions.constrain(TEqn);
            TEqn.solve();
            fvOptions.correct(T);
        }

          #include "write.H"
Finally in write.H the DT changes to DDT and also transportProperties becomes

Code:
DDT              DDT [ 0 1 -1 0 0 0 0 ] 10;
After compilation and running:
bug5.jpg
Simple as that!
armitatz 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
wallDist error in OF-1.5.x elisabet OpenFOAM Bugs 15 May 21, 2020 10:50
porousSimpleFoam - keyword wallDist undefined anon_j OpenFOAM Running, Solving & CFD 5 October 31, 2019 07:42
calculating wall distance wallDist volker OpenFOAM Programming & Development 12 December 28, 2017 12:29
WallDist is undefined in fvschemes for new boundary condition crazzy.pirate43 OpenFOAM Pre-Processing 3 July 14, 2017 07:27
problem with wallDist on yPlus jms OpenFOAM 1 October 14, 2011 02:55


All times are GMT -4. The time now is 15:00.