source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/coupler_out.cpp @ 1875

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

XIOS coupling branch
Some updates.

First coupling test is beginning to work...

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.3 KB
Line 
1#include "coupler_out.hpp"
2#include "attribute_template.hpp"
3#include "object_template.hpp"
4#include "group_template.hpp"
5#include "object_factory.hpp"
6#include "context.hpp"
7#include "xios_spl.hpp"
8#include "string_tools.hpp"
9#include "contexts_manager.hpp"
10#include "services_manager.hpp"
11
12
13namespace xios
14{
15
16  CCouplerOut::CCouplerOut(void) : CObjectTemplate<CCouplerOut>(), CCouplerOutAttributes(),
17                                 virtualFieldGroup(), enabledFields() 
18  {
19     setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
20  }
21
22  CCouplerOut::CCouplerOut(const StdString & id) : CObjectTemplate<CCouplerOut>(id), CCouplerOutAttributes(),
23                                                    virtualFieldGroup(), enabledFields()
24  {
25    setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
26  }
27
28  CCouplerOut::~CCouplerOut(void)
29  { /* Ne rien faire de plus */ }
30
31   ///---------------------------------------------------------------
32  //! Get name of file
33  StdString CCouplerOut::GetName(void)   { return (StdString("coupler_out")); }
34  StdString CCouplerOut::GetDefName(void){ return (CCouplerOut::GetName()); }
35  ENodeType CCouplerOut::GetType(void)   { return (eCouplerIn); }
36
37   /*!
38   \brief Parse xml file and write information into coupler_in object
39   \param [in] node xmld node corresponding in xml coupler_in
40   */
41   void CCouplerOut::parse(xml::CXMLNode & node)
42   TRY
43   {
44      SuperClass::parse(node);
45
46      if (node.goToChildElement())
47      {
48        do
49        {
50           if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node);
51        } while (node.goToNextElement());
52        node.goToParentElement();
53      }
54   }
55   CATCH_DUMP_ATTR
56
57   const string& CCouplerOut::getCouplingContextId(void)
58   {
59     if (couplingContextId_.empty())
60     {
61       vector<string> vectStr=splitRegex(context,"::") ;
62       string poolId=vectStr[0] ;
63       string serviceId=poolId ;
64       string contextId=vectStr[1] ;
65       int contextLeader ;
66       int type = CServicesManager::CLIENT ;
67       couplingContextId_=CXios::getContextsManager()->getServerContextName(poolId, serviceId, 0, type, contextId) ;
68     }
69     return couplingContextId_ ;
70   }
71
72   std::vector<CField*> CCouplerOut::getEnabledFields(void)
73   TRY
74   {
75      if (enabledFields.empty())
76      {
77        this->enabledFields = this->getAllFields();
78        std::vector<CField*> newEnabledFields;
79        bool enabled ;
80        for ( auto it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ )
81        {
82           if ((*it)->enabled.isEmpty()) enabled=true ; 
83           else enabled=(*it)->enabled ;
84           if (enabled) newEnabledFields.push_back(*it);
85        }
86        enabledFields = newEnabledFields;
87      }
88      return (this->enabledFields);
89   }
90   CATCH_DUMP_ATTR
91
92   /*!
93    * assign the context associated to the coupler to the enabled fields
94    */
95   void  CCouplerOut::assignContext(void)
96   {
97     client_ = CContext::getCurrent()->getCouplerOutClient(getCouplingContextId());
98     for (auto& field : getEnabledFields()) field->setContextClient(client_) ; 
99   }
100
101      /*!
102   \brief Get virtual field group
103      In each CCouplerIn, there always exists a field group which is the ancestor of all
104   fields in the CCouplerIn. This is considered be virtual because it is created automatically during
105   CCouplerIn initialization and it normally doesn't appear on xml file
106   \return Pointer to field group
107   */
108   CFieldGroup* CCouplerOut::getVirtualFieldGroup(void) const
109   TRY
110   {
111      return (this->virtualFieldGroup);
112   }
113   CATCH
114
115
116   /*!
117   \brief Get virtual variable group
118      In each CCouplerIn, there always exists a variable group which is the ancestor of all
119   variable in the CCouplerIn. This is considered be virtual because it is created automatically during
120   CCouplerIn initialization and it normally doesn't appear on xml file
121   \return Pointer to variable group
122   */
123
124   //! Get all fields of a file
125   std::vector<CField*> CCouplerOut::getAllFields(void) const
126   TRY
127   {
128      return (this->virtualFieldGroup->getAllChildren());
129   }
130   CATCH
131
132   void CCouplerOut::solveDescInheritance(bool apply, const CAttributeMap * const parent)
133   TRY
134   {
135      SuperClassAttribute::setAttributes(parent,apply);
136      this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL);
137   }
138   CATCH_DUMP_ATTR
139
140   void CCouplerOut::solveFieldRefInheritance(bool apply)
141   TRY
142   {
143      // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier.
144      std::vector<CField*> allF = this->getAllFields();
145      for (unsigned int i = 0; i < allF.size(); i++)
146         allF[i]->solveRefInheritance(apply);
147   }
148   CATCH_DUMP_ATTR
149
150   void CCouplerOut::createInterCommunicator(void)
151   TRY
152   {
153     if (context.isEmpty())
154     {
155        ERROR("void CCouplerOut::createInterCommunicator(void)",
156               "The attribute <context> must be defined to specify the target coupling context");
157     }
158     CContext* contextPtr = CContext::getCurrent();
159     contextPtr->addCouplingChanel(getCouplingContextId(), true) ;
160   }
161   CATCH_DUMP_ATTR
162
163 
164   void CCouplerOut::solveOnlyRefOfEnabledFields(void)
165   TRY
166   {
167     int size = this->enabledFields.size();
168     for (int i = 0; i < size; ++i)
169     {
170       this->enabledFields[i]->solveOnlyReferenceEnabledField();
171     }
172   }
173   CATCH_DUMP_ATTR
174
175   void CCouplerOut::generateNewTransformationGridDest(void)
176   TRY
177   {
178     int size = this->enabledFields.size();
179     for (int i = 0; i < size; ++i)
180     {
181       this->enabledFields[i]->generateNewTransformationGridDest();
182     }
183   }
184   CATCH_DUMP_ATTR
185
186   void CCouplerOut::solveAllRefOfEnabledFieldsAndTransform(void)
187   TRY
188   {
189     int size = this->enabledFields.size();
190     for (int i = 0; i < size; ++i)
191     {       
192      this->enabledFields[i]->solveAllEnabledFieldsAndTransform();
193     }
194   }
195   CATCH_DUMP_ATTR
196
197   /*!
198    * Constructs the filter graph for each active field.
199    *
200    * \param gc the garbage collector to use when building the filter graph
201    */
202   void CCouplerOut::buildFilterGraphOfEnabledFields(CGarbageCollector& gc)
203   TRY
204   {
205     int size = this->enabledFields.size();
206     for (int i = 0; i < size; ++i)
207     {
208       this->enabledFields[i]->buildFilterGraph(gc, true);
209     }
210   }
211   CATCH_DUMP_ATTR
212
213   void CCouplerOut::checkGridOfEnabledFields(void)
214   TRY
215   { 
216     int size = this->enabledFields.size();
217     for (int i = 0; i < size; ++i)
218     {
219       this->enabledFields[i]->checkGridOfEnabledFields();
220     }
221   }
222   CATCH_DUMP_ATTR
223
224   //----------------------------------------------------------------
225   //! Change virtual field group to a new one
226   void CCouplerOut::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup)
227   TRY
228   {
229      this->virtualFieldGroup = newVirtualFieldGroup;
230   }
231   CATCH_DUMP_ATTR
232
233   ///--------------------------------------------------------------
234   /*!
235   */
236   StdString CCouplerOut::dumpClassAttributes(void)
237   {
238     StdString str;
239     CContext* context = CContext::getCurrent();
240     str.append("context=\"");
241     str.append(context->getId());
242     str.append("\"");
243     str.append(" enabled fields=\"");
244     int size = this->enabledFields.size();
245     for (int i = 0; i < size; ++i)
246     {
247       str.append(this->enabledFields[i]->getId());
248       str.append(" ");
249     }
250     str.append("\"");
251     return str;
252   }
253}
Note: See TracBrowser for help on using the repository browser.