G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsC1SurfVisitorBasisEdge.h
1 
14 #pragma once
15 
16 #include <gsUnstructuredSplines/src/gsC1SurfGluingData.h>
17 
18 namespace gismo
19 {
20  template <class T>
21  class gsC1SurfVisitorBasisEdge
22  {
23  public:
24 
25  gsC1SurfVisitorBasisEdge()
26  {
27  }
28 
29  void initialize(const gsBasis<T> & basis, //
30  gsQuadRule<T> & rule)
31  {
32  gsVector<index_t> numQuadNodes( basis.dim() );
33  for (index_t i = 0; i < basis.dim(); ++i) // to do: improve
34  numQuadNodes[i] = basis.degree(i) + 1;
35 
36  // Setup Quadrature
37  rule = gsGaussRule<T>(numQuadNodes);// NB!
38 
39  // Set Geometry evaluation flags
40  md.flags = NEED_MEASURE ;
41  }
42 
43  // Evaluate on element.
44  inline void evaluate(const index_t bfID,
45  std::string typeBf,
46  gsBasis<T> & basis, //
47  gsBasis<T> & basis_geo,
48  gsBasis<T> & basis_plus,
49  gsBasis<T> & basis_minus,
50  const gsGeometry<T> & geo, // patch
51  gsMatrix<T> & quNodes,
52  index_t & uv,
53  gsC1SurfGluingData<T> & gluingData,
54  bool & isBoundary)
55  {
56  md.points = quNodes;
57 
58  // Compute the active basis functions
59  // Assumes actives are the same for all quadrature points on the elements
60  basis.active_into(md.points.col(0), actives);
61 
62  // Evaluate basis functions on element
63  basis.eval_into(md.points, basisData);
64 
65  // Compute geometry related values
66  geo.computeMap(md);
67 
68  numActive = actives.rows();
69 
70  // tau/p
71  gsBSplineBasis<T> bsp_temp = dynamic_cast<gsBSplineBasis<T> & >(basis_geo);
72 
73  T p = basis_geo.maxDegree();
74  T tau_1 = bsp_temp.knots().at(p + 2);
75 
76  gsMatrix<T> alpha, beta,
77  N_0, N_1,
78  N_j_minus, N_i_plus,
79  der_N_i_plus;
80 
81 
82  if (uv == 1) // edge is in v-direction
83  {
84 
85  alpha = gluingData.evalAlpha_R(md.points.bottomRows(1));
86  beta = gluingData.evalBeta_R(md.points.bottomRows(1));
87 
88  basis_geo.evalSingle_into(0,md.points.topRows(1),N_0); // u
89  basis_geo.evalSingle_into(1,md.points.topRows(1),N_1); // u
90 
91  // Initialize local matrix/rhs
92  if (typeBf == "plus")
93  {
94  basis_plus.evalSingle_into(bfID,md.points.bottomRows(1),N_i_plus); // v
95  basis_plus.derivSingle_into(bfID,md.points.bottomRows(1),der_N_i_plus);
96 
97 
98  beta = isBoundary ? beta.setZero() : beta; // For the boundary, only on Patch 0
99 
100  gsMatrix<T> temp = beta.cwiseProduct(N_1);
101  rhsVals = N_i_plus.cwiseProduct(N_0 + N_1) - temp.cwiseProduct(der_N_i_plus) * tau_1 / p;
102 
103  localMat.setZero(numActive, numActive);
104  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
105 
106  } // n_plus
107  else if (typeBf == "minus")
108  {
109  basis_minus.evalSingle_into(bfID,md.points.bottomRows(1),N_j_minus); // v
110 
111 
112  alpha = isBoundary ? alpha.setOnes() : alpha; // For the boundary, only on Patch 0
113 
114  rhsVals = alpha.cwiseProduct(N_j_minus.cwiseProduct(N_1));
115 
116  localMat.setZero(numActive, numActive);
117  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
118  } // n_minus
119 
120  } // Patch 0
121  else if (uv == 0) // edge is in u-direction
122  {
123 
124  alpha = gluingData.evalAlpha_L(md.points.topRows(1));
125  beta = gluingData.evalBeta_L(md.points.topRows(1));
126 
127  basis_geo.evalSingle_into(0,md.points.bottomRows(1),N_0); // v
128  basis_geo.evalSingle_into(1,md.points.bottomRows(1),N_1); // v
129 
130  // Initialize local matrix/rhs
131  if (typeBf == "plus")
132  {
133  basis_plus.evalSingle_into(bfID,md.points.topRows(1),N_i_plus); // u
134  basis_plus.derivSingle_into(bfID,md.points.topRows(1),der_N_i_plus);
135 
136  beta = isBoundary ? beta.setZero() : beta; // For the boundary, only on Patch 0
137 
138  gsMatrix<T> temp = beta.cwiseProduct(N_1);
139  rhsVals = N_i_plus.cwiseProduct(N_0 + N_1) - temp.cwiseProduct(der_N_i_plus) * tau_1 / p;
140 
141  localMat.setZero(numActive, numActive);
142  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
143 
144  } // n_tilde
145  else if (typeBf == "minus")
146  {
147  basis_minus.evalSingle_into(bfID,md.points.topRows(1),N_j_minus); // u
148 
149 
150  alpha = isBoundary ? alpha.setOnes() : alpha; // For the boundary, only on Patch 0
151 
152  rhsVals = - alpha.cwiseProduct(N_j_minus.cwiseProduct(N_1));
153 
154  localMat.setZero(numActive, numActive);
155  localRhs.setZero(numActive, rhsVals.rows());//multiple right-hand sides
156  } // n_bar
157 
158  } // Patch 1
159  } // evaluate1
160 
161  inline void assemble(gsDomainIterator<T> & element,
162  const gsVector<T> & quWeights)
163  {
164  gsMatrix<T> & basisVals = basisData;
165 
166  // ( u, v)
167  localMat.noalias() =
168  basisData * quWeights.asDiagonal() *
169  md.measures.asDiagonal() * basisData.transpose();
170 
171  for (index_t k = 0; k < quWeights.rows(); ++k) // loop over quadrature nodes
172  {
173  // Multiply weight by the geometry measure
174  const T weight = quWeights[k] * md.measure(k);
175  localRhs.noalias() += weight * (basisVals.col(k) * rhsVals.col(k).transpose());
176  }
177 
178  }
179 
180  inline void localToGlobal(const index_t patchIndex,
181  const std::vector<gsMatrix<T> > & eliminatedDofs,
182  gsSparseSystem<T> & system)
183  {
184  // Map patch-local DoFs to global DoFs
185  system.mapColIndices(actives, patchIndex, actives);
186  // Add contributions to the system matrix and right-hand side
187  system.push(localMat, localRhs, actives, eliminatedDofs[0], 0, 0);
188  }
189 
190  protected:
191  gsMatrix<index_t> actives;
192  gsMatrix<T> basisData;
193  index_t numActive;
194 
195  protected:
196  // Local values of the right hand side
197  gsMatrix<T> rhsVals;
198 
199  protected:
200  // Local matrices
201  gsMatrix<T> localMat;
202  gsMatrix<T> localRhs;
203 
204  gsMapData<T> md;
205 
206  }; // class gsVisitorG1BasisEdge
207 } // namespace gismo
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
Class representing a reference quadrature rule.
Definition: gsQuadRule.h:28
void mapColIndices(const gsMatrix< index_t > &actives, const index_t patchIndex, gsMatrix< index_t > &result, const index_t c=0) const
mapColIndices Maps a set of basis indices by the corresponding dofMapper.
Definition: gsSparseSystem.h:584
virtual void computeMap(gsMapData< T > &InOut) const
Computes map function data.
Definition: gsFunction.hpp:822
virtual void derivSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the (partial) derivatives of the i-th basis function at points u into result.
Definition: gsBasis.hpp:455
virtual short_t degree(short_t i) const
Degree with respect to the i-th variable. If the basis is a tensor product of (piecewise) polynomial ...
Definition: gsBasis.hpp:650
the gsMapData is a cache of pre-computed function (map) values.
Definition: gsFuncData.h:324
#define index_t
Definition: gsConfig.h:32
void push(const gsMatrix< T > &localMat, const gsMatrix< T > &localRhs, const gsMatrix< index_t > &actives, const gsMatrix< T > &eliminatedDofs, const size_t r=0, const size_t c=0)
push pushes the local system matrix and rhs for an element to the global system,
Definition: gsSparseSystem.h:972
A univariate B-spline basis.
Definition: gsBSplineBasis.h:694
const KnotVectorType & knots(int i=0) const
Returns the knot vector of the basis.
Definition: gsBSplineBasis.h:369
Class which enables iteration over all elements of a parameter domain.
Definition: gsDomainIterator.h:67
virtual void evalSingle_into(index_t i, const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluate the i-th basis function at points u into result.
Definition: gsBasis.hpp:447
The density of the measure pull back.
Definition: gsForwardDeclarations.h:76
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates nonzero basis functions at point u into result.
Definition: gsBasis.hpp:443
virtual short_t maxDegree() const
If the basis is of polynomial or piecewise polynomial type, then this function returns the maximum po...
Definition: gsBasis.hpp:638
Class that represents the (tensor) Gauss-Legendre quadrature rule.
Definition: gsGaussRule.h:27
A basis represents a family of scalar basis functions defined over a common parameter domain...
Definition: gsBasis.h:78
virtual void active_into(const gsMatrix< T > &u, gsMatrix< index_t > &result) const
Returns the indices of active basis functions at points u, as a list of indices, in result...
Definition: gsBasis.hpp:293