14#ifndef DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HELPER_HH
15#define DUMUX_DISCRETIZATION_CC_MPFA_LOCAL_ASSEMBLER_HELPER_HH
36 struct HasMatrixResize
39 auto operator()(
const M& m) ->
decltype(std::declval<M>().resize(0, 0))
44 struct HasVectorResize
47 auto operator()(
const V& v) ->
decltype(std::declval<V>().resize(0))
51 template<
class Matrix>
52 static constexpr auto matrixHasResizeFunction()
53 {
return decltype(
isValid(HasMatrixResize())(std::declval<Matrix>()) )::value; }
55 template<
class Vector>
56 static constexpr auto vectorHasResizeFunction()
57 {
return decltype(
isValid(HasVectorResize())(std::declval<Vector>()) )::value; }
69 template<
class FVElementGeometry,
class DataHandle,
class IV >
74 assert(iv.numUnknowns() > 0);
78 handle.CA().rightmultiply(handle.A());
80 handle.AB().leftmultiply(handle.A());
83 using GridView =
typename IV::Traits::GridView;
84 static constexpr int dim = GridView::dimension;
85 static constexpr int dimWorld = GridView::dimensionworld;
89 auto& tijOut = handle.tijOutside();
90 tijOut.resize(iv.numFaces());
91 using LocalIndexType =
typename IV::Traits::IndexSet::LocalIndexType;
92 for (LocalIndexType fIdx = 0; fIdx < iv.numFaces(); ++fIdx)
94 const auto& curGlobalScvf = fvGeometry.scvf(iv.localScvf(fIdx).gridScvfIndex());
95 const auto numOutsideFaces = curGlobalScvf.boundary() ? 0 : curGlobalScvf.numOutsideScvs();
97 tijOut[fIdx].resize(numOutsideFaces);
98 std::for_each(tijOut[fIdx].begin(),
104 for (
const auto& localFaceData : iv.localFaceData())
107 if (!localFaceData.isOutsideFace())
110 const auto scvIdx = localFaceData.ivLocalInsideScvIndex();
111 const auto scvfIdx = localFaceData.ivLocalScvfIndex();
112 const auto idxInOut = localFaceData.scvfLocalOutsideScvfIndex();
114 const auto& wijk = handle.omegas()[scvfIdx][idxInOut+1];
115 auto& tij = tijOut[scvfIdx][idxInOut];
118 for (
unsigned int dir = 0; dir < dim; dir++)
121 const auto& scvf = iv.localScvf(iv.localScv(scvIdx).localScvfIndex(dir));
124 if (!scvf.isDirichlet())
126 auto tmp = handle.AB()[scvf.localDofIndex()];
131 tij[scvf.localDofIndex()] -= wijk[dir];
134 tij[scvIdx] += wijk[dir];
147 template<
class DataHandle,
class IV >
148 static typename IV::Traits::MatVecTraits::FaceVector
151 typename IV::Traits::MatVecTraits::FaceVector u;
154 handle.AB().mv(handle.uj(), u);
157 if (handle.deltaG().size() == iv.numUnknowns())
158 handle.A().umv(handle.deltaG(), u);
171 template<
class DataHandle,
class IV >
172 static std::vector< typename IV::Traits::LocalScvType::GlobalCoordinate >
177 using LocalScv =
typename IV::Traits::LocalScvType;
178 using Gradient =
typename LocalScv::GlobalCoordinate;
180 std::vector<Gradient> result; result.reserve(iv.numScvs());
181 for (
unsigned int scvIdx = 0; scvIdx < iv.numScvs(); ++scvIdx)
183 const auto& scv = iv.localScv(scvIdx);
186 for (
unsigned int dir = 0; dir < LocalScv::myDimension; ++dir)
188 auto nu = scv.nu(dir);
191 const auto& scvf = iv.localScvf( scv.localScvfIndex(dir) );
192 const auto faceU = !scvf.isDirichlet() ? u[scvf.localDofIndex()]
193 : handle.uj()[scvf.localDofIndex()];
195 nu *= faceU - handle.uj()[scv.localDofIndex()];
200 result.emplace_back( std::move(gradU) );
207 template<
class Matrix,
209 std::enable_if_t<matrixHasResizeFunction<Matrix>(),
int> = 0 >
212 M.resize(rows, cols);
216 template<
class Matrix,
218 std::enable_if_t<!matrixHasResizeFunction<Matrix>(),
int> = 0 >
223 template<
class Vector,
225 std::enable_if_t<vectorHasResizeFunction<Vector>(),
int> = 0 >
232 template<
class Vector,
234 std::enable_if_t<!vectorHasResizeFunction<Vector>(),
int> = 0 >
A class that contains helper functions as well as functionality which is common to different mpfa sch...
Definition: localassemblerhelper.hh:34
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:235
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:70
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:173
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:210
static void resizeVector(Vector &v, size_type size)
resizes a vector to the given size (specialization for dynamic matrix type)
Definition: localassemblerhelper.hh:226
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:149
Dune::DynamicMatrix< Scalar > multiplyMatrices(const Dune::DynamicMatrix< Scalar > &M1, const Dune::DynamicMatrix< Scalar > &M2)
Multiply two dynamic matrices.
Definition: math.hh:722
constexpr auto isValid(const Expression &t)
A function that creates a test functor to do class member introspection at compile time.
Definition: isvalid.hh:81
A helper function for class member function introspection.