Re: [deal.II] DataOut<dim> class only offers 6 digit output for double type?

20 views
Skip to first unread message

Timo Heister

unread,
Feb 8, 2022, 6:50:06 PM2/8/22
to dea...@googlegroups.com
huyanzhuo,

We compute and then output data inside DataOut<dim> as float (32 bit
floating point) and not as double (64bit). Float has an accuracy of
approximately 7 decimal digits, so your number would be roughly
1647.999 but it happens to be rounded up to 1648.000.
I am afraid there is no easy way to change this because this is
hard-coded inside DataOut<dim>. It is in the Patch class if you are
curious:
https://www.dealii.org/developer/doxygen/deal.II/structDataOutBase_1_1Patch.html#a366bf92bcc2b667586d630455953d911

Normally, this should be enough for visualization.

On Tue, Feb 8, 2022 at 4:58 PM huyanzhuo <hu4ya...@gmail.com> wrote:
>
> I'm using the 8.5.1 version.
> As the theme side, i gives a vector to a DataOut<dim> object, the type of the vector entry is double, with 15 effective digit. But there is only 6 digit when write to a file (vtk or gpl). My vector is around 1647.99932xxxx, the result write into the file is 1648. How can i improve the presion of the result in file?
>
> --
> The deal.II project is located at http://www.dealii.org/
> For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
> ---
> You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/db91c18b-7e9b-4aa0-9a81-3e93e1f3df2an%40googlegroups.com.



--
Timo Heister
http://www.math.clemson.edu/~heister/

Wolfgang Bangerth

unread,
Feb 8, 2022, 11:53:49 PM2/8/22
to dea...@googlegroups.com

> As the theme side, i gives a vector to a  DataOut<dim> object, the type of the
> vector entry is double, with 15 effective digit. But there is only 6 digit
> when write to a file (vtk or gpl). My vector is around  1647.99932xxxx, the
> result write into the file is 1648. How can i improve the presion of the
> result in file?

You probably just need to call
output_file_stream.precision(12);
before calling
data_out.write_vtk(output_file_stream);
This should make sure that output is written with 12 digits rather than C++'s
default of 6 digits.

That said, do you really need this many digits of accuracy? It is very
difficult to solve PDEs to more than, say, 4 digits of accuracy. As a
consequence, it would surprise me if you actually need more accuracy than just
the default 6 digits in your output files.

Best
W.


--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Reply all
Reply to author
Forward
0 new messages