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

Last change on this file since 1784 was 1784, checked in by ymipsl, 4 years ago
  • Preparing coupling functionalities.
  • Make some cleaner things

YM

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 6.5 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   std::vector<CField*> CCouplerOut::getEnabledFields(void)
58   TRY
59   {
60      if (enabledFields.empty())
61      {
62        this->enabledFields = this->getAllFields();
63        std::vector<CField*> newEnabledFields;
64        bool enabled ;
65        for ( auto it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ )
66        {
67           if ((*it)->enabled.isEmpty()) enabled=true ; 
68           else enabled=(*it)->enabled ;
69           if (enabled) newEnabledFields.push_back(*it);
70        }
71        enabledFields = newEnabledFields;
72      }
73      return (this->enabledFields);
74   }
75   CATCH_DUMP_ATTR
76
77      /*!
78   \brief Get virtual field group
79      In each CCouplerIn, there always exists a field group which is the ancestor of all
80   fields in the CCouplerIn. This is considered be virtual because it is created automatically during
81   CCouplerIn initialization and it normally doesn't appear on xml file
82   \return Pointer to field group
83   */
84   CFieldGroup* CCouplerOut::getVirtualFieldGroup(void) const
85   TRY
86   {
87      return (this->virtualFieldGroup);
88   }
89   CATCH
90
91
92   /*!
93   \brief Get virtual variable group
94      In each CCouplerIn, there always exists a variable group which is the ancestor of all
95   variable in the CCouplerIn. This is considered be virtual because it is created automatically during
96   CCouplerIn initialization and it normally doesn't appear on xml file
97   \return Pointer to variable group
98   */
99
100   //! Get all fields of a file
101   std::vector<CField*> CCouplerOut::getAllFields(void) const
102   TRY
103   {
104      return (this->virtualFieldGroup->getAllChildren());
105   }
106   CATCH
107
108   void CCouplerOut::solveDescInheritance(bool apply, const CAttributeMap * const parent)
109   TRY
110   {
111      SuperClassAttribute::setAttributes(parent,apply);
112      this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL);
113   }
114   CATCH_DUMP_ATTR
115
116   void CCouplerOut::solveFieldRefInheritance(bool apply)
117   TRY
118   {
119      // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier.
120      std::vector<CField*> allF = this->getAllFields();
121      for (unsigned int i = 0; i < allF.size(); i++)
122         allF[i]->solveRefInheritance(apply);
123   }
124   CATCH_DUMP_ATTR
125
126   void CCouplerOut::createInterCommunicator(void)
127   TRY
128   {
129     if (context.isEmpty())
130     {
131        ERROR("void CCouplerOut::createInterCommunicator(void)",
132               "The attribute <context> must be defined to specify the target coupling context");
133     }
134     CContext* contextPtr = CContext::getCurrent();
135     contextPtr->addCouplingChanel(context, true) ;
136   }
137   CATCH_DUMP_ATTR
138
139 
140   void CCouplerOut::solveOnlyRefOfEnabledFields(void)
141   TRY
142   {
143     int size = this->enabledFields.size();
144     for (int i = 0; i < size; ++i)
145     {
146       this->enabledFields[i]->solveOnlyReferenceEnabledField();
147     }
148   }
149   CATCH_DUMP_ATTR
150
151   void CCouplerOut::generateNewTransformationGridDest(void)
152   TRY
153   {
154     int size = this->enabledFields.size();
155     for (int i = 0; i < size; ++i)
156     {
157       this->enabledFields[i]->generateNewTransformationGridDest();
158     }
159   }
160   CATCH_DUMP_ATTR
161
162   void CCouplerOut::solveAllRefOfEnabledFieldsAndTransform(void)
163   TRY
164   {
165     int size = this->enabledFields.size();
166     for (int i = 0; i < size; ++i)
167     {       
168      this->enabledFields[i]->solveAllEnabledFieldsAndTransform();
169     }
170   }
171   CATCH_DUMP_ATTR
172
173   /*!
174    * Constructs the filter graph for each active field.
175    *
176    * \param gc the garbage collector to use when building the filter graph
177    */
178   void CCouplerOut::buildFilterGraphOfEnabledFields(CGarbageCollector& gc)
179   TRY
180   {
181     int size = this->enabledFields.size();
182     for (int i = 0; i < size; ++i)
183     {
184       this->enabledFields[i]->buildFilterGraph(gc, true);
185     }
186   }
187   CATCH_DUMP_ATTR
188
189   void CCouplerOut::checkGridOfEnabledFields(void)
190   TRY
191   { 
192     int size = this->enabledFields.size();
193     for (int i = 0; i < size; ++i)
194     {
195       this->enabledFields[i]->checkGridOfEnabledFields();
196     }
197   }
198   CATCH_DUMP_ATTR
199
200   //----------------------------------------------------------------
201   //! Change virtual field group to a new one
202   void CCouplerOut::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup)
203   TRY
204   {
205      this->virtualFieldGroup = newVirtualFieldGroup;
206   }
207   CATCH_DUMP_ATTR
208
209   ///--------------------------------------------------------------
210   /*!
211   */
212   StdString CCouplerOut::dumpClassAttributes(void)
213   {
214     StdString str;
215     CContext* context = CContext::getCurrent();
216     str.append("context=\"");
217     str.append(context->getId());
218     str.append("\"");
219     str.append(" enabled fields=\"");
220     int size = this->enabledFields.size();
221     for (int i = 0; i < size; ++i)
222     {
223       str.append(this->enabledFields[i]->getId());
224       str.append(" ");
225     }
226     str.append("\"");
227     return str;
228   }
229}
Note: See TracBrowser for help on using the repository browser.