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

Out-of-scope k variable usage when updating source terms. #225

Open
willGraham01 opened this issue Feb 3, 2023 · 4 comments
Open

Out-of-scope k variable usage when updating source terms. #225

willGraham01 opened this issue Feb 3, 2023 · 4 comments
Assignees
Labels
bug Something isn't working priority:2 Second priority
Milestone

Comments

@willGraham01
Copy link
Collaborator

willGraham01 commented Feb 3, 2023

The variable k is used in the Ksource update loop, with a specific instance here, despite not being a loop variable.

This is only possible since the indexing-variables are declared right at the top of execute(). In the previous two loops (Isource, Jsource), k is a loop variable so this is fine. However in the Ksource update loop only i and j are loop variables. It is only because k is globally scoped that the code compiles: but then we also notice that in this loop the value k is not changing, but is fixed to k = inputs.K1.index, and is still being used to fetch constants from the input matrices!

@samcunliffe samcunliffe added bug Something isn't working priority:2 Second priority labels Feb 4, 2023
@willGraham01
Copy link
Collaborator Author

willGraham01 commented Feb 6, 2023

Having delved into the code some more, I believe that what's meant to be happening in these loops is that:

  • When updating across the K0 plane, we should be using inputs.K0.index (possibly offset by -1) in place of k,
  • When updating across the K1 plane, we should be using inputs.K1.index (which we are currently doing "implicitly").

However, we should clarify this and make these associations explicit if we are! We may additionally need to regenerate the test data if we are meant to be using inputs.K0.index in the K0 loop (as presently we are still using k).

@prmunro
Copy link
Collaborator

prmunro commented Feb 7, 2023

This is a good spot and it is indeed an error in the code (which I know you already know!). This part of the code hasn't been used for some time and I need to go back into the theory to test this. In particular, this part of the code will only be encountered when dispersive materials are modelled. As mentioned, I haven't used this feature for >15 years. Can we create an issue for me to generate a test that will use the dispersive materials feature, and also to double check what this k-value should be, as I am 99% confident that Will has the correct solution?

@prmunro
Copy link
Collaborator

prmunro commented Feb 7, 2023

Having delved into the code some more, I believe that what's meant to be happening in these loops is that:

  • When updating across the K0 plane, we should be using inputs.K0.index (possibly offset by -1) in place of k,
  • When updating across the K1 plane, we should be using inputs.K1.index (which we are currently doing "implicitly").

However, we should clarify this and make these associations explicit if we are! We may additionally need to regenerate the test data if we are meant to be using inputs.K0.index in the K0 loop (as presently we are still using k).

I agree with this @willGraham01

@prmunro
Copy link
Collaborator

prmunro commented Feb 7, 2023

As discussed, @willGraham01 , please make change as described above, I will review later.

willGraham01 added a commit that referenced this issue Feb 20, 2023
willGraham01 added a commit that referenced this issue Feb 23, 2023
* Cherry-pick Sam's linting

* Add flag to Source class to indicate empty array

* Add flag to Source class to indicate empty array

* Indentation

* Initialise values rather than assign

* Refactored source updates - flagged mystery indexing

* Pre-commit consistency with #223

* Update clang-format to #222 settings

* Fix out-of-order initilisation warning

* Revert pre-commit to suppress GitHub failures until #223 is ready

* Remove unused variables in updating Ksource terms

* Start refactoring the refactored functions. Flag more inconsistencies

* Missing std::

* Merge E_s steady-state updates into one function (revert files to previous commit if undesired)

* Fix bugs in unification (IE Will can't type)

* Pull out E_s source updates, and wrap to avoid empty-source updates

* Pull out H-source updates, don't add empty array checks yet

* Fully refactor H-field, now to find the bug...

* Add that newline to make pre-commit happy

* Missed a -1 in ONE place... does this fix the bug?

* Remove useless comment

* Apply Peter's suggestion on #226

* Add Peter's resolution to #225

* Apply Sam's suggestions for SourceIndex struct

* Small doc changes that didn't get caught
willGraham01 added a commit that referenced this issue Mar 6, 2023
* Cherry-pick Sam's linting

* Add flag to Source class to indicate empty array

* Add flag to Source class to indicate empty array

* Indentation

* Initialise values rather than assign

* Refactored source updates - flagged mystery indexing

* Pre-commit consistency with #223

* Update clang-format to #222 settings

* Fix out-of-order initilisation warning

* Revert pre-commit to suppress GitHub failures until #223 is ready

* Remove unused variables in updating Ksource terms

* Start refactoring the refactored functions. Flag more inconsistencies

* Missing std::

* Merge E_s steady-state updates into one function (revert files to previous commit if undesired)

* Fix bugs in unification (IE Will can't type)

* Pull out E_s source updates, and wrap to avoid empty-source updates

* Pull out H-source updates, don't add empty array checks yet

* Fully refactor H-field, now to find the bug...

* Add that newline to make pre-commit happy

* Missed a -1 in ONE place... does this fix the bug?

* Remove useless comment

* Apply Peter's suggestion on #226

* Add Peter's resolution to #225

* Apply Sam's suggestions for SourceIndex struct

* Small doc changes that didn't get caught
willGraham01 added a commit that referenced this issue Mar 7, 2023
* Cherry-pick Sam's linting

* Add flag to Source class to indicate empty array

* Add flag to Source class to indicate empty array

* Indentation

* Initialise values rather than assign

* Refactored source updates - flagged mystery indexing

* Pre-commit consistency with #223

* Update clang-format to #222 settings

* Fix out-of-order initilisation warning

* Revert pre-commit to suppress GitHub failures until #223 is ready

* Remove unused variables in updating Ksource terms

* Start refactoring the refactored functions. Flag more inconsistencies

* Missing std::

* Merge E_s steady-state updates into one function (revert files to previous commit if undesired)

* Fix bugs in unification (IE Will can't type)

* Pull out E_s source updates, and wrap to avoid empty-source updates

* Pull out H-source updates, don't add empty array checks yet

* Fully refactor H-field, now to find the bug...

* Add that newline to make pre-commit happy

* Missed a -1 in ONE place... does this fix the bug?

* Remove useless comment

* Apply Peter's suggestion on #226

* Add Peter's resolution to #225

* Apply Sam's suggestions for SourceIndex struct

* Small doc changes that didn't get caught
willGraham01 added a commit that referenced this issue Mar 29, 2023
* Cherry-pick Sam's linting

* Add flag to Source class to indicate empty array

* Add flag to Source class to indicate empty array

* Indentation

* Initialise values rather than assign

* Refactored source updates - flagged mystery indexing

* Pre-commit consistency with #223

* Update clang-format to #222 settings

* Fix out-of-order initilisation warning

* Revert pre-commit to suppress GitHub failures until #223 is ready

* Remove unused variables in updating Ksource terms

* Start refactoring the refactored functions. Flag more inconsistencies

* Missing std::

* Merge E_s steady-state updates into one function (revert files to previous commit if undesired)

* Fix bugs in unification (IE Will can't type)

* Pull out E_s source updates, and wrap to avoid empty-source updates

* Pull out H-source updates, don't add empty array checks yet

* Fully refactor H-field, now to find the bug...

* Add that newline to make pre-commit happy

* Missed a -1 in ONE place... does this fix the bug?

* Remove useless comment

* Apply Peter's suggestion on #226

* Add Peter's resolution to #225

* Apply Sam's suggestions for SourceIndex struct

* Small doc changes that didn't get caught
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority:2 Second priority
Projects
None yet
Development

No branches or pull requests

3 participants