libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::CompositeFEMFunction< Output > Class Template Reference

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

#include <composite_fem_function.h>

Inheritance diagram for libMesh::CompositeFEMFunction< Output >:
[legend]

Public Member Functions

 CompositeFEMFunction ()
 
 ~CompositeFEMFunction ()
 
void attach_subfunction (const FEMFunctionBase< Output > &f, const std::vector< unsigned int > &index_map)
 Attach a new subfunction, along with a map from the indices of that subfunction to the indices of the global function. More...
 
virtual Output operator() (const FEMContext &c, const Point &p, const Real time=0) libmesh_override
 
virtual void operator() (const FEMContext &c, const Point &p, const Real time, DenseVector< Output > &output) libmesh_override
 Evaluation function for time-dependent vector-valued functions. More...
 
virtual Output component (const FEMContext &c, unsigned int i, const Point &p, Real time) libmesh_override
 
virtual UniquePtr< FEMFunctionBase< Output > > clone () const libmesh_override
 
unsigned int n_subfunctions () const
 
unsigned int n_components () const
 
virtual void init_context (const FEMContext &)
 Prepares a context object for use. More...
 
void operator() (const FEMContext &, const Point &p, DenseVector< Output > &output)
 Evaluation function for time-independent vector-valued functions. More...
 

Private Attributes

std::vector< FEMFunctionBase< 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::CompositeFEMFunction< Output >

FEMFunction which is a function of another function.

Author
Roy Stogner
Date
2012 FEMFunction which is a function of another function.

Definition at line 43 of file composite_fem_function.h.

Constructor & Destructor Documentation

template<typename Output = Number>
libMesh::CompositeFEMFunction< Output >::CompositeFEMFunction ( )
explicit

Definition at line 47 of file composite_fem_function.h.

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

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

Definition at line 49 of file composite_fem_function.h.

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

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

Member Function Documentation

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

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 60 of file composite_fem_function.h.

References libMesh::FEMFunctionBase< Output >::clone(), libMesh::CompositeFEMFunction< Output >::index_maps, libMesh::invalid_uint, libMesh::CompositeFEMFunction< Output >::reverse_index_map, and libMesh::CompositeFEMFunction< Output >::subfunctions.

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

62  {
63  const unsigned int subfunction_index = subfunctions.size();
64  libmesh_assert_equal_to(subfunctions.size(), index_maps.size());
65 
66  subfunctions.push_back(f.clone().release());
67  index_maps.push_back(index_map);
68 
69  unsigned int max_index =
70  *std::max_element(index_map.begin(), index_map.end());
71 
72  if (max_index >= reverse_index_map.size())
73  reverse_index_map.resize
74  (max_index+1, std::make_pair(libMesh::invalid_uint,
76 
77  for (std::size_t j=0; j != index_map.size(); ++j)
78  {
79  libmesh_assert_less(index_map[j], reverse_index_map.size());
80  libmesh_assert_equal_to(reverse_index_map[index_map[j]].first,
82  libmesh_assert_equal_to(reverse_index_map[index_map[j]].second,
84  reverse_index_map[index_map[j]] =
85  std::make_pair(subfunction_index, j);
86  }
87  }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual UniquePtr<FEMFunctionBase<Output> > libMesh::CompositeFEMFunction< Output >::clone ( ) const
virtual
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::FEMFunctionBase< Output >.

Definition at line 135 of file composite_fem_function.h.

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

136  {
137  CompositeFEMFunction * returnval = new CompositeFEMFunction();
138  for (std::size_t i=0; i != subfunctions.size(); ++i)
139  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
140  return UniquePtr<FEMFunctionBase<Output>> (returnval);
141  }
std::vector< std::vector< unsigned int > > index_maps
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual Output libMesh::CompositeFEMFunction< Output >::component ( const FEMContext context,
unsigned int  i,
const Point p,
Real  time 
)
virtual
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::FEMFunctionBase< Output >.

Definition at line 118 of file composite_fem_function.h.

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

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

122  {
123  if (i >= reverse_index_map.size() ||
125  return 0;
126 
127  libmesh_assert_less(reverse_index_map[i].first,
128  subfunctions.size());
129  libmesh_assert_not_equal_to(reverse_index_map[i].second,
131  return subfunctions[reverse_index_map[i].first]->
132  component(c, reverse_index_map[i].second, p, time);
133  }
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:184
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
virtual Output component(const FEMContext &c, unsigned int i, const Point &p, Real time) libmesh_override
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual void libMesh::FEMFunctionBase< Output >::init_context ( const FEMContext )
virtualinherited

Prepares a context object for use.

Most problems will want to reimplement this for efficiency, in order to call FE::get_*() as their particular function requires.

Reimplemented in libMesh::ParsedFEMFunction< Output >, libMesh::ParsedFEMFunction< T >, and SlitFunc.

Definition at line 71 of file fem_function_base.h.

71 {}
template<typename Output = Number>
unsigned int libMesh::CompositeFEMFunction< Output >::n_components ( ) const

Definition at line 148 of file composite_fem_function.h.

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

149  {
150  return reverse_index_map.size();
151  }
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
template<typename Output = Number>
unsigned int libMesh::CompositeFEMFunction< Output >::n_subfunctions ( ) const

Definition at line 143 of file composite_fem_function.h.

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

144  {
145  return subfunctions.size();
146  }
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual Output libMesh::CompositeFEMFunction< Output >::operator() ( const FEMContext ,
const Point p,
const Real  time = 0 
)
virtual
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::FEMFunctionBase< Output >.

Definition at line 89 of file composite_fem_function.h.

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

92  {
93  return this->component(c,0,p,time);
94  }
virtual Output component(const FEMContext &c, unsigned int i, const Point &p, Real time) libmesh_override
template<typename Output = Number>
virtual void libMesh::CompositeFEMFunction< Output >::operator() ( const FEMContext ,
const Point p,
const Real  time,
DenseVector< Output > &  output 
)
virtual

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::FEMFunctionBase< Output >.

Definition at line 96 of file composite_fem_function.h.

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

100  {
101  libmesh_assert_greater_equal (output.size(),
102  reverse_index_map.size());
103 
104  // Necessary in case we have output components not covered by
105  // any subfunctions
106  output.zero();
107 
108  DenseVector<Output> temp;
109  for (std::size_t i=0; i != subfunctions.size(); ++i)
110  {
111  temp.resize(index_maps[i].size());
112  (*subfunctions[i])(c, p, time, temp);
113  for (std::size_t j=0; j != temp.size(); ++j)
114  output(index_maps[i][j]) = temp(j);
115  }
116  }
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output>
void libMesh::FEMFunctionBase< Output >::operator() ( const FEMContext context,
const Point p,
DenseVector< Output > &  output 
)
inherited

Evaluation function for time-independent vector-valued functions.

Sets output values in the passed-in output DenseVector.

Definition at line 143 of file fem_function_base.h.

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

146 {
147  // Call the time-dependent function with t=0.
148  this->operator()(context, p, 0., output);
149 }
virtual Output operator()(const FEMContext &, const Point &p, const Real time=0.)=0

Member Data Documentation

template<typename Output = Number>
std::vector<std::vector<unsigned int> > libMesh::CompositeFEMFunction< Output >::index_maps
private
template<typename Output = Number>
std::vector<std::pair<unsigned int, unsigned int> > libMesh::CompositeFEMFunction< Output >::reverse_index_map
private
template<typename Output = Number>
std::vector<FEMFunctionBase<Output> *> libMesh::CompositeFEMFunction< Output >::subfunctions
private

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