-
Notifications
You must be signed in to change notification settings - Fork 707
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
Make all template specialization of FPE compile for float #14155
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// --------------------------------------------------------------------- | ||
// | ||
// Copyright (C) 2022 by the deal.II authors | ||
// | ||
// This file is part of the deal.II library. | ||
// | ||
// The deal.II library is free software; you can use it, redistribute | ||
// it, and/or modify it under the terms of the GNU Lesser General | ||
// Public License as published by the Free Software Foundation; either | ||
// version 2.1 of the License, or (at your option) any later version. | ||
// The full text of the license can be found in the file LICENSE.md at | ||
// the top level directory of deal.II. | ||
// | ||
// --------------------------------------------------------------------- | ||
|
||
|
||
// Check that all template specializations of FEPointEvaluation are | ||
// compiling. | ||
|
||
#include <deal.II/matrix_free/fe_point_evaluation.h> | ||
|
||
#include "../tests.h" | ||
|
||
template <int n_components, int dim, int spacedim, typename Number> | ||
void | ||
test() | ||
{ | ||
return; // nothing to do, since we are only interested if the code | ||
// compiles | ||
|
||
std::unique_ptr<Mapping<dim, spacedim>> mapping; | ||
std::unique_ptr<FiniteElement<dim, spacedim>> fe; | ||
|
||
FEPointEvaluation<n_components, dim, spacedim, Number> fpe( | ||
*mapping, *fe, UpdateFlags::update_default); | ||
|
||
Triangulation<dim, spacedim> tria; | ||
|
||
fpe.reinit(tria.begin(), ArrayView<const Point<dim>>()); | ||
|
||
fpe.evaluate(ArrayView<const Number>(), EvaluationFlags::values); | ||
|
||
fpe.integrate(ArrayView<Number>(), EvaluationFlags::values); | ||
} | ||
|
||
int | ||
main() | ||
{ | ||
initlog(); | ||
|
||
test<1, 1, 1, double>(); | ||
test<2, 1, 1, double>(); | ||
|
||
test<1, 2, 2, double>(); | ||
test<2, 2, 2, double>(); | ||
test<3, 2, 2, double>(); | ||
|
||
test<1, 3, 3, double>(); | ||
test<2, 3, 3, double>(); | ||
test<3, 3, 3, double>(); | ||
test<4, 3, 3, double>(); | ||
|
||
test<1, 1, 1, float>(); | ||
test<2, 1, 1, float>(); | ||
|
||
test<1, 2, 2, float>(); | ||
test<2, 2, 2, float>(); | ||
test<3, 2, 2, float>(); | ||
|
||
test<1, 3, 3, float>(); | ||
test<2, 3, 3, float>(); | ||
test<3, 3, 3, float>(); | ||
test<4, 3, 3, float>(); | ||
|
||
deallog << "OK!" << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
DEAL::OK! |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't sound quite right to me. Shouldn't the operator just return a
Tensor
representation of what it stores internally, and then if someone wants this in another type they can later cast from that tensor to one with a different scalar?Note that that's basically what you do in the implementation, which now looks as follows:
My preference would be to make the place that calls this function do the cast at the calling site, not internally here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to agree with @bangerth here, since this only converts the end result, I would prefer doing that explicitly in
FEPointEvaluation
(I was confused by the abbreviation FPE, which I read as floating point exception).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That the tensor used the old number- type was not indended:
Tensor<order + 1, dim, Number> t; <<<<<<<<<<<<<<<<<< old tensor type
I have adjusted that.
Since the
operator()
is for casting, the casting is already done explicitly done inFEPointEvaluation
:dealii/include/deal.II/matrix_free/fe_point_evaluation.h
Lines 950 to 954 in 1195dbb
The alternative would to cast from
DerivativeForm
totypename internal::FEPointEvaluation::EvaluatorTypeTraits<dim, n_components, double>::gradient_type
(please note that one has to use double instead of Number in this long expression) and after that cast it to a float version (or do an assignment, which seems to broke inTensor
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think what I meant to say is this: I consider the cast operator as saying "give me a tensor representation of this object", the emphasis being on "representation of this object" rather than "give me". The emphasis here is on the object. As a consequence, a
DerivativeForm<...,double>
should return aTensor<...,double>
.In contrast, your implementation is for the question "I want to use this object as an X", in which the emphasis is on want to use -- a caller side consideration. I would prefer an explicit cast to
Tensor<...,Number2>
in such situations.