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. All overridden virtual functions are documented in function_base.h.

Author
Roy Stogner
Date
2012

Definition at line 44 of file composite_function.h.

Constructor & Destructor Documentation

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

Definition at line 48 of file composite_function.h.

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

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

Definition at line 50 of file composite_function.h.

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

51  {
52  for (std::size_t i=0; i != subfunctions.size(); ++i)
53  delete subfunctions[i];
54  }
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

Attach a new subfunction, along with a map from the indices of that subfunction to the indices of the global function. (*this)(index_map[i]) will return f(i).

Definition at line 61 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().

63  {
64  const unsigned int subfunction_index = subfunctions.size();
65  libmesh_assert_equal_to(subfunctions.size(), index_maps.size());
66 
67  subfunctions.push_back(f.clone().release());
68  index_maps.push_back(index_map);
69 
70  unsigned int max_index =
71  *std::max_element(index_map.begin(), index_map.end());
72 
73  if (max_index >= reverse_index_map.size())
74  reverse_index_map.resize
75  (max_index+1, std::make_pair(libMesh::invalid_uint,
77 
78  for (std::size_t j=0; j != index_map.size(); ++j)
79  {
80  libmesh_assert_less(index_map[j], reverse_index_map.size());
81  libmesh_assert_equal_to(reverse_index_map[index_map[j]].first,
83  libmesh_assert_equal_to(reverse_index_map[index_map[j]].second,
85  reverse_index_map[index_map[j]] =
86  std::make_pair(subfunction_index, j);
87  }
88 
89  // Now check for time dependence
90  // We only check the function we just added instead of researching all subfunctions
91  // If this is the first subfunction, then that determines the time-dependence.
92  if (subfunctions.size() == 1)
94 
95  // Otherwise, we have more than 1 function already.
96  // If _is_time_dependent is true, then one of the previous
97  // subfunctions is time-dependent and thus this CompositeFunction
98  // time-dependent. If _is_time_dependent is false, then the subfunction
99  // just added determines the time-dependence.
100  else if (!this->_is_time_dependent)
102  }
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 147 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.

148  {
149  CompositeFunction * returnval = new CompositeFunction();
150  for (std::size_t i=0; i != subfunctions.size(); ++i)
151  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
152  return UniquePtr<FunctionBase<Output> > (returnval);
153  }
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.
Note
Subclasses aren't required to override this, since the default implementation is based on the full vector evaluation, which is often correct.
Subclasses are recommended to override this, since the default implementation is based on a vector evaluation, which is usually unnecessarily inefficient.

Reimplemented from libMesh::FunctionBase< Output >.

Definition at line 131 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()().

134  {
135  if (i >= reverse_index_map.size() ||
137  return 0;
138 
139  libmesh_assert_less(reverse_index_map[i].first,
140  subfunctions.size());
141  libmesh_assert_not_equal_to(reverse_index_map[i].second,
143  return subfunctions[reverse_index_map[i].first]->
144  component(reverse_index_map[i].second,p,time);
145  }
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 208 of file function_base.h.

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

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

209 {
210  return (this->_initialized);
211 }
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 160 of file composite_function.h.

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

161  {
162  return reverse_index_map.size();
163  }
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 155 of file composite_function.h.

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

156  {
157  return subfunctions.size();
158  }
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 function value at coordinate p and time time, which defaults to zero.

Pure virtual, so you have to override it.

Implements libMesh::FunctionBase< Output >.

Definition at line 104 of file composite_function.h.

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

106  {
107  return this->component(0,p,time);
108  }
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

Evaluation function for time-dependent vector-valued functions. Sets output values in the passed-in output DenseVector.

Pure virtual, so you have to override it.

Implements libMesh::FunctionBase< Output >.

Definition at line 110 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.

113  {
114  libmesh_assert_greater_equal (output.size(),
115  reverse_index_map.size());
116 
117  // Necessary in case we have output components not covered by
118  // any subfunctions
119  output.zero();
120 
121  DenseVector<Output> temp;
122  for (std::size_t i=0; i != subfunctions.size(); ++i)
123  {
124  temp.resize(index_maps[i].size());
125  (*subfunctions[i])(p, time, temp);
126  for (std::size_t j=0; j != temp.size(); ++j)
127  output(index_maps[i][j]) = temp(j);
128  }
129  }
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

Evaluation function for time-independent vector-valued functions. Sets output values in the passed-in output DenseVector.

Definition at line 243 of file function_base.h.

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

245 {
246  // Call the time-dependent function with t=0.
247  this->operator()(p, 0., output);
248 }
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 215 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().

216 {
218 }
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 168 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: