|
[Sponsors] |
December 20, 2020, 16:54 |
Accessing values of a ScalarField
|
#1 |
New Member
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6 |
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? |
|
December 21, 2020, 02:35 |
|
#3 |
New Member
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6 |
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.
|
|
January 1, 2021, 12:37 |
|
#5 |
New Member
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6 |
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. |
|
January 2, 2021, 14:52 |
|
#7 |
New Member
Saumava Dey
Join Date: Sep 2020
Posts: 29
Rep Power: 6 |
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. |
|
January 3, 2021, 08:32 |
|
#9 | |
Senior Member
Join Date: Apr 2020
Location: UK
Posts: 748
Rep Power: 14 |
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; } Quote:
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. |
||
Tags |
internalfield, mesh, volscalarfield |
|
|
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 |