TDMS
Time Domain Maxwell Solver
Toggle main menu visibility
Loading...
Searching...
No Matches
source.h
Go to the documentation of this file.
1
/**
2
* @file source.h
3
*/
4
#pragma once
5
6
#include <complex>
7
#include <string>
8
9
#include "
cell_coordinate.h
"
10
#include "
mat_io.h
"
11
12
/**
13
* @brief Typedef for providing indices to the Source class.
14
*
15
* Assume the notation as in the docstring of the Source class. Recall that data
16
* in a Source instance is indexed via
17
* {real,imag}[cell_c][cell_b][split_field_ID].
18
*
19
* SourceIndex is a container for indexing the Source.{real,imag} objects in an
20
* efficient and notationally-consistent manner.
21
*/
22
struct
SourceIndex
{
23
int
split_field_ID
= 0,
//!< Index of the split field
24
cell_b
= 0,
//!< Index in the minor (B-)axis
25
cell_c
= 0;
//!< Index in the major (C-)axis
26
};
27
28
/**
29
* @brief The Source class stores values of the Source field across a particular
30
* plane.
31
*
32
* Let A (= {i,j,k}) be the axial direction that the plane the given Source
33
* instance is storing data for. Let B, C be the remaining axial directions,
34
* with C being the axial direction with the slower-varying index. That is: A =
35
* i : B = j : C = k, A = j : B = i : C = k, A = k : B = i : C = j.
36
*
37
* The Source data (real and imag) is indexed by 3 indices, accessed via
38
* {real,imag}[cell_c][cell_b][split_field_ID].
39
*
40
* split_field_ID ranges between 0-7 inclusive.
41
* TODO: Indices <-> sources need to be deduced from input file generator
42
* functions.
43
*
44
* Let cell_a be the A-index of the plane that the instance is storing data
45
* on. Then (cell_A, cell_B, cell_C) is the Yee-cell index whose (source) data
46
* we are accessing with this call.
47
*/
48
class
Source {
49
private
:
50
/*! Flags if the array is empty to avoid pointer preservation */
51
bool
no_data_stored
=
true
;
52
53
public
:
54
double
***
real
=
nullptr
;
//!< Real data for the source term
55
double
***
imag
=
nullptr
;
//!< Imag data for the source term
56
57
Source(
const
mxArray *ptr,
int
dim1,
int
dim2,
const
std::string &name);
58
59
/** @brief Check if the source term is empty (true) or not (false) */
60
bool
is_empty
()
const
{
return
no_data_stored
; }
61
62
std::complex<double> operator[](
SourceIndex
index)
const
{
63
return
std::complex<double>(
64
real
[index.cell_c][index.cell_b][index.split_field_ID],
65
imag
[index.cell_c][index.cell_b][index.split_field_ID]);
66
}
67
68
/**
69
* @brief Return the value at the index provided if the Source is nonempty,
70
* otherwise return 0 if the Source is empty.
71
*
72
* This is for use in the update equations, where the split-H field requires
73
* updating by a non-zero offset despite potentially having no source terms
74
* provided.
75
*
76
* @param index Element to access (if it exists)
77
* @return std::complex<double>
78
*/
79
std::complex<double>
value_or_zero_if_empty
(
SourceIndex
index)
const
{
80
if
(this->
is_empty
()) {
81
return
std::complex<double>(0., 0.);
82
}
else
{
83
return
operator[](index);
84
}
85
}
86
};
cell_coordinate.h
Container for {ijk} or {IJK} grouped variables.
Source::no_data_stored
bool no_data_stored
Definition
source.h:51
Source::imag
double *** imag
Imag data for the source term.
Definition
source.h:55
Source::value_or_zero_if_empty
std::complex< double > value_or_zero_if_empty(SourceIndex index) const
Return the value at the index provided if the Source is nonempty, otherwise return 0 if the Source is...
Definition
source.h:79
Source::is_empty
bool is_empty() const
Check if the source term is empty (true) or not (false).
Definition
source.h:60
Source::real
double *** real
Real data for the source term.
Definition
source.h:54
mat_io.h
Includes MATLAB headers for I/O.
SourceIndex
Typedef for providing indices to the Source class.
Definition
source.h:22
SourceIndex::split_field_ID
int split_field_ID
Index of the split field.
Definition
source.h:23
SourceIndex::cell_c
int cell_c
Index in the major (C-)axis.
Definition
source.h:25
SourceIndex::cell_b
int cell_b
Index in the minor (B-)axis.
Definition
source.h:24
tdms
include
source.h
Generated by
1.17.0