|
[Sponsors] |
Creating a pointer to block solver in block preconditioner |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 15, 2021, 04:53 |
Creating a pointer to block solver in block preconditioner
|
#1 |
Member
Join Date: Mar 2021
Posts: 39
Rep Power: 5 |
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] Code:
autoPtr<BlockBiCGStabSolver<Type> > solverPtr_; Code:
solverPtr_( new BlockBiCGStabSolver<Type> ( "test", matrix, dict ) ) Code:
template<class Type> void Foam::BlockMyPrecon<Type>::precondition ( Field<Type>& x, const Field<Type>& b )const { solverPtr_->solve(x, b); } 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); Last edited by trailer; October 15, 2021 at 06:39. |
|
October 18, 2021, 09:36 |
|
#3 | |
Member
Join Date: Mar 2021
Posts: 39
Rep Power: 5 |
Quote:
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 |
||
October 18, 2021, 12:14 |
|
#4 |
Senior Member
|
||
|
|
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 17:01 |
non physical value of alpha | silviliril | OpenFOAM Pre-Processing | 1 | May 18, 2018 08:43 |
3D simulations OpenFoam running too low(more 1 000 000 elements) Suggestion speed up? | silvai | OpenFOAM Running, Solving & CFD | 4 | April 6, 2017 11:44 |
Simulations are not converging in OpenFOAM for many elements (more than 1 000 000) | silvai | OpenFOAM Running, Solving & CFD | 6 | April 3, 2017 08:33 |
blockMesh: block with 6 vertexes | dani | OpenFOAM | 3 | June 25, 2009 13:13 |