G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsBarrierPatch.hpp
Go to the documentation of this file.
1 
17 #pragma once
18 
20 
21 namespace gismo
22 {
37 template<short_t d, typename T>
40  const gsDofMapper &mapper)
41  : m_mp(mp), m_mb(mp)
42 {
43  // Input data sanity check
44  if (mp.empty() || !mapper.freeSize()) {
45  throw std::invalid_argument("Invalid input to gsBarrierPatch constructor");
46  }
47 
48  // Set the default options
49  this->defaultOptions();
50 
51  // Set the mapper
52  this->setMapper(mapper);
53 }
54 
56 template<short_t d, typename T>
58  : m_mp(mp), m_mb(mp)
59 {
60  // Input data sanity check
61  if (mp.empty()) {
62  throw std::invalid_argument("Invalid multi-patch input to gsBarrierPatch constructor");
63  }
64 
65  // Set the default options
66  this->defaultOptions();
67 
68  // Depending on patchWise flag, choose the appropriate mapper method
69  if (patchWise) {
70  // make mapper that also fixes interfaces
71  m_freeInterface = 0;
72  } else {
73  // make mapper that free interfaces
75  }
76 }
77 
78 // // vertex constructor
79 // template<short_t d, typename T>
80 // gsBarrierPatch<d, T>::gsBarrierPatch( const gsMultiPatch<T> &mp, std::vector<patchCorner> corners, index_t offset)
81 // {
82 // this->defaultOptions();
83 // // make mapper that fixes a ring around vertices
84 // // _makeMapper();
85 // }
86 
87 // // interface constructor
88 // template<short_t d, typename T>
89 // gsBarrierPatch<d, T>::gsBarrierPatch( const gsMultiPatch<T> &mp, std::vector<boundaryInterface> ifaces, index_t offset)
90 // {
91 // this->defaultOptions();
92 // // make mapper that fixes an offset around sides
93 // // _makeMapper();
94 // }
95 
97 template<short_t d, typename T>
99 {
100  // Preprocessing: Scale the computational domain to [0,1]^d for better
101  // numerical stability and to have consistent convergence criteria.
102  gsMatrix<T> boundingBox;
103  m_mp.boundingBox(boundingBox);
104  gsVector<T, d> bbmin = boundingBox.col(0);
105  gsVector<T, d> bbmax = boundingBox.col(1);
106  T maxside = (bbmax-bbmin).maxCoeff();
107 
108  gsVector<T, d> scaleFactor(d);
109  scaleFactor.setConstant(m_boxsize/maxside);
110 
111  // Apply transformation (translation and scaling) to the patches
112  for (auto &patch:m_mp) {
113  patch->translate(-bbmin);
114  patch->scale(scaleFactor);
115  }
116 
117  // Start parameterization construction.
118  gsStopwatch timer;
119  switch (m_freeInterface)
120  {
121  case 0:
122  {
123  // Construct analysis-suitable parameterization piecewise.
124  for (size_t iptch = 0; iptch < m_mp.nPatches(); ++iptch)
125  {
126  gsInfo << "Parameterizing " << iptch
127  << "-th patch. Total number of patches is "
128  << m_mp.nPatches() << ".\n";
129 
130  gsDofMapper currMapper = _makeMapperOnePatch(m_mp.patch(iptch));
131  gsMultiPatch<T> optCurrPatch = gsBarrierCore<d, T>::compute(m_mp.patch(iptch),
132  currMapper,
133  m_options);
134 
135  m_mp.patch(iptch).setCoefs(optCurrPatch.patch(0).coefs());
136  }
137  break;
138  }
139  case 1:
140  {
141  // Construct analysis-suitable parameterization with moving interfaces.
142  m_mp = gsBarrierCore<d, T>::compute(m_mp, m_mapper, m_options);
143  break;
144  }
145  }
146 
147  gsInfo << "\nParameterization construction completed. Running time: " << timer.stop() << ".\n";
148 
149  // Restore scale to the original size of the input model.
150  for (auto &isf:scaleFactor) {
151  isf = 1./isf;
152  }
153 
154  for (auto &ptch:m_mp) {
155  ptch->scale(scaleFactor);
156  ptch->translate(bbmin);
157  }
158 }
159 
161  // calling the defaultOptions method of gsBarrierCore.
162  template<short_t d, typename T>
164  {
166  }
167 
169 template<short_t d, typename T>
171 {
172  // Initiate the mapper for the design Degrees of Freedom (DoFs)
173  m_mapper.init(m_mb, m_mp.targetDim());
174 
175  // For each patch, we mark the boundary in each target dimension
176  for (size_t iptch = 0; iptch != m_mp.nPatches(); iptch++)
177  {
178  gsMatrix<index_t> idx = m_mp.basis(iptch).allBoundary();
179  for (index_t idim = 0; idim != m_mp.targetDim(); idim++)
180  {
181  m_mapper.markBoundary(iptch, idx, idim);
182  }
183  }
184 
185  // Finalize the mapper after marking all boundaries
186  m_mapper.finalize();
187 
188  logMapperInformation();
189 }
190 
192 template<short_t d, typename T>
194 {
195  // Initiate the mapper for the design Degrees of Freedom (DoFs)
196  // In this method, we set all the inner control points as optimization variables
197  // However, it is also possible to set only a part of them as optimization variables
198  m_mapper.init(m_mb, m_mp.targetDim());
199 
200  // Iterate over each patch to mark the boundary in each target dimension
201  for (gsMultiPatch<>::const_biterator bit = m_mp.bBegin();
202  bit != m_mp.bEnd(); ++bit)
203  {
204  gsMatrix<index_t> idx = m_mb.basis(bit->patch).allBoundary();
205  for (index_t idim = 0; idim != m_mp.targetDim(); ++idim)
206  {
207  m_mapper.markBoundary(bit->patch, idx, idim);
208  }
209  }
210 
211  // Finalize the mapper after marking all boundaries
212  m_mapper.finalize();
213 
214  logMapperInformation();
215 }
216 
217 template<short_t d, typename T>
219 {
220  // Initiate the mapper for the design Degrees of Freedom (DoFs)
221  // We're setting all the inner control points as optimization variables
222  // However, it's also possible to set only a part of them as optimization variables
223  m_mapper.init(m_mb, m_mp.targetDim());
224 
225  // Ensure C^0 continuity at the interface by mapping equivalent degrees of freedom
226  for (gsBoxTopology::const_iiterator it = m_mb.topology().iBegin();
227  it != m_mb.topology().iEnd(); ++it) // C^0 at the interface
228  {
229  m_mb.matchInterface(*it, m_mapper);
230  }
231 
232  // Mark the boundary in each target dimension for each patch
233  for (gsMultiPatch<>::const_biterator bit = m_mp.bBegin();
234  bit != m_mp.bEnd(); ++bit)
235  {
236  gsMatrix<index_t> idx = m_mb.basis(bit->patch).boundary(bit->index());
237  for (index_t idim = 0; idim != m_mp.targetDim(); ++idim)
238  {
239  m_mapper.markBoundary(bit->patch, idx, idim);
240  }
241  }
242 
243  // Finalize the mapper after marking all boundaries
244  m_mapper.finalize();
245 
246  logMapperInformation();
247 }
248 
249 template<short_t d, typename T>
251 {
252  // Initialize the mapper for the design Degrees of Freedom (DoFs)
253  // By default, all the inner control points are set as optimization variables
254  // However, it's also possible to set only a part of them as optimization variables
255  gsDofMapper mapper;
256  gsMultiBasis<T> mb(currPatch);
257  mapper.init(mb, currPatch.targetDim());
258 
259  // Mark the boundary in each target dimension
260  gsMatrix<index_t> idx = currPatch.basis().allBoundary();
261  for (index_t idim = 0; idim != m_mp.targetDim(); ++idim)
262  {
263  mapper.markBoundary(0, idx, idim);
264  }
265 
266  // Finalize the mapper after marking all boundaries
267  mapper.finalize();
268 
269  // Return the generated mapper
270  return mapper;
271 }
272 
273 template<short_t d, typename T>
275  gsDebug << "#Number of free variables: " << m_mapper.freeSize() << "\n";
276  gsDebug << "#Number of fixed variables: " << m_mapper.boundarySize() << "\n";
277  gsDebug << "#Total number of variables: " << m_mapper.size() << "\n\n\n";
278 }
279 
280 }// namespace gismo
void init(const gsMultiBasis< T > &bases, index_t nComp=1)
Initialize by a gsMultiBasis.
Definition: gsDofMapper.hpp:20
Abstract base class representing a geometry map.
Definition: gsGeometry.h:92
void defaultOptions()
Sets the default options.
Definition: gsBarrierPatch.hpp:163
#define gsDebug
Definition: gsDebug.h:61
void _makeMapperLocalPatches()
Creates a mapper for local patches.
Definition: gsBarrierPatch.hpp:193
#define index_t
Definition: gsConfig.h:32
Maintains a mapping from patch-local dofs to global dof indices and allows the elimination of individ...
Definition: gsDofMapper.h:68
gsBarrierPatch(const gsMultiPatch< T > &mp, const gsDofMapper &mapper)
Constructs the object using a given multi-patch and a degree of freedom mapper.
Definition: gsBarrierPatch.hpp:39
gsDofMapper _makeMapperOnePatch(const gsGeometry< T > &currPatch) const
Creates a mapper for a single patch.
Definition: gsBarrierPatch.hpp:250
void finalize()
Must be called after all boundaries and interfaces have been marked to set up the dof numbering...
Definition: gsDofMapper.cpp:240
void markBoundary(index_t k, const gsMatrix< index_t > &boundaryDofs, index_t comp=0)
Mark the local dofs boundaryDofs of patch k as eliminated.
Definition: gsDofMapper.cpp:188
void _makeMapper()
Creates a mapper.
Definition: gsBarrierPatch.hpp:170
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
static gsMultiPatch< T > compute(const gsMultiPatch< T > &mp, const gsDofMapper &mapper, const gsOptionList &options)
construct analysis-suitable parameterization
Definition: gsBarrierCore.hpp:129
#define gsInfo
Definition: gsDebug.h:43
double stop()
Return elapsed time in seconds.
Definition: gsStopwatch.h:83
void setMapper(const gsDofMapper &mapper)
Sets the mapper.
Definition: gsBarrierPatch.h:48
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
A Stopwatch object can be used to measure execution time of code, algorithms, etc.
Definition: gsStopwatch.h:72
void compute()
Computes analysis-suitable parameterizations using different methods.
Definition: gsBarrierPatch.hpp:98
static gsOptionList defaultOptions()
Default options.
Definition: gsBarrierCore.hpp:24
void _makeMapperGlobalPatches()
Creates a mapper for global patches.
Definition: gsBarrierPatch.hpp:218
void logMapperInformation()
Log information about the mapper.
Definition: gsBarrierPatch.hpp:274
short_t targetDim() const
Dimension of the ambient physical space (overriding gsFunction::targetDim())
Definition: gsGeometry.h:286
index_t freeSize() const
Returns the number of free (not eliminated) dofs.
Definition: gsDofMapper.h:436
virtual const gsBasis< T > & basis() const =0
Returns a const reference to the basis of the geometry.
This software facilitates the creation of analysis-suitable parameterizations from given boundary rep...
bool empty() const
Returns true if gsMultiPatch is empty.
Definition: gsMultiPatch.h:202