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

Creating a pointer to block solver in block preconditioner

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 15, 2021, 05:53
Default Creating a pointer to block solver in block preconditioner
  #1
Member
 
Join Date: Mar 2021
Posts: 35
Rep Power: 2
trailer is on a distinguished road
Dear Foamers,


I am trying to create a preconditioner for a block Coupled solver in foam-extend based on BlockBiCGStabSolver.


However, I am getting the following error:


Code:
error: passing ‘const Foam::BlockBiCGStabSolver<Foam::Vector<double> >’ as ‘this’ argument discards qualifiers [-fpermissive]
In my preconditioner class (.H), I have:
Code:
 autoPtr<BlockBiCGStabSolver<Type> > solverPtr_;
In the .C file this is initialized as:
Code:
    solverPtr_( 
                    new BlockBiCGStabSolver<Type>
                     (
                        "test",
                        matrix,
                        dict                     
                    )
               )
In the preconditioner class, the virtual precondition function is defined as:


Code:
template<class Type>
void Foam::BlockMyPrecon<Type>::precondition
(
    Field<Type>& x,
    const Field<Type>& b
)const
{
    solverPtr_->solve(x, b);
}
Why is this error appearing? Am I not creating the solverPtr_ correctly?


If I use a raw pointer or std::unique_ptr, I get no compilation errors and the solver works.


Note: I got it to also work with
Code:
const_cast< autoPtr<BlockBiCGStabSolver<Type> > & >( solverPtr_ )->solve(x ,b);
although I do not know if this is the best approach.

Last edited by trailer; October 15, 2021 at 07:39.
trailer is offline   Reply With Quote

Old   October 18, 2021, 03:39
Default
  #2
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 346
Blog Entries: 1
Rep Power: 10
dlahaye is on a distinguished road
Not sure.

I imagine, however, that the code that already exists gives examples on how to accomplish this.

I am happy to look further into this.

Cheers, Domenico.
dlahaye is offline   Reply With Quote

Old   October 18, 2021, 10:36
Default
  #3
Member
 
Join Date: Mar 2021
Posts: 35
Rep Power: 2
trailer is on a distinguished road
Quote:
Originally Posted by dlahaye View Post
Not sure.

I imagine, however, that the code that already exists gives examples on how to accomplish this.

I am happy to look further into this.

Cheers, Domenico.

I could not find any example of already existing implementation for creating a preconditioner from an already existing solver.

Upon closure inspection, the problem seem the be because of the virtual function for preconditioning:


Code:
        //- Execute preconditioning
        virtual void precondition
        (
            Field<Type>& x,
            const Field<Type>& b
        ) const;

This has a const at the end of the function parameters to not change anything inside the class.


However, the virtual solve function in the solvers is:
Code:
        virtual BlockSolverPerformance<Type> solve
        (
            Field<Type>& x,
            const Field<Type>& b
        );

Since the latter is missing the const keyword, the compiler gives an error upon compilation.



However, I do not understand why I was able to compile the code with a raw pointer/c++ smart pointer
trailer is offline   Reply With Quote

Old   October 18, 2021, 13:14
Default
  #4
Senior Member
 
Domenico Lahaye
Join Date: Dec 2013
Posts: 346
Blog Entries: 1
Rep Power: 10
dlahaye is on a distinguished road
For preconditioners

https://github.com/OpenFOAM/OpenFOAM...reconditioners
dlahaye 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
[blockMesh] Creating a block in a windtunnel hasse94 OpenFOAM Meshing & Mesh Conversion 3 August 16, 2021 18:01
non physical value of alpha silviliril OpenFOAM Pre-Processing 1 May 18, 2018 09:43
3D simulations OpenFoam running too low(more 1 000 000 elements) Suggestion speed up? silvai OpenFOAM Running, Solving & CFD 4 April 6, 2017 12:44
Simulations are not converging in OpenFOAM for many elements (more than 1 000 000) silvai OpenFOAM Running, Solving & CFD 6 April 3, 2017 09:33
blockMesh: block with 6 vertexes dani OpenFOAM 3 June 25, 2009 14:13


All times are GMT -4. The time now is 20:03.