source: XIOS/trunk/src/node/interpolate_domain.cpp @ 982

Last change on this file since 982 was 982, checked in by mhnguyen, 5 years ago

Implementing domain interpolation weights exportation
The option 'file' locates file to read if it exists, otherwise a new file with name = 'file' will be created

+) Write interpolation weights into a file

Test
+) On Curie
+) Work

File size: 3.3 KB
Line 
1#include "interpolate_domain.hpp"
2#include "type.hpp"
3
4namespace xios {
5
6  /// ////////////////////// Définitions ////////////////////// ///
7
8  CInterpolateDomain::CInterpolateDomain(void)
9    : CObjectTemplate<CInterpolateDomain>(), CInterpolateDomainAttributes(), CTransformation<CDomain>()
10  { /* Ne rien faire de plus */ }
11
12  CInterpolateDomain::CInterpolateDomain(const StdString & id)
13    : CObjectTemplate<CInterpolateDomain>(id), CInterpolateDomainAttributes(), CTransformation<CDomain>()
14  { /* Ne rien faire de plus */ }
15
16  CInterpolateDomain::~CInterpolateDomain(void)
17  {}
18
19  CTransformation<CDomain>* CInterpolateDomain::create(const StdString& id, xml::CXMLNode* node)
20  {
21    CInterpolateDomain* interpDomain = CInterpolateDomainGroup::get("interpolate_domain_definition")->createChild(id);
22    if (node) interpDomain->parse(*node);
23    return static_cast<CTransformation<CDomain>*>(interpDomain);
24  }
25
26  bool CInterpolateDomain::_dummyRegistered = CInterpolateDomain::registerTrans();
27  bool CInterpolateDomain::registerTrans()
28  {
29    registerTransformation(TRANS_INTERPOLATE_DOMAIN, create);
30  }
31
32  //----------------------------------------------------------------
33
34  StdString CInterpolateDomain::GetName(void)    { return StdString("interpolate_domain"); }
35  StdString CInterpolateDomain::GetDefName(void) { return StdString("interpolate_domain"); }
36  ENodeType CInterpolateDomain::GetType(void)    { return eInterpolateDomain; }
37
38  void CInterpolateDomain::checkValid(CDomain* domainSrc)
39  {
40    int order = 2;
41    if (!this->order.isEmpty()) order = this->order.getValue();
42    else this->order.setValue(order);
43    if (order < 1)
44    {
45       ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
46             << "Interpolation order is less than 1, it should be greater than 0."
47             << "Please define a correct one") ;
48    }
49
50    StdString weightFile = "interpolation_weights_" + domainSrc->getDomainOutputName();
51
52    if (!this->mode.isEmpty())
53    { 
54      if (mode_attr::read == this->mode)
55      {
56         if (this->file.isEmpty())
57         {
58            ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
59                 << "Read mode is activated but there is no file specified." << std::endl
60                 << "Please define a correct file containing interpolation weights with option 'file'. ");
61         }
62         else
63         {
64           weightFile = this->file;
65           ifstream f(weightFile.c_str());
66           if (!f.good())
67             ERROR("void CInterpolateDomain::checkValid(CDomain* domainSrc)",
68                   << "Read mode is activated but file "  << weightFile << " doesn't exist." << std::endl
69                   << "Please check this file ");
70         }
71      }
72      else
73      {
74        if (file.isEmpty())
75          this->file.setValue(weightFile);
76      }   
77    }
78    else
79    {
80      if (!file.isEmpty()) // set mode read
81      {
82         weightFile = this->file;
83         ifstream f(weightFile.c_str());
84         if (!f.good()) // file doesn't exist
85           this->mode.setValue(mode_attr::write);
86         else
87           this->mode.setValue(mode_attr::read);
88      }
89      else // only calculate weights() Mode set write but there is no file)
90      {
91        this->mode.setValue(mode_attr::write);
92      }
93    }
94
95  }
96
97}
Note: See TracBrowser for help on using the repository browser.