Salome HOME
The big test of different synchronizations.
[modules/med.git] / src / MEDCoupling / MEDCouplingAMRAttribute.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 __MEDCOUPLINGAMRATTRIBUTE_HXX__
22 #define __MEDCOUPLINGAMRATTRIBUTE_HXX__
23
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingNatureOfFieldEnum"
26 #include "MEDCouplingCartesianAMRMesh.hxx"
27
28 namespace ParaMEDMEM
29 {
30   /// @cond INTERNAL
31   class DataArrayDoubleCollection : public RefCountObject, public TimeLabel
32   {
33   public:
34     static DataArrayDoubleCollection *New(const std::vector< std::pair<std::string,int> >& fieldNames);
35     DataArrayDoubleCollection *deepCpy() const;
36     void allocTuples(int nbOfTuples);
37     void dellocTuples();
38     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
39     void spillNatures(const std::vector<NatureOfField>& nfs);
40     std::vector<DataArrayDouble *> retrieveFields() const;
41     const DataArrayDouble *getFieldWithName(const std::string& name) const;
42     static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse);
43     static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
44     static void SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine);
45     static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
46     static void SynchronizeGhostZoneOfOneUsingTwo(int ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac);
47     void synchronizeMyGhostZoneUsing(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const;
48     void synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const;
49   private:
50     DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
51     DataArrayDoubleCollection(const DataArrayDoubleCollection& other);
52     std::size_t getHeapMemorySizeWithoutChildren() const;
53     std::vector<const BigMemoryObject *> getDirectChildren() const;
54     void updateTime() const;
55     static void CheckDiscriminantNames(const std::vector<std::string>& names);
56     static bool IsConservativeNature(NatureOfField n);
57     static void CheckSameNatures(NatureOfField n1, NatureOfField n2);
58     static void CheckValidNature(NatureOfField n);
59   private:
60     std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > > _arrs;
61   };
62
63   class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
64   {
65   public:
66     static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
67     MEDCouplingGridCollection *deepCpy(const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf) const;
68     void alloc(int ghostLev);
69     void dealloc();
70     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
71     void spillNatures(const std::vector<NatureOfField>& nfs);
72     bool presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const;
73     const DataArrayDoubleCollection& getFieldsAt(int pos) const;
74     static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse);
75     static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
76     void synchronizeFineEachOther(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
77     void synchronizeFineEachOtherExt(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
78     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > findNeighbors(int ghostLev) const;
79     static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
80     void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const;
81   private:
82     MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
83     MEDCouplingGridCollection(const MEDCouplingGridCollection& other, const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf);
84     std::size_t getHeapMemorySizeWithoutChildren() const;
85     std::vector<const BigMemoryObject *> getDirectChildren() const;
86     void updateTime() const;
87   private:
88     std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
89   };
90
91   /// @endcond
92
93   class MEDCouplingDataForGodFather : public RefCountObject
94   {
95     friend class MEDCouplingCartesianAMRMesh;
96   public:
97     MEDCOUPLING_EXPORT MEDCouplingCartesianAMRMesh *getMyGodFather();
98     MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarse() = 0;
99     MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarseBetween(int fromLev, int toLev) = 0;
100     MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFine() = 0;
101     MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFineBetween(int fromLev, int toLev) = 0;
102     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZones() = 0;
103     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh) = 0;
104     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevel(int level) = 0;
105     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level) = 0;
106     MEDCOUPLING_EXPORT virtual void alloc() = 0;
107     MEDCOUPLING_EXPORT virtual void dealloc() = 0;
108   protected:
109     MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf);
110     void checkGodFatherFrozen() const;
111   protected:
112     virtual bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
113     MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF);
114   protected:
115     MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMesh> _gf;
116     TimeLabelConstOverseer _tlc;
117   };
118
119   class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
120   {
121   public:
122     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
123     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev);
124     MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
125     MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
126     MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpy() const;
127     MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpyWithoutGodFather() const;
128     MEDCOUPLING_EXPORT int getNumberOfLevels() const;
129     MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
130     MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
131     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
132     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
133     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
134     //
135     MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
136     MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(int fromLev, int toLev);
137     MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
138     MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(int fromLev, int toLev);
139     MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
140     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh);
141     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevel(int level);
142     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level);
143     MEDCOUPLING_EXPORT void alloc();
144     MEDCOUPLING_EXPORT void dealloc();
145     MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
146     //
147     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
148     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
149     MEDCOUPLING_EXPORT void updateTime() const;
150   private:
151     MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
152     MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF);
153     const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
154     void synchronizeFineToCoarseByOneLevel(int level);
155     void synchronizeCoarseToFineByOneLevel(int level);
156   private:
157     int _ghost_lev;
158     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> > _levs;
159     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
160     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
161     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;
162   };
163 }
164
165 #endif