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

How to define a custom value and read an update from the fvSolution file?

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 4, 2025, 11:21
Default How to define a custom value and read an update from the fvSolution file?
  #1
Senior Member
 
Klaus
Join Date: Mar 2009
Posts: 287
Rep Power: 23
klausb will become famous soon enough
I am working in some customizations involving the PCG source code. I need to be able to set and update values from the fvSolution file, solvers, p section. The code below includes the relevant code sections. The code compiles fine.


The problem is, that the value from the fvSolution file is not read, the default values are not changeing, when I set a different value in the fvSolution file.


How to read a value from fvSolution file, solvers, p section for use within PCG.C?


Code:
#include "myPCG.H"
#include "PrecisionAdaptor.H"
#include "SquareMatrix.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam
{
    defineTypeNameAndDebug(myPCG, 0);

    lduMatrix::solver::addsymMatrixConstructorToTable<myPCG>
        addmyPCGSymMatrixConstructorToTable_;
}

// * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //

Foam::myPCG::myPCG
(
    const word& fieldName,
    const lduMatrix& matrix,
    const FieldField<Field, scalar>& interfaceBouCoeffs,
    const FieldField<Field, scalar>& interfaceIntCoeffs,
    const lduInterfaceFieldPtrsList& interfaces,
    const dictionary& solverControls
)
:
    lduMatrix::solver
    (
        fieldName,
        matrix,
        interfaceBouCoeffs,
        interfaceIntCoeffs,
        interfaces,
        solverControls
    ),
    
    eigenvaluesComputed_(false),  // Correct initialization in the initializer list
    
    eigRatio_(solverControls.lookupOrDefault<scalar>("eigRatio", 1.5)) // This doesn't read the value from the fvSolution file

    
{
    // Optional: Print the values for debugging
    if ((log_ >= 2) || (lduMatrix::debug >= 2))
    {
        Info<< "Eigenvalues Parameters:" << nl
            << "    eigRatio: " << eigRatio_ << nl
            << endl;
    }
}

...
klausb is offline   Reply With Quote

Old   March 6, 2025, 07:06
Default
  #2
Member
 
Eren
Join Date: Aug 2018
Posts: 92
Rep Power: 9
ErenC is on a distinguished road
I'm not sure about the exact procedure but I can suggest you this:
Start from src/OpenFOAM/matrices/solution. You'll see the entries that solver excepts from you. You can define a new entry there and call it in your function maybe.
ErenC is offline   Reply With Quote

Old   March 7, 2025, 06:25
Default
  #3
Senior Member
 
Join Date: Apr 2020
Location: UK
Posts: 821
Rep Power: 16
Tobermory will become famous soon enough
Quote:
Originally Posted by klausb View Post

How to read a value from fvSolution file, solvers, p section for use within PCG.C?
Here's another suggestion to try. It sounds as if it is not finding the eigRatio dictionary entry ... so maybe it's looking in the wrong place? Try changing the lookupOrDefault to lookup and force an error - it will then hopefully tell you where it's looking.
Tobermory 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



All times are GMT -4. The time now is 21:37.