svMultiPhysics
Loading...
Searching...
No Matches
Fibers.h
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 FIBERS_H
5#define FIBERS_H
6
7#include "Array.h"
8#include "Array3.h"
9
10class ComMod;
11class CmMod;
12class MeshParameters;
13class cmType;
14class mshType;
15
16/**
17 * @brief Fiber directions associated with one mesh.
18 */
19class Fibers {
20public:
21 /// Location of the fiber directions in the input.
22 enum class DataCollocation {
23 /// No fiber directions are associated with the mesh.
25 /// The fiber directions are associated with the mesh nodes.
27 /// The fiber directions are associated with the mesh cells.
29 /// The fiber directions are constant vectors defined in the input file.
31 };
32
33 /**
34 * @brief Reads fiber directions from file paths or constant vectors.
35 */
36 void read(const MeshParameters &mesh_parameters, mshType &mesh, int nsd);
37
38 /**
39 * @brief Parallel distribution of fiber directions.
40 */
41 void distribute(ComMod &com_mod, const CmMod &cm_mod, const cmType &cm,
42 mshType &mesh);
43
44 /**
45 * @brief Returns the location of the fiber directions in the input.
46 */
47 DataCollocation get_data_location() const { return data_location; }
48
49 /// Returns the number of raw directions supplied by the user.
50 int get_num_directions() const { return num_input_fibers; }
51
52 /**
53 * @brief Returns fibers at a quadrature point.
54 *
55 * Raw directions are returned by default. When @p orthonormalize is true,
56 * an owned, completed orthonormal basis is returned without modifying or
57 * caching the raw fibers. Constant and cell directions are completed
58 * directly; interpolated point directions are first orthonormalized.
59 */
60 Array<double> get_quadrature_fibers(int nsd, int g, int e,
61 bool orthonormalize = false) const;
62
63 /**
64 * @brief Evaluates fibers with supplied basis-function values.
65 *
66 * For point data, raw directions are re-interpolated with the supplied
67 * values before optional orthonormalization.
68 */
69 Array<double> get_quadrature_fibers(
70 int nsd, const Vector<double> &basis_functions, int e,
71 bool orthonormalize = false) const;
72
73 /**
74 * @brief Returns true if there are fiber directions.
75 */
76 bool has_fibers() const { return num_input_fibers != 0; }
77
78 /**
79 * @brief Returns an nsd-by-1 zero fiber matrix for meshes with no directions.
80 */
81 static Array<double> zero_fibers(int nsd);
82
83private:
84 /**
85 * @brief Fiber directions read from the input.
86 *
87 * Indexed as @c (component, location):
88 * - @c component packs all directions contiguously as
89 * @f$ i \cdot n_{sd} + j @f$ for direction @f$ i @f$ and spatial
90 * component @f$ j @f$;
91 * - @c location is the single constant entry, the cell, or the point,
92 * depending on @ref data_location.
93 *
94 * Cleared early in @ref distribute once metadata is shared; partitioned
95 * fiber data live in @ref quadrature_fibers and @ref element_nodal_fibers.
96 */
97 Array<double> input_fibers;
98
99 /**
100 * @brief Raw fiber directions at the quadrature points.
101 *
102 * Indexed as @c (component, gauss_point, element):
103 * - @c component packs all directions as in @ref input_fibers;
104 * - @c gauss_point is the quadrature point within the element (always 0 for
105 * constant and cell data);
106 * - @c element is the local element index after @ref distribute (or the
107 * global element index before it).
108 *
109 * For constant data the array is @c (nsd*num_input_fibers, 1, 1).
110 */
111 Array3<double> quadrature_fibers;
112
113 /**
114 * @brief Point-associated input fibers gathered at each element's nodes.
115 *
116 * Indexed as @c (component, local_node, element):
117 * - @c component packs all directions as in @ref input_fibers;
118 * - @c local_node is the element-local node index;
119 * - @c element is the local element index after @ref distribute (or the
120 * global element index before it).
121 *
122 * Used only for point data so fibers can be re-interpolated with alternative
123 * basis functions after the mesh has been partitioned.
124 */
125 Array3<double> element_nodal_fibers;
126
127 /// Location of the fiber directions in the input.
129
130 /// Number of fiber directions supplied as input.
131 int num_input_fibers = 0;
132
133 /// Whether every raw input location contains mutually orthogonal directions.
134 bool basis_input_is_orthogonal = true;
135
136 /**
137 * @brief Reads fiber directions from VTK files.
138 *
139 * expected_location must be point or cell and selects which FIB_DIR
140 * association is required.
141 */
142 void read_from_file(const MeshParameters &mesh_parameters, mshType &mesh,
143 int nsd, DataCollocation expected_location);
144
145 /**
146 * @brief Reads constant fiber directions as specified in the input file.
147 */
148 void read_directions(const MeshParameters &mesh_parameters, int nsd);
149
150 /**
151 * @brief Checks that every input fiber direction has unit length.
152 */
153 void check_input_fibers_unit(int nsd) const;
154
155 /**
156 * @brief Returns whether input directions are mutually orthogonal.
157 */
158 bool input_fibers_are_orthogonal(int nsd) const;
159
160 /**
161 * @brief Populates the raw quadrature representation.
162 */
163 void populate_quadrature_fibers(const mshType &mesh, int nsd);
164
165 /**
166 * @brief Interpolates the original point directions for one element.
167 *
168 * Uses the supplied basis-function values with the cached
169 * @ref element_nodal_fibers.
170 */
171 Array<double>
172 interpolate_point_fibers_element(int nsd,
173 const Vector<double> &basis_functions,
174 int e) const;
175
176 /**
177 * @brief Interpolates nodal fiber directions onto the mesh quadrature
178 * points.
179 *
180 * Builds @ref element_nodal_fibers and fills @ref quadrature_fibers using
181 * the mesh shape functions.
182 */
183 void interpolate_point_fibers_mesh(const mshType &mesh, int nsd);
184};
185
186#endif
The Array3 template class implements a simple interface to 3D arrays.
Definition Array3.h:25
The CmMod class duplicates the data structures in the Fortran CMMOD module defined in COMU....
Definition CmMod.h:37
The ComMod class duplicates the data structures in the Fortran COMMOD module defined in MOD....
Definition ComMod.h:1633
Fiber directions associated with one mesh.
Definition Fibers.h:19
int get_num_directions() const
Returns the number of raw directions supplied by the user.
Definition Fibers.h:50
Array< double > get_quadrature_fibers(int nsd, int g, int e, bool orthonormalize=false) const
Returns fibers at a quadrature point.
Definition Fibers.cpp:588
static Array< double > zero_fibers(int nsd)
Returns an nsd-by-1 zero fiber matrix for meshes with no directions.
Definition Fibers.cpp:304
void read(const MeshParameters &mesh_parameters, mshType &mesh, int nsd)
Reads fiber directions from file paths or constant vectors.
Definition Fibers.cpp:312
bool has_fibers() const
Returns true if there are fiber directions.
Definition Fibers.h:76
DataCollocation
Location of the fiber directions in the input.
Definition Fibers.h:22
@ none
No fiber directions are associated with the mesh.
Definition Fibers.h:24
@ constant
The fiber directions are constant vectors defined in the input file.
Definition Fibers.h:30
@ point
The fiber directions are associated with the mesh nodes.
Definition Fibers.h:26
@ cell
The fiber directions are associated with the mesh cells.
Definition Fibers.h:28
DataCollocation get_data_location() const
Returns the location of the fiber directions in the input.
Definition Fibers.h:47
void distribute(ComMod &com_mod, const CmMod &cm_mod, const cmType &cm, mshType &mesh)
Parallel distribution of fiber directions.
Definition Fibers.cpp:235
The MeshParameters class is used to store paramaters for the 'Add_mesh' XML element.
Definition Parameters.h:2020
The Vector template class is used for storing int and double data.
Definition Vector.h:26
The cmType class stores data and defines methods used for mpi communication.
Definition CmMod.h:57
This is the container for a mesh or NURBS patch, those specific to NURBS are noted.
Definition ComMod.h:879