Skip to content
Snippets Groups Projects
Commit 07fe1c9c authored by Gauthier Becker's avatar Gauthier Becker
Browse files

Fix compiling with DEBUG pragma

Modified PViewDataGModel to allow for multiple views in the same file
and multiple PViewDataGModel::write() call
parent 439006cd
No related branches found
No related tags found
No related merge requests found
...@@ -471,7 +471,7 @@ int GModel::getPhysicalNumber(const int &dim, const std::string &name) ...@@ -471,7 +471,7 @@ int GModel::getPhysicalNumber(const int &dim, const std::string &name)
return -1; return -1;
} }
int GModel::getDim() int GModel::getDim() const
{ {
if(getNumRegions() > 0) return 3; if(getNumRegions() > 0) return 3;
if(getNumFaces() > 0) return 2; if(getNumFaces() > 0) return 2;
......
...@@ -48,7 +48,8 @@ class GModel ...@@ -48,7 +48,8 @@ class GModel
int _writeMSH2(const std::string &name, double version=2.2, bool binary=false, int _writeMSH2(const std::string &name, double version=2.2, bool binary=false,
bool saveAll=false, bool saveParametric=false, bool saveAll=false, bool saveParametric=false,
double scalingFactor=1.0, int elementStartNum=0, double scalingFactor=1.0, int elementStartNum=0,
int saveSinglePartition=0); int saveSinglePartition=0,
bool multipleView=false);
protected: protected:
// the name of the model // the name of the model
...@@ -299,7 +300,7 @@ class GModel ...@@ -299,7 +300,7 @@ class GModel
std::string getElementaryName(int dim, int num); std::string getElementaryName(int dim, int num);
//get the highest dimension of the GModel //get the highest dimension of the GModel
int getDim(); int getDim() const;
// set the selection flag on all entities // set the selection flag on all entities
void setSelection(int val); void setSelection(int val);
...@@ -554,7 +555,7 @@ class GModel ...@@ -554,7 +555,7 @@ class GModel
int writeMSH(const std::string &name, double version=2.2, bool binary=false, int writeMSH(const std::string &name, double version=2.2, bool binary=false,
bool saveAll=false, bool saveParametric=false, bool saveAll=false, bool saveParametric=false,
double scalingFactor=1.0, int elementStartNum=0, double scalingFactor=1.0, int elementStartNum=0,
int saveSinglePartition=0); int saveSinglePartition=0, bool multipleView=false);
int writePartitionedMSH(const std::string &baseName, bool binary=false, int writePartitionedMSH(const std::string &baseName, bool binary=false,
bool saveAll=false, bool saveParametric=false, bool saveAll=false, bool saveParametric=false,
double scalingFactor=1.0); double scalingFactor=1.0);
......
...@@ -373,13 +373,17 @@ static void writeElementsMSH(FILE *fp, GModel *model, GEntity *ge, std::vector<T ...@@ -373,13 +373,17 @@ static void writeElementsMSH(FILE *fp, GModel *model, GEntity *ge, std::vector<T
int GModel::writeMSH(const std::string &name, double version, bool binary, int GModel::writeMSH(const std::string &name, double version, bool binary,
bool saveAll, bool saveParametric, bool saveAll, bool saveParametric,
double scalingFactor, int elementStartNum, double scalingFactor, int elementStartNum,
int saveSinglePartition) int saveSinglePartition,bool multipleView )
{ {
if(version < 3) if(version < 3)
return _writeMSH2(name, version, binary, saveAll, saveParametric, return _writeMSH2(name, version, binary, saveAll, saveParametric,
scalingFactor, elementStartNum, saveSinglePartition); scalingFactor, elementStartNum, saveSinglePartition,multipleView);
FILE *fp = fopen(name.c_str(), binary ? "wb" : "w"); FILE *fp;
if(multipleView)
fp = fopen(name.c_str(), binary ? "ab" : "a");
else
fp = fopen(name.c_str(), binary ? "wb" : "w");
if(!fp){ if(!fp){
Msg::Error("Unable to open file '%s'", name.c_str()); Msg::Error("Unable to open file '%s'", name.c_str());
return 0; return 0;
......
...@@ -816,9 +816,13 @@ static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition) ...@@ -816,9 +816,13 @@ static int getNumElementsMSH(GModel *m, bool saveAll, int saveSinglePartition)
int GModel::_writeMSH2(const std::string &name, double version, bool binary, int GModel::_writeMSH2(const std::string &name, double version, bool binary,
bool saveAll, bool saveParametric, double scalingFactor, bool saveAll, bool saveParametric, double scalingFactor,
int elementStartNum, int saveSinglePartition) int elementStartNum, int saveSinglePartition,bool multipleView)
{ {
FILE *fp = fopen(name.c_str(), binary ? "wb" : "w"); FILE *fp;
if(multipleView)
fp = fopen(name.c_str(), binary ? "ab" : "a");
else
fp = fopen(name.c_str(), binary ? "wb" : "w");
if(!fp){ if(!fp){
Msg::Error("Unable to open file '%s'", name.c_str()); Msg::Error("Unable to open file '%s'", name.c_str());
return 0; return 0;
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#include "GModel.h" #include "GModel.h"
#include "SBoundingBox3d.h" #include "SBoundingBox3d.h"
template<class real> template<class Real>
class stepData{ class stepData{
private: private:
// a pointer to the underlying model // a pointer to the underlying model
...@@ -34,7 +34,7 @@ class stepData{ ...@@ -34,7 +34,7 @@ class stepData{
// optimal. This is the price to pay if we want 1) rapid access to // optimal. This is the price to pay if we want 1) rapid access to
// the data and 2) not to store any additional info in MVertex or // the data and 2) not to store any additional info in MVertex or
// MElement) // MElement)
std::vector<real*> *_data; std::vector<Real*> *_data;
// a vector containing the multiplying factor allowing to compute // a vector containing the multiplying factor allowing to compute
// the number of values stored in _data for each index (number of // the number of values stored in _data for each index (number of
// values = getMult() * getNumComponents()). If _mult is empty, a // values = getMult() * getNumComponents()). If _mult is empty, a
...@@ -52,7 +52,7 @@ class stepData{ ...@@ -52,7 +52,7 @@ class stepData{
_min(min), _max(max), _numComp(numComp), _data(0) _min(min), _max(max), _numComp(numComp), _data(0)
{ {
} }
stepData(stepData<real> &other) : _data(0) stepData(stepData<Real> &other) : _data(0)
{ {
_model = other._model; _model = other._model;
_entities = other._entities; _entities = other._entities;
...@@ -65,12 +65,12 @@ class stepData{ ...@@ -65,12 +65,12 @@ class stepData{
_numComp = other._numComp; _numComp = other._numComp;
if(other._data){ if(other._data){
int n = other.getNumData(); int n = other.getNumData();
_data = new std::vector<real*>(n, (real*)0); _data = new std::vector<Real*>(n, (Real*)0);
for(int i = 0; i < n; i++){ for(int i = 0; i < n; i++){
real *d = other.getData(i); Real *d = other.getData(i);
if(d){ if(d){
int m = other.getMult(i) * _numComp; int m = other.getMult(i) * _numComp;
(*_data)[i] = new real[m]; (*_data)[i] = new Real[m];
for(int j = 0; j < m; j++) (*_data)[i][j] = d[j]; for(int j = 0; j < m; j++) (*_data)[i][j] = d[j];
} }
} }
...@@ -109,15 +109,15 @@ class stepData{ ...@@ -109,15 +109,15 @@ class stepData{
} }
void resizeData(int n) void resizeData(int n)
{ {
if(!_data) _data = new std::vector<real*>(n, (real*)0); if(!_data) _data = new std::vector<Real*>(n, (Real*)0);
if(n > (int)_data->size()) _data->resize(n, (real*)0); if(n > (int)_data->size()) _data->resize(n, (Real*)0);
} }
real *getData(int index, bool allocIfNeeded=false, int mult=1) Real *getData(int index, bool allocIfNeeded=false, int mult=1)
{ {
if(allocIfNeeded){ if(allocIfNeeded){
if(index >= getNumData()) resizeData(index + 100); // optimize this if(index >= getNumData()) resizeData(index + 100); // optimize this
if(!(*_data)[index]){ if(!(*_data)[index]){
(*_data)[index] = new real[_numComp * mult]; (*_data)[index] = new Real[_numComp * mult];
for(int i = 0; i < _numComp * mult; i++) (*_data)[index][i] = 0.; for(int i = 0; i < _numComp * mult; i++) (*_data)[index][i] = 0.;
} }
if(mult > 1){ if(mult > 1){
...@@ -234,12 +234,14 @@ class PViewDataGModel : public PViewData { ...@@ -234,12 +234,14 @@ class PViewDataGModel : public PViewData {
bool addData(GModel *model, std::map<int, std::vector<double> > &data, bool addData(GModel *model, std::map<int, std::vector<double> > &data,
int step, double time, int partition, int numComp); int step, double time, int partition, int numComp);
// Allow to destroy the data
void destroyData();
// I/O routines // I/O routines
bool readMSH(const std::string &viewName, const std::string &fileName, bool readMSH(const std::string &viewName, const std::string &fileName,
int fileIndex, FILE *fp, bool binary, bool swap, int step, int fileIndex, FILE *fp, bool binary, bool swap, int step,
double time, int partition, int numComp, int numNodes, double time, int partition, int numComp, int numNodes,
const std::string &interpolationScheme); const std::string &interpolationScheme);
bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true); bool writeMSH(const std::string &fileName, bool binary=false, bool savemesh=true,bool multipleView=false);
bool readMED(const std::string &fileName, int fileIndex); bool readMED(const std::string &fileName, int fileIndex);
bool writeMED(const std::string &fileName); bool writeMED(const std::string &fileName);
}; };
......
...@@ -46,6 +46,14 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> > ...@@ -46,6 +46,14 @@ bool PViewDataGModel::addData(GModel *model, std::map<int, std::vector<double> >
return true; return true;
} }
void PViewDataGModel::destroyData()
{
for(unsigned int i=0;i<_steps.size();i++)
{
_steps[i]->destroyData();
}
}
bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fileName, bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fileName,
int fileIndex, FILE *fp, bool binary, bool swap, int fileIndex, FILE *fp, bool binary, bool swap,
int step, double time, int partition, int numComp, int step, double time, int partition, int numComp,
...@@ -125,7 +133,7 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi ...@@ -125,7 +133,7 @@ bool PViewDataGModel::readMSH(const std::string &viewName, const std::string &fi
return true; return true;
} }
bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool savemesh) bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool savemesh,bool multipleView)
{ {
if(_steps.empty()) return true; if(_steps.empty()) return true;
...@@ -139,7 +147,7 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool sa ...@@ -139,7 +147,7 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool sa
bool writeNodesAndElements = savemesh; bool writeNodesAndElements = savemesh;
FILE *fp; FILE *fp;
if(writeNodesAndElements){ if(writeNodesAndElements){
if(!model->writeMSH(fileName, 2.0, binary)) return false; if(!model->writeMSH(fileName, 2.0, binary,false,false,1.0,0,0,multipleView)) return false;
// append data // append data
fp = fopen(fileName.c_str(), binary ? "ab" : "a"); fp = fopen(fileName.c_str(), binary ? "ab" : "a");
if(!fp){ if(!fp){
...@@ -148,6 +156,9 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool sa ...@@ -148,6 +156,9 @@ bool PViewDataGModel::writeMSH(const std::string &fileName, bool binary, bool sa
} }
} }
else{ else{
if(multipleView)
fp = fopen(fileName.c_str(), binary ? "ab" : "a");
else
fp = fopen(fileName.c_str(), binary ? "wb" : "w"); fp = fopen(fileName.c_str(), binary ? "wb" : "w");
if(!fp){ if(!fp){
Msg::Error("Unable to open file '%s'", fileName.c_str()); Msg::Error("Unable to open file '%s'", fileName.c_str());
......
...@@ -1143,15 +1143,15 @@ Xnodeptr *u1, *u2, *u3, *u4, *u5; ...@@ -1143,15 +1143,15 @@ Xnodeptr *u1, *u2, *u3, *u4, *u5;
#endif #endif
{ {
printf ("U1: "); printf ("U1: ");
nodeptr_print (u1); nodeptr_print (G,u1);
printf ("U2: "); printf ("U2: ");
nodeptr_print (u2); nodeptr_print (G,u2);
printf ("U3: "); printf ("U3: ");
nodeptr_print (u3); nodeptr_print (G,u3);
printf ("U4: "); printf ("U4: ");
nodeptr_print (u4); nodeptr_print (G,u4);
printf ("U5: "); printf ("U5: ");
nodeptr_print (u5); nodeptr_print (G,u5);
} }
#endif /* DEBUG */ #endif /* DEBUG */
......
...@@ -55,10 +55,10 @@ static int ...@@ -55,10 +55,10 @@ static int
#ifdef DEBUG #ifdef DEBUG
#ifdef CC_PROTOTYPE_ANSI #ifdef CC_PROTOTYPE_ANSI
static void static void
dumpcutcadj (Xgraph *G), dumpcutcadj (Xgraph *G);
#else #else
static void static void
dumpcutcadj (), dumpcutcadj ();
#endif #endif
#endif #endif
......
...@@ -226,7 +226,6 @@ static int newton3(double p[4],double x[3]) { ...@@ -226,7 +226,6 @@ static int newton3(double p[4],double x[3]) {
fprintf(stderr," ## ERR 9104, newton3: fx= %E x= %E\n",fx,x[2]); fprintf(stderr," ## ERR 9104, newton3: fx= %E x= %E\n",fx,x[2]);
return(0); return(0);
} }
}
#endif #endif
return(n); return(n);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment