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 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;
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);
60 std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > > _arrs;
63 class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
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);
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;
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;
88 std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
93 class MEDCouplingDataForGodFather : public RefCountObject
95 friend class MEDCouplingCartesianAMRMesh;
97 MEDCOUPLING_EXPORT MEDCouplingCartesianAMRMeshGen *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 alloc() = 0;
105 MEDCOUPLING_EXPORT virtual void dealloc() = 0;
107 MEDCouplingDataForGodFather(MEDCouplingCartesianAMRMeshGen *gf);
108 void checkGodFatherFrozen() const;
110 virtual bool changeGodFather(MEDCouplingCartesianAMRMeshGen *gf);
111 MEDCouplingDataForGodFather(const MEDCouplingDataForGodFather& other, bool deepCpyGF);
113 MEDCouplingAutoRefCountObjectPtr<MEDCouplingCartesianAMRMeshGen> _gf;
114 TimeLabelConstOverseer _tlc;
117 class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
120 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
121 MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev);
122 MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
123 MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
124 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpy() const;
125 MEDCOUPLING_EXPORT MEDCouplingAMRAttribute *deepCpyWithoutGodFather() const;
126 MEDCOUPLING_EXPORT int getNumberOfLevels() const;
127 MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
128 MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
129 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
130 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
131 MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
133 MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
134 MEDCOUPLING_EXPORT void synchronizeFineToCoarseBetween(int fromLev, int toLev);
135 MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
136 MEDCOUPLING_EXPORT void synchronizeCoarseToFineBetween(int fromLev, int toLev);
137 MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
138 MEDCOUPLING_EXPORT void synchronizeAllGhostZonesOfDirectChidrenOf(const MEDCouplingCartesianAMRMeshGen *mesh);
139 MEDCOUPLING_EXPORT void alloc();
140 MEDCOUPLING_EXPORT void dealloc();
141 MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMeshGen *gf);
143 MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
144 MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
145 MEDCOUPLING_EXPORT void updateTime() const;
147 MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
148 MEDCouplingAMRAttribute(const MEDCouplingAMRAttribute& other, bool deepCpyGF);
149 const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
150 void synchronizeFineToCoarseByOneLevel(int level);
151 void synchronizeCoarseToFineByOneLevel(int level);
154 std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> > _levs;
155 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
156 std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
157 std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;