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 ()=default
 
 CompositeFEMFunction (CompositeFEMFunction &&)=default
 This class can be default move constructed and assigned. More...
 
CompositeFEMFunctionoperator= (CompositeFEMFunction &&)=default
 
 CompositeFEMFunction (const CompositeFEMFunction &)=delete
 This class contains unique_ptr members so it can't be default copied or assigned. More...
 
CompositeFEMFunctionoperator= (const CompositeFEMFunction &)=delete
 
virtual ~CompositeFEMFunction ()=default
 The subfunctions vector is automatically cleaned up. More...
 
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) override
 
virtual void operator() (const FEMContext &c, const Point &p, const Real time, DenseVector< Output > &output) override
 Evaluation function for time-dependent vector-valued functions. More...
 
virtual Output component (const FEMContext &c, unsigned int i, const Point &p, Real time) override
 
virtual std::unique_ptr< FEMFunctionBase< Output > > clone () const 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< std::unique_ptr< 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 44 of file composite_fem_function.h.

Constructor & Destructor Documentation

◆ CompositeFEMFunction() [1/3]

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

◆ CompositeFEMFunction() [2/3]

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

This class can be default move constructed and assigned.

◆ CompositeFEMFunction() [3/3]

template<typename Output = Number>
libMesh::CompositeFEMFunction< Output >::CompositeFEMFunction ( const CompositeFEMFunction< Output > &  )
delete

This class contains unique_ptr members so it can't be default copied or assigned.

◆ ~CompositeFEMFunction()

template<typename Output = Number>
virtual libMesh::CompositeFEMFunction< Output >::~CompositeFEMFunction ( )
virtualdefault

The subfunctions vector is automatically cleaned up.

Member Function Documentation

◆ attach_subfunction()

template<typename Output = Number>
void libMesh::CompositeFEMFunction< Output >::attach_subfunction ( const FEMFunctionBase< 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 73 of file composite_fem_function.h.

75  {
76  const unsigned int subfunction_index =
77  cast_int<unsigned int>(subfunctions.size());
78  libmesh_assert_equal_to(subfunctions.size(), index_maps.size());
79 
80  subfunctions.push_back(f.clone());
81  index_maps.push_back(index_map);
82 
83  unsigned int max_index =
84  *std::max_element(index_map.begin(), index_map.end());
85 
86  if (max_index >= reverse_index_map.size())
87  reverse_index_map.resize
88  (max_index+1, std::make_pair(libMesh::invalid_uint,
90 
91  for (auto j : index_range(index_map))
92  {
93  libmesh_assert_less(index_map[j], reverse_index_map.size());
94  libmesh_assert_equal_to(reverse_index_map[index_map[j]].first,
96  libmesh_assert_equal_to(reverse_index_map[index_map[j]].second,
98  reverse_index_map[index_map[j]] =
99  std::make_pair(subfunction_index, j);
100  }
101  }

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

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

◆ clone()

template<typename Output = Number>
virtual std::unique_ptr<FEMFunctionBase<Output> > libMesh::CompositeFEMFunction< Output >::clone ( ) const
inlineoverridevirtual
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 149 of file composite_fem_function.h.

150  {
151  CompositeFEMFunction * returnval = new CompositeFEMFunction();
152  for (auto i : index_range(subfunctions))
153  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
154  return std::unique_ptr<FEMFunctionBase<Output>> (returnval);
155  }

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

◆ component()

template<typename Output = Number>
virtual Output libMesh::CompositeFEMFunction< Output >::component ( const FEMContext context,
unsigned int  i,
const Point p,
Real  time 
)
inlineoverridevirtual
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 132 of file composite_fem_function.h.

136  {
137  if (i >= reverse_index_map.size() ||
139  return 0;
140 
141  libmesh_assert_less(reverse_index_map[i].first,
142  subfunctions.size());
143  libmesh_assert_not_equal_to(reverse_index_map[i].second,
145  return subfunctions[reverse_index_map[i].first]->
146  component(c, reverse_index_map[i].second, p, time);
147  }

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

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

◆ init_context()

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

Definition at line 72 of file fem_function_base.h.

72 {}

◆ n_components()

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

Definition at line 162 of file composite_fem_function.h.

163  {
164  return reverse_index_map.size();
165  }

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

◆ n_subfunctions()

template<typename Output = Number>
unsigned int libMesh::CompositeFEMFunction< Output >::n_subfunctions ( ) const
inline

Definition at line 157 of file composite_fem_function.h.

158  {
159  return subfunctions.size();
160  }

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

◆ operator()() [1/3]

template<typename Output >
void libMesh::FEMFunctionBase< Output >::operator() ( const FEMContext context,
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 144 of file fem_function_base.h.

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

◆ operator()() [2/3]

template<typename Output = Number>
virtual void libMesh::CompositeFEMFunction< Output >::operator() ( const FEMContext ,
const Point p,
const Real  time,
DenseVector< Output > &  output 
)
inlineoverridevirtual

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

114  {
115  libmesh_assert_greater_equal (output.size(),
116  reverse_index_map.size());
117 
118  // Necessary in case we have output components not covered by
119  // any subfunctions
120  output.zero();
121 
122  DenseVector<Output> temp;
123  for (auto i : index_range(subfunctions))
124  {
125  temp.resize(cast_int<unsigned int>(index_maps[i].size()));
126  (*subfunctions[i])(c, p, time, temp);
127  for (auto j : index_range(temp))
128  output(index_maps[i][j]) = temp(j);
129  }
130  }

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

◆ operator()() [3/3]

template<typename Output = Number>
virtual Output libMesh::CompositeFEMFunction< Output >::operator() ( const FEMContext ,
const Point p,
const Real  time = 0 
)
inlineoverridevirtual
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 103 of file composite_fem_function.h.

106  {
107  return this->component(c,0,p,time);
108  }

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

◆ operator=() [1/2]

template<typename Output = Number>
CompositeFEMFunction& libMesh::CompositeFEMFunction< Output >::operator= ( CompositeFEMFunction< Output > &&  )
default

◆ operator=() [2/2]

template<typename Output = Number>
CompositeFEMFunction& libMesh::CompositeFEMFunction< Output >::operator= ( const CompositeFEMFunction< Output > &  )
delete

Member Data Documentation

◆ index_maps

template<typename Output = Number>
std::vector<std::vector<unsigned int> > libMesh::CompositeFEMFunction< Output >::index_maps
private

◆ reverse_index_map

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

◆ subfunctions

template<typename Output = Number>
std::vector<std::unique_ptr<FEMFunctionBase<Output> > > libMesh::CompositeFEMFunction< Output >::subfunctions
private

The documentation for this class was generated from the following file:
libMesh::invalid_uint
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value.
Definition: libmesh.h:249
libMesh::FEMFunctionBase::operator()
virtual Output operator()(const FEMContext &, const Point &p, const Real time=0.)=0
libMesh::CompositeFEMFunction::subfunctions
std::vector< std::unique_ptr< FEMFunctionBase< Output > > > subfunctions
Definition: composite_fem_function.h:169
libMesh::index_range
IntRange< std::size_t > index_range(const std::vector< T > &vec)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition: int_range.h:106
libMesh::DenseVector::zero
virtual void zero() override
Set every element in the vector to 0.
Definition: dense_vector.h:379
libMesh::CompositeFEMFunction::reverse_index_map
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
Definition: composite_fem_function.h:175
libMesh::CompositeFEMFunction::index_maps
std::vector< std::vector< unsigned int > > index_maps
Definition: composite_fem_function.h:172
libMesh::CompositeFEMFunction::CompositeFEMFunction
CompositeFEMFunction()=default
libMesh::CompositeFEMFunction::component
virtual Output component(const FEMContext &c, unsigned int i, const Point &p, Real time) override
Definition: composite_fem_function.h:132
libMesh::DenseVector::size
virtual unsigned int size() const override
Definition: dense_vector.h:92