Skip to content

Add missing from field aligned - #1061

Closed
johnomotani wants to merge 11 commits into
nextfrom
add_missing_fromFieldAligned
Closed

Add missing from field aligned#1061
johnomotani wants to merge 11 commits into
nextfrom
add_missing_fromFieldAligned

Conversation

@johnomotani

Copy link
Copy Markdown
Contributor

In several y-derivatives where we have to convert the input to field-aligned coordinates, the result was not transformed back to the original coordinates.

Also, several advective and flux derivatives which take two fields, v and f, as inputs, had cases using yup/ydown fields for one of v and f, but not the other. These do not make sense as multiplication of a field in field-aligned coordinates with another in non-field-aligned coordinates is incorrect. Delete these cases and fall back to converting both v and f to field-aligned if either does not have yup/ydown fields.

Advective and flux derivatives, which take v and f as inputs, had cases
using yup/ydown fields for one of v and f, but not the other. These do
not make sense as multiplication of a field in field-aligned coordinates
with another in non-field-aligned coordinates is incorrect.

Delete these cases and fall back to converting both v and f to
field-aligned if either does not have yup/ydown fields.
@johnomotani johnomotani added the work in progress Not ready for merging label May 14, 2018
In several y-derivatives where we have to convert the input to
field-aligned coordinates, the result was not transformed back to
the original coordinates.
@johnomotani
johnomotani force-pushed the add_missing_fromFieldAligned branch from ec64af4 to 05a2266 Compare May 14, 2018 20:54
@johnomotani johnomotani removed the work in progress Not ready for merging label May 14, 2018
Comment thread src/mesh/difops.cxx Outdated
}

result = mesh->fromFieldAligned(result);
result = mesh->fromFieldAligned(result_fa);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that result_fa is actually set in the above loop. What happened previously was that result was used to store the field aligned result and then we did an "in-place" transform back into non-field aligned : result = mesh->fromFieldAligned(result);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers @d7919, that was just a mistake.

Comment thread src/mesh/difops.cxx
else if (vUseUpDown) {
// Only v has up/down fields
// f must shift to field aligned coordinates
Field3D f_fa = mesh->toFieldAligned(f);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're shifting f to be field aligned such that it should make sense to multiply with v, which has field aligned data available (in yup and ydown), so I think this is ok but could be missing something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may well have misunderstood. I thought that to/fromFieldAligned rotate the points in the z-direction by zShift, so the toroidal position of the point (i,j,k) would be different for field-aligned and non-field-aligned fields?

Comment thread src/mesh/difops.cxx Outdated

for(auto &i : result.region(RGN_NOBNDRY)) {
result[i] = (var_fa[i.yp()] - var_fa[i]) / (metric->dy[i]*sqrt(metric->g_22[i]));
result_fa[i] = (var_fa[i.yp()] - var_fa[i]) / (metric->dy[i]*sqrt(metric->g_22[i]));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is required, although it probably doesn't hurt beyond memory usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed it's not required. I thought it would be clearer to keep field-aligned and non-field-aligned fields separate, but am happy to revert back if people think it would be better. You make a good point about the memory usage, I'm inclined now to change it back to result = mesh->fromFieldAligned(result); style.

We can save memory by just using the 'result' variable to store the
field aligned result and transform it at the end using 'result =
this->fromFieldAligned(result);'
Also remove a 'Field3D result = Field3D(this);' line which seems to have
been a typo.
In the unstaggered case, only the value of v is used, so yup/ydown
fields for v are not needed.
@johnomotani
johnomotani force-pushed the add_missing_fromFieldAligned branch from 042426e to 86fb49f Compare July 2, 2018 19:47
Was previously a typo that resulted in using non-field-aligned f in
VDDY, which is incorrect.
Previously these were incorrectly setting the location of their result
to the location of the input variable. This commit changes this to use
the specified output location. This probably did not cause bugs as the
location was overridden in DDX/DDY/DDZ, etc.
@johnomotani
johnomotani force-pushed the add_missing_fromFieldAligned branch from 037689c to 4b1706d Compare July 3, 2018 10:54
@codecov-io

Copy link
Copy Markdown

Codecov Report

Merging #1061 into next will increase coverage by 19.68%.
The diff coverage is 0%.

Impacted file tree graph

@@             Coverage Diff             @@
##             next    #1061       +/-   ##
===========================================
+ Coverage   20.16%   39.84%   +19.68%     
===========================================
  Files         162      187       +25     
  Lines       19814    26322     +6508     
===========================================
+ Hits         3995    10488     +6493     
- Misses      15819    15834       +15
Impacted Files Coverage Δ
src/mesh/index_derivs.cxx 5.13% <0%> (+0.28%) ⬆️
tests/unit/sys/test_output.cxx 100% <0%> (ø)
tests/unit/include/bout/test_generic_factory.cxx 100% <0%> (ø)
tests/unit/bout_test_main.cxx 100% <0%> (ø)
tests/unit/sys/test_optionsreader.cxx 100% <0%> (ø)
tests/unit/field/test_vector3d.cxx 98.46% <0%> (ø)
tests/unit/mesh/test_interpolation.cxx 98.09% <0%> (ø)
tests/unit/field/test_fieldperp.cxx 99.76% <0%> (ø)
tests/unit/sys/test_options.cxx 100% <0%> (ø)
tests/unit/include/bout/test_region.cxx 99.49% <0%> (ø)
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d68f200...7ac04ea. Read the comment docs.

@johnomotani

Copy link
Copy Markdown
Contributor Author

More up to date version of these fixes is included in #1176

@johnomotani
johnomotani deleted the add_missing_fromFieldAligned branch September 27, 2018 11:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants