76
76
#include < dune/fem/space/common/restrictprolongtuple.hh>
77
77
#include < dune/fem/function/blockvectorfunction.hh>
78
78
#include < dune/fem/misc/capabilities.hh>
79
+
80
+ #if HAVE_PETSC
81
+ #include < dune/fem/operator/linear/petscoperator.hh>
79
82
#endif
83
+ #include < dune/fem/operator/linear/istloperator.hh>
84
+ #include < dune/fem/operator/linear/spoperator.hh>
85
+ #endif // endif HAVE_DUNE_FEM
80
86
81
87
#include < limits>
82
88
#include < list>
@@ -130,7 +136,66 @@ SET_TYPE_PROP(FvBaseDiscretization, DiscExtensiveQuantities, Ewoms::FvBaseExtens
130
136
// ! Calculates the gradient of any quantity given the index of a flux approximation point
131
137
SET_TYPE_PROP (FvBaseDiscretization, GradientCalculator, Ewoms::FvBaseGradientCalculator<TypeTag>);
132
138
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
134
199
SET_PROP (FvBaseDiscretization, SparseMatrixAdapter)
135
200
{
136
201
private:
@@ -141,6 +206,7 @@ private:
141
206
public:
142
207
typedef typename Ewoms::Linear::IstlSparseMatrixAdapter<Block> type;
143
208
};
209
+ #endif
144
210
145
211
// ! The maximum allowed number of timestep divisions for the
146
212
// ! Newton solver
@@ -342,13 +408,15 @@ class FvBaseDiscretization
342
408
343
409
typedef typename LocalResidual::LocalEvalBlockVector LocalEvalBlockVector;
344
410
411
+ typedef typename GET_PROP_TYPE (TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
412
+
345
413
class BlockVectorWrapper
346
414
{
347
415
protected:
348
416
SolutionVector blockVector_;
349
417
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() )
352
420
{}
353
421
354
422
SolutionVector& blockVector ()
@@ -358,14 +426,12 @@ class FvBaseDiscretization
358
426
};
359
427
360
428
#if HAVE_DUNE_FEM
361
- typedef typename GET_PROP_TYPE (TypeTag, DiscreteFunctionSpace) DiscreteFunctionSpace;
362
-
363
429
// discrete function storing solution data
364
- typedef Dune::Fem::ISTLBlockVectorDiscreteFunction<DiscreteFunctionSpace, PrimaryVariables> DiscreteFunction;
430
+ typedef typename GET_PROP_TYPE (TypeTag, DiscreteFunction) DiscreteFunction;
365
431
366
432
// 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;
369
435
370
436
// discrete function restriction and prolongation operator for adaptation
371
437
typedef Dune::Fem::RestrictProlongDefault< DiscreteFunction > DiscreteFunctionRestrictProlong;
@@ -374,7 +440,6 @@ class FvBaseDiscretization
374
440
typedef Dune::Fem::AdaptationManager<Grid, RestrictProlong > AdaptationManager;
375
441
#else
376
442
typedef BlockVectorWrapper DiscreteFunction;
377
- typedef size_t DiscreteFunctionSpace;
378
443
#endif
379
444
380
445
// copying a discretization object is not a good idea
@@ -394,14 +459,14 @@ public:
394
459
, elementMapper_(gridView_)
395
460
, vertexMapper_(gridView_)
396
461
#endif
397
- , newtonMethod_(simulator)
398
- , localLinearizer_(ThreadManager::maxThreads())
399
- , linearizer_(new Linearizer())
400
462
#if HAVE_DUNE_FEM
401
- , space_ ( simulator.vanguard().gridPart() )
463
+ , discreteFunctionSpace_ ( simulator.vanguard().gridPart() )
402
464
#else
403
- , space_ ( asImp_().numGridDof() )
465
+ , discreteFunctionSpace_ ( asImp_().numGridDof() )
404
466
#endif
467
+ , newtonMethod_(simulator)
468
+ , localLinearizer_(ThreadManager::maxThreads())
469
+ , linearizer_(new Linearizer( ))
405
470
, enableGridAdaptation_( EWOMS_GET_PARAM(TypeTag, bool , EnableGridAdaptation) )
406
471
, enableIntensiveQuantityCache_(EWOMS_GET_PARAM(TypeTag, bool , EnableIntensiveQuantityCache))
407
472
, enableStorageCache_(EWOMS_GET_PARAM(TypeTag, bool , EnableStorageCache))
@@ -426,7 +491,7 @@ public:
426
491
427
492
size_t numDof = asImp_ ().numGridDof ();
428
493
for (unsigned timeIdx = 0 ; timeIdx < historySize; ++timeIdx) {
429
- solution_[timeIdx].reset (new DiscreteFunction (" solution" , space_ ));
494
+ solution_[timeIdx].reset (new DiscreteFunction (" solution" , discreteFunctionSpace_ ));
430
495
431
496
if (storeIntensiveQuantities ()) {
432
497
intensiveQuantityCache_[timeIdx].resize (numDof);
@@ -1091,6 +1156,16 @@ public:
1091
1156
SolutionVector& solution (unsigned timeIdx)
1092
1157
{ return solution_[timeIdx]->blockVector (); }
1093
1158
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
+
1094
1169
protected:
1095
1170
/* !
1096
1171
* \copydoc solution(int) const
@@ -1508,7 +1583,7 @@ public:
1508
1583
void resetLinearizer ()
1509
1584
{
1510
1585
delete linearizer_;
1511
- linearizer_ = new Linearizer;
1586
+ linearizer_ = new Linearizer () ;
1512
1587
linearizer_->init (simulator_);
1513
1588
}
1514
1589
@@ -1742,6 +1817,11 @@ public:
1742
1817
solution (timeIdx).resize (numDof);
1743
1818
1744
1819
auxMod->applyInitial ();
1820
+
1821
+ #if DUNE_VERSION_NEWER( DUNE_FEM, 2, 7 )
1822
+ discreteFunctionSpace_.extendSize ( asImp_ ().numAuxiliaryDof () );
1823
+ #endif
1824
+
1745
1825
}
1746
1826
1747
1827
/* !
@@ -1808,6 +1888,11 @@ public:
1808
1888
const Ewoms::Timer& updateTimer () const
1809
1889
{ return updateTimer_; }
1810
1890
1891
+ #if HAVE_DUNE_FEM
1892
+ const DiscreteFunctionSpace& space () const { return discreteFunctionSpace_; }
1893
+ #endif
1894
+
1895
+
1811
1896
protected:
1812
1897
void resizeAndResetIntensiveQuantitiesCache_ ()
1813
1898
{
@@ -1878,9 +1963,18 @@ protected:
1878
1963
ElementMapper elementMapper_;
1879
1964
VertexMapper vertexMapper_;
1880
1965
1966
+ DiscreteFunctionSpace discreteFunctionSpace_;
1967
+
1881
1968
// a vector with all auxiliary equations to be considered
1882
1969
std::vector<BaseAuxiliaryModule<TypeTag>*> auxEqModules_;
1883
1970
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
+
1884
1978
NewtonMethod newtonMethod_;
1885
1979
1886
1980
Ewoms::Timer prePostProcessTimer_;
@@ -1899,15 +1993,6 @@ protected:
1899
1993
mutable IntensiveQuantitiesVector intensiveQuantityCache_[historySize];
1900
1994
mutable std::vector<bool > intensiveQuantityCacheUpToDate_[historySize];
1901
1995
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
-
1911
1996
std::list<BaseOutputModule<TypeTag>*> outputModules_;
1912
1997
1913
1998
Scalar gridTotalVolume_;
0 commit comments