Salome HOME
Remapper: PointLocator method does not make sense for srcMeshDim=2, trgtMeshDim=3...
[tools/medcoupling.git] / src / MEDLoader / MEDFileEquivalence.hxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony Geay (EDF R&D)
20
21 #ifndef __MEDFILEEQUIVALENCE_HXX__
22 #define __MEDFILEEQUIVALENCE_HXX__
23
24 #include "MEDLoaderDefines.hxx"
25 #include "MEDCouplingRefCountObject.hxx"
26 #include "MEDCouplingMemArray.hxx"
27 #include "MEDFileUtilities.txx"
28 #include "MCAuto.hxx"
29
30 #include "NormalizedGeometricTypes"
31
32 #include <vector>
33
34 namespace MEDCoupling
35 {
36   class MEDFileEquivalenceCell;
37   class MEDFileEquivalenceNode;
38   class MEDFileEquivalences;
39   class MEDFileMesh;
40
41   class MEDFileEquivalencePair : public RefCountObject, public MEDFileWritableStandAlone
42   {
43   public:
44     static MEDFileEquivalencePair *Load(MEDFileEquivalences *father, med_idt fid, const std::string& name, const std::string &desc);
45     void writeLL(med_idt fid) const;
46     const MEDFileEquivalences *getFather() const { return _father; }
47     MEDFileEquivalences *getFather() { return _father; }
48     const MEDFileMesh *getMesh() const;
49     MEDFileMesh *getMesh();
50     MEDFileEquivalencePair *deepCopy(MEDFileEquivalences *father) const;
51     bool isEqual(const MEDFileEquivalencePair *other, std::string& what) const;
52     void getRepr(std::ostream& oss) const;
53     static MEDFileEquivalencePair *New(MEDFileEquivalences *father, const std::string& name);
54     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
55     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
56   public:
57     MEDLOADER_EXPORT std::string getName() const { return _name; }
58     MEDLOADER_EXPORT void setName(const std::string& name) { _name=name; }
59     MEDLOADER_EXPORT std::string getDescription() const { return _description; }
60     MEDLOADER_EXPORT void setDescription(const std::string& descr) { _description=descr; }
61     MEDLOADER_EXPORT MEDFileEquivalenceCell *initCell();
62     MEDLOADER_EXPORT MEDFileEquivalenceNode *initNode();
63     MEDLOADER_EXPORT MEDFileEquivalenceCell *getCell() { return _cell; }
64     MEDLOADER_EXPORT MEDFileEquivalenceNode *getNode() { return _node; }
65     MEDLOADER_EXPORT void setArray(int meshDimRelToMaxExt, DataArrayInt *da);
66   private:
67     MEDFileEquivalencePair(MEDFileEquivalences *father, const std::string& name, const std::string& desc):_father(father),_name(name),_description(desc) { }
68     void load(med_idt fid);
69   private:
70     MEDFileEquivalences *_father;
71     std::string _name;
72     std::string _description;
73     MCAuto<MEDFileEquivalenceCell> _cell;
74     MCAuto<MEDFileEquivalenceNode> _node;
75   };
76
77   class MEDFileEquivalences : public RefCountObject, public MEDFileWritableStandAlone
78   {
79   public:
80     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
81     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
82     MEDLOADER_EXPORT const MEDFileMesh *getMesh() const { return _owner; }
83     MEDLOADER_EXPORT MEDFileMesh *getMesh() { return _owner; }
84     void getDtIt(int &dt, int &it) const;
85     std::string getMeshName() const;
86     void pushEquivalence(MEDFileEquivalencePair *elt);
87     static MEDFileEquivalences *New(MEDFileMesh *owner) { return new MEDFileEquivalences(owner); }
88     MEDFileEquivalences *deepCopy(MEDFileMesh *owner) const;
89     bool isEqual(const MEDFileEquivalences *other, std::string& what) const;
90     void getRepr(std::ostream& oss) const;
91   public:
92     MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalence(int i);
93     MEDLOADER_EXPORT MEDFileEquivalencePair *getEquivalenceWithName(const std::string& name);
94     MEDLOADER_EXPORT int size() const;
95     MEDLOADER_EXPORT std::vector<std::string> getEquivalenceNames() const;
96     MEDLOADER_EXPORT MEDFileEquivalencePair *appendEmptyEquivalenceWithName(const std::string& name);
97     MEDLOADER_EXPORT void killEquivalenceWithName(const std::string& name);
98     MEDLOADER_EXPORT void killEquivalenceAt(int i);
99     MEDLOADER_EXPORT void clear();
100   public:
101     MEDLOADER_EXPORT void writeLL(med_idt fid) const;
102     static int PresenceOfEquivalences(med_idt fid, const std::string& meshName);
103     static MEDFileEquivalences *Load(med_idt fid, int nbOfEq, MEDFileMesh *owner);
104     static void CheckDataArray(const DataArrayInt *data);
105   private:
106     MEDFileEquivalences(MEDFileMesh *owner):_owner(owner) { }
107     void deepCpyFrom(const MEDFileEquivalences& other);
108   private:
109     MEDFileMesh *_owner;
110     std::vector< MCAuto<MEDFileEquivalencePair> > _equ;
111   };
112
113   class MEDFileEquivalenceBase : public RefCountObject, public MEDFileWritableStandAlone
114   {
115   protected:
116     MEDFileEquivalenceBase(MEDFileEquivalencePair *father);
117     const MEDFileEquivalencePair *getFather() const { return _father; }
118     MEDFileEquivalencePair *getFather() { return _father; }
119     const MEDFileMesh *getMesh() const { return getFather()->getMesh(); }
120     MEDFileMesh *getMesh() { return getFather()->getMesh(); }
121   protected:
122     ~MEDFileEquivalenceBase() { }
123   private:
124     MEDFileEquivalencePair *_father;
125   };
126
127   class MEDFileEquivalenceData : public MEDFileEquivalenceBase
128   {
129   public:
130     MEDFileEquivalenceData(MEDFileEquivalencePair *owner, DataArrayInt *data);
131     MEDLOADER_EXPORT void setArray(DataArrayInt *data);
132     MEDLOADER_EXPORT const DataArrayInt *getArray() const { return _data; }
133     MEDLOADER_EXPORT DataArrayInt *getArray() { return _data; }
134     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
135     bool isEqual(const MEDFileEquivalenceData *other, std::string& what) const;
136   protected:
137     void writeAdvanced(med_idt fid, med_entity_type medtype, med_geometry_type medgt) const;
138   protected:
139     ~MEDFileEquivalenceData() { }
140   protected:
141     MCAuto<DataArrayInt> _data;
142   };
143
144   class MEDFileEquivalenceCellType : public MEDFileEquivalenceData
145   {
146   public:
147     MEDFileEquivalenceCellType(MEDFileEquivalencePair *owner, INTERP_KERNEL::NormalizedCellType type, DataArrayInt *data):MEDFileEquivalenceData(owner,data),_type(type) { }
148     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
149     INTERP_KERNEL::NormalizedCellType getType() const { return _type; }
150     MEDFileEquivalenceCellType *deepCopy(MEDFileEquivalencePair *owner) const;
151     bool isEqual(const MEDFileEquivalenceCellType *other, std::string& what) const;
152     void getRepr(std::ostream& oss) const;
153   public:
154     void writeLL(med_idt fid) const;
155   protected:
156     ~MEDFileEquivalenceCellType() { }
157   private:
158     INTERP_KERNEL::NormalizedCellType _type;
159   };
160
161   class MEDFileEquivalenceCell : public MEDFileEquivalenceBase
162   {
163   public:
164     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
165     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
166     static MEDFileEquivalenceCell *Load(med_idt fid, MEDFileEquivalencePair *owner);
167     void writeLL(med_idt fid) const;
168     MEDFileEquivalenceCell *deepCopy(MEDFileEquivalencePair *owner) const;
169     bool isEqual(const MEDFileEquivalenceCell *other, std::string& what) const;
170     void getRepr(std::ostream& oss) const;
171   public:
172     MEDLOADER_EXPORT void clear() { _types.clear(); }
173     MEDLOADER_EXPORT std::size_t size() const { return _types.size(); }
174     MEDLOADER_EXPORT DataArrayInt *getArray(INTERP_KERNEL::NormalizedCellType type);
175     MEDLOADER_EXPORT void setArray(int meshDimRelToMax, DataArrayInt *da);
176     MEDLOADER_EXPORT void setArrayForType(INTERP_KERNEL::NormalizedCellType type, DataArrayInt *da);
177     MEDLOADER_EXPORT std::vector<INTERP_KERNEL::NormalizedCellType> getTypes() const;
178   public:
179     MEDFileEquivalenceCell(MEDFileEquivalencePair *owner):MEDFileEquivalenceBase(owner) { }
180   private:
181     ~MEDFileEquivalenceCell() { }
182   private:
183     void load(med_idt fid);
184     std::string getName() const { return getFather()->getName(); }
185   private:
186     std::vector< MCAuto<MEDFileEquivalenceCellType> > _types;
187   };
188
189   class MEDFileEquivalenceNode : public MEDFileEquivalenceData
190   {
191   public:
192     MEDFileEquivalenceNode(MEDFileEquivalencePair *owner, DataArrayInt *data):MEDFileEquivalenceData(owner,data) { }
193     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
194     void writeLL(med_idt fid) const;
195     MEDFileEquivalenceNode *deepCopy(MEDFileEquivalencePair *owner) const;
196     bool isEqual(const MEDFileEquivalenceNode *other, std::string& what) const;
197     void getRepr(std::ostream& oss) const;
198   protected:
199     ~MEDFileEquivalenceNode() { }
200   };
201 }
202
203 #endif
204