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
Generalize QGrid to work with arbitrary integer orders? #1711
Comments
Thanks for opening up an issue. Yeah, it would be great to set the quad order via some integral type directly. |
I'm not super familiar with enums and casting, but it may be possible to static_cast any integer to the Order enum as long as the underling type is fixed, like enum Order : int { ..... } but check me on this :-). |
It appears you are right, I just wrote this code snippet:
And it worked as you'd expect, so yeah, I'd say there are no code changes actually necessary, just a |
It seems to work okay for me too, but I am wondering if the underlying type for the enum Order needs to be fixed to int in the libMesh code. I think (please check me) that this would ensure the static_cast does not have undefined behavior. i.e. right now the libMesh implementation has: enum Order { } instead of enum Order : int { } |
Hmm... So the
syntax is C++11-specific, which probably explains why we didn't adopt it yet (just haven't gotten around to it). According to these docs,
it sounds like you would only run into unspecified behavior if you tried to Anyway, we should probably specify |
Officially, this does not work:
The language they quote is pretty much the same in the C++11 and C++14 standards. |
Yeah but the lowest possible range is |
At least, that's how I parsed this paragraph from the same site:
|
Ok, here's the definition of the range:
So if we specify an underlying type then we get it, if not then we're only guaranteed enough bits to hold every listed value? |
The conversion to int is still guaranteed to exist, but whether the conversion does what we expect or not is only guaranteed for the values in the range. |
So we don't have to go whole hog enum-class (and thereby break backwards compatibility with user code due to the different scoping rules), but we do have to explicitly specify an enum-base value. I'd say "int"? "short" might be sufficient but we never store lots of these things so we don't need to be stingy. |
Yeah, your website is much more specific about the fact that bitfields can be used. I wonder if any compiler would really do this??? Anyway, to have compliant code and avoid weird bitfield stuff, we should definitely add |
I'd be dumbfounded if a compiler actually limited us to 6 bits, but I wouldn't be shocked if one limited us to 8. And presumably we do want to support orders greater than 256 so |
I'll make a PR this weekend some time unless someone else gets to it first... |
I played with this quite a bit last year when I was working in the grain tracker and have been introducing specifying the enum storage type when appropriate in MOOSE since then. BTW - you aren't just limited to To throw more gas on the fire, there's also "scoped enums", which gives you a strong type (no more implicit conversion), which I really like! If you are going to go through everything, you might consider looking into changing over to scoped enums where appropriate too (also starting to do this in MOOSE). |
Specifying a fixed type prevents the compiler from trying to optimize by choosing the smallest possible integral type which fits the range of enumerated values, and forces it to use the specified type instead. See also: http://en.cppreference.com/w/cpp/language/enum This is useful in contexts where values outside the original enumeration range are expected to be used, for example in the Order enumeration as discussed in libMesh#1711.
Thanks John!
…On Wed, May 30, 2018 at 2:52 PM, John W. Peterson ***@***.***> wrote:
Closed #1711 <#1711> via #1713
<#1713>.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1711 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ALNyy2A_HAKrnfjs0-zghD-j2aqfwKOZks5t3upQgaJpZM4UMzNy>
.
--
Charles Puelz
Postdoc
UNC Math Department
cpuelz.github.io
|
Thanks for pointing out this issue. |
There was a mailing list thread recently about the desire to use the
QGrid
quadrature rule without being limited to the existingOrder
enumerations, which only go up to 43rd.I don't know about the wisdom of this approach... (surely at some point round-off error becomes important once you have thousands of quadrature points on a single element?) but it might be possible if we add an additional
parameter to the
QGrid
class, where_integral_order
is either selected by the user, or defaults to_order
if not otherwise set.The text was updated successfully, but these errors were encountered: