From 4062f7935c72e01a12e2e9fd58bbf57d8fd73625 Mon Sep 17 00:00:00 2001 From: ageay Date: Wed, 4 Nov 2009 15:44:51 +0000 Subject: [PATCH] *** empty log message *** --- src/ParaMEDMEM/ICoCoField.cxx | 34 ++++ src/ParaMEDMEM/ICoCoField.hxx | 14 +- src/ParaMEDMEM/ICoCoTrioField.cxx | 247 ++++++++++++++++++++++++++++++ src/ParaMEDMEM/ICoCoTrioField.hxx | 69 +++++---- src/ParaMEDMEM/Makefile.am | 2 + 5 files changed, 326 insertions(+), 40 deletions(-) create mode 100644 src/ParaMEDMEM/ICoCoField.cxx create mode 100644 src/ParaMEDMEM/ICoCoTrioField.cxx diff --git a/src/ParaMEDMEM/ICoCoField.cxx b/src/ParaMEDMEM/ICoCoField.cxx new file mode 100644 index 000000000..8b9cd4a10 --- /dev/null +++ b/src/ParaMEDMEM/ICoCoField.cxx @@ -0,0 +1,34 @@ +////////////////////////////////////////////////////////////////////////////// +// +// File: ICoCoField.cpp +// Directory: $TRIO_U_ROOT/Kernel/ICoCo +// Version: /main/1 +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +using namespace ICoCo; +using std::string; + +Field::Field() { + _name=new string; +} + +Field::~Field() { + delete _name; +} + +void Field::setName(const string& name) { + *_name=name; +} + +const string& Field::getName() const { + return *_name; +} + +const char* Field::getCharName() const { + return _name->c_str(); +} diff --git a/src/ParaMEDMEM/ICoCoField.hxx b/src/ParaMEDMEM/ICoCoField.hxx index b2436fde4..027473e58 100644 --- a/src/ParaMEDMEM/ICoCoField.hxx +++ b/src/ParaMEDMEM/ICoCoField.hxx @@ -26,12 +26,14 @@ namespace ICoCo class Field { public: - Field() { } - virtual ~Field() { } - void setName(const std::string& name) { _name=name; } - std::string getName() const { return _name; } - protected: - std::string _name; + Field(); + virtual ~Field(); + void setName(const std::string& name); + const std::string& getName() const; + const char* getCharName() const; + + private: + std::string* _name; }; } diff --git a/src/ParaMEDMEM/ICoCoTrioField.cxx b/src/ParaMEDMEM/ICoCoTrioField.cxx new file mode 100644 index 000000000..02f5d4c33 --- /dev/null +++ b/src/ParaMEDMEM/ICoCoTrioField.cxx @@ -0,0 +1,247 @@ +////////////////////////////////////////////////////////////////////////////// +// +// File: ICoCoTrioField.cpp +// Directory: $TRIO_U_ROOT/Kernel/Framework +// Version: +// +////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include + +using namespace ICoCo; +using namespace std; + +TrioField::TrioField() : + _type(0), + _connectivity(0), + _coords(0), + _field(0), + _has_field_ownership(false) { } + +TrioField::~TrioField() { + clear(); +} + +// After the call to clear(), all pointers are null and field ownership is false. +// Arrays are deleted if necessary +void TrioField::clear() { + if (_connectivity) + delete[] _connectivity; + if (_coords) + delete[] _coords; + if (_field && _has_field_ownership) + delete[] _field; + _connectivity=0; + _coords=0; + _field=0; + _has_field_ownership=false; +} + +int TrioField::nb_values() const +{ + if (_type==0) + return _nb_elems; + else + if (_type==1) + return _nbnodes; + exit(-1); + return -1; + +} +void TrioField::save(ostream& os) const{ + os <> name; + setName(name); + in>>_type; + in>>_mesh_dim; + in>> _space_dim; + in>> _nbnodes; + in>> _nodes_per_elem; + in>> _nb_elems; + + in>> _itnumber; + if (_connectivity) + delete [] _connectivity; + _connectivity=new int[_nodes_per_elem*_nb_elems]; + for (int i=0;i<_nb_elems;i++) + { + for (int j=0;j<_nodes_per_elem;j++) + in>>_connectivity[i*_nodes_per_elem+j]; + + } + if (_coords) + delete [] _coords; + _coords=new double[_nbnodes*_space_dim]; + for (int i=0;i<_nbnodes;i++) + { + for (int j=0;j<_space_dim;j++) + in>> _coords[i*_space_dim+j] ; + + } + + in>> _time1; + in>>_time2; + in>> _nb_field_components; + int test; + in>> test; + if (test) + { + if (_field) + delete [] _field; + _field=new double[_nb_field_components*nb_values()]; + for (int i=0;i> _field[i*_nb_field_components+j]; + + } + } + else + { + _field=0; + } + in>> _has_field_ownership; +} + void TrioField::print() { + + } + +// After the call to set_standalone(), field ownership is true and field is allocated +// to the size _nb_field_components*_nb_elems. +// The values of the field have been copied if necessary. +void TrioField::set_standalone() { + if (!_field) { + _field=new double[_nb_field_components*_nb_elems]; + _has_field_ownership=true; + + } + else if (!_has_field_ownership) { + double *tmp_field=new double[_nb_field_components*_nb_elems]; + memcpy(tmp_field,_field,_nb_field_components*_nb_elems*sizeof(double)); + _field=tmp_field; + _has_field_ownership=true; + } +} + +// Used to simulate a 0D geometry (Cathare/Trio for example). +void TrioField::dummy_geom() { + _mesh_dim=2; + _space_dim=2; + _nbnodes=3; + _nodes_per_elem=3; + _nb_elems=1; + _itnumber=0; + if (_connectivity) + delete[] _connectivity; + _connectivity=new int[3]; + _connectivity[0]=1; + _connectivity[1]=2; + _connectivity[2]=3; + if (_coords) + delete[] _coords; + _coords=new double[6]; + _coords[0]=0; + _coords[1]=0; + _coords[2]=1; + _coords[3]=0; + _coords[4]=0; + _coords[5]=1; + if (_field && _has_field_ownership) + delete[] _field; + _has_field_ownership=false; + _field=0; +} + +// Surcharge de l'operateur = pour la classe TrioField +// remplace les valeurs trouvee dans le TrioField donnee en parametre +TrioField& TrioField::operator=(const TrioField& NewField){ + + clear(); + _type=NewField._type; + _mesh_dim=NewField._mesh_dim; + _space_dim=NewField._space_dim; + _nbnodes=NewField._nbnodes; + _nodes_per_elem=NewField._nodes_per_elem; + _nb_elems=NewField._nb_elems; + _itnumber=NewField._itnumber; + // std::string _name; // ?? Hérité de la classe mère + _time1=NewField._time1; + _time2=NewField._time2; + _nb_field_components=NewField._nb_field_components; + + if (!NewField._connectivity) + _connectivity=0; + else { + _connectivity=new int[_nodes_per_elem*_nb_elems]; + memcpy( _connectivity,NewField._connectivity,_nodes_per_elem*_nb_elems*sizeof(int)); + } + + if (!NewField._coords) + _coords=0; + else { + _coords=new double[_nbnodes*_space_dim]; + memcpy( _coords,NewField._coords,_nbnodes*_space_dim*sizeof(double)); + } + + //Copie des valeurs du champ + _has_field_ownership=NewField._has_field_ownership; + if (_has_field_ownership) { + _field=new double[_nb_elems*_nb_field_components]; + memcpy(_field,NewField._field,_nb_elems*_nb_field_components*sizeof(double)); + } + else + _field=NewField._field; + + return(*this); + +} + diff --git a/src/ParaMEDMEM/ICoCoTrioField.hxx b/src/ParaMEDMEM/ICoCoTrioField.hxx index 869745b4c..d61539260 100644 --- a/src/ParaMEDMEM/ICoCoTrioField.hxx +++ b/src/ParaMEDMEM/ICoCoTrioField.hxx @@ -1,46 +1,46 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D +////////////////////////////////////////////////////////////////////////////// // -// 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. +// File: ICoCoTrioField.h +// Directory: $TRIO_U_ROOT/Kernel/Framework +// Version: // -// 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 -// -#ifndef __ICOCOTRIOFIELD_HXX__ -#define __ICOCOTRIOFIELD_HXX__ +////////////////////////////////////////////////////////////////////////////// -#include "ICoCoField.hxx" - -#include +#ifndef _ICOCOTRIOFIELD_HXX_ +#define _ICOCOTRIOFIELD_HXX_ +#include namespace ICoCo { - /*! - \brief structure for coupling Trio codes via the ICoCo interface + /*! + \brief structure for coupling Trio codes via the ICoCo interface + + This structure contains all the necessary information + for constructing a ParaMEDMEM::ParaFIELD (with the addition of the MPI + communicator). The ICoCo API specifies two kinds of calls for + the ICoCo::Field : either with the mesh only or with the entire information (mesh and field). + This structure can therefore be left without _time, _nb_field_components, _field + information, which are related to the field values. + + _coords and _connectivity tables are always owned by the TrioField. - This structure contains all the necessary information - for constructing a ParaMEDMEM::ParaFIELD (with the addition of the MPI - communicator). The ICoCo API specifies two kinds of calls for - the ICoCo::Field : either with the mesh only or with the entire information (mesh and field). - This structure can therefore be left without _time, _nb_field_components, _field - information, which are related to the field values. - */ - class TrioField : public Field + */ + class TrioField:public Field { public: - TrioField() { _connectivity=0; _coords=0; _field=0; _has_field_ownership=false; } - ~TrioField() { delete[] _connectivity; delete[] _coords; if (_has_field_ownership) delete[] _field; } + + TrioField(); + ~TrioField(); + void clear(); + void print(); + void set_standalone(); + void dummy_geom(); + TrioField& operator=(const TrioField& NewField); + void save(std::ostream& os) const; + void restore(std::istream& in); + int nb_values() const ; public: + int _type ; // 0 elem 1 nodes int _mesh_dim; int _space_dim; int _nbnodes; @@ -49,11 +49,12 @@ namespace ICoCo int _itnumber; int* _connectivity; double* _coords; + double _time1,_time2; int _nb_field_components; double* _field; bool _has_field_ownership; - }; + }; } #endif diff --git a/src/ParaMEDMEM/Makefile.am b/src/ParaMEDMEM/Makefile.am index ba0f42214..746b7170a 100644 --- a/src/ParaMEDMEM/Makefile.am +++ b/src/ParaMEDMEM/Makefile.am @@ -81,6 +81,8 @@ DEC.cxx\ ExplicitTopology.cxx\ MxN_Mapping.cxx\ ICoCoMEDField.cxx\ +ICoCoField.cxx\ +ICoCoTrioField.cxx\ ParaFIELD.cxx\ ParaGRID.cxx\ BlockTopology.cxx -- 2.39.2