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 __MEDCOUPLINGAMRATTRIBUTE_HXX__
22 #define __MEDCOUPLINGAMRATTRIBUTE_HXX__
24 #include "MEDCoupling.hxx"
25 #include "MEDCouplingNatureOfFieldEnum"
26 #include "MEDCouplingCartesianAMRMesh.hxx"
31 class DataArrayDoubleCollection : public RefCountObject, public TimeLabel
34 static DataArrayDoubleCollection *New(const std::vector< std::pair<std::string,int> >& fieldNames);
35 DataArrayDoubleCollection *deepCpy() const;
36 void allocTuples(int nbOfTuples);
38 void copyFrom(const DataArrayDoubleCollection& other);
39 void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
40 void spillNatures(const std::vector<NatureOfField>& nfs);
41 std::vector< std::pair<std::string, std::vector<std::string> > > getInfoOnComponents() const;
42 std::vector<NatureOfField> getNatures() const;
43 std::vector<DataArrayDouble *> retrieveFields() const;
44 const DataArrayDouble *getFieldWithName(const std::string& name) const;
45 DataArrayDouble *at(int pos);
46 const DataArrayDouble *at(int pos) const;
48 static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse);
49 static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
50 static void SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine);
51 static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
52 static void SynchronizeGhostZoneOfOneUsingTwo(int ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac);
53 void synchronizeMyGhostZoneUsing(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const;
54 void synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const;
56 DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
57 DataArrayDoubleCollection(const DataArrayDoubleCollection& other);
58 std::size_t getHeapMemorySizeWithoutChildren() const;
59 std::vector<const BigMemoryObject *> getDirectChildren() const;
60 void updateTime() const;
61 static void CheckDiscriminantNames(const std::vector<std::string>& names);
62 static bool IsConservativeNature(NatureOfField n);
63 static void CheckSameNatures(NatureOfField n1, NatureOfField n2);
64 static void CheckValidNature(NatureOfField n);
66 std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > > _arrs;
69 class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
72 static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
73 MEDCouplingGridCollection *deepCpy(const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf) const;
74 void alloc(int ghostLev);
76 void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
77 void spillNatures(const std::vector<NatureOfField>& nfs);
78 std::vector< std::pair<std::string, std::vector<std::string> > > getInfoOnComponents() const;
79 std::vector<NatureOfField> getNatures() const;
80 bool presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const;
81 const DataArrayDoubleCollection& getFieldsAt(int pos) const;
82 DataArrayDoubleCollection& getFieldsAt(int pos);
83 void copyOverlappedZoneFrom(int ghostLev, const MEDCouplingGridCollection& other);
84 static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse);
85 static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
86 void synchronizeFineEachOther(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
87 void synchronizeFineEachOtherExt(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
88 std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > findNeighbors(int ghostLev) const;
89 static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
90 void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const;
92 MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
93 MEDCouplingGridCollection(const MEDCouplingGridCollection& other, const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf);
94 std::size_t getHeapMemorySizeWithoutChildren() const;
95 std::vector<const BigMemoryObject *> getDirectChildren() const;
96 void updateTime() const;
98 std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
103 class MEDCouplingDataForGodFather : public RefCountObject
105 friend class MEDCouplingCartesianAMRMesh;
107 MEDCOUPLING_EXPORT MEDCouplingCartesianAMRMesh *getMyGodFather();
108 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getMyGodFather() const;
109 MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarse() = 0;
110 MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarseBetween(int fromLev, int toLev) = 0;
111 MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFine() = 0;
112 MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFineBetween(int fromLev, int toLev) = 0;
113 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZones() = 0;
114 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh) = 0;
115 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevel(int level) = 0;
116 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level) = 0;
117 MEDCOUPLING_EXPORT virtual void alloc() = 0;
118 MEDCOUPLING_EXPORT virtual void dealloc() = 0;
120 MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf);
121 void checkGodFatherFrozen() const;
123 virtual bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
124 MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF);
126 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMesh> _gf;
127 TimeLabelConstOverseer _tlc;
130 class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
133 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
134 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev);
135 MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
136 MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
137 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpy() const;
138 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpyWithoutGodFather() const;
139 MEDCOUPLING_EXPORT int getNumberOfLevels() const;
140 MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
141 MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
142 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
143 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
144 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
146 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *projectTo(MEDCouplingCartesianAMRMesh *targetGF) const;
148 MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
149 MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(int fromLev, int toLev);
150 MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
151 MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(int fromLev, int toLev);
152 MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
153 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh);
154 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevel(int level);
155 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level);
157 MEDCOUPLING_EXPORT void alloc();
158 MEDCOUPLING_EXPORT void dealloc();
159 MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
161 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
162 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
163 MEDCOUPLING_EXPORT void updateTime() const;
165 MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
166 MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF);
167 const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
168 void synchronizeFineToCoarseByOneLevel(int level);
169 void synchronizeCoarseToFineByOneLevel(int level);
172 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> > _levs;
173 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
174 std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
175 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;