FEAT 3
Finite Element Analysis Toolbox
Loading...
Searching...
No Matches
chart.hpp
1// FEAT3: Finite Element Analysis Toolbox, Version 3
2// Copyright (C) 2010 by Stefan Turek & the FEAT group
3// FEAT3 is released under the GNU General Public License version 3,
4// see the file 'copyright.txt' in the top level directory for details.
5
6#pragma once
7
8// includes, FEAT
9#include <kernel/geometry/mesh_part.hpp>
10#include <kernel/util/tiny_algebra.hpp>
11#include <kernel/util/xml_scanner.hpp>
12
13namespace FEAT
14{
15 namespace Geometry
16 {
20 namespace Atlas
21 {
30 template<typename Mesh_>
32 {
33 public:
35 typedef Mesh_ MeshType;
39 typedef typename MeshType::VertexSetType VertexSetType;
41 typedef typename VertexSetType::VertexType WorldPoint;
43 typedef typename VertexSetType::CoordType CoordType;
44
45 public:
46 ChartBase() = default;
47 ChartBase(const ChartBase&) = default;
48 ChartBase& operator=(const ChartBase&) = default;
49 virtual ~ChartBase() = default;
50
52 virtual std::size_t bytes() const
53 {
54 return std::size_t(0);
55 }
56
63 virtual bool can_explicit() const = 0;
64
71 virtual bool can_implicit() const = 0;
72
82 virtual void adapt(MeshType& mesh, const PartType& meshpart) const = 0;
83
93 virtual void adapt(PartType& mesh, const PartType& meshpart) const = 0;
94
121 virtual void transform(const WorldPoint& origin, const WorldPoint& angles, const WorldPoint& offset) = 0;
122
132 virtual WorldPoint map(const WorldPoint& param) const = 0;
133
143 virtual WorldPoint project(const WorldPoint& point) const = 0;
144
153 virtual CoordType dist(const WorldPoint& point) const = 0;
154
166 virtual CoordType dist(const WorldPoint& point, WorldPoint& grad_dist) const = 0;
167
176 virtual CoordType signed_dist(const WorldPoint& point) const = 0;
177
189 virtual CoordType signed_dist(const WorldPoint& point, WorldPoint& grad_dist) const = 0;
190
198 virtual String get_type() const = 0;
199
209 virtual void write(std::ostream& os, const String& sindent) const = 0;
210 }; // class ChartBase<...>
211
213 namespace Intern
214 {
215 template<bool enable_>
216 struct ImplicitChartHelper
217 {
218 template<typename CT_, typename MT_, typename PT_>
219 static bool adapt(const CT_&, MT_&, const PT_&)
220 {
221 return false;
222 }
223
224 template<typename CT_, typename WP_>
225 static bool project(const CT_&, WP_&)
226 {
227 return false;
228 }
229 };
230
231 template<>
232 struct ImplicitChartHelper<true>
233 {
234 template<typename CT_, typename MT_, typename PT_>
235 static bool adapt(const CT_& chart, MT_& mesh, const PT_& part)
236 {
237 // First of all, check whether the chart can really perform
238 // implicit adaption
239 if(!chart.can_implicit())
240 return false;
241
242 // Try to project the whole meshpart
243 chart.project_meshpart(mesh, part);
244
245 // okay
246 return true;
247 }
248
249 template<typename CT_, typename WP_>
250 static bool project(const CT_& chart, WP_& wp)
251 {
252 chart.project_point(wp);
253 return true;
254 }
255 };
256
257 template<bool enable_>
258 struct ExplicitChartHelper
259 {
260 template<typename CT_, typename MT_, typename PT_>
261 static bool adapt(const CT_&, MT_&, const PT_&)
262 {
263 return false;
264 }
265
266 template<typename CT_, typename WP_, typename PP_>
267 static bool map(const CT_&, WP_&, const PP_&)
268 {
269 return false;
270 }
271 };
272
273 template<>
274 struct ExplicitChartHelper<true>
275 {
276 template<typename CT_, typename MT_, typename PT_>
277 static bool adapt(const CT_& chart, MT_& mesh, const PT_& part)
278 {
279 // a world point in the mesh
280 typedef typename CT_::WorldPoint WorldPoint;
281 // a parameter point in the part
282 typedef typename CT_::ParamPoint ParamPoint;
283
284 // vertex set type of our mesh
285 typedef typename MT_::VertexSetType VertexSetType;
286
287 // attribute type of our mesh part
288 typedef typename PT_::AttributeSetType AttributeSetType;
289
290 // First of all, check whether the chart can really perform
291 // explicit adaption
292 if(!chart.can_explicit())
293 return false;
294
295 // Try to fetch the parametrization attribute.
296 const AttributeSetType* attrib = part.find_attribute("param");
297 if(attrib == nullptr)
298 return false;
299
300 // We have the attribute; check whether it matches our chart
301 int attrib_dim = attrib->get_dimension();
302 XASSERTM(attrib_dim == CT_::param_dim, "Invalid chart attribute dimension");
303
304 // Get the vertex set of the mesh
305 VertexSetType& vtx = mesh.get_vertex_set();
306
307 // Get the vertex target set of the part
308 const TargetSet& vidx = part.template get_target_set<0>();
309
310 // loop over all vertices in the mesh part
311 Index num_vtx = vidx.get_num_entities();
312 for(Index i(0); i < num_vtx; ++i)
313 {
314 // apply the chart's map function
315 chart.map_param(
316 reinterpret_cast< WorldPoint&>(vtx[vidx[i]]),
317 *reinterpret_cast<const ParamPoint*>(attrib->raw_at(i))
318 );
319 }
320
321 // okay
322 return true;
323 }
324
325 template<typename CT_, typename WP_, typename PP_>
326 static bool map(const CT_& chart, WP_& wp, const PP_& pp)
327 {
328 chart.map_param(wp, pp);
329 return true;
330 }
331 };
332 } // namespace Intern
334
351 template<typename Derived_, typename Mesh_, typename Traits_>
352 class ChartCRTP :
353 public ChartBase<Mesh_>
354 {
355 public:
359 typedef Traits_ TraitsType;
367 typedef typename MeshType::VertexSetType VertexSetType;
369 typedef typename VertexSetType::CoordType CoordType;
370
372 static constexpr bool is_explicit = TraitsType::is_explicit;
374 static constexpr bool is_implicit = TraitsType::is_implicit;
375
377 static constexpr int world_dim = TraitsType::world_dim;
379 static constexpr int param_dim = TraitsType::param_dim;
380
382 //typedef Tiny::Vector<CoordType, world_dim> WorldPoint;
386
387 protected:
393 Derived_& cast() {return static_cast<Derived_&>(*this);}
394
396 const Derived_& cast() const {return static_cast<const Derived_&>(*this);}
397
398 public:
400 virtual bool can_explicit() const override
401 {
402 return is_explicit;
403 }
404
406 virtual bool can_implicit() const override
407 {
408 return is_implicit;
409 }
410
420 virtual void adapt(MeshType& mesh, const PartType& part) const override
421 {
422 // ensure that the mesh world dimension is compatible
423 XASSERTM(MeshType::world_dim == world_dim, "Mesh/Chart world dimension mismatch");
424
425 // Try to adapt explicitly
426 if(Intern::ExplicitChartHelper<is_explicit>::adapt(cast(), mesh, part))
427 return;
428
429 // Try to adapt implicitly
430 if(Intern::ImplicitChartHelper<is_implicit>::adapt(cast(), mesh, part))
431 return;
432
433 // If we come out here, we have no way of adaption...
434 XABORTM("No mesh adaption possible!");
435 }
436
450 virtual void adapt(PartType& DOXY(parent_meshpart), const PartType& DOXY(meshpart)) const override
451 {
452 XABORTM("Adaption of MeshPart not possible yet");
453 }
454
456 virtual WorldPoint map(const WorldPoint& param) const override
457 {
458 ASSERTM(is_explicit, "cannot map point: Chart is not explicit");
459 WorldPoint wp;
460 if constexpr(!is_explicit)
461 wp = CoordType(0);
462 ParamPoint pp;
463 pp.template copy_n<param_dim>(param);
464 Intern::ExplicitChartHelper<is_explicit>::map(cast(), wp, pp);
465 return wp;
466 }
467
469 virtual WorldPoint project(const WorldPoint& point) const override
470 {
471 ASSERTM(is_implicit, "cannot project point: Chart is not implicit");
472 WorldPoint wp(point);
473 if constexpr(!is_implicit)
474 wp = CoordType(0);
475 Intern::ImplicitChartHelper<is_implicit>::project(cast(), wp);
476 return wp;
477 }
478
480 virtual CoordType dist(const WorldPoint& point) const override
481 {
482 return (this->cast()).compute_dist(point);
483 }
484
486 virtual CoordType dist(const WorldPoint& point, WorldPoint& grad_dist) const override
487 {
488 return (this->cast()).compute_dist(point, grad_dist);
489 }
490
492 virtual CoordType signed_dist(const WorldPoint& point) const override
493 {
494 return (this->cast()).compute_signed_dist(point);
495 }
496
498 virtual CoordType signed_dist(const WorldPoint& point, WorldPoint& grad_dist) const override
499 {
500 return (this->cast()).compute_signed_dist(point, grad_dist);
501 }
502
503 }; // class ChartCRTP<...>
504
505 } // namespace Atlas
506 } // namespace Geometry
507} // namespace FEAT
#define XABORTM(msg)
Abortion macro definition with custom message.
Definition: assertion.hpp:192
#define ASSERTM(expr, msg)
Debug-Assertion macro definition with custom message.
Definition: assertion.hpp:230
#define XASSERTM(expr, msg)
Assertion macro definition with custom message.
Definition: assertion.hpp:263
virtual void adapt(MeshType &mesh, const PartType &meshpart) const =0
Adapts a mesh using this chart.
virtual void adapt(PartType &mesh, const PartType &meshpart) const =0
Adapts a mesh part using this chart.
virtual String get_type() const =0
Writes the type as String.
virtual CoordType signed_dist(const WorldPoint &point) const =0
Computes the signed distance of a point to this chart.
virtual CoordType signed_dist(const WorldPoint &point, WorldPoint &grad_dist) const =0
Computes the signed distance of a point to this chart.
virtual WorldPoint project(const WorldPoint &point) const =0
Projects a point onto the chart.
virtual bool can_explicit() const =0
Specifies whether the chart can perform explicit projection.
MeshType::VertexSetType VertexSetType
our vertex set type
Definition: chart.hpp:39
virtual bool can_implicit() const =0
Specifies whether the chart can perform implicit projection.
virtual CoordType dist(const WorldPoint &point) const =0
Computes the distance of a point to this chart.
virtual std::size_t bytes() const
Definition: chart.hpp:52
MeshPart< Mesh_ > PartType
our mesh part type
Definition: chart.hpp:37
VertexSetType::CoordType CoordType
out coordinate type
Definition: chart.hpp:43
Mesh_ MeshType
our mesh type
Definition: chart.hpp:35
virtual void write(std::ostream &os, const String &sindent) const =0
Writes the Chart into a stream in XML format.
virtual WorldPoint map(const WorldPoint &param) const =0
Maps a parameter to a world point.
virtual CoordType dist(const WorldPoint &point, WorldPoint &grad_dist) const =0
Computes the distance of a point to this chart.
VertexSetType::VertexType WorldPoint
Type of a single vertex.
Definition: chart.hpp:41
virtual void transform(const WorldPoint &origin, const WorldPoint &angles, const WorldPoint &offset)=0
Applies a "proper rigid" transformation onto the chart.
Chart CRTP base-class template.
Definition: chart.hpp:354
const Derived_ & cast() const
Casts this to its true type.
Definition: chart.hpp:396
Derived_ & cast()
Casts this to its true type.
Definition: chart.hpp:393
static constexpr int world_dim
the world dimension of this chart
Definition: chart.hpp:377
virtual WorldPoint project(const WorldPoint &point) const override
Projects a point onto the chart.
Definition: chart.hpp:469
BaseClass::PartType PartType
mesh-part type
Definition: chart.hpp:363
static constexpr int param_dim
the parameter dimension of this chart
Definition: chart.hpp:379
virtual CoordType dist(const WorldPoint &point) const override
Computes the distance of a point to this chart.
Definition: chart.hpp:480
ChartBase< Mesh_ > BaseClass
base-class type
Definition: chart.hpp:357
virtual bool can_explicit() const override
Specifies whether the chart can perform explicit projection.
Definition: chart.hpp:400
virtual WorldPoint map(const WorldPoint &param) const override
Maps a parameter to a world point.
Definition: chart.hpp:456
Tiny::Vector< CoordType, param_dim > ParamPoint
out parameter type
Definition: chart.hpp:385
static constexpr bool is_implicit
specifies whether this chart is implicit
Definition: chart.hpp:374
virtual void adapt(PartType &parent_meshpart, const PartType &meshpart) const override
Adapts a whole MeshPart referring to another MeshPart.
Definition: chart.hpp:450
static constexpr bool is_explicit
specifies whether this chart is explicit
Definition: chart.hpp:372
virtual CoordType dist(const WorldPoint &point, WorldPoint &grad_dist) const override
Definition: chart.hpp:486
virtual bool can_implicit() const override
Specifies whether the chart can perform implicit projection.
Definition: chart.hpp:406
PartType::AttributeSetType AttributeSetType
attribute type of our mesh-part
Definition: chart.hpp:365
virtual CoordType signed_dist(const WorldPoint &point) const override
Computes the signed distance of a point to this chart.
Definition: chart.hpp:492
BaseClass::WorldPoint WorldPoint
our world point type
Definition: chart.hpp:383
virtual CoordType signed_dist(const WorldPoint &point, WorldPoint &grad_dist) const override
Definition: chart.hpp:498
VertexSetType::CoordType CoordType
coordinate type
Definition: chart.hpp:369
Traits_ TraitsType
traits type
Definition: chart.hpp:359
MeshType::VertexSetType VertexSetType
vertex set type of our mesh
Definition: chart.hpp:367
virtual void adapt(MeshType &mesh, const PartType &part) const override
Adapts a whole MeshPart.
Definition: chart.hpp:420
BaseClass::MeshType MeshType
mesh type
Definition: chart.hpp:361
Container for saving data related to mesh entities.
Class template for partial meshes.
Definition: mesh_part.hpp:90
String class implementation.
Definition: string.hpp:46
Tiny Vector class template.
FEAT namespace.
Definition: adjactor.hpp:12
std::uint64_t Index
Index data type.