2#ifndef DUNE_PDELAB_LOCALOPERATOR_DARCYCCFV_HH
3#define DUNE_PDELAB_LOCALOPERATOR_DARCYCCFV_HH
8#include<dune/geometry/referenceelements.hh>
11#include<dune/pdelab/common/geometrywrapper.hh>
12#include<dune/pdelab/common/function.hh>
13#include<dune/pdelab/localoperator/pattern.hh>
14#include<dune/pdelab/localoperator/flags.hh>
15#include<dune/pdelab/localoperator/idefault.hh>
16#include<dune/pdelab/localoperator/defaultimp.hh>
17#include<dune/pdelab/localoperator/convectiondiffusionparameter.hh>
20template<
class GV,
class V>
23 typename V::value_type>
25 using IndexSet =
typename GV::IndexSet;
30 const IndexSet& indexSet;
34 using DataType =
typename V::value_type;
37 VectorExchange (
const GV& gv_, V& c_)
38 : gv(gv_), c(c_), indexSet(gv.indexSet())
42 bool contains (
int dim,
int codim)
const
57 template<
class EntityType>
58 size_t size (EntityType& e)
const
64 template<
class MessageBuffer,
class EntityType>
65 void gather (MessageBuffer& buff,
const EntityType& e)
const
67 buff.write(c[indexSet.index(e)]);
74 template<
class MessageBuffer,
class EntityType>
75 void scatter (MessageBuffer& buff,
const EntityType& e,
size_t n)
79 c[indexSet.index(e)]=x;
90template<
typename T,
typename PL>
93 typename PL::Traits::RangeFieldType,
94 PL::Traits::GridViewType::dimension,
95 Dune::FieldVector<typename PL::Traits::RangeFieldType,PL::Traits::GridViewType::dimension> >,
96 DarcyVelocityFromHeadCCFV<T,PL> >
99 using GV =
typename PL::Traits::GridViewType;
100 using IndexSet =
typename GV::IndexSet;
101 using DF =
typename GV::Grid::ctype;
102 using RF =
typename PL::Traits::RangeFieldType;
103 using RangeType =
typename PL::Traits::RangeType;
104 enum { dim = PL::Traits::GridViewType::dimension };
105 using Element =
typename GV::Traits::template Codim<0>::Entity;
106 using IntersectionIterator =
typename GV::IntersectionIterator;
107 using Intersection =
typename IntersectionIterator::Intersection;
109 using BCType =
typename Dune::PDELab::ConvectionDiffusionBoundaryConditions::Type;
116 mutable RF determinant;
117 mutable int cachedindex;
118 typename T::Traits::RangeFieldType time;
123 std::vector<RT0Coeffs> storedcoeffs;
124 mutable std::vector<RT0RangeType> rt0vectors;
131 : t(t_), pl(pl_), cachedindex(-1), time(0), gv(pl_.getGridView()), is(gv.indexSet()), storedcoeffs(is.size(0)),
132 rt0vectors(rt0fe.localBasis().size())
138 int index = is.index(element);
141 auto geo = element.geometry();
145 auto inside_cell_center_local = ref_el.position(0,0);
146 auto inside_cell_center_global = geo.global(inside_cell_center_local);
149 auto tensor_inside = t.A(element,inside_cell_center_local);
152 typename PL::Traits::RangeType pl_inside;
153 pl.evaluate(element,inside_cell_center_local,pl_inside);
157 auto B = geo.jacobianInverseTransposed(inside_cell_center_local);
161 for (
const auto& intersection : intersections(pl.getGridView(),element))
164 vn[intersection.indexInInside()] = 0.0;
170 if (intersection.neighbor())
172 auto outside_cell = intersection.outside();
173 auto outside_cell_center_local =
referenceElement(outside_cell.geometry()).position(0,0);
174 auto outside_cell_center_global = outside_cell.geometry().global(outside_cell_center_local);
177 auto d(outside_cell_center_global);
178 d -= inside_cell_center_global;
179 auto distance = d.two_norm();
182 auto tensor_outside = t.A(outside_cell,outside_cell_center_local);
183 auto n_F = intersection.centerUnitOuterNormal();
185 tensor_inside.mv(n_F,An_F);
186 auto k_inside = n_F*An_F;
187 tensor_outside.mv(n_F,An_F);
188 auto k_outside = n_F*An_F;
189 auto k_avg = 2.0/(1.0/(k_inside+1E-30) + 1.0/(k_outside+1E-30));
192 typename PL::Traits::RangeType pl_outside;
193 pl.evaluate(outside_cell,outside_cell_center_local,pl_outside);
196 vn[intersection.indexInInside()] = k_avg*(pl_inside-pl_outside)/distance;
200 if (intersection.boundary())
203 auto d = intersection.geometry().global(face_local);
204 d -= inside_cell_center_global;
208 auto bctype = t.bctype(intersection,face_local);
211 if (bctype==Dune::PDELab::ConvectionDiffusionBoundaryConditions::Dirichlet)
213 auto iplocal_s = intersection.geometryInInside().global(face_local);
214 auto g_l = t.g(intersection.inside(),iplocal_s);
215 auto n_F = intersection.centerUnitOuterNormal();
217 tensor_inside.mv(n_F,An_F);
218 auto k_inside = n_F*An_F;
219 vn[intersection.indexInInside()] = k_inside * (pl_inside-g_l)/distance;
223 if (bctype==Dune::PDELab::ConvectionDiffusionBoundaryConditions::Neumann)
225 auto j = t.j(intersection,face_local);
226 vn[intersection.indexInInside()] = j;
231 auto vstar=intersection.centerUnitOuterNormal();
232 vstar *= vn[intersection.indexInInside()];
234 if (intersection.indexInInside()%2==0)
235 normalhat[intersection.indexInInside()/2] = -1.0;
237 normalhat[intersection.indexInInside()/2] = 1.0;
239 B.
umtv(vstar,vstarhat);
240 vstarhat *= determinant;
241 storedcoeffs[index][intersection.indexInInside()] = vstarhat*normalhat;
246 VectorExchange<GV,std::vector<RT0Coeffs> > dh(gv,storedcoeffs);
247 if (gv.grid().comm().size()>1)
252 void set_time (
typename T::Traits::RangeFieldType time_)
262 int index = is.index(e);
265 rt0fe.localBasis().evaluateFunction(x,rt0vectors);
267 for (
unsigned int i=0; i<rt0fe.localBasis().size(); i++)
268 yhat.axpy(storedcoeffs[index][i],rt0vectors[i]);
271 if (index != cachedindex)
273 B = e.geometry().jacobianTransposed(x);
284 return pl.getGridView();
Provide velocity field for liquid phase.
Definition: darcyccfv.hh:97
CommDataHandleIF describes the features of a data handle for communication in parallel runs using the...
Definition: datahandleif.hh:78
void scatter(MessageBufferImp &buff, const EntityType &e, size_t n)
unpack data from message buffer to user.
Definition: datahandleif.hh:143
bool contains(int dim, int codim) const
returns true if data for given valid codim should be communicated
Definition: datahandleif.hh:94
size_t size(const EntityType &e) const
how many objects of type DataType have to be sent for a given entity
Definition: datahandleif.hh:118
void gather(MessageBufferImp &buff, const EntityType &e) const
pack data from user to message buffer
Definition: datahandleif.hh:129
bool fixedSize(int dim, int codim) const
returns true if size of data per entity of given dim and codim is a constant
Definition: datahandleif.hh:107
void umtv(const X &x, Y &y) const
y += A^T x
Definition: densematrix.hh:419
field_type determinant(bool doPivoting=true) const
calculates the determinant of this matrix
FieldTraits< value_type >::real_type two_norm() const
two norm sqrt(sum over squared values of entries)
Definition: densevector.hh:641
vector space out of a tensor product of fields.
Definition: fvector.hh:91
IndexTypeImp IndexType
The type used for the indices.
Definition: indexidset.hh:92
leaf of a function tree
Definition: function.hh:302
Raviart-Thomas local finite elements for cubes.
Definition: raviartthomascube.hh:40
A few common exception classes.
Traits for type conversions and type information.
Implements a vector constructed from a given type representing a field and a compile-time given size.
unspecified value type referenceElement(T &&... t)
Returns a reference element for the objects t....
constexpr Interior interior
PartitionSet for the interior partition.
Definition: partitionset.hh:271
Convenience header that includes all available Raviart-Thomas local finite elements for cubes.
R RangeType
range type
Definition: function.hh:62
traits class holding the function signature, same as in local function
Definition: function.hh:183
GV::Traits::template Codim< 0 >::Entity ElementType
codim 0 entity
Definition: function.hh:119
GV GridViewType
The type of the grid view the function lives on.
Definition: function.hh:116