FEniCS / dolfinx

Next generation FEniCS problem solving environment
https://fenicsproject.org
GNU Lesser General Public License v3.0
731 stars 177 forks source link

Quad Precision FEM in Fenicsx #2926

Closed RamakrishnanChandran closed 9 months ago

RamakrishnanChandran commented 9 months ago

Dear Team,

I'm a Master student in Computational Engineering in FAU Erlangen, Germany. I'm working on Mixed Precision AMG solver for my Master thesis.

I have been using Fenics to extract Matrix and RHS data from the FEM discretization of novel 2D poisson problem with dirichlet BC using Fenics 2019.1.0 library (using python Driver adapting the tutorial code of 2D poisson problem)

I enquired about this in Fenics Discourse. (https://fenicsproject.discourse.group/t/quad-precision-fenics/12979)

Is there any possibility of passing the quad precision template param to the backend C++ code from the python front end such that it could be handled by form complier appropriately.

Thanks and Regards, Ramakrishnan C.

jhale commented 9 months ago

This project sounds very interesting and it would be good if you could keep us informed on how things go as it proceeds.

Regarding your question, FEniCS 2019.1.0 is the legacy version and it does not support mixed/multi-precision operations.

We have built DOLFINx with mixed and multi-precision arithmetic in mind, but we haven't yet explored the potential in terms of implementing real algorithms; for your project I would strongly recommend using the C++ interface to DOLFINx where you have explicit control over the types of both the expansion coefficients and geometry information through templating, rather than Python.

Additionally, we've never tried quad precision, only double and lower precisions.

jhale commented 9 months ago

C++ doesn't have a quad precision implementation in its standard library. So you will immediately run into issues with our use of the type concepts std::floating_point and dolfinx::scalar https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/common/types.h#L19

Are you sure you need quad precision? Typically you'd be looking to use doubles as your highest precision and then improve performance through clever use of lower precisions.

RamakrishnanChandran commented 9 months ago

Dear Mr. Hale,

Yeah, I will check how I can use the C++ interface to create a driver for Data extraction for my experiments.

In case you are aware of any tutorials. Could you please give some suggestions for any tutorial which uses C++ interface directly.

Thanks and regards, Ramakrishnan C.

On Fri, Dec 8, 2023 at 11:55 AM Jack S. Hale @.***> wrote:

This project sounds very interesting and it would be good if you could keep us informed on how things go as it proceeds.

Regarding your question, FEniCS 2019.1.0 is the legacy version and it does not support mixed/multi-precision operations.

We have built DOLFINx with mixed and multi-precision arithmetic in mind, but we haven't yet explored the potential in terms of implementing real algorithms; for your project I would strongly recommend using the C++ interface to DOLFINx where you have explicit control over the types of both the expansion coefficients and geometry information through templating, rather than Python.

Additionally, we've never tried quad precision, only lower precisions.

— Reply to this email directly, view it on GitHub https://github.com/FEniCS/dolfinx/issues/2926#issuecomment-1846958591, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZDGVRD2KYLVXZFV3VJACPLYILW2RAVCNFSM6AAAAABAMN3QBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWHE2TQNJZGE . You are receiving this because you authored the thread.Message ID: @.***>

RamakrishnanChandran commented 9 months ago

Dear Mr. Hale,

Yeah, that is true. The AMG solver (part of GaspiLS, a linear solver library) which is experimented uses Double and single precision in IR algorithmic setup.

However, f the Matrix and RHS data from FENICS and L2 error norm measurement if done in higher precision could help in producing results which are more reliable. That's the reason, I'm looking for Quad precision.

Anyway, the use of concepts coupled with no quad precision in std library means even if I use C++ interface of FENICSx for Data extraction, I can't build the code for quad precision right?

Thanks and Regards, Ramakrishnan C.

On Fri, Dec 8, 2023 at 12:01 PM Jack S. Hale @.***> wrote:

C++ doesn't have a quad precision implementation in its standard library. So you will immediately run into issues with our use of the type concepts std::floating_point and dolfinx::scalar https://github.com/FEniCS/dolfinx/blob/main/cpp/dolfinx/common/types.h#L19

Are you sure you need quad precision? Typically you'd be looking to use doubles as your highest precision and then improve performance through clever use of lower precisions.

— Reply to this email directly, view it on GitHub https://github.com/FEniCS/dolfinx/issues/2926#issuecomment-1846966624, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZDGVREDV2BSTA6OVRWWYUTYILXQ5AVCNFSM6AAAAABAMN3QBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBWHE3DMNRSGQ . You are receiving this because you authored the thread.Message ID: @.***>

jhale commented 9 months ago

You can make a fork and modify the concepts to accept the types you need.

RamakrishnanChandran commented 9 months ago

Dear Mr. Hale,

Thanks for your hint. I will try to work on that guidelines and update you.

Thanks and Regards, Ramakrishnan C.

On Fri, 8 Dec, 2023, 9:49 pm Jack S. Hale, @.***> wrote:

You can make a fork and modify the concepts to accept the types you need.

— Reply to this email directly, view it on GitHub https://github.com/FEniCS/dolfinx/issues/2926#issuecomment-1847826917, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZDGVRFHFCNJY7LC733O5CDYIN4MVAVCNFSM6AAAAABAMN3QBWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBXHAZDMOJRG4 . You are receiving this because you authored the thread.Message ID: @.***>

garth-wells commented 9 months ago

You could try with C++23 fixed width floating-point types (https://en.cppreference.com/w/cpp/types/floating-point). I don't know where compiler support is at.