Salome HOME
1c387876045a0b2022039526eb853396be5d9794
[tools/medcoupling.git] / src / MEDCoupling / MEDCouplingAMRAttribute.hxx
1 // Copyright (C) 2007-2020  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 MEDCoupling
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     std::string getClassName() const override { return std::string("DataArrayDoubleCollection"); }
36     DataArrayDoubleCollection *deepCopy() const;
37     void allocTuples(mcIdType nbOfTuples);
38     void dellocTuples();
39     void copyFrom(const DataArrayDoubleCollection& other);
40     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
41     void spillNatures(const std::vector<NatureOfField>& nfs);
42     std::vector< std::pair<std::string, std::vector<std::string> > > getInfoOnComponents() const;
43     std::vector<NatureOfField> getNatures() const;
44     std::vector<DataArrayDouble *> retrieveFields() const;
45     const DataArrayDouble *getFieldWithName(const std::string& name) const;
46     DataArrayDouble *getFieldWithName(const std::string& name);
47     DataArrayDouble *at(mcIdType pos);
48     const DataArrayDouble *at(mcIdType pos) const;
49     mcIdType size() const;
50     static void SynchronizeFineToCoarse(mcIdType ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, mcIdType patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse);
51     static void SynchronizeCoarseToFine(mcIdType ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, mcIdType patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
52     static void SynchronizeFineEachOther(mcIdType patchId, mcIdType ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine);
53     static void SynchronizeCoarseToFineOnlyInGhostZone(mcIdType ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, mcIdType patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
54     static void SynchronizeGhostZoneOfOneUsingTwo(mcIdType ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac);
55     void synchronizeMyGhostZoneUsing(mcIdType ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const;
56     void synchronizeMyGhostZoneUsingExt(mcIdType ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const;
57   private:
58     DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
59     DataArrayDoubleCollection(const DataArrayDoubleCollection& other);
60     std::size_t getHeapMemorySizeWithoutChildren() const;
61     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
62     void updateTime() const;
63     static void CheckDiscriminantNames(const std::vector<std::string>& names);
64     static bool IsConservativeNature(NatureOfField n);
65     static void CheckSameNatures(NatureOfField n1, NatureOfField n2);
66     static void CheckValidNature(NatureOfField n);
67   private:
68     std::vector< std::pair< MCAuto<DataArrayDouble>, NatureOfField > > _arrs;
69   };
70
71   class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
72   {
73   public:
74     static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
75     std::string getClassName() const override { return std::string("MEDCouplingGridCollection"); }
76     MEDCouplingGridCollection *deepCopy(const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf) const;
77     void alloc(mcIdType ghostLev);
78     void dealloc();
79     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
80     void spillNatures(const std::vector<NatureOfField>& nfs);
81     std::vector< std::pair<std::string, std::vector<std::string> > > getInfoOnComponents() const;
82     std::vector<NatureOfField> getNatures() const;
83     bool presenceOf(const MEDCouplingCartesianAMRMeshGen *m, mcIdType& pos) const;
84     const DataArrayDoubleCollection& getFieldsAt(mcIdType pos) const;
85     DataArrayDoubleCollection& getFieldsAt(mcIdType pos);
86     void copyOverlappedZoneFrom(mcIdType ghostLev, const MEDCouplingGridCollection& other);
87     static void SynchronizeFineToCoarse(mcIdType ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse);
88     static void SynchronizeCoarseToFine(mcIdType ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
89     void synchronizeFineEachOther(mcIdType ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
90     void synchronizeFineEachOtherExt(mcIdType ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
91     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > findNeighbors(mcIdType ghostLev) const;
92     static void SynchronizeCoarseToFineOnlyInGhostZone(mcIdType ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
93     void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const;
94   private:
95     MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
96     MEDCouplingGridCollection(const MEDCouplingGridCollection& other, const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf);
97     std::size_t getHeapMemorySizeWithoutChildren() const;
98     std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
99     void updateTime() const;
100   private:
101     std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MCAuto<DataArrayDoubleCollection> > > _map_of_dadc;
102   };
103
104   /// @endcond
105
106   class MEDCouplingDataForGodFather : public RefCountObject
107   {
108     friend class MEDCouplingCartesianAMRMesh;
109   public:
110     MEDCOUPLING_EXPORT MEDCouplingCartesianAMRMesh *getMyGodFather();
111     std::string getClassName() const override { return std::string("MEDCouplingDataForGodFather"); }
112     MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getMyGodFather() const;
113     MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarse() = 0;
114     MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarseBetween(mcIdType fromLev, mcIdType toLev) = 0;
115     MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFine() = 0;
116     MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFineBetween(mcIdType fromLev, mcIdType toLev) = 0;
117     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZones() = 0;
118     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh) = 0;
119     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevel(mcIdType level) = 0;
120     MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(mcIdType level) = 0;
121     MEDCOUPLING_EXPORT virtual void alloc() = 0;
122     MEDCOUPLING_EXPORT virtual void dealloc() = 0;
123   protected:
124     MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf);
125     void checkGodFatherFrozen() const;
126   protected:
127     virtual bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
128     MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF);
129   protected:
130     MCAuto<MEDCouplingCartesianAMRMesh> _gf;
131     TimeLabelConstOverseer _tlc;
132   };
133
134   class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
135   {
136   public:
137     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, mcIdType ghostLev);
138     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, mcIdType ghostLev);
139     std::string getClassName() const override { return std::string("MEDCouplingAMRAttribute"); }
140     MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
141     MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
142     MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCopy() const;
143     MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpyWithoutGodFather() const;
144     MEDCOUPLING_EXPORT mcIdType getNumberOfLevels() const;
145     MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
146     MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
147     MEDCOUPLING_EXPORT DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName);
148     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
149     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
150     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
151     MEDCOUPLING_EXPORT std::string writeVTHB(const std::string& fileName) const;
152     //
153     MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *projectTo(MEDCouplingCartesianAMRMesh *targetGF) const;
154     //
155     MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
156     MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(mcIdType fromLev, mcIdType toLev);
157     MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
158     MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(mcIdType fromLev, mcIdType toLev);
159     MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
160     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh);
161     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevel(mcIdType level);
162     MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(mcIdType level);
163     //
164     MEDCOUPLING_EXPORT void alloc();
165     MEDCOUPLING_EXPORT void dealloc();
166     MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
167     //
168     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
169     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
170     MEDCOUPLING_EXPORT void updateTime() const;
171   private:
172     MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, mcIdType ghostLev);
173     MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF);
174     const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
175     void synchronizeFineToCoarseByOneLevel(mcIdType level);
176     void synchronizeCoarseToFineByOneLevel(mcIdType level);
177   private:
178     mcIdType _ghost_lev;
179     std::vector< MCAuto<MEDCouplingGridCollection> > _levs;
180     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
181     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
182     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;
183   };
184 }
185
186 #endif