File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CurveClass Class Reference

Provides a flexible curve class which provides a quick way to calculate return values for any given x-vale with a resolution of 10,000 units on the x-axis. More...

#include <CurveClasses.h>

Inheritance diagram for CurveClass:
GompertzCurveClass HollingsDiscCurveClass PettiforFeedingTimeCurveClass Polynomial2CurveClass ThresholdCurveClass

Public Member Functions

 CurveClass (bool a_reversecurve, double a_MaxX, double a_MinX, const char *a_name)
 
virtual ~CurveClass ()
 
virtual double GetY (double a_X)
 
virtual void WriteDataFile (int a_step)
 

Protected Member Functions

virtual void CalculateCurveValues ()
 fills in the curve for 10,000 values from MinX to MaxX More...
 
virtual double DoCalc (double)
 The specific calulation of y for a given x. More...
 

Protected Attributes

double m_parameterMaxX
 A parameter for a the maximum value of X we consider. More...
 
double m_parameterMinX
 A parameter for a the minimum value of X we consider. More...
 
double m_step
 The size of each step on the X-axis. More...
 
double m_step_inv
 The inverse of m_step. More...
 
double * m_values
 The values of y we store for each X. More...
 
string m_name
 A scaler for the x-values. More...
 
bool m_reversecurve
 If true the values fall from 1 to zero, otherwise its zero to 1. More...
 

Detailed Description

Provides a flexible curve class which provides a quick way to calculate return values for any given x-vale with a resolution of 10,000 units on the x-axis.

Constructor & Destructor Documentation

◆ CurveClass()

CurveClass::CurveClass ( bool  a_reversecurve,
double  a_MaxX,
double  a_MinX,
const char *  a_name 
)

Make space for the y-values.

41 {
42  m_parameterMinX = a_MinX;
43  m_parameterMaxX = a_MaxX;
44  m_reversecurve = a_reversecurve;
45  m_name = a_name;
47  m_values = new double[10000];
48 }

◆ ~CurveClass()

CurveClass::~CurveClass ( )
virtual
52 {
53  delete[] m_values;
54 }

Member Function Documentation

◆ CalculateCurveValues()

void CurveClass::CalculateCurveValues ( )
protectedvirtual

fills in the curve for 10,000 values from MinX to MaxX

We set m_step to be the size of each step on the X-axis, assuming 10000 steps over the range minX to maxX.

Calculate the value based on the input paramters.

58 {
60  m_step = (m_parameterMaxX - m_parameterMinX) / 10000.0;
61  m_step_inv = 1.0 / m_step;
62  for (int i = 0; i<10000; i++)
63  {
64  double x = m_parameterMinX + (i * m_step);
66  m_values[i] = DoCalc(x);
67  if (m_reversecurve) m_values[i] = 1 - m_values[i];
68 
69  }
70 }

Referenced by GompertzCurveClass::GompertzCurveClass(), HollingsDiscCurveClass::HollingsDiscCurveClass(), PettiforFeedingTimeCurveClass::PettiforFeedingTimeCurveClass(), Polynomial2CurveClass::Polynomial2CurveClass(), and ThresholdCurveClass::ThresholdCurveClass().

◆ DoCalc()

virtual double CurveClass::DoCalc ( double  )
inlineprotectedvirtual

The specific calulation of y for a given x.

Reimplemented in PettiforFeedingTimeCurveClass, HollingsDiscCurveClass, ThresholdCurveClass, Polynomial2CurveClass, and GompertzCurveClass.

64 { return 0; }

◆ GetY()

double CurveClass::GetY ( double  a_X)
virtual

This is the time sensitive method so we avoid division, rather use multiplication by the inverse of m_step. Here we have a choice if a_X is bigger than maxX - either return the value for maxX or return parameter A (asymptote)

If a_X is <= minX then we need to return minX

Otherwise we have to calculate which index is closest to a_X

Find and return the correct Y-value

74 {
77  if (a_X > m_parameterMaxX) return m_values[9999]; //return m_parameterA;
79  if (a_X <= m_parameterMinX) return m_values[0];
81  int index = (int)((a_X - m_parameterMinX)* m_step_inv);
83  return m_values[index];
84 }

Referenced by Landscape::SupplyGooseGrazingForageH().

◆ WriteDataFile()

void CurveClass::WriteDataFile ( int  a_step)
virtual

Opens a stream file and outputs every a_step data points as x & y, tab separated.

88 {
90  string str1 = "CurvePoints" + m_name + ".txt";
91  ofstream ofile(str1.c_str(), ios::out);
92  for (int i = 0; i<10000; i = i + a_step)
93  {
94  ofile << m_parameterMinX + m_step*i << '\t' << m_values[i] << endl;
95  }
96  ofile.close();
97 }

Referenced by Landscape::Landscape().

Member Data Documentation

◆ m_name

string CurveClass::m_name
protected

A scaler for the x-values.

A name to identify the curve

◆ m_parameterMaxX

double CurveClass::m_parameterMaxX
protected

A parameter for a the maximum value of X we consider.

◆ m_parameterMinX

double CurveClass::m_parameterMinX
protected

A parameter for a the minimum value of X we consider.

◆ m_reversecurve

bool CurveClass::m_reversecurve
protected

If true the values fall from 1 to zero, otherwise its zero to 1.

◆ m_step

double CurveClass::m_step
protected

The size of each step on the X-axis.

◆ m_step_inv

double CurveClass::m_step_inv
protected

The inverse of m_step.

◆ m_values

double* CurveClass::m_values
protected

The values of y we store for each X.


The documentation for this class was generated from the following files:
CurveClass::m_step_inv
double m_step_inv
The inverse of m_step.
Definition: CurveClasses.h:51
CurveClass::m_parameterMinX
double m_parameterMinX
A parameter for a the minimum value of X we consider.
Definition: CurveClasses.h:47
CurveClass::m_reversecurve
bool m_reversecurve
If true the values fall from 1 to zero, otherwise its zero to 1.
Definition: CurveClasses.h:59
CurveClass::m_parameterMaxX
double m_parameterMaxX
A parameter for a the maximum value of X we consider.
Definition: CurveClasses.h:45
CurveClass::m_values
double * m_values
The values of y we store for each X.
Definition: CurveClasses.h:53
CurveClass::DoCalc
virtual double DoCalc(double)
The specific calulation of y for a given x.
Definition: CurveClasses.h:64
CurveClass::m_step
double m_step
The size of each step on the X-axis.
Definition: CurveClasses.h:49
CurveClass::m_name
string m_name
A scaler for the x-values.
Definition: CurveClasses.h:57