53template <
int WDim,
typename TElem>
57 static const int dim = WDim;
84 = ReferenceMappingProvider::get<ref_dim, dim> (roid, vCornerCoords);
91 std::vector<MathVector<ref_dim> > loc_shape_grads (TElem::NUM_VERTICES);
93 rTrialSpace.
grads (loc_shape_grads, dre.
corner (base_co));
94 VecSet (loc_base_grad, 0.0);
95 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
103 ext_grad *= 1 / locLSF.
value (0, base_co);
115 static const int dim = WDim;
127 UG_THROW (
"LevSetGFlinearExtrapolation: Illegal dimensionality.");
136template <
int WDim,
int RDim>
139 static const int dim = WDim;
168 = ReferenceMappingProvider::get<ref_dim, dim> (roid, vCornerCoords);
175 std::vector<MathVector<ref_dim> > loc_shape_grads (n_co);
177 rTrialSpace.
grads (loc_shape_grads, dre.
corner (base_co));
178 VecSet (loc_base_grad, 0.0);
179 for (
size_t co = 0; co < n_co; co++)
187 ext_grad *= 1 / locLSF.
value (0, base_co);
199 static const int dim = WDim;
219 UG_THROW (
"LevSetGFlinearExtrapolation: Illegal dimensionality.");
232template <
typename TDomain,
typename TAlgebra>
244 if (m_spLSF.invalid ())
return 1;
248 UG_THROW (
"LevSetGFsimpleExtrapolation: Hanging nodes are not supported.");
251 UG_ASSERT (g_level >= 0 && (
size_t) g_level < m_vGLData.size (),
"Grid level of the level-set function mismatch!");
255 m_pElem = pElem; m_si = si; m_vCornerCoords = vCornerCoords;
259 spLSF->indices (pElem, m_indLSF, use_hanging);
260 m_locLSF.resize (m_indLSF);
266 inside = outside = 0;
267 for (
size_t co = 0; co < m_indLSF.num_dof (); co++)
269 if (corner_inside (co))
281 m_elemCenter = vCornerCoords[0];
282 for (
size_t co = 1; co < n_co; co++)
283 m_elemCenter += vCornerCoords[co];
284 m_elemCenter /= (
number) n_co;
287 if (m_excl_ssg.size () != 0)
289 Grid::vertex_traits::secure_container corner_list;
290 m_excl_ssg.subset_handler()->grid()->associated_elements (corner_list, pElem);
291 if (corner_list.size () != n_co)
292 UG_THROW (
"LevSetGFsimpleExtrapolation: Hanging nodes are not supported. - Illegal number of vertices in an element.");
293 for (
size_t co = 0; co < n_co; co++)
294 m_co_excluded [co] = m_excl_ssg.contains (m_excl_ssg.subset_handler()->get_subset_index (corner_list [co]));
297 for (
size_t co = 0; co < max_num_corners; co++)
298 m_co_excluded [co] =
false;
306template <
typename TDomain,
typename TAlgebra>
312 const ICData & ic_data = m_vICData[fct];
315 return ic_data.
value;
318 (* ic_data.
func) (val, m_elemCenter, m_time, m_si);
328template <
typename TDomain,
typename TAlgebra>
329template <
typename TElem>
336 for (
size_t fct = 0; fct < locU.
num_all_fct (); fct++)
338 UG_THROW (
"LevSetGFlinearExtrapolation:"
339 " Hanging nodes are not currently supported for the ghost-fluid method");
344 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
345 if ((! corner_inside (co)) && (! corner_excluded (co)))
347 for (
size_t fct = 0; fct < locU.
num_all_fct (); fct++)
348 if (m_vICData[fct].Dirichlet)
351 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
353 locU.
value (fct, co) = factor * locU.
value (fct, base_co);
358 locU.
value (fct, co) = locU.
value (fct, base_co);
369template <
typename TDomain,
typename TAlgebra>
379 if (fct < 0 || fct >= m_vICData.size ())
380 UG_THROW (
"LevSetGFlinearExtrapolation: Wrong function index.");
382 bool Dirichlet = m_vICData[fct].Dirichlet;
389 for (
size_t co = 0; co < num_co; co++)
390 if ((! corner_inside (co)) && (! corner_excluded (co)))
393 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
395 u [co] = factor * u [base_co];
401 for (
size_t co = 0; co < num_co; co++)
402 if ((! corner_inside (co)) && (! corner_excluded (co)))
403 u [co] = u [base_co];
414template <
typename TDomain,
typename TAlgebra>
428 case 0: extrapolate_by_lsf_in_<0> (num_co, base_co, u, fct);
break;
429 case 1: extrapolate_by_lsf_in_<1> (num_co, base_co, u, fct);
break;
430 case 2: extrapolate_by_lsf_in_<2> (num_co, base_co, u, fct);
break;
431 case 3: extrapolate_by_lsf_in_<3> (num_co, base_co, u, fct);
break;
433 UG_THROW (
"LevSetGFlinearExtrapolation: Wrong dimensionality of the element.");
443template <
typename TDomain,
typename TAlgebra>
452 if (fct < 0 || fct >= m_vICData.size ())
453 UG_THROW (
"LevSetGFlinearExtrapolation: Wrong function index.");
455 bool Dirichlet = m_vICData[fct].Dirichlet;
458 for (
size_t co = 0; co < num_co; co++)
459 if ((! corner_inside (co)) && (! corner_excluded (co)))
461 size_t n_base_co = 0;
463 for (
size_t base_co = 0; base_co < num_co; base_co++)
464 if (corner_inside (base_co))
470 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
472 u [co] = factor * u [base_co];
476 u [co] += u [base_co];
479 UG_ASSERT (n_base_co != 0,
"LevSetGFlinearExtrapolation:"
480 "Attempt to interpolate in an element that is not cut.");
492template <
typename TDomain,
typename TAlgebra>
505 case 0: extrapolate_by_lsf_in_<0> (num_co, u, fct);
break;
506 case 1: extrapolate_by_lsf_in_<1> (num_co, u, fct);
break;
507 case 2: extrapolate_by_lsf_in_<2> (num_co, u, fct);
break;
508 case 3: extrapolate_by_lsf_in_<3> (num_co, u, fct);
break;
510 UG_THROW (
"LevSetGFlinearExtrapolation: Wrong dimensionality of the element.");
517template <
typename TDomain,
typename TAlgebra>
518template <
typename TElem>
525 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
527 for (
size_t fct = 0; fct < locD.
num_all_fct (); fct++)
528 locD.
value (fct, co) = 0;
536template <
typename TDomain,
typename TAlgebra>
537template <
typename TElem>
548 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
549 if ((! corner_inside (co)) && (! corner_excluded (co)))
554 number & a_ij = locM.
value (row_fct, base_co, col_fct, co);
555 if (m_vICData[col_fct].Dirichlet)
558 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
560 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij * factor;
563 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij;
569 for (
size_t row_co = 0; row_co < TElem::NUM_VERTICES; row_co++)
570 if (row_co != base_co)
571 for (
size_t col_co = 0; col_co < TElem::NUM_VERTICES; col_co++)
574 locM.
value (row_fct, row_co, col_fct, col_co) = 0;
584template <
typename TDomain,
typename TAlgebra>
585template <
typename TElem>
597 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
598 if ((! corner_inside (co)) && (! corner_excluded (co)))
603 number & a_ij = locM.
value (row_fct, base_co, col_fct, co);
604 if (m_vICData[col_fct].Dirichlet)
607 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
609 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij * factor;
614 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij;
620 for (
size_t row_co = 0; row_co < TElem::NUM_VERTICES; row_co++)
621 if (row_co != base_co)
624 locB.
value (row_fct, row_co) = 0;
625 for (
size_t col_co = 0; col_co < TElem::NUM_VERTICES; col_co++)
627 locM.
value (row_fct, row_co, col_fct, col_co) = 0;
640template <
typename TDomain,
typename TAlgebra>
641template <
typename TElem>
649 for (
size_t base_co = 0; base_co < TElem::NUM_VERTICES; base_co++)
650 if (corner_inside (base_co))
655 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
656 if ((! corner_inside (co)) && (! corner_excluded (co)))
661 number & a_ij = locM.
value (row_fct, base_co, col_fct, co);
662 if (m_vICData[col_fct].Dirichlet)
665 VecSubtract (r, m_vCornerCoords[co], m_vCornerCoords[base_co]);
667 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij * factor;
672 locM.
value (row_fct, base_co, col_fct, base_co) += a_ij;
679 for (
size_t row_co = 0; row_co < TElem::NUM_VERTICES; row_co++)
680 if (! corner_inside (row_co))
683 locB.
value (row_fct, row_co) = 0;
684 for (
size_t col_co = 0; col_co < TElem::NUM_VERTICES; col_co++)
686 locM.
value (row_fct, row_co, col_fct, col_co) = 0;
694template <
typename TDomain,
typename TAlgebra>
697 m_vGLData.resize (0);
698 if (! m_spLSF.valid ())
return;
700 int finest_lev = m_spLSF->grid_level().level ();
705 finest_lev = approx_space->num_levels () - 1;
706 UG_ASSERT (finest_lev >= 0,
"Wrong finest grid level!");
709 m_vGLData.resize (finest_lev + 1);
710 m_vGLData[finest_lev].lsf_on_gl = m_spLSF;
711 m_vGLData[finest_lev].inject =
SPNULL;
714 for (
int fine_lev = finest_lev; fine_lev > 0; fine_lev--)
716 int coarse_lev = fine_lev - 1;
718 GridLevel coarse_gl (coarse_lev, view_type);
723 m_vGLData[coarse_lev].inject->set_levels (coarse_gl, fine_gl);
724 m_vGLData[coarse_lev].inject->init ();
731template <
typename TDomain,
typename TAlgebra>
734 if (m_vGLData.size () < 2)
return;
735 for (
int coarse_lev = m_vGLData.size () - 2; coarse_lev >= 0; coarse_lev--)
736 m_vGLData[coarse_lev].inject->do_restrict
737 (* m_vGLData[coarse_lev].lsf_on_gl, * m_vGLData[coarse_lev + 1].lsf_on_gl);
743template <
typename TDomain,
typename TAlgebra>
753 if (m_spLSF.invalid ())
return;
759 if (level < 0 || (
size_t) level >= m_vGLData.size ())
760 UG_THROW (
"Attempt to assemble on a grid level where the LSF is undefined.");
764 std::vector<size_t> vLSFVertInd (1);
765 std::vector<size_t> vDefVertInd;
768 t_vert_iterator iter = dd->template begin<Vertex> ();
769 t_vert_iterator iterEnd = dd->template end<Vertex> ();
770 for (; iter != iterEnd; iter++)
775 if (m_excl_ssg.size () != 0 && m_excl_ssg.contains (m_excl_ssg.subset_handler()->get_subset_index (pVertex)))
779 if (spLSF->inner_algebra_indices (pVertex, vLSFVertInd) != 1)
780 UG_THROW (
"LevSetGFlinearExtrapolation: Non-scalar Level-Set Function.");
781 if (lsf_inside (
BlockRef ((* spLSF) [vLSFVertInd[0]], 0)))
786 for (
size_t dof = 0; dof < n_dofs; dof++)
787 d [vDefVertInd[dof]] = 0;
794template <
typename TDomain,
typename TAlgebra>
805 if (m_spLSF.invalid ())
return;
811 if (level < 0 || (
size_t) level >= m_vGLData.size ())
812 UG_THROW (
"LevSetGFlinearExtrapolation: Attempt to assemble on a grid level where the LSF is undefined.");
815 std::vector<size_t> vLSFVertInd (1);
816 std::vector<DoFIndex> multInd (1);
821 grid.attach_to_vertices (aBC);
822 grid.attach_to_vertices (aNumElem);
828 for (
size_t fct = 0; fct < dd->
num_fct (); fct++)
831 t_vert_iterator iter = dd->template begin<Vertex> ();
832 t_vert_iterator iterEnd = dd->template end<Vertex> ();
833 for (; iter != iterEnd; iter++)
837 aaNumElem [pVertex] = 0;
841 boost::mpl::for_each<AssembleElemList> (
SumUpNearIfOuterValues (
this, u, fct, dd, time, aaBC, aaNumElem));
855 if (m_excl_ssg.size () != 0 && m_excl_ssg.contains (si))
859 t_vert_iterator iter = dd->template begin<Vertex> (si);
860 t_vert_iterator iterEnd = dd->template end<Vertex> (si);
861 for (; iter != iterEnd; iter++)
866 if (spLSF->inner_algebra_indices (pVertex, vLSFVertInd) != 1)
867 UG_THROW (
"LevSetGFlinearExtrapolation: Non-scalar Level-Set Function.");
868 if (lsf_inside (
BlockRef ((* spLSF) [vLSFVertInd[0]], 0)))
872 UG_THROW (
"LevSetGFlinearExtrapolation: More than one DoF per vertex for a component. Not the Lagrange element?");
874 const uint nElem = aaNumElem [pVertex];
877 const number bcVal = aaBC [pVertex];
878 DoFRef (u, multInd[0]) = bcVal / nElem;
881 DoFRef (u, multInd[0]) = 0;
886 grid.detach_from_vertices (aNumElem);
887 grid.detach_from_vertices (aBC);
893template <
typename TDomain,
typename TAlgebra>
894template <
typename TElem>
917 std::vector<DoFIndex> multInd (1);
920 t_elem_iterator iterEnd = dd->template end<TElem> (si);
921 for (t_elem_iterator iter = dd->template begin<TElem> (si); iter != iterEnd; iter++)
923 TElem * pElem = *iter;
926 Vertex * vVertex [TElem::NUM_VERTICES];
928 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
929 vCornerCoords[co] = aaPos[vVertex[co] = pElem->vertex (co)];
933 (TElem::NUM_VERTICES, pElem, si, level,
false, vCornerCoords, time) != 0)
937 number vValue [TElem::NUM_VERTICES];
940 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
943 UG_THROW (
"LevSetGFlinearExtrapolation: More than one DoF per vertex for a component. Not the Lagrange element?");
944 if (corner_inside (co))
945 vValue[co] =
DoFRef (u, multInd[0]);
948 extrapolate_by_lsf (TElem::NUM_VERTICES, vValue, fct);
949 for (
size_t co = 0; co < TElem::NUM_VERTICES; co++)
950 if (! corner_inside (co))
952 aaBC[vVertex[co]] += vValue[co];
953 (aaNumElem[vVertex[co]])++;
962template <
typename TDomain,
typename TAlgebra>
972 if (m_spLSF.invalid ())
return;
978 if (level < 0 || (
size_t) level >= m_vGLData.size ())
979 UG_THROW (
"Attempt to assemble on a grid level where the LSF is undefined.");
983 std::vector<size_t> vLSFVertInd (1);
984 std::vector<size_t> vMatVertInd;
987 t_vert_iterator iter = dd->template begin<Vertex> ();
988 t_vert_iterator iterEnd = dd->template end<Vertex> ();
989 for (; iter != iterEnd; iter++)
994 if (m_excl_ssg.size () != 0 && m_excl_ssg.contains (m_excl_ssg.subset_handler()->get_subset_index (pVertex)))
998 if (spLSF->inner_algebra_indices (pVertex, vLSFVertInd) != 1)
999 UG_THROW (
"LevSetGFlinearExtrapolation: Non-scalar Level-Set Function.");
1000 if (lsf_inside (
BlockRef ((* spLSF) [vLSFVertInd[0]], 0)))
1005 for (
size_t dof = 0; dof < n_dofs; dof++)
const MathVector< dim, int > * corner() const
virtual void jacobian_transposed(MathMatrix< dim, worldDim > &JT, const MathVector< dim > &locPos) const=0
const GridLevel & grid_level() const
SmartPtr< MultiGrid > multi_grid()
size_t inner_algebra_indices(GridObject *elem, std::vector< size_t > &ind, bool bClear=true) const
size_t inner_dof_indices(GridObject *elem, size_t fct, std::vector< DoFIndex > &ind, bool bClear=true) const
bool is_def_in_subset(size_t fct, int si) const
virtual ReferenceObjectID reference_object_id() const=0
static void compute(const GridObject *elem, size_t n_co, const MathVector< dim > vCornerCoords[], size_t base_co, const LocalVector &locLSF, MathVector< dim > &ext_grad)
Definition levset_lin_extrapol_impl.h:210
Definition levset_lin_extrapol_impl.h:138
static void compute(const GridObject *elem, size_t n_co, const MathVector< dim > vCornerCoords[], size_t base_co, const LocalVector &locLSF, MathVector< dim > &ext_grad)
Definition levset_lin_extrapol_impl.h:151
static const int ref_dim
Definition levset_lin_extrapol_impl.h:140
static const int dim
Definition levset_lin_extrapol_impl.h:139
static void compute(const MathVector< dim > vCornerCoords[], size_t base_co, const LocalVector &locLSF, MathVector< dim > &ext_grad)
Definition levset_lin_extrapol_impl.h:120
Definition levset_lin_extrapol_impl.h:55
TElem elem_t
Definition levset_lin_extrapol_impl.h:56
static const int dim
Definition levset_lin_extrapol_impl.h:57
static void compute(const MathVector< dim > vCornerCoords[], size_t base_co, const LocalVector &locLSF, MathVector< dim > &ext_grad)
Definition levset_lin_extrapol_impl.h:69
static const int ref_dim
Definition levset_lin_extrapol_impl.h:58
size_t num_all_col_fct() const
size_t num_all_row_fct() const
number & value(size_t rowFct, size_t rowDoF, size_t colFct, size_t colDoF)
virtual void grads(std::vector< std::vector< grad_type > > &vvGrad, const std::vector< MathVector< dim > > &vLocPos) const=0
size_t num_all_fct() const
number & value(size_t fct, size_t dof)
size_t num_all_dof(size_t fct) const
static const DimReferenceElement< dim > & get(ReferenceObjectID roid)
MathMatrix< N, M, T >::value_type RightInverse(MathMatrix< N, M, T > &mOut, const MathMatrix< M, N, T > &m)
const NullSmartPtr SPNULL
#define UG_ASSERT(expr, msg)
void MatVecMult(vector_t_out &vOut, const matrix_t &m, const vector_t_in &v)
void VecScaleAppend(vector_t &vOut, typename vector_t::value_type s1, const vector_t &v1)
void VecSubtract(vector_t &vOut, const vector_t &v, typename vector_t::value_type s)
vector_t::value_type VecDot(const vector_t &v1, const vector_t &v2)
const number & DoFRef(const TMatrix &mat, const DoFIndex &iInd, const DoFIndex &jInd)
void SetDirichletRow(TMatrix &mat, const DoFIndex &ind)
const number & BlockRef(const number &m, size_t i)
void GetLocalVector(LocalVector &lvec, const TVector &vec)
void VecSet(vector_t &dest, number alpha, const std::vector< size_t > vIndex)