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