1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 /* Programme de test du constructeur de copies de la classe FIELD_ de MEDMEM
25 #include "MEDMEM_Exception.hxx"
26 #include "MEDMEM_Mesh.hxx"
27 #include "MEDMEM_Family.hxx"
28 #include "MEDMEM_Group.hxx"
30 #include "MEDMEM_MedMeshDriver.hxx"
31 #include "MEDMEM_MedFieldDriver.hxx"
32 #include "MEDMEM_Support.hxx"
33 #include "MEDMEM_Field.hxx"
34 #include "MEDMEM_FieldConvert.hxx"
35 #include "MEDMEM_define.hxx"
43 using namespace MEDMEM;
44 using namespace MED_EN;
47 static void affiche_field_(FIELD_ * myField, const SUPPORT * mySupport)
49 cout << "Field "<< myField->getName() << " : " <<myField->getDescription() << endl ;
50 int NumberOfComponents = myField->getNumberOfComponents() ;
51 cout << "- Nombre de composantes : "<< NumberOfComponents << endl ;
52 for (int i=1; i<NumberOfComponents+1; i++) {
53 cout << " - composante "<<i<<" :"<<endl ;
54 cout << " - nom : "<<myField->getComponentName(i)<< endl;
55 cout << " - description : "<<myField->getComponentDescription(i) << endl;
56 cout << " - units : "<<myField->getMEDComponentUnit(i) << endl;
58 cout << "- iteration :" << endl ;
59 cout << " - numero : " << myField->getIterationNumber()<< endl ;
60 cout << " - ordre : " << myField->getOrderNumber()<< endl ;
61 cout << " - temps : " << myField->getTime()<< endl ;
63 cout << "- Type : " << myField->getValueType()<< endl;
65 cout << "- Adresse support : " << mySupport << endl;
68 template <class INTERLACING_TAG>
69 void affiche_fieldT(FIELD<double, INTERLACING_TAG> * myField,
70 const SUPPORT * mySupport)
72 affiche_field_((FIELD_ *) myField, mySupport);
74 cout << "- Valeurs :"<<endl;
75 int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
76 int NumberOfComponents = myField->getNumberOfComponents() ;
78 if ( myField->getInterlacingType() == MED_EN::MED_FULL_INTERLACE ) {
79 for (int i=1; i<NumberOf+1; i++) {
80 const double * value = myField->getRow(i) ;
81 for (int j=0; j<NumberOfComponents; j++)
82 cout << value[j]<< " ";
87 for (int j=1; j<NumberOfComponents+1; j++) {
88 const double * value = myField->getColumn(j) ;
89 for (int i=0; i<NumberOf; i++)
90 cout << value[i]<< " ";
96 int main (int argc, char ** argv)
98 if ((argc !=3) && (argc != 4))
100 cerr << "Usage : " << argv[0]
101 << " filename meshname fieldname" << endl << endl;
105 string filename = argv[1] ;
106 string meshname = argv[2] ;
108 MESH * myMesh= new MESH;
109 myMesh->setName(meshname);
110 MED_MESH_RDONLY_DRIVER myMeshDriver(filename,myMesh) ;
111 myMeshDriver.setMeshName(meshname);
112 int current = myMesh->addDriver(myMeshDriver);
113 myMesh->read(current);
116 if (argc != 4) exit(0) ;
117 // else we have a field !
118 string fieldname = argv[3];
120 FIELD<double> * myField ;
121 const SUPPORT * mySupport = myMesh->getSupportOnAll(MED_CELL);
124 myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
128 mySupport = myMesh->getSupportOnAll(MED_NODE);
131 myField = new FIELD<double>(mySupport,MED_DRIVER,filename,fieldname) ;
135 cout << "Field double " << fieldname << " not found !!!" << endl ;
140 affiche_fieldT(myField, mySupport);
141 FIELD<double> * myField2 = new FIELD<double>(* myField); // Contructeur par recopie, sauf SUPPORT
142 myField->removeReference(); // Ne détruit pas le Support
143 affiche_fieldT(myField2, myField2->getSupport());
144 FIELD<double,NoInterlace> * myField3 = FieldConvert( *myField2 );
145 myField2->removeReference();
147 affiche_fieldT(myField3, myField3->getSupport());
148 FIELD<double,FullInterlace> * myField4 = FieldConvert( *myField3 );
149 myField3->removeReference();
150 affiche_fieldT(myField4, myField4->getSupport());
151 myField4->removeReference();
153 FIELD<double,NoInterlace> * myField5 = new FIELD<double,NoInterlace>(mySupport,MED_DRIVER,filename,fieldname) ;
154 affiche_fieldT(myField5, myField5->getSupport());
155 myField5->removeReference();
157 myMesh->removeReference();