33 #ifndef __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__OBSTACLE_CONSTRAINT_INTERFACE_IMPL__
34 #define __H__UG__LIB_ALGEBRA__OPERATOR__PRECONDITIONER__PROJECTED_GAUSS_SEIDEL__OBSTACLE_CONSTRAINT_INTERFACE_IMPL__
45 template <
typename TDomain,
typename TAlgebra>
49 if(m_spDomain.invalid())
50 UG_THROW(
"No domain set in 'IObstacleConstraint::init' \n");
53 UG_THROW(
"DofDistribution not set in 'IObstacleConstraint'.");
56 init_obstacle_dofs_with_values(1.0);
58 UG_LOG(
"In IObstacleConstraint::init: "<<m_mObstacleValues.size()<<
" obstacleDoFs tagged \n");
62 template <
typename TDomain,
typename TAlgebra>
69 template <
typename TDomain,
typename TAlgebra>
76 template <
typename TDomain,
typename TAlgebra>
83 template <
typename TDomain,
typename TAlgebra>
90 template <
typename TDomain,
typename TAlgebra>
97 template <
typename TDomain,
typename TAlgebra>
99 add(
number value,
const char*
function,
const char* subsets)
101 m_vConstNumberData.push_back(
ConstNumberData(value,
function, subsets));
104 template <
typename TDomain,
typename TAlgebra>
111 template <
typename TDomain,
typename TAlgebra>
119 template <
typename TDomain,
typename TAlgebra>
121 add(
const char*
name,
const char*
function)
135 if(LuaUserData<MathVector<dim>,
dim>::check_callback_returns(
name)){
144 UG_THROW(
"IObstacleConstraint::add: Lua-Callback with name '"<<
name<<
145 "' does not exist.");
148 UG_THROW(
"IObstacleConstraint::add: Cannot find matching callback "
149 "signature. Use one of:\n"
150 "a) Number - Callback\n"
152 "b) Conditional Number - Callback\n"
154 "c) "<<
dim<<
"d Vector - Callback\n"
155 << (LuaUserData<MathVector<dim>,
dim>::signature()));
158 template <
typename TDomain,
typename TAlgebra>
160 add(
const char*
name,
const char*
function,
const char* subsets)
165 add(sp,
function, subsets);
171 add(sp,
function, subsets);
174 if(LuaUserData<MathVector<dim>,
dim>::check_callback_returns(
name)){
177 add(sp,
function, subsets);
183 UG_THROW(
"IObstacleConstraint::add: Lua-Callback with name '"<<
name<<
184 "' does not exist.");
187 UG_THROW(
"IObstacleConstraint::add: Cannot find matching callback "
188 "signature. Use one of:\n"
189 "a) Number - Callback\n"
191 "b) Conditional Number - Callback\n"
193 "c) "<<
dim<<
"d Vector - Callback\n"
194 << (LuaUserData<MathVector<dim>,
dim>::signature()));
199 template <
typename TDomain,
typename TAlgebra>
203 m_vCondNumberData.clear();
204 m_vNumberData.clear();
205 m_vConstNumberData.clear();
206 m_vVectorData.clear();
208 m_mObstacleValues.clear();
209 m_vActiveDofs.clear();
212 template <
typename TDomain,
typename TAlgebra>
218 if(functionGroup.
size() != numFct)
219 UG_THROW(
"IObstacleConstraint:extract_data:"
220 " Only "<<numFct<<
" function(s) allowed in specification of a"
221 " Obstacle Value, but the following functions given:"
228 for(
size_t si = 0; si < subsetGroup.
size(); ++si)
231 const int subsetIndex = subsetGroup[si];
234 if(subsetIndex < 0 || subsetIndex >= pSH->num_subsets())
235 UG_THROW(
"IObstacleConstraint:extract_data:"
236 " Invalid Subset Index " << subsetIndex <<
". (Valid is"
237 " 0, .. , " << pSH->num_subsets() <<
").");
240 for(
size_t i=0; i < functionGroup.
size(); ++i)
242 const size_t fct = functionGroup[i];
245 if(fct >= m_spDD->num_fct())
246 UG_THROW(
"IObstacleConstraint:extract_data:"
247 " Function "<< fct <<
" does not exist in pattern.");
250 if(!m_spDD->is_def_in_subset(fct, subsetIndex))
251 UG_THROW(
"IObstacleConstraint:extract_data:"
252 " Function "<<fct<<
" not defined on subset "<<subsetIndex);
259 template <
typename TDomain,
typename TAlgebra>
260 template <
typename TUserData,
typename TScheduledUserData>
262 extract_data(std::map<
int, std::vector<TUserData*> >& mvUserDataObsSegment,
263 std::vector<TScheduledUserData>& vUserData)
266 mvUserDataObsSegment.clear();
268 for(
size_t i = 0; i < vUserData.size(); ++i)
271 if (vUserData[i].bWholeDomain ==
false){
273 vUserData[i].ssGrp = m_spDD->subset_grp_by_name(vUserData[i].ssName.c_str());
275 " all contained in DoFDistribution.");
280 vUserData[i].ssGrp = ssGrp;
285 fctGrp = m_spDD->fct_grp_by_name(vUserData[i].fctName.c_str());
287 " all contained in DoFDistribution.");
290 check_functions_and_subsets(fctGrp, vUserData[i].ssGrp, TUserData::numFct);
293 if(fctGrp.
size() != TUserData::numFct)
294 UG_THROW(
"IObstacleConstraint: wrong number of fct");
296 for(
size_t fct = 0; fct < TUserData::numFct; ++fct)
298 vUserData[i].fct[fct] = fctGrp[fct];
302 for(
size_t si = 0; si < vUserData[i].ssGrp.size(); ++si)
305 const int subsetIndex = vUserData[i].ssGrp[si];
308 mvUserDataObsSegment[subsetIndex].push_back(&vUserData[i]);
313 template <
typename TDomain,
typename TAlgebra>
317 extract_data(m_mNumberObsSegment, m_vNumberData);
318 extract_data(m_mCondNumberObsSegment, m_vCondNumberData);
319 extract_data(m_mConstNumberObsSegment, m_vConstNumberData);
320 extract_data(m_mVectorObsSegment, m_vVectorData);
323 template <
typename TDomain,
typename TAlgebra>
330 m_mObstacleValues.clear();
331 m_vObsSubsets.resize(0);
333 init_obstacle_dofs_with_values<CondNumberData>(m_mCondNumberObsSegment, time);
334 init_obstacle_dofs_with_values<NumberData>(m_mNumberObsSegment, time);
335 init_obstacle_dofs_with_values<ConstNumberData>(m_mConstNumberObsSegment, time);
336 init_obstacle_dofs_with_values<VectorData>(m_mVectorObsSegment, time);
339 template <
typename TDomain,
typename TAlgebra>
340 template <
typename TUserData>
344 typename std::map<int, std::vector<TUserData*> >::const_iterator iter;
345 for(iter = mvUserData.begin(); iter != mvUserData.end(); ++iter)
348 const int si = (*iter).first;
351 m_vObsSubsets.push_back(si);
354 const std::vector<TUserData*>& vUserData = (*iter).second;
359 if(m_spDD->max_dofs(
VERTEX))
360 init_obstacle_dofs_with_values<RegularVertex, TUserData>(vUserData, si, time);
361 if(m_spDD->max_dofs(
EDGE))
362 init_obstacle_dofs_with_values<Edge, TUserData>(vUserData, si, time);
363 if(m_spDD->max_dofs(
FACE))
364 init_obstacle_dofs_with_values<Face, TUserData>(vUserData, si, time);
365 if(m_spDD->max_dofs(
VOLUME))
366 init_obstacle_dofs_with_values<Volume, TUserData>(vUserData, si, time);
368 UG_CATCH_THROW(
"IObstacleConstraint::init_obstacle_dofs_with_values:"
369 " While calling 'obstacle_value' for TUserData, aborting.");
373 template <
typename TDomain,
typename TAlgebra>
374 template <
typename TBaseElem,
typename TUserData>
379 std::vector<DoFIndex> multInd;
385 std::vector<position_type> vPos;
389 iter_type iter = m_spDD->begin<
TBaseElem>(si);
390 iter_type iterEnd = m_spDD->end<
TBaseElem>(si);
393 for( ; iter != iterEnd; iter++)
399 for(
size_t i = 0; i < vUserData.size(); ++i)
401 for(
size_t f = 0; f < TUserData::numFct; ++f)
404 const size_t fct = vUserData[i]->fct[f];
407 const LFEID& lfeID = m_spDD->local_finite_element_id(fct);
410 InnerDoFPosition<TDomain>(vPos, elem, *m_spDomain, lfeID);
413 m_spDD->inner_dof_indices(elem, fct, multInd);
416 "Mismatch: numInd="<<multInd.size()<<
", numPos="
417 <<vPos.size()<<
" on "<<elem->reference_object_id());
420 for(
size_t j = 0; j < multInd.size(); ++j)
423 if(!(*vUserData[i])(val, vPos[j], time, si))
continue;
426 m_mObstacleValues[multInd[j]] = val[f];
433 template <
typename TDomain,
typename TAlgebra>
438 if (m_mObstacleValues.find(dof) == m_mObstacleValues.end()){
return false;}
442 template <
typename TDomain,
typename TAlgebra>
448 UG_LOG(
"IObstacleConstraint<TDomain,TAlgebra>::adjust_restrictionR \n");
452 typedef typename vector<DoFIndex>::iterator iter_type;
453 iter_type dofIter = m_vActiveDofs.begin();
454 iter_type dofIterEnd = m_vActiveDofs.end();
455 for( ; dofIter != dofIterEnd; dofIter++)
457 UG_LOG(
"IObstacleConstraint<TDomain,TAlgebra>::"
458 "adjust_restrictionR::activeDof : " <<*dofIter<<
"\n");
459 SetCol(R, (*dofIter)[0], (*dofIter)[1]);
462 if (m_vActiveDofs.size() > 0)
464 UG_LOG(
"#OfActiveDofs: " <<m_vActiveDofs.size()<<
"\n");
467 UG_LOG(
"IObstacleConstraint::adjust_restrictionR() \n");
location name
Definition: checkpoint_util.lua:128
Definition: smart_pointer.h:296
Definition: smart_pointer.h:108
Definition: function_group.h:52
size_t size() const
number of functions in this group
Definition: function_group.h:116
void add(SmartPtr< UserData< number, dim, bool > > func, const char *function)
adds a lua callback (cond and non-cond)
Definition: obstacle_constraint_interface_impl.h:64
void check_functions_and_subsets(FunctionGroup &functionGroup, SubsetGroup &subsetGroup, size_t numFct) const
Definition: obstacle_constraint_interface_impl.h:214
void init_obstacle_dofs_with_values(number time)
store the obstacle value set by means of UserDatas
Definition: obstacle_constraint_interface_impl.h:325
void clear()
clear all UserData-member variables
Definition: obstacle_constraint_interface_impl.h:201
virtual void adjust_restriction(matrix_type &R, ConstSmartPtr< DoFDistribution > ddCoarse, ConstSmartPtr< DoFDistribution > ddFine, int type, number time=0.0)
sets constraints in restriction
Definition: obstacle_constraint_interface_impl.h:445
void init()
Definition: obstacle_constraint_interface_impl.h:47
void extract_data()
extract the UserDatas
Definition: obstacle_constraint_interface_impl.h:315
algebra_type::matrix_type matrix_type
Matrix type.
Definition: obstacle_constraint_interface.h:82
bool is_obs_dof(const DoFIndex &dof)
checks if a given dof is in an obstacle subset
Definition: obstacle_constraint_interface_impl.h:436
Identifier for Local Finite Elements.
Definition: local_finite_element_id.h:98
static SmartPtr< LuaUserData< TData, dim, TRet > > create(const std::string &name)
Definition: lua_user_data.h:223
provides data specified in the lua script
Definition: lua_user_data.h:96
static bool check_callback_returns(const char *callName, const bool bThrow=false)
returns true if callback has correct return values
Definition: lua_user_data_impl.h:247
static std::string signature()
returns string of required callback signature
Definition: lua_user_data_impl.h:65
Definition: multi_index.h:50
Group of subsets.
Definition: subset_group.h:51
size_t size() const
number of subsets in this group
Definition: subset_group.h:122
void add_all()
select all subsets of underlying subset handler
Definition: subset_group.cpp:133
Const iterator to traverse the surface of a multi-grid hierarchy.
Definition: surface_view.h:237
void SetCol(TSparseMatrix &A, size_t i, size_t alpha, number val=0.0)
Definition: sparsematrix_util.h:735
base_type::TBaseElem TBaseElem
#define UG_ASSERT(expr, msg)
Definition: assert.h:70
#define UG_CATCH_THROW(msg)
Definition: error.h:64
#define UG_THROW(msg)
Definition: error.h:57
#define UG_LOG(msg)
Definition: log.h:367
double number
Definition: types.h:124
function util LuaCallbackHelper create(func)
@ VOLUME
Definition: grid_base_objects.h:63
@ VERTEX
Definition: grid_base_objects.h:60
@ EDGE
Definition: grid_base_objects.h:61
@ FACE
Definition: grid_base_objects.h:62
bool CheckLuaCallbackName(const char *name)
returns true if callback exists
Definition: lua_user_data.cpp:50
function func(x, y, z, t, si)
T value_type
Definition: sparsematrix_interface.h:2
grouping for subset and conditional data
Definition: obstacle_constraint_interface.h:305
grouping for subset and conditional data
Definition: obstacle_constraint_interface.h:334
grouping for subset and non-conditional data
Definition: obstacle_constraint_interface.h:276
grouping for subset and non-conditional data
Definition: obstacle_constraint_interface.h:363