[dune-fem] Fwd: b4102c1 added dump on file for discretefunction (usefull to debug in Matlab

Robert Kloefkorn robertk at posteo.de
Mon Feb 9 16:16:15 CET 2015


Hi Marco,

thanks for contributing to dune-fem.

Nevertheless, I would like to point out, that the method you added in
your last patch is very user specific (matlab etc.) and also available
via the method

write( OutStreamInterface< StreamTraits > &out ) const

where in your case OutStreamInterface is to chosen as
ASCIIOutStream file( filename );

Also, there is a reason why the method print( filename ) is not
available. Creating a filename is something the user should do, because
it reduces maintenance on dune-fem side. The same holds for the methods
that were added to some of the matrix classes some weeks ago.

If you think that this is a feature that is badly needed, then please
express this on the dune-fem list (dune-fem at dune-project.org).

Thanks and regards,

Robert


-------- Forwarded Message --------
Subject: 	b4102c1 added dump on file for discretefunction (usefull to
debug in Matlab
Date: 	Mon, 9 Feb 2015 15:02:30 +0000
From: 	marco.agnese88 at gmail.com <ma2413 at imperial.ac.uk>



b4102c1 added dump on file for discretefunction (usefull to debug in
Matlab commit b4102c1bb3b143d231e8363fe60086fe8eab37a7
Author: marco.agnese88 at gmail.com <ma2413 at imperial.ac.uk>
Date: Mon, 9 Feb 2015 15:02:30 +0000

added dump on file for discretefunction (usefull to debug in Matlab

diff --git a/dune/fem/function/common/discretefunction.hh
b/dune/fem/function/common/discretefunction.hh
index f47812f..389b884 100644
--- a/dune/fem/function/common/discretefunction.hh
+++ b/dune/fem/function/common/discretefunction.hh
@@ -3,6 +3,8 @@

// C++ includes
#include <string>
+#include <iostream>
+#include <fstream>

// dune-common inlcudes
#include <dune/common/version.hh>
@@ -348,6 +350,15 @@ namespace Dune
asImp().print( out );
}

+ /** brief dump all DoFs into a file (for debugging purposes)
+ *
+ * param[in] filename name of file to dump into
+ */
+ inline void print( const std :: string &filename ) const
+ {
+ asImp().print( filename );
+ }
+
/** brief check for NaNs
* returns if one of the DoFs is NaN b false is returned, otherwise b true
*/
@@ -664,6 +675,9 @@ namespace Dune
/** copydoc Dune::Fem::DiscreteFunctionInterface::print */
void print ( std :: ostream &out ) const;

+ /** copydoc Dune::Fem::DiscreteFunctionInterface::print */
+ void print ( const std :: string &filename ) const;
+
/** copydoc Dune::Fem::DiscreteFunctionInterface::dofsValid */
inline bool dofsValid () const;

diff --git a/dune/fem/function/common/discretefunction_inline.hh
b/dune/fem/function/common/discretefunction_inline.hh
index 82503bb..4a74f6a 100644
--- a/dune/fem/function/common/discretefunction_inline.hh
+++ b/dune/fem/function/common/discretefunction_inline.hh
@@ -100,6 +100,23 @@ namespace Dune
out << (*dit) << std::endl;
}

+ template< class Impl >
+ inline void DiscreteFunctionDefault<Impl >
+ :: print ( const std::string &filename ) const
+ {
+ std::cout << "Dump " << BaseType :: name() << " on file" << std::endl;
+ std::ofstream ofs;
+ ofs.open(filename.c_str());
+ if(ofs.is_open())
+ {
+ const ConstDofIteratorType end = BaseType :: dend();
+ for( ConstDofIteratorType dit = BaseType :: dbegin(); dit != end; ++dit )
+ ofs << (*dit) << std::endl;
+ }
+ else
+ std::cout << "Not able to open the file " << filename << std::endl;
+ ofs.close();
+ }

template< class Impl >
inline bool DiscreteFunctionDefault< Impl >







More information about the dune-fem mailing list