CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Writing/output of simple data into an ASCII-File (https://www.cfd-online.com/Forums/openfoam-programming-development/95274-writing-output-simple-data-into-ascii-file.html)

Minisasi May 3, 2016 18:27

Hello,
What I'd like to do is something a bit different.

I am implementing a new BC which is used by a certain volScalarField A.
This newBC calculates the values on the same patch of another volScalarField named B.
The B field is recalled inside the BC as

Code:

volScalarField B = this->db().lookupObject<volScalarField>("B");   
  fvPatchScalarField  Bs = B.boundaryField()[patchIndex];

Then (still inside the BC)
Code:

forAll (something, j)
{
Bs[j]= .....bla bla bla
}

Both A and B are initialized in the createFields.H as:

Code:

volScalarField A
    (
        IOobject
        (
            "A",
            runTime.timeName(),
            mesh,
            IOobject::MUST_READ_IF_MODIFIED,
            IOobject::AUTO_WRITE
        ),
        mesh,
        dimensionedScalar("A",dimensionSet(1, 2, -3, 0, 0, -1, 0),0)
    );

My problem is that I don't know exactly how to extract the values of Bs and write them at each time step as BC for B. In the last section of my BC
Code:

void Foam::newBC::write(Ostream& os) const
I tried something like
Code:

writeEntry("Bs", os);
but of course it writes those values inside the patch of A where the BC is used.

Shall I have to code a different BC for B? If so how do I store those Bs value from my newBC of A? (because write now as soon as I get out of the newBC they are removed)
Any ideas?

(sorry for being messy)
Thx

vigneshTG May 4, 2016 02:58

Hi Minisasi,

Can you try something like this ?

Code:

    if (dimensionedInternalField().mesh().time().outputTime())
    {
      B.write();
    }

Hope it helps !!

Minisasi May 4, 2016 10:42

Hi,

Thank you for your reply, but unfortunately it didn't work.:(

I tried to follow what they previously wrote couple of posts ago, and I wrote inside my newBC (for A)
Code:

fileName testFile("TEST.txt");
OFstream os(db().time().constant()/testFile);
os << "This is the first line in the file.\n";
os << B.boundaryField()[patchIndex].size();
os << endl

 forAll (something, j)
{
Bs[j]...... bla bla bla;
    os<< Bs[j];
    os << endl;
}

This kinda work, in the sense that it writes out in the /constant folder a .txt file with all the Bs values I wanted. The point is that I need those values inside the B boundary file.

Any hints?

reza_65 August 19, 2017 17:00

increasing writing precision
 
Dear Former,

In my OpenFOAM code, I defined a variable to trace my flame front position. So, in my log file the x position of that variable will be reported (component (0)). It works fine, but my problem is I can not increase the writing precision of this value! For example, in my running log file, I have Time = 0.000000240, max flametip = 71.9713, but I want my flametip have more accuracy!
I will apperaciate any suggestion and help.
To bear in mind, in my control dict, I put writePrecision 9; , timePrecision 9; and writeFormat ascii;

Best Regards,
Reza

Bloerb January 8, 2019 13:28

...........................


All times are GMT -4. The time now is 01:44.