1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Anthony Geay
21 #ifndef __MEDCOUPLINGCARTESIANAMRMESH_HXX__
22 #define __MEDCOUPLINGCARTESIANAMRMESH_HXX__
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingTimeLabel.hxx"
26 #include "MEDCouplingRefCountObject.hxx"
27 #include "MEDCouplingAutoRefCountObjectPtr.hxx"
29 #include "BoxSplittingOptions.hxx"
30 #include "InterpKernelException.hxx"
34 class MEDCouplingIMesh;
35 class MEDCouplingUMesh;
38 class DataArrayDouble;
39 class MEDCoupling1SGTUMesh;
40 class MEDCouplingCartesianAMRMesh;
41 class MEDCouplingCartesianAMRMeshGen;
46 * This class does not inherit from TimeLabel so only const method should exist.
48 class MEDCouplingCartesianAMRPatchGen : public RefCountObject
51 MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
52 MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
53 MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
54 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getMesh() const { return _mesh; }
56 MEDCouplingCartesianAMRPatchGen(MEDCouplingCartesianAMRMeshGen *mesh);
57 const MEDCouplingCartesianAMRMeshGen *getMeshSafe() const;
58 MEDCouplingCartesianAMRMeshGen *getMeshSafe();
60 std::vector<const BigMemoryObject *> getDirectChildren() const;
62 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMeshGen> _mesh;
66 * This class does not inherit from TimeLabel so only const method should exist.
68 class MEDCouplingCartesianAMRPatch : public MEDCouplingCartesianAMRPatchGen
71 MEDCouplingCartesianAMRPatch(MEDCouplingCartesianAMRMeshGen *mesh, const std::vector< std::pair<int,int> >& bottomLeftTopRight);
72 // direct forward to _mesh
73 MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
74 // end of direct forward to _mesh
75 MEDCOUPLING_EXPORT int getNumberOfOverlapedCellsForFather() const;
76 MEDCOUPLING_EXPORT bool isInMyNeighborhood(const MEDCouplingCartesianAMRPatch *other, int ghostLev) const;
78 MEDCOUPLING_EXPORT const std::vector< std::pair<int,int> >& getBLTRRange() const { return _bl_tr; }
80 std::size_t getHeapMemorySizeWithoutChildren() const;
82 //! bottom left/top right cell range relative to \a _father
83 std::vector< std::pair<int,int> > _bl_tr;
87 * This class does not inherit from TimeLabel so only const method should exist.
89 class MEDCouplingCartesianAMRPatchGF : public MEDCouplingCartesianAMRPatchGen
92 MEDCouplingCartesianAMRPatchGF(MEDCouplingCartesianAMRMesh *mesh);
94 std::size_t getHeapMemorySizeWithoutChildren() const;
97 class MEDCouplingDataForGodFather : public RefCountObject
99 friend class MEDCouplingCartesianAMRMesh;
101 MEDCOUPLING_EXPORT virtual void alloc(int ghostLev) = 0;
102 MEDCOUPLING_EXPORT virtual void dealloc() = 0;
104 MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf);
105 void checkGodFatherFrozen() const;
107 virtual bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
109 MEDCouplingCartesianAMRMesh *_gf;
110 TimeLabelConstOverseer _tlc;
115 * This class is the base class dedicated to AMR using Adaptative Hierarchical Overlapped image Grid.
116 * This class does \b NOT inherit from MEDCouplingMesh because this class overlaps image grid structured meshes to perform adaptative mesh refinement.
117 * But this class aggregates MEDCouplingMesh instances !
119 class MEDCouplingCartesianAMRMeshGen : public RefCountObject, public TimeLabel
122 MEDCOUPLING_EXPORT int getSpaceDimension() const;
123 MEDCOUPLING_EXPORT const std::vector<int>& getFactors() const { return _factors; }
124 MEDCOUPLING_EXPORT void setFactors(const std::vector<int>& newFactors);
125 MEDCOUPLING_EXPORT int getMaxNumberOfLevelsRelativeToThis() const;
126 MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevel() const;
127 MEDCOUPLING_EXPORT int getNumberOfCellsAtCurrentLevelGhost(int ghostLev) const;
128 MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithOverlap() const;
129 MEDCOUPLING_EXPORT int getNumberOfCellsRecursiveWithoutOverlap() const;
130 MEDCOUPLING_EXPORT const MEDCouplingIMesh *getImageMesh() const { return _mesh; }
132 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getFather() const;
133 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMeshGen *getGodFather() const;
134 MEDCOUPLING_EXPORT int getAbsoluteLevel() const;
135 MEDCOUPLING_EXPORT std::vector<MEDCouplingCartesianAMRPatchGen *> retrieveGridsAt(int absoluteLev) const;
136 MEDCOUPLING_EXPORT void detachFromFather();
137 MEDCOUPLING_EXPORT void addPatch(const std::vector< std::pair<int,int> >& bottomLeftTopRight, const std::vector<int>& factors);
138 MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const std::vector<bool>& criterion, const std::vector<int>& factors);
139 MEDCOUPLING_EXPORT void createPatchesFromCriterion(const INTERP_KERNEL::BoxSplittingOptions& bso, const DataArrayByte *criterion, const std::vector<int>& factors);
140 MEDCOUPLING_EXPORT void removeAllPatches();
141 MEDCOUPLING_EXPORT void removePatch(int patchId);
142 MEDCOUPLING_EXPORT int getNumberOfPatches() const;
143 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRPatch *getPatch(int patchId) const;
144 MEDCOUPLING_EXPORT bool isPatchInNeighborhoodOf(int patchId1, int patchId2, int ghostLev) const;
145 MEDCOUPLING_EXPORT DataArrayDouble *createCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis) const;
146 MEDCOUPLING_EXPORT void fillCellFieldOnPatch(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch) const;
147 MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhost(int patchId, const DataArrayDouble *cellFieldOnThis, DataArrayDouble *cellFieldOnPatch, int ghostLev) const;
148 MEDCOUPLING_EXPORT void fillCellFieldOnPatchGhostAdv(int patchId, const DataArrayDouble *cellFieldOnThis, int ghostLev, const std::vector<const DataArrayDouble *>& arrsOnPatches) const;
149 MEDCOUPLING_EXPORT void fillCellFieldOnPatchOnlyGhostAdv(int patchId, int ghostLev, const std::vector<const DataArrayDouble *>& arrsOnPatches) const;
150 MEDCOUPLING_EXPORT void fillCellFieldComingFromPatch(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis) const;
151 MEDCOUPLING_EXPORT void fillCellFieldComingFromPatchGhost(int patchId, const DataArrayDouble *cellFieldOnPatch, DataArrayDouble *cellFieldOnThis, int ghostLev) const;
152 MEDCOUPLING_EXPORT DataArrayInt *findPatchesInTheNeighborhoodOf(int patchId, int ghostLev) const;
154 MEDCOUPLING_EXPORT MEDCouplingUMesh *buildUnstructured() const;
155 MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshFromPatchEnvelop() const;
156 MEDCOUPLING_EXPORT MEDCoupling1SGTUMesh *buildMeshOfDirectChildrenOnly() const;
158 MEDCouplingCartesianAMRMeshGen(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
159 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
160 MEDCouplingCartesianAMRMeshGen(MEDCouplingCartesianAMRMeshGen *father, MEDCouplingIMesh *mesh);
161 void checkPatchId(int patchId) const;
162 void checkFactorsAndIfNotSetAssign(const std::vector<int>& factors);
163 void retrieveGridsAtInternal(int lev, std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatchGen> >& grids) const;
164 static void ApplyFactorsOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, const std::vector<int>& factors);
165 static void ApplyGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
166 static void ApplyAllGhostOnCompactFrmt(std::vector< std::pair<int,int> >& partBeforeFact, int ghostSize);
168 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
169 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
170 MEDCOUPLING_EXPORT void updateTime() const;
172 MEDCouplingCartesianAMRMeshGen *_father;
173 MEDCouplingAutoRefCountObjectPtr<MEDCouplingIMesh> _mesh;
174 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRPatch> > _patches;
175 std::vector<int> _factors;
178 class MEDCouplingCartesianAMRMeshSub : public MEDCouplingCartesianAMRMeshGen
181 MEDCouplingCartesianAMRMeshSub(MEDCouplingCartesianAMRMeshGen *father, MEDCouplingIMesh *mesh);
184 class MEDCouplingCartesianAMRMesh : public MEDCouplingCartesianAMRMeshGen
187 MEDCOUPLING_EXPORT static MEDCouplingCartesianAMRMesh *New(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
188 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
189 MEDCOUPLING_EXPORT const MEDCouplingDataForGodFather *getDataConst() const { return _data; }
190 MEDCOUPLING_EXPORT MEDCouplingDataForGodFather *getData() { return _data; }
191 MEDCOUPLING_EXPORT void setData(MEDCouplingDataForGodFather *data);
192 MEDCOUPLING_EXPORT void allocData(int ghostLev) const;
193 MEDCOUPLING_EXPORT void deallocData() const;
195 MEDCouplingCartesianAMRMesh(const std::string& meshName, int spaceDim, const int *nodeStrctStart, const int *nodeStrctStop,
196 const double *originStart, const double *originStop, const double *dxyzStart, const double *dxyzStop);
197 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
198 void checkData() const;
199 ~MEDCouplingCartesianAMRMesh();
201 mutable MEDCouplingAutoRefCountObjectPtr<MEDCouplingDataForGodFather> _data;