CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Running, Solving & CFD (https://www.cfd-online.com/Forums/openfoam-solving/)
-   -   cellSet volume in fvOptions (https://www.cfd-online.com/Forums/openfoam-solving/186415-cellset-volume-fvoptions.html)

pablo_fil April 18, 2017 12:49

cellSet volume in fvOptions
 
Hi all!

I'll try to explain my case briefly. I want to use a vectorCodedSource fvOptions file, and two of the variables I have to use are volume of a cellSet and volume of each cell in that volume. The cellSet is an small box inside a larger box.

I'm having trouble with it as I'm not able to select JUST the cells in my cellSet.

This is my fvOptions file:
Code:

/*--------------------------------*- C++ -*----------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  2.3.0                                |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version    2.0;
    format      ascii;
    class      dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
velocitySource
{
    type            vectorCodedSource;
    active          true;
    selectionMode  cellSet;
    cellSet        selectedCells;
    name            velocitySource;

    vectorCodedSourceCoeffs
    {
    fields          (U);
    selectionMode  cellSet;
    cellSet        selectedCells;
    name            velocitySource;

        codeInclude
        #{
        #};

        codeCorrect
        #{
        #};

        codeAddSup
        #{

    const scalarField& V = mesh_.V();
    const vectorField& C = mesh_.C();
    scalar V_ = 0.0;
    forAll(C, i)
    {
        V_ += V[i];
    }
    reduce(V_, sumOp<scalar>());
    Info<< indent
    << "- selected " << returnReduce(C.size(), sumOp<label>())
    << " cell(s) with volume " << V_ << endl;

        #};

        codeSetValue
        #{

        #};

        code
        #{
            $codeCorrect
            $codeAddSup
            $codeSetValue
        #};
    }

    velocitySourceCoeffs
    {
    }
}
// ************************************************************************* //

When I start the solver (simpleFoam in this case) I get the following log.

Code:

/*---------------------------------------------------------------------------*\
| =========                |                                                |
| \\      /  F ield        | OpenFOAM: The Open Source CFD Toolbox          |
|  \\    /  O peration    | Version:  4.1                                  |
|  \\  /    A nd          | Web:      www.OpenFOAM.org                      |
|    \\/    M anipulation  |                                                |
\*---------------------------------------------------------------------------*/
Build  : 4.1
Exec  : simpleFoam
Date  : Apr 18 2017
Time  : 18:31:45
Host  : "pablo-K52Jr"
PID    : 23352
Case  : /home/pablo/misCasosFE/bloques
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


SIMPLE: convergence criteria
    field U    tolerance 0.0001
    field p    tolerance 0.001
    field "(k|epsilon|omega)"    tolerance 0.001

Reading field p

Reading field U

Reading/calculating face flux field phi

Selecting incompressible transport model Newtonian
Selecting turbulence model type RAS
Selecting RAS turbulence model kOmegaSST
Selecting patchDistMethod meshWave
kOmegaSSTCoeffs
{
    alphaK1        0.85;
    alphaK2        1;
    alphaOmega1    0.5;
    alphaOmega2    0.856;
    gamma1          0.55555556;
    gamma2          0.44;
    beta1          0.075;
    beta2          0.0828;
    betaStar        0.09;
    a1              0.31;
    b1              1;
    c1              10;
    F3              false;
}

No MRF models present

Creating finite volume options from "system/fvOptions"

Selecting finite volume options model type vectorCodedSource
    Source: velocitySource
    - selecting cells using cellSet selectedCells
    - selected 90 cell(s) with volume 0.30424486

Starting time loop

Time = 1

Using dynamicCode for fvOption:: velocitySource at line 20 in "/home/pablo/misCasosFE/bloques/system/fvOptions.velocitySource.vectorCodedSourceCoeffs"
Creating new library in "dynamicCode/velocitySource/platforms/linux64GccDPInt32Opt/lib/libvelocitySource_ba8e2470764f35c431307b63ebef6c2a4b610dc8.so"
Invoking "wmake -s libso /home/pablo/misCasosFE/bloques/dynamicCode/velocitySource"
'/home/pablo/misCasosFE/bloques/dynamicCode/velocitySource/../platforms/linux64GccDPInt32Opt/lib/libvelocitySource_ba8e2470764f35c431307b63ebef6c2a4b610dc8.so' is up to date.
Selecting finite volume options model type velocitySource
    Source: velocitySource
- selected 245760 cell(s) with volume 2400
smoothSolver:  Solving for Ux, Initial residual = 0.99999999, Final residual = 0.00056604347, No Iterations 1
smoothSolver:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
smoothSolver:  Solving for Uz, Initial residual = 0, Final residual = 0, No Iterations 0
GAMG:  Solving for p, Initial residual = 1, Final residual = 0.069625931, No Iterations 4
time step continuity errors : sum local = 3.3696411e-05, global = -7.2204088e-06, cumulative = -7.2204088e-06
smoothSolver:  Solving for omega, Initial residual = 0.00040862179, Final residual = 3.5476531e-07, No Iterations 1
smoothSolver:  Solving for k, Initial residual = 1, Final residual = 0.00077749877, No Iterations 1
ExecutionTime = 5.03 s  ClockTime = 10 s

Time = 2

- selected 245760 cell(s) with volume 2400
smoothSolver:  Solving for Ux, Initial residual = 0.26881031, Final residual = 0.00013096311, No Iterations 1
smoothSolver:  Solving for Uy, Initial residual = 0.77932555, Final residual = 0.0011502071, No Iterations 1
smoothSolver:  Solving for Uz, Initial residual = 0.63576559, Final residual = 0.00068403217, No Iterations 1
GAMG:  Solving for p, Initial residual = 0.063295736, Final residual = 0.0031233036, No Iterations 4
time step continuity errors : sum local = 8.1311918e-05, global = -1.6413664e-05, cumulative = -2.3634073e-05
smoothSolver:  Solving for omega, Initial residual = 0.0009977819, Final residual = 1.9905606e-06, No Iterations 1
smoothSolver:  Solving for k, Initial residual = 0.26501268, Final residual = 0.00026149791, No Iterations 1
ExecutionTime = 7.15 s  ClockTime = 12 s

As you can see, I select 90 cell(s) with volume 0.30424486, but my fvOptions file gives me 245760 cell(s) with volume 2400, wich is wrong. But, the last values match the whole domains cell number and volume.

I think my error is in the C cell selection, but I'm quite lost. I've read all the documentation available as well as every single post here.

Could someone help me please?:)

Antimony April 19, 2017 02:20

Hi,

My guess is the issue is here:

Code:

const scalarField& V = mesh_.V();
const vectorField& C = mesh_.C();

You are requesting for and accessing the cell volumes for the entire mesh and not the subset as you might think.

You might want to change/amend that based on this post:

https://www.cfd-online.com/Forums/op...tml#post645116

Hope this helps.

Cheers,
Antimony

pablo_fil April 19, 2017 03:20

Quote:

Originally Posted by Antimony (Post 645427)
Hi,

My guess is the issue is here:

Code:

const scalarField& V = mesh_.V();
const vectorField& C = mesh_.C();

You are requesting for and accessing the cell volumes for the entire mesh and not the subset as you might think.

You might want to change/amend that based on this post:

https://www.cfd-online.com/Forums/op...tml#post645116

Hope this helps.

Cheers,
Antimony

Hi!

First of all thanks for your quick reply.
I have already tested the solutions appearing in that post, but they didn't work as there were many UNDEFINED VARIABLEs.

Maybe you know how to define that set of variables.

Sent from my HUAWEI VNS-L31 using CFD Online Forum mobile app

Antimony April 19, 2017 04:12

Hi,

I tested it just now and it works fine. Perhaps you could mention which are the variables it says are undefined? If it is the name of your cellSet, then where it says cellSetName_, you need to replace it with "selectedCells"

(The double quotes are needed and I assume that the name of the cellSet is selectedCells)

A caveat: I tested it out on OF 2.4.x and not on OF 4.1. So I am not sure if that adds to any problems.

Hope this helps.

Cheers,
Antimony

pablo_fil April 19, 2017 10:37

Quote:

Originally Posted by Antimony (Post 645444)
Hi,

I tested it just now and it works fine. Perhaps you could mention which are the variables it says are undefined? If it is the name of your cellSet, then where it says cellSetName_, you need to replace it with "selectedCells"

(The double quotes are needed and I assume that the name of the cellSet is selectedCells)

A caveat: I tested it out on OF 2.4.x and not on OF 4.1. So I am not sure if that adds to any problems.

Hope this helps.

Cheers,
Antimony

Hi Antimony,

I have tryed using this in an older version of OpenFOAM (3.0x):
Code:

        codeSetValue
        #{
            cellSet selectedCells(mesh_, cellSetName_);
            labelList cells = selectedCells.toc();
        #};

or this:

Code:

        codeSetValue
        #{
            cellSet selectedCells(mesh, "myBox");
            labelList cells = selectedCells.toc();
        #};

In both cases i get the following error:

Code:

G:/OpenFOAM/Pablo_AMD-3.0.x/run/bloques/system/fvOptions.velocitySource.vectorCodedSourceCoeffs: In member function ‘virtual void Foam::fv::velocitySourceFvOptionvectorSource::setValue(Foam::fvMatrix<Foam::Vector<double> >&, Foam::label)’:
G:/OpenFOAM/Pablo_AMD-3.0.x/run/bloques/system/fvOptions.velocitySource.vectorCodedSourceCoeffs:41:1: error: ‘cellSet’ was not declared in this scope
G:/OpenFOAM/Pablo_AMD-3.0.x/run/bloques/system/fvOptions.velocitySource.vectorCodedSourceCoeffs:42:31: error: ‘selectedCells’ was not declared in this scope
/opt/OpenFOAM/OpenFOAM-3.0.x/wmake/rules/General/transform:8: fallo en las instrucciones para el objetivo 'Make/cygwin64mingw-w64DPInt32Opt/codedFvOptionTemplate.o'

Maybe in other files it works, but in fvOptions it seems that I have to declare that variables.

It's been a great help, it seems that we are close to the answer :o

Antimony April 19, 2017 22:12

Hi,

My attempt was in fvOptions. :)
But like I said, I ran it in OF 2.4 and so not sure if there has been a big change after that. :o

So here is the code snippet that I used (which I modified from your original one slightly):

Code:

codeAddSup
#{

    const scalarField& V = mesh_.V();
    const vectorField& C = mesh_.C();
    cellSet selectedCells(mesh_, "c0");

 
    cells_ = selectedCells.toc();

    scalar V_ = 0.0;

    for(int i=0;i<cells_.size();i++)
        V_ += V[cells_[i]];

    Info<< indent
    << "- selected " << cells_.size()
    << " cell(s) with volume " << V_ << endl;

#};

Cheers,
Antimony

pablo_fil April 21, 2017 04:47

It works!!!
 
Quote:

Originally Posted by Antimony (Post 645578)
Hi,

My attempt was in fvOptions. :)
But like I said, I ran it in OF 2.4 and so not sure if there has been a big change after that. :o

So here is the code snippet that I used (which I modified from your original one slightly):

Code:

codeAddSup
#{

    const scalarField& V = mesh_.V();
    const vectorField& C = mesh_.C();
    cellSet selectedCells(mesh_, "c0");

 
    cells_ = selectedCells.toc();

    scalar V_ = 0.0;

    for(int i=0;i<cells_.size();i++)
    V_ += V[cells_[i]];

    Info<< indent
    << "- selected " << cells_.size()
    << " cell(s) with volume " << V_ << endl;

#};

Cheers,
Antimony

IT WORKS!!!

Thank you so much for your help. Finally, the problem was about OpenFOAM and its well (un)known backwards-compatibility.

It works in OF2.4.0.

:):):):):)


All times are GMT -4. The time now is 19:21.