1 #include "Calculator.hxx"
2 #include "MEDMEM_Field.hxx"
3 #include "MEDMEM_Mesh.hxx"
7 using namespace MED_EN;
9 CALCULATOR::CALCULATOR()
11 string ressourceDir(getenv("MED_ROOT_DIR"));
12 ressourceDir+="/share/salome/resources/";
13 const string FileName(ressourceDir+"pointe.med");
14 const string FieldName("fieldcelldouble");
15 const string MeshName("maa1");
18 myMesh_ = new MEDMEM::MESH(MEDMEM::MED_DRIVER,FileName.c_str(),MeshName.c_str());
19 cout<<"Lecture du Maillage Source : " << myMesh_->getName() << endl << flush;
20 cout<<"Construction du support : "<< endl << flush;
21 MEDMEM::SUPPORT* fromSupport=new MEDMEM::SUPPORT(myMesh_,"XsupportX",MED_CELL);
22 myField_ = new MEDMEM::FIELD<double>(fromSupport,MEDMEM::MED_DRIVER,FileName.c_str(),FieldName.c_str());
23 cout<<"Lecture du champ Source : " << myField_->getName() << endl << flush;
24 cout<<"Fin Constructeur TESTMED"<<endl<<flush;
26 catch (MEDMEM::MEDEXCEPTION& ex)
32 CALCULATOR::~CALCULATOR()
40 MEDMEM::FIELD<double>* CALCULATOR::createConstField(double value)
42 MEDMEM::FIELD<double>* myField=new MEDMEM::FIELD<double>(myField_->getSupport(),1);
43 for(int i=0; i!=myField_->getNumberOfValues();++i)
44 myField->setValueIJ(i+1,1,value);
45 myField->setName("Const field");
49 double CALCULATOR::norm2(const MEDMEM::FIELD<double>& field)
54 double CALCULATOR::normMax(const MEDMEM::FIELD<double>& field)
56 return field.normMax();
59 MEDMEM::FIELD<double>* CALCULATOR::add(const MEDMEM::FIELD<double>& field1, const MEDMEM::FIELD<double>& field2)
61 return new MEDMEM::FIELD<double>(field1+field2);
64 void CALCULATOR::printField(const MEDMEM::FIELD<double>* myField)
66 const MEDMEM::SUPPORT * mySupport = myField->getSupport();
67 std::cout << "\n------------------ Field "<< myField->getName() << " : " <<myField->getDescription() << "------------------" << std::endl ;
68 int NumberOfComponents = myField->getNumberOfComponents() ;
69 std::cout << "- Type : " << mySupport->getEntity() << std::endl;
70 std::cout << "- Nombre de composantes : "<< NumberOfComponents << std::endl ;
71 std::cout << "- Nombre de valeurs : "<< myField->getNumberOfValues() << std::endl ;
72 for (int i=1; i<NumberOfComponents+1; i++) {
73 std::cout << " - composante "<<i<<" :"<<std::endl ;
74 std::cout << " - nom : "<<myField->getComponentName(i)<< std::endl;
75 std::cout << " - description : "<<myField->getComponentDescription(i) << std::endl;
76 std::cout << " - units : "<<myField->getMEDComponentUnit(i) << std::endl;
78 std::cout << "- iteration :" << std::endl ;
79 std::cout << " - numero : " << myField->getIterationNumber()<< std::endl ;
80 std::cout << " - ordre : " << myField->getOrderNumber()<< std::endl ;
81 std::cout << " - temps : " << myField->getTime()<< std::endl ;
82 std::cout << "- Type : " << myField->getValueType()<< std::endl;
84 std::cout << "- Valeurs :"<<std::endl;
85 int NumberOf = mySupport->getNumberOfElements(MED_ALL_ELEMENTS);
87 //mySupport->isOnAllElements()
88 bool displayNode = mySupport->isOnAllElements() && mySupport->getEntity()==MED_NODE;
89 bool displayBary = mySupport->isOnAllElements() && mySupport->getEntity()==MED_CELL;
90 int dim_space = mySupport->getMesh()->getSpaceDimension();
91 const double * coord = mySupport->getMesh()->getCoordinates(MED_FULL_INTERLACE);
93 MEDMEM::FIELD<double>* barycenter(0);
95 barycenter = mySupport->getMesh()->getBarycenter(mySupport);
97 for (int i=1; i<NumberOf+1; i++) {
98 const double * value = myField->getValueI(MED_FULL_INTERLACE,i) ;
101 int N=(i-1)*dim_space;
102 std::cout << std::setw(5) << coord[N] << " " << std::setw(5) << coord[N+1]<< " " << std::setw(5) << coord[N+2] << " : " ;
105 std::cout << std::setw(5) << barycenter->getValueIJ(i,1) << " " << std::setw(5) << barycenter->getValueIJ(i,2)
106 << " " << std::setw(5) << barycenter->getValueIJ(i,3) << " : " ;
107 for (int j=0; j<NumberOfComponents; j++)
108 std::cout << value[j]<< " ";
109 std::cout<<std::endl;
111 std::cout << std::endl;
112 std::cout << "Norme euclidienne : " << myField->norm2() << std::endl;
113 std::cout << "Norme max : " << myField->normMax() << std::endl;
114 std::cout << "------------------------------------------------------------------------" << std::endl << std::endl << std::flush;