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

Hermite polynomials #14657

Merged
merged 1 commit into from Jun 10, 2023
Merged

Hermite polynomials #14657

merged 1 commit into from Jun 10, 2023

Conversation

ivweber
Copy link
Contributor

@ivweber ivweber commented Jan 10, 2023

I have grouped together the modified files into different sets. These are the files for generating Hermite polynomials.

@drwells drwells self-assigned this Jan 12, 2023
Copy link
Member

@bangerth bangerth left a comment

Choose a reason for hiding this comment

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

Yes, very nice! I've left a bunch of comments, but this is close -- nicely done, many thanks!

#include <deal.II/lac/full_matrix.h>

#include <algorithm>
#include <exception>
#include <memory>
#include <vector>
Copy link
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 you actually need any of these header files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One of the member functions returns an std::vector, but you're right I think the others might be from an older implementation.

Comment on lines 51 to 52
* either a non-zero shape value or derivative at $y=0$ and $y=1$
* on the reference interval $y \in [0,1]$.
Copy link
Member

Choose a reason for hiding this comment

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

This is an interesting convention to use $y$ to denote the single variable the polynomial depends on. Would you mind changing it to $x$ here and everywhere below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

Comment on lines 58 to 61
* $j-(r+1)$ (or value for $j=r+1$) at $x=1$. The basis is rescaled
* so that a function corresponding to a non-zero $j^{th}$
* derivative has derivative value $j! 4^{j}$ at the corresponding
* node.
Copy link
Member

Choose a reason for hiding this comment

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

Is it correct that the value of the 0th and (r+1)st basis function is one at the end points of the interval then? Maybe state that as well, just to be extra clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is correct. I will specify this directly.

* derivative has derivative value $j! 4^{j}$ at the corresponding
* node.
*/
class HermitePoly : public Polynomial<double>
Copy link
Member

Choose a reason for hiding this comment

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

All of the other classes in this direction have names of the form PolynomialsX. So maybe call this one PolynomialsHermite?

{
public:
/**
* Constructor for an individual Hermite polynomial. We write f_{j}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Constructor for an individual Hermite polynomial. We write f_{j}
* Constructor for an individual Hermite polynomial. We write $f_{j}$

source/base/polynomials_hermite.cc Show resolved Hide resolved
, degree(2 * regularity + 1)
, regularity(regularity)
, side_index(index % (regularity + 1))
, side((index > regularity) ? 1 : 0)
Copy link
Member

Choose a reason for hiding this comment

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

This may be easier to read as follows, given the modulus operation in the line above:

Suggested change
, side((index > regularity) ? 1 : 0)
, side((index >= regularity+1) ? 1 : 0)

, regularity(regularity)
, side_index(index % (regularity + 1))
, side((index > regularity) ? 1 : 0)
{}
Copy link
Member

Choose a reason for hiding this comment

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

Would you mind adding an assertion like this:

Suggested change
{}
{
AssertIndexRange(index, 2*(regularity+1));
}

const unsigned int sz = 2 * regularity + 2;

for (unsigned int i = 0; i < sz; ++i)
polys.push_back(HermitePoly(regularity, i));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
polys.push_back(HermitePoly(regularity, i));
polys.emplace_back(HermitePoly(regularity, i));

source/base/polynomials_hermite.cc Show resolved Hide resolved
Copy link
Member

@peterrum peterrum left a comment

Choose a reason for hiding this comment

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

@ivweber Looks good to me once you fixed the few typos and you have fixed the merge conflict!

@drwells @bangerth Could you also give a final look at the PR so that Ivy can proceed with the follow-up PRs.

.gitignore Outdated
@@ -16,6 +16,7 @@ CMakeLists.txt.user
/compile_commands.json
/.clang_complete
/contrib/utilities/programs
/include/build/
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/include/build/

/**
* This class implements Hermite interpolation polynomials (see
* @cite CiarletRiavart1972interpolation) enforcing the maximum
* posible level of regularity $r$ in the FEM basis given a
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* posible level of regularity $r$ in the FEM basis given a
* possible level of regularity $r$ in the FEM basis given a

/**
* This stores whether the shape function corresponds to a non-zero
* value or derivative at $x=0$ on the reference interval
* ($\mathtt{side} =0$), or at $x=1$ ($\mathtt{side} =1$).
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* ($\mathtt{side} =0$), or at $x=1$ ($\mathtt{side} =1$).
* ($\mathtt{side} =0$) or at $x=1$ ($\mathtt{side} =1$).

@ivweber
Copy link
Contributor Author

ivweber commented May 15, 2023

@peterrum I've just corrected the typos and changed .gitignore back.

Copy link
Member

@drwells drwells left a comment

Choose a reason for hiding this comment

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

This looks good but we could improve things by picking a clearer name.

include/deal.II/base/polynomials_hermite.h Show resolved Hide resolved
@peterrum
Copy link
Member

@ivweber May I ask you to resolve the conflict in doc/doxygen/references.bib and to rebase the branch on master. It seems that some tests are not running which might be because the changes to the tests have been integrated in the meantime. You could optionally also squash the commits.

@ivweber ivweber force-pushed the pull_request_polynomials branch 4 times, most recently from 8c2c02a to 876b8e8 Compare May 16, 2023 07:45
@ivweber
Copy link
Contributor Author

ivweber commented May 16, 2023

@peterrum @drwells I have just rebased the pull request and corrected the references file.

@ivweber
Copy link
Contributor Author

ivweber commented May 16, 2023

I've just reverted back to a clean version from before the rebase

Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

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

Thank you for tackling this. To me, both the implementation and the naming look good, as the first step to implement a finite element based on these polynomials.

Just to be sure: I assume it would be difficult/impossible to express these polynomials as the product of the factors (x-x0)*(x-x0)*(x-x_1)*(x-x_1) for some x_0 and x_1? For the values it is easy to see what to do, but not for the derivatives. The reason I'm asking is that for Lagrange polynomials we observed that expressing the polynomial with conventional coefficients in front of 1, x, x^2, etc. are unstable in terms of roundoff behavior, and one needs to form with roots. I'm wondering if the Hermite polynomials have similar behavior. On the other hand, it really starts to matter for degrees beyond 6, so we might be fine. If you're wondering and have not looked into it, the evaluation stability is the reason why the Polynomial class has these members:

/**
* Stores whether the polynomial is in Lagrange product form, i.e.,
* constructed as a product $(x-x_0) (x-x_1) \ldots (x-x_n)/c$, or not.
*/
bool in_lagrange_product_form;
/**
* If the polynomial is in Lagrange product form, i.e., constructed as a
* product $(x-x_0) (x-x_1) \ldots (x-x_n)/c$, store the shifts $x_i$.
*/
std::vector<number> lagrange_support_points;
And for evaluation
if (in_lagrange_product_form == false)
{
Assert(coefficients.size() > 0, ExcEmptyObject());
// Horner scheme
const unsigned int m = coefficients.size();
number value = coefficients.back();
for (int k = m - 2; k >= 0; --k)
value = value * x + coefficients[k];
return value;
}
else
{
// direct evaluation of Lagrange polynomial
const unsigned int m = lagrange_support_points.size();
number value = 1.;
for (unsigned int j = 0; j < m; ++j)
value *= x - lagrange_support_points[j];
value *= lagrange_weight;
return value;
}

Comment on lines 18 to 19
#ifndef dealii_hermite_polynomials
#define dealii_hermite_polynomials
Copy link
Member

Choose a reason for hiding this comment

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

Can you please rename:

Suggested change
#ifndef dealii_hermite_polynomials
#define dealii_hermite_polynomials
#ifndef dealii_polynomials_hermite_h
#define dealii_polynomials_hermite_h

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@peterrum
Copy link
Member

@ivweber I think we are very close to merging!

However, some of the tests are not picked up. Only 4 tests are picked up in contrast to the 10, which should be the normal case (see #15165). I think the might be related to the fact that the branch is not rebased on master (not 100% sure). May I ask you to rebase the code. If it helps I can do that for you and I force push it to this branch.

@ivweber
Copy link
Contributor Author

ivweber commented May 22, 2023

@kronbichler As far as I know, for most Hermite interpolation polynomials it's difficult to find a fully factorised form of the polynomial because part of the expression is a truncated Taylor series at x=0 for (1-x)^(-r-1), where r is the level of regularity being enforced. Some of the polynomials can be easily written like this, but it's only for the whole basis at lower polynomial degrees.

@ivweber ivweber force-pushed the pull_request_polynomials branch 2 times, most recently from 6a15bb6 to 7b58a85 Compare May 22, 2023 09:08
Copy link
Member

@kronbichler kronbichler left a comment

Choose a reason for hiding this comment

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

Looks good, apart from a minor comment regarding appearance. Thank you for the explanation, this is what I suspected.

@@ -2159,4 +2168,4 @@ @article{zalesak1979fully
pages={335--362},
year={1979},
publisher={Elsevier}
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you please fix the missing line break at the end of the file, such that this diff here disappears?

@ivweber
Copy link
Contributor Author

ivweber commented May 22, 2023

@peterrum I tried git rebase dealii/master on a copy of the branch and removed the duplicate entries in references.bib that this produced, but I can still only see 4 tests. Is it possible that github-actions doesn't have access to this PR for some reason?

@kronbichler
Copy link
Member

/rebuild

@peterrum
Copy link
Member

I tried git rebase dealii/master on a copy of the branch and removed the duplicate entries in references.bib that this produced, but I can still only see 4 tests. Is it possible that github-actions doesn't have access to this PR for some reason?

I must admit I am bit clueless what the issue is. Maybe you need to create a new PR!? This would be really annoying...

@ivweber ivweber requested a review from bangerth May 25, 2023 08:47
@ivweber
Copy link
Contributor Author

ivweber commented May 25, 2023

@drwells Is there a way to get GitHub Actions to start tests on this PR? I looked at the missing tests mentioned above, and they were all ones directly linked to GitHub. Also for some reason the indent test isn't listed as a GitHub Action here, while it is on other PRs.

@drwells
Copy link
Member

drwells commented May 25, 2023

I don't know - it should work. I'll spend some time digging into this problem.

@drwells
Copy link
Member

drwells commented May 25, 2023

I think we ran into an interesting corner-case where the CI needs to be approved for first time contributors, but the first PR (#13239) wasn't actually merged or had CI enabled. I need someone with higher repository permissions to handle this (or possibly upgrade my access).

@ivweber
Copy link
Contributor Author

ivweber commented May 30, 2023

@drwells Would it be useful to remove the previous pull request, or would be likely to create further issues?

@tamiko
Copy link
Member

tamiko commented Jun 5, 2023

@ivweber I have pushed a rebase of your changes to your branch (on github) in order to get the tests going.

@peterrum
Copy link
Member

peterrum commented Jun 6, 2023

@ivweber Finally, the test have run. There are few indentation issues. Good to go once you fixed these 👍

@tamiko
Copy link
Member

tamiko commented Jun 9, 2023

@ivweber I will rebase this pull request again to get rid of your merge commit. This means that the history on github and on your local branch will diverge.

Edit: I have squashed everything into a single commit to clean up the history and making it easier to review the changes.

@tamiko tamiko merged commit 77cf9aa into dealii:master Jun 10, 2023
14 checks passed
@bangerth
Copy link
Member

Nice job, @ivweber ! It took a little while to get this merged, but welcome to the deal.II authors!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants