G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsPiecewiseFunction.h
Go to the documentation of this file.
1
14#pragma once
15
16namespace gismo
17{
18
27template <class T>
29{
30public:
31 typedef gsFunction<T> Base;
32 typedef typename std::vector<gsFunction<T>*> FunctionContainer;
33 typedef typename FunctionContainer::iterator fiterator;
34 typedef typename FunctionContainer::const_iterator const_fiterator;
35
37 typedef memory::shared_ptr< gsPiecewiseFunction > Ptr;
38
40 typedef memory::unique_ptr< gsPiecewiseFunction > uPtr;
41
42public:
43
44 explicit gsPiecewiseFunction(index_t npieces = 0) : Base()
45 { m_funcs.reserve(2+npieces); }
46
47 gsPiecewiseFunction(const gsFunction<T> & func) : Base()
48 {
49 m_funcs.push_back(func.clone().release());
50 //m_funcs.resize(n, func.clone());
51 }
52
53 gsPiecewiseFunction(const gsPiecewiseFunction & other) : Base()
54 {
55 m_funcs.resize(other.m_funcs.size() );
56 cloneAll( other.m_funcs.begin(), other.m_funcs.end(),
57 m_funcs.begin() );
58 }
59
60 gsPiecewiseFunction(FunctionContainer & funcs) : Base()
61 {
62 m_funcs.swap(funcs); // funcs are consumed
63 }
64
65 ~gsPiecewiseFunction()
66 {
67 freeAll(m_funcs);
68 }
69
70 #if EIGEN_HAS_RVALUE_REFERENCES
72 gsPiecewiseFunction(gsPiecewiseFunction&& other)
73 : m_funcs(give(other.m_funcs)) {}
74
76 gsPiecewiseFunction& operator= ( const gsPiecewiseFunction& other )
77 {
78 freeAll(m_funcs);
79 m_funcs.resize(other.m_funcs.size() );
80 cloneAll( other.m_funcs.begin(), other.m_funcs.end(),
81 m_funcs.begin() );
82 return *this;
83 }
84
86 gsPiecewiseFunction& operator= ( gsPiecewiseFunction&& other )
87 {
88 freeAll(m_funcs);
89 m_funcs = give(other.m_funcs);
90 return *this;
91 }
92#else
95 {
96 this->swap( other );
97 return *this;
98 }
99#endif
100
103 {
104 m_funcs.swap( other.m_funcs );
105 }
106
107 GISMO_CLONE_FUNCTION(gsPiecewiseFunction)
108
109 short_t domainDim () const {return m_funcs.front()->domainDim();};
110 short_t targetDim () const {return m_funcs.front()->targetDim();};
111
113 void addPiece(const gsFunction<T> & func)
114 {
115 m_funcs.push_back( func.clone().release() );
116 }
117
118 void addPiecePointer(gsFunction<T> * func)
119 {
120 m_funcs.push_back( func );
121 }
122
123 void addPiecePointer(typename gsFunction<T>::uPtr func)
124 {
125 m_funcs.push_back(func.release());
126 }
127
128 const gsFunction<T> & piece(const index_t i) const
129 {
130 GISMO_ASSERT(static_cast<size_t>(i) < m_funcs.size(), "Wrong piece index");
131 return *m_funcs[i];
132 }
133
134 index_t size() const {return m_funcs.size();}
135
136 std::ostream &print(std::ostream &os) const
137 {
138 os << "Piecewise Function with "<<m_funcs.size() <<" pieces.\n";
139 return os;
140 }
141
142 friend std::ostream & operator<<(std::ostream & os, const gsPiecewiseFunction & pwf)
143 {
144 return pwf.print(os);
145 }
146
148 void clear()
149 {
150 freeAll(m_funcs);
151 m_funcs.clear();
152 }
153
156
157 index_t nPieces() const {return m_funcs.size();}
158
159
160protected:
161
162 FunctionContainer m_funcs;
163};
164
165} // namespace gismo
166
uPtr clone()
Clone methode. Produceds a deep copy inside a uPtr.
A function from a n-dimensional domain to an m-dimensional image.
Definition gsFunction.h:60
memory::unique_ptr< gsFunction > uPtr
Unique pointer for gsFunction.
Definition gsFunction.h:68
A matrix with arbitrary coefficient type and fixed or dynamic size.
Definition gsMatrix.h:41
A function depending on an index i, typically referring to a patch/sub-domain. On each patch a differ...
Definition gsPiecewiseFunction.h:29
memory::shared_ptr< gsPiecewiseFunction > Ptr
Shared pointer for gsPiecewiseFunction.
Definition gsPiecewiseFunction.h:37
void swap(gsPiecewiseFunction &other)
Swap with another gsPiecewiseFunction.
Definition gsPiecewiseFunction.h:102
gsPiecewiseFunction & operator=(gsPiecewiseFunction other)
Assignment operator (uses copy-and-swap idiom)
Definition gsPiecewiseFunction.h:94
short_t targetDim() const
Dimension of the target space.
Definition gsPiecewiseFunction.h:110
memory::unique_ptr< gsPiecewiseFunction > uPtr
Unique pointer for gsPiecewiseFunction.
Definition gsPiecewiseFunction.h:40
index_t size() const
size
Definition gsPiecewiseFunction.h:134
void addPiece(const gsFunction< T > &func)
Add a piece.
Definition gsPiecewiseFunction.h:113
index_t nPieces() const
Number of pieces in the domain of definition.
Definition gsPiecewiseFunction.h:157
short_t domainDim() const
Dimension of the (source) domain.
Definition gsPiecewiseFunction.h:109
void clear()
Clear (delete) all functions.
Definition gsPiecewiseFunction.h:148
std::ostream & print(std::ostream &os) const
Prints the object as a string.
Definition gsPiecewiseFunction.h:136
const gsFunction< T > & piece(const index_t i) const
Returns the piece(s) of the function(s) at subdomain k.
Definition gsPiecewiseFunction.h:128
void eval_into(const gsMatrix< T > &, gsMatrix< T > &) const
Evaluate the function at points u into result.
Definition gsPiecewiseFunction.h:154
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define GISMO_NO_IMPLEMENTATION
Definition gsDebug.h:129
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
The G+Smo namespace, containing all definitions for the library.
void cloneAll(It start, It end, ItOut out)
Clones all pointers in the range [start end) and stores new raw pointers in iterator out.
Definition gsMemory.h:295
S give(S &x)
Definition gsMemory.h:266
void freeAll(It begin, It end)
Frees all pointers in the range [begin end)
Definition gsMemory.h:312