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 >:

Public Member Functions

 CompositeFEMFunction ()
 
 ~CompositeFEMFunction ()
 
void attach_subfunction (const FEMFunctionBase< Output > &f, const std::vector< unsigned int > &index_map)
 
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
 
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 &)
 
void operator() (const FEMContext &, const Point &p, DenseVector< Output > &output)
 

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.

FEMFunction which is a function of another function.

Author
Roy Stogner
Date
2012

Definition at line 43 of file composite_fem_function.h.

Constructor & Destructor Documentation

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

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 ( )
inline

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 
)
inline

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

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  }
const unsigned int invalid_uint
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
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::FEMFunctionBase< Output >.

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

138  {
139  CompositeFEMFunction * returnval = new CompositeFEMFunction();
140  for (std::size_t i=0; i != subfunctions.size(); ++i)
141  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
142  return UniquePtr<FEMFunctionBase<Output> > (returnval);
143  }
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 c,
unsigned int  i,
const Point p,
Real  time 
)
inlinevirtual
Returns
the vector component i at coordinate p and time time.

Reimplemented from libMesh::FEMFunctionBase< Output >.

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

124  {
125  if (i >= reverse_index_map.size() ||
127  return 0;
128 
129  libmesh_assert_less(reverse_index_map[i].first,
130  subfunctions.size());
131  libmesh_assert_not_equal_to(reverse_index_map[i].second,
133  return subfunctions[reverse_index_map[i].first]->
134  component(c, reverse_index_map[i].second, p, time);
135  }
const unsigned int invalid_uint
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 )
inlinevirtualinherited

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 >, and libMesh::ParsedFEMFunction< T >.

Definition at line 71 of file fem_function_base.h.

References libMesh::FEMFunctionBase< Output >::clone(), libMesh::FEMFunctionBase< Output >::component(), libMesh::FEMFunctionBase< Output >::operator()(), and libMesh::Real.

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

Definition at line 150 of file composite_fem_function.h.

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

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

Definition at line 145 of file composite_fem_function.h.

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

146  {
147  return subfunctions.size();
148  }
std::vector< FEMFunctionBase< Output > * > subfunctions
template<typename Output = Number>
virtual Output libMesh::CompositeFEMFunction< Output >::operator() ( const FEMContext ,
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::FEMFunctionBase< Output >.

Definition at line 87 of file composite_fem_function.h.

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

90  {
91  return this->component(c,0,p,time);
92  }
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 
)
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.

Implements libMesh::FEMFunctionBase< Output >.

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

98  {
99  libmesh_assert_greater_equal (output.size(),
100  reverse_index_map.size());
101 
102  // Necessary in case we have output components not covered by
103  // any subfunctions
104  output.zero();
105 
106  DenseVector<Output> temp;
107  for (std::size_t i=0; i != subfunctions.size(); ++i)
108  {
109  temp.resize(index_maps[i].size());
110  (*subfunctions[i])(c, p, time, temp);
111  for (std::size_t j=0; j != temp.size(); ++j)
112  output(index_maps[i][j]) = temp(j);
113  }
114  }
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 
)
inlineinherited

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

Definition at line 144 of file fem_function_base.h.

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

147 {
148  // Call the time-dependent function with t=0.
149  this->operator()(context, p, 0., output);
150 }
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

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