source: XIOS/dev/dev_olga/src/transformation/domain_algorithm_compute_connectivity.cpp @ 1620

Last change on this file since 1620 was 1612, checked in by oabramkina, 2 years ago

Dev: adding exception handling.

To activate it, compilation flag -DXIOS_EXCEPTION should be added.

File size: 4.8 KB
Line 
1/*!
2   \file domain_algorithm_compute_connectivity.cpp
3   \author Ha NGUYEN
4   \since 15 Jul 2016
5   \date 15 Jul 2016
6
7   \brief Algorithm for compute_connectivity on an domain.
8 */
9#include "domain_algorithm_compute_connectivity.hpp"
10#include "compute_connectivity_domain.hpp"
11#include "mesh.hpp"
12#include "domain.hpp"
13#include "grid.hpp"
14#include "grid_transformation_factory_impl.hpp"
15
16namespace xios {
17CGenericAlgorithmTransformation* CDomainAlgorithmComputeConnectivity::create(CGrid* gridDst, CGrid* gridSrc,
18                                                                     CTransformation<CDomain>* transformation,
19                                                                     int elementPositionInGrid,
20                                                                     std::map<int, int>& elementPositionInGridSrc2ScalarPosition,
21                                                                     std::map<int, int>& elementPositionInGridSrc2AxisPosition,
22                                                                     std::map<int, int>& elementPositionInGridSrc2DomainPosition,
23                                                                     std::map<int, int>& elementPositionInGridDst2ScalarPosition,
24                                                                     std::map<int, int>& elementPositionInGridDst2AxisPosition,
25                                                                     std::map<int, int>& elementPositionInGridDst2DomainPosition)
26TRY
27{
28  std::vector<CDomain*> domainListDestP = gridDst->getDomains();
29  std::vector<CDomain*> domainListSrcP  = gridSrc->getDomains();
30
31  CComputeConnectivityDomain* compute_connectivityDomain = dynamic_cast<CComputeConnectivityDomain*> (transformation);
32  int domainDstIndex = elementPositionInGridDst2DomainPosition[elementPositionInGrid];
33  int domainSrcIndex = elementPositionInGridSrc2DomainPosition[elementPositionInGrid];
34
35  return (new CDomainAlgorithmComputeConnectivity(domainListDestP[domainDstIndex], domainListSrcP[domainSrcIndex], compute_connectivityDomain));
36}
37CATCH
38
39bool CDomainAlgorithmComputeConnectivity::registerTrans()
40TRY
41{
42  CGridTransformationFactory<CDomain>::registerTransformation(TRANS_COMPUTE_CONNECTIVITY_DOMAIN, create);
43}
44CATCH
45
46CDomainAlgorithmComputeConnectivity::CDomainAlgorithmComputeConnectivity(CDomain* domainDestination, CDomain* domainSource,
47                                                                         CComputeConnectivityDomain* compute_connectivityDomain)
48: CDomainAlgorithmTransformation(domainDestination, domainSource)
49TRY
50{
51  this->type_ = (ELEMENT_NO_MODIFICATION_WITHOUT_DATA);
52  compute_connectivityDomain->checkValid(domainDestination);
53  int& nbNeighborMax = compute_connectivityDomain->n_neighbor_max;
54  CArray<int,1>& nbNeighbor = compute_connectivityDomain->n_neighbor;
55  CArray<int,2>& localNeighbors = compute_connectivityDomain->local_neighbor;
56  int type = 1; // Edge type
57  switch (compute_connectivityDomain->type)
58  {
59    case CComputeConnectivityDomain::type_attr::node :
60      type = 0;
61      break;
62    case CComputeConnectivityDomain::type_attr::edge :
63      type = 1;
64      break;
65    default:
66      break;
67  }
68
69  computeLocalConnectivity(type, domainDestination, nbNeighborMax, nbNeighbor, localNeighbors);
70}
71CATCH
72
73/*!
74 *  Compute local connectivity of a domain
75 *  \param[in] type type of connectivity (node or edge)
76 *  \param[in] domain domain on which we calculate local connectivity
77 *  \param[in/out] nbConnectivityMax maximum number of neighbor a cell of domain has
78 *  \param[in/out] nbConnectivity number of neighbor a cell has
79 *  \param[in/out] localConnectivity localConnectivity local index of neighbor of a cell
80 */
81void CDomainAlgorithmComputeConnectivity::computeLocalConnectivity(int type,
82                                                                  CDomain* domain,
83                                                                  int& nbConnectivityMax,
84                                                                  CArray<int,1>& nbConnectivity,
85                                                                  CArray<int,2>& localConnectivity)
86TRY
87{
88
89  CMesh mesh;
90
91  CArray<double,2>& bounds_lon = domain->bounds_lon_1d;
92  CArray<double,2>& bounds_lat = domain->bounds_lat_1d;
93  int ncell = bounds_lon.shape()[1];
94  CArray<int,1> localIndex(ncell);
95  for (int idx = 0; idx <ncell; ++idx) localIndex(idx) = idx;
96
97  mesh.getLocalNghbFaces(type, localIndex, bounds_lon, bounds_lat, localConnectivity, nbConnectivity);
98  nbConnectivityMax = 0;
99  for (int idx =0; idx < nbConnectivity.numElements(); ++idx)
100    if (nbConnectivityMax < nbConnectivity(idx)) nbConnectivityMax = nbConnectivity(idx);
101}
102CATCH
103
104/*!
105  Compute the index mapping between domain on grid source and one on grid destination
106*/
107void CDomainAlgorithmComputeConnectivity::computeIndexSourceMapping_(const std::vector<CArray<double,1>* >& dataAuxInputs)
108{
109}
110
111}
Note: See TracBrowser for help on using the repository browser.