dolfin team mailing list archive
-
dolfin team
-
Mailing list archive
-
Message #24400
Re: [noreply@xxxxxxxxxxxxx: [Branch ~dolfin-core/dolfin/main] Rev 6178: Fix problem with pugixml reducing precision of doubles.]
On 12 September 2011 13:42, Anders Logg <logg@xxxxxxxxx> wrote:
> Why 20? Any perhaps this should be made into a global parameter value?
>
That's just a left over debugging line. I've removed it now.
Garth
> --
> Anders
>
>
> ---------- Forwarded message ----------
> From: noreply@xxxxxxxxxxxxx
> To: Anders Logg <logg@xxxxxxxxx>
> Date: Mon, 12 Sep 2011 12:07:16 -0000
> Subject: [Branch ~dolfin-core/dolfin/main] Rev 6178: Fix problem with pugixml reducing precision of doubles.
> ------------------------------------------------------------
> revno: 6178
> committer: Garth N. Wells <gnw20@xxxxxxxxx>
> branch nick: dolfin-all
> timestamp: Mon 2011-09-12 12:52:42 +0100
> message:
> Fix problem with pugixml reducing precision of doubles.
>
> Solution is to cast double to a string before passing to pugixml, thereby avoiding a cast inside pugixml.
> modified:
> dolfin/io/XMLArray.h
>
>
> --
> lp:dolfin
> https://code.launchpad.net/~dolfin-core/dolfin/main
>
> Your team DOLFIN Core Team is subscribed to branch lp:dolfin.
> To unsubscribe from this branch go to https://code.launchpad.net/~dolfin-core/dolfin/main/+edit-subscription
>
> === modified file 'dolfin/io/XMLArray.h'
> --- dolfin/io/XMLArray.h 2011-07-02 14:50:50 +0000
> +++ dolfin/io/XMLArray.h 2011-09-12 11:52:42 +0000
> @@ -23,6 +23,7 @@
>
> #include <ostream>
> #include <string>
> +#include <boost/lexical_cast.hpp>
> #include "dolfin/common/Array.h"
> #include "dolfin/log/log.h"
> #include "pugixml.hpp"
> @@ -90,12 +91,16 @@
> array_node.append_attribute("type") = type.c_str();
> array_node.append_attribute("size") = size;
>
> + std::cout << std::setprecision(20);
> +
> // Add data
> for (uint i = 0; i < size; ++i)
> {
> pugi::xml_node element_node = array_node.append_child("element");
> element_node.append_attribute("index") = i;
> - element_node.append_attribute("value") = x[i];
> + // NOTE: Casting to a string to avoid loss of precision when
> + // pugixml performs double-to-char conversion
> + element_node.append_attribute("value") = boost::lexical_cast<std::string>(x[i]).c_str();
> }
> }
> //-----------------------------------------------------------------------------
>
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dolfin
> Post to : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help : https://help.launchpad.net/ListHelp
>
>
Follow ups
References