source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/scalar.cpp @ 1870

Last change on this file since 1870 was 1870, checked in by ymipsl, 4 years ago

Some update on XIOS_COUPLING branch...

YM

File size: 7.4 KB
Line 
1#include "scalar.hpp"
2
3#include "attribute_template.hpp"
4#include "object_template.hpp"
5#include "group_template.hpp"
6#include "object_factory.hpp"
7#include "xios_spl.hpp"
8#include "type.hpp"
9
10namespace xios {
11
12   /// ////////////////////// Définitions ////////////////////// ///
13
14   CScalar::CScalar(void)
15      : CObjectTemplate<CScalar>()
16      , CScalarAttributes()
17      , relFiles()
18   { /* Ne rien faire de plus */ }
19
20   CScalar::CScalar(const StdString & id)
21      : CObjectTemplate<CScalar>(id)
22      , CScalarAttributes()
23      , relFiles()
24   { /* Ne rien faire de plus */ }
25
26   CScalar::~CScalar(void)
27   { /* Ne rien faire de plus */ }
28
29   std::map<StdString, ETranformationType> CScalar::transformationMapList_ = std::map<StdString, ETranformationType>();
30   bool CScalar::dummyTransformationMapList_ = CScalar::initializeTransformationMap(CScalar::transformationMapList_);
31   bool CScalar::initializeTransformationMap(std::map<StdString, ETranformationType>& m)
32   {
33     m["reduce_axis"]   = TRANS_REDUCE_AXIS_TO_SCALAR;
34     m["extract_axis"]  = TRANS_EXTRACT_AXIS_TO_SCALAR;
35     m["reduce_domain"] = TRANS_REDUCE_DOMAIN_TO_SCALAR;
36     m["reduce_scalar"] = TRANS_REDUCE_SCALAR_TO_SCALAR;
37   }
38
39   StdString CScalar::GetName(void)   { return (StdString("scalar")); }
40   StdString CScalar::GetDefName(void){ return (CScalar::GetName()); }
41   ENodeType CScalar::GetType(void)   { return (eScalar); }
42
43   CScalar* CScalar::createScalar()
44   {
45     CScalar* scalar = CScalarGroup::get("scalar_definition")->createChild();
46     return scalar;
47   }
48
49   bool CScalar::IsWritten(const StdString & filename) const
50   {
51      return (this->relFiles.find(filename) != this->relFiles.end());
52   }
53
54   void CScalar::addRelFile(const StdString& filename)
55   {
56      this->relFiles.insert(filename);
57   }
58
59   void CScalar::checkAttributes(void)
60   {
61      if (checkAttributes_done_) return ;
62
63      checkAttributes_done_ = true ; 
64   }
65
66  void CScalar::checkAttributesOnClient()
67  {
68
69  }
70
71  /*!
72  \brief Check if a scalar is completed
73  Before make any scalar processing, we must be sure that all scalar informations have
74  been sent, for exemple when reading a grid in a file or when grid elements are sent by an
75  other context (coupling). So all direct reference of the scalar (scalar_ref) must be also completed
76  \return true if scalar and scalar reference are completed
77  */
78  bool CScalar::checkIfCompleted(void)
79  {
80    if (hasDirectScalarReference()) if (!getDirectScalarReference()->checkIfCompleted()) return false;
81    return isCompleted_ ;
82  }
83
84  /*!
85  \brief Set a scalar as completed
86   When all information about a scalar have been received, the scalar is tagged as completed and is
87   suitable for processing
88  */
89  void CScalar::setCompleted(void)
90  {
91    if (hasDirectScalarReference()) getDirectScalarReference()->setCompleted() ;
92    isCompleted_=true ;
93  }
94
95  /*!
96  \brief Set a scalar as uncompleted
97   When informations about a scalar are expected from a grid reading from file or coupling, the scalar is
98   tagged as uncompleted and is not suitable for processing
99  */
100  void CScalar::setUncompleted(void)
101  {
102    if (hasDirectScalarReference()) getDirectScalarReference()->setUncompleted() ;
103    isCompleted_=false ;
104  }
105
106
107
108
109  /*!
110    Compare two scalar objects.
111    They are equal if only if they have identical attributes as well as their values.
112    Moreover, they must have the same transformations.
113  \param [in] scalar Compared scalar
114  \return result of the comparison
115  */
116  bool CScalar::isEqual(CScalar* obj)
117  {
118    vector<StdString> excludedAttr;
119    excludedAttr.push_back("scalar_ref");
120    bool objEqual = SuperClass::isEqual(obj, excludedAttr);
121    if (!objEqual) return objEqual;
122
123    TransMapTypes thisTrans = this->getAllTransformations();
124    TransMapTypes objTrans  = obj->getAllTransformations();
125
126    TransMapTypes::const_iterator it, itb, ite;
127    std::vector<ETranformationType> thisTransType, objTransType;
128    for (it = thisTrans.begin(); it != thisTrans.end(); ++it)
129      thisTransType.push_back(it->first);
130    for (it = objTrans.begin(); it != objTrans.end(); ++it)
131      objTransType.push_back(it->first);
132
133    if (thisTransType.size() != objTransType.size()) return false;
134    for (int idx = 0; idx < thisTransType.size(); ++idx)
135      objEqual &= (thisTransType[idx] == objTransType[idx]);
136
137    return objEqual;
138  }
139
140  CTransformation<CScalar>* CScalar::addTransformation(ETranformationType transType, const StdString& id)
141  {
142    transformationMap_.push_back(std::make_pair(transType, CTransformation<CScalar>::createTransformation(transType,id)));
143    return transformationMap_.back().second;
144  }
145
146  bool CScalar::hasTransformation()
147  {
148    return (!transformationMap_.empty());
149  }
150
151  void CScalar::setTransformations(const TransMapTypes& scalarTrans)
152  {
153    transformationMap_ = scalarTrans;
154  }
155
156  CScalar::TransMapTypes CScalar::getAllTransformations(void)
157  {
158    return transformationMap_;
159  }
160
161  void CScalar::duplicateTransformation(CScalar* src)
162  {
163    if (src->hasTransformation())
164    {
165      this->setTransformations(src->getAllTransformations());
166    }
167  }
168
169  /*!
170   * Go through the hierarchy to find the scalar from which the transformations must be inherited
171   */
172  void CScalar::solveInheritanceTransformation()
173  {
174    if (hasTransformation() || !hasDirectScalarReference())
175      return;
176
177    CScalar* scalar = this;
178    std::vector<CScalar*> refScalar;
179    while (!scalar->hasTransformation() && scalar->hasDirectScalarReference())
180    {
181      refScalar.push_back(scalar);
182      scalar = scalar->getDirectScalarReference();
183    }
184
185    if (scalar->hasTransformation())
186      for (size_t i = 0; i < refScalar.size(); ++i)
187        refScalar[i]->setTransformations(scalar->getAllTransformations());
188  }
189
190  void CScalar::sendScalarToFileServer(CContextClient* client)
191  {
192    if (sendScalarToFileServer_done_.count(client)!=0) return ;
193    else sendScalarToFileServer_done_.insert(client) ;
194
195    StdString scalarDefRoot("scalar_definition");
196    CScalarGroup* scalarPtr = CScalarGroup::get(scalarDefRoot);
197    this->sendAllAttributesToServer(client);
198  }
199  /*!
200    Parse children nodes of a scalar in xml file.
201    \param node child node to process
202  */
203  void CScalar::parse(xml::CXMLNode & node)
204  {
205    SuperClass::parse(node);
206
207    if (node.goToChildElement())
208    {
209      StdString nodeElementName;
210      do
211      {
212        StdString nodeId("");
213        if (node.getAttributes().end() != node.getAttributes().find("id"))
214        { nodeId = node.getAttributes()["id"]; }
215
216        nodeElementName = node.getElementName();
217        std::map<StdString, ETranformationType>::const_iterator ite = transformationMapList_.end(), it;
218        it = transformationMapList_.find(nodeElementName);
219        if (ite != it)
220        {
221          transformationMap_.push_back(std::make_pair(it->second, CTransformation<CScalar>::createTransformation(it->second,
222                                                                                                                 nodeId,
223                                                                                                                 &node)));
224        }
225        else
226        {
227          ERROR("void CScalar::parse(xml::CXMLNode & node)",
228                << "The transformation " << nodeElementName << " has not been supported yet.");
229        }
230      } while (node.goToNextElement()) ;
231      node.goToParentElement();
232    }
233  }
234
235  // Definition of some macros
236  DEFINE_REF_FUNC(Scalar,scalar)
237
238} // namespace xios
Note: See TracBrowser for help on using the repository browser.