G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsMappedSpline.hpp
Go to the documentation of this file.
1 
15 
16 namespace gismo
17 {
18 
19 template<short_t d,class T>
20 gsMappedSpline<d,T>::gsMappedSpline( const gsMultiPatch<T> & mp, const gsSparseMatrix<T> & m )
21 {
22  GISMO_ASSERT(mp.nPatches()>0,"MultiPatch is empty?");
23  m_mbases = new gsMappedBasis<d,T>(gsMultiBasis<T>(mp),m);
24 
25  // collect and transform the coefficients
26  gsMatrix<T> local = mp.coefs();
27  m_mbases->local_coef_to_global_coef(local,m_global);
28 
29  init(*m_mbases);
30 }
31 
32 template<short_t d,class T>
33 gsMappedSpline<d,T>::gsMappedSpline( const gsMappedBasis<d,T> & mbases, const gsMatrix<T> & coefs )
34 :
35 m_global(coefs)
36 {
37  m_mbases=mbases.clone().release();
38  init(mbases);
39 }
40 
41 template<short_t d,class T>
42 gsMappedSpline<d,T>::gsMappedSpline( const gsMappedSpline& other )
43 : gsFunctionSet<T>(), m_global(other.m_global)
44 {
45  m_mbases=other.m_mbases->clone().release();
46 }
47 
48 template<short_t d,class T>
49 gsMappedSpline<d,T> & gsMappedSpline<d,T>::operator=( const gsMappedSpline& other )
50 {
51  delete m_mbases;
52  m_mbases=other.m_mbases->clone().release();
53  m_global = other.m_global;
54  m_ss = other.m_ss;
55  for (auto & s : m_ss) s.setSource(*this);
56  return *this;
57 }
58 
59 template<short_t d,class T>
60 void gsMappedSpline<d,T>::eval_into(const unsigned patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const
61 {
62  gsMatrix<index_t> actives;
63  gsMatrix<T> evals;
64 
65  index_t N = targetDim();
66  // gsC1Basis<d,t> * basis = dynamic_cast<gsC1Basis<d,t> *>(this->getBase(patch));
67  // if (basis==NULL)
68  // {
69  // m_mbases->active_into(patch,u,actives);
70  // m_mbases->eval_into(patch,u,evals);
71  // m_mbases->getBase(patch).linearCombination_into(m_coefs,actives,evals,result);
72  // }
73  // else
74  // {
75  gsMatrix<T> tmp;
76  result.resize( N,u.cols());
77  // This loop enables that the number of actives can be different for each column in u
78  for (index_t k = 0; k!=u.cols(); k++)
79  {
80  m_mbases->active_into(patch,u.col(k),actives);
81  m_mbases->eval_into(patch,u.col(k),evals);
82  m_mbases->getBase(patch).linearCombination_into(m_global,actives,evals,tmp);
83  result.col(k) = tmp;
84  }
85  // }
86 }
87 
88 template<short_t d,class T>
89 void gsMappedSpline<d,T>::deriv_into(const unsigned patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const
90 {
91  gsMatrix<index_t> actives;
92  gsMatrix<T> evals;
93 
94  index_t N = targetDim();
95  index_t M = domainDim();
96  result.resize( N * M,u.cols());
97 
98  gsMatrix<T> tmp;
99  // This loop enables that the number of actives can be different for each column in u
100  for (index_t k = 0; k!=u.cols(); k++)
101  {
102  m_mbases->active_into(patch,u.col(k),actives);
103  m_mbases->deriv_into(patch,u.col(k),evals);
104  m_mbases->getBase(patch).linearCombination_into(m_global,actives,evals,tmp);
105  result.col(k) = tmp;
106  }
107 }
108 
109 template<short_t d,class T>
110 void gsMappedSpline<d,T>::deriv2_into(const unsigned patch, const gsMatrix<T> & u, gsMatrix<T>& result ) const
111 {
112  gsMatrix<index_t> actives;
113  gsMatrix<T> evals;
114 
115  index_t N = targetDim();
116  index_t M = domainDim();
117  index_t S = M*(M+1)/2;
118  result.resize( S*N,u.cols());
119  gsMatrix<T> tmp;
120  // This loop enables that the number of actives can be different for each column in u
121  for (index_t k = 0; k!=u.cols(); k++)
122  {
123  m_mbases->active_into(patch,u.col(k),actives);
124  m_mbases->deriv2_into(patch,u.col(k),evals);
125  m_mbases->getBase(patch).linearCombination_into(m_global,actives,evals,tmp);
126  result.col(k) = tmp;
127  }
128 }
129 
130 template<short_t d,class T>
131 void gsMappedSpline<d,T>::evalAllDers_into(const unsigned patch, const gsMatrix<T> & u,
132  const int n, std::vector<gsMatrix<T> >& result,
133  bool sameElement) const
134 {
135  result.resize(n+1);
136 
137  gsMatrix<index_t> actives;
138  std::vector< gsMatrix<T> > evals;
139 
140  index_t N = targetDim();
141  index_t m = domainDim();
142  index_t S = m*(m+1)/2;
143 
144  std::vector<index_t> blocksizes(3);
145  blocksizes[0] = N;
146  blocksizes[1] = N*m;
147  blocksizes[2] = N*S;
148 
149  gsMatrix<T> tmp;
150  // todo: change the loop over i and the loop over k
151  for( int i = 0; i <= n; i++)
152  {
153  result[i].resize(blocksizes[i],u.cols());
154  // This loop enables that the number of actives can be different for each column in u
155  for (index_t k = 0; k!=u.cols(); k++)
156  {
157  m_mbases->active_into(patch,u.col(k),actives);//..
158  m_mbases->evalAllDers_into(patch,u.col(k),n,evals,sameElement);
159  m_mbases->getBase(patch).linearCombination_into(m_global,actives,evals[i],tmp);
160  result[i].col(k) = tmp;
161 
162  }
163  }
164 
165  // for( int i = 0; i <= n; i++)
166  // result[i].resize(blocksizes[i],u.cols());
167 
168  // // todo: change the loop over i and the loop over k
169  // for (index_t k = 0; k!=u.cols(); k++)
170  // {
171  // // This loop enables that the number of actives can be different for each column in u
172  // m_mbases->active_into(patch,u.col(k),actives);
173  // m_mbases->evalAllDers_into(patch,u.col(k),n,evals);
174  // for( int i = 0; i <= n; i++)
175  // {
176  // m_mbases->getBase(patch).linearCombination_into(m_global,actives,evals[i],tmp);
177  // result[i].col(k) = tmp;
178  // }
179  // }
180 }
181 
182 template<short_t d,class T>
183 gsMultiPatch<T> gsMappedSpline<d,T>::exportToPatches() const
184 {
185  gsMatrix<T> local;
186  m_mbases->global_coef_to_local_coef(m_global,local);
187  return m_mbases->exportToPatches(local);
188 }
189 
190 template<short_t d,class T>
191 gsGeometry<T> * gsMappedSpline<d,T>::exportPatch(int i,gsMatrix<T> const & localCoef) const
192 {
193  return m_mbases->exportPatch(i,localCoef);
194 }
195 
196 }
#define index_t
Definition: gsConfig.h:32
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
Provides declaration of Basis abstract interface.