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

Trying to create a range of values in openFoam c file

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 31, 2022, 19:55
Question Trying to create a range of values in openFoam c file
  #1
New Member
 
Nadeem Kever
Join Date: Jul 2019
Posts: 4
Rep Power: 7
NKever is on a distinguished road
Hi all,

I'm trying to do something very simple, but am not sure how to go about it. Essentially, here's what I need to do:
first create a range of values
then do a for loop over that range.
In matlab, it would look something like this:

Code:
x1 = 1; %Start
x2 = 3; %end
n = 5; %number of steps
y = linspace(x1,x2,n);  % creates the range between z1 and x2 in n steps
for i = y
    i
end
In OF (in the context of what I need to do) I assume it would look something like:
Code:
tmp = 0;
x1 = 1; //Start
x2 = 3; //end
n = 5; //number of steps
y = RANGE(x1,x2,n); // pseudocode for range  <-- What goes here to create the range??
for (int i = 0; i < n; i ++){
      tmp = y[i]
      // do stuff with tmp val here
    
}
I know this is a very basic question, but as someone still learning c++ and oF I can't figure it out!

Thanks for any help!

Last edited by NKever; January 1, 2023 at 09:38.
NKever is offline   Reply With Quote

Reply

Tags
c++, for loop, ranges


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
Using PengRobinsonGas EoS with sprayFoam Jabo OpenFOAM Running, Solving & CFD 36 July 16, 2024 04:52
[OpenFOAM.com] swak4foam compiling issues on a cluster saj216 OpenFOAM Installation 5 January 17, 2023 17:05
OpenFoam "Permission denied" and "command not found" problems. iyidaniel@yahoo.co.uk OpenFOAM Running, Solving & CFD 11 January 2, 2018 07:47
[swak4Foam] funkySetFields compilation error tayo OpenFOAM Community Contributions 39 December 3, 2012 06:18
"parabolicVelocity" in OpenFoam 2.1.0 ? sawyer86 OpenFOAM Running, Solving & CFD 21 February 7, 2012 12:44


All times are GMT -4. The time now is 05:38.