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

Accessing values of a ScalarField

Register Blogs Community New Posts Updated Threads Search

Like Tree4Likes
  • 1 Post By dlahaye
  • 1 Post By dlahaye
  • 1 Post By dlahaye
  • 1 Post By Tobermory

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 20, 2020, 16:54
Default Accessing values of a ScalarField
  #1
New Member
 
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6
saumavadey is on a distinguished road
If I define a volScalarField within my code, does it by default correspond to the mesh size I am working with?

The mesh I am working with is having 100 cells. I am asking this because if I am printing the 150th element value by the command:

Info << h.internalField()[150] << endl;

it is still printing some value, which in my knowledge is not supposed to happen.

Can anyone explain why is this happening?
saumavadey is offline   Reply With Quote

Old   December 20, 2020, 17:02
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Boundary values, i.e., values of volScalarField in center of face on the boundary?
saumavadey likes this.
dlahaye is offline   Reply With Quote

Old   December 21, 2020, 02:35
Default
  #3
New Member
 
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6
saumavadey is on a distinguished road
If it is printing the boundary values then it should have some limit. If I am trying to print the 1000th value for a 100 cell mesh, then also it is printing some value. So, the mystery still remains persistent.
saumavadey is offline   Reply With Quote

Old   December 21, 2020, 09:12
Default
  #4
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Run in debugger?
dlahaye is offline   Reply With Quote

Old   January 1, 2021, 12:37
Default
  #5
New Member
 
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6
saumavadey is on a distinguished road
A part of my code reads like this:

C = (T1-T2)/(H1-H2);

All variables, C, T1, T2, H1, H2 are volScalarFields corresponding to a particular 1D mesh.

This step is not working.

Individually when I am printing the values of the fields (T1-T2) and (H1-H2), the values are finite corresponding to the number of cells.

Can't figure out where is the error.
saumavadey is offline   Reply With Quote

Old   January 1, 2021, 14:43
Default
  #6
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
The division of vector is mathematically not defined.

What are you trying to accomplish?
saumavadey likes this.
dlahaye is offline   Reply With Quote

Old   January 2, 2021, 14:52
Default
  #7
New Member
 
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6
saumavadey is on a distinguished road
I require to find out the value of C for each cell which can be calculated as:
C[i] = (T1[i] - T2[i])/(H1[i] - H2[i]);

All variables, C, T1, T2, H1, H2 are volScalarFields corresponding to a particular 1D mesh.
saumavadey is offline   Reply With Quote

Old   January 2, 2021, 16:22
Default
  #8
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 802
Blog Entries: 1
Rep Power: 19
dlahaye is on a distinguished road
Again, the division of vectors is mathematically not defined.
saumavadey likes this.
dlahaye is offline   Reply With Quote

Old   January 3, 2021, 08:32
Default
  #9
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 748
Rep Power: 14
Tobermory will become famous soon enough
This is as expected, and is a feature of C++ (ie nothing to do with OpenFOAM). For example, look at the following code:
Code:
#include<iostream>
using namespace std;
int main()
{
		int a[3] = {40, 41, 42};
		cout << "a[0] = " << a[0] << endl;
		cout << "a[2] = " << a[2] << endl;
		cout << "a[5] = " << a[5] << endl;
		return 0;
}
I define an array with 3 entries .. but can still write the contents of the 6th - the output (try it) is:
Quote:
a[0] = 40
a[2] = 42
a[5] = 6294224
So what is going on? Well, have a read up on arrays in C++ ... you'll realise that arrays are addressed by pointers, in other words a[5] is just equivalent to *(a+5), and there is nothing stopping you calculating whatever pointer address you want and then going and checking the memory contents of that address (so long as the address exists). The contents may be junk, of course ... like in the above example.

So, long and short of it - you can't rely on the code spitting out its dummy if you go beyond the array dimensions; instead, you need to check yourself.
saumavadey likes this.
Tobermory is offline   Reply With Quote

Reply

Tags
internalfield, mesh, volscalarfield


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
[openSmoke] libOpenSMOKE Tobi OpenFOAM Community Contributions 562 January 25, 2023 10:21
Values for nu t and nu tilda Phizz82 OpenFOAM Running, Solving & CFD 1 March 2, 2020 07:00
help needed for accessing previous step values weirdsda FLUENT 5 April 7, 2017 09:58
strange node values @ solid/fluid interface - help JB FLUENT 2 November 1, 2008 13:04
Accessing node values using a UDF Nico FLUENT 2 December 20, 2007 03:50


All times are GMT -4. The time now is 15:52.