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

Data awfully saved with IOStream when using scalar

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 22, 2019, 08:32
Default Data awfully saved with IOStream when using scalar [SOLVED]
  #1
New Member
 
Join Date: Sep 2019
Posts: 18
Rep Power: 7
rucky96 is on a distinguished road
Hi all,

I am trying to save some data from some variables that I am working out every time step with:
Code:
        energyFile << runTime.timeName() << "\t\t"
                   << Em.weightedAverage(mesh.V()).value() << "\t\t" //Em is volScalarField
                   << Ek.weightedAverage(mesh.V()).value() << "\t\t"//Ek is volScalarField
                   << Et.weightedAverage(mesh.V()).value() << "\t\t"//Et is volScalarField
                   << max(mag(J)).value() << "\t\t"//J is volVectorField
                   << a.weightedAverage(mesh.V()).value()+b.weightedAverage(mesh.V()).value() << "\t\t" //a & b are volScalarField
                   << pR << "\t\t" ////pR is scalar
                   << endl;
When I run the simulation I obtain:
Code:
0.01            0.271417                0.000693869             0.272111                3.13241         0.0263245               5.1935
00.02           0.271321                0.000464667             0.271786                3.44374         0.0238673               4.8994
00.03           0.271221                0.00033977              0.271561                3.48565         0.0224566               5.15044 000.04          0.271117                0.000268453             0.271386                3.47999         0.021592                4.63075 000.05          0.271011                0.000229149             0.27124         3.41899         0.0210318               4.6224100.06            0.270903                0.000210638             0.271114                3.29874         0.0206501               4.8617
000.07          0.270795                0.000206592             0.271001                3.14365         0.0203772               4.84191 00.08           0.270686                0.000213266             0.270899                2.99081         0.0201733               4.81369
which is awfully saved and I cannot plot it.

However, if i remove the scalar "pR"
Code:
        energyFile << runTime.timeName() << "\t\t"
                   << Em.weightedAverage(mesh.V()).value() << "\t\t" //Em is volScalarField
                   << Ek.weightedAverage(mesh.V()).value() << "\t\t"//Ek is volScalarField
                   << Et.weightedAverage(mesh.V()).value() << "\t\t"//Et is volScalarField
                   << max(mag(J)).value() << "\t\t"//J is volVectorField
                   << a.weightedAverage(mesh.V()).value()+b.weightedAverage(mesh.V()).value() << "\t\t" //a & b are volScalarField
                   //<< pR << "\t\t" ////pR is scalar
                   << endl;
the data is properly saved:
Code:
0.01            0.271417                0.000693869             0.272111                3.13241         0.0263245
0.02            0.271321                0.000464667             0.271786                3.44374         0.0238673
0.03            0.271221                0.00033977              0.271561                3.48565         0.0224566
0.04            0.271117                0.000268453             0.271386                3.47999         0.021592
0.05            0.271011                0.000229149             0.27124                 3.41899         0.0210318
0.06            0.270903                0.000210638             0.271114                3.29874         0.0206501
0.07            0.270795                0.000206592             0.271001                3.14365         0.0203772
0.08            0.270686                0.000213266             0.270899                2.99081         0.0201733
I am compiling in a Linux server and my laptop has a Windows 10 Pro OS in case it has something to do.

Does anyone known what is happening and how can I save a scalar?

Regards.

Last edited by rucky96; January 14, 2020 at 21:29.
rucky96 is offline   Reply With Quote

Old   December 27, 2019, 14:52
Default
  #2
New Member
 
Dan
Join Date: Nov 2013
Posts: 27
Rep Power: 13
Danubi is on a distinguished road
Are you having the same problem running the case in parallel and in serial?


In case you run in parallel you should use:


Code:
if(Pstream::master())

and the printing commands within { }.


Hope this helps
Danubi is offline   Reply With Quote

Old   December 30, 2019, 19:28
Default
  #3
New Member
 
Join Date: Sep 2019
Posts: 18
Rep Power: 7
rucky96 is on a distinguished road
Hi Danubi, thanks for answering.

I tried the following:
Code:
        if(Pstream::master())
        {
                energyFile << runTime.timeName() << "\t\t" 
                        << Em.weightedAverage(mesh.V()).value() << "\t\t"
                        << Ek.weightedAverage(mesh.V()).value() << "\t\t"
                        << Et.weightedAverage(mesh.V()).value() << "\t\t"
                        << max(mag(J)).value() << "\t\t"
                        << a.weightedAverage(mesh.V()).value()+b.weightedAverage(mesh.V()).value() << "\t\t"
                        << pR << "\t\t"
                        << endl;
        }
But when the simulation ends the first time step, it is "frozen". Neither print the values ​​nor jump to the second time step nor returns FATAL ERROR. Do I have to add something else?

PS: The problem also disappears when I run it in serial
rucky96 is offline   Reply With Quote

Old   January 14, 2020, 21:28
Default
  #4
New Member
 
Join Date: Sep 2019
Posts: 18
Rep Power: 7
rucky96 is on a distinguished road
In the end I have solved it, I took the idea of ​​Danubi and continued testing combinations until it has come out:
Code:
	energyFile << runTime.timeName() << "\t\t" 
		<< Em.weightedAverage(mesh.V()).value() << "\t\t"
                << Ek.weightedAverage(mesh.V()).value() << "\t\t"
                << Et.weightedAverage(mesh.V()).value() << "\t\t"
                << max(mag(J)).value() << "\t\t"
                << a.weightedAverage(mesh.V()).value()+b.weightedAverage(mesh.V()).value() << "\t\t";
	if(Pstream::master()){energyFile << pR << "\t\t" << endl;}
Don't ask me why, I don't know what I did but works.
rucky96 is offline   Reply With Quote

Reply

Tags
iostream


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
ERROR: request for volScalarField thermo:psi from objectRegistry region0 AAbouali OpenFOAM Running, Solving & CFD 1 September 19, 2020 05:53
Non uniform temperature gradient Nabeel Abed OpenFOAM Programming & Development 2 August 20, 2019 09:10
UDF value to large for defined data type Anna73 Fluent UDF and Scheme Programming 9 September 30, 2018 23:18
Run OpenFoam in 2 nodes of a cluster WhiteW OpenFOAM Running, Solving & CFD 16 December 20, 2016 01:51
studying a valve case mina.basta OpenFOAM 33 August 30, 2013 05:46


All times are GMT -4. The time now is 16:23.