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

Using fvOptions to add a momentum source

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By jherb

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 27, 2014, 08:46
Default Using fvOptions to add a momentum source
  #1
New Member
 
Wallace Green
Join Date: May 2010
Posts: 19
Rep Power: 12
wallace is on a distinguished road
… where the source term depends on the current velocity field. How can I make sure that it converges at each time-step in an unsteady simulation?

I'm using pimpleFoam and I've made a new fvOption which is similar to actuationDiskSource. I understand that it works as follows:

Essentially, the class has a public function AddSup where eqn.source() is used to set the source term, where eqn would appear to reference UEqn when the IOOptionList is created by the solver, simple-/pimpleFoam. Using eqn.psi(), the fvOption class also has access to the current velocity, and mesh_ is a reference to the mesh database provided by the base class option. So it's straightforward to make a momentum source term, which depends on the current velocity field, in my case sampled at different points.

In pimpleFoam, the UEqn is defined with == fvOptions(U) on the r.h.s., and then the solution loop is passed through. I hope I'm wrong, but from pisoFoam.C, I don't get the impression that fvOptions(U) is called again, (and addSup recalculates the source term based on the intermediate velocity field solution), during each time-step.

Perhaps this is a question on how literally to interpret the top-level solver syntax (if you haven't had the time to trace back through everything). I hope I'm not getting terminology wrong here but in

Code:
    
    3 tmp<fvVectorMatrix> UEqn
    4 (
    5     fvm::ddt(U)
    6   + fvm::div(phi, U)
    7   + turbulence->divDevReff(U)
    8  ==
    9     fvOptions(U)
   10 );
I assume that the l.h.s terms are implicitly included in the matrix, while the r.h.s is explicit. Therefore, for a velocity dependent source term in an unsteady solution, there would need to be an inner loop for each time-step to converge the source term.

Assuming I'm right so far, my next step would be to modify s-/pimpleFoam to repeat the solution loop at each step. On my first attempt (for simplicity, with simpleFoam) I'm confused by the results:

Clearly it's not as simple adding a loop,
Code:
               for (int i = 0; i < 2; i++){}
ultimately a while loop to be controlled by some measure of convergence of the calculated source term, around the following:
Code:
   59         // --- Pressure-velocity SIMPLE corrector
   60         {
   61             #include "UEqn.H"
   62             #include "pEqn.H"
   63         }
   64 
   65         turbulence->correct();
   66 
   67         runTime.write();
With no source term, I might have expected the second loop to converge immediately, but it appears to do almost as much work as the first loop (same no. of iterations, very similar initial residual).

I guess my questions are more implicit than explicit here
Basically, I'd be glad if someone "in-the-know" could confirm my understanding of the way the fvOptions are adding source terms. I'm quite confident about that part, but then I'm much less sure how they are being dealt with in the solver. As my simpleFoam loop test didn't do what I expected, I'm unsure of how to make a time-step inner loop in pimpleFoam to converge the source term.
wallace is offline   Reply With Quote

Old   June 2, 2014, 13:50
Default
  #2
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 171
Rep Power: 10
pbachant is on a distinguished road
Did you ever make any progress on this?
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   April 16, 2015, 15:20
Default momentum source term in pimpleFoam, pimpleDyMFoam
  #3
Member
 
Pruthvi
Join Date: Feb 2014
Posts: 41
Rep Power: 8
pruthvi1991 is on a distinguished road
Hell everybody,

I'm working on a similar problem, trying to implement a solver in the non-inertial frame for a flapping airfoil study. I haven't tried using fvOptions but I explicitly added the body force term on the RHS of Ueqn. However I'm not confident that my implementation is correct. Here is a thread about it.

Can you guys check it out and give your opinion on this issue?

Thanks,
Pruthvi.
pruthvi1991 is offline   Reply With Quote

Old   November 18, 2015, 05:48
Default Still issues about fvOptions...
  #4
Member
 
Peter
Join Date: Nov 2015
Location: Hamburg, Germany
Posts: 57
Rep Power: 7
potentialFoam is on a distinguished road
I would like to add a user-defined momentum source term to the Navier-Stokes equations.
The source depends on the actual flow field, it should be used in the solvers simpleFoam, pimpleFoam, ... and for OF 3.0.0 (or 2.4.0).

I suppose, a reasonable approach would be the use of a 'fvOptions'-dictionary file with the 'vectorCodedSource'-type.

Do you think, this is the best solution?
If yes, where do I find information on how to write this 'fvOptions'-file?

The OF-tutorials provide no help for this source type.
potentialFoam is offline   Reply With Quote

Old   November 18, 2015, 08:21
Default
  #5
Senior Member
 
Joachim Herb
Join Date: Sep 2010
Posts: 601
Rep Power: 18
jherb is on a distinguished road
google is your friend:
https://www.google.de/search?q=openf...term+fvOptions
http://www.sourceflux.de/blog/adding...ons-fvoptions/
http://www.sourceflux.de/blog/softwa...ign-fvoptions/
dyle likes this.
jherb is offline   Reply With Quote

Old   November 18, 2015, 10:00
Default
  #6
Member
 
Peter
Join Date: Nov 2015
Location: Hamburg, Germany
Posts: 57
Rep Power: 7
potentialFoam is on a distinguished road
Thanks for your fast answer! Unfortunately, Google had not helped me.

http://www.sourceflux.de/blog/adding...ons-fvoptions/
-> deals only with specific 'MRFSource'-option and gives no further information on a 'codedSource'-type option,

http://www.sourceflux.de/blog/softwa...ign-fvoptions/
-> is the subsequent post and deals only with the modification of a special solver.

My problem concerns still the 'vectorCodedSource'-type, especially the formulation of the 'code...'-parameters, or more exact the definition of the momentum source term.

Here is my actual 'fvOptions'-file:

Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

momentumSource
{
    type            vectorCodedSource;
    active          on;
    
    vectorCodedSourceCoeffs
    {
        fieldNames  (U); // ??

        selectionMode   cellZone; //cellSet;//cellZone; ??
        cellZone           sourceBox;

    redirectType  sourceTime; //velocitySource; //none;
    
    codeInclude
    #{

    #};
        
    codeCorrect
    #{
        Pout<< "**codeCorrect**" << endl;
    #};
    
        codeAddSup
    #{
        vectorField& USource = eqn.source();
        USource = (1 1 1); // Definition of the user-defined momentum source term
    #};
        
    codeSetValue
    #{
        Pout<< "**codeSetValue**" << endl;
    #};
        
    // Dummy entry. Make dependent on above to trigger recompilation
    code
    #{
        $codeInclude
        $codeCorrect
        $codeAddSup
        $codeSetValue
    #};
    }
    
    sourceTimeCoeffs
    {
    // Dummy entry
    }
  
}
Besides, I am wondering whether the variables
- fieldNames
- redirectType
are defined correctly.

Regards,
Peter
potentialFoam is offline   Reply With Quote

Old   November 18, 2015, 10:51
Default
  #7
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 171
Rep Power: 10
pbachant is on a distinguished road
If you're looking to add the source to the velocity field, you have the fieldNames entry correct. I'm not sure what redirectType means. The documentation is usually in the header files, but there is no explanation for that entry: https://github.com/OpenFOAM/OpenFOAM.../CodedSource.H
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   December 8, 2015, 05:22
Default Still no source term...
  #8
Member
 
Peter
Join Date: Nov 2015
Location: Hamburg, Germany
Posts: 57
Rep Power: 7
potentialFoam is on a distinguished road
Dear Foamers,

first: thanks Pete!

Unfortunately, I still cannot introduce a momentum source into OF.
And both google and the source code seem to be no help.

At first, I would be quite happy to introduce a constant momentum source like e.g. (1 1 1).

I think the
Code:
 codeAddSup{}
function inside the vectorCodedSource-type should do it.
This is my 'fvOptions'-file:
(I use OF 2.4.0 or 3.0.0.)

Code:
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    location    "system";
    object      fvOptions;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

momentumSource
{
    type            vectorCodedSource;
    active          on; // true;

    vectorCodedSourceCoeffs
    {
    fieldNames (U);

    selectionMode   cellZone;
    cellZone        sourceBox;

    redirectType    none;
//     redirectType    velocitySource;
//     redirectType    sourceTime;
//     redirectType    ramp;
    
    codeInclude
    #{

    #};
        
    codeCorrect
    #{
        Pout<< "**codeCorrect**" << endl;
    #};
    
        codeAddSup
    #{
        ....... // ### Momentum Source ###
        Pout << "***codeAddSup***" << endl;
    #};
        
    codeSetValue
    #{
        Pout<< "**codeSetValue**" << endl;
    #};
        
    // Dummy entry
    #{
//         $codeInclude
//         $codeCorrect
        $codeAddSup
//         $codeSetValue
    #};

    }
    
//     sourceTimeCoeffs
    noneCoeffs
    {
    // Dummy entry
    }
  
}
for ### Momentum Source ### I tried the following combinations:

Code:
vectorField& Usource = eqn.source();
Usource += vector(10000, 0, 0);
-> Runs, but there is no source term?!
and
Code:
volVectorField& Usource = eqn.source();
Usource = (10000 0 0);
-> error: invalid initialization of reference of type ‘Foam::volVectorField& {aka Foam::GeometricField<Foam::Vector<double>, Foam::fvPatchField, Foam::volMesh>&}’ from expression of type ‘Foam::Field<Foam::Vector<double> >’

I cannot solve this tiny nasty problem! And would be really glad for some help!
potentialFoam is offline   Reply With Quote

Old   December 8, 2015, 09:31
Default
  #9
Senior Member
 
Pete Bachant
Join Date: Jun 2012
Location: Boston, MA
Posts: 171
Rep Power: 10
pbachant is on a distinguished road
Well your second version doesn't work because you are trying to set a volVectorField& to a scalar. The first version looks like it should work. You should check that your cellZone is created properly by reading the topoSet log or inspecting in ParaView. Note that the newest version of the momentum sources in OpenFOAM use cellSets rather than cellZones. You could also try selecting all cells to make sure the source is being added.
__________________
Home | Twitter | GitHub
pbachant is offline   Reply With Quote

Old   December 9, 2015, 11:41
Default
  #10
Member
 
Peter
Join Date: Nov 2015
Location: Hamburg, Germany
Posts: 57
Rep Power: 7
potentialFoam is on a distinguished road
Thanks again, Pete!
You were right, I did a mistake in 'topoSet'. So the upper code snippet works.
Thanks a lot!
potentialFoam is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[swak4Foam] Swak4FOAM 0.2.3 / OF2.2.x installation error FerdiFuchs OpenFOAM Community Contributions 27 April 16, 2014 16:14
friction forces icoFoam ofslcm OpenFOAM 3 April 7, 2012 11:57
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 02:24
no enthalpy change across the momentum source Atit Koonsrisuk CFX 2 December 19, 2005 03:33


All times are GMT -4. The time now is 18:32.