Salome HOME
deb5aba72af6c32d16bf4dcd53f0b12bb9c11fb4
[tools/medcoupling.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     void allocTuples(int nbOfTuples);
36     void dellocTuples();
37     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
38     void spillNatures(const std::vector<NatureOfField>& nfs);
39     std::vector<DataArrayDouble *> retrieveFields() const;
40     const DataArrayDouble *getFieldWithName(const std::string& name) const;
41     static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *fine, DataArrayDoubleCollection *coarse);
42     static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
43     static void SynchronizeFineEachOther(int patchId, int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, const std::vector<const MEDCouplingCartesianAMRMeshGen *>& children, const std::vector<DataArrayDoubleCollection *>& fieldsOnFine);
44     static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingCartesianAMRMeshGen *fatherOfFineMesh, int patchId, const DataArrayDoubleCollection *coarse, DataArrayDoubleCollection *fine);
45     static void SynchronizeGhostZoneOfOneUsingTwo(int ghostLev, const MEDCouplingCartesianAMRPatch *p1, const DataArrayDoubleCollection *p1dac, const MEDCouplingCartesianAMRPatch *p2, const DataArrayDoubleCollection *p2dac);
46     void synchronizeMyGhostZoneUsing(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp, const MEDCouplingCartesianAMRMeshGen *father) const;
47     void synchronizeMyGhostZoneUsingExt(int ghostLev, const DataArrayDoubleCollection& other, const MEDCouplingCartesianAMRPatch *thisp, const MEDCouplingCartesianAMRPatch *otherp) const;
48   private:
49     DataArrayDoubleCollection(const std::vector< std::pair<std::string,int> >& fieldNames);
50     std::size_t getHeapMemorySizeWithoutChildren() const;
51     std::vector<const BigMemoryObject *> getDirectChildren() const;
52     void updateTime() const;
53     static void CheckDiscriminantNames(const std::vector<std::string>& names);
54     static bool IsConservativeNature(NatureOfField n);
55     static void CheckSameNatures(NatureOfField n1, NatureOfField n2);
56     static void CheckValidNature(NatureOfField n);
57   private:
58     std::vector< std::pair< MEDCouplingAutoRefCountObjectPtr<DataArrayDouble>, NatureOfField > > _arrs;
59   };
60
61   class MEDCouplingGridCollection : public RefCountObject, public TimeLabel
62   {
63   public:
64     static MEDCouplingGridCollection *New(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
65     void alloc(int ghostLev);
66     void dealloc();
67     void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
68     void spillNatures(const std::vector<NatureOfField>& nfs);
69     bool presenceOf(const MEDCouplingCartesianAMRMeshGen *m, int& pos) const;
70     const DataArrayDoubleCollection& getFieldsAt(int pos) const;
71     static void SynchronizeFineToCoarse(int ghostLev, const MEDCouplingGridCollection *fine, const MEDCouplingGridCollection *coarse);
72     static void SynchronizeCoarseToFine(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
73     void synchronizeFineEachOther(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
74     void synchronizeFineEachOtherExt(int ghostLev, const std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> >& ps) const;
75     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > findNeighbors(int ghostLev) const;
76     static void SynchronizeCoarseToFineOnlyInGhostZone(int ghostLev, const MEDCouplingGridCollection *coarse, const MEDCouplingGridCollection *fine);
77     void fillIfInTheProgenyOf(const std::string& fieldName, const MEDCouplingCartesianAMRMeshGen *head, std::vector<const DataArrayDouble *>& recurseArrs) const;
78   private:
79     MEDCouplingGridCollection(const std::vector<const MEDCouplingCartesianAMRMeshGen *>& ms, const std::vector< std::pair<std::string,int> >& fieldNames);
80     std::size_t getHeapMemorySizeWithoutChildren() const;
81     std::vector<const BigMemoryObject *> getDirectChildren() const;
82     void updateTime() const;
83   private:
84     std::vector< std::pair<const MEDCouplingCartesianAMRMeshGen *,MEDCouplingAutoRefCountObjectPtr<DataArrayDoubleCollection> > > _map_of_dadc;
85   };
86
87   /// @endcond
88
89   class MEDCouplingAMRAttribute : public MEDCouplingDataForGodFather, public TimeLabel
90   {
91   public:
92     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
93     MEDCOUPLING_EXPORT static MEDCouplingAMRAttribute *New(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string, std::vector<std::string> > >& fieldNames, int ghostLev);
94     MEDCOUPLING_EXPORT void spillInfoOnComponents(const std::vector< std::vector<std::string> >& compNames);
95     MEDCOUPLING_EXPORT void spillNatures(const std::vector<NatureOfField>& nfs);
96     MEDCOUPLING_EXPORT std::vector<DataArrayDouble *> retrieveFieldsOn(MEDCouplingCartesianAMRMeshGen *mesh) const;
97     MEDCOUPLING_EXPORT const DataArrayDouble *getFieldOn(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
98     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnRecurseWithoutOverlapWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
99     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
100     MEDCOUPLING_EXPORT MEDCouplingFieldDouble *buildCellFieldOnWithoutGhost(MEDCouplingCartesianAMRMeshGen *mesh, const std::string& fieldName) const;
101     //
102     MEDCOUPLING_EXPORT void synchronizeFineToCoarse();
103     MEDCOUPLING_EXPORT void synchronizeCoarseToFine();
104     MEDCOUPLING_EXPORT void synchronizeAllGhostZones();
105     MEDCOUPLING_EXPORT void alloc();
106     MEDCOUPLING_EXPORT void dealloc();
107     MEDCOUPLING_EXPORT bool changeGodFather(MEDCouplingCartesianAMRMeshGen *gf);
108     //
109     MEDCOUPLING_EXPORT std::size_t getHeapMemorySizeWithoutChildren() const;
110     MEDCOUPLING_EXPORT std::vector<const BigMemoryObject *> getDirectChildren() const;
111     MEDCOUPLING_EXPORT void updateTime() const;
112   private:
113     MEDCouplingAMRAttribute(MEDCouplingCartesianAMRMeshGen *gf, const std::vector< std::pair<std::string,int> >& fieldNames, int ghostLev);
114     const DataArrayDoubleCollection& findCollectionAttachedTo(const MEDCouplingCartesianAMRMeshGen *m) const;
115   private:
116     int _ghost_lev;
117     std::vector< MEDCouplingAutoRefCountObjectPtr<MEDCouplingGridCollection> > _levs;
118     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _neighbors;
119     std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > _mixed_lev_neighbors;
120     std::vector< std::vector< std::pair<const MEDCouplingCartesianAMRPatch *,const MEDCouplingCartesianAMRPatch *> > > _cross_lev_neighbors;
121   };
122 }
123
124 #endif