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

Creating labelList from cells with certain attribute

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2015, 08:47
Default Creating labelList from cells with certain attribute
  #1
New Member
 
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 12
juhuettn is on a distinguished road
Hello Foamers,

I am stuck in the moment with following problem:
I want to use the setValues command to manipulate my Matrix just before solving. I not only want to set the values of a boundary, I want to set the values of internal cells. To be more precise, I want to set the values of internal cells which have a certain attribute. The attribute is a blending function value of each cell.

My basic idea of solving this problem is to create a volScalarField with all the cells forfilling the attribute. The size of this field needs to be exactly the amount of the chosen cells, so I do not override too many values in the matrix. I would then create a labelList from that field and use these two as arguments for the setValue funtion.

I do not know how to create the field with exactly the amount of cells which have the attribute. I thought of using a forAll loop, but for this I have to initiate a field which has already a given size.

I am very helpful for any help! Thanks, Julian
juhuettn is offline   Reply With Quote

Old   March 26, 2015, 03:10
Default
  #2
Senior Member
 
Jens Höpken
Join Date: Apr 2009
Location: Duisburg, Germany
Posts: 159
Rep Power: 17
jhoepken is on a distinguished road
Send a message via Skype™ to jhoepken
Maybe it's just me, but I don't really get what you ask for. You want to set values in a volScalarField as well as on the boundary? Could you explain this in brief?
__________________
Blog: sourceflux.de/blog
"The OpenFOAM Technology Primer": sourceflux.de/book
Twitter: @sourceflux_de
Interested in courses on OpenFOAM?
jhoepken is offline   Reply With Quote

Old   March 27, 2015, 02:36
Default
  #3
New Member
 
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 12
juhuettn is on a distinguished road
Hello Jens,

Sorry, I thought it would maybe be too confusing :-).

I want to implement a two-layer turbulence model, so I need to use the transport equation for k and epsilon in the outer boundary layer, but closer to the wall I need to use algebraic equations to solve the turbulence parameters.

The problem is, that I need to include the algebraic into the matrix before solving it. So I need to set up the matrix with the standard transport equations and then replace some parts of the matrix with the algebraic equations. I do not need to set the values at the wall, as they are already set by the boundary conditions, but the values of the cells which forfill the attribute to use the algebraic equations. For this, I want to use the "setValue" command. To use the setValues I need to give the function a labellist and a volScalarField with the values to set for the cells.

What I am now struggeling with is to built a labellist and a volScalarField with the cells forfilling an attribute (saying some scalar of the cell is smaller than some number), for which the setValues command should be used to replace the transport equations with the algebraic equations befor solving the matrix.

I hope this was somehow more understandable :-).

Last edited by juhuettn; March 27, 2015 at 04:13.
juhuettn is offline   Reply With Quote

Old   March 27, 2015, 05:30
Default
  #4
New Member
 
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 12
juhuettn is on a distinguished road
Maybe someone can help me to get there step by step. In the moment I am using following piece to start with to build my labelList:

Code:
label CellCount = 0;

forAll (epsilon_, cellI)
{
    if (checkFctn[cellI] < 0.8)
    {
         "find CellID[cellI]" //Here, I would like to write out the cellID to use the ID as value for the labellist. Is there a function to do that?
        
        cellCount++; //Amount of cells with checkFctn < 0.8 to use as size for labellist
    }

labelList (cellCount, cellIDs);
I do not know how to write out the cellIDs during the forAll loop and extract them to use them as values in the labelList.

Tanks for any kind of help,
Julian
juhuettn is offline   Reply With Quote

Old   March 31, 2015, 10:32
Default
  #5
New Member
 
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 12
juhuettn is on a distinguished road
Hello Foamers,

I will try again to get this going by posting my process. I now managed to create a labellist with the cell IDs I am needing as argument for my setValue() function. As far as I understood, the setValue() function needs also a volScalarField with the same size as the labelList to work correctly (is that right)?

I created the labelList as follows:

Code:
    

    // Dissipation Sequation
    tmp<fvScalarMatrix> epsEqn
    (
        fvm::ddt(epsilon_)        
        + fvm::div(phi_, epsilon_)
        - fvm::laplacian(DepsilonEff(), epsilon_)
     ==
        C1_*G*epsilon_/k_
        - fvm::Sp(C2_*epsilon_/k_, epsilon_)
    );

    epsEqn().relax();

    //create labelList with cells to change for setValues function

    const tmp<volScalarField> tfCheck = fCheck();
    const volScalarField& fCheckTemp = tfCheck();

    label n = 0;
    forAll(epsilon_, cellI)
    {
        if (fCheckTemp[cellI]<0.8)
        {
            n++;
        }
    }

    cout <<"n="<< n;

    labelList setElements(n);

    n = 0;

    forAll(epsilon_, cellI)
    {
        if (fCheckTemp[cellI]<0.8)
        {
            setElements[n++] = cellI;
        }
    }

    const labelUList& keepCells = setElements;

    epsEqn().setValues(keepCells, epsilonOverwrite_);

    solve(epsEqn);
My problem now is, that the Field "epsilonOverwrite" needs to have the same size as the labelList keepCells (I think so). The code compiles when I use a Field with the full mesh size, but the simulation crashes (I think, the wrong values are picked from the field).

Does anybody know how to create a volScalarField only including the cells of a given labelList?

I would be so thankful for any kind of help or support!

Julian
juhuettn is offline   Reply With Quote

Old   April 26, 2019, 18:58
Default
  #6
api
New Member
 
Ashwin
Join Date: Mar 2018
Location: Houston Texas
Posts: 10
Rep Power: 8
api is on a distinguished road
In case this issue is still pending, I am positing my solution here. There are some redundant variables. So please ignore them.

codeSetValue
#{
Pout<< "**codeSetValue**" << endl;
int my_cs_sz =0;
List<label> my_labs;
const volScalarField& alpha_m2 = mesh().lookupObject<volScalarField>("alpha.air");
forAll(alpha_m2, celli)
{
if(alpha_m2[celli]>0){
my_labs.append(celli);
}
}

cellSet my_set(mesh(),"arc");
const labelUList& my_cel =my_set.toc();
forAll(my_cel,id)
{
my_cs_sz+=1;
}

//List<scalar> my_list(my_cs_sz);
List<scalar> my_list(my_labs.size());
scalar my_temp = 782 + mesh().time().value()*30000;
my_list =(my_temp);
eqn.setValues(my_cel,my_list);
Pout<< my_cs_sz << endl;
//eqn.setValues() = 8000;
#};
}


I was trying to set temperature values to locations based on alpha.
api is offline   Reply With Quote

Old   November 8, 2019, 20:25
Default
  #7
New Member
 
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 6
Samuel Twain is on a distinguished road
Hello api:
I want to set different value for different elememt in my_lisy. But it seems that in your code the operator= is only reloaded to set the same value for all elements in my_list. Could you please give me some advices.
Thanks
samuel
Samuel Twain is offline   Reply With Quote

Old   November 10, 2019, 19:06
Default
  #8
api
New Member
 
Ashwin
Join Date: Mar 2018
Location: Houston Texas
Posts: 10
Rep Power: 8
api is on a distinguished road
you can set the list to any value. I am not sure if i understand your question well. I think the snippet below is what you are looking for.



Code:
            codeSetValue
            #{
               List<label> my_labs;
               List<scalar> my_list;
               scalar my_temp=0.0,xc=0.0,yc=0.0;
               const volScalarField& alpha_m2 =mesh().lookupObject<volScalarField>("alpha.air");
               forAll(alpha_m2,celli)
               {
               my_temp=0;
               xc=0.0;
               yc=0.0;
                if(alpha_m2[celli]>0.2){
                 my_labs.append(celli);
                 xc=fabs(0.5-mesh().C()[celli].x());
                 yc=fabs(1.0-mesh().C()[celli].y());
                 my_temp=578-xc*100-yc*100;  // define any function to set the value for each induvidual cell
                my_list.append(my_temp);   // setting the above defined value to the cellid identified by the if condition
                 }
               }
               eqn.setValues(my_labs, my_list);
            #};
api is offline   Reply With Quote

Old   November 10, 2019, 23:06
Default
  #9
New Member
 
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 6
Samuel Twain is on a distinguished road
Thanks a lot!!!!!That's really what I need!
samuel
Samuel Twain 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
[snappyHexMesh] No layers in a small gap bobburnquist OpenFOAM Meshing & Mesh Conversion 6 August 26, 2015 09:38
[mesh manipulation] refineMesh creating ugly cells at refinement interface. CoolHand OpenFOAM Meshing & Mesh Conversion 4 April 24, 2014 10:04
killed "snappyHexMesh" parkh32 OpenFOAM Pre-Processing 2 April 8, 2012 17:12
[Netgen] Import netgen mesh to OpenFOAM hsieh OpenFOAM Meshing & Mesh Conversion 32 September 13, 2011 05:50
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51


All times are GMT -4. The time now is 20:11.