Nektar++
Loading...
Searching...
No Matches
CADAssociation.cpp
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////////////
2//
3// File: CADAssociation.cpp
4//
5// For more information, please see: http://www.nektar.info/
6//
7// The MIT License
8//
9// Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10// Department of Aeronautics, Imperial College London (UK), and Scientific
11// Computing and Imaging Institute, University of Utah (USA).
12//
13// Permission is hereby granted, free of charge, to any person obtaining a
14// copy of this software and associated documentation files (the "Software"),
15// to deal in the Software without restriction, including without limitation
16// the rights to use, copy, modify, merge, publish, distribute, sublicense,
17// and/or sell copies of the Software, and to permit persons to whom the
18// Software is furnished to do so, subject to the following conditions:
19//
20// The above copyright notice and this permission notice shall be included
21// in all copies or substantial portions of the Software.
22//
23// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29// DEALINGS IN THE SOFTWARE.
30//
31// Description: Association between mesh entities and the CAD they lie on.
32//
33////////////////////////////////////////////////////////////////////////////////
34
35#include <algorithm>
36
40
42{
43
44namespace
45{
46/// Returned by GetLinks() for an entity with no association, so that callers
47/// may iterate without first testing for presence.
48const std::vector<CADLink> g_noLinks;
49} // namespace
50
51const std::vector<CADLink> &CADAssociation::GetLinks(const Geometry *geom) const
52{
53 auto it = m_links.find(geom);
54 return it == m_links.end() ? g_noLinks : it->second;
55}
56
57std::vector<CADLink> CADAssociation::GetLinks(const Geometry *geom,
58 CADType::cadType t) const
59{
60 std::vector<CADLink> ret;
61 for (auto &link : GetLinks(geom))
62 {
63 if (link.Type() == t)
64 {
65 ret.push_back(link);
66 }
67 }
68 return ret;
69}
70
72{
73 size_t cnt = 0;
74 for (auto &link : GetLinks(geom))
75 {
76 cnt += (link.Type() == t) ? 1 : 0;
77 }
78 return cnt;
79}
80
82 int cadId) const
83{
84 for (auto &link : GetLinks(geom))
85 {
86 if (link.Type() == t && link.Id() == cadId)
87 {
88 return &link;
89 }
90 }
91 return nullptr;
92}
93
95 CADType::cadType t) const
96{
97 for (auto &link : GetLinks(geom))
98 {
99 if (link.Type() == t)
100 {
101 return &link;
102 }
103 }
104 return nullptr;
105}
106
108{
109 const CADLink *link = GetLink(geom, CADType::eSurf);
110 return link == nullptr ? CADSurfSharedPtr()
111 : std::static_pointer_cast<CADSurf>(link->obj);
112}
113
115{
116 const CADLink *link = GetLink(geom, CADType::eCurve);
117 return link == nullptr ? CADCurveSharedPtr()
118 : std::static_pointer_cast<CADCurve>(link->obj);
119}
120
122{
123 const CADLink *link = GetLink(geom, CADType::eVert);
124 return link == nullptr ? CADVertSharedPtr()
125 : std::static_pointer_cast<CADVert>(link->obj);
126}
127
128std::vector<CADSurfSharedPtr> CADAssociation::GetSurfs(
129 const Geometry *geom) const
130{
131 std::vector<CADSurfSharedPtr> ret;
132 for (auto &link : GetLinks(geom))
133 {
134 if (link.Type() == CADType::eSurf)
135 {
136 ret.push_back(std::static_pointer_cast<CADSurf>(link.obj));
137 }
138 }
139 return ret;
140}
141
142std::vector<CADCurveSharedPtr> CADAssociation::GetCurves(
143 const Geometry *geom) const
144{
145 std::vector<CADCurveSharedPtr> ret;
146 for (auto &link : GetLinks(geom))
147 {
148 if (link.Type() == CADType::eCurve)
149 {
150 ret.push_back(std::static_pointer_cast<CADCurve>(link.obj));
151 }
152 }
153 return ret;
154}
155
156std::array<NekDouble, 2> CADAssociation::GetSurfUV(const Geometry *geom,
157 int cadId) const
158{
159 const CADLink *link = GetLink(geom, CADType::eSurf, cadId);
160 ASSERTL0(link != nullptr,
161 "The desired CADSurf is not associated with this entity.");
162 return link->param;
163}
164
165NekDouble CADAssociation::GetCurveT(const Geometry *geom, int cadId) const
166{
167 const CADLink *link = GetLink(geom, CADType::eCurve, cadId);
168 ASSERTL0(link != nullptr,
169 "The desired CADCurve is not associated with this entity.");
170 return link->param[0];
171}
172
173void CADAssociation::Add(const Geometry *geom, CADLink link)
174{
175 ASSERTL1(link.obj != nullptr, "Cannot associate a null CAD object.");
176
177 auto &links = m_links[geom];
178 for (auto &existing : links)
179 {
180 // One link per distinct CAD object: overwrite the parametric position
181 // if this CAD object is already present.
182 if (existing.Type() == link.Type() && existing.Id() == link.Id())
183 {
184 existing = std::move(link);
185 return;
186 }
187 }
188 links.push_back(std::move(link));
189}
190
191void CADAssociation::Set(const Geometry *geom, CADLink link)
192{
193 ASSERTL1(link.obj != nullptr, "Cannot associate a null CAD object.");
194
195 CADType::cadType t = link.Type();
196 auto &links = m_links[geom];
197
198 links.erase(std::remove_if(links.begin(), links.end(),
199 [t](const CADLink &existing) {
200 return existing.Type() == t;
201 }),
202 links.end());
203 links.push_back(std::move(link));
204}
205
207{
208 m_links.erase(geom);
209
210 // Curvature nodes are owned by the curve attached to this geometry, so they
211 // die with it; drop their associations too. Nothing else holds them, so a
212 // caller could not reasonably be expected to find them itself. Note that
213 // Geometry::GetCurve() is fatal for anything without a shape dimension.
214 if (geom->GetShapeDim() < 1)
215 {
216 return;
217 }
218
219 if (Curve *curve = geom->GetCurve(); curve != nullptr)
220 {
221 for (auto *pt : curve->m_points)
222 {
223 m_links.erase(pt);
224 }
225 }
226}
227
229{
230 for (auto it = m_links.begin(); it != m_links.end();)
231 {
232 if (it->first->GetShapeDim() > 0)
233 {
234 ++it;
235 continue;
236 }
237
238 auto &links = it->second;
239 links.erase(std::remove_if(
240 links.begin(), links.end(),
241 [t](const CADLink &link) { return link.Type() == t; }),
242 links.end());
243
244 it = links.empty() ? m_links.erase(it) : std::next(it);
245 }
246}
247
248} // namespace Nektar::SpatialDomains
#define ASSERTL0(condition, msg)
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
CADVertSharedPtr GetVert(const Geometry *geom) const
The CAD vertex geom coincides with, or nullptr.
const CADLink * GetLink(const Geometry *geom, CADType::cadType t, int cadId) const
The link to the CAD object of type t and ID cadId, or nullptr if geom is not associated with it.
size_t Count(const Geometry *geom, CADType::cadType t) const
Number of CAD objects of type t that geom is associated with.
std::unordered_map< const Geometry *, std::vector< CADLink > > m_links
CADCurveSharedPtr GetCurve(const Geometry *geom) const
The first CAD curve geom lies on, or nullptr.
CADSurfSharedPtr GetSurf(const Geometry *geom) const
The first CAD surface geom lies on, or nullptr.
std::array< NekDouble, 2 > GetSurfUV(const Geometry *geom, int cadId) const
The of geom on the CAD surface of ID cadId.
void ClearVertLinks(CADType::cadType t)
Drop links of type t from zero-dimensional entities (vertices and curvature nodes),...
std::vector< CADSurfSharedPtr > GetSurfs(const Geometry *geom) const
All CAD surfaces geom lies on.
const std::vector< CADLink > & GetLinks(const Geometry *geom) const
All links held by geom, in insertion order.
void Add(const Geometry *geom, CADLink link)
Associate geom with the CAD object in link.
void Remove(Geometry *geom)
Drop every association held by geom.
void Set(const Geometry *geom, CADLink link)
Associate geom with link, replacing any link it already holds of the same CAD type.
NekDouble GetCurveT(const Geometry *geom, int cadId) const
The of geom on the CAD curve of ID cadId.
std::vector< CADCurveSharedPtr > GetCurves(const Geometry *geom) const
All CAD curves geom lies on.
int GetShapeDim() const
Dimension of the shape itself, which may be less than GetCoordim().
Definition Geometry.h:557
virtual Curve * GetCurve()
The curvature attached to this object, or nullptr if it is straight-sided. Only valid for shapes that...
Definition Geometry.h:238
std::shared_ptr< CADCurve > CADCurveSharedPtr
Definition CADCurve.h:247
std::shared_ptr< CADVert > CADVertSharedPtr
Definition CADCurve.h:49
std::shared_ptr< CADSurf > CADSurfSharedPtr
Definition CADCurve.h:51