svMultiPhysics
Loading...
Searching...
No Matches
BasisFactory.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Stanford University, The Regents of the University of California, and others.
2// SPDX-License-Identifier: BSD-3-Clause
3
4#ifndef SVMP_FE_BASIS_BASISFACTORY_H
5#define SVMP_FE_BASIS_BASISFACTORY_H
6
7/**
8 * @file BasisFactory.h
9 * @brief Runtime creation of basis families
10 */
11
12#include "BasisFunction.h"
13#include <memory>
14#include <optional>
15#include <string>
16#include <vector>
17
18namespace svmp::FE::basis {
19
20/**
21 * @brief Runtime description of a basis to construct.
22 * @ingroup FE_Basis
23 *
24 * @details A request identifies exactly one construction target -- a named
25 * ElementType layout, or a reference BasisTopology with an explicit order -- plus
26 * the family and field policy; basis_factory::create() validates and builds from
27 * it. The spline/NURBS fields are reserved for future families and are unused by
28 * the scalar Lagrange/Serendipity factory.
29 */
31 ElementType element_type{ElementType::Unknown}; ///< Named element layout, or Unknown to request by topology.
32 BasisType basis_type{BasisType::Lagrange}; ///< Basis family to construct.
33 std::optional<int> order{}; ///< Polynomial order; required by the factory.
34 Continuity continuity{Continuity::C0}; ///< Inter-element continuity (Lagrange/Serendipity are C0).
35 FieldType field_type{FieldType::Scalar}; ///< Field type (Lagrange/Serendipity support Scalar).
36 std::vector<double> knot_vector{}; ///< Reserved for spline/NURBS families; unused here.
37 std::vector<double> weights{}; ///< Reserved for rational (NURBS) families; unused here.
38 std::vector<int> axis_orders{}; ///< Reserved for per-axis tensor spline orders; unused here.
39 std::vector<std::vector<double>> axis_knot_vectors{}; ///< Reserved for per-axis spline knots; unused here.
40 std::vector<std::vector<double>> axis_weights{}; ///< Reserved for per-axis rational weights; unused here.
41 std::vector<int> tensor_extents{}; ///< Reserved for tensor-product extents; unused here.
42 std::string custom_id{}; ///< Optional identifier for Custom families.
43 /// Reference topology for arbitrary-order requests, or Unknown to request by
44 /// element_type.
46 // Implementation note (kept out of the rendered docs): topology is declared
47 // last so existing aggregate initializers for named elements keep their
48 // positional meaning.
49};
50
51namespace basis_factory {
52
53/**
54 * @brief Create a basis from a runtime request.
55 * @ingroup FE_Basis
56 *
57 * @details A request must identify exactly one construction target: set
58 * BasisRequest::element_type for a named mesh-node layout, or set
59 * BasisRequest::topology for an arbitrary-order reference-topology basis.
60 * Setting neither target, or setting both, is rejected. Named element requests
61 * keep the element's fixed polynomial order contract; topology requests are the
62 * arbitrary-order path.
63 *
64 * @param req Basis family, target, and order request.
65 * @return Unique basis instance. Move it into a std::shared_ptr at the call site
66 * if shared ownership is needed.
67 */
68[[nodiscard]] std::unique_ptr<BasisFunction> create(const BasisRequest& req);
69
70/**
71 * @brief Return the default basis request (family and order) for an element type.
72 * @ingroup FE_Basis
73 *
74 * @details This is the single source of truth for which basis family and
75 * polynomial order a given element type uses by default: serendipity node
76 * layouts (Quad8, Hex20, Wedge15) select the quadratic serendipity family,
77 * and every complete Lagrange element selects the Lagrange family at the
78 * order given by its node layout. Solver-facing adapters should translate
79 * their element names to ElementType and delegate the basis choice here
80 * rather than tabulating family/order themselves.
81 *
82 * @param element_type Element type to select a default basis for.
83 * @return Basis request suitable for create().
84 * @throws BasisElementCompatibilityException If no default basis is defined
85 * for the element type.
86 */
87[[nodiscard]] BasisRequest default_basis_request(ElementType element_type);
88
89/**
90 * @brief Create the default basis for an element type.
91 * @ingroup FE_Basis
92 *
93 * @details Equivalent to create(default_basis_request(element_type)).
94 *
95 * @param element_type Element type to create a default basis for.
96 * @return Unique basis instance. Move it into a std::shared_ptr at the call site
97 * if shared ownership is needed.
98 */
99[[nodiscard]] std::unique_ptr<BasisFunction> create_default_for(ElementType element_type);
100
101} // namespace basis_factory
102
103} // namespace svmp::FE::basis
104
105#endif // SVMP_FE_BASIS_BASISFACTORY_H
std::unique_ptr< BasisFunction > create_default_for(ElementType element_type)
Create the default basis for an element type.
Definition BasisFactory.cpp:103
BasisRequest default_basis_request(ElementType element_type)
Return the default basis request (family and order) for an element type.
Definition BasisFactory.cpp:83
BasisTopology
Reference-cell topology of a basis (the shape, independent of order).
Definition BasisTraits.h:28
std::unique_ptr< BasisFunction > create(const BasisRequest &req)
Create a basis from a runtime request.
Definition BasisFactory.cpp:72
@ Unknown
Unrecognized or uninitialized topology.
BasisType
Basis function families.
Definition Types.h:247
FieldType
Field types for function spaces.
Definition Types.h:257
Continuity
Continuity requirements for function spaces.
Definition Types.h:268
ElementType
Reference element types supported by the FE library.
Definition Types.h:215
@ Lagrange
Standard nodal Lagrange basis.
@ Scalar
Scalar field (temperature, pressure)
@ C0
Continuous (standard FEM)
@ Unknown
Unrecognized or uninitialized element type.
Runtime description of a basis to construct.
Definition BasisFactory.h:30
ElementType element_type
Named element layout, or Unknown to request by topology.
Definition BasisFactory.h:31
Continuity continuity
Inter-element continuity (Lagrange/Serendipity are C0).
Definition BasisFactory.h:34
std::optional< int > order
Polynomial order; required by the factory.
Definition BasisFactory.h:33
std::string custom_id
Definition BasisFactory.h:42
FieldType field_type
Field type (Lagrange/Serendipity support Scalar).
Definition BasisFactory.h:35
BasisType basis_type
Basis family to construct.
Definition BasisFactory.h:32
std::vector< double > weights
Reserved for rational (NURBS) families; unused here.
Definition BasisFactory.h:37
std::vector< int > tensor_extents
Reserved for tensor-product extents; unused here.
Definition BasisFactory.h:41
BasisTopology topology
Definition BasisFactory.h:45
std::vector< std::vector< double > > axis_knot_vectors
Reserved for per-axis spline knots; unused here.
Definition BasisFactory.h:39
std::vector< int > axis_orders
Reserved for per-axis tensor spline orders; unused here.
Definition BasisFactory.h:38
std::vector< std::vector< double > > axis_weights
Reserved for per-axis rational weights; unused here.
Definition BasisFactory.h:40
std::vector< double > knot_vector
Reserved for spline/NURBS families; unused here.
Definition BasisFactory.h:36