libMesh
Loading...
Searching...
No Matches
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.
 
CompositeFEMFunctionoperator= (CompositeFEMFunction &&)=default
 
 CompositeFEMFunction (const CompositeFEMFunction &)=delete
 This class contains unique_ptr members so it can't be default copied or assigned.
 
CompositeFEMFunctionoperator= (const CompositeFEMFunction &)=delete
 
virtual ~CompositeFEMFunction ()=default
 The subfunctions vector is automatically cleaned up.
 
void attach_subfunction (const FEMFunctionBase< Output > &f, 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.
 
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.
 
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 ()
 Any post-construction initialization.
 
virtual void init_context (const FEMContext &)
 Prepares a context object for use.
 
void operator() (const FEMContext &, const Point &p, DenseVector< Output > &output)
 Evaluation function for time-independent vector-valued functions.
 

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,
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
82 unsigned int max_index =
83 *std::max_element(index_map.begin(), index_map.end());
84
85 if (max_index >= reverse_index_map.size())
87 (max_index+1, std::make_pair(libMesh::invalid_uint,
89
90 for (auto j : index_range(index_map))
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
101 index_maps.push_back(std::move(index_map));
102 }
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
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
const unsigned int invalid_uint
A number which is used quite often to represent an invalid or uninitialized value for an unsigned int...
Definition libmesh.h:303

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.

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

151 {
152 auto returnval = std::make_unique<CompositeFEMFunction>();
153 for (auto i : index_range(subfunctions))
154 returnval->attach_subfunction(*subfunctions[i], index_maps[i]);
155 return returnval;
156 }
void attach_subfunction(const FEMFunctionBase< Output > &f, 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...

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

137 {
138 if (i >= reverse_index_map.size() ||
140 return 0;
141
142 libmesh_assert_less(reverse_index_map[i].first,
143 subfunctions.size());
144 libmesh_assert_not_equal_to(reverse_index_map[i].second,
146 return subfunctions[reverse_index_map[i].first]->
147 component(c, reverse_index_map[i].second, p, time);
148 }
virtual Output component(const FEMContext &c, unsigned int i, const Point &p, Real time) override

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

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

◆ init()

template<typename Output = Number>
virtual void libMesh::FEMFunctionBase< Output >::init ( )
inlinevirtualinherited

Any post-construction initialization.

Reimplemented in libMesh::WrappedFunctor< Output >.

Definition at line 69 of file fem_function_base.h.

69{}

◆ 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 SlitFunc, libMesh::FDMGradient< GradType >, libMesh::ParsedFEMFunction< Output >, libMesh::ParsedFEMFunction< Number >, and libMesh::WrappedFunctor< Output >.

Definition at line 77 of file fem_function_base.h.

77{}

◆ n_components()

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

Definition at line 163 of file composite_fem_function.h.

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

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

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

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 149 of file fem_function_base.h.

152{
153 // Call the time-dependent function with t=0.
154 this->operator()(context, p, 0., output);
155}
virtual Output operator()(const FEMContext &, const Point &p, const Real time=0.)=0

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

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

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

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

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: