Skip to content

Commit 1099ccb

Browse files
authored
Merge pull request #1 from andlaus/fix_fem_solver_backend
Fixes for the dune-fem linear solver backend
2 parents 063bbba + f17d818 commit 1099ccb

13 files changed

+202
-386
lines changed

ewoms/common/basicproperties.hh

-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,6 @@ NEW_PROP_TAG(GridView);
7878

7979
#if HAVE_DUNE_FEM
8080
NEW_PROP_TAG(GridPart);
81-
//! The class describing the discrete function space when dune-fem is used, otherwise it points to the stencil class
82-
NEW_PROP_TAG(DiscreteFunctionSpace);
83-
NEW_PROP_TAG(DiscreteFunction);
84-
NEW_PROP_TAG(LinearOperator);
8581
#endif
8682

8783
//! Property which tells the Vanguard how often the grid should be refined

ewoms/disc/common/fvbasediscretization.hh

+24-122
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
#include <ewoms/parallel/gridcommhandles.hh>
5151
#include <ewoms/parallel/threadmanager.hh>
5252
#include <ewoms/linear/nullborderlistmanager.hh>
53-
#include <ewoms/linear/istlsparsematrixadapter.hh>
5453
#include <ewoms/common/simulator.hh>
5554
#include <ewoms/common/alignedallocator.hh>
5655
#include <ewoms/common/timer.hh>
@@ -76,13 +75,7 @@
7675
#include <dune/fem/space/common/restrictprolongtuple.hh>
7776
#include <dune/fem/function/blockvectorfunction.hh>
7877
#include <dune/fem/misc/capabilities.hh>
79-
80-
#if HAVE_PETSC
81-
#include <dune/fem/operator/linear/petscoperator.hh>
8278
#endif
83-
#include <dune/fem/operator/linear/istloperator.hh>
84-
#include <dune/fem/operator/linear/spoperator.hh>
85-
#endif // endif HAVE_DUNE_FEM
8679

8780
#include <limits>
8881
#include <list>
@@ -136,78 +129,6 @@ SET_TYPE_PROP(FvBaseDiscretization, DiscExtensiveQuantities, Ewoms::FvBaseExtens
136129
//! Calculates the gradient of any quantity given the index of a flux approximation point
137130
SET_TYPE_PROP(FvBaseDiscretization, GradientCalculator, Ewoms::FvBaseGradientCalculator<TypeTag>);
138131

139-
//! Set the type of a global Jacobian matrix from the solution types
140-
#if HAVE_DUNE_FEM
141-
SET_PROP(FvBaseDiscretization, DiscreteFunction)
142-
{
143-
private:
144-
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
145-
typedef typename GET_PROP_TYPE(TypeTag, PrimaryVariables) PrimaryVariables;
146-
public:
147-
// discrete function storing solution data
148-
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace, PrimaryVariables> type;
149-
};
150-
#endif
151-
152-
#if USE_DUNE_FEM_SOLVERS
153-
SET_PROP(FvBaseDiscretization, SparseMatrixAdapter)
154-
{
155-
private:
156-
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
157-
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
158-
// discrete function storing solution data
159-
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace> DiscreteFunction;
160-
161-
#if USE_DUNE_FEM_PETSC_SOLVERS
162-
#warning "Using Dune-Fem PETSc solvers"
163-
typedef Dune::Fem::PetscLinearOperator< DiscreteFunction, DiscreteFunction > LinearOperator;
164-
#elif USE_DUNE_FEM_VIENNACL_SOLVERS
165-
#warning "Using Dune-Fem ViennaCL solvers"
166-
typedef Dune::Fem::SparseRowLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator;
167-
#else
168-
#warning "Using Dune-Fem ISTL solvers"
169-
typedef Dune::Fem::ISTLLinearOperator < DiscreteFunction, DiscreteFunction > LinearOperator;
170-
#endif
171-
172-
struct FemMatrixBackend : public LinearOperator
173-
{
174-
typedef LinearOperator ParentType;
175-
typedef typename LinearOperator :: MatrixType Matrix;
176-
typedef typename ParentType :: MatrixBlockType MatrixBlock;
177-
template <class Simulator>
178-
FemMatrixBackend( const Simulator& simulator )
179-
: LinearOperator("eWoms::Jacobian", simulator.model().space(), simulator.model().space() )
180-
{}
181-
182-
void commit()
183-
{
184-
this->flushAssembly();
185-
}
186-
187-
template< class LocalBlock >
188-
void addToBlock ( const size_t row, const size_t col, const LocalBlock& block )
189-
{
190-
this->addBlock( row, col, block );
191-
}
192-
193-
void clearRow( const size_t row, const Scalar diag = 1.0 ) { this->unitRow( row ); }
194-
};
195-
public:
196-
typedef FemMatrixBackend type;
197-
};
198-
#else
199-
SET_PROP(FvBaseDiscretization, SparseMatrixAdapter)
200-
{
201-
private:
202-
typedef typename GET_PROP_TYPE(TypeTag, Scalar) Scalar;
203-
enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
204-
typedef Ewoms::MatrixBlock<Scalar, numEq, numEq> Block;
205-
206-
public:
207-
typedef typename Ewoms::Linear::IstlSparseMatrixAdapter<Block> type;
208-
};
209-
#endif
210-
211132
//! The maximum allowed number of timestep divisions for the
212133
//! Newton solver
213134
SET_INT_PROP(FvBaseDiscretization, MaxTimeStepDivisions, 10);
@@ -408,15 +329,13 @@ class FvBaseDiscretization
408329

409330
typedef typename LocalResidual::LocalEvalBlockVector LocalEvalBlockVector;
410331

411-
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
412-
413332
class BlockVectorWrapper
414333
{
415334
protected:
416335
SolutionVector blockVector_;
417336
public:
418-
BlockVectorWrapper(const std::string& name OPM_UNUSED, const DiscreteFunctionSpace& space)
419-
: blockVector_(space.size())
337+
BlockVectorWrapper(const std::string& name OPM_UNUSED, const size_t size)
338+
: blockVector_(size)
420339
{}
421340

422341
SolutionVector& blockVector()
@@ -426,12 +345,14 @@ class FvBaseDiscretization
426345
};
427346

428347
#if HAVE_DUNE_FEM
348+
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
349+
429350
// discrete function storing solution data
430-
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunction) DiscreteFunction;
351+
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace, PrimaryVariables> DiscreteFunction;
431352

432353
// problem restriction and prolongation operator for adaptation
433-
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
434-
typedef typename Problem :: RestrictProlongOperator ProblemRestrictProlongOperator;
354+
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
355+
typedef typename Problem :: RestrictProlongOperator ProblemRestrictProlongOperator;
435356

436357
// discrete function restriction and prolongation operator for adaptation
437358
typedef Dune::Fem::RestrictProlongDefault< DiscreteFunction > DiscreteFunctionRestrictProlong;
@@ -440,6 +361,7 @@ class FvBaseDiscretization
440361
typedef Dune::Fem::AdaptationManager<Grid, RestrictProlong > AdaptationManager;
441362
#else
442363
typedef BlockVectorWrapper DiscreteFunction;
364+
typedef size_t DiscreteFunctionSpace;
443365
#endif
444366

445367
// copying a discretization object is not a good idea
@@ -459,14 +381,14 @@ public:
459381
, elementMapper_(gridView_)
460382
, vertexMapper_(gridView_)
461383
#endif
384+
, newtonMethod_(simulator)
385+
, localLinearizer_(ThreadManager::maxThreads())
386+
, linearizer_(new Linearizer())
462387
#if HAVE_DUNE_FEM
463-
, discreteFunctionSpace_( simulator.vanguard().gridPart() )
388+
, space_( simulator.vanguard().gridPart() )
464389
#else
465-
, discreteFunctionSpace_( asImp_().numGridDof() )
390+
, space_( asImp_().numGridDof() )
466391
#endif
467-
, newtonMethod_(simulator)
468-
, localLinearizer_(ThreadManager::maxThreads())
469-
, linearizer_(new Linearizer( ))
470392
, enableGridAdaptation_( EWOMS_GET_PARAM(TypeTag, bool, EnableGridAdaptation) )
471393
, enableIntensiveQuantityCache_(EWOMS_GET_PARAM(TypeTag, bool, EnableIntensiveQuantityCache))
472394
, enableStorageCache_(EWOMS_GET_PARAM(TypeTag, bool, EnableStorageCache))
@@ -491,7 +413,7 @@ public:
491413

492414
size_t numDof = asImp_().numGridDof();
493415
for (unsigned timeIdx = 0; timeIdx < historySize; ++timeIdx) {
494-
solution_[timeIdx].reset(new DiscreteFunction("solution", discreteFunctionSpace_));
416+
solution_[timeIdx].reset(new DiscreteFunction("solution", space_));
495417

496418
if (storeIntensiveQuantities()) {
497419
intensiveQuantityCache_[timeIdx].resize(numDof);
@@ -1156,16 +1078,6 @@ public:
11561078
SolutionVector& solution(unsigned timeIdx)
11571079
{ return solution_[timeIdx]->blockVector(); }
11581080

1159-
template <class BVector>
1160-
void communicate( BVector& x ) const
1161-
{
1162-
#if HAVE_DUNE_FEM
1163-
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace, typename BVector::block_type> DF;
1164-
DF tmpX("temp-x", discreteFunctionSpace_, x);
1165-
tmpX.communicate();
1166-
#endif
1167-
}
1168-
11691081
protected:
11701082
/*!
11711083
* \copydoc solution(int) const
@@ -1583,7 +1495,7 @@ public:
15831495
void resetLinearizer ()
15841496
{
15851497
delete linearizer_;
1586-
linearizer_ = new Linearizer();
1498+
linearizer_ = new Linearizer;
15871499
linearizer_->init(simulator_);
15881500
}
15891501

@@ -1817,11 +1729,6 @@ public:
18171729
solution(timeIdx).resize(numDof);
18181730

18191731
auxMod->applyInitial();
1820-
1821-
#if DUNE_VERSION_NEWER( DUNE_FEM, 2, 7 )
1822-
discreteFunctionSpace_.extendSize( asImp_().numAuxiliaryDof() );
1823-
#endif
1824-
18251732
}
18261733

18271734
/*!
@@ -1888,11 +1795,6 @@ public:
18881795
const Ewoms::Timer& updateTimer() const
18891796
{ return updateTimer_; }
18901797

1891-
#if HAVE_DUNE_FEM
1892-
const DiscreteFunctionSpace& space() const { return discreteFunctionSpace_; }
1893-
#endif
1894-
1895-
18961798
protected:
18971799
void resizeAndResetIntensiveQuantitiesCache_()
18981800
{
@@ -1963,18 +1865,9 @@ protected:
19631865
ElementMapper elementMapper_;
19641866
VertexMapper vertexMapper_;
19651867

1966-
DiscreteFunctionSpace discreteFunctionSpace_;
1967-
19681868
// a vector with all auxiliary equations to be considered
19691869
std::vector<BaseAuxiliaryModule<TypeTag>*> auxEqModules_;
19701870

1971-
mutable std::array< std::unique_ptr< DiscreteFunction >, historySize > solution_;
1972-
1973-
#if HAVE_DUNE_FEM
1974-
std::unique_ptr< RestrictProlong > restrictProlong_;
1975-
std::unique_ptr< AdaptationManager> adaptationManager_;
1976-
#endif
1977-
19781871
NewtonMethod newtonMethod_;
19791872

19801873
Ewoms::Timer prePostProcessTimer_;
@@ -1993,6 +1886,15 @@ protected:
19931886
mutable IntensiveQuantitiesVector intensiveQuantityCache_[historySize];
19941887
mutable std::vector<bool> intensiveQuantityCacheUpToDate_[historySize];
19951888

1889+
DiscreteFunctionSpace space_;
1890+
mutable std::array< std::unique_ptr< DiscreteFunction >, historySize > solution_;
1891+
1892+
#if HAVE_DUNE_FEM
1893+
std::unique_ptr<RestrictProlong> restrictProlong_;
1894+
std::unique_ptr<AdaptationManager> adaptationManager_;
1895+
#endif
1896+
1897+
19961898
std::list<BaseOutputModule<TypeTag>*> outputModules_;
19971899

19981900
Scalar gridTotalVolume_;

ewoms/disc/common/fvbaselinearizer.hh

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace Ewoms {
5454
template<class TypeTag>
5555
class EcfvDiscretization;
5656

57-
5857
/*!
5958
* \ingroup FiniteVolumeDiscretizations
6059
*

ewoms/disc/common/fvbaseproperties.hh

+3-12
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
#include <ewoms/common/basicproperties.hh>
3838
#include <ewoms/io/vtkprimaryvarsmodule.hh>
3939
#include <ewoms/linear/parallelbicgstabbackend.hh>
40-
#include <ewoms/linear/parallelistlbackend.hh>
41-
#include <ewoms/linear/femsolverbackend.hh>
42-
#include <ewoms/linear/amgxsolverbackend.hh>
4340

4441
BEGIN_PROPERTIES
4542

@@ -57,19 +54,10 @@ NEW_PROP_TAG(ParallelBiCGStabLinearSolver);
5754
NEW_PROP_TAG(LocalLinearizerSplice);
5855
NEW_PROP_TAG(FiniteDifferenceLocalLinearizer);
5956

60-
NEW_PROP_TAG(DiscreteFunctionSpace);
61-
6257
SET_SPLICES(FvBaseDiscretization, LinearSolverSplice, LocalLinearizerSplice);
6358

6459
//! use a parallel BiCGStab linear solver by default
65-
#if USE_AMGX_SOLVERS
66-
SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, AmgXSolverBackend);
67-
#elif USE_DUNE_FEM_SOLVERS
68-
SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, FemSolverBackend);
69-
#else
7060
SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelBiCGStabLinearSolver);
71-
//SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelIstlLinearSolver);
72-
#endif
7361

7462
//! by default, use finite differences to linearize the system of PDEs
7563
SET_TAG_PROP(FvBaseDiscretization, LocalLinearizerSplice, FiniteDifferenceLocalLinearizer);
@@ -92,6 +80,9 @@ NEW_PROP_TAG(GridView);
9280
//! The class describing the stencil of the spatial discretization
9381
NEW_PROP_TAG(Stencil);
9482

83+
//! The class describing the discrete function space when dune-fem is used, otherwise it points to the stencil class
84+
NEW_PROP_TAG(DiscreteFunctionSpace);
85+
9586
//! The type of the problem
9687
NEW_PROP_TAG(Problem);
9788
//! The type of the base class for all problems which use this model

ewoms/disc/ecfv/ecfvdiscretization.hh

-18
Original file line numberDiff line numberDiff line change
@@ -91,24 +91,6 @@ private:
9191
public:
9292
typedef Dune::Fem::FiniteVolumeSpace< FunctionSpace, GridPart, 0 > type;
9393
};
94-
#else
95-
SET_PROP(EcfvDiscretization, DiscreteFunctionSpace)
96-
{
97-
private:
98-
enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
99-
struct DiscreteFunctionSpace
100-
{
101-
static const int dimRange = numEq ;
102-
size_t numGridDofs_;
103-
size_t extension_;
104-
DiscreteFunctionSpace( const size_t numGridDofs )
105-
: numGridDofs_( numGridDofs ), extension_(0) {}
106-
void extendSize( const size_t extension ) { extension_ = extension; }
107-
size_t size() const { return dimRange * (numGridDofs_ + extension_); }
108-
};
109-
public:
110-
typedef DiscreteFunctionSpace type;
111-
};
11294
#endif
11395

11496
//! Set the border list creator for to the one of an element based

ewoms/disc/vcfv/vcfvdiscretization.hh

-18
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,6 @@ public:
101101
// Lagrange discrete function space with unknowns at the cell vertices
102102
typedef Dune::Fem::LagrangeDiscreteFunctionSpace< FunctionSpace, GridPart, 1 > type;
103103
};
104-
#else
105-
SET_PROP(VcfvDiscretization, DiscreteFunctionSpace)
106-
{
107-
private:
108-
enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
109-
struct DiscreteFunctionSpace
110-
{
111-
static const int dimRange = numEq ;
112-
size_t numGridDofs_;
113-
size_t extension_;
114-
DiscreteFunctionSpace( const size_t numGridDofs )
115-
: numGridDofs_( numGridDofs ), extension_(0) {}
116-
void extendSize( const size_t extension ) { extension_ = extension; }
117-
size_t size() const { return dimRange * (numGridDofs_ + extension_); }
118-
};
119-
public:
120-
typedef DiscreteFunctionSpace type;
121-
};
122104
#endif
123105

124106
//! Set the border list creator for vertices

0 commit comments

Comments
 (0)