From: secher Date: Mon, 12 Mar 2007 15:16:44 +0000 (+0000) Subject: new version with output MED file creation X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4faba7c4dc4ab6e6542abb7274947850264da878;p=modules%2Ffilter.git new version with output MED file creation --- diff --git a/src/FILTERGUI/SelectParams.cxx b/src/FILTERGUI/SelectParams.cxx index 08d1f42..9f27db0 100644 --- a/src/FILTERGUI/SelectParams.cxx +++ b/src/FILTERGUI/SelectParams.cxx @@ -59,9 +59,8 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel, // 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 @@ -86,10 +85,8 @@ SelectParams::SelectParams(FilterGUI* theModule,SelectField *sel, 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]; @@ -631,7 +628,7 @@ void SelectParams::getOutFileName() // true); } -void SelectParams::process() +void SelectParams::process() throw(SALOME_Exception) { string command; @@ -643,6 +640,7 @@ void SelectParams::process() setCursor(QCursor(Qt::WaitCursor)); + MESSAGE("Generate Criteria"); // generate MED integer field (0 or 1) for filtoo input try{ generateCriteria(); @@ -656,20 +654,24 @@ void SelectParams::process() 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 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); @@ -679,22 +681,212 @@ void SelectParams::process() // 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 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 fieldsNames = _med->getFieldNames(); + int numberOfFields = fieldsNames.size(); + + // loop on fields + for (int i=0; igetName().c_str(),fieldsNames[i].c_str()) == 0) + isReferenceField = true; + else + if( strcmp(_myIField->getName().c_str(),fieldsNames[i].c_str()) == 0) + isReferenceField = true; + + deque 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;jgetField(fieldsNames[i],myIteration[j].dt,myIteration[j].it); + FIELD *myDField = NULL; + FIELD *newDField = NULL; + FIELD *myIField = NULL; + FIELD *newIField = NULL; + + if (dynamic_cast*>(field)){ + if(!isReferenceField) + // read input field on input file + myDField = new FIELD(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it); + else + myDField = _myDField; + // create new output field + newDField = new FIELD(newSup,field->getNumberOfComponents()); + newDField->setName(myDField->getName()); + } + else{ + if(!isReferenceField) + // read input field on input file + myIField = new FIELD(MEDMEM::MED_DRIVER,_inputFile,fieldsNames[i],myIteration[j].dt,myIteration[j].it); + else + myIField = _myIField; + // create new output field + newIField = new FIELD(newSup,field->getNumberOfComponents()); + newIField->setName(myIField->getName()); + } + + // loop on nodes on new field + for (int k=1; kgetValueIJ(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; @@ -723,6 +915,7 @@ void SelectParams::generateCriteria() throw(SALOME_Exception) // 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){ @@ -751,7 +944,7 @@ void SelectParams::generateCriteria() throw(SALOME_Exception) case MED_CELL: // listElements contains elements which contains a node of element i listElements.clear(); - + for(int j=indC[i-1];jisChecked() ){ 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; @@ -810,10 +1003,10 @@ void SelectParams::generateCriteria() throw(SALOME_Exception) } 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); diff --git a/src/FILTERGUI/SelectParams.h b/src/FILTERGUI/SelectParams.h index d561ee6..51a3d62 100644 --- a/src/FILTERGUI/SelectParams.h +++ b/src/FILTERGUI/SelectParams.h @@ -65,6 +65,10 @@ protected: 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(); @@ -77,12 +81,10 @@ protected slots: 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; @@ -90,6 +92,11 @@ private: 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; @@ -104,8 +111,8 @@ private: QString _inputFile, _inputMesh, _inputField; int _inputTS; SelectField *_sel; - ::MEDMEM::MED *_med; - MESH* _mesh; + ::MEDMEM::MED *_med, *_newMed; + MESH* _mesh, *_newMesh; FIELD * _myGradient; FIELD * _myDField; FIELD * _myIField;