Skip to content

Commit 60e877c

Browse files
author
Robert Kloefkorn
committed
[feature][solver] This adds a FemSolverBackend and the
AMGXSolverBackend and various smaller fixes to accommodate this.
1 parent 3b55853 commit 60e877c

15 files changed

+976
-40
lines changed

ewoms-prereqs.cmake

+10
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ set (ewoms_CONFIG_VAR
1313
HAVE_DUNE_ISTL
1414
HAVE_DUNE_ALUGRID
1515
HAVE_DUNE_FEM
16+
HAVE_PETSC
17+
HAVE_AMGXSOLVER
1618
HAVE_ECL_INPUT
1719
HAVE_ECL_OUTPUT
20+
HAVE_VIENNACL
21+
HAVE_OPENCL
1822
DUNE_AVOID_CAPABILITIES_IS_PARALLEL_DEPRECATION_WARNING
1923
)
2024

@@ -36,6 +40,12 @@ set (ewoms_DEPS
3640
"dune-alugrid"
3741
"dune-fem"
3842
"opm-grid"
43+
# PETSc numerical backend
44+
"PETSc"
45+
# AMGX wrapper using PETSc
46+
"AmgXSolver"
47+
# ViennaCL
48+
"ViennaCL"
3949
# valgrind client requests
4050
"Valgrind"
4151
# quadruple precision floating point calculations

ewoms/common/basicproperties.hh

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ 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);
8185
#endif
8286

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

ewoms/disc/common/fvbasediscretization.hh

+110-25
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,13 @@
7676
#include <dune/fem/space/common/restrictprolongtuple.hh>
7777
#include <dune/fem/function/blockvectorfunction.hh>
7878
#include <dune/fem/misc/capabilities.hh>
79+
80+
#if HAVE_PETSC
81+
#include <dune/fem/operator/linear/petscoperator.hh>
7982
#endif
83+
#include <dune/fem/operator/linear/istloperator.hh>
84+
#include <dune/fem/operator/linear/spoperator.hh>
85+
#endif // endif HAVE_DUNE_FEM
8086

8187
#include <limits>
8288
#include <list>
@@ -130,7 +136,66 @@ SET_TYPE_PROP(FvBaseDiscretization, DiscExtensiveQuantities, Ewoms::FvBaseExtens
130136
//! Calculates the gradient of any quantity given the index of a flux approximation point
131137
SET_TYPE_PROP(FvBaseDiscretization, GradientCalculator, Ewoms::FvBaseGradientCalculator<TypeTag>);
132138

133-
//! Set the type of a global jacobian matrix from the solution types
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
134199
SET_PROP(FvBaseDiscretization, SparseMatrixAdapter)
135200
{
136201
private:
@@ -141,6 +206,7 @@ private:
141206
public:
142207
typedef typename Ewoms::Linear::IstlSparseMatrixAdapter<Block> type;
143208
};
209+
#endif
144210

145211
//! The maximum allowed number of timestep divisions for the
146212
//! Newton solver
@@ -342,13 +408,15 @@ class FvBaseDiscretization
342408

343409
typedef typename LocalResidual::LocalEvalBlockVector LocalEvalBlockVector;
344410

411+
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
412+
345413
class BlockVectorWrapper
346414
{
347415
protected:
348416
SolutionVector blockVector_;
349417
public:
350-
BlockVectorWrapper(const std::string& name OPM_UNUSED, const size_t size)
351-
: blockVector_(size)
418+
BlockVectorWrapper(const std::string& name OPM_UNUSED, const DiscreteFunctionSpace& space)
419+
: blockVector_(space.size())
352420
{}
353421

354422
SolutionVector& blockVector()
@@ -358,14 +426,12 @@ class FvBaseDiscretization
358426
};
359427

360428
#if HAVE_DUNE_FEM
361-
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
362-
363429
// discrete function storing solution data
364-
typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace, PrimaryVariables> DiscreteFunction;
430+
typedef typename GET_PROP_TYPE(TypeTag, DiscreteFunction) DiscreteFunction;
365431

366432
// problem restriction and prolongation operator for adaptation
367-
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
368-
typedef typename Problem :: RestrictProlongOperator ProblemRestrictProlongOperator;
433+
typedef typename GET_PROP_TYPE(TypeTag, Problem) Problem;
434+
typedef typename Problem :: RestrictProlongOperator ProblemRestrictProlongOperator;
369435

370436
// discrete function restriction and prolongation operator for adaptation
371437
typedef Dune::Fem::RestrictProlongDefault< DiscreteFunction > DiscreteFunctionRestrictProlong;
@@ -374,7 +440,6 @@ class FvBaseDiscretization
374440
typedef Dune::Fem::AdaptationManager<Grid, RestrictProlong > AdaptationManager;
375441
#else
376442
typedef BlockVectorWrapper DiscreteFunction;
377-
typedef size_t DiscreteFunctionSpace;
378443
#endif
379444

380445
// copying a discretization object is not a good idea
@@ -394,14 +459,14 @@ public:
394459
, elementMapper_(gridView_)
395460
, vertexMapper_(gridView_)
396461
#endif
397-
, newtonMethod_(simulator)
398-
, localLinearizer_(ThreadManager::maxThreads())
399-
, linearizer_(new Linearizer())
400462
#if HAVE_DUNE_FEM
401-
, space_( simulator.vanguard().gridPart() )
463+
, discreteFunctionSpace_( simulator.vanguard().gridPart() )
402464
#else
403-
, space_( asImp_().numGridDof() )
465+
, discreteFunctionSpace_( asImp_().numGridDof() )
404466
#endif
467+
, newtonMethod_(simulator)
468+
, localLinearizer_(ThreadManager::maxThreads())
469+
, linearizer_(new Linearizer( ))
405470
, enableGridAdaptation_( EWOMS_GET_PARAM(TypeTag, bool, EnableGridAdaptation) )
406471
, enableIntensiveQuantityCache_(EWOMS_GET_PARAM(TypeTag, bool, EnableIntensiveQuantityCache))
407472
, enableStorageCache_(EWOMS_GET_PARAM(TypeTag, bool, EnableStorageCache))
@@ -426,7 +491,7 @@ public:
426491

427492
size_t numDof = asImp_().numGridDof();
428493
for (unsigned timeIdx = 0; timeIdx < historySize; ++timeIdx) {
429-
solution_[timeIdx].reset(new DiscreteFunction("solution", space_));
494+
solution_[timeIdx].reset(new DiscreteFunction("solution", discreteFunctionSpace_));
430495

431496
if (storeIntensiveQuantities()) {
432497
intensiveQuantityCache_[timeIdx].resize(numDof);
@@ -1091,6 +1156,16 @@ public:
10911156
SolutionVector& solution(unsigned timeIdx)
10921157
{ return solution_[timeIdx]->blockVector(); }
10931158

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+
10941169
protected:
10951170
/*!
10961171
* \copydoc solution(int) const
@@ -1508,7 +1583,7 @@ public:
15081583
void resetLinearizer ()
15091584
{
15101585
delete linearizer_;
1511-
linearizer_ = new Linearizer;
1586+
linearizer_ = new Linearizer();
15121587
linearizer_->init(simulator_);
15131588
}
15141589

@@ -1742,6 +1817,11 @@ public:
17421817
solution(timeIdx).resize(numDof);
17431818

17441819
auxMod->applyInitial();
1820+
1821+
#if DUNE_VERSION_NEWER( DUNE_FEM, 2, 7 )
1822+
discreteFunctionSpace_.extendSize( asImp_().numAuxiliaryDof() );
1823+
#endif
1824+
17451825
}
17461826

17471827
/*!
@@ -1808,6 +1888,11 @@ public:
18081888
const Ewoms::Timer& updateTimer() const
18091889
{ return updateTimer_; }
18101890

1891+
#if HAVE_DUNE_FEM
1892+
const DiscreteFunctionSpace& space() const { return discreteFunctionSpace_; }
1893+
#endif
1894+
1895+
18111896
protected:
18121897
void resizeAndResetIntensiveQuantitiesCache_()
18131898
{
@@ -1878,9 +1963,18 @@ protected:
18781963
ElementMapper elementMapper_;
18791964
VertexMapper vertexMapper_;
18801965

1966+
DiscreteFunctionSpace discreteFunctionSpace_;
1967+
18811968
// a vector with all auxiliary equations to be considered
18821969
std::vector<BaseAuxiliaryModule<TypeTag>*> auxEqModules_;
18831970

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+
18841978
NewtonMethod newtonMethod_;
18851979

18861980
Ewoms::Timer prePostProcessTimer_;
@@ -1899,15 +1993,6 @@ protected:
18991993
mutable IntensiveQuantitiesVector intensiveQuantityCache_[historySize];
19001994
mutable std::vector<bool> intensiveQuantityCacheUpToDate_[historySize];
19011995

1902-
DiscreteFunctionSpace space_;
1903-
mutable std::array< std::unique_ptr< DiscreteFunction >, historySize > solution_;
1904-
1905-
#if HAVE_DUNE_FEM
1906-
std::unique_ptr<RestrictProlong> restrictProlong_;
1907-
std::unique_ptr<AdaptationManager> adaptationManager_;
1908-
#endif
1909-
1910-
19111996
std::list<BaseOutputModule<TypeTag>*> outputModules_;
19121997

19131998
Scalar gridTotalVolume_;

ewoms/disc/common/fvbaselinearizer.hh

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

57+
5758
/*!
5859
* \ingroup FiniteVolumeDiscretizations
5960
*
@@ -95,8 +96,6 @@ class FvBaseLinearizer
9596

9697
typedef GlobalEqVector Vector;
9798

98-
typedef typename SparseMatrixAdapter::IstlMatrix IstlMatrix;
99-
10099
enum { numEq = GET_PROP_VALUE(TypeTag, NumEq) };
101100
enum { historySize = GET_PROP_VALUE(TypeTag, TimeDiscHistorySize) };
102101

@@ -229,9 +228,6 @@ public:
229228
*/
230229
void linearizeAuxiliaryEquations()
231230
{
232-
// flush possible local caches into matrix structure
233-
jacobian_->commit();
234-
235231
auto& model = model_();
236232
const auto& comm = simulator_().gridView().comm();
237233
for (unsigned auxModIdx = 0; auxModIdx < model.numAuxiliaryModules(); ++auxModIdx) {
@@ -262,6 +258,9 @@ public:
262258
if (!succeeded)
263259
throw Opm::NumericalIssue("linearization of an auxilary equation failed");
264260
}
261+
262+
// flush possible local caches into matrix structure
263+
jacobian_->commit();
265264
}
266265

267266
/*!
@@ -499,6 +498,9 @@ private:
499498
std::rethrow_exception(exceptionPtr);
500499
}
501500

501+
// flush possible local caches into matrix structure
502+
jacobian_->commit();
503+
502504
applyConstraintsToLinearization_();
503505
}
504506

ewoms/disc/common/fvbaseproperties.hh

+12-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
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>
4043

4144
BEGIN_PROPERTIES
4245

@@ -54,10 +57,19 @@ NEW_PROP_TAG(ParallelBiCGStabLinearSolver);
5457
NEW_PROP_TAG(LocalLinearizerSplice);
5558
NEW_PROP_TAG(FiniteDifferenceLocalLinearizer);
5659

60+
NEW_PROP_TAG(DiscreteFunctionSpace);
61+
5762
SET_SPLICES(FvBaseDiscretization, LinearSolverSplice, LocalLinearizerSplice);
5863

5964
//! 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
6070
SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelBiCGStabLinearSolver);
71+
//SET_TAG_PROP(FvBaseDiscretization, LinearSolverSplice, ParallelIstlLinearSolver);
72+
#endif
6173

6274
//! by default, use finite differences to linearize the system of PDEs
6375
SET_TAG_PROP(FvBaseDiscretization, LocalLinearizerSplice, FiniteDifferenceLocalLinearizer);
@@ -80,9 +92,6 @@ NEW_PROP_TAG(GridView);
8092
//! The class describing the stencil of the spatial discretization
8193
NEW_PROP_TAG(Stencil);
8294

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-
8695
//! The type of the problem
8796
NEW_PROP_TAG(Problem);
8897
//! 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,6 +91,24 @@ 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+
};
94112
#endif
95113

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

0 commit comments

Comments
 (0)