|
[Sponsors] |
Creating labelList from cells with certain attribute |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 25, 2015, 09:47 |
Creating labelList from cells with certain attribute
|
#1 |
New Member
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 13 |
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 |
|
March 26, 2015, 04:10 |
|
#2 |
Senior Member
|
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? |
|
March 27, 2015, 03:36 |
|
#3 |
New Member
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 13 |
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 05:13. |
|
March 27, 2015, 06:30 |
|
#4 |
New Member
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 13 |
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); Tanks for any kind of help, Julian |
|
March 31, 2015, 11:32 |
|
#5 |
New Member
Julian Hüttner
Join Date: Nov 2013
Location: Karlsruhe, Germany
Posts: 22
Rep Power: 13 |
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); 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 |
|
April 26, 2019, 19:58 |
|
#6 |
New Member
Ashwin
Join Date: Mar 2018
Location: Houston Texas
Posts: 10
Rep Power: 8 |
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. |
|
November 8, 2019, 21:25 |
|
#7 |
New Member
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 7 |
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 |
|
November 10, 2019, 20:06 |
|
#8 |
New Member
Ashwin
Join Date: Mar 2018
Location: Houston Texas
Posts: 10
Rep Power: 8 |
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); #}; |
|
November 11, 2019, 00:06 |
|
#9 |
New Member
samuel
Join Date: Oct 2019
Posts: 15
Rep Power: 7 |
Thanks a lot!!!!!That's really what I need!
samuel |
|
|
|
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 10:38 |
[mesh manipulation] refineMesh creating ugly cells at refinement interface. | CoolHand | OpenFOAM Meshing & Mesh Conversion | 4 | April 24, 2014 11:04 |
killed "snappyHexMesh" | parkh32 | OpenFOAM Pre-Processing | 2 | April 8, 2012 18:12 |
[Netgen] Import netgen mesh to OpenFOAM | hsieh | OpenFOAM Meshing & Mesh Conversion | 32 | September 13, 2011 06:50 |
Problem in running ICEM grid in Openfoam | Tarak | OpenFOAM | 6 | September 9, 2011 18:51 |