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 ()=default
 
 CompositeFEMFunction (CompositeFEMFunction &&)=default
 
CompositeFEMFunctionoperator= (CompositeFEMFunction &&)=default
 
 CompositeFEMFunction (const CompositeFEMFunction &)=delete
 
CompositeFEMFunctionoperator= (const CompositeFEMFunction &)=delete
 
virtual ~CompositeFEMFunction ()=default
 
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) override
 
virtual void operator() (const FEMContext &c, const Point &p, const Real time, DenseVector< Output > &output) override
 
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 &)
 
void operator() (const FEMContext &, const Point &p, DenseVector< Output > &output)
 

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.

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

◆ 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 72 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().

74  {
75  const unsigned int subfunction_index =
76  cast_int<unsigned int>(subfunctions.size());
77  libmesh_assert_equal_to(subfunctions.size(), index_maps.size());
78 
79  subfunctions.push_back(f.clone());
80  index_maps.push_back(index_map);
81 
82  unsigned int max_index =
83  *std::max_element(index_map.begin(), index_map.end());
84 
85  if (max_index >= reverse_index_map.size())
86  reverse_index_map.resize
87  (max_index+1, std::make_pair(libMesh::invalid_uint,
89 
90  for (std::size_t j=0; j != index_map.size(); ++j)
91  {
92  libmesh_assert_less(index_map[j], reverse_index_map.size());
93  libmesh_assert_equal_to(reverse_index_map[index_map[j]].first,
95  libmesh_assert_equal_to(reverse_index_map[index_map[j]].second,
97  reverse_index_map[index_map[j]] =
98  std::make_pair(subfunction_index, j);
99  }
100  }
const unsigned int invalid_uint
Definition: libmesh.h:245
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
std::vector< std::unique_ptr< FEMFunctionBase< Output > > > subfunctions

◆ 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 148 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.

149  {
150  CompositeFEMFunction * returnval = new CompositeFEMFunction();
151  for (std::size_t i=0; i != subfunctions.size(); ++i)
152  returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
153  return std::unique_ptr<FEMFunctionBase<Output>> (returnval);
154  }
std::vector< std::vector< unsigned int > > index_maps
std::vector< std::unique_ptr< FEMFunctionBase< 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 131 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()().

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(c, reverse_index_map[i].second, p, time);
146  }
const unsigned int invalid_uint
Definition: libmesh.h:245
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) override
std::vector< std::unique_ptr< FEMFunctionBase< Output > > > subfunctions

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

Definition at line 73 of file fem_function_base.h.

73 {}

◆ n_components()

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

Definition at line 161 of file composite_fem_function.h.

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

162  {
163  return reverse_index_map.size();
164  }
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map

◆ n_subfunctions()

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

Definition at line 156 of file composite_fem_function.h.

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

157  {
158  return subfunctions.size();
159  }
std::vector< std::unique_ptr< FEMFunctionBase< 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 145 of file fem_function_base.h.

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

◆ operator()() [2/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 102 of file composite_fem_function.h.

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

105  {
106  return this->component(c,0,p,time);
107  }
virtual Output component(const FEMContext &c, unsigned int i, const Point &p, Real time) override

◆ operator()() [3/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 109 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(), libMesh::CompositeFEMFunction< Output >::subfunctions, and libMesh::DenseVector< T >::zero().

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(cast_int<unsigned int>(index_maps[i].size()));
125  (*subfunctions[i])(c, p, time, temp);
126  for (unsigned int j=0; j != temp.size(); ++j)
127  output(index_maps[i][j]) = temp(j);
128  }
129  }
virtual unsigned int size() const override
Definition: dense_vector.h:92
std::vector< std::pair< unsigned int, unsigned int > > reverse_index_map
std::vector< std::vector< unsigned int > > index_maps
std::vector< std::unique_ptr< FEMFunctionBase< Output > > > subfunctions
virtual void zero() override
Definition: dense_vector.h:379

◆ 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

◆ subfunctions


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