From: secher Date: Thu, 5 Apr 2007 13:25:53 +0000 (+0000) Subject: update for take accounbt of field on partial support X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=39ee2fb4dfac50f63d0695b9a7a4706c07350ad8;p=modules%2Ffilter.git update for take accounbt of field on partial support --- diff --git a/idl/FILTER_Gen.idl b/idl/FILTER_Gen.idl index 75001a1..c676771 100644 --- a/idl/FILTER_Gen.idl +++ b/idl/FILTER_Gen.idl @@ -53,6 +53,8 @@ module SALOME_FILTER StrSeq getMeshNames(); StrSeq getFieldNames(); long getMeshDimension(in string meshName); + long getFieldEntity(in string fieldName,in long dt,in long it); + boolean fieldIsOnAllElements(in string fieldName,in long dt,in long it); DTITSeq getFieldIteration(in string fieldName); string getMeshName(in string fieldName,in long dt,in long it); void readReferenceField(in string meshName,in string fieldName,in long ts); diff --git a/src/FILTER/Filter_Gen_i.cxx b/src/FILTER/Filter_Gen_i.cxx index 25d03bb..9c8ffe2 100755 --- a/src/FILTER/Filter_Gen_i.cxx +++ b/src/FILTER/Filter_Gen_i.cxx @@ -183,6 +183,16 @@ CORBA::Long Filter_Gen_i::getMeshDimension(const char* meshName) return _med->getMesh(meshName)->getMeshDimension(); } +CORBA::Long Filter_Gen_i::getFieldEntity(const char* fieldName,CORBA::Long dt,CORBA::Long it) +{ + return _med->getField(fieldName,dt,it)->getSupport()->getEntity(); +} + +CORBA::Boolean Filter_Gen_i::fieldIsOnAllElements(const char* fieldName,CORBA::Long dt,CORBA::Long it) +{ + return _med->getField(fieldName,dt,it)->getSupport()->isOnAllElements(); +} + DTITSeq* Filter_Gen_i::getFieldIteration(const char* fieldName) { DTITSeq *seq = new DTITSeq(); @@ -290,14 +300,8 @@ LongSeq* Filter_Gen_i::getHistogram(CORBA::Long size,ref_func rf) void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double sthresh,CORBA::Boolean areaFlag,ref_func rf) throw(SALOME_FILTER::FILTER_Gen::FilterError) { double val, min, max; - double sigmaV; bool isGVal; MED_EN::medEntityMesh typ; - const int *revC; - const int *indC; - FIELD *volume; - set listElements; - set ::iterator elemIt ; if(_myDField) typ = _myDField->getSupport()->getEntity(); @@ -315,57 +319,12 @@ void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,C // 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){ - // calculate reverse connectivity to have the list of elements which contains node i - revC = _myDField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ); - indC = _myDField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ); - // calculate volume field on mesh - volume = _myDField->getSupport()->getMesh()->getVolume(_myDField->getSupport()); - } - else{ - // calculate reverse connectivity to have the list of elements which contains node i - revC = _myIField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,typ); - indC = _myIField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,typ); - // calculate volume field on mesh - volume = _myIField->getSupport()->getMesh()->getVolume(_myIField->getSupport()); - } - break; - default: - break; - } - for (int i=1; igetValueIJ(elem,1); - if( vol != 0. ){ - sigmaV += 1./vol; - if(_myDField) - val += _myDField->getValueIJ(elem,1)/vol; - else - val += ((double)_myIField->getValueIJ(elem,1))/vol; - } - } - val /= sigmaV; + throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on cells"); break; case MED_FACE: throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on faces"); @@ -375,10 +334,17 @@ void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,C break; case MED_NODE: // read reference field value - if(_myDField) - val = _myDField->getValueIJ(i,1); - else - val = (double)_myIField->getValueIJ(i,1); + switch(rf){ + case F_FIELD: + if(_myDField) + val = _myDField->getValueIJ(i,1); + else + val = (double)_myIField->getValueIJ(i,1); + break; + case F_GRAD: + val = _myGradient->getValueIJ(i,1); + break; + } break; case MED_ALL_ENTITIES: throw SALOME_FILTER::FILTER_Gen::FilterError("Filter doesn't run on reference field on all entities"); @@ -417,8 +383,6 @@ void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,C void Filter_Gen_i::createEnsightInputFiles() { - int id; - MESSAGE("Calculate boundary"); // generate MED boundary of geometry SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE); @@ -428,15 +392,15 @@ void Filter_Gen_i::createEnsightInputFiles() MESSAGE("Create ensight mesh"); ENSIGHT_MESH_WRONLY_DRIVER myMeshDriver("/tmp/input.case",_mesh); myMeshDriver.addSupport(supB); -// myMeshDriver.open(); + myMeshDriver.open(); myMeshDriver.write(); -// myMeshDriver.close(); + myMeshDriver.close(); MESSAGE("Create ensight field"); ENSIGHT_FIELD_WRONLY_DRIVER myFieldDriver("/tmp/input.case",_criteria); -// myFieldDriver.open(); + myFieldDriver.open(); myFieldDriver.write(); -// myFieldDriver.close(); + myFieldDriver.close(); } void Filter_Gen_i::filtering() @@ -450,9 +414,9 @@ void Filter_Gen_i::filtering() system(command.c_str()); // destroy filtoo input files -// command = "cd /tmp;rm -f input.*"; -// MESSAGE(command); -// system(command.c_str()); + command = "cd /tmp;rm -f input.*"; + MESSAGE(command); + system(command.c_str()); } @@ -470,11 +434,6 @@ void Filter_Gen_i::projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen _newMed = new ::MED(); _newMed->addMesh(myMesh); - // destroy filtoo output files -// command = "cd /tmp;rm -f output.*"; -// MESSAGE(command); -// system(command.c_str()); - // get new mesh name deque meshesNames = _newMed->getMeshNames(); int numberOfMeshes = meshesNames.size(); @@ -529,6 +488,11 @@ void Filter_Gen_i::projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen // select input field MEDMEM::FIELD_* field = _med->getField(fieldsNames[i],myIteration[j].dt,myIteration[j].it); + + // if field not on nodes, take following field + if( field->getSupport()->getEntity() != MED_NODE ) + break; + FIELD *myDField = NULL; FIELD *newDField = NULL; FIELD *myIField = NULL; @@ -604,6 +568,12 @@ void Filter_Gen_i::projectFieldsOnDecimateMesh() throw(SALOME_FILTER::FILTER_Gen catch(SALOME_Exception){ throw SALOME_FILTER::FILTER_Gen::FilterError("Unvalid decimate mlesh created by filtoo"); } + + // destroy filtoo output files + command = "cd /tmp;rm -f output.*"; + MESSAGE(command); + system(command.c_str()); + } void Filter_Gen_i::readMapping() diff --git a/src/FILTER/Filter_Gen_i.hxx b/src/FILTER/Filter_Gen_i.hxx index 6870a56..87b3694 100644 --- a/src/FILTER/Filter_Gen_i.hxx +++ b/src/FILTER/Filter_Gen_i.hxx @@ -58,6 +58,8 @@ public: SALOME_FILTER::StrSeq* getMeshNames(); SALOME_FILTER::StrSeq* getFieldNames(); CORBA::Long getMeshDimension(const char* meshName); + CORBA::Long getFieldEntity(const char* fieldName,CORBA::Long dt,CORBA::Long it); + CORBA::Boolean fieldIsOnAllElements(const char* fieldName,CORBA::Long dt,CORBA::Long it); SALOME_FILTER::DTITSeq* getFieldIteration(const char* fieldName); char* getMeshName(const char* fieldName,CORBA::Long dt,CORBA::Long it); void readReferenceField(const char* meshName, const char* fieldName, CORBA::Long ts); diff --git a/src/FILTER/field2nodes.cxx b/src/FILTER/field2nodes.cxx index 0639478..b6c2758 100644 --- a/src/FILTER/field2nodes.cxx +++ b/src/FILTER/field2nodes.cxx @@ -43,8 +43,8 @@ int main (int argc, char ** argv) { string filenameIN ; string filenameOUT; - set listElements; - set ::iterator elemIt ; + set listElements, supset; + set ::iterator elemIt, ssIt; if ( argc == 3 ) { filenameIN = argv[1] ; @@ -56,8 +56,10 @@ int main (int argc, char ** argv) { cout << "-> Read all meshes " ; int NumberOfMeshes = myMed.getNumberOfMeshes() ; cout << "( "< **volume = new FIELD*[NumberOfMeshes]; deque MeshName = myMed.getMeshNames() ; for (int i=0; iread() ; cout << "-> Mesh "<addDriver(MED_DRIVER,filenameOUT,MeshName[i],MED_EN::MED_ECRI); @@ -86,83 +88,181 @@ int main (int argc, char ** argv) { switch(myField->getSupport()->getEntity()){ case MED_CELL: cout << "*************************** CHAMP AUX CELLULES" << endl; - MESH *mesh = myMed.getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it)->getSupport()->getMesh(); - SUPPORT *sup = new SUPPORT(mesh,"Support",MED_NODE); + MESH *mesh = myField->getSupport()->getMesh(); + + // create new support for new field + SUPPORT *newSup; + if( myField->getSupport()->isOnAllElements() ) + newSup = new SUPPORT(mesh,"Support",MED_NODE); + else{ + int nbe = myField->getSupport()->getNumberOfElements(MED_ALL_ELEMENTS); + const int *numb = myField->getSupport()->getNumber(MED_ALL_ELEMENTS); + list myList; + for(int k=0;kbuildSupportOnNodeFromElementList(myList,MED_CELL); + } + // read number of nodes - int NumberOfNodes = sup->getNumberOfElements(MED_ALL_ELEMENTS); + int NumberOfNodes = newSup->getNumberOfElements(MED_ALL_ELEMENTS); // calculate reverse connectivity to have the list of elements which contains node i const int *revC = myField->getSupport()->getMesh()->getReverseConnectivity(MED_NODAL,MED_CELL); const int *indC = myField->getSupport()->getMesh()->getReverseConnectivityIndex(MED_NODAL,MED_CELL); + int ivol; // calculate volume field on mesh - FIELD *volume = myField->getSupport()->getMesh()->getVolume(myField->getSupport()); + for(int k=0;kgetName().c_str(),MeshName[k].c_str())==0) + ivol = k; + if( volume[ivol] == NULL ) + volume[ivol] = myField->getSupport()->getMesh()->getVolume(myField->getSupport()); if (dynamic_cast*>(myField)){ FIELD *myDField = (MEDMEM::FIELD*)myField; - FIELD *newDField = new FIELD(sup,NumberOfComponents); + FIELD *newDField = new FIELD(newSup,NumberOfComponents); newDField->setName(myField->getName()); + newDField->setIterationNumber(FieldIteration[j].dt); + newDField->setOrderNumber(FieldIteration[j].it); + newDField->setTime(myDField->getTime()); double *val = new double[NumberOfComponents]; - for (int k=1; kisOnAllElements() ){ + for (int k=1; kgetValueIJ(elem,1); + if( vol != 0. ){ + sigmaV += 1./vol; + for(int l=1;l<=NumberOfComponents;l++) + val[l-1] += myDField->getValueIJ(elem,l)/vol; + } + } + for(int l=1;l<=NumberOfComponents;l++) + newDField->setValueIJ(k,l,val[l-1]/sigmaV); } - - // calculate field value on node i - double sigmaV = 0.; - for(int j=0;jgetValueIJ(elem,1); - if( vol != 0. ){ - sigmaV += 1./vol; - for(int j=1;j<=NumberOfComponents;j++) - val[j] += myDField->getValueIJ(elem,j)/vol; + } + else{ + const int *numb = newSup->getNumber(MED_ALL_ELEMENTS); + for (int k=1; k<=NumberOfNodes; k++){ + int kk = numb[k-1]; + // listElements contains elements which contains a node of element i + listElements.clear(); + for(int l=indC[kk-1];lgetValueIJ(elem,1); + if( vol != 0. ){ + sigmaV += 1./vol; + for(int l=1;l<=NumberOfComponents;l++) + val[l-1] += myDField->getValueIJ(elem,l)/vol; + } } + for(int l=1;l<=NumberOfComponents;l++) + newDField->setValueIJ(k,l,val[l-1]/sigmaV); } - for(int j=1;j<=NumberOfComponents;j++) - newDField->setValueIJ(k,j,val[j]/sigmaV); } delete [] val; int id = newDField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI); newDField->write(id); + delete newSup; + delete newDField; cout << " * Iteration "< *myIField = (MEDMEM::FIELD*)myField; - FIELD *newIField = new FIELD(sup,NumberOfComponents); + FIELD *newIField = new FIELD(newSup,NumberOfComponents); newIField->setName(myField->getName()); + newIField->setIterationNumber(FieldIteration[j].dt); + newIField->setOrderNumber(FieldIteration[j].it); + newIField->setTime(myIField->getTime()); double *val = new double[NumberOfComponents]; - for (int k=1; kisOnAllElements() ){ + for (int k=1; kgetValueIJ(elem,1); - if( vol != 0. ){ - sigmaV += 1./vol; - for(int j=1;j<=NumberOfComponents;j++) - val[j] += ((double)myIField->getValueIJ(elem,j))/vol; + // calculate field value on node k + double sigmaV = 0.; + for(int l=0;lgetValueIJ(elem,1); + if( vol != 0. ){ + sigmaV += 1./vol; + for(int l=1;l<=NumberOfComponents;l++) + val[l-1] += ((double)myIField->getValueIJ(elem,l))/vol; + } + } + for(int l=1;l<=NumberOfComponents;l++) + newIField->setValueIJ(k,l,(int)(val[l-1]/sigmaV)); + } + } + else{ + const int *numb = newSup->getNumber(MED_ALL_ELEMENTS); + for (int k=1; k<=NumberOfNodes; k++){ + int kk = numb[k-1]; + // listElements contains elements which contains a node of element i + listElements.clear(); + for(int l=indC[kk-1];lgetValueIJ(elem,1); + if( vol != 0. ){ + sigmaV += 1./vol; + for(int l=1;l<=NumberOfComponents;l++) + val[l-1] += myIField->getValueIJ(elem,l)/vol; + } } + for(int l=1;l<=NumberOfComponents;l++) + newIField->setValueIJ(k,l,(int)(val[l-1]/sigmaV)); } - for(int j=1;j<=NumberOfComponents;j++) - newIField->setValueIJ(k,j,(int)(val[j]/sigmaV)); } delete [] val; int id = newIField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI); newIField->write(id); + delete newSup; + delete newIField; cout << " * Iteration "< #include @@ -76,8 +77,8 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file, // 1) tree to visualize meshes and fields _myList = new QListView( _GroupC1, "List of fields" ); - _myList->setMinimumSize( 400, 400 ); - _myList->setMaximumSize( 400, 400 ); + _myList->setMinimumSize( 500, 500 ); + _myList->setMaximumSize( 500, 500 ); _myList->setRootIsDecorated(true); _myList->addColumn(tr("FILTER_NAME")); _myList->addColumn(tr("FILTER_TYPE")); @@ -95,8 +96,26 @@ SelectField::SelectField(FilterGUI* theModule,const QString& file, SALOME_FILTER::DTITSeq *myIteration = _filter->getFieldIteration((*fieldsNames)[j]); string meshName = _filter->getMeshName((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it); if( strcmp(meshName.c_str(),(*meshesNames)[i]) == 0){ - QListViewItem *elem = new QListViewItem( element, QString((*fieldsNames)[j]), tr("FILTER_FIELD") ); - if(_dimMesh != 3) + int ent = _filter->getFieldEntity((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it); + bool isOnAllElements = _filter->fieldIsOnAllElements((*fieldsNames)[j],(*myIteration)[0].dt,(*myIteration)[0].it); + + char stre[10]; + switch(ent){ + case MED_EN::MED_CELL: + strcpy(stre,"on cells"); + break; + case MED_EN::MED_FACE: + strcpy(stre,"on faces"); + break; + case MED_EN::MED_EDGE: + strcpy(stre,"on edges"); + break; + case MED_EN::MED_NODE: + strcpy(stre,"on nodes"); + break; + } + QListViewItem *elem = new QListViewItem( element, QString((*fieldsNames)[j]), tr("FILTER_FIELD"),stre ); + if( (_dimMesh != 3) || (ent != MED_EN::MED_NODE) || !isOnAllElements ) elem->setSelectable(false); } }