33 #ifndef __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__USER_DATA_IMPL__
34 #define __H__UG__LIB_DISC__SPATIAL_DISC__USER_DATA__USER_DATA_IMPL__
47 : m_locPosDim(-1), m_timePoint(0), m_defaultTimePoint(-1), m_si(-1)
59 local_ip_series_to_be_cleared();
63 m_pvLocIP1d.clear(); m_pvLocIP2d.clear(); m_pvLocIP3d.clear();
65 m_vTime.clear(); m_vTime.push_back(0.0);
73 const int timePointSpec,
77 if(m_locPosDim == -1) m_locPosDim = ldim;
78 else if(m_locPosDim != ldim)
79 UG_THROW(
"Local IP dimension conflict");
82 int theTimePoint = (m_defaultTimePoint >= 0)? m_defaultTimePoint : timePointSpec;
85 std::vector<const MathVector<ldim>*>& vvIP = get_local_ips(
Int2Type<ldim>());
89 if(!bMayChange && numIP != 0)
90 for(
size_t s = 0;
s < vvIP.size(); ++
s)
94 if(vvIP[
s] == vPos && m_vNumIP[
s] == numIP && m_vTimePoint[
s] == theTimePoint)
100 m_vNumIP.push_back(numIP);
101 m_vTimePoint.push_back(theTimePoint);
102 m_vMayChange.push_back(bMayChange);
110 local_ip_series_added(m_vNumIP.size() - 1);
113 return m_vNumIP.size() - 1;
124 if(seriesID >= num_series())
125 UG_THROW(
"Trying to set new ips for invalid seriesID "<<seriesID);
128 if(!m_vMayChange[seriesID])
129 UG_THROW(
"Local IP is not changable, but trying to set new ips.");
132 if(m_locPosDim == -1) m_locPosDim = ldim;
133 else if(m_locPosDim != ldim)
134 UG_THROW(
"Local IP dimension conflict");
137 std::vector<const MathVector<ldim>*>& vvIP = get_local_ips(
Int2Type<ldim>());
141 if(vvIP[seriesID] == vPos && m_vNumIP[seriesID] == numIP)
return;
144 vvIP[seriesID] = vPos;
145 m_vNumIP[seriesID] = numIP;
153 local_ips_changed(seriesID, numIP);
158 const int timePointSpec)
161 if(seriesID >= num_series())
162 UG_THROW(
"Trying to set new ips for invalid seriesID "<<seriesID);
165 if(!m_vMayChange[seriesID])
166 UG_THROW(
"Time point specification is not changable, but trying to set a new one.");
169 m_vTimePoint[seriesID] = (m_defaultTimePoint >= 0)? m_defaultTimePoint : timePointSpec;
179 if(m_locPosDim != ldim)
UG_THROW(
"Local IP dimension conflict");
181 UG_ASSERT(
s < num_series(),
"Wrong series id");
192 if(m_locPosDim != ldim)
UG_THROW(
"Local IP dimension conflict");
194 UG_ASSERT(
s < num_series(),
"Wrong series id");
203 UG_ASSERT(
s < num_series(),
"Wrong series id");
205 return m_vTimePoint[
s];
211 UG_ASSERT(
s < num_series(),
"Wrong series id:" <<
s <<
">=" << num_series());
215 if (m_vTimePoint[
s] >= 0)
216 return m_vTimePoint[
s];
223 UG_ASSERT(
s < num_series(),
"Wrong series id:" <<
s <<
">=" << num_series());
226 if ((time_spec = m_vTimePoint[
s]) >= 0)
227 return ((
size_t) time_spec) == m_timePoint;
234 UG_ASSERT(
s < num_series(),
"Wrong series id: "<<
s<<
" (numSeries: "<<num_series()<<
")");
237 if(numIP != num_ip(
s))
238 UG_THROW(
"UserData::set_global_ips: Num Local IPs is " << num_ip(
s)
239 <<
", but trying to set Num Global IPs: " << numIP <<
243 m_vvGlobPos[
s] = vPos;
249 global_ips_changed(
s, vPos, numIP);
255 UG_ASSERT(
s < num_series(),
"Wrong series id");
256 UG_ASSERT(
s < m_vvGlobPos.size(),
"Invalid index.");
264 UG_ASSERT(m_vvGlobPos[
s] != NULL,
"Global IP not set.");
271 template <
typename TData,
int dim,
typename TRet>
275 typedef std::pair<DataImport<TData,dim>*,
CallbackFct> Pair;
277 m_vCallback.push_back(Pair(obj, boost::bind(
func, obj)));
280 template <
typename TData,
int dim,
typename TRet>
284 typedef typename std::vector<std::pair<DataImport<TData,dim>*,
CallbackFct> > VecType;
285 typedef typename VecType::iterator iterator;
286 iterator iter = m_vCallback.begin();
287 while(iter != m_vCallback.end())
289 if((*iter).first == obj) iter = m_vCallback.erase(iter);
294 template <
typename TData,
int dim,
typename TRet>
298 typedef typename std::vector<std::pair<DataImport<TData,dim>*,
CallbackFct> > VecType;
299 typedef typename VecType::const_iterator iterator;
300 for(iterator iter = m_vCallback.begin(); iter != m_vCallback.end(); ++iter)
307 template <
typename TData,
int dim,
typename TRet>
311 UG_ASSERT(
s < m_vvValue.size(),
"Invalid index "<<
s);
314 template <
typename TData,
int dim,
typename TRet>
318 UG_ASSERT(ip < num_ip(
s),
"Invalid index "<<ip);
319 UG_ASSERT(ip < m_vvValue[
s].size(),
"Invalid index "<<ip);
322 template <
typename TData,
int dim,
typename TRet>
325 const size_t s = seriesID;
330 if(
s < m_vvValue.size())
331 UG_THROW(
"Decrease is not implemented. Series: "<<
s<<
332 ", currNumSeries: "<<m_vvValue.size());
335 m_vvValue.resize(
s+1);
336 m_vvBoolFlag.resize(
s+1);
339 m_vvValue[
s].resize(num_ip(
s));
340 m_vvBoolFlag[
s].resize(num_ip(
s),
true);
341 value_storage_changed(
s);
342 call_storage_callback();
345 base_type::local_ip_series_added(seriesID);
348 template <
typename TData,
int dim,
typename TRet>
354 m_vvBoolFlag.clear();
360 template <
typename TData,
int dim,
typename TRet>
364 if(newNumIP >= m_vvValue[seriesID].size())
367 m_vvValue[seriesID].resize(newNumIP);
368 m_vvBoolFlag[seriesID].resize(newNumIP,
true);
371 value_storage_changed(seriesID);
372 call_storage_callback();
383 template <
typename TData,
int dim>
386 this->m_fctGrp.set_function_pattern(fctPatt);
390 template <
typename TData,
int dim>
393 set_functions(std::string(symbFct));
396 template <
typename TData,
int dim>
402 template <
typename TData,
int dim>
409 template <
typename TData,
int dim>
414 if(spFctPatt.
invalid())
return;
417 if(m_SymbFct.size() == 1 && m_SymbFct[0].empty()) m_SymbFct.clear();
420 for(
size_t i = 0; i < m_SymbFct.size(); ++i)
422 if(m_SymbFct.empty())
423 UG_THROW(
"Error while setting functions in a DependentUserData: passed "
424 "function string lacks a "
425 "function specification at position "<<i<<
"(of "
426 <<m_SymbFct.size()-1<<
")");
429 if(m_SymbFct.empty()){
430 this->m_fctGrp.clear();
436 this->m_fctGrp.clear();
437 this->m_fctGrp.add(m_SymbFct);
438 }
UG_CATCH_THROW(
"DependentUserData: Cannot find some symbolic function "
445 }
UG_CATCH_THROW(
"DependentUserData: Cannot create Function Index Mapping.");
450 template <
typename TData,
int dim>
458 m_vvNumDoFPerFct.resize(map.
num_fct());
459 for(
size_t fct = 0; fct < m_vvNumDoFPerFct.size(); ++fct)
460 m_vvNumDoFPerFct[fct] = ind.
num_dof(map[fct]);
462 resize_deriv_array();
465 template <
typename TData,
int dim>
469 for(
size_t s = 0;
s < m_vvvvDeriv.size(); ++
s)
470 resize_deriv_array(
s);
473 template <
typename TData,
int dim>
477 m_vvvvDeriv[
s].resize(num_ip(
s));
479 for(
size_t ip = 0; ip < m_vvvvDeriv[
s].size(); ++ip)
482 m_vvvvDeriv[
s][ip].resize(m_vvNumDoFPerFct.size());
485 for(
size_t fct = 0; fct < m_vvNumDoFPerFct.size(); ++fct)
486 m_vvvvDeriv[
s][ip][fct].
resize(m_vvNumDoFPerFct[fct]);
490 template <
typename TData,
int dim>
493 for(
size_t ip = 0; ip < nip; ++ip)
494 for(
size_t fct = 0; fct < vvvDeriv[ip].size(); ++fct)
495 for(
size_t sh = 0; sh < vvvDeriv[ip][fct].size(); ++sh)
497 vvvDeriv[ip][fct][sh] = 0.0;
501 template <
typename TData,
int dim>
504 UG_ASSERT(s < this->num_series(),
"Wrong series id"<<
s);
505 UG_ASSERT(
s < m_vvvvDeriv.size(),
"Invalid index "<<
s);
506 UG_ASSERT(ip < this->num_ip(
s),
"Invalid index "<<ip);
507 UG_ASSERT(ip < m_vvvvDeriv[
s].size(),
"Invalid index "<<ip);
510 template <
typename TData,
int dim>
514 UG_ASSERT(fct < m_vvvvDeriv[
s][ip].size(),
"Invalid index.");
517 template <
typename TData,
int dim>
520 check_s_ip_fct(
s,ip,fct);
521 UG_ASSERT(dof < m_vvvvDeriv[
s][ip][fct].size(),
"Invalid index.");
524 template <
typename TData,
int dim>
528 m_vvvvDeriv.resize(seriesID+1);
531 base_type::local_ip_series_added(seriesID);
534 template <
typename TData,
int dim>
541 base_type::local_ip_series_to_be_cleared();
544 template <
typename TData,
int dim>
547 UG_ASSERT(seriesID < m_vvvvDeriv.size(),
"wrong series id.");
550 if(newNumIP >= m_vvvvDeriv[seriesID].size())
551 resize_deriv_array(seriesID);
554 base_type::local_ips_changed(seriesID, newNumIP);
Definition: smart_pointer.h:296
bool invalid() const
returns true if the pointer is invalid, false if not.
Definition: smart_pointer.h:420
void check_series(size_t s) const
checks in debug mode the correct index
Definition: user_data_impl.h:308
void register_storage_callback(DataImport< TData, dim > *obj, void(DataImport< TData, dim >::*func)())
register external callback, invoked when data storage changed
Definition: user_data_impl.h:273
void call_storage_callback() const
calls are registered external storage callbacks
Definition: user_data_impl.h:296
void check_series_ip(size_t s, size_t ip) const
checks in debug mode the correct index
Definition: user_data_impl.h:315
virtual void local_ip_series_added(const size_t seriesID)
resizes the data field, when local ip changed signaled
Definition: user_data_impl.h:323
virtual void local_ip_series_to_be_cleared()
free the data field memory and set series to zero
Definition: user_data_impl.h:349
void unregister_storage_callback(DataImport< TData, dim > *obj)
register all callbacks registered by class
Definition: user_data_impl.h:282
boost::function< void()> CallbackFct
registered callbacks
Definition: user_data.h:581
virtual void local_ips_changed(const size_t seriesID, const size_t newNumIP)
implement callback, called when local IPs changed
Definition: user_data_impl.h:361
Data import.
Definition: data_import.h:180
void resize_deriv_array()
resizes the derivative arrays for current number of ips.
Definition: user_data_impl.h:466
virtual void local_ip_series_to_be_cleared()
implement callback, invoked when local ips are cleared
Definition: user_data_impl.h:535
void extract_fct_grp()
extracts the function group
Definition: user_data_impl.h:410
virtual void local_ip_series_added(const size_t seriesID)
resizes the derivative field when local ip change is signaled
Definition: user_data_impl.h:525
void check_s_ip_fct(size_t s, size_t ip, size_t fct) const
checks in debug mode the correct usage of indices
Definition: user_data_impl.h:511
static void set_zero(std::vector< std::vector< TData > > vvvDeriv[], const size_t nip)
sets all derivative values to zero
Definition: user_data_impl.h:491
virtual void set_function_pattern(ConstSmartPtr< FunctionPattern > fctPatt)
sets the associated function pattern
Definition: user_data_impl.h:384
virtual void update_dof_sizes(const LocalIndices &ind)
resize lin defect arrays
Definition: user_data_impl.h:451
void check_s_ip_fct_dof(size_t s, size_t ip, size_t fct, size_t dof) const
checks in debug mode the correct usage of indices
Definition: user_data_impl.h:518
void check_s_ip(size_t s, size_t ip) const
checks in debug mode the correct usage of indices
Definition: user_data_impl.h:502
virtual void local_ips_changed(const size_t seriesID, const size_t newNumIP)
implement callback, called when local IPs changed
Definition: user_data_impl.h:545
void set_functions(const char *symbFct)
Definition: user_data_impl.h:391
describes a mapping between two local index sets
Definition: function_group.h:186
size_t num_fct() const
returns the number of indices that are mapped
Definition: function_group.h:195
std::vector< const MathVector< 2 > * > m_pvLocIP2d
Definition: user_data.h:460
bool at_current_time(size_t s) const
returns true iff the time point specification is equal to the current one, or not specified
Definition: user_data_impl.h:221
ICplUserData()
default constructor
Definition: user_data_impl.h:46
void check_s(size_t s) const
checks in debug mode the correct usage of indices
Definition: user_data_impl.h:253
const MathVector< ldim > * local_ips(size_t s) const
returns local ips
Definition: user_data_impl.h:176
void clear()
clear all data
Definition: user_data_impl.h:57
void set_local_ips(const size_t seriesId, const MathVector< ldim > *vPos, const size_t numIP)
sets new local ip positions for a local ip series
Definition: user_data_impl.h:119
void set_time_point(size_t timePoint)
sets the current time point
Definition: user_data.h:279
size_t time_point()
returns the current time point
Definition: user_data.h:282
std::vector< const MathVector< 1 > * > m_pvLocIP1d
local ips of dimension 1d-3d
Definition: user_data.h:459
std::vector< const MathVector< 3 > * > m_pvLocIP3d
Definition: user_data.h:461
void check_s_ip(size_t s, size_t ip) const
checks in debug mode the correct usage of indices
Definition: user_data_impl.h:260
std::vector< size_t > m_vNumIP
number of evaluation points (-1 indicates no ips set)
Definition: user_data.h:453
std::vector< number > m_vTime
time for evaluation
Definition: user_data.h:470
size_t register_local_ip_series(const MathVector< ldim > *vPos, const size_t numIP, const int timePointSpec, bool bMayChange=true)
set local positions, returns series id
Definition: user_data_impl.h:71
int m_locPosDim
dimension of local position (-1 indicates no dim set)
Definition: user_data.h:456
void set_global_ips(size_t s, const MathVector< dim > *vPos, size_t numIP)
set global positions
Definition: user_data_impl.h:232
int time_point_specification(size_t s) const
returns the time point specification (note: it may be -1, i.e. not specified)
Definition: user_data_impl.h:201
const MathVector< ldim > & local_ip(size_t s, size_t ip) const
returns local ip
Definition: user_data_impl.h:189
std::vector< bool > m_vMayChange
flags if local ips may change
Definition: user_data.h:450
Definition: local_algebra.h:50
size_t num_dof(size_t fct) const
number of dofs for accessible function
Definition: local_algebra.h:117
a mathematical Vector with N entries.
Definition: math_vector.h:97
#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
void TokenizeTrimString(const string &str, vector< string > &vToken, const char delimiter)
Definition: string_util.cpp:83
void CreateFunctionIndexMapping(FunctionIndexMapping &map, const FunctionGroup &grpFromSmall, const FunctionGroup &grpToLarge)
Definition: groups_util.cpp:44
function func(x, y, z, t, si)
bool resize(size_t newRows, size_t newCols)
Definition: metaprogramming_util.h:42