libMesh::CompositeFunction< Output > Class Template Reference

Function which is a function of another function. More...

#include <composite_function.h>

Inheritance diagram for libMesh::CompositeFunction< Output >:

Public Member Functions

 CompositeFunction ()
 
 ~CompositeFunction ()
 
void attach_subfunction (const FunctionBase< Output > &f, const std::vector< unsigned int > &index_map)
 
virtual Output operator() (const Point &p, const Real time=0) libmesh_override
 
virtual void operator() (const Point &p, const Real time, DenseVector< Output > &output) libmesh_override
 
virtual Output component (unsigned int i, const Point &p, Real time) libmesh_override
 
virtual UniquePtr< FunctionBase< Output > > clone () const libmesh_override
 
unsigned int n_subfunctions () const
 
unsigned int n_components () const
 
virtual void init ()
 
virtual void clear ()
 
void operator() (const Point &p, DenseVector< Output > &output)
 
bool initialized () const
 
void set_is_time_dependent (bool is_time_dependent)
 
bool is_time_dependent () const
 

Protected Attributes

const FunctionBase_master
 
bool _initialized
 
bool _is_time_dependent
 

Private Attributes

std::vector< FunctionBase< Output > * > subfunctions
 
std::vector< std::vector< unsigned int > > index_maps
 
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
 

Detailed Description

template<typename Output = Number>
class libMesh::CompositeFunction< Output >

Function which is a function of another function.

Function which is a function of another function.

Author
Roy Stogner
Date
2012

Definition at line 43 of file composite_function.h.

Constructor & Destructor Documentation

template<typename Output = Number>
libMesh::CompositeFunction< Output >::CompositeFunction ( )
inlineexplicit

Definition at line 47 of file composite_function.h.

Referenced by libMesh::CompositeFunction< Output >::clone().

47 {}
template<typename Output = Number>
libMesh::CompositeFunction< Output >::~CompositeFunction ( )
inline

Definition at line 49 of file composite_function.h.

References libMesh::CompositeFunction< Output >::subfunctions.

50  {
51  for (std::size_t i=0; i != subfunctions.size(); ++i)
52  delete subfunctions[i];
53  }
std::vector< FunctionBase< Output > * > subfunctions

Member Function Documentation

template<typename Output = Number>
void libMesh::CompositeFunction< Output >::attach_subfunction ( const FunctionBase< Output > &  f,
const std::vector< unsigned int > &  index_map 
)
inline

Definition at line 58 of file composite_function.h.

References libMesh::FunctionBase< Output >::_is_time_dependent, libMesh::FunctionBase< Output >::clone(), libMesh::CompositeFunction< Output >::index_maps, libMesh::invalid_uint, libMesh::FunctionBase< Output >::is_time_dependent(), libMesh::CompositeFunction< Output >::reverse_index_map, and libMesh::CompositeFunction< Output >::subfunctions.

Referenced by libMesh::CompositeFunction< Output >::clone(), and libMesh::DirichletBoundary::DirichletBoundary().

60  {
61  const unsigned int subfunction_index = subfunctions.size();
62  libmesh_assert_equal_to(subfunctions.size(), index_maps.size());
63 
64  subfunctions.push_back(f.clone().release());
65  index_maps.push_back(index_map);
66 
67  unsigned int max_index =
68  *std::max_element(index_map.begin(), index_map.end());
69 
70  if (max_index >= reverse_index_map.size())
71  reverse_index_map.resize
72  (max_index+1, std::make_pair(libMesh::invalid_uint,
74 
75  for (std::size_t j=0; j != index_map.size(); ++j)
76  {
77  libmesh_assert_less(index_map[j], reverse_index_map.size());
78  libmesh_assert_equal_to(reverse_index_map[index_map[j]].first,
80  libmesh_assert_equal_to(reverse_index_map[index_map[j]].second,
82  reverse_index_map[index_map[j]] =
83  std::make_pair(subfunction_index, j);
84  }
85 
86  // Now check for time dependence
87  // We only check the function we just added instead of researching all subfunctions
88  // If this is the first subfunction, then that determines the time-dependence.
89  if( subfunctions.size() == 1 )
91 
92  // Otherwise, we have more than 1 function already.
93  // If _is_time_dependent is true, then one of the previous
94  // subfunctions is time-dependent and thus this CompositeFunction
95  // time-dependent. If _is_time_dependent is false, then the subfunction
96  // just added determines the time-dependence.
97  else if( !this->_is_time_dependent )
99  }
const unsigned int invalid_uint
Definition: libmesh.h:184
bool is_time_dependent() const
std::vector< FunctionBase< Output > * > subfunctions
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::clear ( )
inlinevirtualinherited
template<typename Output = Number>
virtual UniquePtr<FunctionBase<Output> > libMesh::CompositeFunction< Output >::clone ( ) const
inlinevirtual

Returns a new copy of the function. The new copy should be as ``deep'' as necessary to allow independent destruction and simultaneous evaluations of the copies in different threads.

Implements libMesh::FunctionBase< Output >.

Definition at line 148 of file composite_function.h.

References libMesh::CompositeFunction< Output >::attach_subfunction(), libMesh::CompositeFunction< Output >::CompositeFunction(), libMesh::CompositeFunction< Output >::index_maps, and libMesh::CompositeFunction< Output >::subfunctions.

149  {
150  CompositeFunction * returnval = new CompositeFunction();
151  for (std::size_t i=0; i != subfunctions.size(); ++i)
152  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
153  return UniquePtr<FunctionBase<Output> > (returnval);
154  }
std::vector< FunctionBase< Output > * > subfunctions
std::vector< std::vector< unsigned int > > index_maps
template<typename Output = Number>
virtual Output libMesh::CompositeFunction< Output >::component ( unsigned int  i,
const Point p,
Real  time 
)
inlinevirtual
Returns
the vector component i at coordinate p and time time.

Reimplemented from libMesh::FunctionBase< Output >.

Definition at line 132 of file composite_function.h.

References libMesh::invalid_uint, libMesh::CompositeFunction< Output >::reverse_index_map, and libMesh::CompositeFunction< Output >::subfunctions.

Referenced by libMesh::CompositeFunction< Output >::operator()().

135  {
136  if (i >= reverse_index_map.size() ||
138  return 0;
139 
140  libmesh_assert_less(reverse_index_map[i].first,
141  subfunctions.size());
142  libmesh_assert_not_equal_to(reverse_index_map[i].second,
144  return subfunctions[reverse_index_map[i].first]->
145  component(reverse_index_map[i].second,p,time);
146  }
const unsigned int invalid_uint
Definition: libmesh.h:184
std::vector< FunctionBase< Output > * > subfunctions
virtual Output component(unsigned int i, const Point &p, Real time) libmesh_override
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
template<typename Output = Number>
virtual void libMesh::FunctionBase< Output >::init ( )
inlinevirtualinherited
template<typename Output >
bool libMesh::FunctionBase< Output >::initialized ( ) const
inlineinherited
Returns
true when this object is properly initialized and ready for use, false otherwise.

Definition at line 212 of file function_base.h.

References libMesh::FunctionBase< Output >::_initialized.

Referenced by libMesh::FunctionBase< Real >::clear(), and libMesh::AnalyticFunction< Output >::operator()().

213 {
214  return (this->_initialized);
215 }
template<typename Output >
bool libMesh::FunctionBase< Output >::is_time_dependent ( ) const
inlineinherited
template<typename Output = Number>
unsigned int libMesh::CompositeFunction< Output >::n_components ( ) const
inline

Definition at line 161 of file composite_function.h.

References libMesh::CompositeFunction< Output >::reverse_index_map.

162  {
163  return reverse_index_map.size();
164  }
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
template<typename Output = Number>
unsigned int libMesh::CompositeFunction< Output >::n_subfunctions ( ) const
inline

Definition at line 156 of file composite_function.h.

References libMesh::CompositeFunction< Output >::subfunctions.

157  {
158  return subfunctions.size();
159  }
std::vector< FunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual Output libMesh::CompositeFunction< Output >::operator() ( const Point p,
const Real  time = 0 
)
inlinevirtual
Returns
the scalar value at coordinate p and time time, which defaults to zero. Purely virtual, so you have to overload it. Note that this cannot be a const method, check MeshFunction.

Implements libMesh::FunctionBase< Output >.

Definition at line 101 of file composite_function.h.

References libMesh::CompositeFunction< Output >::component().

103  {
104  return this->component(0,p,time);
105  }
virtual Output component(unsigned int i, const Point &p, Real time) libmesh_override
template<typename Output = Number>
virtual void libMesh::CompositeFunction< Output >::operator() ( const Point p,
const Real  time,
DenseVector< Output > &  output 
)
inlinevirtual

Return function for vectors. Returns in output the values of the data at the coordinate p and for time time. Purely virtual, so you have to overload it. Note that this cannot be a const method, check MeshFunction. Can optionally provide subdomain_ids which will restrict the function to operate on elements with subdomain id contained in the set. This is useful in cases where there are multiple dimensioned elements, for example.

Implements libMesh::FunctionBase< Output >.

Definition at line 107 of file composite_function.h.

References libMesh::CompositeFunction< Output >::index_maps, libMesh::DenseVector< T >::resize(), libMesh::CompositeFunction< Output >::reverse_index_map, libMesh::DenseVector< T >::size(), and libMesh::CompositeFunction< Output >::subfunctions.

110  {
111  libmesh_assert_greater_equal (output.size(),
112  reverse_index_map.size());
113 
114  // Necessary in case we have output components not covered by
115  // any subfunctions
116  output.zero();
117 
118  DenseVector<Output> temp;
119  for (std::size_t i=0; i != subfunctions.size(); ++i)
120  {
121  temp.resize(index_maps[i].size());
122  (*subfunctions[i])(p, time, temp);
123  for (std::size_t j=0; j != temp.size(); ++j)
124  output(index_maps[i][j]) = temp(j);
125  }
126  }
std::vector< FunctionBase< Output > * > subfunctions
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
template<typename Output>
void libMesh::FunctionBase< Output >::operator() ( const Point p,
DenseVector< Output > &  output 
)
inlineinherited

Return function for vectors. Returns in output the values of the data at the coordinate p.

Definition at line 247 of file function_base.h.

References libMesh::FunctionBase< Output >::operator()().

249 {
250  // Call the time-dependent function with t=0.
251  this->operator()(p, 0., output);
252 }
virtual Output operator()(const Point &p, const Real time=0.)=0
template<typename Output >
void libMesh::FunctionBase< Output >::set_is_time_dependent ( bool  is_time_dependent)
inlineinherited

Function to set whether this is a time-dependent function or not. This is intended to be only used by subclasses who cannot natively determine time-dependence. In such a case, this function should be used immediately following construction.

Definition at line 219 of file function_base.h.

References libMesh::FunctionBase< Output >::_is_time_dependent, and libMesh::FunctionBase< Output >::is_time_dependent().

Referenced by libMesh::FunctionBase< Real >::clear().

220 {
222 }
bool is_time_dependent() const

Member Data Documentation

template<typename Output = Number>
bool libMesh::FunctionBase< Output >::_is_time_dependent
protectedinherited
template<typename Output = Number>
const FunctionBase* libMesh::FunctionBase< Output >::_master
protectedinherited

Const pointer to our master, initialized to NULL. There may be cases where multiple functions are required, but to save memory, one master handles some centralized data.

Definition at line 172 of file function_base.h.

template<typename Output = Number>
std::vector<std::vector<unsigned int> > libMesh::CompositeFunction< Output >::index_maps
private
template<typename Output = Number>
std::vector<std::pair<unsigned int, unsigned int> > libMesh::CompositeFunction< Output >::reverse_index_map
private

The documentation for this class was generated from the following file: