// if no reference field selection: throw exception
if( _inputMesh.isNull() || _inputField.isNull() ){
- MESSAGE("Select an input Field in MED file before filtering!!");
delete sel;
- throw SALOME_Exception("Salome Exception");
+ throw SALOME_Exception("Select an input Field in MED file before filtering!!");
}
// read of input mesh
buildFrame();
}
// if no reference field selection: throw exception
- else{
- MESSAGE("Select an input Field in MED file before filtering!!");
- throw SALOME_Exception("Salome Exception");
- }
+ else
+ throw SALOME_Exception("Select an input Field in MED file before filtering!!");
// Allocate histogram arrays
_x = new double[_size];
// true);
}
-void SelectParams::process()
+void SelectParams::process() throw(SALOME_Exception)
{
string command;
setCursor(QCursor(Qt::WaitCursor));
+ MESSAGE("Generate Criteria");
// generate MED integer field (0 or 1) for filtoo input
try{
generateCriteria();
return;
}
+ MESSAGE("Calculate boundary");
// generate MED boundary of geometry
SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE);
// call ensight driver MED to generate input ensight mesh ,
// input ensight boundary mesh and input criteria ensight field for filtoo
+ MESSAGE("Create ensight mesh");
int id;
ENSIGHT_MESH_DRIVER myMeshDriver("/tmp/input.geom",_mesh);
myMeshDriver.addSupport(supB);
id=_mesh->addDriver(myMeshDriver);
_mesh->write(id);
+ MESSAGE("Create ensight field");
ENSIGHT_FIELD_DRIVER<int> myFieldDriver("/tmp/input.data",_criteria);
id=_criteria->addDriver(myFieldDriver);
_criteria->write(id);
+ MESSAGE("call filtoo");
// send filtoo command
command = "cd /tmp;filtoo -f input -o output > /tmp/filter.log";
MESSAGE(command);
// command = "cd /tmp;rm -f input.*";
// MESSAGE(command);
// system(command.c_str());
-
+
// have to call ensight driver MED to generate output MED file from filtoo output
+ MED _newMed(ENSIGHT_DRIVER,"/tmp/output.case");
+ _newMed.read();
- // create fields on new mesh
- // if new nodes on new mesh: interpolation
- // if input fields on cell, transform it on nodes
+ // project input fileds on new mesh
+ projectFields();
// destroy filtoo output files
+// command = "cd /tmp;rm -f output.*";
+// MESSAGE(command);
+// system(command.c_str());
// create new MED file with new mesh and fields
+ id = _newMed.addDriver(MED_DRIVER,_myOFN->text());
+ _newMed.write(id);
// close the window
accept();
}
+void SelectParams::projectFields()
+{
+
+ // get new mesh name
+ deque<string> meshesNames = _newMed->getMeshNames();
+ int numberOfMeshes = meshesNames.size();
+ if( numberOfMeshes != 1)
+ throw SALOME_Exception("Unvalid number of meshes in filtoo output");
+
+ // new mesh generated by filtoo
+ _newMesh = _newMed->getMesh(meshesNames[0]);
+
+ // create support on nodes on all new mesh
+ SUPPORT *newSup = new SUPPORT(_newMesh,"Support",MED_NODE);
+
+ // read the id of nodes of output mesh, in input mesh
+ readMapping();
+
+ // read connectivity of new mesh to get neighbour node of created node
+ _connL = _newMesh->getConnectivityLength(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+ _conn = _newMesh->getConnectivity(MED_FULL_INTERLACE,MED_NODAL,MED_CELL,MED_ALL_ELEMENTS);
+ _connI = _newMesh->getConnectivityIndex(MED_NODAL,MED_CELL);
+
+ // read number of nodes on new mesh
+ int numberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS);
+ int numberOfComponents;
+
+ deque<string> fieldsNames = _med->getFieldNames();
+ int numberOfFields = fieldsNames.size();
+
+ // loop on fields
+ for (int i=0; i<numberOfFields; i++){
+
+ // is the input field the reference field?
+ bool isReferenceField= false;
+ if(_myDField)
+ if( strcmp(_myDField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+ isReferenceField = true;
+ else
+ if( strcmp(_myIField->getName().c_str(),fieldsNames[i].c_str()) == 0)
+ isReferenceField = true;
+
+ deque<DT_IT_> myIteration = _med->getFieldIteration (fieldsNames[i]);
+ string meshName = _med->getField(fieldsNames[i],myIteration[0].dt,myIteration[0].it)->getSupport()->getMesh()->getName();
+
+ // we process only fields on input mesh
+ if( strcmp(meshName.c_str(),_mesh->getName().c_str()) == 0){
+
+ // loop on time steps
+ int numberOfIteration = myIteration.size();
+ for(int j=0;j<numberOfIteration;j++){
+
+ // select input field
+ MEDMEM::FIELD_* field = _med->getField(fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+ FIELD<double> *myDField = NULL;
+ FIELD<double> *newDField = NULL;
+ FIELD<int> *myIField = NULL;
+ FIELD<int> *newIField = NULL;
+
+ if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
+ if(!isReferenceField)
+ // read input field on input file
+ myDField = new FIELD<double>(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+ else
+ myDField = _myDField;
+ // create new output field
+ newDField = new FIELD<double>(newSup,field->getNumberOfComponents());
+ newDField->setName(myDField->getName());
+ }
+ else{
+ if(!isReferenceField)
+ // read input field on input file
+ myIField = new FIELD<int>(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
+ else
+ myIField = _myIField;
+ // create new output field
+ newIField = new FIELD<int>(newSup,field->getNumberOfComponents());
+ newIField->setName(myIField->getName());
+ }
+
+ // loop on nodes on new field
+ for (int k=1; k<numberOfNodes+1; k++){
+ // read number of nodes on input field
+ int l = getNodeNumber(k);
+ double dval;
+ int ival;
+
+ for(int c=1;c<=numberOfComponents;c++){
+ // read value on input field
+ if(myDField)
+ dval = myDField->getValueIJ(l,c);
+ else
+ ival = myIField->getValueIJ(l,c);
+
+ // write value on new field
+ if(newDField)
+ newDField->setValueIJ(k,c,dval);
+ else
+ newIField->setValueIJ(k,c,ival);
+ }
+
+ }
+ if(newDField)
+ _newMed->addField(newDField);
+ else
+ _newMed->addField(newIField);
+
+ // Destroy input field if not referecne field
+ if(!isReferenceField)
+ if(myDField){
+ delete myDField->getSupport();
+ delete myDField;
+ }
+ else{
+ delete myIField->getSupport();
+ delete myIField;
+ }
+
+ }
+ }
+ }
+
+}
+
+void SelectParams::readMapping()
+{
+ ifstream mapFile("/tmp/output.renum");
+
+ // read number of vertices to map
+ mapFile >> _nbvmap;
+ _map = new int[_nbvmap];
+
+ for(int i=0;i<_nbvmap;i++)
+ mapFile >> _map[i];
+
+}
+
+int SelectParams::getNodeNumber(int num)
+{
+ int oldnum = _map[num];
+
+ // if new node get neighbour node
+ if(oldnum == 0)
+ oldnum = _map[getNeighbourVertex(num)];
+
+ return oldnum;
+}
+
+int SelectParams::getNeighbourVertex(int num) throw(SALOME_Exception)
+{
+ int nnum;
+ int numberOfElements = _newMesh->getNumberOfElements(MED_CELL,MED_ALL_ELEMENTS);
+
+ int index;
+ // get index of created node in connectivity array
+ for(index=0;index<_connL;index++){
+ if(_conn[index] == num){
+
+ // get index of element which contain created node
+ int i;
+ for(i=1;i<=numberOfElements;i++)
+ if(_connI[i] > index)
+ break;
+
+ // search neighbour node which are in old mesh
+ for(int j=_connI[i-1];j<_connI[i];j++){
+ nnum = _conn[j-1];
+ if( _map[nnum] != 0)
+ break;
+ }
+
+ // if neighbour node in old mesh: go out loop, else continue
+ if(_map[nnum]!=0)
+ break;
+ }
+ }
+
+ // if no neighbour node in old mesh: throw exception
+ if(_map[nnum]==0)
+ throw SALOME_Exception("None of the neighbour node are in old mesh!!");
+
+ return nnum;
+}
+
void SelectParams::generateCriteria() throw(SALOME_Exception)
{
double val, min, max;
// read number of nodes
int NumberOf = sup->getNumberOfElements(MED_ALL_ELEMENTS);
+ // if reference field is on elements get reference field on nodes
switch(typ){
case MED_CELL:
if(_myDField){
case MED_CELL:
// listElements contains elements which contains a node of element i
listElements.clear();
-
+
for(int j=indC[i-1];j<indC[i];j++){
// c element contains node i
int c=revC[j-1];
if( _myOneThresh->isChecked() ){
if( _myExt->isChecked() )
if( val >= _fthresh ) isGVal = true;
- else isGVal = false;
+ else isGVal = false;
else
if( val <= _fthresh ) isGVal = true;
- else isGVal = false;
+ else isGVal = false;
}
else{
min = _fthresh;
}
if( _myExt->isChecked() )
if( (val <= min) || (val >= max) ) isGVal = true;
- else isGVal = false;
+ else isGVal = false;
else
if( (val >= min) && (val <= max) ) isGVal = true;
- else isGVal = false;
+ else isGVal = false;
}
if( isGVal )
_criteria->setValueIJ(i,1,1);
virtual void displaySThresh();
virtual void enableWidgets();
virtual void generateCriteria() throw(SALOME_Exception);
+ virtual void projectFields();
+ virtual void readMapping();
+ virtual int getNodeNumber(int);
+ virtual int getNeighbourVertex(int) throw(SALOME_Exception) ;
protected slots:
virtual void gradSelected();
virtual void enterSThresh();
virtual void moveThresh(const QMouseEvent &e);
virtual void getOutFileName();
- virtual void process();
+ virtual void process() throw(SALOME_Exception);
virtual void ClickOnCancel();
virtual void ClickOnHelp();
-private:
-
private:
int _size;
long _myHistoCurve, _myHistoFThresh, _myHistoSThresh;
double _fthresh, _sthresh;
double *_x, *_y;
double _xft[100], _yft[100], _xst[100], _yst[100];
+ int _nbvmap;
+ int *_map;
+ int _connL;
+ const int *_conn;
+ const int *_connI;
QLineEdit *_myLESH, *_myFThresh, *_myExpr, *_myLEST, *_myLEFT, *_myOFN;
QButtonGroup *_myHSize, *_myFunc, *_myFScale, *_myNbThresh, *_myArea, *_myVThresh, *_myOutFile;
QString _inputFile, _inputMesh, _inputField;
int _inputTS;
SelectField *_sel;
- ::MEDMEM::MED *_med;
- MESH* _mesh;
+ ::MEDMEM::MED *_med, *_newMed;
+ MESH* _mesh, *_newMesh;
FIELD<double> * _myGradient;
FIELD<double> * _myDField;
FIELD<int> * _myIField;