G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsC1SurfGluingData.h
1 
14 #pragma once
15 
17 #include <gsUnstructuredSplines/src/gsC1SurfGluingDataAssembler.h>
20 
21 
22 namespace gismo
23 {
24 
25 template<class T, class Visitor = gsC1SurfGluingDataVisitor<T>>
26 class gsC1SurfGluingData : public gsC1SurfGD<T>
27 {
28 
29 public:
30  gsC1SurfGluingData()
31  {
32  setGDEdge();
33  }
34 
35  gsC1SurfGluingData(gsMultiPatch<T> const & mp,
36  gsMultiBasis<T> & mb)
37  : gsC1SurfGD<T>(mp, mb)
38  {
39  // Solve the system for alpha_L and alpha_R and beta
40  refresh();
41  assemble();
42  solve();
43 
44  // Solve the system for beta_L and beta_R
45  refreshBeta();
46  assembleBeta();
47  solveBeta();
48  }
49 
50  gsMatrix<T> evalAlpha_R(gsMatrix<T> points)
51  {
52  gsMatrix<T> ones(1, points.cols());
53  ones.setOnes();
54  return sol.row(0) * ( ones - points ) + sol.row(1) * points;
55  }
56 
57  gsMatrix<T> evalAlpha_L(gsMatrix<T> points)
58  {
59  gsMatrix<T> ones(1, points.cols());
60  ones.setOnes();
61  return sol.row(2) * ( ones - points ) + sol.row(3) * points;
62  }
63 
64  gsMatrix<T> evalBeta_R(gsMatrix<T> points)
65  {
66  gsMatrix<T> ones(1, points.cols());
67  ones.setOnes();
68  return solBeta.row(0) * ( ones - points ) + solBeta.row(1) * points;
69  }
70 
71  gsMatrix<T> evalBeta_L(gsMatrix<T> points)
72  {
73  gsMatrix<T> ones(1, points.cols());
74  ones.setOnes();
75  return solBeta.row(2) * ( ones - points ) + solBeta.row(3) * points;
76  }
77 
78  gsMatrix<T> evalBeta(gsMatrix<T> points)
79  {
80  gsMatrix<T> ones(1, points.cols());
81  ones.setOnes();
82  return sol.row(4) * ( ones - points ).cwiseProduct( ones - points)
83  + sol.row(5) * ( ones - points ).cwiseProduct(points) + sol.row(6) * points;
84  }
85 
86  gsMatrix<T> getSol(){ return sol; }
87 
88  gsMatrix<T> getSolBeta(){ return solBeta; }
89 
90 
91 
92 protected:
93 
94  gsSparseSystem<T> mSys;
95  gsSparseSystem<T> mSysBeta;
96  gsMatrix<T> dirichletDofs;
97  gsMatrix<T> dirichletDofsBeta;
98 
99  gsMatrix<T> sol; // In order, it contains: alpha_0L, alpha_1L, alpha_0R, alpha_1R, beta_0, beta_1, beta_2
100  // to construct the linear combination of the GD:
101  // alpha_L = ( 1 - t ) * alpha_0L + alpha_1L * t
102  // alpha_R = ( 1 - t ) * alpha_0R + alpha_1R * t
103  //beta = ( 1 - t )^2 * beta_0 + 2 * t * ( 1 - t ) * beta_1 + t^2 * beta_2
104 
105  gsMatrix<T> solBeta;
106 
107  void refresh()
108  {
109  gsVector<index_t> size(1);
110  size << 7;
111 
112  gsDofMapper map(size);
113  map.finalize();
114 
115  gsSparseSystem<T> sys(map);
116  mSys = sys;
117  }
118 
119  void refreshBeta()
120  {
121  gsVector<index_t> size(1);
122  size << 4;
123 
124  gsDofMapper mapBeta(size);
125  mapBeta.finalize();
126 
127  gsSparseSystem<T> sysBeta(mapBeta);
128  mSysBeta = sysBeta;
129  }
130 
131  void assemble()
132  {
133  mSys.reserve(49, 1); // Reserve for the matrix 7x7 values
134 
135  dirichletDofs.setZero(mSys.colMapper(0).boundarySize(),1);
136 
137  // Assemble volume integrals
138  Visitor visitor;
139  apply(visitor);
140 
141  mSys.matrix().makeCompressed();
142  }
143 
144  void assembleBeta()
145  {
146  mSysBeta.reserve(16, 1); // Reserve for the matrix 4x4 values
147 
148  dirichletDofsBeta.setZero(mSysBeta.colMapper(0).boundarySize(), 1);
149 
150  // Assemble volume integrals
151  Visitor visitorBeta;
152  applyBeta(visitorBeta);
153 
154  mSysBeta.matrix().makeCompressed();
155  }
156 
157  void apply(Visitor visitor)
158  {
159  #pragma omp parallel
160  {
161  Visitor
162  #ifdef _OPENMP
163  // Create thread-private visitor
164  visitor_(visitor);
165  const int tid = omp_get_thread_num();
166  const int nt = omp_get_num_threads();
167  #else
168  &visitor_ = visitor;
169  #endif
170  gsQuadRule<T> quRule ; // Quadrature rule
171  gsMatrix<T> quNodes ; // Temp variable for mapped nodes
172  gsVector<T> quWeights; // Temp variable for mapped weights
173 
174  const gsBasis<T> & basis = this->m_mb[0].basis(0).component(1); // = 0
175 
176  // Initialize reference quadrature rule and visitor data
177  visitor_.initialize(basis,quRule);
178 
179  // Initialize domain element iterator -- using unknown 0
180  typename gsBasis<T>::domainIter domIt = basis.makeDomainIterator(boundary::none);
181 
182  #ifdef _OPENMP
183  for ( domIt->next(tid); domIt->good(); domIt->next(nt) )
184  #else
185  for (; domIt->good(); domIt->next() )
186  #endif
187  {
188  // Map the Quadrature rule to the element
189  quRule.mapTo( domIt->lowerCorner(), domIt->upperCorner(), quNodes, quWeights );
190 
191  // Perform required evaluations on the quadrature nodes
192  visitor_.evaluate(quNodes, this->m_mp);
193 
194  // Assemble on element
195  visitor_.assemble(*domIt, quWeights);
196 
197  // Push to global matrix and right-hand side vector
198  #pragma omp critical(localToGlobal)
199  visitor_.localToGlobal( dirichletDofs, mSys); // omp_locks inside
200  }
201  }//omp parallel
202  }
203 
204  void applyBeta(Visitor visitorBeta)
205  {
206  #pragma omp parallel
207  {
208  Visitor
209  #ifdef _OPENMP
210  // Create thread-private visitor
211  visitor_Beta(visitorBeta);
212  const int tid = omp_get_thread_num();
213  const int nt = omp_get_num_threads();
214  #else
215  &visitor_Beta = visitorBeta;
216  #endif
217  gsQuadRule<T> quRule ; // Quadrature rule
218  gsMatrix<T> quNodes ; // Temp variable for mapped nodes
219  gsVector<T> quWeights; // Temp variable for mapped weights
220 
221  const gsBasis<T> & basis = this->m_mb[0].basis(0).component(1); // = 0
222 
223  // Initialize reference quadrature rule and visitor data
224  visitor_Beta.initialize(basis,quRule);
225 
226  // Initialize domain element iterator -- using unknown 0
227  typename gsBasis<T>::domainIter domIt = basis.makeDomainIterator(boundary::none);
228 
229  #ifdef _OPENMP
230  for ( domIt->next(tid); domIt->good(); domIt->next(nt) )
231  #else
232  for (; domIt->good(); domIt->next() )
233  #endif
234  {
235  // Map the Quadrature rule to the element
236  quRule.mapTo( domIt->lowerCorner(), domIt->upperCorner(), quNodes, quWeights );
237 
238  // Perform required evaluations on the quadrature nodes
239  visitor_Beta.evaluateBeta(quNodes, this->m_mp, sol);
240 
241  // Assemble on element
242  visitor_Beta.assembleBeta(*domIt, quWeights);
243 
244  // Push to global matrix and right-hand side vector
245  #pragma omp critical(localToGlobal)
246  visitor_Beta.localToGlobalBeta( dirichletDofsBeta, mSysBeta); // omp_locks inside
247  }
248  }//omp parallel
249  }
250 
251 
252 
253  void solve()
254  {
255  typename gsSparseSolver<T>::SimplicialLDLT solver;
256 
257  solver.compute(mSys.matrix());
258  sol = solver.solve(mSys.rhs()); // My solution
259  }
260 
261  void solveBeta()
262  {
263  typename gsSparseSolver<T>::SimplicialLDLT solver;
264 
265  solver.compute(mSysBeta.matrix());
266  solBeta = solver.solve(mSysBeta.rhs()); // My solution
267  }
268 
269  void setGDEdge()
270  {
271  gsMatrix<T> solTMP(7, 1);
272  gsMatrix<T> solBetaTMP(4, 1);
273 
274  solTMP(0, 0) = 1;
275  solTMP(1, 0) = 1;
276  solTMP(2, 0) = 1;
277  solTMP(3, 0) = 1;
278  solTMP(4, 0) = 0;
279  solTMP(5, 0) = 0;
280  solTMP(6, 0) = 0;
281 
282  solBetaTMP(0, 0) = 0;
283  solBetaTMP(1, 0) = 0;
284  solBetaTMP(2, 0) = 0;
285  solBetaTMP(3, 0) = 0;
286 
287  sol = solTMP;
288  solBeta = solBetaTMP;
289  }
290 }; // class gsGluingData
291 
292 
293 
294 } // namespace gismo
295 
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
Visitor for the Gluing Data.
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
const gsBasis< T > & basis(const index_t k) const
Helper which casts and returns the k-th piece of this function set as a gsBasis.
Definition: gsFunctionSet.hpp:33
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
virtual void mapTo(const gsVector< T > &lower, const gsVector< T > &upper, gsMatrix< T > &nodes, gsVector< T > &weights) const
Maps quadrature rule (i.e., points and weights) from the reference domain to an element.
Definition: gsQuadRule.h:177
Compute the gluing data for one interface.
virtual domainIter makeDomainIterator() const
Create a domain iterator for the computational mesh of this basis, that points to the first element o...
Definition: gsBasis.hpp:493
Reparametrize one Patch.
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78