File: sparseGridCommon.h

package info (click to toggle)
stopt 5.12%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,860 kB
  • sloc: cpp: 70,456; python: 5,950; makefile: 72; sh: 57
file content (102 lines) | stat: -rw-r--r-- 4,514 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright (C) 2016 EDF
// All Rights Reserved
// This code is published under the GNU Lesser General Public License (GNU LGPL)
#ifndef  SPARSEGRIDCOMMON_H
#define  SPARSEGRIDCOMMON_H
#include  <Eigen/Dense>
#include "StOpt/core/sparse/sparseGridTypes.h"
#include "StOpt/core/sparse/sparseGridUtils.h"
#include "StOpt/core/utils/comparisonUtils.h"


/** \file sparseGridCommon.h
 * \brief Regroup some functions used in sparse grids whether you use classical sparse grids with boundaries or
 *        simplified one suppressing boundaries.
 * \author Xavier Warin
 */

namespace StOpt
{
/// \defgroup sparseCommon   sparse grid common functions
/// \brief Regroup some functions used in different sparse grids approximation
/// @{

/// \brief Create data structure of levels par sparse grids
///        The level  \f$ (l_i)_{i=1,NDIM} \f$ kept satisfies
///        \f$ \sum_{i=1}^{NDIM} l_i \alpha_i \le \f$  levelMax
/// \param   p_levelCurrent      current multilevel
/// \param   p_idimMin           minimal dimension treated
/// \param   p_levelMax          max level
/// \param   p_alpha             weight used for anisotropic sparse grids
/// \param   p_dataSet           data_structure
/// \param   p_levelCalc         utilitarian to store the current sum  \f$ \sum_{i=1}^{NDIM} l_i \alpha_i \f$
void createLevelsSparse(const Eigen::ArrayXc &p_levelCurrent,
                        const int   &p_idimMin,
                        const int   &p_levelMax,
                        const Eigen::ArrayXd &p_alpha,
                        SparseSet    &p_dataSet,
                        double   p_levelCalc);

/// \brief Create data_structure of levels for full grid
///        The levels  \f$ (l_i)_{i=1,NDIM} \f$ satisfies :
///         \f$ l_i  \alpha_i \le \f$ levelMax
///
/// \param   p_levelCurrent      current multilevel
/// \param   p_idimMin           minimal dimension treated
/// \param   p_levelMax          max level
/// \param   p_alpha             weight used for anisotropic sparse grids
/// \param   p_dataSet           data_structure
void createLevelsFull(const Eigen::ArrayXc &p_levelCurrent,
                      const int   &p_idimMin,
                      const int   &p_levelMax,
                      const Eigen::ArrayXd &p_alpha,
                      SparseSet    &p_dataSet);

/// \brief 1 dimensional recursive construction of the grid for 1D
/// \param p_levelCurrent       Current index of the point
/// \param p_positionCurrent    Current level of the point
/// \param p_dataSet            Data structure with all the points (all level already exists)
/// \param p_ipoint             Point number
void sparse1DConstruction(Eigen::ArrayXc &p_levelCurrent,
                          Eigen::ArrayXui &p_positionCurrent,
                          SparseSet &p_dataSet,
                          size_t &p_ipoint);

/// \brief  Create a a new data structure from a first one  with  holes in levels
///         and modify hierarchized values accordingly
/// \param p_dataSet          first data set with "holes "in levels
/// \param p_hierarchized    hierarchized values
/// \param p_valuesFunction  an array storing the nodal values (modified on the new struture)
/// \param p_newDataSet      new data set
/// \param p_newHierarchized  array of hierarchized values
/// \param p_newValuesFunction array of nodal values
template< class T >
void modifyDataSetAndHierachized(const SparseSet    &p_dataSet,
                                 const T &p_hierarchized,
                                 const T &p_valuesFunction,
                                 SparseSet &p_newDataSet,
                                 T   &p_newHierarchized,
                                 T &p_newValuesFunction)
{
    DoubleOrArray().resize(p_newHierarchized, p_hierarchized.size());
    DoubleOrArray().resize(p_newValuesFunction, p_hierarchized.size());
    int nCount = 0;
    for (auto level :  p_dataSet)
    {
        SparseLevel levelLoc;
        for (auto position : level.second)
        {
            levelLoc[position.first] = nCount;
            DoubleOrArray().affect(p_newHierarchized, nCount, DoubleOrArray()(p_hierarchized, position.second));
            DoubleOrArray().affect(p_newValuesFunction, nCount++, DoubleOrArray()(p_valuesFunction, position.second));
        }
        p_newDataSet[level.first] = levelLoc;
    }
    DoubleOrArray().resize(p_newHierarchized, nCount);
    DoubleOrArray().resize(p_newValuesFunction, nCount);
}


///@}
}
#endif /* SPARSEGRIDCOMMON.H */