TDMS
Time Domain Maxwell Solver
All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
vertex_phasors.h
Go to the documentation of this file.
1/**
2 * @file vertex_phasors.h
3 * @brief Contains a class that handles the complex amplitude extraction at the
4 * vertices.
5 */
6#pragma once
7
8#include <complex>
9
10#include "arrays/tdms_matrix.h"
11#include "arrays/vector_typedefs.h"
12#include "field.h"
13#include "grid_labels.h"
14#include "utils.h"
15
16/**
17 * Class container for handling complex amplitude samples at the vertices, and
18 * their extraction.
19 *
20 * Abbreviated to CAmpSample in MATLAB code
21 */
23private:
24 /* n_vertices()-by-3 int array.
25 Each "row" corresponds to the index of a vertex at which to extract the field
26 components requested.
27 */
28 Vertices vertices;
29 /*! The MATLAB indices of the field components we want to extract at the
30 * vertices.
31 */
32 FieldComponentsVector components;
33
34 mxArray *mx_camplitudes = nullptr;//< Complex amplitudes at the vertices
35 int f_ex_vector_size =
36 0;//< Number of elements in the frequency extraction vector
37
38 /* Storage for real and imag parts of mx_surface_amplitudes (these can be
39 f_ex_vector_size * n_surface_vertices arrays of FullFieldSnapshots when MATLAB
40 is removed!)
41
42 Arrays are index by
43 [frequency_index][field_component_position][vertex_id/number].
44
45 frequency_index corresponds to the frequencies at which the user has requested
46 we extract the amplitudes.
47
48 field_component_position corresponds to components.index(field_component) of
49 the field_component we are interested it. Since the user might not request
50 consecutive components for extraction (EG [Ex, Ey, Hz] would correspond to [1,
51 2, 6]) we need to be able to convert these MATLAB indices -> consecutive
52 indices for storage here.
53 */
54 double ***camplitudesR = nullptr,
55 ***camplitudesI = nullptr;//!< @copydoc camplitudesR
56
57public:
58 VertexPhasors() = default;
59 /*! @copydoc set_from */
60 VertexPhasors(const mxArray *ptr) { set_from(ptr); }
61
62 /**
63 * @brief Setup using data from an input file
64 *
65 * @param ptr Pointer to the struct containing the list of vertices and
66 * components to extract phasors at/for
67 */
68 void set_from(const mxArray *ptr);
69
70 /** @brief Get the pointer to the data */
71 mxArray *get_mx_camplitudes() { return mx_camplitudes; }
72
73 /**
74 * @brief Allocate memory for the camplitude{R,I} arrays.
75 *
76 * Provided there are vertices for us to extract at, allocates the memory for
77 * the camplitude{R,I} arrays and creates the mx_camplitudes pointer to the
78 * output data.
79 *
80 * @param n_frequencies The number of frequencies at which we need to extract
81 * phasors
82 */
83 void setup_complex_amplitude_arrays(int n_frequencies);
84
85 /** @brief Fetch the number of vertices at which we are extracting phasors */
86 int n_vertices() { return vertices.n_vertices(); }
87 /** @brief Fetch the number of field components we are extracting */
88 int n_components() { return components.size(); }
89 /** @brief Returns true/false based on whether there are/aren't vertices to
90 * extract at */
92 // Returns true/false based on whether there are/aren't elements in BOTH the
93 // vertices and components arrays
94 bool there_are_elements_in_arrays() {
95 return (vertices.has_elements() &&
97 }
98
99 /**
100 * @brief Normalise the surface amplitudes at frequency_vector_index by the E-
101 * and H-norms provided.
102 *
103 * E-field components in camplitudes{R,I} are divided by the (complex) Enorm.
104 * H-field components in camplitudes{R,I} are divided by the (complex) Hnorm.
105 *
106 * @param frequency_index Frequency index, camplitudes{R,I}[frequency_index]
107 * will be normalised
108 * @param Enorm,Hnorm The {E,H}-norm to normalise the {E,H}-components by
109 */
110 void normalise_vertices(int frequency_index, std::complex<double> Enorm,
111 std::complex<double> Hnorm);
112
113 /**
114 * @brief Extract the phasor values at the vertices on the surface, for the
115 * given frequency index
116 *
117 * @param frequency_index The entries in camplitudes{R,I}[frequency_index]
118 * will be written to
119 * @param E,H The electric,magnetic split field
120 * @param n Current timestep index
121 * @param omega Angular frequency
122 * @param params The parameters for this simulation
123 */
124 void extractPhasorsVertices(int frequency_index, ElectricSplitField &E,
125 MagneticSplitField &H, int n, double omega,
126 SimulationParameters &params);
127
128 /**
129 * @brief Incriments camplitudes{R,I} at the given index by the field values
130 * provided.
131 *
132 * If we allow element-wise assignment, we are essentially performing the
133 * operations: camplitudesR[frequency_index][:][vertex_index] += F.real(),
134 * camplitudesI[frequency_index][:][vertex_index] += F.imag().
135 *
136 * Only field components that we are extracting at the vertices are pulled out
137 * of F.
138 *
139 * @param frequency_index Frequency index
140 * @param vertex_index Vertex index
141 * @param F Field values to assign
142 */
143 void update_vertex_camplitudes(int frequency_index, int vertex_index,
145
147};
Definition field.h:161
Definition arrays.h:116
Definition field.h:188
Class storing the various constants and behaviour flags for one executation of the tdms executable.
Definition simulation_parameters.h:69
Definition vertex_phasors.h:22
void extractPhasorsVertices(int frequency_index, ElectricSplitField &E, MagneticSplitField &H, int n, double omega, SimulationParameters &params)
Extract the phasor values at the vertices on the surface, for the given frequency index.
Definition vertex_phasors.cpp:85
void update_vertex_camplitudes(int frequency_index, int vertex_index, FullFieldSnapshot F)
Incriments camplitudes{R,I} at the given index by the field values provided.
Definition vertex_phasors.cpp:146
double *** camplitudesI
Definition vertex_phasors.h:55
int n_components()
Fetch the number of field components we are extracting.
Definition vertex_phasors.h:88
void normalise_vertices(int frequency_index, std::complex< double > Enorm, std::complex< double > Hnorm)
Normalise the surface amplitudes at frequency_vector_index by the E- and H-norms provided.
Definition vertex_phasors.cpp:39
void setup_complex_amplitude_arrays(int n_frequencies)
Allocate memory for the camplitude{R,I} arrays.
Definition vertex_phasors.cpp:66
VertexPhasors(const mxArray *ptr)
Setup using data from an input file.
Definition vertex_phasors.h:60
mxArray * get_mx_camplitudes()
Get the pointer to the data.
Definition vertex_phasors.h:71
FieldComponentsVector components
Definition vertex_phasors.h:32
bool there_are_vertices_to_extract_at()
Returns true/false based on whether there are/aren't vertices to extract at.
Definition vertex_phasors.h:91
int n_vertices()
Fetch the number of vertices at which we are extracting phasors.
Definition vertex_phasors.h:86
void set_from(const mxArray *ptr)
Setup using data from an input file.
Definition vertex_phasors.cpp:12
Classes for the electric and magnetic (split) fields on a grid.
Class to hold the labels of a Yee cell.
bool has_elements(const std::vector< T > &v)
Return true if the vector has non-zero size.
Definition utils.h:43
Useful miscellaneous utility functions.