Skip to content

Commit 063f4a1

Browse files
Rename phasorinc, add {C,D}Collection documentation, and main()main.cpp (#200)
* Move main into its own file. * Typo and fix details tags. * Rename phasorinc. * Document the CCollection and DCollection classes. * Recursive glob everything in the source directory. Co-authored-by: Will Graham <[email protected]>
1 parent 864c43d commit 063f4a1

14 files changed

+199
-156
lines changed

Diff for: .github/workflows/doxygen-gh-pages.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
deploy:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: DenverCoder1/doxygen-github-pages-action@v1.1.0
11+
- uses: DenverCoder1/doxygen-github-pages-action@v1.2.0
1212
with:
1313
github_token: ${{ secrets.GITHUB_TOKEN }}
1414
folder: html

Diff for: README.md

+41-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
***
1212
## Introduction
1313

14-
TDMS (Time Domain Maxwell Solver) is a hybrid C++ and MATLAB for solving
14+
TDMS, the Time Domain Maxwell Solver, is a hybrid C++ and MATLAB tool for solving
1515
Maxwell's equations to simulate light propagation through a medium. See the
1616
[pdf documentation](https://github.com/UCL/TDMS/blob/gh-doc/masterdoc.pdf) for
1717
further details.
@@ -20,19 +20,19 @@ further details.
2020
***
2121
## Compilation
2222

23-
TDMS requires building against [FFTW](https://www.fftw.org/) and
23+
TDMS needs to be built against [FFTW](https://www.fftw.org/) and
2424
[MATLAB](https://www.mathworks.com/products/matlab.html), thus both need to be
2525
downloaded and installed prior to compiling TDMS. Install with
2626

2727
```bash
28-
cd tdms
29-
mkdir build; cd build
30-
cmake .. \
28+
$ cd tdms
29+
$ mkdir build; cd build
30+
$ cmake .. \
3131
# -DMatlab_ROOT_DIR=/usr/local/MATLAB/R2019b/ \
3232
# -DFFTW_ROOT=/usr/local/fftw3/ \
33-
# -DCMAKE_INSTALL_PREFIX=$HOME/.local/
33+
# -DCMAKE_INSTALL_PREFIX=$HOME/.local/ \
3434
# -DBUILD_TESTING=ON
35-
make install
35+
$ make install
3636
```
3737
where lines need to be commented in and the paths modified if cmake cannot
3838
(1) find MATLAB, (2) find FFTW or (3) install to the default install prefix.
@@ -62,16 +62,45 @@ where lines need to be commented in and the paths modified if cmake cannot
6262
***
6363
## Usage
6464
65+
Once the executable has been compiled and installed, `tdms` should be in the `PATH`.
66+
Check that installation worked with
67+
68+
```bash
69+
$ tdms -h
70+
```
71+
72+
You can invoke it directly or call it from a MATLAB script.
73+
We recommend that beginners with MATLAB installed start with the demonstration MATLAB script.
74+
6575
#### To run the demonstration code
6676

67-
Once the executable has been compiled, move into directory _examples/arc_01_,
68-
launch Matlab and run the Matlab script:
77+
Move into directory [`examples/arc_01`](./examples/arc_01/),
78+
launch MATLAB and run the MATLAB script:
6979

70-
_run_pstd_bscan.m_
80+
[`run_pstd_bscan.m`](./examples/arc_01/run_pstd_bscan.m)
7181

7282
This script will generate the input to the executable, run the executable and
7383
display sample output.
7484

85+
#### To run standalone
86+
87+
You can also run `tdms` from the command line...
88+
89+
```bash
90+
$ tdms --help
91+
Usage:
92+
tdms [options] infile outfile
93+
tdms [options] infile gridfile outfile
94+
Options:
95+
-h: Display this help message
96+
-fd, --finite-difference: Use the finite-difference solver, instead of the pseudo-spectral method.
97+
-q: Quiet operation. Silence all logging
98+
-m: Minimise output file size by not saving vertex and facet information
99+
```
100+
101+
The basic workflow is with two arguments, an input file as specified by [`iterate_fdtd_matrix.m`](./tdms/matlab/iteratefdtd_matrix.m), and an output file name to be created.
102+
103+
You can choose two possible solver methods: either pseudo-spectral time-domain (PSTD, the default) or finite-difference (FDTD, with option `--finite-difference`).
75104

76105
#### Parallelism
77106

@@ -80,9 +109,10 @@ number of threads can be set with the `OMP_NUM_THREADS` environment variable.
80109
For example, to use 4 threads, in a bash shell, use:
81110

82111
```bash
83-
export OMP_NUM_THREADS=4
112+
$ export OMP_NUM_THREADS=4
84113
```
85114

115+
Before calling the `tdms` executable.
86116

87117
## Contributing
88118

Diff for: doc/developers.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ spdlog::debug("Send help");
9999
```
100100

101101
### Compiling on UCL's Myriad cluster
102+
102103
<details>
104+
103105
> **Warning**
104106
> These instructions are a bit experimental. Please use with care (and report anything that's wrong here)!
105107
@@ -134,13 +136,13 @@ spdlog::debug("Send help");
134136
CApath: none
135137
```
136138
it's because the MATLAB module is interfering with the SSL certificates (and we clone over https by default). This issue is known and reported. As a workaround, we've added the build option `-DGIT_SSH=ON` to switch to `git clone` over ssh instead.
139+
137140
</details>
138141

139142

140143
## Where's the main?
141144

142-
The C++ `main` function is in openandorder.cpp <!-- words with a dot in them are assumed to be files so this will hyperlink to openandorder.cpp iff *that* file is also documented. --> however this only really does file I/O and setup.
143-
The main FDTD algorithm code is in iterator.cpp <!-- won't be linked as an undocumented file doesn't exist for doxygen... this is fine, we can link to the real file in github.--> and classes included therein.
145+
The C++ `main` function is in main.cpp however the main algorithm code is execute_simulation() in iterator.cpp
144146

145147
## Testing
146148

Diff for: tdms/CMakeLists.txt

+8-27
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,15 @@ else()
8181
add_definitions(-DSPDLOG_ACTIVE_LEVEL=SPDLOG_LEVEL_INFO)
8282
endif()
8383

84-
8584
# TDMS target -----------------------------------------------------------------
86-
set(SOURCES
87-
src/fields/base.cpp
88-
src/fields/electric.cpp
89-
src/fields/magnetic.cpp
90-
src/fields/split.cpp
91-
src/fields/td_field_exporter_2d.cpp
92-
src/argument_parser.cpp
93-
src/array_init.cpp
94-
src/arrays.cpp
95-
src/dimensions.cpp
96-
src/fdtd_grid_initialiser.cpp
97-
src/grid_labels.cpp
98-
src/interface.cpp
99-
src/interpolate.cpp
100-
src/iterator.cpp
101-
src/interpolation_methods.cpp
102-
src/matrix_collection.cpp
103-
src/mesh_base.cpp
104-
src/numerical_derivative.cpp
105-
src/shapes.cpp
106-
src/simulation_parameters.cpp
107-
src/source.cpp
108-
src/timer.cpp
109-
src/utils.cpp
110-
matlabio/matlabio.cpp
111-
)
85+
86+
# wildcard to find all *.cpp files in the src directory except for main.cpp
87+
# (which we don't want for the testing target)
88+
file(GLOB_RECURSE SOURCES "src/*.cpp")
89+
list(FILTER SOURCES EXCLUDE REGEX "src/main.cpp")
90+
91+
# TODO: can delete this line when matlabio is removed.
92+
set(SOURCES ${SOURCES} matlabio/matlabio.cpp)
11293

11394
if (BUILD_TESTING)
11495
test_target()

Diff for: tdms/cmake/targets.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function(release_target)
22
add_executable(tdms)
33

4-
target_sources(tdms PRIVATE ${SOURCES} src/openandorder.cpp)
4+
target_sources(tdms PRIVATE ${SOURCES} src/main.cpp)
55

66
target_link_libraries(tdms
77
FFTW::Double
@@ -36,7 +36,7 @@ function(test_target)
3636

3737
add_library(tdms_lib SHARED)
3838
target_sources(tdms_lib PUBLIC ${SOURCES})
39-
add_executable(tdms "src/openandorder.cpp")
39+
add_executable(tdms "src/main.cpp")
4040

4141
target_link_libraries(tdms_lib LINK_PUBLIC
4242
FFTW::Double

Diff for: tdms/include/arrays.h

+28-4
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,26 @@ class MaterialCollection{
9191
static void init_xyz_vectors(const mxArray *ptr, XYZVectors &arrays, const std::string &prefix);
9292
};
9393

94+
/**
95+
* @brief A class to encapsulate collection of algebraic terms in the
96+
* discretized forms of Maxwells equations for E fields. The symbol chosen in
97+
* the original reference is \f$C\f$.
98+
*
99+
* @details Algebraic terms \f$C_{a,b,c}\f$ defined in Section 4.2 of Munro, P,.
100+
* "Application of numerical methods to high numerical aperture imaging", 2006,
101+
* PhD thesis, Imperial College London.
102+
*
103+
* The definitions are equations 4.13, 4.14 (pp 82-3). Part of Maxwell's E-field
104+
* equations in equations 4.7-9.
105+
*/
94106
class CCollectionBase {
95107
public:
96108
XYZVectors a;
97109
XYZVectors b;
98110
XYZVectors c;
99111
};
100112

101-
// TODO: docstring
113+
/*! @copydoc CCollectionBase */
102114
class CCollection : public CCollectionBase {
103115
private:
104116
void init_xyz_vectors(const mxArray *ptr, XYZVectors &arrays, const std::string &prefix);
@@ -110,19 +122,31 @@ class CCollection : public CCollectionBase {
110122
explicit CCollection(const mxArray *ptr);
111123
};
112124

113-
// TODO: docstring
125+
/*! @copydoc CCollectionBase */
114126
class CMaterial : public CCollectionBase, MaterialCollection {
115127
public:
116128
explicit CMaterial(const mxArray *ptr);
117129
};
118130

131+
/**
132+
* @brief A class to encapsulate collection of algebraic terms in the
133+
* discretized forms of Maxwells equations for H fields. The symbol chosen in
134+
* the original reference is \f$D\f$.
135+
*
136+
* @details Algebraic terms \f$D_{a,b}\f$ defined in Section 4.2 of Munro, P,.
137+
* "Application of numerical methods to high numerical aperture imaging", 2006,
138+
* PhD thesis, Imperial College London.
139+
*
140+
* The definitions are equations 4.15, 4.16 (pp 82-3). Part of Maxwell's H-field
141+
* equations in equations 4.10-12.
142+
*/
119143
class DCollectionBase {
120144
public:
121145
XYZVectors a;
122146
XYZVectors b;
123147
};
124148

125-
// TODO: docstring
149+
/*! @copydoc DCollectionBase */
126150
class DCollection: public DCollectionBase{
127151
private:
128152
static void init_xyz_vectors(const mxArray *ptr, XYZVectors &arrays, const std::string &prefix);
@@ -131,7 +155,7 @@ class DCollection: public DCollectionBase{
131155
explicit DCollection(const mxArray *ptr);
132156
};
133157

134-
// TODO: docstring
158+
/*! @copydoc DCollectionBase */
135159
class DMaterial : public DCollectionBase, MaterialCollection {
136160
public:
137161
explicit DMaterial(const mxArray *ptr);

Diff for: tdms/include/mesh_base.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ void triangulateCuboidSkip(int I0, int I1, int J0, int J1, int K0, int K1, mxArr
9494
void conciseTriangulateCuboid(int I0, int I1, int J0, int J1, int K0, int K1, mxArray **vertices,
9595
mxArray **facets);
9696
void conciseTriangulateCuboidSkip(int I0, int I1, int J0, int J1, int K0, int K1,
97-
PhasorInc &phasorinc, mxArray **vertices, mxArray **facets);
97+
SurfaceSpacingStride &spacing_stride, mxArray **vertices, mxArray **facets);
9898

9999
void conciseCreateBoundary(int I0, int I1,int K0, int K1, mxArray **vertices, mxArray ** facets);

Diff for: tdms/include/simulation_parameters.h

+34-34
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ enum RunMode{
3434
};
3535

3636
enum Dimension{
37-
THREE, // Full dimensionality - compute all H and E components
38-
TE, // Transverse electric - only compute Ex, Ey, and Hz components
39-
TM // Transverse magnetic - only compute Hx, Hy, and Ez components
37+
THREE, //< Full dimensionality - compute all H and E components
38+
TE, //< Transverse electric - only compute Ex, Ey, and Hz components
39+
TM //< Transverse magnetic - only compute Hx, Hy, and Ez components
4040
};
4141

4242
enum InterpolationMethod{
@@ -50,7 +50,7 @@ enum InterpolationMethod{
5050
* to extract the phasors on. the surface i.e. x = 2 means extract from
5151
* every 2nd Yee cell.
5252
*/
53-
struct PhasorInc{
53+
struct SurfaceSpacingStride{
5454
int x = 1;
5555
int y = 1;
5656
int z = 1;
@@ -74,44 +74,44 @@ class SimulationParameters{
7474
public:
7575
SimulationParameters();
7676

77-
double omega_an = 0.0; // Angular ω
78-
unsigned int Nt = 0; // Number of simulation steps
79-
unsigned int Np = 0; // Number of times to extract the phasors
80-
unsigned int Npe = 0; // Extract the phasors every this number of iterations
81-
unsigned int start_tind = 0; // Starting iteration number for the time steps
82-
double dt = 0.0; // Time step
83-
bool has_tdfdir = false; // Is the tdfdir (time domain field directory) defined?
84-
bool is_multilayer = false; // Is this simulation of a multilayer?
85-
bool is_disp_ml = false; // Is the material dispersive?
86-
double to_l = 0.0; // Time delay of pulse
87-
double hwhm = 0.0; // Half width at half max of pulse
88-
PerfectlyMatchedLayer pml; // Perfectly matched layer struct with size attributes
89-
bool exphasorsvolume = false; // Should phasors be extracted in the whole volume?
90-
bool exphasorssurface = false; // Should phasors be extracted on a surface?
91-
bool intphasorssurface = false; // Should phasors be extracted/interpolated?
92-
RunMode run_mode = complete; // Run mode
93-
SourceMode source_mode = pulsed; // Source mode
94-
Dimension dimension = THREE; // Dimensions to calculate in
95-
bool is_structure = false; // Has a grating structure been defined?
96-
bool exdetintegral = false; // TODO: detector sensitivity evaluation ?
97-
int k_det_obs = 0; // TODO: no idea what this is?!
98-
double z_obs = 0.0; // Value of the input grid_labels_z at k_det_obs
77+
double omega_an = 0.0; //< Angular ω
78+
unsigned int Nt = 0; //< Number of simulation steps
79+
unsigned int Np = 0; //< Number of times to extract the phasors
80+
unsigned int Npe = 0; //< Extract the phasors every this number of iterations
81+
unsigned int start_tind = 0; //< Starting iteration number for the time steps
82+
double dt = 0.0; //< Time step
83+
bool has_tdfdir = false; //< Is the tdfdir (time domain field directory) defined?
84+
bool is_multilayer = false; //< Is this simulation of a multilayer?
85+
bool is_disp_ml = false; //< Is the material dispersive?
86+
double to_l = 0.0; //< Time delay of pulse
87+
double hwhm = 0.0; //< Half width at half max of pulse
88+
PerfectlyMatchedLayer pml; //< Perfectly matched layer struct with size attributes
89+
bool exphasorsvolume = false; //< Should phasors be extracted in the whole volume?
90+
bool exphasorssurface = false; //< Should phasors be extracted on a surface?
91+
bool intphasorssurface = false; //< Should phasors be extracted/interpolated?
92+
RunMode run_mode = complete; //< Run mode
93+
SourceMode source_mode = pulsed; //< Source mode
94+
Dimension dimension = THREE; //< Dimensions to calculate in
95+
bool is_structure = false; //< Has a grating structure been defined?
96+
bool exdetintegral = false; //< TODO: detector sensitivity evaluation ?
97+
int k_det_obs = 0; //< TODO: no idea what this is?!
98+
double z_obs = 0.0; //< Value of the input grid_labels_z at k_det_obs
9999
bool air_interface_present = false;
100-
double air_interface = 0.0; // TODO: what is this?!
101-
bool interp_mat_props = false; // Should the material properties be interpolated?
102-
InterpolationMethod interp_method = cubic; // Type of surface field interpolation to do
103-
bool exi_present = false; // Is the time dependent x incident field present?
104-
bool eyi_present = false; // Is the time dependent y incident field present?
105-
PhasorInc phasorinc; // Surface stride for extracting phasors
106-
YeeCellDimensions delta; // Yee cell dimensions (dx, dy, dz)
100+
double air_interface = 0.0; //< TODO: what is this?!
101+
bool interp_mat_props = false; //< Should the material properties be interpolated?
102+
InterpolationMethod interp_method = cubic; //< Type of surface field interpolation to do
103+
bool exi_present = false; //< Is the time dependent x incident field present?
104+
bool eyi_present = false; //< Is the time dependent y incident field present?
105+
SurfaceSpacingStride spacing_stride; //< Surface stride for extracting phasors (in matlab this is called 'phasorinc')
106+
YeeCellDimensions delta; //< Yee cell dimensions (dx, dy, dz)
107107

108108
void set_run_mode(std::string mode_string);
109109

110110
void set_source_mode(std::string mode_string);
111111

112112
void set_dimension(std::string mode_string);
113113

114-
void set_phasorinc(const double* vector);
114+
void set_spacing_stride(const double* vector);
115115

116116
void set_Np(FrequencyExtractVector &f_ex_vec);
117117
};

Diff for: tdms/src/argument_parser.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ ArgumentNamespace ArgumentParser::parse_args(int n_args, char *arg_ptrs[]) {
4747

4848
void ArgumentParser::print_help_message(){
4949
fprintf(stdout,"Usage:\n"
50-
"openandorder [options] infile outfile\n"
51-
"openandorder [options] infile gridfile outfile\n"
50+
"tdms [options] infile outfile\n"
51+
"tdms [options] infile gridfile outfile\n"
5252
"Options:\n"
5353
"-h:\tDisplay this help message\n"
54-
"--finite-difference:\tUse the finite-difference solver, instead of the pseudo-spectral method.\n"
54+
"-fd, --finite-difference:\tUse the finite-difference solver, instead of the pseudo-spectral method.\n"
5555
"-q:\tQuiet operation. Silence all logging\n"
5656
"-m:\tMinimise output file size by not saving vertex and facet information\n\n");
5757
}

0 commit comments

Comments
 (0)