return seq;
}
-void Filter_Gen_i::generateCriteria(CORBA::Long nbthresh,CORBA::Double fthresh,CORBA::Double sthresh,CORBA::Boolean areaFlag) throw(SALOME_FILTER::FILTER_Gen::FilterError)
+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;
{
string command;
+ // read of new mesh in ensight file
+ MESH* myMesh = new MESH();
+ ENSIGHT_MESH_RDONLY_DRIVER myEnsightMeshDriver("/tmp/output.case", myMesh) ;
+ myMesh->addDriver(ENSIGHT_DRIVER,"/tmp/output.case","myMesh",MED_EN::MED_LECT);
+ myMesh->read() ;
+
// have to call ensight driver MED to generate output MED file from filtoo output
- _newMed = new ::MED(ENSIGHT_DRIVER,"/tmp/output.case");
- _newMed->read();
+ _newMed = new ::MED();
+ _newMed->addMesh(myMesh);
// destroy filtoo output files
// command = "cd /tmp;rm -f output.*";
FIELD<int> *newIField = NULL;
if (dynamic_cast<MEDMEM::FIELD<double>*>(field)){
- if(!isReferenceField)
+ if(!isReferenceField){
// read input field on input file
myDField = new FIELD<double>(MEDMEM::MED_DRIVER,_file,fieldsNames[i],myIteration[j].dt,myIteration[j].it);
- else
+ }
+ else{
myDField = _myDField;
+ }
// create new output field
newDField = new FIELD<double>(newSup,field->getNumberOfComponents());
newDField->setName(myDField->getName());
newIField = new FIELD<int>(newSup,field->getNumberOfComponents());
newIField->setName(myIField->getName());
}
+ numberOfComponents = field->getNumberOfComponents();
// loop on nodes on new field
- for (int k=1; k<numberOfNodes+1; k++){
+ for (int k=1; k<=numberOfNodes; k++){
// read number of nodes on input field
int l = getNodeNumber(k);
double dval;
ival = myIField->getValueIJ(l,c);
// write value on new field
- if(newDField)
+ if(newDField){
newDField->setValueIJ(k,c,dval);
+ }
else
newIField->setValueIJ(k,c,ival);
}
else
_newMed->addField(newIField);
- // Destroy input field if not referecne field
+ // Destroy input field if not reference field
if(!isReferenceField)
if(myDField){
delete myDField->getSupport();
int Filter_Gen_i::getNodeNumber(int num)
{
- int oldnum = _map[num];
+ int oldnum = _map[num-1];
// if new node get neighbour node
if(oldnum == 0)
- oldnum = _map[getNeighbourVertex(num)];
+ oldnum = _map[getNeighbourVertex(num)-1];
return oldnum;
}
// 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)
+ if( _map[nnum-1] != 0)
break;
}
// if neighbour node in old mesh: go out loop, else continue
- if(_map[nnum]!=0)
+ if(_map[nnum-1]!=0)
break;
}
}
// if no neighbour node in old mesh: throw exception
- if(_map[nnum]==0)
+ if(_map[nnum-1]==0)
throw SALOME_Exception("None of the neighbour node are in old mesh!!");
return nnum;
--- /dev/null
+// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+#include<string>
+#include<deque>
+
+#include "MEDMEM_Exception.hxx"
+#include "MEDMEM_define.hxx"
+
+#include "MEDMEM_Med.hxx"
+#include "MEDMEM_Mesh.hxx"
+#include "MEDMEM_Family.hxx"
+#include "MEDMEM_Support.hxx"
+#include "MEDMEM_Field.hxx"
+
+using namespace std;
+using namespace MEDMEM;
+
+void usage(char * name)
+{
+ cout << " ERROR ABOUT SYNTAX " << endl ;
+ cout << " " << name << " <input med file> <output med file> " << endl ;
+ exit(-1);
+}
+
+int main (int argc, char ** argv) {
+
+ string filenameIN ;
+ string filenameOUT;
+ set <int> listElements;
+ set <int>::iterator elemIt ;
+
+ if ( argc == 3 ) {
+ filenameIN = argv[1] ;
+ filenameOUT = argv[2] ;
+ cout << "-> reading all into the Med file " << filenameIN << " and writing all into the Ensight file " << filenameOUT << endl ;
+
+ MED myMed(MED_DRIVER,filenameIN) ;
+
+ cout << "-> Read all meshes " ;
+ int NumberOfMeshes = myMed.getNumberOfMeshes() ;
+ cout << "( "<<NumberOfMeshes << " ) :" << endl ;
+ deque<string> MeshName = myMed.getMeshNames() ;
+ for (int i=0; i<NumberOfMeshes; i++) {
+ 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);
+ myMed.getMesh(MeshName[i])->write(id);
+ cout << "-> Mesh "<<i+1<<", named "<<MeshName[i]<<" is written !" << endl;
+ }
+
+ myMed.updateSupport() ;
+
+ cout << "-> Read all fields " ;
+ int NumberOfFields = myMed.getNumberOfFields() ;
+ cout << "( "<<NumberOfFields << " ) :" << endl;
+ deque<string> FieldName = myMed.getFieldNames() ;
+ for (int i=0; i<NumberOfFields; i++) {
+ deque<DT_IT_> FieldIteration = myMed.getFieldIteration(FieldName[i]) ;
+ cout << "-> Field "<<i+1<<", named "<<FieldName[i] << " :" << endl ;
+ int NumberOfIteration = FieldIteration.size() ;
+ cout << " Number of iteration pair : "<< NumberOfIteration << endl;
+ for (int j=0; j<NumberOfIteration; j++) {
+ FIELD_ * myField = myMed.getField(FieldName[i],FieldIteration[j].dt,FieldIteration[j].it) ;
+
+ myField->read() ;
+ cout << " * Iteration "<<FieldIteration[j].dt<<" and order number "<<FieldIteration[j].it<<" ) is read !" << endl;
+
+ int NumberOfComponents = myField->getNumberOfComponents();
+ 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);
+ // read number of nodes
+ int NumberOfNodes = sup->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);
+ // calculate volume field on mesh
+ FIELD<double> *volume = 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);
+ newDField->setName(myField->getName());
+ 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);
+ }
+
+ // 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;
+ }
+ }
+ 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);
+ 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);
+ newIField->setName(myField->getName());
+ 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);
+ }
+
+ // 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;
+ }
+ }
+ 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);
+ cout << " * Iteration "<<FieldIteration[j].dt<<" and order number "<<FieldIteration[j].it<<" ) is written !" << endl;
+ }
+ break;
+ case MED_FACE:
+ cout << "*************************** CHAMP AUX FACES" << endl;
+ break;
+ case MED_EDGE:
+ cout << "*************************** CHAMP AUX ARETES" << endl;
+ break;
+ case MED_NODE:
+ cout << "*************************** CHAMP AUX NOEUDS" << endl;
+ int id = myField->addDriver(MED_DRIVER,filenameOUT,FieldName[i],MED_EN::MED_ECRI);
+ myField->write(id);
+ cout << " * Iteration "<<FieldIteration[j].dt<<" and order number "<<FieldIteration[j].it<<" ) is written !" << endl;
+ break;
+ }
+
+ }
+ }
+
+ }
+ else usage(argv[0]);
+}