|
[Sponsors] |
UDF C++ . Variable Pressure control depending on measured airflow speed and pre-set s |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
July 7, 2019, 13:56 |
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 |
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. |
|
July 7, 2019, 17:49 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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." |
|
July 8, 2019, 08:08 |
|
#3 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
No I don't need to impress you gents. Just to see if there is a better way of doing this. Thanks.
|
|
July 9, 2019, 12:16 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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. |
|
July 10, 2019, 07:00 |
|
#5 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
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); |
|
July 16, 2019, 10:10 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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:
|
|
July 18, 2019, 08:35 |
|
#7 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
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 |
|
July 18, 2019, 08:56 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
|
|
July 20, 2019, 07:38 |
|
#9 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
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); |
|
July 20, 2019, 08:34 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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.
|
|
July 21, 2019, 14:12 |
|
#11 |
Senior Member
AH
Join Date: Apr 2014
Posts: 287
Rep Power: 0 |
Was just discussing, thanks for your contribution.
|
|
|
|