Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#216 iteratefdtd_matrix: Updates for the main loop #224

Merged
merged 27 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
49f4f4c
Cherry-pick Sam's linting
willGraham01 Jan 31, 2023
c16f9fa
Add flag to Source class to indicate empty array
willGraham01 Jan 31, 2023
d11dc2e
Add flag to Source class to indicate empty array
willGraham01 Jan 31, 2023
0a9b35a
Indentation
willGraham01 Jan 31, 2023
fb5c0b5
Initialise values rather than assign
willGraham01 Jan 31, 2023
61651cb
Refactored source updates - flagged mystery indexing
willGraham01 Feb 2, 2023
dc18a04
Pre-commit consistency with #223
willGraham01 Feb 2, 2023
7386288
Update clang-format to #222 settings
willGraham01 Feb 2, 2023
a3c015a
Fix out-of-order initilisation warning
willGraham01 Feb 2, 2023
c20f1db
Revert pre-commit to suppress GitHub failures until #223 is ready
willGraham01 Feb 2, 2023
04a4353
Remove unused variables in updating Ksource terms
willGraham01 Feb 2, 2023
92e64e5
Start refactoring the refactored functions. Flag more inconsistencies
willGraham01 Feb 2, 2023
10a41b1
Missing std::
willGraham01 Feb 2, 2023
d3e838d
Merge E_s steady-state updates into one function (revert files to pre…
willGraham01 Feb 2, 2023
aaf61e6
Fix bugs in unification (IE Will can't type)
willGraham01 Feb 2, 2023
c146fa4
Pull out E_s source updates, and wrap to avoid empty-source updates
willGraham01 Feb 3, 2023
962c454
Pull out H-source updates, don't add empty array checks yet
willGraham01 Feb 3, 2023
553f75a
Fully refactor H-field, now to find the bug...
willGraham01 Feb 3, 2023
b79d266
Add that newline to make pre-commit happy
willGraham01 Feb 3, 2023
9bf6d11
Missed a -1 in ONE place... does this fix the bug?
willGraham01 Feb 3, 2023
15de02f
Remove useless comment
willGraham01 Feb 3, 2023
577cdfc
Apply Peter's suggestion on #226
willGraham01 Feb 8, 2023
8b18880
Add Peter's resolution to #225
willGraham01 Feb 8, 2023
22b3b67
Merge in changes from main
willGraham01 Feb 20, 2023
fd56895
Merge branch 'main' into wgraham-216-iteratefdtd_matrix_updates
willGraham01 Feb 23, 2023
7ece7e9
Apply Sam's suggestions for SourceIndex struct
willGraham01 Feb 23, 2023
147d8bb
Small doc changes that didn't get caught
willGraham01 Feb 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions tdms/include/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,7 @@ class SplitFieldComponent : public Tensor3D<double> {
fftw_plan *plan_b = nullptr;// Backward fftw plan

double **operator[](int value) const { return tensor[value]; };
double operator[](CellCoordinate cell) const {
return tensor[cell.k][cell.j][cell.i];
}
double &operator[](ijk cell) const { return tensor[cell.k][cell.j][cell.i]; }

void initialise_from_matlab(double ***tensor, Dimensions &dims);

Expand Down
14 changes: 10 additions & 4 deletions tdms/include/simulation_manager/objects_from_infile.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ class IndependentObjectsFromInfile {

/* DERIVED VARIABLES FROM INDEPENDENT INPUTS */

IJKDimensions IJK_tot;//< total number of Yee cells in the x,y,z directions
// respectively
int Nsteps; //< Number of dfts to perform before checking for phasor
// convergence
IJKDimensions IJK_tot;//!< total number of Yee cells in the x,y,z directions
//!< respectively
int Nsteps;//!< Number of dfts to perform before checking for phasor
//!< convergence

IndependentObjectsFromInfile(
InputMatrices matrices_from_input_file,
Expand Down Expand Up @@ -140,5 +140,11 @@ class ObjectsFromInfile : public IndependentObjectsFromInfile {
PreferredInterpolationMethods _pim =
PreferredInterpolationMethods::BandLimited);

/** @brief Determine whether the {IJK}source terms are empty (true) or not
* (false) */
bool all_sources_are_empty() {
return Isource.is_empty() && Jsource.is_empty() && Ksource.is_empty();
}

~ObjectsFromInfile();
};
154 changes: 137 additions & 17 deletions tdms/include/simulation_manager/simulation_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@
*/
class SimulationManager {
private:
ObjectsFromInfile
inputs; //< The input objects that are generated from an input file
LoopTimers timers; //< Timers for tracking the execution of the simulation
PSTDVariables PSTD;//< PSTD-solver-specific variables
FDTDBootstrapper FDTD; //< FDTD bootstrapping variables
OutputMatrices outputs;//< Output object that will contain the results of this
// simulation, given the input file

PreferredInterpolationMethods
pim;//< The interpolation methods to use in this simulation
SolverMethod solver_method;//< The solver method to use in this simulation
/*! The input objects that are generated from an input file */
ObjectsFromInfile inputs;

LoopTimers timers; //!< Timers for tracking the execution of the simulation
PSTDVariables PSTD; //!< PSTD-solver-specific variables
FDTDBootstrapper FDTD;//!< FDTD bootstrapping variables

/*! Output object that will contain the results of this simulation, given the
* input file */
OutputMatrices outputs;

/*! The solver method to use in this simulation */
SolverMethod solver_method;
/*! The interpolation methods to use in this simulation */
PreferredInterpolationMethods pim;

EHVec eh_vec;//!< TODO

double ramp_width = 4.;//< Width of the ramp when introducing the waveform in
// steady state mode
/*! Width of the ramp when introducing the waveform in steady state mode */
double ramp_width = 4.;
/**
* @brief Evaluates the linear ramp function r(t)
*
Expand All @@ -65,10 +69,10 @@ class SimulationManager {
return std::min(1., t / (ramp_width * period));
}

std::vector<std::complex<double>>
E_norm;//< Holds the E-field phasors norm at each extraction frequency
std::vector<std::complex<double>>
H_norm;//< Holds the H-field phasors norm at each extraction frequency
/*! Holds the {E,H}-field phasors norm at each extraction frequency */
std::vector<std::complex<double>> E_norm;
/*! @copydoc E_norm */
std::vector<std::complex<double>> H_norm;
/**
* @brief Extracts the phasors norms at the given frequency (index)
*
Expand All @@ -88,6 +92,122 @@ class SimulationManager {
*/
void prepare_output(const mxArray *fieldsample, const mxArray *campssample);

/**
* @brief Update electric-split field components and current densities AT A
* PARTICULAR CELL in steady-state after an E-field timestep has been
* performed.
*
* @param time_H The time the magnetic field is currently sitting at.
* @param parallel The axis to which the plane of the Source term is parallel.
* EG X = Isource, Y = Jsource, etc
* @param C_axis Whether we are updating terms along the C-axis (true) or
* B-axis (false) of the Source plane. See Source doc for axis information.
* @param zero_plane Whether we are updating terms on the 0-plane (true) or
* the 1-plane (false). EG I0 would have this input as true, whereas J1 as
* false.
* @param is_conductive Whether the medium is conductive (so J_c needs to be
* updated)
* @param cell_b,cell_c The coordinates (cell_a, cell_b, cell_c) of the Yee
* cell in which we are updating the field. See the Source doc for notation
* information.
* @param array_ind The index of the various material property arrays that
* correspond to this particular Yee cell, and thus update equation.
* @param J_c The current density in the conductive medium
* @param J_s The current density in the dispersive medium
*/
void E_source_update_steadystate(double time_H, AxialDirection parallel,
bool C_axis, bool zero_plane,
bool is_conductive, int cell_b, int cell_c,
int array_ind, CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/**
* @brief Update magnetic-split field components AT A
* PARTICULAR CELL in steady-state after an H-field timestep has been
* performed.
*
* @param time_E The time the electric field is currently sitting at
* @param parallel The axis to which the plane of the Source term is parallel.
* EG X = Isource, Y = Jsource, etc
* @param C_axis Whether we are updating terms along the C-axis (true) or
* B-axis (false) of the Source plane. See Source doc for axis information.
* @param zero_plane Whether we are updating terms on the 0-plane (true) or
* the 1-plane (false). EG I0 would have this input as true, whereas J1 as
* false.
* @param array_ind The index of the various material property arrays that
* correspond to this particular Yee cell, and thus update equation.
* @param cell_b,cell_c The coordinates (cell_a, cell_b, cell_c) of the Yee
* cell in which we are updating the field. See the Source doc for notation
* information.
*/
void H_source_update_steadystate(double time_E, AxialDirection parallel,
bool zero_plane, bool C_axis, int array_ind,
int cell_b, int cell_c);
/**
* @brief [E-FIELD UPDATES] Performs updates to the electric-split field
* components and current density fields after an E-field timestep has been
* performed, in accordance with the I,J, and K-source terms.
*
* @param time_H The time the magnetic field is currently sitting at.
* @param is_conductive Whether the medium is conductive (so J_c needs to be
* updated)
* @param J_c The current density in the conductive medium
* @param J_s The current density in the dispersive medium
*/
void E_source_update_all_steadystate(double time_H, bool is_conductive,
CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/**
* @brief [H-FIELD UPDATES] Performs updates to the magnetic-split field
* components after an H-field timestep has been performed, in accordance with
* the I,J, and K-source terms.
*
* @param time_E The time the electric field is currently sitting at.
*/
void H_source_update_all_steadystate(double time_E);

/*! @copydoc E_source_update_all_steadystate */
void E_Isource_update_steadystate(double time_H, bool is_conductive,
CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/*! @copydoc E_source_update_all_steadystate */
void E_Jsource_update_steadystate(double time_H, bool is_conductive,
CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/*! @copydoc E_source_update_all_steadystate */
void E_Ksource_update_steadystate(double time_H, bool is_conductive,
CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/*! @copydoc H_source_update_all_steadystate */
void H_Isource_update_steadystate(double time_E);
/*! @copydoc H_source_update_all_steadystate */
void H_Jsource_update_steadystate(double time_E);
/*! @copydoc H_source_update_all_steadystate */
void H_Ksource_update_steadystate(double time_E);

/**
* @brief [E-FIELD UPDATES] Performs the updates to the electric-split field
* components nad current density fields after an E-field timestep has been
* performed, in accordance with the source terms.
*
* @param time_H The time the magnetic field is currently sitting at.
* @param is_conductive Whether the medium is conductive (so J_c needs to be
* updated)
* @param J_c The current density in the conductive medium
* @param J_s The current density in the dispersive medium
*/
void update_source_terms_pulsed(double time_H, bool is_conductive,
CurrentDensitySplitField &J_c,
CurrentDensitySplitField &J_s);
/**
* @brief [H-FIELD UPDATES] Performs the updates to the magnetic-split field
* components and current density fields after an H-field timestep has been
* performed, in accordance with the source terms.
*
* @param time_E The time the electric field is currently sitting at.
* @param tind The current iteration number
*/
void update_source_terms_pulsed(double time_E, int tind);

public:
SimulationManager(InputMatrices in_matrices, SolverMethod _solver_method,
PreferredInterpolationMethods _pim);
Expand Down
55 changes: 53 additions & 2 deletions tdms/include/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,65 @@
*/
#pragma once

#include <complex>
#include <string>

#include "cell_coordinate.h"
#include "mat_io.h"

/**
* @brief Typedef for providing indices to the Source class.
*
* Assume the notation as in the docstring of the Source class. Recall that data
* in a Source instance is indexed via
* {real,imag}[cell_c][cell_b][split_field_ID].
*
* SourceIndex is a container for indexing the Source.{real,imag} objects in an
* efficient and notationally-consistent manner.
*/
struct SourceIndex {
int split_field_ID = 0,//!< Index of the split field
cell_b = 0, //!< Index in the minor (B-)axis
cell_c = 0; //!< Index in the major (C-)axis
};

/**
* @brief The Source class stores values of the Source field across a particular
* plane.
*
* Let A (= {i,j,k}) be the axial direction that the plane the given Source
* instance is storing data for. Let B, C be the remaining axial directions,
* with C being the axial direction with the slower-varying index. That is: A =
* i : B = j : C = k, A = j : B = i : C = k, A = k : B = i : C = j.
*
* The Source data (real and imag) is indexed by 3 indices, accessed via
* {real,imag}[cell_c][cell_b][split_field_ID].
*
* split_field_ID ranges between 0-7 inclusive.
* TODO: Indices <-> sources need to be deduced from input file generator
* functions.
*
* Let cell_a be the A-index of the plane that the instance is storing data
* on. Then (cell_A, cell_B, cell_C) is the Yee-cell index whose (source) data
* we are accessing with this call.
*/
class Source {
private:
/*! Flags if the array is empty to avoid pointer preservation */
bool no_data_stored = true;

public:
double ***real = nullptr;
double ***imag = nullptr;
double ***real = nullptr;//!< Real data for the source term
double ***imag = nullptr;//!< Imag data for the source term

Source(const mxArray *ptr, int dim1, int dim2, const std::string &name);

/** @brief Check if the source term is empty (true) or not (false) */
bool is_empty() { return no_data_stored; }

std::complex<double> operator[](SourceIndex index) {
return std::complex<double>(
real[index.cell_c][index.cell_b][index.split_field_ID],
imag[index.cell_c][index.cell_b][index.split_field_ID]);
}
};
Loading