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

Problem in Writing Field U

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By AriaFoam89
  • 2 Post By LuckyTran

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 18, 2018, 19:31
Default Problem in Writing Field U
  #1
New Member
 
Aria
Join Date: Jul 2018
Posts: 2
Rep Power: 0
AriaFoam89 is on a distinguished road
Hi foamers,


I'm trying to write the velocity field with a different name in each time directory, then I write this code in creatFields.H of my solver (let's say mybuoyantBoussinesqPimpleFoam):
Code:
Info<< "Calculating myName\n" << endl
volVectorField myName
  (
  IOobject 
    (
      "myName",
      runTime.timeName(),
      mesh,
      IOobject::MUST_READ,
      IOobject::AUTO_WRITE
    ),
    U
  );
However, I get wrong answer. in each time directory this will be written:
Code:
dimensions      [0 1 -1 0 0 0 0];

internalField   uniform (0 0 0);

boundaryField
{
    upperWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
    leftWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
    rightWall
    {
        type            fixedValue;
        value           uniform (0 0 0);
    }
    frontAndBack
    {
        type            empty;
    }
 }
I know that the velocity shouldn't be zero and it shouldn't be a fixed value because a few lines above my code, writing the velocity field is defined like this in creatFields.H:
Code:
Info<< "Reading field U\n" << endl;
volVectorField U
(
    IOobject
    (
        "U",
        runTime.timeName(),
        mesh,
        IOobject::MUST_READ,
        IOobject::AUTO_WRITE
    ),
    mesh
);
and the above code is writing a correct (varying with time) vector for velocity my question is why my method is not working properly?



Thanks
ALBATTROSS likes this.
AriaFoam89 is offline   Reply With Quote

Old   November 20, 2018, 10:07
Default
  #2
New Member
 
Amir
Join Date: Oct 2018
Posts: 17
Rep Power: 7
ALBATTROSS is on a distinguished road
Hi,

can you please help me with this? I have the same problem with writing gradU!
Wrong shear rate result with the existing code

thanks
ALBATTROSS is offline   Reply With Quote

Old   November 21, 2018, 09:04
Wink
  #3
Senior Member
 
Lucky
Join Date: Apr 2011
Location: Orlando, FL USA
Posts: 5,675
Rep Power: 66
LuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura aboutLuckyTran has a spectacular aura about
createFields is called only at startup to initialize fields to make places for them in memory.


You defined myName = U in createFields. During startup your field myName will be set equal to the current values for U (if your startTime is 0 then then myName will take on the values of U at 0). If you do nothing else, the field myName never gets updated again ever and stays at the initial values.


You need to go into your mybuoyantBoussinesqPimpleFoam.c and add a line that looks like this. The best place to put this is immediately before runTime.write();


Code:
volVectorField myName
(
      U
);
runTime.write();
Now, just before the fields are written, your myName field is set equal to the current U.


The reason U works is because there is more to a solver than createFields.H. There is a pEqn.H and UEqn.H where all the magic of foam happens and you calculate a new U. createFields only establishes whether a field is writable and initializes it. It doesn't do anything else. The fields are written when runTime.write() is called. The values of each field when runTime.write() is called is what gets written.


Also instead of using IOobject::MUST_READ you can probably use the NO_READ option since there's never any point to reading the myName field from the disk. It's always equal to U isn't it?
vivek05 and ALBATTROSS like this.
LuckyTran is offline   Reply With Quote

Old   November 22, 2018, 17:36
Default
  #4
New Member
 
Aria
Join Date: Jul 2018
Posts: 2
Rep Power: 0
AriaFoam89 is on a distinguished road
Quote:
Originally Posted by LuckyTran View Post
createFields is called only at startup to initialize fields to make places for them in memory.


You defined myName = U in createFields. During startup your field myName will be set equal to the current values for U (if your startTime is 0 then then myName will take on the values of U at 0). If you do nothing else, the field myName never gets updated again ever and stays at the initial values.


You need to go into your mybuoyantBoussinesqPimpleFoam.c and add a line that looks like this. The best place to put this is immediately before runTime.write();


Code:
volVectorField myName
(
      U
);
runTime.write();
Now, just before the fields are written, your myName field is set equal to the current U.


The reason U works is because there is more to a solver than createFields.H. There is a pEqn.H and UEqn.H where all the magic of foam happens and you calculate a new U. createFields only establishes whether a field is writable and initializes it. It doesn't do anything else. The fields are written when runTime.write() is called. The values of each field when runTime.write() is called is what gets written.


Also instead of using IOobject::MUST_READ you can probably use the NO_READ option since there's never any point to reading the myName field from the disk. It's always equal to U isn't it?

Hi LuckyTran,

thanks for the tips. I tried adding your suggested code in time loop before runTime.write() :
Code:
volVectorField myName
(
      U
);
however, it's the same again U=0 in each time directory. but when I added myName = U before runTime.write() it worked now openfoam is writing myName as the same as U.(there is a little difference between them)
AriaFoam89 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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with cyclic boundaries in Openfoam 1.5 fs82 OpenFOAM 36 January 7, 2015 00:31
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
Problem in sampling data of custom field function in ANSYS FLUENT v14 apek_great ANSYS 1 February 26, 2014 05:10
Surface Vector Field Problem at Parallel cwang5 OpenFOAM Bugs 6 July 12, 2010 08:31
pressure field problem. michal FLUENT 1 March 18, 2004 14:45


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