source: XIOS/dev/dev_ym/XIOS_COUPLING/src/node/coupler_in.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: 5.0 KB
Line 
1#include "coupler_in.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
9namespace xios
10{
11
12  CCouplerIn::CCouplerIn(void) : CObjectTemplate<CCouplerIn>(), CCouplerInAttributes(),
13                                 virtualFieldGroup(), enabledFields() 
14  {
15     setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
16  }
17
18   CCouplerIn::CCouplerIn(const StdString & id) : CObjectTemplate<CCouplerIn>(id), CCouplerInAttributes(),
19                                                  virtualFieldGroup(), enabledFields()
20    {
21      setVirtualFieldGroup(CFieldGroup::create(getId() + "_virtual_field_group"));
22    }
23
24   CCouplerIn::~CCouplerIn(void)
25   { /* Ne rien faire de plus */ }
26
27   ///---------------------------------------------------------------
28  //! Get name of coupler_in
29   StdString CCouplerIn::GetName(void)   { return (StdString("coupler_in")); }
30   StdString CCouplerIn::GetDefName(void){ return (CCouplerIn::GetName()); }
31   ENodeType CCouplerIn::GetType(void)   { return (eCouplerIn); }
32
33   std::vector<CField*> CCouplerIn::getEnabledFields(void)
34   TRY
35   {
36      if (enabledFields.empty())
37      {
38        this->enabledFields = this->getAllFields();
39        std::vector<CField*> newEnabledFields;
40        bool enabled ;
41        for ( auto it = this->enabledFields.begin(); it != this->enabledFields.end(); it++ )
42        {
43           if ((*it)->enabled.isEmpty()) enabled=true ; 
44           else enabled=(*it)->enabled ;
45           if (enabled) newEnabledFields.push_back(*it);
46        }
47        enabledFields = newEnabledFields;
48      }
49      return (this->enabledFields);
50   }
51   CATCH_DUMP_ATTR
52
53   void CCouplerIn::createInterCommunicator(void)
54   TRY
55   {
56     if (context.isEmpty())
57     {
58        ERROR("void CCouplerOut::createInterCommunicator(void)",
59               "The attribute <context> must be defined to specify the target coupling context");
60     }
61     CContext* contextPtr = CContext::getCurrent();
62     contextPtr->addCouplingChanel(context, false) ;
63   }
64   CATCH_DUMP_ATTR
65
66 
67   /*!
68   \brief Parse xml file and write information into coupler_in object
69   \param [in] node xmld node corresponding in xml coupler_in
70   */
71   void CCouplerIn::parse(xml::CXMLNode & node)
72   TRY
73   {
74      SuperClass::parse(node);
75
76      if (node.goToChildElement())
77      {
78        do
79        {
80           if (node.getElementName()=="field" || node.getElementName()=="field_group") this->getVirtualFieldGroup()->parseChild(node);
81        } while (node.goToNextElement());
82        node.goToParentElement();
83      }
84   }
85   CATCH_DUMP_ATTR
86
87   /*!
88   \brief Get virtual field group
89      In each CCouplerIn, there always exists a field group which is the ancestor of all
90   fields in the CCouplerIn. This is considered be virtual because it is created automatically during
91   CCouplerIn initialization and it normally doesn't appear on xml file
92   \return Pointer to field group
93   */
94   CFieldGroup* CCouplerIn::getVirtualFieldGroup(void) const
95   TRY
96   {
97      return (this->virtualFieldGroup);
98   }
99   CATCH
100
101   void CCouplerIn::solveDescInheritance(bool apply, const CAttributeMap * const parent)
102   TRY
103   {
104      SuperClassAttribute::setAttributes(parent,apply);
105      this->getVirtualFieldGroup()->solveDescInheritance(apply, NULL);
106   }
107   CATCH_DUMP_ATTR
108
109   void CCouplerIn::solveFieldRefInheritance(bool apply)
110   TRY
111   {
112      // Rsolution des hritages par rfrence de chacun des champs contenus dans le fichier.
113      std::vector<CField*> allF = this->getAllFields();
114      for (unsigned int i = 0; i < allF.size(); i++)
115         allF[i]->solveRefInheritance(apply);
116   }
117   CATCH_DUMP_ATTR
118   /*!
119   \brief Get virtual variable group
120      In each CCouplerIn, there always exists a variable group which is the ancestor of all
121   variable in the CCouplerIn. This is considered be virtual because it is created automatically during
122   CCouplerIn initialization and it normally doesn't appear on xml file
123   \return Pointer to variable group
124   */
125
126   //! Get all fields of a file
127   std::vector<CField*> CCouplerIn::getAllFields(void) const
128   TRY
129   {
130      return (this->virtualFieldGroup->getAllChildren());
131   }
132   CATCH
133
134
135
136   //----------------------------------------------------------------
137   //! Change virtual field group to a new one
138   void CCouplerIn::setVirtualFieldGroup(CFieldGroup* newVirtualFieldGroup)
139   TRY
140   {
141      this->virtualFieldGroup = newVirtualFieldGroup;
142   }
143   CATCH_DUMP_ATTR
144   
145   ///--------------------------------------------------------------
146   /*!
147   */
148   StdString CCouplerIn::dumpClassAttributes(void)
149   {
150     StdString str;
151     CContext* context = CContext::getCurrent();
152     str.append("context=\"");
153     str.append(context->getId());
154     str.append("\"");
155     str.append(" enabled fields=\"");
156     int size = this->enabledFields.size();
157     for (int i = 0; i < size; ++i)
158     {
159       str.append(this->enabledFields[i]->getId());
160       str.append(" ");
161     }
162     str.append("\"");
163     return str;
164   }
165}
Note: See TracBrowser for help on using the repository browser.