File: OneDimRegularSpaceGrid.h

package info (click to toggle)
stopt 6.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,264 kB
  • sloc: cpp: 75,778; python: 6,012; makefile: 72; sh: 57
file content (63 lines) | stat: -rw-r--r-- 1,754 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
// Copyright (C) 2016 EDF
// All Rights Reserved
// This code is published under the GNU Lesser General Public License (GNU LGPL)
#ifndef ONEDIMREGULARSPACEGRID_H
#define  ONEDIMREGULARSPACEGRID_H
#include <assert.h>
#include <algorithm>
#include "StOpt/core/utils/comparisonUtils.h"

/** \file OneDimRegularSpaceGrid.h
 * \brief Defines a specialization of the RegularSpaceGrid  object in one dimension
 * \author Xavier Warin
 */
namespace StOpt
{
/// \class OneDimRegularSpaceGrid OneDimRegularSpaceGrid.h
/// define a grid in one dimension
class OneDimRegularSpaceGrid
{
private :
    double m_lowValue ; ///< minimal value of the mesh
    double m_step; ///< Step size
    int m_nbStep ; ///< Number of step

public :

    /// \brief Default constructor
    OneDimRegularSpaceGrid() {}

    /// \brief Constructor
    /// \param p_lowValue   minimal value of the grid
    /// \param p_step       step size
    /// \param p_nbStep     number of steps
    OneDimRegularSpaceGrid(const double &p_lowValue, const double &p_step, const  int  &p_nbStep) : m_lowValue(p_lowValue), m_step(p_step), m_nbStep(p_nbStep) {}

    /// \brief To a coordinate get back the  mesh number
    /// \param  p_coord   coordinate
    /// \return mesh number associated to the coordinate
    inline int  getMesh(const double   &p_coord) const
    {
        assert(isLesserOrEqual(m_lowValue, p_coord));
        return std::min(roundIntAbove((p_coord - m_lowValue) / m_step), m_nbStep);

    }

    /// \name get back value
    ///@{
    inline double getLowValue() const
    {
        return  m_lowValue ;
    }
    inline double getStep() const
    {
        return m_step;
    }
    inline int getNbStep() const
    {
        return m_nbStep;
    }
    ///@}
};
}
#endif