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

Filling cells with values

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 1 Post By geth03
  • 1 Post By geth03

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 24, 2020, 09:51
Default Filling cells with values
  #1
New Member
 
Join Date: Sep 2020
Posts: 28
Rep Power: 6
Reptider is on a distinguished road
Hello!
I have created the body with blockMesh. I suggest that there are cells within the body.
My problem is to create own solver by which I fill each cell by certain value, for example, temperature = 5.
I have created initial conditions for T in the "0" file and created the "createFields.H" file, where defined values of field are read, it looks like:
Code:
volScalarField T
(
    IOobject
    (
        "T",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);
So then I would like to use "forAll" for changing already defined values in each cells like that:
Code:
forAll(T, i)
{
	...
}
How can I do that?
What should I do for see these values (fields) in paraview?
Reptider is offline   Reply With Quote

Old   November 24, 2020, 10:07
Default
  #2
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
why don't you just use setFieldsDict?
it would be more flexible.
geth03 is offline   Reply With Quote

Old   November 24, 2020, 10:17
Default
  #3
New Member
 
Join Date: Sep 2020
Posts: 28
Rep Power: 6
Reptider is on a distinguished road
Quote:
Originally Posted by geth03 View Post
why don't you just use setFieldsDict?
it would be more flexible.
I need to understand how to work with "forAll", because after that I must use "topoSet" to define zones of my body and go through the cells of each zones and assign special values for them.
Reptider is offline   Reply With Quote

Old   November 24, 2020, 10:45
Default
  #4
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
i see.

after defining your zone in topoSet you need to access the cells:

word myZone = "nameGivenInTopoSetDict";
label zoneID = mesh.cellZones().findZoneID(myZone);
const labelList& cells = mesh.cellZones()[zoneID];
forAll(cells, i)
{
const label cell = cells[i];
T[cell] = yourValue; //keep in mind that you need to match Unit also!
}

//repeat for other zones!
Reptider likes this.
geth03 is offline   Reply With Quote

Old   November 24, 2020, 10:59
Default
  #5
New Member
 
Join Date: Sep 2020
Posts: 28
Rep Power: 6
Reptider is on a distinguished road
Quote:
Originally Posted by geth03 View Post
i see.

after defining your zone in topoSet you need to access the cells:

word myZone = "nameGivenInTopoSetDict";
label zoneID = mesh.cellZones().findZoneID(myZone);
const labelList& cells = mesh.cellZones()[zoneID];
forAll(cells, i)
{
const label cell = cells[i];
T[cell] = yourValue; //keep in mind that you need to match Unit also!
}

//repeat for other zones!
Thank you!
Could you give me another advice what should I write in the solver that is responsible for sending cells to paraview? (Create "Cell Arrays" under "Mesh regions").
ParaView doesn't see new partial temperatures ( "T(partial)" ), but see created cellZones. They're represented by different colours. I can choose old T(partial) only which shows zero values at each cells (when "internalMesh" is chosen"). I have attached paraView interface: https://ibb.co/DrNqG8V.
In addition to this, I've noticed that new time has appeared (1 sec). How can I avoid this?

Last edited by Reptider; November 24, 2020 at 14:57.
Reptider is offline   Reply With Quote

Old   November 25, 2020, 03:26
Default
  #6
Senior Member
 
Join Date: Dec 2019
Location: Cologne, Germany
Posts: 369
Rep Power: 8
geth03 is on a distinguished road
look at this T-object:

volScalarField T
(
IOobject
(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

if you create a volScalarField as IOobject it means it is an input-output object, which means the solver can read and/or write data, so paraview can find it in the time-directories. if you write AUTO_WRITE it will create a T-file in every output directory that you can open with paraview, the files will be updated when your solver calls the function runTime.write().

you decide in controlDict under writeInterval when runtime.write() should be called. if you change your T-field in the solver manually with cellZones and later on let the solver update the field by solving an equation you will see the field which is provided by the result of the equation for T.

if you initialize your T-field in the 0-directory with 0-entries for the internal mesh it is normal that in the old timestep which is time=0 sec that paraview shows only 0 Kelvin.
Reptider likes this.
geth03 is offline   Reply With Quote

Old   November 25, 2020, 10:41
Default
  #7
New Member
 
Join Date: Sep 2020
Posts: 28
Rep Power: 6
Reptider is on a distinguished road
Quote:
Originally Posted by geth03 View Post
look at this T-object:

volScalarField T
(
IOobject
(
"T",
runTime.timeName(),
mesh,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh
);

if you create a volScalarField as IOobject it means it is an input-output object, which means the solver can read and/or write data, so paraview can find it in the time-directories. if you write AUTO_WRITE it will create a T-file in every output directory that you can open with paraview, the files will be updated when your solver calls the function runTime.write().

you decide in controlDict under writeInterval when runtime.write() should be called. if you change your T-field in the solver manually with cellZones and later on let the solver update the field by solving an equation you will see the field which is provided by the result of the equation for T.

if you initialize your T-field in the 0-directory with 0-entries for the internal mesh it is normal that in the old timestep which is time=0 sec that paraview shows only 0 Kelvin.
Yeah! I appreciate your help!
I've got that code:
Code:
word one_sec = "1";
    while (runTime.loop())
    { 
          Info<< "Time = " << runTime.timeName() << endl;
          if ( runTime.timeName() == one_sec )
          {
          	Info<< "\nSet up certain values for cellZones\n" << endl;
                word myZone1 = "cs1";
    		label zoneID1 = mesh.cellZones().findZoneID(myZone1);
    		const labelList& cells1 = mesh.cellZones()[zoneID1];
    		forAll(cells1, i)
    		{
    		const label cell = cells1[i];
    		T[cell] = 5;
    		}
    
    		word myZone2 = "cs2";
    		label zoneID2 = mesh.cellZones().findZoneID(myZone2);
    		const labelList& cells2 = mesh.cellZones()[zoneID2];
    		forAll(cells2, j)
    		{
    		const label cell = cells2[j];
    		T[cell] = 25;
    		}
    
    		word myZone3 = "cs3";
    		label zoneID3 = mesh.cellZones().findZoneID(myZone3);
    		const labelList& cells3 = mesh.cellZones()[zoneID3];
    		forAll(cells3, k)
    		{
    		const label cell = cells3[k];
    		T[cell] = 100;
    		}
    		
    		runTime.write(); 		
          }
     }
It creates the new file "1" at the directory of programm. Now I can see changed T field in paraview at 1 sec.
Reptider 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] snappyHexMesh sticking point natty_king OpenFOAM Meshing & Mesh Conversion 11 February 20, 2024 10:12
How to cell field values to cells in setFields upuli OpenFOAM Running, Solving & CFD 3 January 23, 2017 11:32
[ICEM] Problem with prism cells sidharath ANSYS Meshing & Geometry 0 September 1, 2015 08:09
[snappyHexMesh] No layers in a small gap bobburnquist OpenFOAM Meshing & Mesh Conversion 6 August 26, 2015 10:38
snappyhexmesh remove blockmesh geometry philipp1 OpenFOAM Running, Solving & CFD 2 December 12, 2014 11:58


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