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

Access and manipulating data from specific cellzone

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 4 Post By Zeppo

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 3, 2017, 07:18
Default Access and manipulating data from specific cellzone
  #1
New Member
 
Or Werner
Join Date: Mar 2016
Posts: 7
Rep Power: 10
wernero is on a distinguished road
Dear all!

I'm working on a new solver for electromagnetics. I define a material character ('chi'), and read it successfully . Also, volVectorfield 'M' and 'H' are defined.

Let's assume a cellzone named "ironCore" is exist in polymesh. The next calculation is required:
Code:
1. for all the cells:
1.1 if the current cell is from "ironCore" cellzone: M[ID]=chi*H[ID].
1.2 otherwise: M[ID]=(0 0 0);
I assume it is possible to create a volScalarField chi, which is zero outside "ironCore". Then the calculation is performed with:
Code:
forAll(chi, celli)
{
  M[celli]=chi[celli]*H[celli];
}
but when ironCore is only a small part of the mesh, this is a waste. Is there a way to create a list of all the cells in "ironCore", so I could do the calculation only on those cells? The volVectorField M could be initialized with to (0 0 0), so it should be manipulated only in the specific cellzone
Code:
for (ii=first_cell_of_ironCore ; ii<number_of_cells_in_ironCore ; ii++)
{
  M[celli]=chi[celli]*H[celli];
}
thanks in advance...
Or.
wernero is offline   Reply With Quote

Old   May 5, 2017, 13:09
Default
  #2
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
This code might be a point you can start from:
Code:
const fvMesh& mesh = ...;

word cellSetName = "yourCellZoneName";

label zoneID = mesh.cellZones().findZoneID(cellSetName);

if (zoneID == -1)
{
    FatalErrorIn("yourFunctionName")
        << "Cannot find cellZone " << cellSetName << endl
        << "Valid cellZones are " << mesh.cellZones().names()
        << exit(FatalError);
}

const labelList& cells = mesh.cellZones()[zoneID];

Info << "Cells in cellzone " << cellSetName << ":" << endl;
forAll(cells, i)
{
    const label cell = cells[i];
    Info << cell << endl;
}
alainislas, geth03, wht and 1 others like this.
Zeppo is offline   Reply With Quote

Old   May 10, 2017, 10:28
Default
  #3
New Member
 
Or Werner
Join Date: Mar 2016
Posts: 7
Rep Power: 10
wernero is on a distinguished road
Thank you very much Sergei.

about the part of
Code:
const label cell = cells[i];
is "label cell" the index of the cell in the whole mesh, or the index of the cell in the list "cells"?

If it is the index in the whole mesh, than it is quite what I need, and I could manage from here.


thanks again for helping me,

Or.
wernero is offline   Reply With Quote

Old   May 12, 2017, 12:00
Default
  #4
Senior Member
 
Zeppo's Avatar
 
Sergei
Join Date: Dec 2009
Posts: 261
Rep Power: 21
Zeppo will become famous soon enough
Code:
const label cell = cells[i];
Here cell is a cell index in a whole mesh and you can use it like this
Code:
const volScalarField& T = ...
T[cell] = 300.0;
Zeppo 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



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