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

cellSet volume in fvOptions

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes
  • 1 Post By Antimony
  • 1 Post By Antimony
  • 1 Post By Antimony
  • 1 Post By pablo_fil

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 18, 2017, 13:49
Post cellSet volume in fvOptions
  #1
New Member
 
Pablo Mtz. Filgueira
Join Date: Apr 2014
Location: Vitoria-Gasteiz
Posts: 25
Rep Power: 7
pablo_fil is on a distinguished road
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?
pablo_fil is offline   Reply With Quote

Old   April 19, 2017, 03:20
Default
  #2
Senior Member
 
Join Date: Aug 2013
Posts: 380
Rep Power: 9
Antimony is on a distinguished road
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:

Access to cellid in cellSet

Hope this helps.

Cheers,
Antimony
pablo_fil likes this.
Antimony is offline   Reply With Quote

Old   April 19, 2017, 04:20
Default
  #3
New Member
 
Pablo Mtz. Filgueira
Join Date: Apr 2014
Location: Vitoria-Gasteiz
Posts: 25
Rep Power: 7
pablo_fil is on a distinguished road
Quote:
Originally Posted by Antimony View Post
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:

Access to cellid in cellSet

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
pablo_fil is offline   Reply With Quote

Old   April 19, 2017, 05:12
Default
  #4
Senior Member
 
Join Date: Aug 2013
Posts: 380
Rep Power: 9
Antimony is on a distinguished road
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 likes this.
Antimony is offline   Reply With Quote

Old   April 19, 2017, 11:37
Default
  #5
New Member
 
Pablo Mtz. Filgueira
Join Date: Apr 2014
Location: Vitoria-Gasteiz
Posts: 25
Rep Power: 7
pablo_fil is on a distinguished road
Quote:
Originally Posted by Antimony View Post
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
pablo_fil is offline   Reply With Quote

Old   April 19, 2017, 23:12
Default
  #6
Senior Member
 
Join Date: Aug 2013
Posts: 380
Rep Power: 9
Antimony is on a distinguished road
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.

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 likes this.
Antimony is offline   Reply With Quote

Old   April 21, 2017, 05:47
Default It works!!!
  #7
New Member
 
Pablo Mtz. Filgueira
Join Date: Apr 2014
Location: Vitoria-Gasteiz
Posts: 25
Rep Power: 7
pablo_fil is on a distinguished road
Quote:
Originally Posted by Antimony View Post
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.

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.

Antimony likes this.
pablo_fil is offline   Reply With Quote

Reply

Tags
fvoptions, source term, vectorcodedsource

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[GAMBIT] Meshing T-pipe maxpoint ANSYS Meshing & Geometry 19 November 25, 2016 02:33
[blockMesh] edges not aligned with or perpendicular to non-empty directions ynos OpenFOAM Meshing & Mesh Conversion 5 March 24, 2015 09:15
On the damBreak4phaseFine cases paean OpenFOAM Running, Solving & CFD 0 November 14, 2008 22:14
[Commercial meshers] CuBit t42 OpenFOAM Meshing & Mesh Conversion 6 July 10, 2008 08:51
[blockMesh] Axisymmetrical mesh Rasmus Gjesing (Gjesing) OpenFOAM Meshing & Mesh Conversion 10 April 2, 2007 15:00


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