Loading [MathJax]/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
Osmia_Nest_Manager Class Reference

#include <Osmia_Population_Manager.h>

Public Member Functions

 Osmia_Nest_Manager ()
 Osmia nest manager constructor. More...
 
 ~Osmia_Nest_Manager ()
 Osmia nest manager denstructor. More...
 
void InitOsmiaBeeNesting ()
 Read in the Osmia nest density files and allocate to each LE object. More...
 
void UpdateOsmiaNesting ()
 Tell all LE objects to update their osmia nest status. More...
 
bool IsOsmiaNestPossible (int a_polyindex)
 Find out whether an osmia nest can be made here. More...
 
Osmia_NestCreateNest (int a_x, int a_y, int a_polyindex)
 Create the osmia nest here
More...
 
void ReleaseOsmiaNest (int a_polyindex, Osmia_Nest *a_nest)
 release nest here
More...
 
bool GetNestPossible (TTypesOfLandscapeElement index)
 Is a nest possible in this polytype. More...
 
int GetNoNests (int a_polyindex)
 
bool SanityCheck (int a_polyindex)
 
bool CheckZeroNests ()
 

Protected Attributes

vector< OsmiaPolygonEntrym_PolyList
 
vector< omp_nest_lock_t * > m_PolyListLocks
 
bool m_PossibleNestType [tole_Foobar]
 Holds a set of flags indicating whether an Osmia nest is possible (true) or not (false) More...
 

Constructor & Destructor Documentation

◆ Osmia_Nest_Manager()

Osmia_Nest_Manager::Osmia_Nest_Manager ( )
inline

Osmia nest manager constructor.

305  {
306  ;
307  }

◆ ~Osmia_Nest_Manager()

Osmia_Nest_Manager::~Osmia_Nest_Manager ( )
inline

Osmia nest manager denstructor.

310  {
311  int nopolys = m_PolyList.size();
312  for (int e = 0; e < nopolys; e++) {
313  omp_destroy_nest_lock(m_PolyListLocks[e]);
314  delete m_PolyListLocks[e];
315  }
316  m_PolyList.clear();
317  }

References m_PolyList, and m_PolyListLocks.

Member Function Documentation

◆ CheckZeroNests()

bool Osmia_Nest_Manager::CheckZeroNests ( )
inline
359  {
360  for (unsigned int s = 0; s < m_PolyList.size(); s++) {
361  if (!m_PolyList[s].SanityCheck2()) return false;
362  }
363  return true;
364  }

References m_PolyList.

Referenced by Osmia_Population_Manager::DoBefore().

◆ CreateNest()

Osmia_Nest* Osmia_Nest_Manager::CreateNest ( int  a_x,
int  a_y,
int  a_polyindex 
)
inline

Create the osmia nest here

336  {
337  Osmia_Nest* a_nest = new Osmia_Nest(a_x, a_y,a_polyindex, this);
338  m_PolyList[a_polyindex].IncOsmiaNesting(a_nest);
339  return a_nest;
340  }

References m_PolyList.

Referenced by Osmia_Population_Manager::CreateNest().

◆ GetNestPossible()

bool Osmia_Nest_Manager::GetNestPossible ( TTypesOfLandscapeElement  index)
inline

Is a nest possible in this polytype.

349 { return m_PossibleNestType[int(index)]; }

References m_PossibleNestType.

◆ GetNoNests()

int Osmia_Nest_Manager::GetNoNests ( int  a_polyindex)
inline
351  {
352  return m_PolyList[a_polyindex].GetNoNests();
353  }

References m_PolyList.

Referenced by Osmia_Nest::GetNoNests().

◆ InitOsmiaBeeNesting()

void Osmia_Nest_Manager::InitOsmiaBeeNesting ( )

Read in the Osmia nest density files and allocate to each LE object.

Reads in an input file Ela and provides a max nest number to each instance of LE* in the m_elems vector

851 {
853  array<TTypesOfLandscapeElement, tole_Foobar> tole_ref;
854  array<double, tole_Foobar> maxOsmiaNests;
855  std::fill(maxOsmiaNests.begin(), maxOsmiaNests.end(), 0);
856  array<double, tole_Foobar> minOsmiaNests;
857  std::fill(minOsmiaNests.begin(), minOsmiaNests.end(), 0);
858  fstream ifile(cfg_OsmiaNestByLE_Datafile.value(), ios::in);
859  if (!ifile.is_open()) {
860  g_msg->Warn("Cannot open file: ", cfg_OsmiaNestByLE_Datafile.value());
861  exit(1);
862  }
863  // Read the file tole type by tole type - here we can't rely on the order but need the tole number
864  int length;
865  ifile >> length;
866  if (length != tole_Foobar) {
867  g_msg->Warn("Inconsistent file length with tole_Foobar: ", int(tole_Foobar));
868  exit(1);
869  }
870  // read the file
871  for (int i = 0; i < length; i++)
872  {
873  int toleref;
874  ifile >> toleref >> minOsmiaNests[i] >> maxOsmiaNests[i];
875  tole_ref[i] = g_landscape_ptr->TranslateEleTypes(toleref);
876  if (minOsmiaNests[i] > 0) m_PossibleNestType[tole_ref[i]] = true; else m_PossibleNestType[tole_ref[i]] = false;
877  }
878  ifile.close();
879  unsigned nopolys = g_landscape_ptr->SupplyNumberOfPolygons();
880  OsmiaPolygonEntry ope(0, 0);
881  m_PolyList.resize(nopolys);
882  m_PolyListLocks.resize(nopolys);
883  double totalnests = 0;
884  for (unsigned int e = 0; e < nopolys; e++) {
885  m_PolyListLocks[e] = new omp_nest_lock_t;
886  omp_init_nest_lock(m_PolyListLocks[e]);
887  ope.SetAreaAttribute( int(floor(g_landscape_ptr->SupplyPolygonAreaVector(e)+0.5)));
888  ope.SetIndexAttribute(e);
889  m_PolyList[e] = ope;
891  // first find the eletype
892  int found = -1;
893  for (int j = 0; j < length; j++)
894  {
895  if (tole_ref[j] == eletype) {
896  found = j;
897  break;
898  }
899  }
900  if (found == -1) {
901  g_msg->Warn("Inconsistent file data, missing tole type ref: ", eletype);
902  exit(1);
903  }
904  // We have the ref type, so now calculate the number of nests and set it
905  double n = (minOsmiaNests[found] + double(g_rand_uni_fnc() * (maxOsmiaNests[found] - minOsmiaNests[found])))*0.001;
906  m_PolyList[e].SetMaxOsmiaNests(n); // ***CJT*** Added 0.001 scaler here to reduce densities for debug
907  totalnests += m_PolyList[e].GetMaxNoNests(); // Just to have a record of the max possible nests
908  }
909 }

References cfg_OsmiaNestByLE_Datafile, g_landscape_ptr, g_msg, g_rand_uni_fnc(), m_PolyList, m_PolyListLocks, m_PossibleNestType, OsmiaPolygonEntry::SetAreaAttribute(), OsmiaPolygonEntry::SetIndexAttribute(), Landscape::SupplyElementTypeFromVector(), Landscape::SupplyNumberOfPolygons(), Landscape::SupplyPolygonAreaVector(), tole_Foobar, Landscape::TranslateEleTypes(), CfgStr::value(), and MapErrorMsg::Warn().

Referenced by Osmia_Population_Manager::Init().

◆ IsOsmiaNestPossible()

bool Osmia_Nest_Manager::IsOsmiaNestPossible ( int  a_polyindex)
inline

Find out whether an osmia nest can be made here.

331  {
332  return m_PolyList[a_polyindex].IsOsmiaNestPossible();
333  }

References m_PolyList.

Referenced by Osmia_Population_Manager::IsOsmiaNestPossible().

◆ ReleaseOsmiaNest()

void Osmia_Nest_Manager::ReleaseOsmiaNest ( int  a_polyindex,
Osmia_Nest a_nest 
)
inline

release nest here

343  {
344  omp_set_nest_lock(m_PolyListLocks[a_polyindex]);
345  m_PolyList[a_polyindex].ReleaseOsmiaNest(a_nest);
346  omp_unset_nest_lock(m_PolyListLocks[a_polyindex]);
347  }

References m_PolyList, and m_PolyListLocks.

Referenced by Osmia_Nest::KillAllSubsequentCells(), Osmia_Population_Manager::ReleaseOsmiaNest(), and Osmia_Nest::RemoveCell().

◆ SanityCheck()

bool Osmia_Nest_Manager::SanityCheck ( int  a_polyindex)
inline
355  {
356  return m_PolyList[a_polyindex].SanityCheck();
357  }

References m_PolyList.

Referenced by Osmia_Population_Manager::SantityCheck().

◆ UpdateOsmiaNesting()

void Osmia_Nest_Manager::UpdateOsmiaNesting ( )
inline

Tell all LE objects to update their osmia nest status.

Loops through all landscape element objects and updates their Osmia nesting status

321  {
325  for (unsigned int s = 0; s < m_PolyList.size(); s++) {
326  m_PolyList[s].UpdateOsmiaNesting();
327  }
328  }

References m_PolyList.

Referenced by Osmia_Population_Manager::DoFirst(), and Osmia_Population_Manager::Osmia_Population_Manager().

Member Data Documentation

◆ m_PolyList

◆ m_PolyListLocks

vector<omp_nest_lock_t*> Osmia_Nest_Manager::m_PolyListLocks
protected

◆ m_PossibleNestType

bool Osmia_Nest_Manager::m_PossibleNestType[tole_Foobar]
protected

Holds a set of flags indicating whether an Osmia nest is possible (true) or not (false)

Referenced by GetNestPossible(), and InitOsmiaBeeNesting().


The documentation for this class was generated from the following files:
Landscape::SupplyNumberOfPolygons
unsigned int SupplyNumberOfPolygons(void)
Returns the number of polygons in the landscape.
Definition: Landscape.h:2127
g_rand_uni_fnc
double g_rand_uni_fnc()
Definition: ALMaSS_Random.cpp:56
tole_Foobar
Definition: LandscapeFarmingEnums.h:183
CfgStr::value
char * value() const
Definition: Configurator.h:182
cfg_OsmiaNestByLE_Datafile
static CfgStr cfg_OsmiaNestByLE_Datafile("OSMIA_NESTBYLEDATAFILE", CFG_CUSTOM, "OsmiaNestsByHabitat.txt")
Input file for Osmia nest density per LE.
Osmia_Nest
The Osmia nest is assumed to be a linear element with egg cells added one by one.
Definition: Osmia.h:128
TTypesOfLandscapeElement
TTypesOfLandscapeElement
Values that represent the types of landscape polygon that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:57
Landscape::TranslateEleTypes
TTypesOfLandscapeElement TranslateEleTypes(int EleReference)
Returns element type translated from the ALMaSS reference number.
Definition: Landscape.h:2313
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
g_landscape_ptr
Landscape * g_landscape_ptr
Definition: Landscape.cpp:352
Landscape::SupplyElementTypeFromVector
TTypesOfLandscapeElement SupplyElementTypeFromVector(unsigned int a_index)
Gets the TTypesOfVegetation type of a polygon using the m_elems.
Definition: Landscape.h:1727
Osmia_Nest_Manager::m_PossibleNestType
bool m_PossibleNestType[tole_Foobar]
Holds a set of flags indicating whether an Osmia nest is possible (true) or not (false)
Definition: Osmia_Population_Manager.h:369
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Osmia_Nest_Manager::m_PolyList
vector< OsmiaPolygonEntry > m_PolyList
Definition: Osmia_Population_Manager.h:366
OsmiaPolygonEntry
Is the list of nests held by a polygon and associated density controls.
Definition: Osmia_Population_Manager.h:189
Landscape::SupplyPolygonAreaVector
double SupplyPolygonAreaVector(int a_polyref)
Returns the polygon area of a particular polygon using an index to m_elems.
Definition: Landscape.h:1820
Osmia_Nest_Manager::m_PolyListLocks
vector< omp_nest_lock_t * > m_PolyListLocks
Definition: Osmia_Population_Manager.h:367