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 *getFieldWithName(const std::string& name);
46 DataArrayDouble *at(int pos);
47 const DataArrayDouble *at(int pos) const;
49 static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse);
50 static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
51 static void SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine);
52 static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
53 static void SynchronizeGhostZoneOfOneUsingTwo(int ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac);
54 void synchronizeMyGhostZoneUsing(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const;
55 void synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const;
57 DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
58 DataArrayDoubleCollection(const DataArrayDoubleCollection& other);
59 std::size_t getHeapMemorySizeWithoutChildren() const;
60 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
61 void updateTime() const;
62 static void CheckDiscriminantNames(const std::vector<std::string>& names);
63 static bool IsConservativeNature(NatureOfField n);
64 static void CheckSameNatures(NatureOfField n1, NatureOfField n2);
65 static void CheckValidNature(NatureOfField n);
67 std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > > _arrs;
70 class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
73 static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
74 MEDCouplingGridCollection *deepCpy(const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf) const;
75 void alloc(int ghostLev);
77 void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
78 void spillNatures(const std::vector<NatureOfField>& nfs);
79 std::vector< std::pair<std::string, std::vector<std::string> > > getInfoOnComponents() const;
80 std::vector<NatureOfField> getNatures() const;
81 bool presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const;
82 const DataArrayDoubleCollection& getFieldsAt(int pos) const;
83 DataArrayDoubleCollection& getFieldsAt(int pos);
84 void copyOverlappedZoneFrom(int ghostLev, const MEDCouplingGridCollection& other);
85 static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse);
86 static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
87 void synchronizeFineEachOther(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
88 void synchronizeFineEachOtherExt(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
89 std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > findNeighbors(int ghostLev) const;
90 static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
91 void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const;
93 MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
94 MEDCouplingGridCollection(const MEDCouplingGridCollection& other, const MEDCouplingCartesianAMRMeshGen *newGf, const MEDCouplingCartesianAMRMeshGen *oldGf);
95 std::size_t getHeapMemorySizeWithoutChildren() const;
96 std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
97 void updateTime() const;
99 std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
104 class MEDCouplingDataForGodFather : public RefCountObject
106 friend class MEDCouplingCartesianAMRMesh;
108 MEDCOUPLING_EXPORT MEDCouplingCartesianAMRMesh *getMyGodFather();
109 MEDCOUPLING_EXPORT const MEDCouplingCartesianAMRMesh *getMyGodFather() const;
110 MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarse() = 0;
111 MEDCOUPLING_EXPORT virtual void synchronizeFineToCoarseBetween(int fromLev, int toLev) = 0;
112 MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFine() = 0;
113 MEDCOUPLING_EXPORT virtual void synchronizeCoarseToFineBetween(int fromLev, int toLev) = 0;
114 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZones() = 0;
115 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh) = 0;
116 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevel(int level) = 0;
117 MEDCOUPLING_EXPORT virtual void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level) = 0;
118 MEDCOUPLING_EXPORT virtual void alloc() = 0;
119 MEDCOUPLING_EXPORT virtual void dealloc() = 0;
121 MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMesh *gf);
122 void checkGodFatherFrozen() const;
124 virtual bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
125 MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF);
127 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMesh> _gf;
128 TimeLabelConstOverseer _tlc;
131 class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
134 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
135 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev);
136 MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
137 MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
138 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpy() const;
139 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpyWithoutGodFather() const;
140 MEDCOUPLING_EXPORT int getNumberOfLevels() const;
141 MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
142 MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
143 MEDCOUPLING_EXPORT DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName);
144 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
145 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
146 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
147 MEDCOUPLING_EXPORT std::string writeVTHB(const std::string& fileName) const;
149 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *projectTo(MEDCouplingCartesianAMRMesh *targetGF) const;
151 MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
152 MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(int fromLev, int toLev);
153 MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
154 MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(int fromLev, int toLev);
155 MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
156 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh);
157 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevel(int level);
158 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesAtASpecifiedLevelUsingOnlyFather(int level);
160 MEDCOUPLING_EXPORT void alloc();
161 MEDCOUPLING_EXPORT void dealloc();
162 MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMesh *gf);
164 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
165 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildrenWithNull() const;
166 MEDCOUPLING_EXPORT void updateTime() const;
168 MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMesh *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
169 MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF);
170 const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
171 void synchronizeFineToCoarseByOneLevel(int level);
172 void synchronizeCoarseToFineByOneLevel(int level);
175 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> > _levs;
176 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
177 std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
178 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;