source: XIOS/trunk/src/node/field_impl.hpp @ 501

Last change on this file since 501 was 501, checked in by ymipsl, 9 years ago

Add licence copyright to all file ond directory src using the command :
svn propset -R copyright -F header_licence src

XIOS is now officialy under CeCILL licence

YM

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 5.2 KB
Line 
1
2#ifndef __FIELD_IMPL_HPP__
3#define __FIELD_IMPL_HPP__
4
5#include "xmlioserver_spl.hpp"
6#include "field.hpp"
7#include "context.hpp"
8#include "grid.hpp"
9#include "timer.hpp"
10#include "array_new.hpp"
11
12
13namespace xios {
14
15  template <int N>
16  void CField::setData(const CArray<double, N>& _data)
17  {
18    if (hasInstantData) 
19    {
20      grid->inputField(_data, instantData); 
21      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second) ;
22    }
23   
24    if (!hasExpression)
25    {
26      const std::vector<CField*>& refField=getAllReference();
27      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
28     
29      for (; it != end; it++) (*it)->setData(_data) ;
30      if (hasOutputFile || hasFieldOut) updateData(_data) ;
31    }
32     
33  }
34
35  void CField::setDataFromExpression(const CArray<double, 1>& _data)
36  {
37    if (hasInstantData) 
38    {
39      instantData=_data; 
40      for(list< pair<CField *,int> >::iterator it=fieldDependency.begin(); it!=fieldDependency.end(); ++it)  it->first->setSlot(it->second) ;
41    }
42   
43    if (!hasExpression)
44    {
45      const std::vector<CField*>& refField=getAllReference();
46      std::vector<CField*>::const_iterator  it = refField.begin(), end = refField.end();
47     
48      for (; it != end; it++) (*it)->setData(_data) ;
49      if (hasOutputFile || hasFieldOut) updateData(_data) ;
50    }
51     
52  }
53
54   template <int N>
55   bool CField::updateData(const CArray<double, N>& _data)
56   {       
57      CContext* context=CContext::getCurrent();
58      const CDate & currDate = context->getCalendar()->getCurrentDate();
59      const CDate opeDate      = *last_operation + freq_operation;
60      const CDate writeDate    = *last_Write     + freq_write;       
61      bool doOperation, doWrite; 
62
63   
64      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
65      info(50) << "Next operation "  << opeDate<<std::endl;
66
67      doOperation = (opeDate <= currDate) ;
68      if (isOnceOperation)
69        if (isFirstOperation) doOperation=true ;
70        else doOperation=false ;
71
72      if (doOperation)
73      {
74         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
75         {
76            this->data.resize(this->grid->storeIndex_client.numElements());
77         }
78           
79         CArray<double,1> input(data.numElements()) ;
80         this->grid->inputField(_data, input);         
81         (*this->foperation)(input);
82         
83         *last_operation = currDate;
84         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
85      }
86
87      doWrite = (writeDate < (currDate + freq_operation)) ;
88      if (isOnceOperation)
89      { 
90        if(isFirstOperation) 
91        {
92          doWrite=true ;
93          isFirstOperation=false ;
94        }
95        else doWrite=false ;
96      }
97     
98      if (doWrite)
99      {
100         this->foperation->final();
101         *last_Write = writeDate;
102         if (hasOutputFile)
103         {
104           info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate << std::endl;
105           CTimer::get("XIOS Send Data").resume() ;
106           sendUpdateData() ;
107           CTimer::get("XIOS Send Data").suspend() ;
108         }
109         
110         if (hasFieldOut)
111         {
112           fieldOut->setDataFromExpression(data) ;
113         }
114         return (true);       
115      }
116
117      return (false);
118   }
119   
120   bool CField::updateDataFromExpression(const CArray<double, 1>& _data)
121   {       
122      CContext* context=CContext::getCurrent();
123      const CDate & currDate = context->getCalendar()->getCurrentDate();
124      const CDate opeDate      = *last_operation + freq_operation;
125      const CDate writeDate    = *last_Write     + freq_write;       
126      bool doOperation, doWrite; 
127
128   
129      info(50) << "CField::updateData " << currDate <<  " : send data to " << this->getBaseFieldId() << std::endl;
130      info(50) << "Next operation "  << opeDate<<std::endl;
131
132      doOperation = (opeDate <= currDate) ;
133      if (isOnceOperation)
134        if (isFirstOperation) doOperation=true ;
135        else doOperation=false ;
136
137      if (doOperation)
138      {
139         if (this->data.numElements() != this->grid->storeIndex_client.numElements())
140         {
141            this->data.resize(this->grid->storeIndex_client.numElements());
142         }
143           
144        (*this->foperation)(_data);
145         
146         *last_operation = currDate;
147         info(50) << "(*last_operation = currDate) : " << *last_operation << " = " << currDate << std::endl; 
148      }
149
150      doWrite = (writeDate < (currDate + freq_operation)) ;
151      if (isOnceOperation)
152      { 
153        if(isFirstOperation) 
154        {
155          doWrite=true ;
156          isFirstOperation=false ;
157        }
158        else doWrite=false ;
159      }
160     
161      if (doWrite)
162      {
163         this->foperation->final();
164         *last_Write = writeDate;
165         info(50) << "(*last_Write = currDate) : " << *last_Write << " = " << currDate  << std::endl;
166         CTimer::get("XIOS Send Data").resume() ;
167         sendUpdateData() ;
168         CTimer::get("XIOS Send Data").suspend() ;
169         return (true);       
170      }
171
172      return (false);
173   }
174
175} // namespace xios
176
177#endif
Note: See TracBrowser for help on using the repository browser.