33 #ifndef __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FVCR__PRESSURE_SEPARATION__
34 #define __H__UG__PLUGINS__NAVIER_STOKES__INCOMPRESSIBLE__FVCR__PRESSURE_SEPARATION__
57 template<
typename TElem,
typename TPos,
int dim>
60 size_t noc=elem->num_vertices();
61 for (
size_t i=0;i<noc;i++){
62 bary+=posA[elem->vertex(i)];
67 bool multMatVec(
const std::vector<number>& avec,
const std::vector<number>& b,std::vector<number>& c,
size_t m,
size_t n){
71 for(i = 0; i < m; i = i + 1){
73 for(j = 0; j < n; j = j + 1){
74 c[i] = c[i] + avec[count] * b[j];
83 const std::vector<number>& matField,
84 const std::vector<number>& b ){
86 std::vector<std::vector<number> > P(n);
87 for(
size_t i = 0; i < n; ++i) P[i].
resize(n);
89 std::vector<number> Pvec(n*n);
90 std::vector<number> b2(n);
92 std::vector<std::vector<number> > A(n);
93 for(
size_t i = 0; i < n; ++i) A[i].
resize(n);
94 std::vector<std::vector<number> > L(n);
95 for(
size_t i = 0; i < n; ++i) L[i].
resize(n);
96 std::vector<std::vector<number> > U(n);
97 for(
size_t i = 0; i < n; ++i) U[i].
resize(n);
102 std::vector<number> z(n);
109 A[i][j]=matField[count];
122 max=std::abs(A[i][i]);
124 if (std::abs(A[k][i])>max){
126 max=std::abs(A[k][i]);
171 L[k][i]=A[k][i]/A[i][i];
173 A[k][l]=A[k][l]-L[k][i]*A[i][l];
213 bool leastSquares(std::vector<number>& x,
const std::vector<number>& mField,
const std::vector<number>& b){
216 if (mField.size()!=m*n){
217 n = mField.size()/b.size();
219 std::vector<number> tmmField(n*n);
220 std::vector<number> tmb(n);
223 for (
size_t i=0;i<n;i++){
224 for (
size_t j=i;j<n;j++){
226 for (
size_t k=0;k<m;k++){
227 z+=mField[n*k+i]*mField[n*k+j];
230 if (j!=i) tmmField[i*n+j]=z;
233 for (
size_t k=0;k<m;k++) tmb[i]+= mField[n*k+i]*b[k];
235 return solveLS(x,tmmField,tmb);
238 int bubblesort(std::vector<int>& list,std::vector<number> array){
240 int length=array.size();
242 for (i=0;i<length;i++)
244 for (i=0;i<length-1;i++){
247 for (j=i+1;j<length;j++){
253 array[mini] = array[i];
255 list[i] = list[mini];
265 template <
typename TGr
idFunction>
267 :
public StdUserData<SeparatedPressureSource<TGridFunction>, MathVector<TGridFunction::dim>, TGridFunction::dim>,
286 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object
elem_type;
297 typedef typename TGridFunction::template dim_traits<dim>::const_iterator
ElemIterator;
343 for (
int i=0;i<
dim;i++){
344 f->set_entry(i, f_x);
352 UG_THROW(
"NavierStokes: Setting source vector of dimension 2"
353 " to a Discretization for world dim " <<
dim);
356 f->set_entry(0, f_x);
357 f->set_entry(1, f_y);
365 UG_THROW(
"NavierStokes: Setting source vector of dimension 3"
366 " to a Discretization for world dim " <<
dim);
371 f->set_entry(0, f_x);
372 f->set_entry(1, f_y);
373 f->set_entry(2, f_z);
395 grid.template attach_to<Vertex>(
m_aP);
409 template <
int refDim>
426 const size_t numVertices = element->num_vertices();
443 for(
size_t i = 0; i < numVertices; ++i){
444 vVrt[i] = element->vertex(i);
445 coCoord[i] = posAcc[vVrt[i]];
448 for (
size_t i=0;i<domain_traits<dim>::MaxNumVerticesOfElem;i++)
452 crfvgeo.
update(elem, &(coCoord[0]), domain.subset_handler().get());
458 std::vector<number> shapes;
464 for (
size_t sh=0;sh<numVertices;sh++)
465 pinter +=
m_p[vVrt[sh]]*shapes[sh];
466 for (
int d=0;d<
dim;d++){
468 grad[scvf.
from()][d]-=flux;
469 grad[scvf.
to()][d]+=flux;
473 for (
size_t i=0;i<crfvgeo.
num_scv();i++){
478 (*m_imSource)(vValue,
487 for (
size_t i=0;i<nip;i++)
495 std::vector<DoFIndex> multInd;
511 for(
int si = 0; si < domain.subset_handler()->
num_subsets(); ++si){
514 for( ;iter !=iterEnd; ++iter)
517 m_u->inner_dof_indices(elem,
_P_, multInd);
522 for(
int si = 0; si < domain.subset_handler()->
num_subsets(); ++si){
525 for( ;iter !=iterEnd; ++iter)
529 const size_t numVertices = elem->num_vertices();
530 for(
size_t i = 0; i < numVertices; ++i){
531 vVrt[i] = elem->vertex(i);
532 coCoord[i] = posAcc[vVrt[i]];
534 geo.
update(elem, &(coCoord[0]), domain.subset_handler().get());
535 for(
size_t i = 0; i < numVertices; ++i){
537 m_vol[vVrt[i]]+=scvVol;
538 m_p[vVrt[i]]+=scvVol*pValue;
544 for(
int si = 0; si < domain.subset_handler()->num_subsets(); ++si){
547 for( ;iter !=iterEnd; ++iter)
550 if (pbm && pbm->
is_slave(vrt))
continue;
564 UG_THROW(
"LevelSetUserData: Need element.");
571 UG_THROW(
"LevelSetUserData: Need element.");
577 const int si = this->
subset();
580 elem, NULL, this->
template local_ips<dim>(
s),
587 const int si = this->
subset();
590 elem, NULL, this->
template local_ips<dim>(
s),
601 template <
typename TGr
idFunction>
622 typedef typename TGridFunction::template dim_traits<dim>::grid_base_object
elem_type;
633 typedef typename TGridFunction::template dim_traits<dim>::const_iterator
ElemIterator;
661 static const size_t _P_ =
dim;
679 for (
int i=0;i<
dim;i++){
680 f->set_entry(i, f_x);
688 UG_THROW(
"NavierStokes: Setting source vector of dimension 2"
689 " to a Discretization for world dim " <<
dim);
692 f->set_entry(0, f_x);
693 f->set_entry(1, f_y);
701 UG_THROW(
"NavierStokes: Setting source vector of dimension 3"
702 " to a Discretization for world dim " <<
dim);
707 f->set_entry(0, f_x);
708 f->set_entry(1, f_y);
709 f->set_entry(2, f_z);
715 void set_source(
const char* fctName)
728 m_spApproxSpace = approxSpace;
730 grid.template attach_to<elem_type>(m_aPOld);
731 grid.template attach_to<Vertex>(m_aP);
732 grid.template attach_to<Vertex>(m_aVol);
733 m_pOld.access(
grid,m_aPOld);
739 SetAttachmentValues(m_pOld, m_u->template begin<elem_type>(), m_u->template end<elem_type>(), 0);
745 template <
int refDim>
762 const size_t numVertices = element->num_vertices();
779 for(
size_t i = 0; i < numVertices; ++i){
780 vVrt[i] = element->vertex(i);
781 coCoord[i] = posAcc[vVrt[i]];
784 for (
size_t i=0;i<domain_traits<dim>::MaxNumVerticesOfElem;i++)
788 crfvgeo.
update(elem, &(coCoord[0]), domain.subset_handler().get());
794 std::vector<number> shapes;
796 for (
size_t ip=0;ip<crfvgeo.
num_scvf();ip++){
800 for (
size_t sh=0;sh<numVertices;sh++)
801 pinter += m_p[vVrt[sh]]*shapes[sh];
802 for (
int d=0;d<
dim;d++){
804 grad[scvf.
from()][d]-=flux;
805 grad[scvf.
to()][d]+=flux;
809 for (
size_t i=0;i<crfvgeo.
num_scv();i++){
814 (*m_imSource)(vValue,
823 for (
size_t i=0;i<nip;i++)
831 std::vector<DoFIndex> multInd;
847 for(
int si = 0; si < domain.subset_handler()->
num_subsets(); ++si){
849 ElemIterator iterEnd = m_u->template end<elem_type>(si);
850 for( ;iter !=iterEnd; ++iter)
853 m_u->inner_dof_indices(elem, _P_, multInd);
854 m_pOld[elem]+=
DoFRef(*m_u,multInd[0]);
858 for(
int si = 0; si < domain.subset_handler()->
num_subsets(); ++si){
860 ElemIterator iterEnd = m_u->template end<elem_type>(si);
861 for( ;iter !=iterEnd; ++iter)
864 number pValue = m_pOld[elem];
865 const size_t numVertices = elem->num_vertices();
866 for(
size_t i = 0; i < numVertices; ++i){
867 vVrt[i] = elem->vertex(i);
868 coCoord[i] = posAcc[vVrt[i]];
870 geo.
update(elem, &(coCoord[0]), domain.subset_handler().get());
871 for(
size_t i = 0; i < numVertices; ++i){
873 m_vol[vVrt[i]]+=scvVol;
874 m_p[vVrt[i]]+=scvVol*pValue;
880 for(
int si = 0; si < domain.subset_handler()->num_subsets(); ++si){
883 for( ;iter !=iterEnd; ++iter)
886 if (pbm && pbm->
is_slave(vrt))
continue;
887 m_p[vrt]/=m_vol[vrt];
893 static const size_t max_number_of_ips = 20;
898 number time,
int si)
const
900 UG_THROW(
"LevelSetUserData: Need element.");
905 number time,
int si,
const size_t nip)
const
907 UG_THROW(
"LevelSetUserData: Need element.");
913 const number t = this->time();
914 const int si = this->subset();
915 for(
size_t s = 0;
s < this->num_series(); ++
s)
916 evaluate<dim>(this->values(
s), this->ips(
s), t, si,
917 elem, NULL, this->
template local_ips<dim>(
s),
function NavierStokes(fcts, subsets, discType)
TData & value(size_t s, size_t ip)
size_t num_ip(size_t s) const
size_t num_series() const
const MathVector< worldDim > & normal() const
const MathVector< dim > & local_ip() const
const SCV & scv(size_t i) const
const SCVF & scvf(size_t i) const
void update(GridObject *elem, const MathVector< worldDim > *vCornerCoords, const ISubsetHandler *ish=NULL)
const SCV & scv(size_t i) const
void update(GridObject *elem, const MathVector< worldDim > *vCornerCoords, const ISubsetHandler *ish=NULL)
virtual ReferenceObjectID reference_object_id() const=0
const MathVector< dim > & ip(size_t s, size_t ip) const
const MathVector< dim > * ips(size_t s) const
virtual void shapes(std::vector< std::vector< shape_type > > &vvShape, const std::vector< MathVector< dim > > &vLocPos) const=0
LocalVector & solution(size_t i)
Definition: pressure_separation.h:269
TGridFunction::template dim_traits< dim >::const_iterator ElemIterator
element iterator
Definition: pressure_separation.h:297
domain_type::position_accessor_type position_accessor_type
position accessor type
Definition: pressure_separation.h:277
aElementNumber m_pOld
Definition: pressure_separation.h:305
virtual void compute(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: pressure_separation.h:574
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: pressure_separation.h:595
ANumber m_aVol
Definition: pressure_separation.h:312
SeparatedPressureSource(SmartPtr< ApproximationSpace< domain_type > > approxSpace, SmartPtr< TGridFunction > spGridFct)
constructor
Definition: pressure_separation.h:387
domain_type::grid_type grid_type
grid type
Definition: pressure_separation.h:283
virtual ~SeparatedPressureSource()
Definition: pressure_separation.h:407
PeriodicAttachmentAccessor< Vertex, ANumber > aVertexNumber
MathVector<dim> attachment.
Definition: pressure_separation.h:293
virtual void compute(LocalVectorTimeSeries *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: pressure_separation.h:584
ANumber m_aP
Definition: pressure_separation.h:308
TGridFunction::algebra_type algebra_type
algebra type
Definition: pressure_separation.h:274
TGridFunction::template traits< Vertex >::const_iterator VertexIterator
vertex iterator
Definition: pressure_separation.h:300
static const size_t max_number_of_ips
Definition: pressure_separation.h:557
SmartPtr< TGridFunction > m_u
Definition: pressure_separation.h:316
void set_source(SmartPtr< CplUserData< MathVector< dim >, dim > > data)
Definition: pressure_separation.h:335
SmartPtr< ApproximationSpace< domain_type > > m_spApproxSpace
Definition: pressure_separation.h:319
Grid::AttachmentAccessor< elem_type, ANumber > aElementNumber
Definition: pressure_separation.h:294
aVertexNumber m_vol
Definition: pressure_separation.h:313
TGridFunction::template dim_traits< dim >::grid_base_object elem_type
element type
Definition: pressure_separation.h:286
aVertexNumber m_p
Definition: pressure_separation.h:309
static const int dim
world dimension
Definition: pressure_separation.h:280
void set_source(number f_x, number f_y, number f_z)
Definition: pressure_separation.h:362
virtual bool requires_grid_fct() const
returns if grid function is needed for evaluation
Definition: pressure_separation.h:598
TGridFunction::domain_type domain_type
domain type
Definition: pressure_separation.h:271
SmartPtr< CplUserData< MathVector< dim >, dim > > m_imSource
Data import for source.
Definition: pressure_separation.h:330
void evaluate(MathVector< dim > vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Definition: pressure_separation.h:410
grid_type * m_grid
Definition: pressure_separation.h:322
void update()
Definition: pressure_separation.h:491
virtual void operator()(MathVector< dim > &value, const MathVector< dim > &globIP, number time, int si) const
Definition: pressure_separation.h:560
void set_source(number f_x)
Definition: pressure_separation.h:340
ANumber m_aPOld
Definition: pressure_separation.h:304
void set_source(number f_x, number f_y)
Definition: pressure_separation.h:349
static const size_t _P_
Definition: pressure_separation.h:325
Definition: pressure_separation.h:605
virtual bool continuous() const
returns if provided data is continuous over geometric object boundaries
Definition: pressure_separation.h:922
SmartPtr< TGridFunction > m_u
Definition: pressure_separation.h:652
Grid::AttachmentAccessor< elem_type, ANumber > aElementNumber
Definition: pressure_separation.h:630
ANumber m_aP
Definition: pressure_separation.h:644
virtual bool requires_grid_fct() const
returns if grid function is needed for evaluation
Definition: pressure_separation.h:925
aVertexNumber m_vol
Definition: pressure_separation.h:649
void set_source(number f_x, number f_y)
Definition: pressure_separation.h:685
SmartPtr< CplUserData< MathVector< dim >, dim > > m_imSource
Data import for source.
Definition: pressure_separation.h:666
TGridFunction::template traits< Vertex >::const_iterator VertexIterator
vertex iterator
Definition: pressure_separation.h:636
domain_type::grid_type grid_type
grid type
Definition: pressure_separation.h:619
void update()
Definition: pressure_separation.h:827
TGridFunction::domain_type domain_type
domain type
Definition: pressure_separation.h:607
void set_source(number f_x)
Definition: pressure_separation.h:676
virtual void compute(LocalVector *u, GridObject *elem, const MathVector< dim > vCornerCoords[], bool bDeriv=false)
Definition: pressure_separation.h:910
virtual ~SeparatedPressureSourceInter()
Definition: pressure_separation.h:743
aVertexNumber m_p
Definition: pressure_separation.h:645
void evaluate(MathVector< dim > vValue[], const MathVector< dim > vGlobIP[], number time, int si, GridObject *elem, const MathVector< dim > vCornerCoords[], const MathVector< refDim > vLocIP[], const size_t nip, LocalVector *u, const MathMatrix< refDim, dim > *vJT=NULL) const
Definition: pressure_separation.h:746
TGridFunction::algebra_type algebra_type
algebra type
Definition: pressure_separation.h:610
aElementNumber m_pOld
Definition: pressure_separation.h:641
ANumber m_aPOld
Definition: pressure_separation.h:640
TGridFunction::template dim_traits< dim >::const_iterator ElemIterator
element iterator
Definition: pressure_separation.h:633
void set_source(SmartPtr< CplUserData< MathVector< dim >, dim > > data)
Definition: pressure_separation.h:671
domain_type::position_accessor_type position_accessor_type
position accessor type
Definition: pressure_separation.h:613
grid_type * m_grid
Definition: pressure_separation.h:658
SmartPtr< ApproximationSpace< domain_type > > m_spApproxSpace
Definition: pressure_separation.h:655
TGridFunction::template dim_traits< dim >::grid_base_object elem_type
element type
Definition: pressure_separation.h:622
SeparatedPressureSourceInter(SmartPtr< ApproximationSpace< domain_type > > approxSpace, SmartPtr< TGridFunction > spGridFct)
constructor
Definition: pressure_separation.h:723
PeriodicAttachmentAccessor< Vertex, ANumber > aVertexNumber
MathVector<dim> attachment.
Definition: pressure_separation.h:629
ANumber m_aVol
Definition: pressure_separation.h:648
void set_source(number f_x, number f_y, number f_z)
Definition: pressure_separation.h:698
bool access(Grid &g, TAttachment &a)
bool is_slave(TElem *) const
Grid::VertexAttachmentAccessor< position_attachment_type > position_accessor_type
size_t num_subsets() const
void SetAttachmentValues(TAttachmentAccessor &aaVal, TIter elemsBegin, TIter elemsEnd, const TVal &val)
value_type & operator()(std::size_t row, std::size_t col)
#define UG_ASSERT(expr, msg)
bool solveLS(std::vector< number > &x, const std::vector< number > &matField, const std::vector< number > &b)
Definition: pressure_separation.h:82
int bubblesort(std::vector< int > &list, std::vector< number > array)
Definition: pressure_separation.h:238
bool multMatVec(const std::vector< number > &avec, const std::vector< number > &b, std::vector< number > &c, size_t m, size_t n)
Definition: pressure_separation.h:67
void computeElemBarycenter(MathVector< dim > &bary, TElem *elem, TPos posA)
Definition: pressure_separation.h:58
bool leastSquares(std::vector< number > &x, const std::vector< number > &mField, const std::vector< number > &b)
Definition: pressure_separation.h:213
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
bool resize(size_t newRows, size_t newCols)
geometry_traits< TElem >::const_iterator const_iterator