Salome HOME
557b1c4a72e8c59f7c145704b01e031bf3fd658b
[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
42   /// @cond INTERNAL
43   class MEDCouplingCartesianAMRPatch : public RefCountObject
44   {
45   public:
46     MEDCouplingCartesianAMRPatch(MEDCouplingCartesianAMRMesh *mesh, const std::vector< std::pair<int,int> >& bottomLeftTopRight);
47     // direct forward to _mesh
48     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
49     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
50     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
51     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
52     // end of direct forward to _mesh
53     MEDCOUPLING_EXPORT int getNumberOfOverlapedCellsForFather() const;
54     MEDCOUPLING_EXPORT bool isInMyNeighborhood(const MEDCouplingCartesianAMRPatch *other, int ghostLev) const;
55     // basic set/get
56     MEDCOUPLING_EXPORT const std::vector< std::pair<int,int> >& getBLTRRange() const { return _bl_tr; }
57     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getMesh() const { return _mesh; }
58   private:
59     std::size_t getHeapMemorySizeWithoutChildren() const;
60     std::vector<const BigMemoryObject *> getDirectChildren() const;
61   private:
62     //! bottom left/top right cell range relative to \a _father
63     std::vector< std::pair<int,int> > _bl_tr;
64     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMesh> _mesh;
65   };
66   /// @endcond
67
68   /*!
69    * This class is the base class dedicated to AMR using Adaptative Hierarchical Overlapped image Grid.
70    * This class does \b NOT inherit from MEDCouplingMesh because this class overlaps image grid structured meshes to perform adaptative mesh refinement.
71    * But this class aggregates MEDCouplingMesh instances !
72    */
73   class MEDCouplingCartesianAMRMesh : public RefCountObject, public TimeLabel
74   {
75   public:
76     MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
77                                                                const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
78     MEDCOUPLING_EXPORT int getSpaceDimension() const;
79     MEDCOUPLING_EXPORT const std::vector<int>& getFactors() const { return _factors; }
80     MEDCOUPLING_EXPORT void setFactors(const std::vector<int>& newFactors);
81     MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
82     MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevel() const;
83     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
84     MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
85     MEDCOUPLING_EXPORT const MEDCouplingIMesh *getImageMesh() const { return _mesh; }
86     //
87     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getFather() const;
88     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getGodFather() const;
89     MEDCOUPLING_EXPORT void detachFromFather();
90     MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
91     MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const std::vector<bool>& criterion, const std::vector<int>& factors);
92     MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const DataArrayByte *criterion, const std::vector<int>& factors);
93     MEDCOUPLING_EXPORT void removeAllPatches();
94     MEDCOUPLING_EXPORT void removePatch(int patchId);
95     MEDCOUPLING_EXPORT int getNumberOfPatches() const;
96     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRPatch *getPatch(int patchId) const;
97     MEDCOUPLING_EXPORT bool isPatchInNeighborhoodOf(int patchId1, int patchId2, int ghostLev) const;
98     MEDCOUPLING_EXPORT DataArrayDouble *createCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis) const;
99     MEDCOUPLING_EXPORT void fillCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch) const;
100     MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhost(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch, int ghostLev) const;
101     MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhostAdv(int patchId, const DataArrayDouble *cellFieldOnThis, int ghostLev, const std::vector<const DataArrayDouble *>& arrsOnPatches) const;
102     MEDCOUPLING_EXPORT void fillCellFieldComingFromPatch(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis) const;
103     MEDCOUPLING_EXPORT void fillCellFieldComingFromPatchGhost(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis, int ghostLev) const;
104     MEDCOUPLING_EXPORT DataArrayInt *findPatchesInTheNeighborhoodOf(int patchId, int ghostLev) const;
105     //
106     MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const;
107     MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshFromPatchEnvelop() const;
108     MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshOfDirectChildrenOnly() const;
109   private:
110     MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
111                                 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
112     MEDCouplingCartesianAMRMesh(MEDCouplingCartesianAMRMesh *father, MEDCouplingIMesh *mesh);
113     void checkPatchId(int patchId) const;
114     void checkFactorsAndIfNotSetAssign(const std::vector<int>& factors);
115     static void ApplyFactorsOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, const std::vector<int>& factors);
116     static void ApplyGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
117     static void ApplyAllGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
118   protected:
119     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
120     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
121     MEDCOUPLING_EXPORT void updateTime() const;
122   private:
123     MEDCouplingCartesianAMRMesh *_father;
124     MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> _mesh;
125     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatch> > _patches;
126     std::vector<int> _factors;
127   };
128 }
129
130 #endif
131