Skip to content

Use input field/vector location for CELL_DEFAULT in vecops - #1293

Merged
ZedThree merged 26 commits into
v4.2-rcfrom
vecops-consistent-cell-default
Oct 15, 2018
Merged

Use input field/vector location for CELL_DEFAULT in vecops#1293
ZedThree merged 26 commits into
v4.2-rcfrom
vecops-consistent-cell-default

Conversation

@ZedThree

@ZedThree ZedThree commented Oct 3, 2018

Copy link
Copy Markdown
Member

Some operations used CELL_DEFAULT to mean CELL_CENTRE, others used it to mean use the input field/vector location, others didn't handle it at all. Now all vector operations use it to mean use the input field/vector location.

@ZedThree ZedThree added this to the BOUT-4.2 milestone Oct 3, 2018
Comment thread src/field/vecops.cxx Outdated
TRACE("Grad( Field3D )");

if(outloc_x == CELL_DEFAULT)
if (outloc_x == CELL_DEFAULT) {

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 think this might be dangerous, currently assume that either all components are at the same location or all are staggered in direction of component. Here we're allowing some to be set from input field and others to set from argument.

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 realise you're not changing this but thought I should flag!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, I think it's probably weird to consider a vector with components at different locations, I'm not sure when you would want that. So I don't really know what use-case this overload is for.

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 think it's for the single location overload taking CELL_VSHIFT to set things in the staggered in each direction case. I think we'd like the three location overload to be hidden if this where possible, or possibly just have the two things merged.

@ZedThree ZedThree Oct 3, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I see! Yes, maybe we just shouldn't expose this as part of the public API

EDIT: and similarly for the other three location overloads

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.

Yup, maybe with an ASSERT for further safety?

Comment thread src/field/vecops.cxx
Comment thread src/field/vecops.cxx
@ZedThree

ZedThree commented Oct 3, 2018

Copy link
Copy Markdown
Member Author

Sounds like CELL_VSHIFT may be generally a little bit broken, or at least suspicious.

This PR is the minimal set of changes to make vecops not completely broken. This is blocking for v4.2, as elm-pb won't run without it, so I'd like to get this in and try and fix vecops properly in either 4.2.1 or 4.3

Comment thread src/field/vecops.cxx
Comment thread src/field/vecops.cxx Outdated
outloc_x = f.getLocation();
if(outloc_y == CELL_DEFAULT)
}
if (outloc_y == CELL_DEFAULT) {

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.

As above, can we just pass this through?

Comment thread src/field/vecops.cxx
@ZedThree

ZedThree commented Oct 9, 2018

Copy link
Copy Markdown
Member Author

CELL_DEFAULT means "do the right thing, if unambiguous; otherwise, throw", where "do the right thing" covers two input fields at the same location or exactly one staggered and one cell centred. This should go into the documentation for CELL_DEFAULT

CELL_VSHIFT should be invalid for Mesh::coordinates, and Field??::setLocation check should have preconditions.

We need to make sure "top-level" checks take into account if staggered grids are actually be used

coordinates.

Replaces throw with ASSERT
@d7919

d7919 commented Oct 9, 2018

Copy link
Copy Markdown
Member

A further issue here -- routines like Grad which return a vector don't set the vector's location (particularly tricky for the three location argument versions). This can also impact later routines which try to get the input vector location as the vector location may no longer be set appropriately.

@d7919

d7919 commented Oct 9, 2018

Copy link
Copy Markdown
Member

#1308 (into this branch) attempts to fix some of these issues.

…ult-more-pass-through

Vecops consistent cell default add more checking on location
@ZedThree
ZedThree changed the base branch from next to v4.2-rc October 12, 2018 12:42
@ZedThree

Copy link
Copy Markdown
Member Author

I'm happy with this. @johnomotani you're basically in charge of staggering code at this point, do you want to sign off on this?

Comment thread include/vecops.hxx Outdated

/// Advection of a scalar field \p f by a velocity vector \p v
///
/// Both vectors must be at the same location, which cannot be CELL_VSHIFT

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should say 'The vector and the field must...'.

Comment thread src/field/vecops.cxx
Comment thread src/field/vecops.cxx Outdated
result += FDDZ(metric->J*vcn.z, f, outloc);
result = FDDX(metric->J * vcn.x, f, outloc);
result += FDDY(metric->J * vcn.y, f, outloc);
result += FDDZ(metric->J * vcn.z, f, outloc);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

locations of J again.

Comment thread src/field/vecops.cxx Outdated
Field3D result(localmesh);
result = FDDX(metric->J * vcn.x, f, outloc, method);
result += FDDY(metric->J * vcn.y, f, outloc, method);
result += FDDZ(metric->J * vcn.z, f, outloc, method);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

and again

Comment thread src/field/vecops.cxx
Also clarify that Div cannot have outloc == VSHIFT
Not currently supported, as it would involve "cross-staggering" terms
@ZedThree

Copy link
Copy Markdown
Member Author

@johnomotani That should be everything fixed now!

@ZedThree
ZedThree merged commit c7014c2 into v4.2-rc Oct 15, 2018
@ZedThree
ZedThree deleted the vecops-consistent-cell-default branch October 15, 2018 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants