CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF C++ . Variable Pressure control depending on measured airflow speed and pre-set s

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 7, 2019, 13:56
Default UDF C++ . Variable Pressure control depending on measured airflow speed and pre-set s
  #1
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Please find attached flowchart and c++ code.

Based on measured airflow speed compared against pre-set speed, pressure is varied ( input pressure in air duct). Pressure is incremented/decremented by 10% per a loop. Till the pre-set speed is reached.

Programming written in UDF fluent independent. Compiling outside fluent first. Thanks in advance.
Attached Files
File Type: pdf exp C++.pdf (28.0 KB, 16 views)
visitor is offline   Reply With Quote

Old   July 7, 2019, 17:49
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Are you just showing your code so we can be impressed, or do you have a question or request?

I have no idea what you mean with "Programming written in UDF fluent independent."
pakk is offline   Reply With Quote

Old   July 8, 2019, 08:08
Default
  #3
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
No I don't need to impress you gents. Just to see if there is a better way of doing this. Thanks.
visitor is offline   Reply With Quote

Old   July 9, 2019, 12:16
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
A better way of making the flowchart? Yes, you have a very slow searching method. Look for 'binary search', it is much more efficient than what you have.


A better way of writing the code that goes with the flowchart? Yes. I can see what you try, because you added the flowchart, but you made several grammar errors. If you would have tried to compile this, you would have certainly received errors.


A better way to actually solve your problem? Yes, you might not need a UDF. Fluent has the 'target mass flow rate' option if you have a pressure outlet, but I think that I never used it, so I can not say if it works well.


But although I see improvements in three aspects, let me end in a positive note: it is great, really super, that you made a flowchart before coding. It shows that you thought about your approach, and it makes it easy for others (including you six months from now!) to understand what you are trying to achieve with the code.
I'd rather have somebody working for me making code with mistakes but including such a flowchart, than code without mistakes that I can not understand.
pakk is offline   Reply With Quote

Old   July 10, 2019, 07:00
Default
  #5
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
I am not an expert in c++, just trying my best and sharing. This is another possible way, haven't worked with bolean. Will try it out later and get back, should be alright. Loop continues to monitor airflow and adjust pressure.


Float AirFlow:
Float pressure:

int increment_pressure= 1000; //increments pressure by 1000 Pa
Cin>> AirFlow;
switch (i++)
{
case (AirFlow >=5.5): // case with airflow input, if higher than 5.5 m/s
pressure -= increment_pressure; // this will start reduction of 1000 Pa
case (AirFlow <=5.0): // case if speed is lower than 5 m/s
pressure += increment_pressure; // this will increment pressure by 1000 Pa
}
printf("%d %d",increment_pressure, pressure);
visitor is offline   Reply With Quote

Old   July 16, 2019, 10:10
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Forget about c++, and use c. Fluent uses c. It is possible to cross-compile and use c++, but I find it hard to imagine a situation in which that is the best solution.


Regardless if you use c or c++, your code has some problems:

  • You don't declare i.
  • You don't initialize i.
  • You don't use i (you have no loop!)
  • You use switch/case in a way that makes no sense. It looks like you should have used if/then.
pakk is offline   Reply With Quote

Old   July 18, 2019, 08:35
Default
  #7
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Dear pack, thanks for your reply.

Yes there should be declaration and include libraries, .. was just focusing on the body code.

The case switch should do it, when ever a specific case is detected an action is taken. No need for a loop, I think.

Also regarding earlier posts in using faster boolean programing. I would have thought once a code is compiled, it will run fast anyway. Boolean or not.

Thanks
visitor is offline   Reply With Quote

Old   July 18, 2019, 08:56
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
  • Without a loop, your pressure will change one time, and then the program exits. That does not correspond to your flowchart.
  • The case/switch that you use REALLY makes no sense. You say that it "should do it", but I guarantee you that it will not, because you use it in a different way than the compiler will understand. I, as a human, understand what you want, but the compiler will not.
  • "when ever a specific case is detected an action is taken" => this screams for if/then. If the flow is too high, reduce the pressure. If the flow is too low, increase the pressure.
  • You use the words "Boolean programming" and "Boolean code", as if they have a clear meaning. They do not. So I don't know what you mean by that. I know what Boolean means.
pakk is offline   Reply With Quote

Old   July 20, 2019, 07:38
Default
  #9
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Thanks pakk for correcting me. I have included the variable AirFlow in the switch bracket now. This means as the variable change, then the individual case statement will act. However, what I have discovered is that the switch/case method doesn't handle float numbers, just whole numbers integers. The AirFlow in duct will vary with float numbers.

Float AirFlow:
Float pressure:

int increment_pressure= 1000; //increments pressure by 1000 Pa
Cin>> AirFlow;
switch (AirFlow)
{
case (AirFlow >=5.5): // case with airflow input, if higher than 5.5 m/s
pressure -= increment_pressure; // this will start reduction of 1000 Pa
case (AirFlow <=5.0): // case if speed is lower than 5 m/s
pressure += increment_pressure; // this will increment pressure by 1000 Pa
}
printf("%d %d",increment_pressure, pressure);
visitor is offline   Reply With Quote

Old   July 20, 2019, 08:34
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
It doesn't look like you use any of my comments (you still use c++ syntax in stead of c, you still use switch/case in stead of if/then, and you still don't have a loop), so I guess you are not interested in me helping you getting your code working. Good luck on your own.
pakk is offline   Reply With Quote

Old   July 21, 2019, 14:12
Default
  #11
Senior Member
 
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0
visitor is on a distinguished road
Was just discussing, thanks for your contribution.
visitor 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



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