G+Smo  25.01.0
Geometry + Simulation Modules
 
Loading...
Searching...
No Matches
gsFunctionSum.h
Go to the documentation of this file.
1
15#pragma once
16
18
19namespace gismo
20{
21template<class T> class gsFunctionPieceSum;
22
23template<class T>
24class gsFunctionSum : public gsFunctionSet<T>
25{
27 typedef memory::shared_ptr< gsFunctionSum<T> > Ptr;
28
30 typedef memory::unique_ptr< gsFunctionSum<T> > uPtr;
31
32public:
33 gsFunctionSum()
34 :
35 m_size(0)
36 {}
37
38 gsFunctionSum(const std::vector<const gsFunctionSet<T> * > & functions)
39 :
40 m_functions(functions),
41 m_size(functions.size())
42 {
43 _init(m_functions);
44 }
45
46 gsFunctionSum(const gsFunctionSet<T> * undeformed, const gsFunctionSet<T> * deformation)
47 :
48 m_size(2)
49 {
50 m_functions.push_back(undeformed);
51 m_functions.push_back(deformation);
52
53 _init(m_functions);
54 }
55
56 index_t nPieces() const {return m_functions[0]->nPieces();}
57
58 short_t domainDim() const
59 { return m_functions[0]->domainDim(); }
60
61 short_t targetDim() const
62 { return m_functions[0]->targetDim(); }
63
64 const gsFunctionPieceSum<T> & piece(const index_t k) const { return m_pieces[k]; }
65
66 index_t size() const {return nPieces();}
67
68 std::ostream &print(std::ostream &os) const
69 {
70 for (index_t p = 1; p!=m_size; p++)
71 gsInfo<<"Piece "<<p<<":\n"<<m_pieces[p]<<"\n";
72 return os;
73 }
74
75
76 index_t funcSize() const {return m_functions.size();}
77
78 const gsFunctionSet<T> * func(const index_t i) const { return m_functions[i]; }
79
80private:
81 void _init(const std::vector<const gsFunctionSet<T> * > & functions)
82 {
83 GISMO_ASSERT(functions.size()>0,"Must give one or more function sets.");
84 for (index_t p = 1; p!=m_size; p++)
85 {
86 GISMO_ASSERT(functions[p-1]->nPieces()==functions[p]->nPieces(),"Number of pieces does not match for function "<<p-1<<" and "<<p<<"!");
87 GISMO_ASSERT(functions[p-1]->domainDim()==functions[p]->domainDim(),"Domain dimension does not match for function "<<p-1<<" and "<<p<<"!");
88 GISMO_ASSERT(functions[p-1]->targetDim()==functions[p]->targetDim(),"Target dimension does not match for function "<<p-1<<" and "<<p<<"!");
89 }
90
91 for (index_t p = 0; p!=functions[0]->nPieces(); p++)
92 m_pieces.push_back(gsFunctionPieceSum<T>(this,p));
93 }
94
95protected:
96 std::vector<const gsFunctionSet<T> * > m_functions;
97 std::vector<gsFunctionPieceSum<T> > m_pieces;
98 const index_t m_size;
99 gsMatrix<T> m_support;
100
101};
102
103template<class T>
104class gsFunctionPieceSum : public gsFunction<T>
105{
107 typedef memory::shared_ptr< gsFunctionPieceSum<T> > Ptr;
108
110 typedef memory::unique_ptr< gsFunctionPieceSum<T> > uPtr;
111
112 using Base = gsFunction<T>;
113
114public:
115 gsFunctionPieceSum(const gsFunctionSum<T> * geom, const index_t index)
116 :
117 m_geom(geom),
118 m_index(index)
119 {
120 m_support = m_geom->func(0)->piece(m_index).support();
121 for (index_t p = 1; p!=m_geom->funcSize(); p++)
122 for (index_t d=0; d!=m_support.rows(); d++)
123 {
124 GISMO_ASSERT(m_geom->func(p)->piece(m_index).support().rows()!=0 && m_geom->func(p)->piece(m_index).support().cols()!=0,"Support is empty");
125
126 if (m_support(d,0) > m_geom->func(p)->piece(m_index).support()(d,0))
127 m_support(d,0) = m_geom->func(p)->piece(m_index).support()(d,0);
128 if (m_support(d,1) < m_geom->func(p)->piece(m_index).support()(d,1))
129 m_support(d,1) = m_geom->func(p)->piece(m_index).support()(d,1);
130 }
131 }
132
133 gsMatrix<T> support() const
134 {
135 return m_support;
136 }
137
138 short_t domainDim() const
139 { return m_geom->domainDim(); }
140
141 short_t targetDim() const
142 { return m_geom->targetDim(); }
143
145 void eval_into(const gsMatrix<T> & u, gsMatrix<T>& result) const
146 {
147 gsMatrix<T> tmp;
148 m_geom->func(0)->piece(m_index).eval_into(u,result);
149 for (index_t p = 1; p!=m_geom->funcSize(); p++)
150 {
151 m_geom->func(p)->piece(m_index).eval_into(u,tmp);
152 result += tmp;
153 }
154 }
155
157 void deriv_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const
158 {
159 gsMatrix<T> tmp;
160 m_geom->func(0)->piece(m_index).deriv_into(u,result);
161 for (index_t p = 1; p!=m_geom->funcSize(); p++)
162 {
163 m_geom->func(p)->piece(m_index).deriv_into(u,tmp);
164 result += tmp;
165 }
166
167 }
168
170 void deriv2_into(const gsMatrix<T> & u, gsMatrix<T>& result ) const
171 {
172 gsMatrix<T> tmp;
173 m_geom->func(0)->piece(m_index).deriv2_into(u,result);
174 for (index_t p = 1; p!=m_geom->funcSize(); p++)
175 {
176 m_geom->func(p)->piece(m_index).deriv2_into(u,tmp);
177 result += tmp;
178 }
179
180 }
181
184 void evalAllDers_into(const gsMatrix<T> & u, int n, std::vector<gsMatrix<T> >& result) const
185 {
186 std::vector<gsMatrix<T> > tmp;
187 m_geom->func(0)->piece(m_index).evalAllDers_into(u,n,result);
188 for (index_t p = 1; p!=m_geom->funcSize(); p++)
189 {
190 m_geom->func(p)->piece(m_index).evalAllDers_into(u,n,tmp);
191 for (size_t k = 0; k!=result.size(); k++)
192 {
193 result[k] += tmp[k];
194 }
195 }
196 }
198
199 GISMO_CLONE_FUNCTION(gsFunctionPieceSum)
200
201 std::ostream &print(std::ostream &os) const
202 {
203 for (index_t p = 0; p!= m_geom->funcSize(); p++)
204 gsInfo<<" function "<<p<<":\n"<<m_geom->func(p)->piece(m_index)<<"\n";
205 return os;
206 }
207
208protected:
209 const gsFunctionSum<T> * m_geom;
210 const index_t m_index;
211 gsMatrix<T> m_support;
212
213};
214
215} // namespace gismo
virtual void evalAllDers_into(const gsMatrix< T > &u, int n, std::vector< gsMatrix< T > > &result, bool sameElement=false) const
Evaluate the nonzero functions and their derivatives up to order n at points u into result.
Definition gsFunctionSet.hpp:81
#define short_t
Definition gsConfig.h:35
#define index_t
Definition gsConfig.h:32
#define gsInfo
Definition gsDebug.h:43
#define GISMO_ASSERT(cond, message)
Definition gsDebug.h:89
This is the interface of all objects that computes functions on points like gsBasis,...
The G+Smo namespace, containing all definitions for the library.