Salome HOME
First test OK with createPatchesFromCriterion
[modules/med.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 DataArrayByte;
37   class MEDCoupling1SGTUMesh;
38   class MEDCouplingCartesianAMRMesh;
39
40   /// @cond INTERNAL
41   class MEDCouplingCartesianAMRPatch : public RefCountObject
42   {
43   public:
44     MEDCouplingCartesianAMRPatch(MEDCouplingCartesianAMRMesh *mesh, const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
45     // direct forward to _mesh
46     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
47     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
48     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
49     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
50     // end of direct forward to _mesh
51     MEDCOUPLING_EXPORT int getNumberOfOverlapedCellsForFather() const;
52     // basic set/get
53     MEDCOUPLING_EXPORT const std::vector< std::pair<int,int> >& getBLTRRange() const { return _bl_tr; }
54     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getMesh() const { return _mesh; }
55   private:
56     std::size_t getHeapMemorySizeWithoutChildren() const;
57     std::vector<const BigMemoryObject *> getDirectChildren() const;
58   private:
59     //! bottom left/top right cell range relative to \a _father
60     std::vector< std::pair<int,int> > _bl_tr;
61     std::vector<int> _factors;
62     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMesh> _mesh;
63   };
64   /// @endcond
65
66   /*!
67    * This class is the base class dedicated to AMR using Adaptative Hierarchical Overlapped image Grid.
68    * This class does \b NOT inherit from MEDCouplingMesh because this class overlaps image grid structured meshes to perform adaptative mesh refinement.
69    * But this class aggregates MEDCouplingMesh instances !
70    */
71   class MEDCouplingCartesianAMRMesh : public RefCountObject, public TimeLabel
72   {
73   public:
74     MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
75                                                                const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
76     MEDCOUPLING_EXPORT int getSpaceDimension() const;
77     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
78     MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevel() const;
79     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
80     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
81     MEDCOUPLING_EXPORT const MEDCouplingIMesh *getImageMesh() const { return _mesh; }
82     //
83     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getFather() const;
84     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getGodFather() const;
85     MEDCOUPLING_EXPORT void detachFromFather();
86     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
87     MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const DataArrayByte *criterion, const std::vector<int>& factors);
88     MEDCOUPLING_EXPORT void removePatch(int patchId);
89     MEDCOUPLING_EXPORT int getNumberOfPatches() const;
90     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRPatch *getPatch(int patchId) const;
91     //
92     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const;
93     MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshFromPatchEnvelop() const;
94   private:
95     MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
96                                 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
97     MEDCouplingCartesianAMRMesh(MEDCouplingCartesianAMRMesh *father, MEDCouplingIMesh *mesh);
98     void checkPatchId(int patchId) const;
99   protected:
100     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
101     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
102     MEDCOUPLING_EXPORT void updateTime() const;
103   private:
104     MEDCouplingCartesianAMRMesh *_father;
105     MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> _mesh;
106     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatch> > _patches;
107   };
108 }
109
110 #endif
111