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();
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();
// 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");
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");
void Filter_Gen_i::createEnsightInputFiles()
{
- int id;
-
MESSAGE("Calculate boundary");
// generate MED boundary of geometry
SUPPORT *supB = _mesh->getBoundaryElements(MED_FACE);
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()
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());
}
_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();
// 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;
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()
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] ;
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);
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;
// 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>
// 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"));
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);
}
}