G+Smo  24.08.0
Geometry + Simulation Modules
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
gsCPPInterface.hpp
1 
16 #pragma once
17 
18 #include <gsCore/gsMultiPatch.h>
19 #include <gsUtils/gsSortedVector.h>
22 
23 namespace gismo {
24 
25 template<class T>
27  const gsMultiBasis<T> & basis,
28  const boundaryInterface & bi,
29  const gsOptionList & opt)
30  : m_slaveGeom( &(mp[bi.first().patch ])),
31  m_masterGeom( &(mp[bi.second().patch ])),
32  m_masterBdr((mp[bi.second().patch]).boundary(bi.second())),
33  m_slaveBasis(&(basis[bi.first().patch ])),
34  m_masterBasis(&(basis[bi.second().patch])),
35  m_boundaryInterface(bi),
36  m_Tolerance(opt.getReal("Tolerance"))
37 {
38 
39  GISMO_ASSERT( m_slaveGeom->geoDim()==m_masterBdr->geoDim(), "gsCPPInterface: Dimensions do not agree." );
40 
41  m_fixedDir = m_boundaryInterface.second().direction();
42  // Index of the parametric direction which is normal to the boundary of the master surface
43  m_fixedParam = m_boundaryInterface.second().parameter();
44  // Value of the parameter in the fixed direction ( usually 0 or 1).
45  // This is constant on the entire master boundary
46 
47  // Vector with the ordered indices of directions that are 'free' i.e. not the m_fixedDir
48  for (index_t j=0; j<m_masterBdr->domainDim(); j++)
49  {
50  if (j != m_fixedDir ) { m_freeDirs.push_back(j); }
51  }
52 }
53 
54 
55 template <class T>
57 {
58  m_masterBdr = m_masterGeom->boundary(m_boundaryInterface.second());
59 }
60 
61 template <class T>
62 void gsCPPInterface<T>::eval_into(const gsMatrix<T> & u, gsMatrix<T> & result) const
63 {
64  GISMO_ASSERT( u.rows() == domainDim(), "gsCPPInterface::eval_into: "
65  "The rows of the evaluation points must be equal to the dimension of the domain." );
66 
67  gsVector<T> masterParams;
68  /* -- version with isInside check
69  gsVector<bool> isInside;
70  gsMatrix<T> slavePts, preIm;
71 
72  // Get the evaluation of u on the slave surface
73  slavePts = m_slaveGeom->eval( u );
74  //check whether slave points lie within master geometry
75  m_masterGeom->locateOn(slavePts,isInside,preIm,false,m_Tolerance);
76 
77  // Pick the relevant points only, wipe out the rest
78  index_t npts = 0;
79  for (index_t i=u.cols()-1; i>=0; --i)
80  if (isInside[i])
81  u.col(i).swap(u.col(npts++));
82  u.conservativeResize(u.rows(), npts);
83  result.resize(u.rows(), npts);
84 
85  for (index_t i=0; i<npts; i++) // For every set( column ) of parameters
86  {
87  // Find the parameters of the point of the master surface boundary,
88  // which is closest to the slavePoint
89  m_masterBdr->closestPointTo(slavePts.col(i), masterParams, m_Tolerance);
90 
91  // masterParams are 1 less than the masters' domain dimensions
92  // since only the boundary is considered in the CPP procedure
93  // but we need to return domainDim, parameters thus the following loop
94  for (size_t j=0; j<m_freeDirs.size(); j++)
95  {
96  result( m_freeDirs[j], i ) = masterParams(j);
97  }
98  result( m_fixedDir, i ) = m_fixedParam; // this param is known a priori
99  }
100 
101  */
102 
103  //--- closest point version
104  result.resizeLike(u);
105  gsVector<T> slavePoint;
106 
107  for (index_t i=0; i<u.cols(); i++) // For every set( column ) of parameters
108  {
109  // Get the evaluation of u on the slave surface
110  slavePoint = m_slaveGeom->eval( u.col(i) );
111 
112  // Find the parameters of the point of the master surface boundary,
113  // which is closest to the slavePoint
114  m_masterBdr->closestPointTo( slavePoint, masterParams, m_Tolerance);
115 
116  // masterParams are 1 less than then masters domain dimensions
117  // since only the boundary is considered in the CPP procedure
118  // but we need to return domainDim, parameters thus the following loop
119  for (size_t j=0; j<m_freeDirs.size(); j++)
120  {
121  result( m_freeDirs[j], i ) = masterParams(j);
122  }
123  result( m_fixedDir, i ) = m_fixedParam; // this param is known a priori
124  }
125  //--- closest point version
126 }
127 
128 
129 template <class T>
131 {
132  gsTensorDomainBoundaryIterator<T> * tdi = new gsTensorDomainBoundaryIterator<T> (*m_slaveBasis, m_boundaryInterface.first());
133  for (index_t i=0; i<domainDim(); ++i)
134  {
135  if (i!=m_boundaryInterface.first().direction())
136  tdi->setBreaks(m_breakpoints[i],i);
137  }
138  return typename gsDomainIterator<T>::uPtr(tdi);
139 }
140 
141 
142 template <class T>
143 std::ostream& gsCPPInterface<T>::print(std::ostream & os) const
144 {
145  os << "gsCPPInterface:"
146  << "\n First (slave) side: " << m_boundaryInterface.first()
147  << "\n Second (master) side: " << m_boundaryInterface.second();
148 
149  os << "\n";
150  return os;
151 }
152 
153 
154 } // End namespace gismo
Provides a mapping between the corresponding sides of two patches sharing an interface, by means of a closest point projection.
Definition: gsCPPInterface.h:32
gsDomainIterator< T >::uPtr makeDomainIterator() const
Returns a domain iterator.
Definition: gsCPPInterface.hpp:130
bool parameter() const
Returns the parameter value (false=0=start, true=1=end) that corresponds to this side.
Definition: gsBoundary.h:128
Struct that defines the boundary sides and corners and types of a geometric object.
Definition: gsBoundary.h:55
#define index_t
Definition: gsConfig.h:32
virtual std::ostream & print(std::ostream &os) const
Prints the state of the object.
Definition: gsCPPInterface.hpp:143
gsCPPInterface(const gsMultiPatch< T > &mp, const gsMultiBasis< T > &mb, const boundaryInterface &bi, const gsOptionList &opt=defaultOptions())
Constructor.
Definition: gsCPPInterface.hpp:26
#define GISMO_ASSERT(cond, message)
Definition: gsDebug.h:89
boundaryInterface m_boundaryInterface
Corresponding boundary interface.
Definition: gsCPPInterface.h:71
memory::unique_ptr< gsDomainIterator > uPtr
Unique pointer for gsDomainIterator.
Definition: gsDomainIterator.h:73
void setBreaks(std::vector< T > newBreaks, index_t i)
Function to set the breakpoints in direction i manually.
Definition: gsTensorDomainBoundaryIterator.h:194
Provides declaration of TensorNurbsBasis abstract interface.
Holds a set of patch-wise bases and their topology information.
Definition: gsMultiBasis.h:36
Provides declaration of the MultiPatch class.
Re-implements gsDomainIterator for iteration over all elements of the boundary of a tensor product pa...
Definition: gsTensorDomainBoundaryIterator.h:37
Fits a (closed) B-spline curve to some given data.
Container class for a set of geometry patches and their topology, that is, the interface connections ...
Definition: gsMultiPatch.h:33
An std::vector with sorting capabilities.
patchSide & second()
second, returns the second patchSide of this interface
Definition: gsBoundary.h:782
gsGeometry< T >::Ptr m_masterBdr
The boundary geometry of second patch – Master.
Definition: gsCPPInterface.h:66
Struct which represents an interface between two patches.
Definition: gsBoundary.h:649
Class which holds a list of parameters/options, and provides easy access to them. ...
Definition: gsOptionList.h:32
virtual void eval_into(const gsMatrix< T > &u, gsMatrix< T > &result) const
Evaluates the interface map.
Definition: gsCPPInterface.hpp:62
short_t direction() const
Returns the parametric direction orthogonal to this side.
Definition: gsBoundary.h:113