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

How do I execute solve w/in a loop over which the solved variable is changing?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 9, 2013, 15:20
Default How do I execute solve w/in a loop over which the solved variable is changing?
  #1
New Member
 
Tom Chyczewski
Join Date: Mar 2009
Location: Bethpage, New York, USA
Posts: 15
Rep Power: 17
chyczewski is on a distinguished road
I thought this would be straight forward but it is tripping me up. Any help would be appreciated.

I need to iterate a 2D (geographical space, x and y) equation for each point in wave space (say kx and ky). I thought the following would work:

Code:
for (int m=0; m<nkx; ++m)
{
   for (int n=0; n<nky; ++n)
   {
      forAll(Umn,i)
      {
         Amn[i]      = wasd[m][n][i];
         Umn[i].x() = U[i].x() + some f(m,n);
         Umn[i].y() = U[i].y() + some f(m,n);
         Umn[i].z() = 0.0;
         Smn[i]      = s[m][n][i]
      }

      phi = (fvc::interpolate(Umn) & mesh.Sf());

      solve
      (
         fvm::ddt(Amn)+fvm::div(phi,Amn) == Smn
      )

      forall(Amn,i)
      {
         wasd[m][n][i] = Amn[i];
      }
   }
}
But it seems as though the solve function is only seeing Amn as it was for the first call to solve (although I have confirmed that Amn is being changed for each m and n.)

A simplified version of this problem is
Code:
#include "fvCFD.H"
#include "fvIOoptionList.H"
#include "simpleControl.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

int main(int argc, char *argv[])
{
    #include "setRootCase.H"
    #include "createTime.H"
    #include "createMesh.H"
    #include "createFields.H"
    #include "createFvOptions.H"

    simpleControl simple(mesh);

    // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

    Info<< "\nCalculating scalar transport\n" << endl;

    #include "CourantNo.H"

    int l;

    scalar DD[64];

    for (l=0; l<64; ++l)
      {
    DD[l] = scalar(l+7);
      }

    for (l=0; l<64; ++l)
      {
    forAll(U,i)
      {
        T[i] = DD[l];
      }

    Info<<"T Before "<<T[56]<<endl;

    solve
      (
       fvm::ddt(T)
       );
    
    Info<<"T After "<<T[56]<<endl;
      }


    return 0;
}
which I adapted from scalarTransportFoam. No matter what T is before the solve (a uniform field with values varying from l=0 to 63), T after the solve is uniformly 7 (which is associated with l=0). Anyone have any ideas on how I am misinterpreting this and how to get around it? Thanks.

(Note that this post is an update to a post I made on 11/19)

Tom
chyczewski is offline   Reply With Quote

Old   December 10, 2013, 15:34
Default
  #2
ngj
Senior Member
 
Niels Gjoel Jacobsen
Join Date: Mar 2009
Location: Copenhagen, Denmark
Posts: 1,900
Rep Power: 37
ngj will become famous soon enoughngj will become famous soon enough
Hi Tom,

What you are running into is a been of underlying OpenFoam thing.

When you are calling

Code:
fvm::ddt(T)
the building of the matrix obviously requires the values of T at the previous time step for building the matrix system. For a given field, you can only update the old time values once per time step (in an automated fashion, there might be manual ways), i.e. as soon as you have constructed the matrix one time, you have to step forward in time in order to be able to reassign the values in T from the previous time step.

Another detail, which affect you, is that if the old time values do not exist, then they are set equal to T itself, so as you are initialising T with 0 in the solving, you are also initialising the previous time step to 0. And it stays zero for the remaining solutions.

You can find the details on old time fields in:

GeometricField.C

Good luck,

Niels
__________________
Please note that I do not use the Friend-feature, so do not be offended, if I do not accept a request.
ngj is offline   Reply With Quote

Old   December 17, 2013, 07:26
Default
  #3
New Member
 
Tom Chyczewski
Join Date: Mar 2009
Location: Bethpage, New York, USA
Posts: 15
Rep Power: 17
chyczewski is on a distinguished road
Niels,

Thanks for your post. It was very helpful. Looks like I have some issues to resolve.

Tom
chyczewski 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
changing scheme variable with UDF? Wagemakers FLUENT 17 September 30, 2015 14:34
About storing 'solve' data and changing data zxj160 OpenFOAM 3 August 1, 2013 13:37
Changing the unknown(target) variable in convection;From WallTemperature to HTC! fshak92 STAR-CCM+ 1 April 28, 2012 08:14
emag beta feature: charge density charlotte CFX 4 March 22, 2011 09:14
Replace periodic by inlet-outlet pair lego CFX 3 November 5, 2002 20:09


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