]> SALOME platform Git repositories - modules/filter.git/commitdiff
Salome HOME
update for take accounbt of field on partial support
authorsecher <secher>
Thu, 5 Apr 2007 13:25:53 +0000 (13:25 +0000)
committersecher <secher>
Thu, 5 Apr 2007 13:25:53 +0000 (13:25 +0000)
idl/FILTER_Gen.idl
src/FILTER/Filter_Gen_i.cxx
src/FILTER/Filter_Gen_i.hxx
src/FILTER/field2nodes.cxx
src/FILTERGUI/SelectField.cxx

index 75001a15477f0436c8293bc64a19e70a32ec0b49..c676771f50b2890224c536fd5d5c1971b932c17a 100644 (file)
@@ -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);
index 25d03bbec5b2872fd8e82db2f791153072a3e810..9c8ffe27fac9c1c281441f6d03fd475580f0a271 100755 (executable)
@@ -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<double> *volume;
-  set <int> listElements;
-  set <int>::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; i<NumberOf+1; i++){
 
     // if reference field is on elements get reference field on nodes
     switch(typ){
     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];
-       listElements.insert(c);
-      }
-
-      // calculate field value on node i 
-      sigmaV = 0.;
-      val = 0.;
-      for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
-       int elem = *elemIt;
-       double vol = volume->getValueIJ(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<int> 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<string> 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<double> *myDField = NULL;
          FIELD<double> *newDField = NULL;
          FIELD<int> *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()
index 6870a56f408cea7f6039ac7497f846d18b3d4873..87b3694bcc56fce50badaec82707b4c0eea4af8f 100644 (file)
@@ -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);
index 06394789d156ee0452f4cb8066166fa8cb064880..b6c275812d9394694ca172bf12484dcc666e69e7 100644 (file)
@@ -43,8 +43,8 @@ int main (int argc, char ** argv) {
 
   string filenameIN ;
   string filenameOUT;
-  set <int> listElements;
-  set <int>::iterator elemIt ;
+  set <int> listElements, supset;
+  set <int>::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 << "( "<<NumberOfMeshes << " ) :" << endl ;
+    FIELD<double> **volume = new FIELD<double>*[NumberOfMeshes];
     deque<string> MeshName = myMed.getMeshNames() ;
     for (int i=0; i<NumberOfMeshes; i++) {
+      volume[i] = NULL;
       myMed.getMesh(MeshName[i])->read() ;
       cout << "-> Mesh "<<i+1<<", named "<<MeshName[i]<<" is read !" << endl;
       int id = myMed.getMesh(MeshName[i])->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<int> myList;
+           for(int k=0;k<nbe;k++){
+             myList.push_back(numb[k]);
+             supset.insert(numb[k]);
+           }
+           newSup = mesh->buildSupportOnNodeFromElementList(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<double> *volume = myField->getSupport()->getMesh()->getVolume(myField->getSupport());
+         for(int k=0;k<NumberOfMeshes;k++)
+           if(strcmp(mesh->getName().c_str(),MeshName[k].c_str())==0)
+             ivol = k;
+         if( volume[ivol] == NULL )
+           volume[ivol] = myField->getSupport()->getMesh()->getVolume(myField->getSupport());
          if (dynamic_cast<MEDMEM::FIELD<double>*>(myField)){
            FIELD<double> *myDField = (MEDMEM::FIELD<double>*)myField;
-           FIELD<double> *newDField = new FIELD<double>(sup,NumberOfComponents);
+           FIELD<double> *newDField = new FIELD<double>(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; k<NumberOfNodes+1; k++){
-             // listElements contains elements which contains a node of element i
-             listElements.clear();
-             for(int j=indC[k-1];j<indC[k];j++){
-               // c element contains node i
-               int c=revC[j-1];
-               listElements.insert(c);
+           if( newSup->isOnAllElements() ){
+             for (int k=1; k<NumberOfNodes+1; k++){
+               // listElements contains elements which contains a node of element i
+               listElements.clear();
+               for(int l=indC[k-1];l<indC[k];l++){
+                 // c element contains node k
+                 int c=revC[l-1];
+                 listElements.insert(c);
+               }
+               
+               // calculate field value on node k 
+               double sigmaV = 0.;
+               for(int l=0;l<NumberOfComponents;l++)
+                 val[l] = 0.;
+               for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                 int elem = *elemIt;
+                 double vol = volume[ivol]->getValueIJ(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;j<NumberOfComponents;j++)
-               val[j] = 0.;
-             for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
-               int elem = *elemIt;
-               double vol = volume->getValueIJ(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];l<indC[kk];l++){
+                 // c element contains node k
+                 int c=revC[l-1];
+                 // add c element only if it is in partial support
+                 ssIt = supset.find(c);
+                 if(ssIt!=supset.end())
+                   listElements.insert(c);
+               }
+               
+               // calculate field value on node k 
+               double sigmaV = 0.;
+               for(int l=0;l<NumberOfComponents;l++)
+                 val[l] = 0.;
+               for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                 int elem = *elemIt;
+                 double vol = volume[ivol]->getValueIJ(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 "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is written !" << endl;
          }
          else{
            FIELD<int> *myIField = (MEDMEM::FIELD<int>*)myField;
-           FIELD<int> *newIField = new FIELD<int>(sup,NumberOfComponents);
+           FIELD<int> *newIField = new FIELD<int>(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; k<NumberOfNodes+1; k++){
-             // listElements contains elements which contains a node of element i
-             listElements.clear();
-             for(int j=indC[k-1];j<indC[k];j++){
-               // c element contains node i
-               int c=revC[j-1];
-               listElements.insert(c);
-             }
+           if( newSup->isOnAllElements() ){
+             for (int k=1; k<NumberOfNodes+1; k++){
+               // listElements contains elements which contains a node of element i
+               listElements.clear();
+               for(int l=indC[k-1];l<indC[k];l++){
+                 // c element contains node i
+                 int c=revC[l-1];
+                 listElements.insert(c);
+               }
 
-             // calculate field value on node i 
-             double sigmaV = 0.;
-             for(int j=0;j<NumberOfComponents;j++)
-               val[j] = 0.;
-             for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
-               int elem = *elemIt;
-               double vol = volume->getValueIJ(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;l<NumberOfComponents;l++)
+                 val[l] = 0.;
+               for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                 int elem = *elemIt;
+                 double vol = volume[ivol]->getValueIJ(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];l<indC[kk];l++){
+                 // c element contains node k
+                 int c=revC[l-1];
+                 // add c element only if it is in partial support
+                 ssIt = supset.find(c);
+                 if(ssIt!=supset.end())
+                   listElements.insert(c);
+               }
+               
+               // calculate field value on node k 
+               double sigmaV = 0.;
+               for(int l=0;l<NumberOfComponents;l++)
+                 val[l] = 0.;
+               for(elemIt=listElements.begin();elemIt!=listElements.end();elemIt++){
+                 int elem = *elemIt;
+                 double vol = volume[ivol]->getValueIJ(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 "<<FieldIteration[j].dt<<" and  order number "<<FieldIteration[j].it<<" ) is written !" << endl;
          }
          break;
index 942d79d7bdf194534ce8b816ec2b88e60eb878ef..fb1d3183203fc7927b1908e083a96debf964c002 100644 (file)
@@ -18,6 +18,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 #include "SelectField.h"
+#include "MEDMEM_define.hxx"
 
 #include <qgroupbox.h>
 #include <qframe.h>
@@ -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);
       }
     }