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 Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 31, 2022, 18: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: 6
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 08:38.
NKever is offline   Reply With Quote

Reply

Tags
c++, for loop, ranges

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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


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