26#ifndef DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HELPER_HH
27#define DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HELPER_HH
48 struct HasMatrixResize
51 auto operator()(
const M& m) ->
decltype(std::declval<M>().resize(0, 0))
56 struct HasVectorResize
59 auto operator()(
const V& v) ->
decltype(std::declval<V>().resize(0))
63 template<
class Matrix>
64 static constexpr auto matrixHasResizeFunction()
65 {
return decltype(
isValid(HasMatrixResize())(std::declval<Matrix>()) )::value; }
67 template<
class Vector>
68 static constexpr auto vectorHasResizeFunction()
69 {
return decltype(
isValid(HasVectorResize())(std::declval<Vector>()) )::value; }
81 template<
class FVElementGeometry,
class DataHandle,
class IV >
86 assert(iv.numUnknowns() > 0);
90 handle.CA().rightmultiply(handle.A());
92 handle.AB().leftmultiply(handle.A());
95 using GridView =
typename IV::Traits::GridView;
96 static constexpr int dim = GridView::dimension;
97 static constexpr int dimWorld = GridView::dimensionworld;
101 auto& tijOut = handle.tijOutside();
102 tijOut.resize(iv.numFaces());
103 using LocalIndexType =
typename IV::Traits::IndexSet::LocalIndexType;
104 for (LocalIndexType fIdx = 0; fIdx < iv.numFaces(); ++fIdx)
106 const auto& curGlobalScvf = fvGeometry.scvf(iv.localScvf(fIdx).gridScvfIndex());
107 const auto numOutsideFaces = curGlobalScvf.boundary() ? 0 : curGlobalScvf.numOutsideScvs();
109 tijOut[fIdx].resize(numOutsideFaces);
110 std::for_each(tijOut[fIdx].begin(),
116 for (
const auto& localFaceData : iv.localFaceData())
119 if (!localFaceData.isOutsideFace())
122 const auto scvIdx = localFaceData.ivLocalInsideScvIndex();
123 const auto scvfIdx = localFaceData.ivLocalScvfIndex();
124 const auto idxInOut = localFaceData.scvfLocalOutsideScvfIndex();
126 const auto& wijk = handle.omegas()[scvfIdx][idxInOut+1];
127 auto& tij = tijOut[scvfIdx][idxInOut];
130 for (
unsigned int dir = 0; dir < dim; dir++)
133 const auto& scvf = iv.localScvf(iv.localScv(scvIdx).localScvfIndex(dir));
136 if (!scvf.isDirichlet())
138 auto tmp = handle.AB()[scvf.localDofIndex()];
143 tij[scvf.localDofIndex()] -= wijk[dir];
146 tij[scvIdx] += wijk[dir];
159 template<
class DataHandle,
class IV >
160 static typename IV::Traits::MatVecTraits::FaceVector
163 typename IV::Traits::MatVecTraits::FaceVector u;
166 handle.AB().mv(handle.uj(), u);
169 if (handle.deltaG().size() == iv.numUnknowns())
170 handle.A().umv(handle.deltaG(), u);
183 template<
class DataHandle,
class IV >
184 static std::vector< typename IV::Traits::LocalScvType::GlobalCoordinate >
189 using LocalScv =
typename IV::Traits::LocalScvType;
190 using Gradient =
typename LocalScv::GlobalCoordinate;
192 std::vector<Gradient> result; result.reserve(iv.numScvs());
193 for (
unsigned int scvIdx = 0; scvIdx < iv.numScvs(); ++scvIdx)
195 const auto& scv = iv.localScv(scvIdx);
198 for (
unsigned int dir = 0; dir < LocalScv::myDimension; ++dir)
200 auto nu = scv.nu(dir);
203 const auto& scvf = iv.localScvf( scv.localScvfIndex(dir) );
204 const auto faceU = !scvf.isDirichlet() ? u[scvf.localDofIndex()]
205 : handle.uj()[scvf.localDofIndex()];
207 nu *= faceU - handle.uj()[scv.localDofIndex()];
212 result.emplace_back( std::move(gradU) );
219 template<
class Matrix,
221 std::enable_if_t<matrixHasResizeFunction<Matrix>(),
int> = 0 >
224 M.resize(rows, cols);
228 template<
class Matrix,
230 std::enable_if_t<!matrixHasResizeFunction<Matrix>(),
int> = 0 >
235 template<
class Vector,
237 std::enable_if_t<vectorHasResizeFunction<Vector>(),
int> = 0 >
244 template<
class Vector,
246 std::enable_if_t<!vectorHasResizeFunction<Vector>(),
int> = 0 >
A helper function for class member function introspection.
Dune::DynamicMatrix< Scalar > multiplyMatrices(const Dune::DynamicMatrix< Scalar > &M1, const Dune::DynamicMatrix< Scalar > &M2)
Multiply two dynamic matrices.
Definition: math.hh:734
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:93
A class that contains helper functions as well as functionality which is common to different mpfa sch...
Definition: localassemblerhelper.hh:46
static void resizeVector(Vector &v, size_type rows)
resizes a vector to the given size (specialization for static vector type - do nothing)
Definition: localassemblerhelper.hh:247
static void solveLocalSystem(const FVElementGeometry &fvGeometry, DataHandle &handle, IV &iv)
Solves a previously assembled iv-local system of equations and stores the resulting transmissibilitie...
Definition: localassemblerhelper.hh:82
static std::vector< typename IV::Traits::LocalScvType::GlobalCoordinate > assembleScvGradients(const DataHandle &handle, const IV &iv)
Assembles the solution gradients in the sub-control volumes within an interaction volume.
Definition: localassemblerhelper.hh:185
static void resizeMatrix(Matrix &M, size_type rows, size_type cols)
resizes a matrix to the given sizes (specialization for dynamic matrix type)
Definition: localassemblerhelper.hh:222
static void resizeVector(Vector &v, size_type size)
resizes a vector to the given size (specialization for dynamic matrix type)
Definition: localassemblerhelper.hh:238
static IV::Traits::MatVecTraits::FaceVector assembleFaceUnkowns(const DataHandle &handle, const IV &iv)
Assembles the vector of face unknowns within an interaction volume.
Definition: localassemblerhelper.hh:161