Commit 5674ef64 authored by Benoît LÉ's avatar Benoît LÉ

Modification to take into account new xPostProcessingManager in xExport

Old PostProcessing class was renamed xPostProcessingManager and moved to
xExport, execept for the archiveSave function, which is specific to
TLSELementBased. A TLSPostProcessing was derived from xPostProcessingManager,
which only have one more function, archiveSave.
parent 4c9aaa9a
/*
/*
This file is a part of eXlibris C++ Library
under the GNU General Public License:
See the LICENSE.md files for terms and
See the LICENSE.md files for terms and
conditions.
*/
#include "Export.h"
#include <fstream>
#include <string>
#include "Observer.h"
#include "mEntity.h"
#include <string>
#include <fstream>
using namespace std;
using namespace xfem;
stack<pair<string, chrono::time_point<std::chrono::system_clock>>> Display::str_container
= stack<pair<string, chrono::time_point<std::chrono::system_clock>>>();
stack<pair<string, chrono::time_point<std::chrono::system_clock>>> Display::str_container =
stack<pair<string, chrono::time_point<std::chrono::system_clock>>>();
string Display::prefix = string("\033[0;36m");
string Display::suffix = string("\033[0;37m");
void Display::txtColorOff() {
prefix = "";
suffix = "";
}
void Display::setPrefixAndSuffix(string prefix_, string suffix_) {
prefix = prefix_;
suffix = suffix_;
}
void Display::init() { // To be suppressed soon
int i;
for (i=0; i<=10; i=i+1) {
std::cout << " "<< endl;
}
void Display::txtColorOff()
{
prefix = "";
suffix = "";
}
void Display::emph(string str) {
cout << prefix << str << suffix << endl;
void Display::setPrefixAndSuffix(string prefix_, string suffix_)
{
prefix = prefix_;
suffix = suffix_;
}
void Display::dispIn(string& str, unsigned int n) {
cout << string(2*n, ' ') << prefix << "(" << n << ") Enter " << str << suffix << endl; // see http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
void Display::init()
{ // To be suppressed soon
int i;
for (i = 0; i <= 10; i = i + 1)
{
std::cout << " " << endl;
}
}
void Display::dispOut(string& str, unsigned int n, double time) {
cout << string(2*n, ' ') << prefix << "(" << n << ") Quit " << str << string(70-2*n-str.size(), ' ') << time << suffix << endl;
}
void Display::emph(string str) { cout << prefix << str << suffix << endl; }
void Display::stepIn(string str) {
return;
str_container.push(make_pair(str, schrono()));
dispIn(str, str_container.size());
str_container.top().second=chrono::system_clock::now();
void Display::dispIn(string& str, unsigned int n)
{
cout << string(2 * n, ' ') << prefix << "(" << n << ") Enter " << str << suffix
<< endl; // see http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
}
void Display::stepOut() {
return;
schrono stop=chrono::system_clock::now();
pair<string, schrono>& pair=str_container.top();
string& str=pair.first;
std::chrono::duration<double> dur=stop-pair.second;
dispOut(str, str_container.size(), dur.count());
str_container.pop();
void Display::dispOut(string& str, unsigned int n, double time)
{
cout << string(2 * n, ' ') << prefix << "(" << n << ") Quit " << str << string(70 - 2 * n - str.size(), ' ') << time << suffix
<< endl;
}
void Display::stepOut(string str) {
return;
string& str_verif = str_container.top().first;
if (str == str_verif) {
stepOut();
} else {
std::cout << "In Export.cc, " << str << " different from " << str_verif << endl;
}
void Display::stepIn(string str)
{
return;
str_container.push(make_pair(str, schrono()));
dispIn(str, str_container.size());
str_container.top().second = chrono::system_clock::now();
}
PostProcessing::PostProcessing(const xParseData& parse_data_, xexport::xExport &pexport_, xEntityFilter filter) :
parse_data(parse_data_),
export_manager(GetNbDigits(parse_data.getInt("nb_step_max"))),
filter(filter) ,
pexport(pexport_) {
export_manager.init(parse_data, "export_manager");
}
void PostProcessing::init(xMesh& mesh) {
sensor_manager.init(parse_data, &mesh, 2, "export_sensors_label", "export_sensors_point");
}
void PostProcessing::reinit(xMesh& mesh) {
sensor_manager.reinit(&mesh);
void Display::stepOut()
{
return;
schrono stop = chrono::system_clock::now();
pair<string, schrono>& pair = str_container.top();
string& str = pair.first;
std::chrono::duration<double> dur = stop - pair.second;
dispOut(str, str_container.size(), dur.count());
str_container.pop();
}
bool PostProcessing::toExport(const std::string export_name) {
return sensor_manager.toExport(export_name);
void Display::stepOut(string str)
{
return;
string& str_verif = str_container.top().first;
if (str == str_verif)
{
stepOut();
}
else
{
std::cout << "In Export.cc, " << str << " different from " << str_verif << endl;
}
}
bool PostProcessing::toExport(const std::string export_name, const int step) {
return export_manager.toExport(export_name, step, "");
TLSPostProcessing::TLSPostProcessing(const xParseData& parse_data_, xexport::xExport& pexport_, xEntityFilter filter)
: xPostProcessingManager(parse_data_, pexport_, filter)
{
}
void PostProcessing::exportOnSpace(const std::string export_name, const int step, const xLevelSet& ls) {
if(export_manager.toExport(export_name, step, "")) {
pexport.openFile(export_manager.getFileName());
Export(ls, pexport, export_name);
pexport.closeFile();
}
}
void PostProcessing::exportOnSpace(const std::string export_name, const int step, const xMesh& mesh) {
if(export_manager.toExport(export_name, step, "")) {
Export(mesh, pexport, export_manager.getFileName());
}
}
void PostProcessing::exportOnTime(const std::string name, const double time, const double val) {
sensor_manager.measure(val, time, name);
}
void PostProcessing::exportOnTime(const std::string name, const double time, const xEval<double>& eval) {
sensor_manager.measureAll(eval, time, name);
}
void PostProcessing::exportOnTime(const std::string name, const double time, const xEval<xtensor::xVector<>>& eval) {
sensor_manager.measureAll(eval, time, name);
}
void PostProcessing::exportOnTime(const std::string name, const double time, const xEval<xtensor::xTensor2<>>& eval) {
sensor_manager.measureAll(eval, time, name);
}
void PostProcessing::saveMesh(std::string export_name, int step, xMesh& mesh) {
if(step>0 && export_manager.toExport("save", step, "")) {
Export(mesh, pexport, export_name+"_save");
}
}
void PostProcessing::saveField(std::string export_name, int step, const xField<>& field, xRegion reg) {
if(step>0 && export_manager.toExport("save", step, "")) {
xValueManagerDist<double>* double_manager=field.getValueManager();
std::ofstream oss(export_name+"_save.bin", ios::binary);
if(oss.is_open()) {
const int info_size=2*reg.dim()*sizeof(int);
int nb=reg.size(reg.dim());
oss.write((char*)&nb, sizeof(int));
for(auto e: reg) {
xFiniteElement FEM;
FEM.setKeys(e, field.begin(), field.end()) ;
const int size=FEM.sizeKey();
std::vector<xValue<double>*> vals;
vals.reserve(size);
double_manager->getValPtr(FEM.beginKey(), FEM.endKey(), vals);
assert(size<7);
int info[6];
info[0]=size;
for(int i=0; i<e->size(0); ++i) {
auto n=e->get(0, i);
info[i+1]=n->getId();
}
double data[16];
for(int i=0; i<size; ++i) {
data[i]=vals[i]->getVal();
}
oss.write((char*)info, info_size);
oss.write((char*)data, size*sizeof(double));
void TLSPostProcessing::archiveSave(int step)
{
if (step > 0 && export_manager.toExport("save", step, ".tar"))
{
if (system(NULL) == 0)
{
std::cout << "Error: system not callable" << std::endl;
std::abort();
}
oss.close();
}
}
}
void PostProcessing::archiveSave(int step) {
if(step>0 && export_manager.toExport("save", step, ".tar")) {
if(system(NULL)==0) {
std::cout<<"Error: system not callable"<<std::endl;
std::abort();
}
std::ofstream oss("step_save.bin", ios::binary);
if(oss.is_open()) {
double load_factor, old_load_factor, load_factor_variation;
Observer::tell("old_load_factor", old_load_factor);
Observer::tell("load_factor", load_factor);
Observer::tell("load_factor_variation", load_factor_variation);
oss.write((char*)&step, sizeof(int));
oss.write((char*)&old_load_factor, sizeof(double));
oss.write((char*)&load_factor, sizeof(double));
oss.write((char*)&load_factor_variation, sizeof(double));
oss.close();
}
std::string command="tar cf "+export_manager.getFileName()+" *_save.*";
system(command.c_str());
system("rm -f *_save.*");
}
std::ofstream oss("step_save.bin", ios::binary);
if (oss.is_open())
{
double load_factor, old_load_factor, load_factor_variation;
Observer::tell("old_load_factor", old_load_factor);
Observer::tell("load_factor", load_factor);
Observer::tell("load_factor_variation", load_factor_variation);
oss.write((char*)&step, sizeof(int));
oss.write((char*)&old_load_factor, sizeof(double));
oss.write((char*)&load_factor, sizeof(double));
oss.write((char*)&load_factor_variation, sizeof(double));
oss.close();
}
std::string command = "tar cf " + export_manager.getFileName() + " *_save.*";
system(command.c_str());
system("rm -f *_save.*");
}
}
......@@ -7,206 +7,49 @@
#ifndef _TLSDuctile_Export_h_
#define _TLSDuctile_Export_h_
#include <chrono>
#include <stack>
#include <string>
#include "xAlgorithm.h"
#include "xExportAlgorithm.h"
#include "xExportGmsh.h"
#include "xExportManager.h"
#include "xField.h"
#include "xPostProcessingManager.h"
#include "xSensors.h"
#include <chrono>
#include <stack>
#include <string>
class Display {
public:
static void txtColorOff();
static void setPrefixAndSuffix(string, string);
static void emph(string);
class Display
{
public:
static void txtColorOff();
static void setPrefixAndSuffix(string, string);
static void emph(string);
static void init();
static void dispIn(std::string &, unsigned int);
static void dispOut(std::string &, unsigned int, double);
static void init();
static void dispIn(std::string &, unsigned int);
static void dispOut(std::string &, unsigned int, double);
static void stepIn(std::string);
static void stepIn(std::string);
static void stepOut(std::string);
static void stepOut();
static void stepOut(std::string);
static void stepOut();
private:
static std::string prefix;
static std::string suffix;
typedef std::chrono::time_point<std::chrono::system_clock> schrono;
static std::stack<std::pair<std::string, schrono>> str_container;
private:
static std::string prefix;
static std::string suffix;
typedef std::chrono::time_point<std::chrono::system_clock> schrono;
static std::stack<std::pair<std::string, schrono>> str_container;
};
inline int GetNbDigits(int nb) {
if (nb < 0) {
return 1;
}
int digits = 0;
while (nb) {
nb /= 10;
++digits;
}
return digits;
}
class PostProcessing {
public:
PostProcessing(const xParseData &, xexport::xExport &,
xfem::xEntityFilter = xfem::xAcceptAll());
// init and reinit xfem::xGeomElem used by xexport::xSensors to measure.
void init(xfem::xMesh &);
void reinit(xfem::xMesh &);
void createCurvesPlotFiles(std::string);
bool toExport(const std::string export_name);
bool toExport(const std::string export_name, const int step);
void exportOnSpace(const std::string export_name, const int step,
const xfem::xLevelSet &ls);
template <typename ITER>
void exportOnSpace(
const std::string export_name, const int step,
const xfem::xEval<double> &eval,
const xfem::xIntegrationRule &integration_rule, ITER begin, ITER end,
xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>()) {
if (export_manager.toExport(export_name, step, "")) {
exportOnSpace(export_name, eval, integration_rule, begin, end,
integ2appro);
}
}
template <typename ITER>
void exportOnSpace(
const std::string export_name, const int step,
const xfem::xEval<xtensor::xVector<>> &eval,
const xfem::xIntegrationRule &integration_rule, ITER begin, ITER end,
xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>()) {
if (export_manager.toExport(export_name, step, "")) {
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, "")) {
xtensor::xExtractCompVector<> extract(i);
xfem::xEvalUnary<xtensor::xExtractCompVector<>> evalex(extract, eval);
exportOnSpace(export_name, evalex, integration_rule, begin, end,
integ2appro);
}
}
}
template <typename ITER>
void exportOnSpace(
const std::string export_name, const int step,
const xfem::xEval<xtensor::xTensor2<>> &eval,
const xfem::xIntegrationRule &integration_rule, ITER begin, ITER end,
xfem::xEntityToEntity integ2appro = xtool::xIdentity<AOMD::mEntity *>()) {
if (export_manager.toExport(export_name, step, "")) {
exportOnSpace(export_name, eval, integration_rule, begin, end,
integ2appro);
}
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
if (export_manager.toExport(export_name + "_" + std::to_string(i + 1) +
std::to_string(j + 1),
step, "")) {
xtensor::xExtractCompTensor<> extract(i, j);
xfem::xEvalUnary<xtensor::xExtractCompTensor<>> evalex(extract, eval);
exportOnSpace(export_name, evalex, integration_rule, begin, end,
integ2appro);
}
}
}
if (export_manager.toExport(export_name + "_tr", step, "")) {
xfem::xEvalUnary<xtensor::xTrace<>> evaltr(eval);
exportOnSpace(export_name, evaltr, integration_rule, begin, end,
integ2appro);
}
if (export_manager.toExport(export_name + "_dev", step, "")) {
xfem::xEvalUnary<xtensor::xDeviatoric<>> evaldev(eval);
exportOnSpace(export_name, evaldev, integration_rule, begin, end,
integ2appro);
}
}
template <typename ITER>
void exportOnTime(const std::string name, const double time,
const xfem::xEval<double> &eval,
const xfem::xIntegrationRule &integration_rule, ITER begin,
ITER end, xfem::xEntityToEntity entity_to_entity) {
if (sensor_manager.toExport(name)) {
double global = 0.;
xfem::xIntegrateEvalCommand<xfem::xEval<double>> command(eval, global);
xfem::ApplyCommandOnIntegrationRule(command, integration_rule, begin, end,
entity_to_entity);
sensor_manager.measure(global, time, name);
}
}
void exportOnSpace(const std::string export_name, const int step,
const xfem::xMesh &mesh);
void exportOnTime(const std::string name, const double time,
const double val);
void exportOnTime(const std::string name, const double time,
const xfem::xEval<double> &eval);
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 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);
template <typename ITER>
void saveDomain(std::string export_name, int step, ITER it, ITER end) {
if (step > 0 && export_manager.toExport("save", step, "")) {
std::ofstream oss(export_name + "_save.bin", std::ios::binary);
if (oss.is_open()) {
int nb = std::distance(it, end);
oss.write((char *)&nb, sizeof(int));
for (; it != end; ++it) {
auto e = *it;
int data[16];
int size = e->size(0);
for (int i = 0; i < size; ++i) {
data[i] = e->get(0, i)->getId();
}
oss.write((char *)&size, sizeof(int));
oss.write((char *)data, size * sizeof(int));
}
oss.close();
}
}
}
void archiveSave(int step);
class TLSPostProcessing : public xexport::xPostProcessingManager
{
public:
TLSPostProcessing(const xParseData &, xexport::xExport &, xfem::xEntityFilter = xfem::xAcceptAll());
private:
template <typename EVAL, typename ITER>
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 *>()) {
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();
}
void archiveSave(int step);
const xParseData &parse_data;
xexport::xExportManager export_manager;
xexport::xExportSensors sensor_manager;
xexport::xExport &pexport;
xfem::xEntityFilter filter;
private:
};
#endif
This diff is collapsed.
......@@ -8,16 +8,17 @@
#ifndef _TLSDuctile_Formulation_h_
#define _TLSDuctile_Formulation_h_
#include <vector>
#include "xField.h"
class LinearSystem;
class PostProcessing;
class TLSPostProcessing;
class TLSGeom;
namespace xfem
{
class xData;
class xSpaceFactoryBase;
}
} // namespace xfem
namespace xtls
{
class xEvalTLSDamageFunction;
......@@ -36,7 +37,7 @@ class xCSRVector;
class Formulation
{
public:
Formulation(TLSGeom&, const xfem::xData&, const xParseData&, PostProcessing&);
Formulation(TLSGeom&, const xfem::xData&, const xParseData&, TLSPostProcessing&);
virtual ~Formulation();
// Simple accessors
......@@ -133,7 +134,7 @@ class Formulation
TLSGeom& geom;
const xfem::xData& data;
const xParseData& parse_data;
PostProcessing& post_pro;
TLSPostProcessing& post_pro;
xfem::xValueManagerDist<double> double_manager;
xfem::xVariabManager variab_manager;
......
This diff is collapsed.
/*
/*
This file is a part of eXlibris C++ Library
under the GNU General Public License:
See the LICENSE.md files for terms and
See the LICENSE.md files for terms and
conditions.
*/
......@@ -13,30 +13,30 @@
class PreProcessing;
class TLSSolver;
class DynFormulation : public Formulation {
public:
DynFormulation(TLSGeom&, TLSSolver&,
const xfem::xData&, const xParseData&,
PreProcessing&, PostProcessing&);
void readSpeed(xlinalg::xCSRVector&);
void writeSpeed(const xlinalg::xCSRVector&);
void updateCurrentState(double, double);
class DynFormulation : public Formulation
{
public:
DynFormulation(TLSGeom&, TLSSolver&, const xfem::xData&, const xParseData&, PreProcessing&, TLSPostProcessing&);
void readSpeed(xlinalg::xCSRVector&);
void writeSpeed(const xlinalg::xCSRVector&);
void updateCurrentState(double, double);
double getTimeStep() const;
double getTimeStep() const;
bool isToReallocate() const;
void exportStep(int, double);
private:
void updateLevelSetField(double);
bool isToReallocate() const;
void exportStep(int, double);
// Calls tls solver to compute all required mean fields to update phi.
// Required mean fields are declared in the constructor.
void computeLSAdvanceMeanFields();
private:
void updateLevelSetField(double);
// Computes delta phi and writes it to tls solver.
void computeDeltaLevelSetField(double);
// Calls tls solver to compute all required mean fields to update phi.
// Required mean fields are declared in the constructor.
void computeLSAdvanceMeanFields();
TLSSolver& tls_solver;
// Computes delta phi and writes it to tls solver.
void computeDeltaLevelSetField(double);
TLSSolver& tls_solver;
};
#endif
......@@ -6,33 +6,31 @@
*/
#include "FormulationQS.h"
#include "Export.h"
#include "Import.h"
#include "LinearSystem.h"
#include "MaterialCommand.h"
#include "NonUniformMaterialSensitivity.h"
#include "Observer.h"
#include "TLSGeom.h"
#include "TLSSolver.h"
#include "Util.h"
#include "xAlgorithm.h"
#include "xAssembler.h"
#include "xCSRMatrix.h"
#include "xCSRVector.h"
#include "xCommandOnGeomElem.h"
#include "xData.h"
#include "xMaterialSensitivity.h"
#include "xMesh.h"
#include "xSpaceFactory.h"
#include "xCSRMatrix.h"
#include "xCSRVector.h"
#include "MaterialCommand.h"
#include "NonUniformMaterialSensitivity.h"
using namespace xfem;
// using namespace xlinalg;
QSFormulation::QSFormulation(TLSGeom& geom, TLSSolver& tls_solver, const xData& data, const xParseData& parse_data,
PreProcessing& pre_pro, PostProcessing& post_pro)
PreProcessing& pre_pro, TLSPostProcessing& post_pro)
: Formulation(geom, data, parse_data, post_pro),
tls_solver(tls_solver),
disp_field_meas(&double_manager_meas),
......
/*
/*
This file is a part of eXlibris C++ Library
under the GNU General Public License:
See the LICENSE.md files for terms and
See the LICENSE.md files for terms and
conditions.
*/
......@@ -12,84 +12,84 @@
class PreProcessing;
class TLSSolver;
class QSFormulation : public Formulation {
public:
QSFormulation(TLSGeom&, TLSSolver&,
const xfem::xData&, const xParseData&,
PreProcessing&, PostProcessing&);
virtual ~QSFormulation();
class QSFormulation : public Formulation
{
public:
QSFormulation(TLSGeom&, TLSSolver&, const xfem::xData&, const xParseData&, PreProcessing&, TLSPostProcessing&);
virtual ~QSFormulation();
// Updates level set field and material variables
virtual void updateCurrentState();
// Updates level set field and material variables
virtual void updateCurrentState();
// Perturbs level set field and updates material variables
virtual bool updateCurrentStateForced();
// Perturbs level set field and updates material variables
virtual bool updateCurrentStateForced();
// Computes load factor variation
virtual void computeLoadFactorVariation();
// Computes load factor variation
virtual void computeLoadFactorVariation();
// Computes load factor
double computeLoadFactor();
// Computes load factor
double computeLoadFactor();
// Writes to disp field dof values from xlinalg::xCSRVector, a specific
// disp field is selected by the string
void writeDisp(const xlinalg::xCSRVector&, std::string);
// Writes to disp field dof values from xlinalg::xCSRVector, a specific