Salome HOME
bd38f61d28539b3f05230a7ec92546d341fd4b6c
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingCartesianAMRMesh.hxx
1 // Copyright (C) 2007-2014  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
20
21 #ifndef __MEDCOUPLINGCARTESIANAMRMESH_HXX__
22 #define __MEDCOUPLINGCARTESIANAMRMESH_HXX__
23
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingTimeLabel.hxx"
26 #include "MEDCouplingRefCountObject.hxx"
27 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
28
29 #include "BoxSplittingOptions.hxx"
30 #include "InterpKernelException.hxx"
31
32 namespace ParaMEDMEM
33 {
34   class MEDCouplingIMesh;
35   class MEDCouplingUMesh;
36   class DataArrayInt;
37   class DataArrayByte;
38   class DataArrayDouble;
39   class MEDCoupling1SGTUMesh;
40   class MEDCouplingCartesianAMRMesh;
41   class MEDCouplingCartesianAMRMeshGen;
42
43   /// @cond INTERNAL
44
45   class MEDCouplingCartesianAMRPatchGen : public RefCountObject
46   {
47   public:
48     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
49     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
50     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
51     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getMesh() const { return _mesh; }
52   protected:
53     MEDCouplingCartesianAMRPatchGen(MEDCouplingCartesianAMRMeshGen *mesh);
54     const MEDCouplingCartesianAMRMeshGen *getMeshSafe() const;
55     MEDCouplingCartesianAMRMeshGen *getMeshSafe();
56   private:
57     std::vector<const BigMemoryObject *> getDirectChildren() const;
58   protected:
59     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMeshGen> _mesh;
60   };
61
62   class MEDCouplingCartesianAMRPatch : public MEDCouplingCartesianAMRPatchGen
63   {
64   public:
65     MEDCouplingCartesianAMRPatch(MEDCouplingCartesianAMRMeshGen *mesh, const std::vector< std::pair<int,int> >& bottomLeftTopRight);
66     // direct forward to _mesh
67     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
68     // end of direct forward to _mesh
69     MEDCOUPLING_EXPORT int getNumberOfOverlapedCellsForFather() const;
70     MEDCOUPLING_EXPORT bool isInMyNeighborhood(const MEDCouplingCartesianAMRPatch *other, int ghostLev) const;
71     // basic set/get
72     MEDCOUPLING_EXPORT const std::vector< std::pair<int,int> >& getBLTRRange() const { return _bl_tr; }
73   private:
74     std::size_t getHeapMemorySizeWithoutChildren() const;
75   private:
76     //! bottom left/top right cell range relative to \a _father
77     std::vector< std::pair<int,int> > _bl_tr;
78   };
79
80   class MEDCouplingCartesianAMRPatchGF : public MEDCouplingCartesianAMRPatchGen
81   {
82   public:
83     MEDCouplingCartesianAMRPatchGF(MEDCouplingCartesianAMRMesh *mesh);
84   private:
85     std::size_t getHeapMemorySizeWithoutChildren() const;
86   };
87
88   class MEDCouplingDataForGodFather : public RefCountObject
89   {
90   };
91   /// @endcond
92
93   /*!
94    * This class is the base class dedicated to AMR using Adaptative Hierarchical Overlapped image Grid.
95    * This class does \b NOT inherit from MEDCouplingMesh because this class overlaps image grid structured meshes to perform adaptative mesh refinement.
96    * But this class aggregates MEDCouplingMesh instances !
97    */
98   class MEDCouplingCartesianAMRMeshGen : public RefCountObject, public TimeLabel
99   {
100   public:
101     MEDCOUPLING_EXPORT int getSpaceDimension() const;
102     MEDCOUPLING_EXPORT const std::vector<int>& getFactors() const { return _factors; }
103     MEDCOUPLING_EXPORT void setFactors(const std::vector<int>& newFactors);
104     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
105     MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevel() const;
106     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
107     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
108     MEDCOUPLING_EXPORT const MEDCouplingIMesh *getImageMesh() const { return _mesh; }
109     //
110     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getFather() const;
111     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getGodFather() const;
112     MEDCOUPLING_EXPORT int getAbsoluteLevel() const;
113     MEDCOUPLING_EXPORT std::vector<MEDCouplingCartesianAMRPatchGen *> retrieveGridsAt(int absoluteLev) const;
114     MEDCOUPLING_EXPORT void detachFromFather();
115     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
116     MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const std::vector<bool>& criterion, const std::vector<int>& factors);
117     MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const DataArrayByte *criterion, const std::vector<int>& factors);
118     MEDCOUPLING_EXPORT void removeAllPatches();
119     MEDCOUPLING_EXPORT void removePatch(int patchId);
120     MEDCOUPLING_EXPORT int getNumberOfPatches() const;
121     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRPatch *getPatch(int patchId) const;
122     MEDCOUPLING_EXPORT bool isPatchInNeighborhoodOf(int patchId1, int patchId2, int ghostLev) const;
123     MEDCOUPLING_EXPORT DataArrayDouble *createCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis) const;
124     MEDCOUPLING_EXPORT void fillCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch) const;
125     MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhost(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch, int ghostLev) const;
126     MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhostAdv(int patchId, const DataArrayDouble *cellFieldOnThis, int ghostLev, const std::vector<const DataArrayDouble *>& arrsOnPatches) const;
127     MEDCOUPLING_EXPORT void fillCellFieldComingFromPatch(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis) const;
128     MEDCOUPLING_EXPORT void fillCellFieldComingFromPatchGhost(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis, int ghostLev) const;
129     MEDCOUPLING_EXPORT DataArrayInt *findPatchesInTheNeighborhoodOf(int patchId, int ghostLev) const;
130     //
131     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const;
132     MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshFromPatchEnvelop() const;
133     MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshOfDirectChildrenOnly() const;
134   protected:
135     MEDCouplingCartesianAMRMeshGen(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
136                                    const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
137     MEDCouplingCartesianAMRMeshGen(MEDCouplingCartesianAMRMeshGen *father, MEDCouplingIMesh *mesh);
138     void checkPatchId(int patchId) const;
139     void checkFactorsAndIfNotSetAssign(const std::vector<int>& factors);
140     void retrieveGridsAtInternal(int lev, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatchGen> >& grids) const;
141     static void ApplyFactorsOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, const std::vector<int>& factors);
142     static void ApplyGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
143     static void ApplyAllGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
144   protected:
145     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
146     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
147     MEDCOUPLING_EXPORT void updateTime() const;
148   private:
149     MEDCouplingCartesianAMRMeshGen *_father;
150     MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> _mesh;
151     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatch> > _patches;
152     std::vector<int> _factors;
153   };
154
155   class MEDCouplingCartesianAMRMeshSub : public MEDCouplingCartesianAMRMeshGen
156   {
157   public:
158     MEDCouplingCartesianAMRMeshSub(MEDCouplingCartesianAMRMeshGen *father, MEDCouplingIMesh *mesh);
159   };
160
161   class MEDCouplingCartesianAMRMesh : public MEDCouplingCartesianAMRMeshGen
162   {
163   public:
164     MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
165                                                                const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
166     MEDCOUPLING_EXPORT const MEDCouplingDataForGodFather *getDataConst() const { return _data; }
167     MEDCOUPLING_EXPORT MEDCouplingDataForGodFather *getData() { return _data; }
168     MEDCOUPLING_EXPORT void setData(MEDCouplingDataForGodFather *data);
169   private:
170     MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
171                                 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
172     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
173   private:
174     MEDCouplingAutoRefCountObjectPtr<MEDCouplingDataForGodFather> _data;
175   };
176 }
177
178 #endif
179