Salome HOME
Fix computation height of isocel triangle with base equal zero : NaN
[tools/medcoupling.git] / src / MEDLoader / MEDFileJoint.hxx
1 // Copyright (C) 2007-2023  CEA, EDF
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
20 #ifndef __MEDFILEJOINT_HXX__
21 #define __MEDFILEJOINT_HXX__
22
23 #include "MEDLoaderDefines.hxx"
24 #include "MEDFileUtilities.txx"
25 #include "MEDCouplingMemArray.hxx"
26 #include "MCAuto.hxx"
27
28 #include "NormalizedGeometricTypes"
29
30 namespace MEDCoupling
31 {
32 /*!
33  * \brief Joint Correspondence enumerates pairs of corresponding entities of a
34  *        certain geometrical type in adjacent mesh domains.
35  *        Correspondence of nodes is constructed when you specify no cell type,
36  *        else Correspondence of cells is constructed.
37  */
38 class MEDFileJointCorrespondence : public RefCountObject, public MEDFileWritable
39 {
40 public:
41   MEDLOADER_EXPORT static MEDFileJointCorrespondence *New();
42   MEDLOADER_EXPORT static MEDFileJointCorrespondence *New(DataArrayIdType* correspondence); // nodes
43   MEDLOADER_EXPORT static MEDFileJointCorrespondence *New(DataArrayIdType* correspondence,  // cells
44                                                           INTERP_KERNEL::NormalizedCellType loc_geo_type,
45                                                           INTERP_KERNEL::NormalizedCellType rem_geo_type);
46   MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileJointCorrespondence"); }
47   MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
48   MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
49   MEDLOADER_EXPORT MEDFileJointCorrespondence *deepCopy() const;
50   MEDLOADER_EXPORT MEDFileJointCorrespondence *shallowCpy() const;
51   MEDLOADER_EXPORT bool isEqual(const MEDFileJointCorrespondence *other) const;
52   MEDLOADER_EXPORT void setIsNodal(bool isNodal) { _is_nodal = isNodal; }
53   MEDLOADER_EXPORT bool getIsNodal() const { return _is_nodal; }
54   MEDLOADER_EXPORT void setLocalGeometryType(INTERP_KERNEL::NormalizedCellType type) { _loc_geo_type=type; }
55   MEDLOADER_EXPORT INTERP_KERNEL::NormalizedCellType getLocalGeometryType() const { return _loc_geo_type; }
56   MEDLOADER_EXPORT void setRemoteGeometryType(INTERP_KERNEL::NormalizedCellType type) { _rem_geo_type=type; }
57   MEDLOADER_EXPORT INTERP_KERNEL::NormalizedCellType getRemoteGeometryType() const { return _rem_geo_type; }
58   MEDLOADER_EXPORT void setCorrespondence(DataArrayIdType *corr);
59   MEDLOADER_EXPORT const DataArrayIdType *getCorrespondence() const { return _correspondence; }
60   MEDLOADER_EXPORT void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const;
61
62   MEDLOADER_EXPORT std::string simpleRepr() const;
63   MEDLOADER_EXPORT void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName, int order, int iteration) const;
64 private:
65   MEDFileJointCorrespondence();
66   MEDFileJointCorrespondence(DataArrayIdType*                     correspondence,
67                              bool                              is_nodal = true,
68                              INTERP_KERNEL::NormalizedCellType loc_geo_type = INTERP_KERNEL::NORM_ERROR,
69                              INTERP_KERNEL::NormalizedCellType rem_geo_type = INTERP_KERNEL::NORM_ERROR);
70 private:
71   bool                                           _is_nodal;
72   INTERP_KERNEL::NormalizedCellType              _loc_geo_type;
73   INTERP_KERNEL::NormalizedCellType              _rem_geo_type;
74   MCAuto<DataArrayIdType> _correspondence;
75 };
76
77 /*!
78  * \brief Joint of one iteration holds correspondences of entities of all types
79  */
80 class MEDFileJointOneStep : public RefCountObject, public MEDFileWritable
81 {
82 public:
83   MEDLOADER_EXPORT static MEDFileJointOneStep *New(int dt=-1, int it=-1);
84   MEDLOADER_EXPORT static MEDFileJointOneStep *New(const std::string& fileName, const std::string& mName, const std::string& jointName, int number=1);
85   MEDLOADER_EXPORT static MEDFileJointOneStep *New(med_idt fid, const std::string& mName, const std::string& jointName, int number=1);
86   MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileJointOneStep"); }
87   MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
88   MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
89   MEDLOADER_EXPORT MEDFileJointOneStep *deepCopy() const;
90   MEDLOADER_EXPORT MEDFileJointOneStep *shallowCpy() const;
91   MEDLOADER_EXPORT bool isEqual(const MEDFileJointOneStep *other) const;
92   MEDLOADER_EXPORT void setOrder(int order) { _order=order; }
93   MEDLOADER_EXPORT int getOrder() const { return _order; }
94   MEDLOADER_EXPORT void setIteration(int it) { _iteration=it; }
95   MEDLOADER_EXPORT int getIteration() const { return _iteration; }
96   MEDLOADER_EXPORT void pushCorrespondence(MEDFileJointCorrespondence* correspondence);
97   MEDLOADER_EXPORT void clearCorrespondences();
98   MEDLOADER_EXPORT int getNumberOfCorrespondences() const;
99   MEDLOADER_EXPORT MEDFileJointCorrespondence *getCorrespondenceAtPos(int i) const;
100
101   MEDLOADER_EXPORT void write(const std::string& fileName, int mode, const std::string& localMeshName, const std::string& jointName) const;
102
103   MEDLOADER_EXPORT std::string simpleRepr() const;
104   MEDLOADER_EXPORT void writeLL(med_idt fid, const std::string& localMeshName, const std::string& jointName) const;
105 private:
106   MEDFileJointOneStep();
107   MEDFileJointOneStep(med_idt fid, const std::string& mName, const std::string& jointName, int number);
108   MEDLOADER_EXPORT INTERP_KERNEL::NormalizedCellType convertGeometryType(med_geometry_type geotype);
109 protected:
110   int _order;
111   int _iteration;
112 private:
113   std::vector<MCAuto<MEDFileJointCorrespondence> > _correspondences;
114 };
115
116 /*!
117  * \brief Joint holds a sequence of joints of different iterations relating to
118  *        a pair of mesh domains: a local one and a distant one
119  */
120 class MEDFileJoint : public RefCountObject, public MEDFileWritableStandAlone
121 {
122 public:
123     MEDLOADER_EXPORT static MEDFileJoint *New();
124     MEDLOADER_EXPORT static MEDFileJoint *New(const std::string& fileName, const std::string& mName, int num);
125     MEDLOADER_EXPORT static MEDFileJoint *New(med_idt fid, const std::string& mName, int num);
126     MEDLOADER_EXPORT static MEDFileJoint *New(const std::string& jointName, const std::string& locMeshName, const std::string& remoteMeshName, int remoteMeshNum );
127     MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileJoint"); }
128     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
129     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
130     MEDLOADER_EXPORT MEDFileJoint *deepCopy() const;
131     MEDLOADER_EXPORT MEDFileJoint *shallowCpy() const;
132     MEDLOADER_EXPORT bool isEqual(const MEDFileJoint *other) const;
133     MEDLOADER_EXPORT void setLocalMeshName(const std::string& name) { _loc_mesh_name=name; }
134     MEDLOADER_EXPORT std::string getLocalMeshName() const { return _loc_mesh_name; }
135     MEDLOADER_EXPORT void setRemoteMeshName(const std::string& name) { _rem_mesh_name=name; }
136     MEDLOADER_EXPORT std::string getRemoteMeshName() const { return _rem_mesh_name; }
137     MEDLOADER_EXPORT void setDescription(const std::string& name) { _desc_name=name; }
138     MEDLOADER_EXPORT std::string getDescription() const { return _desc_name; }
139     MEDLOADER_EXPORT void setJointName(const std::string& name) { _joint_name=name; }
140     MEDLOADER_EXPORT std::string getJointName() const { return _joint_name; }
141     MEDLOADER_EXPORT bool changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab);
142     MEDLOADER_EXPORT void setDomainNumber(const int& number) { _domain_number=number; }
143     MEDLOADER_EXPORT int getDomainNumber() const { return _domain_number; }
144     MEDLOADER_EXPORT void pushStep(MEDFileJointOneStep* step);
145     MEDLOADER_EXPORT int getNumberOfSteps() const;
146     MEDLOADER_EXPORT MEDFileJointOneStep *getStepAtPos(int i) const;
147
148     MEDLOADER_EXPORT void writeLL(med_idt fid) const;
149
150     MEDLOADER_EXPORT std::string simpleRepr() const;
151   private:
152     MEDFileJoint();
153     MEDFileJoint(med_idt fid, const std::string& mName, int num);
154   private:
155     std::string _loc_mesh_name;
156     std::string _joint_name;
157     std::string _desc_name;
158     int _domain_number;
159     std::string _rem_mesh_name;
160     std::vector< MCAuto<MEDFileJointOneStep> > _joint;
161   };
162
163   /*!
164    * \brief Joints of a mesh domain relating to all other mesh domains
165    */
166   class MEDFileJoints : public RefCountObject, public MEDFileWritableStandAlone
167   {
168   public:
169     MEDLOADER_EXPORT static MEDFileJoints *New();
170     MEDLOADER_EXPORT static MEDFileJoints *New(const std::string& fileName, const std::string& meshName);
171     MEDLOADER_EXPORT static MEDFileJoints *New(med_idt fid, const std::string& meshName);
172     MEDLOADER_EXPORT std::string getClassName() const override { return std::string("MEDFileJoints"); }
173     MEDLOADER_EXPORT MEDFileJoints *deepCopy() const;
174     MEDLOADER_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
175     MEDLOADER_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
176     MEDLOADER_EXPORT std::string simpleRepr() const;
177     MEDLOADER_EXPORT void simpleReprWithoutHeader(std::ostream& oss) const;
178     MEDLOADER_EXPORT void writeLL(med_idt fid) const;
179     MEDLOADER_EXPORT std::string getMeshName() const;
180     MEDLOADER_EXPORT int getNumberOfJoints() const;
181     MEDLOADER_EXPORT MEDFileJoint *getJointAtPos(int i) const;
182     MEDLOADER_EXPORT MEDFileJoint *getJointWithName(const std::string& jname) const;
183     MEDLOADER_EXPORT std::vector<std::string> getJointsNames() const;
184     MEDLOADER_EXPORT bool changeJointNames(const std::vector< std::pair<std::string,std::string> >& modifTab);
185     //
186     MEDLOADER_EXPORT void resize(int newSize);
187     MEDLOADER_EXPORT void pushJoint(MEDFileJoint *joint);
188     MEDLOADER_EXPORT void setJointAtPos(int i, MEDFileJoint *joint);
189     MEDLOADER_EXPORT void destroyJointAtPos(int i);
190   private:
191     ~MEDFileJoints() { }
192     MEDFileJoints();
193     MEDFileJoints(med_idt fid, const std::string& meshName);
194   private:
195     std::vector< MCAuto<MEDFileJoint> > _joints;
196   };
197 }
198
199 #endif