Commit 89c57a55 authored by Benoît LÉ's avatar Benoît LÉ

[xExport] Added some functionnalities to xPostProcessingManager

- Added a getFileName() function, which calls the getFileName() of xExportManager
(which has been made const)

- Added an exportDebug function, to export values managers. In the future it could
eventually be overloaded to export other debug files. A good example could be
xCSRVector or matrixes, but it would introduced a dependency of xExport on xLinalg

- Added a debug flag with a setDebugFlag function to add some debug output

- Now the exportOnSpace functions automatically set the number of splits of the
xExport to 1 (similarly to the old MyExport function of DamageGrowthBase in TLSImplicit)
parent 5230450c
/*
/*
This file is a part of eXlibris C++ Library
under the GNU Lesser General Public License.
See the NOTICE.md & LICENSE.md files for terms
See the NOTICE.md & LICENSE.md files for terms
and conditions.
*/
......@@ -9,8 +9,8 @@
#define _EXPORTMANAGER_H
#include <map>
#include <string>
#include <sstream>
#include <string>
#include <utility>
struct xParseData;
......@@ -28,68 +28,67 @@ struct xParseData;
namespace xexport
{
class xExportManager
{
class xExportManager
{
public:
/// constructor
xExportManager(const int step_string_length_=5);
/// constructor
xExportManager(const int step_string_length_ = 5);
/// to read what to export from an xParseData EXPORT_MANAGER label
/// EXPORT_MANAGER list format must be { name directive name directive .... } where directive is :
/// one single integer discribing output frequency
/// an integer discribing output frequency followed by '+' character followed by a integer discribing threshold (starting potential output)
void init(const xParseData& export_parser_,const std::string& xParseData_token_EXPORT_MANAGER="EXPORT_MANAGER");
/// to read what to export from an xParseData EXPORT_MANAGER label
/// EXPORT_MANAGER list format must be { name directive name directive .... } where directive is :
/// one single integer discribing output frequency
/// an integer discribing output frequency followed by '+' character followed by a integer discribing threshold (starting
/// potential output)
void init(const xParseData& export_parser_, const std::string& xParseData_token_EXPORT_MANAGER = "EXPORT_MANAGER");
/// to manage what to export manually
void registerExport(const std::string& export_name_, const int frequency_, const int threshold_=0);
/// to manage what to export manually
void registerExport(const std::string& export_name_, const int frequency_, const int threshold_ = 0);
/// to know if a specific export is to be exported or not, build the file_name adding the number of the step
inline bool toExport(const std::string& export_name_, const int step_, const std::string& extension_name_="");
/// to know if a specific export is to be exported or not, build the file_name adding the number of the step
inline bool toExport(const std::string& export_name_, const int step_, const std::string& extension_name_ = "");
/// to get the current file_name
inline std::string getFileName() { return file_name; }
/// to get the current file_name
inline std::string getFileName() const { return file_name; }
/// to change default step_string_length
void setNumerationSize(const int step_string_length_);
/// to change default step_string_length
void setNumerationSize(const int step_string_length_);
private:
inline std::string outputId(const int time_id);
int step_string_length;
std::string file_name;
inline std::string outputId(const int time_id);
std::map<std::string, std::pair<int,int> > info_container;
};
int step_string_length;
std::string file_name;
std::map<std::string, std::pair<int, int>> info_container;
};
inline std::string xExportManager::outputId(const int time_id)
{
std::ostringstream out;
out.width(step_string_length);
out.fill('0');
out << time_id;
return "_"+out.str();
}
inline std::string xExportManager::outputId(const int time_id)
{
std::ostringstream out;
out.width(step_string_length);
out.fill('0');
out << time_id;
return "_" + out.str();
}
inline bool xExportManager::toExport(const std::string& export_name_, const int step_, const std::string& extension_name_)
{
std::map<std::string, std::pair<int,int> >::const_iterator it = info_container.find(export_name_);
if (it!=info_container.end())
inline bool xExportManager::toExport(const std::string& export_name_, const int step_, const std::string& extension_name_)
{
std::map<std::string, std::pair<int, int>>::const_iterator it = info_container.find(export_name_);
if (it != info_container.end())
{
const std::pair<int, int>& info = it->second;
bool test1 = step_ >= info.first;
bool test2 = step_ % info.second == 0;
if (test1 && test2)
{
const std::pair<int, int>& info = it->second;
bool test1 = step_>=info.first;
bool test2 = step_%info.second==0;
if (test1 && test2)
{
file_name = export_name_+outputId(step_)+extension_name_;
return true;
}
file_name = export_name_ + outputId(step_) + extension_name_;
return true;
}
file_name = "";
return false;
}
}
file_name = "";
return false;
}
} // namespace xexport
#endif
......@@ -48,6 +48,9 @@ void xPostProcessingManager::initSensors(xfem::xMesh& mesh, const xParseData& pa
}
void xPostProcessingManager::reinitMesh(xMesh& mesh) { sensor_manager.reinit(&mesh); }
void xPostProcessingManager::setDebugFlag(bool debug_) { debug = debug_; }
std::string xPostProcessingManager::getFileName() const { return export_manager.getFileName(); }
bool xPostProcessingManager::toExport(const std::string export_name) { return sensor_manager.toExport(export_name); }
bool xPostProcessingManager::toExport(const std::string export_name, const int step, const std::string& extension_name)
......@@ -59,9 +62,11 @@ void xPostProcessingManager::exportOnSpace(const std::string export_name, const
{
if (export_manager.toExport(export_name, step, ""))
{
if (debug) cout << "Exporting " << export_manager.getFileName() << " with nb split = " << pexport.getNbSplit() << endl;
pexport.openFile(export_manager.getFileName());
Export(ls, pexport, export_name);
pexport.closeFile();
pexport.setNbSplit(1);
}
}
......@@ -69,7 +74,9 @@ void xPostProcessingManager::exportOnSpace(const std::string export_name, const
{
if (export_manager.toExport(export_name, step, ""))
{
if (debug) cout << "Exporting " << export_manager.getFileName() << " with nb split = " << pexport.getNbSplit() << endl;
Export(mesh, pexport, export_manager.getFileName());
pexport.setNbSplit(1);
}
}
......@@ -93,6 +100,15 @@ void xPostProcessingManager::exportOnTime(const std::string name, const double t
sensor_manager.measureAll(eval, time, name);
}
void xPostProcessingManager::exportDebug(const std::string export_name, const int step, xfem::xValueManagerDist<double>& dm)
{
if (export_manager.toExport(export_name, step, ".dbg"))
{
if (debug) cout << "Exporting " << export_manager.getFileName() << endl;
dm.PrintForDebug(export_manager.getFileName());
}
}
void xPostProcessingManager::saveMesh(std::string export_name, int step, xMesh& mesh)
{
if (step > 0 && export_manager.toExport("save", step, ""))
......
......@@ -24,6 +24,9 @@ class xPostProcessingManager
void initExportManager(const xParseData &, std::string, const int);
void initSensors(xfem::xMesh &, const xParseData &, std::string, std::string);
void reinitMesh(xfem::xMesh &);
void setDebugFlag(bool);
std::string getFileName() const;
bool toExport(const std::string export_name);
bool toExport(const std::string export_name, const int step, const std::string &extension_name = "");
......@@ -46,14 +49,17 @@ class xPostProcessingManager
const xfem::xIntegrationRule &integration_rule, ITER begin, ITER end,
xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>())
{
int nb_split = pexport.getNbSplit();
if (export_manager.toExport(export_name, step, ""))
{
pexport.setNbSplit(nb_split);
exportOnSpace(export_name, eval, integration_rule, begin, end, integ2appro);
}
for (int i = 0; i < 3; ++i)
{
if (export_manager.toExport(export_name + "_" + std::to_string(i + 1), step, ""))
{
pexport.setNbSplit(nb_split);
xtensor::xExtractCompVector<> extract(i);
xfem::xEvalUnary<xtensor::xExtractCompVector<>> evalex(extract, eval);
exportOnSpace(export_name, evalex, integration_rule, begin, end, integ2appro);
......@@ -66,8 +72,10 @@ class xPostProcessingManager
const xfem::xIntegrationRule &integration_rule, ITER begin, ITER end,
xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>())
{
int nb_split = pexport.getNbSplit();
if (export_manager.toExport(export_name, step, ""))
{
pexport.setNbSplit(nb_split);
exportOnSpace(export_name, eval, integration_rule, begin, end, integ2appro);
}
for (int i = 0; i < 3; ++i)
......@@ -76,6 +84,7 @@ class xPostProcessingManager
{
if (export_manager.toExport(export_name + "_" + std::to_string(i + 1) + std::to_string(j + 1), step, ""))
{
pexport.setNbSplit(nb_split);
xtensor::xExtractCompTensor<> extract(i, j);
xfem::xEvalUnary<xtensor::xExtractCompTensor<>> evalex(extract, eval);
exportOnSpace(export_name, evalex, integration_rule, begin, end, integ2appro);
......@@ -84,11 +93,13 @@ class xPostProcessingManager
}
if (export_manager.toExport(export_name + "_tr", step, ""))
{
pexport.setNbSplit(nb_split);
xfem::xEvalUnary<xtensor::xTrace<>> evaltr(eval);
exportOnSpace(export_name, evaltr, integration_rule, begin, end, integ2appro);
}
if (export_manager.toExport(export_name + "_dev", step, ""))
{
pexport.setNbSplit(nb_split);
xfem::xEvalUnary<xtensor::xDeviatoric<>> evaldev(eval);
exportOnSpace(export_name, evaldev, integration_rule, begin, end, integ2appro);
}
......@@ -114,6 +125,8 @@ class xPostProcessingManager
void exportOnTime(const std::string name, const double time, const xfem::xEval<xtensor::xVector<>> &eval);
void exportOnTime(const std::string name, const double time, const xfem::xEval<xtensor::xTensor2<>> &eval);
void exportDebug(const std::string export_name, const int step, xfem::xValueManagerDist<double> &dm);
void saveMesh(std::string export_name, int step, xfem::xMesh &mesh);
void saveField(std::string export_name, int step, const xfem::xField<> &field, xfem::xRegion reg);
......@@ -149,16 +162,20 @@ class xPostProcessingManager
void exportOnSpace(const std::string &export_name, const EVAL &eval, const xfem::xIntegrationRule &integration_rule,
ITER begin, ITER end, xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>())
{
if (debug)
std::cout << "Exporting " << export_manager.getFileName() << " with nb split = " << pexport.getNbSplit() << std::endl;
pexport.openFile(export_manager.getFileName());
xfem::xFilteredRegion<ITER, xfem::xEntityFilter> fr(begin, end, filter);
Export(eval, pexport, export_name, integration_rule, fr.begin(), fr.end(), integ2appro);
pexport.closeFile();
pexport.setNbSplit(1);
}
xexport::xExportManager export_manager;
xexport::xExportSensors sensor_manager;
xexport::xExport &pexport;
xfem::xEntityFilter filter;
bool debug;
};
} // namespace xexport
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment