Writing data to a file
Hello,
I modified a solver to calculate a scalar coefficient which I need to compare with some experimental data. This coefficient is not a scalar field, a simple scalar for each time value. My problem is how shall I write this scalar to some text file along with time value? Some thing like: (time scalar value) (0 0 ) (0.1 0.125 ) (0.2 0.137 ) etc? Or some alternative form is also fine. All I need to write is coefficient and time. Can some one please help? |
I believe this question was answered before in this forum, here is a short answer
Code:
#include "OFstream.H" |
Hello Hassan and Kcn ;
Should we use OFstream or IOdictionary? In which part of OpenFoam code, users should add above your code lines? Thanks for any answer. |
Quote:
You use this code anywhere based on your code layout and the limitations of OFstreams. Generally for solvers, as per the original question, you can declare the OFstream before the time loop then use the OFstream object anywhere in your code in the same way as using Info or cout. |
Quote:
Really, I have a problem which I want to know if I have to use OFstream or IOdictionary. Suppose, There is an inlet x-axis velocity as boundary condition in my problem. I'm going to save the flow field for four different inlet velocity values. These four inlet velocities have been specified according to the following expression in a vector: A={1, 2, 3.5, 4.2}. Therefore, I defined boundary condition as follows: Code:
inlet Code:
#start of Main program Thanks for any kind attention &answer. |
Hello Mehdi,
I haven't the full answer for your questions but I would like to highlight few points;
I hope that my comments will be useful for your case and kindly notice that these are just general recommendations you shouldn't consider them as the only solution or a black and white guidelines. For example you will find that sometimes is essential to use the standard for-loop and OF source code has plenty of such cases. |
Hello Hassan,
First of all, I should describe that in my case , every member of vector(A) is corresponding with a inlet velocity that is in X-axis direction (Ux). Suppose, I need to gain flow field for t=10 s. I don't need transient results up to 10s and I'd like to compare flow fields corresponding every inlet velocity with together in final time (t=10s). There are two ways for this object explained as follows: 1-Running OF by run command in Ubuntu for every Ux with considering fix value for inlet boundary condition. Then comparing results and plotting graphs for every Ux (Vector A). 2- Altogether, Writing a code to run OF within a loop calling OF 2.3.1 and calling every Ux=A(i) and saving 10s results for every Ux in a separated folder. In this case, calling OF within loop is an important issue. In my belief, this way is faster than first option. I selected second option. Obviously, for option 2, Wmake command have to be executed after code writing until code be executable. How can I do this case ? What are general guidelines for wring a code according to the way (option)2 ? Thanks, |
As I understand, you want to run you solver with four different inlet conditions for Ux and stop and save the results after 10s. Additionally you want to run these for cases automatically.
I would suggest in that case to write bash script (like Allrun in OF) to loop over the different cases and you can change the BC using sed command. Also you can have a look on pyFoam maybe it could do the job for you. |
Quote:
I don't know great things about bash scripting. For example, how can I transfer vector/matrices values between inlet boundary & basch script? For example, I defined inlet boundary in blockMeshdict as follows: Code:
inlet Code:
# Is this expression correct here?---> A={1, 2, 3.5, 4.2} Also, I tried to use PyFoam. However, after installing PyFoam, I had some troubles with a simple tutorial that I post it at following post: http://www.cfd-online.com/Forums/ope...-problems.html Again, I asked my questions with red color at above codes. Many thanks for your attentions. |
I really cannot help with pyFoam because I don't use it but I read many times on this forum how it could help solving such problems. I think even basic python script could solve your problem.
For bash script, it should be straight forward to create and copy folder because it works exactly like working from the terminal. Your for loop syntax is right, for more options see; http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html Also, you will need to modify the velocity BC from your bash script which could be done using sed see; http://stackoverflow.com/questions/5...ork-it-empties I hope these hints could be useful because I have limited experience with bash scripting in general. |
Hello Hassan,
Thank you very much for your attentions & advises during this discussion. Although, I have many problems with reading and writing files/data/vectors into OF and vise versa operation yet that I will probably have to post them in next treads and I welcome you to take part in the my next discussion soon. Sincerely. M.Asghari |
Quote:
I use OF2.3.1 version, why I use this expression or only use OFstream.H head file #include "OFstream.H" show this errors? can you provide some suggestion? /usr/include/c++/4.8/bits/codecvt.h: In function ‘int main(int, char**)’: /usr/include/c++/4.8/bits/codecvt.h:41:15: error: expected ‘=’ before ‘__attribute__’ namespace std _GLIBCXX_VISIBILITY(default) ^ /usr/include/c++/4.8/bits/codecvt.h:41:15: error: expected identifier before ‘__attribute__’ /usr/include/c++/4.8/bits/codecvt.h:41:15: error: expected ‘;’ before ‘__attribute__’ /usr/include/c++/4.8/bits/codecvt.h:41:15: error: expected primary-expression before ‘__attribute__’ /usr/include/c++/4.8/bits/codecvt.h:41:15: error: expected ‘;’ before ‘__attribute__’ Best Reards, Aaron |
Hello Aaron,
I don't fully understand your question. Could you please include the code which gives this error? I'm sure that this problem isn't related to OF version because I used this class many times under diffrent versions. Bw, Hassan Kassem Quote:
|
How can I avoid overwritting its old time value ?
Quote:
How can i solve this problem? best wishes ziyang |
Quote:
Did you ever solve this problem? I am facing the same issue. |
All times are GMT -4. The time now is 10:58. |