1 | #ifndef __XIOS_CScalar__ |
---|
2 | #define __XIOS_CScalar__ |
---|
3 | |
---|
4 | /// XIOS headers /// |
---|
5 | #include "xios_spl.hpp" |
---|
6 | #include "declare_group.hpp" |
---|
7 | #include "declare_ref_func.hpp" |
---|
8 | #include "group_template.hpp" |
---|
9 | #include "array_new.hpp" |
---|
10 | #include "attribute_enum.hpp" |
---|
11 | #include "attribute_enum_impl.hpp" |
---|
12 | #include "attribute_array.hpp" |
---|
13 | #include "transformation.hpp" |
---|
14 | #include "transformation_enum.hpp" |
---|
15 | #include "transformation_path.hpp" |
---|
16 | #include "element.hpp" |
---|
17 | #include "local_connector.hpp" |
---|
18 | #include "scatterer_connector.hpp" |
---|
19 | #include "gatherer_connector.hpp" |
---|
20 | #include "distribution_type.hpp" |
---|
21 | #include "generic_algorithm_transformation.hpp" |
---|
22 | |
---|
23 | |
---|
24 | namespace xios |
---|
25 | { |
---|
26 | /// ////////////////////// Déclarations ////////////////////// /// |
---|
27 | |
---|
28 | class CScalarGroup; |
---|
29 | class CScalarAttributes; |
---|
30 | class CScalar; |
---|
31 | ///-------------------------------------------------------------- |
---|
32 | |
---|
33 | // Declare/Define CVarAttribute |
---|
34 | BEGIN_DECLARE_ATTRIBUTE_MAP(CScalar) |
---|
35 | #include "scalar_attribute.conf" |
---|
36 | END_DECLARE_ATTRIBUTE_MAP(CScalar) |
---|
37 | |
---|
38 | ///-------------------------------------------------------------- |
---|
39 | |
---|
40 | class CScalar: public CObjectTemplate<CScalar> |
---|
41 | , public CScalarAttributes |
---|
42 | { |
---|
43 | friend class CScalarGroup; |
---|
44 | |
---|
45 | /// typedef /// |
---|
46 | typedef CObjectTemplate<CScalar> SuperClass; |
---|
47 | typedef CScalarAttributes SuperClassAttribute; |
---|
48 | |
---|
49 | public: |
---|
50 | enum EEventId |
---|
51 | { |
---|
52 | EVENT_ID_SCALAR_DISTRIBUTION, |
---|
53 | EVENT_ID_SEND_DISTRIBUTED_ATTRIBUTE, |
---|
54 | } ; |
---|
55 | static bool dispatchEvent(CEventServer& event); |
---|
56 | |
---|
57 | |
---|
58 | public : |
---|
59 | |
---|
60 | typedef CScalarAttributes RelAttributes; |
---|
61 | typedef CScalarGroup RelGroup; |
---|
62 | |
---|
63 | /// Constructeurs /// |
---|
64 | CScalar(void); |
---|
65 | explicit CScalar(const StdString & id); |
---|
66 | CScalar(const CScalar & var); // Not implemented yet. |
---|
67 | CScalar(const CScalar * const var); // Not implemented yet. |
---|
68 | |
---|
69 | /// Destructeur /// |
---|
70 | virtual ~CScalar(void); |
---|
71 | |
---|
72 | public : |
---|
73 | /// Accesseurs statiques /// |
---|
74 | static StdString GetName(void); |
---|
75 | static StdString GetDefName(void); |
---|
76 | static ENodeType GetType(void); |
---|
77 | |
---|
78 | public: |
---|
79 | static CScalar* createScalar(); |
---|
80 | |
---|
81 | public: |
---|
82 | void checkAttributes(void); |
---|
83 | bool checkAttributes_done_ = false ; |
---|
84 | |
---|
85 | void addRelFile(const StdString& filename); |
---|
86 | bool IsWritten(const StdString& filename) const; |
---|
87 | virtual void parse(xml::CXMLNode & node); |
---|
88 | |
---|
89 | public: |
---|
90 | void sendScalarToCouplerOut(CContextClient* client, const string& fieldId, int posInGrid) ; |
---|
91 | private: |
---|
92 | std::set<CContextClient*> sendScalarToCouplerOut_done_ ; |
---|
93 | |
---|
94 | public: |
---|
95 | void makeAliasForCoupling(const string& fieldId, int posInGrid) ; |
---|
96 | string getCouplingAlias(const string& fieldId, int posInGrid) ; |
---|
97 | |
---|
98 | //////////////////////////////// |
---|
99 | //// TRANSFORMATIONS //// |
---|
100 | //////////////////////////////// |
---|
101 | public: |
---|
102 | typedef CTransformation<CScalar>::TransformationMapTypes TransMapTypes; |
---|
103 | private: |
---|
104 | static bool initializeTransformationMap(std::map<StdString, ETranformationType>& m); |
---|
105 | static std::map<StdString, ETranformationType> transformationMapList_; |
---|
106 | static bool dummyTransformationMapList_; TransMapTypes transformationMap_; |
---|
107 | void setTransformations(const TransMapTypes&); |
---|
108 | |
---|
109 | public: |
---|
110 | bool hasTransformation(); |
---|
111 | TransMapTypes getAllTransformations(); |
---|
112 | void duplicateTransformation(CScalar*); |
---|
113 | CTransformation<CScalar>* addTransformation(ETranformationType transType, const StdString& id=""); |
---|
114 | |
---|
115 | void solveInheritanceTransformation_old(); |
---|
116 | void solveInheritanceTransformation(); |
---|
117 | private: |
---|
118 | bool solveInheritanceTransformation_done_= false ; |
---|
119 | private: |
---|
120 | CGenericAlgorithmTransformation* transformationAlgorithm_ = nullptr ; |
---|
121 | public: |
---|
122 | void setTransformationAlgorithm(CGenericAlgorithmTransformation* transformationAlgorithm) { transformationAlgorithm_=transformationAlgorithm ;} |
---|
123 | CGenericAlgorithmTransformation* getTransformationAlgorithm(void) { return transformationAlgorithm_ ;} |
---|
124 | private: |
---|
125 | CTransformationPaths transformationPaths_ ; |
---|
126 | public: |
---|
127 | CTransformationPaths getTransformationPaths(void) {return transformationPaths_;} |
---|
128 | void setTransformationPaths(const CTransformationPaths& transformationPaths) { transformationPaths_=transformationPaths ;} |
---|
129 | //////////////////////////////// |
---|
130 | //////////////////////////////// |
---|
131 | |
---|
132 | bool isEqual(CScalar* scalar); |
---|
133 | private: |
---|
134 | /** Clients that have to send a scalar. There can be multiple clients in case of secondary server, otherwise only one client. */ |
---|
135 | std::list<CContextClient*> clients; |
---|
136 | std::set<CContextClient*> clientsSet; |
---|
137 | public: |
---|
138 | void setContextClient(CContextClient* contextClient) ; |
---|
139 | |
---|
140 | private: |
---|
141 | std::set<StdString> relFiles; |
---|
142 | |
---|
143 | private: |
---|
144 | /** define if the scalar is completed or not ie all attributes have been received before in case |
---|
145 | of grid reading from file or coupling */ |
---|
146 | bool isCompleted_=true ; |
---|
147 | public: |
---|
148 | /*! |
---|
149 | \brief Check if a scalar is completed |
---|
150 | Before make any scalar processing, we must be sure that all scalar informations have |
---|
151 | been sent, for exemple when reading a grid in a file or when grid elements are sent by an |
---|
152 | other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed |
---|
153 | \return true if scalar and scalar reference are completed |
---|
154 | */ |
---|
155 | bool isCompleted(void) |
---|
156 | { |
---|
157 | if (hasDirectScalarReference()) if (!getDirectScalarReference()->isCompleted()) return false; |
---|
158 | else return isCompleted_ ; |
---|
159 | } |
---|
160 | void setCompleted(void) { isCompleted_=true ; } |
---|
161 | void unsetCompleted(void) { isCompleted_=false ; } |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
166 | // this part is related to distribution, element definition, views and connectors // |
---|
167 | ////////////////////////////////////////////////////////////////////////////////////// |
---|
168 | private: |
---|
169 | CLocalElement* localElement_ = nullptr ; |
---|
170 | void initializeLocalElement(void) ; |
---|
171 | |
---|
172 | public: |
---|
173 | CLocalElement* getLocalElement(void) { if (localElement_==nullptr) initializeLocalElement() ; return localElement_ ; } |
---|
174 | CLocalView* getLocalView(CElementView::type type) { return getLocalElement()->getView(type) ;} |
---|
175 | |
---|
176 | private: |
---|
177 | void addFullView(void) ; |
---|
178 | void addWorkflowView(void) ; |
---|
179 | void addModelView(void) ; |
---|
180 | |
---|
181 | private: |
---|
182 | CLocalConnector* modelToWorkflowConnector_ ; |
---|
183 | void computeModelToWorkflowConnector(void) ; |
---|
184 | public: |
---|
185 | CLocalConnector* getModelToWorkflowConnector(void) { if (modelToWorkflowConnector_==nullptr) computeModelToWorkflowConnector() ; return modelToWorkflowConnector_ ;} |
---|
186 | |
---|
187 | public: |
---|
188 | void computeRemoteElement(CContextClient* client, EDistributionType) ; |
---|
189 | void distributeToServer(CContextClient* client, std::map<int, CArray<size_t,1>>& globalIndex, CScattererConnector* &scattererConnector, |
---|
190 | const string& scalarId="") ; |
---|
191 | |
---|
192 | static void recvScalarDistribution(CEventServer& event) ; |
---|
193 | void receivedScalarDistribution(CEventServer& event, int phasis) ; |
---|
194 | void setServerMask(CArray<bool,1>& serverMask, CContextClient* client) ; |
---|
195 | void sendDistributedAttributes(CContextClient* client, CScattererConnector& scattererConnector, const string& scalarId) ; |
---|
196 | static void recvDistributedAttributes(CEventServer& event) ; |
---|
197 | void recvDistributedAttributes(CEventServer& event, const string& type) ; |
---|
198 | |
---|
199 | private: |
---|
200 | map<CContextClient*, CDistributedElement*> remoteElement_ ; |
---|
201 | public: |
---|
202 | CDistributedElement* getRemoteElement(CContextClient* client) {return remoteElement_[client] ;} |
---|
203 | private: |
---|
204 | map<CContextClient*, CScattererConnector*> clientToServerConnector_ ; |
---|
205 | public: |
---|
206 | CScattererConnector* getClientToServerConnector(CContextClient* client) { return clientToServerConnector_[client] ;} |
---|
207 | |
---|
208 | private: |
---|
209 | CGathererConnector* gathererConnector_ ; |
---|
210 | public: |
---|
211 | CGathererConnector* getGathererConnector(void) { return gathererConnector_ ;} |
---|
212 | private: |
---|
213 | CGathererConnector* serverFromClientConnector_ ; |
---|
214 | CDistributedElement* elementFrom_ ; |
---|
215 | public: |
---|
216 | CGathererConnector* getServerFromClientConnector(void) { return serverFromClientConnector_ ;} |
---|
217 | |
---|
218 | private: |
---|
219 | CScattererConnector* serverToClientConnector_ = nullptr ; |
---|
220 | public: |
---|
221 | CScattererConnector* getServerToClientConnector(void) { return serverToClientConnector_ ;} |
---|
222 | |
---|
223 | private: |
---|
224 | map<CContextClient*,CGathererConnector*> clientFromServerConnector_ ; |
---|
225 | public: |
---|
226 | CGathererConnector* getClientFromServerConnector(CContextClient* client) { return clientFromServerConnector_[client] ;} |
---|
227 | |
---|
228 | private: |
---|
229 | DECLARE_REF_FUNC(Scalar,scalar) |
---|
230 | |
---|
231 | }; // class CVar |
---|
232 | ///-------------------------------------------------------------- |
---|
233 | |
---|
234 | // Declare/Define CScalarGroup and CScalarDefinition |
---|
235 | DECLARE_GROUP(CScalar); |
---|
236 | } // namespace xios |
---|
237 | |
---|
238 | #endif // __XIOS_CScalar__ |
---|