The AHA Model  Revision: 12809
Reference implementation 04 (HEDG02_04)
m_env.f90 File Reference

The environmental objects of the AHA Model. More...

Go to the source code of this file.

Data Types

type  the_environment::spatial
 Definition of a spatial object. Spatial object determines the position of the agent, food items and other things in the simulated space. Here we use continuous 3D environment (real type coordinates) More...
 
type  the_environment::spatial_moving
 Definition of a movable spatial object. It extends the the_environment::spatial object, but also adds its previous position history in stack-like arrays. The history is maintained with the commondata::add_to_history() subroutine, adding a single element on the top (end) of the history stack. More...
 
type  the_environment::environment
 Definition of the overall environment. Environment is a general container for all habitats, patches and other similar objects where the whole life of the agents takes place. Environment just provides the limits for all these objects. More...
 
type  the_environment::food_item
 Definition of a single food item. Food item is a spatial object that has specific location in space. It can be "created" and eaten ("disappear"). Food item is an immobile SPATIAL object that has a position in 3D space. More...
 
type  the_environment::food_resource
 Definition of the super-type FOOD resource type. This is a superclass, several sub-classes can be defined for different kinds of food and prey objects. More...
 
type  the_environment::predator
 Definition of the PREDATOR objects. Predator is a moving agent that hunts on the evolving AHA agents but its internal structure is very simplistic (although we can in principle doit as a full AHA complexity with genome, GOS etc...). More...
 
type  the_environment::habitat
 Definition of the environment habitat HABITAT object. There can potentially be of several types of habitats (patches etc.), so the superclass HABITAT defines the most general properties and procedures. More specific procedures are defined in sub-objects. Such procedures can be overriden from super-object to sub-objects providing for procedure polymorphism. More...
 
interface  the_environment::light_surface
 Calculate surface light intensity (that is subject to diel variation) for specific time step of the model. Irradiance can be stochastic if an optionallogical stochastic flag is set to TRUE. More...
 
interface  the_environment::light_depth
 Calculate underwater background irradiance at specific depth. More...
 
interface  the_environment::visual_range
 Calculate visual range of predator using Dag Aksnes's procedures srgetr(), easyr() and deriv(). More...
 
interface  the_environment::visual_range_new
 Calculate visual range of predator using Dag Aksnes's procedures srgetr(), easyr() and deriv(). More...
 
interface  the_environment::dist
 Internal distance calculation backend engine. More...
 
interface  the_environment::join
 An alias for the the_environment::food_resources_collapse_global_object() method for joining food resources into a single global food resource out of the global array the_environment::global_habitats_available. See the_environment::unjoin() for how to unjoin an array of food resources back into an array. More...
 
interface  the_environment::unjoin
 An alias to the_environment::food_resources_update_back_global_object() method to transfer (having been modified) food resource objects out from the single united object back to the global array the_environment::global_habitats_available. See the_environment::join() for how to join an array of food resources into a single global object. More...
 
interface  the_environment::assemble
 Interface to the procedure to assemble the global array of habitat objects the_environment::global_habitats_available from a list of separate habitat object components. This call. More...
 
interface  the_environment::disassemble
 Interface to the procedure to disassemble the global habitats objects array the_environment::global_habitats_available back into separate habitat object components. See the_environment::global_habitats_disassemble() for the backend implementation. More...
 
interface  the_environment::operator(.cat.)
 Interface operator to concatenate two arrays of the spatial the_environment::spatial or spatial moving the_environment::spatial_moving objects. More...
 
interface  the_environment::operator(.catloc.)
 Interface operator to concatenate the location components of two arrays ofthe_environment::spatial class objects. More...
 
interface  the_environment::operator(.within.)
 Interface operators .within. for testing whether a spatial object (first argument lies within an environment (second argument). Usage: More...
 
interface  the_environment::operator(.contains.)
 Interface operators .contains. for testing whether an environment object (first argument) contains a SPATIAL object (second argument). Usage: More...
 
interface  the_environment::operator(.above.)
 Interface operators .above. for spatial objects. Usage: More...
 
interface  the_environment::operator(.below.)
 Interface operators .below. for spatial objects. Usage: More...
 
interface  the_environment::operator(-)
 Interface operator "-" for the the_environment::environment spatial container objects. Return an environment object that is shrunk by a fixed value in the 2D XxY plane. See the_environment::environment_shrink_xy_fixed(). The operator can be used as follows: More...
 

Modules

module  the_environment
 Definition of environmental objects.
 

Functions/Subroutines

elemental subroutine the_environment::spatial_create_empty (this)
 These are public access functions, but probably we don't need to allow public access to functions inside generic interfaces. More...
 
subroutine the_environment::environment_whole_build_vector (this, min_coord, max_coord)
 Create the highest level container environment. Set the size of the 3D environment container as two coordinate vectors setting the minimum and maximum coordinate limits: min_coord(1) for x, min_coord(2) for y, min_coord(3) for z The size of the environment should be set from parameter vectors in COMMONDATA. More...
 
subroutine the_environment::environment_whole_build_object (this, min_coord, max_coord)
 Create the highest level container environment. Set the size of the 3D environment container as two coordinate vectors setting the minimum and maximum coordinate limits. The parameters min_coord and max_coord are SPATIAL objects. More...
 
subroutine the_environment::environment_build_unlimited (this)
 Build an unlimited environment, with the spatial coordinates limited by the maximum machine supported values based on the intrinsic huge function. More...
 
type(environment) function the_environment::environment_shrink_xy_fixed (this, shrink_value)
 Return an environment object that is shrunk by a fixed value in the 2D XxY plane. More...
 
type(spatial) function the_environment::environment_get_minimum_obj (this)
 Function to get the minimum spatial limits (coordinates) of the environment. More...
 
type(spatial) function the_environment::environment_get_maximum_obj (this)
 Function to get the maximum spatial limits (coordinates) of the environment. More...
 
elemental real(srp) function the_environment::environment_get_minimum_depth (this)
 Get the minimum depth in this environment. More...
 
elemental real(srp) function the_environment::environment_get_maximum_depth (this)
 Get the maximum depth in this environment. More...
 
pure type(spatial) function, dimension(dim_environ_corners) the_environment::environment_get_corners_2dxy (this, ref_depth, offset)
 Get the corners of the environment in the 2D X Y plane. This is a very simplistic procedure that works only with the box environmental objects. More...
 
elemental logical function the_environment::environment_check_located_within_3d (this, check_object)
 Check if a spatial object is actually within this environment. More...
 
type(spatial) function the_environment::environment_random_uniform_spatial_3d (this)
 Generate a random spatial object with the uniform distribution within (i.e. bound to) this environment. More...
 
type(spatial) function the_environment::environment_random_uniform_spatial_2d (this, fixdepth)
 Generate a random spatial object with the uniform distribution within (i.e. bound to) this environment, the third depth coordinate is fixed. More...
 
type(spatial) function, dimension(num) the_environment::environment_random_uniform_spatial_vec_3d (this, num)
 Generate a vector of random spatial objects with the uniform distribution within (i.e. bound to) this environment. More...
 
type(spatial) function, dimension(size(fixdep_array)) the_environment::environment_random_uniform_spatial_vec_2d (this, fixdep_array)
 Generate a vector of random spatial objects with the uniform distribution within (i.e. bound to) this environment. The third, depth coordinate is non-stochastic, and provided as an array parameter. More...
 
type(spatial) function, dimension(num) the_environment::environment_random_gaussian_spatial_3d (this, num, centroid, variance)
 Generates a vector of random spatial object with Gaussian coordinates within (i.e. bound to) this environment. More...
 
type(spatial) function, dimension(num) the_environment::environment_random_gaussian_spatial_2d (this, num, centroid, fixdepth, variance, variance_depth)
 Generates a vector of random spatial object with Gaussian coordinates within (i.e. bound to) this environment. The depth coordinate is set separately and can be non-random (fixed for the whole output array) or Gaussian with separate variance. More...
 
type(spatial) function centroid_urandom (fixed_depth)
 Make a random centroid with fixed depth bound within this environment. More...
 
subroutine the_environment::environment_get_nearest_point_in_outside_obj (this, outside_object, offset_into, point_spatial, point_dist)
 Get the spatial point position within this environment that is nearest to an arbitrary spatial object located outside of the this environment. If the spatial object is actually located in this environment, return its own position. More...
 
subroutine the_environment::spatial_fix_position_3d_s (this, x, y, depth)
 Place spatial object into a 3D space, define the object's current coordinates. More...
 
elemental subroutine the_environment::spatial_fix_position_3d_o (this, location)
 Place spatial object into a 3D space, define the object's current coordinates. More...
 
elemental subroutine the_environment::spatial_make_missing (this)
 Assign all commondata::missing` coordinates to the_environment::spatial object. More...
 
elemental type(spatial) function the_environment::spatial_get_current_pos_3d_o (this)
 Get the current spatial position of a SPATIAL object. More...
 
pure real(srp) function, dimension(dimensionality_default) the_environment::spatial_get_current_pos_3d_v (this, vector)
 Get the current spatial position of a SPATIAL object. More...
 
elemental real(srp) function the_environment::spatial_get_current_pos_x_3d (this)
 Get the current X position of a SPATIAL object. More...
 
elemental real(srp) function the_environment::spatial_get_current_pos_y_3d (this)
 Get the current Y position of a SPATIAL object. More...
 
elemental real(srp) function the_environment::spatial_get_current_pos_d_3d (this)
 Get the current DEPTH position of a SPATIAL object. More...
 
real(srp) function the_environment::spatial_calc_irradiance_at_depth (this, time_step_model)
 Calculate the illumination (background irradiance) at the depth of the spatial object at an arbitrary time step of the model. More...
 
real(srp) function the_environment::spatial_visibility_visual_range_cm (this, object_area, contrast, time_step_model)
 Calculate the visibility range of a spatial object. Wrapper to the the_environment::visual_range() function. This function calculates the distance from which this object can be seen by a visual object (e.g. predator or prey). More...
 
pure integer function the_environment::spatial_get_environment_in_pos (this, environments_array)
 Identify in which environment from the input list this spatial agent is currently in. Example call: More...
 
subroutine the_environment::spatial_moving_fix_position_3d_v (this, x, y, depth)
 Place spatial movable object into a 3D space, define the object's current coordinates, but first save previous coordinates. More...
 
elemental subroutine the_environment::spatial_moving_fix_position_3d_o (this, location)
 Place spatial movable object into a 3D space, define the object's current coordinates, but first save previous coordinates. More...
 
elemental subroutine the_environment::spatial_moving_repeat_position_history_3d (this)
 Repeat (re-save) the current position into the positional history stack. More...
 
elemental real(srp) function the_environment::spatial_distance_3d (this, other)
 Calculate the Euclidean distance between two spatial objects. This is a type-bound function. More...
 
pure type(spatial) function, dimension(:), allocatable the_environment::spatial_stack2arrays (a, b)
 Concatenate two arrays of the_environment::spatial objects a and b. This procedure uses array slices which would be faster in most cases than the intrinsic [a,b] method. More...
 
pure type(spatial_moving) function, dimension(:), allocatable the_environment::spatial_moving_stack2arrays (a, b)
 Concatenate two arrays of the_environment::spatial_moving objects a and b. This procedure uses array slices which would be faster in most cases than the intrinsic [a,b] method. More...
 
pure type(spatial) function, dimension(:), allocatable the_environment::spatial_class_stack2arrays_locs (a, b)
 Concatenate the location components of two arrays of the_environment::spatial class objects a and b. This procedure uses array slices which would be faster in most cases than the intrinsic [a,b] method. More...
 
elemental real(srp) function the_environment::dist3d (this, other)
 This is a non-type-bound version of the distance calculation function. More...
 
elemental real(srp) function the_environment::spatial_self_distance_3d (this, from_history)
 Calculate the Euclidean distance between the current and previous position of a single spatial object. More...
 
elemental real(srp) function the_environment::spatial_moving_self_distance_3d (this, from_history)
 Calculate the Euclidean distance between the current and previous position of a single spatial movable object. Optionally, it also calculates the total distance traversed during the from_history points from the history stack along with the distance from the current position and the last historical value. For example, to calculate the average distance throughout the whole history (HISTORY_SIZE_SPATIAL points) do this: More...
 
elemental subroutine the_environment::spatial_moving_create_3d (this)
 Create a new spatial moving object. Initially it has no position, all coordinate values are MISSING or INVALID for real type coordinates. More...
 
elemental subroutine the_environment::spatial_moving_clean_hstory_3d (this)
 Create a new empty history of positions for spatial moving object. Assign all values to the MISSING value code. More...
 
elemental subroutine the_environment::spatial_moving_go_up (this, step)
 The spatial moving object ascends, goes up the depth with specific fixed step size. More...
 
elemental subroutine the_environment::spatial_moving_go_down (this, step)
 The spatial moving object decends, goes down the depth with specific fixed step size. More...
 
subroutine the_environment::spatial_moving_randomwalk_gaussian_step_3d (this, meanshift, cv_shift, environment_limits)
 Implements an optionally environment-restricted Gaussian random walk in 3D. More...
 
subroutine the_environment::spatial_moving_randomwalk_gaussian_step_25d (this, meanshift_xy, cv_shift_xy, meanshift_depth, cv_shift_depth, environment_limits)
 Implements an optionally environment-restricted Gaussian random walk in a "2.5 dimensions", i.e. 2D x y with separate walk parameters for the third depth dimension. More...
 
subroutine the_environment::spatial_moving_corwalk_gaussian_step_3d (this, target, meanshift, cv_shift, is_away, ci_lim, environment_limits, is_converged, debug_reps)
 Implements an optionally environment-restricted correlated directional Gaussian random walk in 3D towards (or away of) an the_environment::spatial class target object. More...
 
subroutine the_environment::spatial_moving_corwalk_gaussian_step_25d (this, target, meanshift_xy, cv_shift_xy, meanshift_depth, cv_shift_depth, is_away, ci_lim, environment_limits, is_converged, debug_reps)
 Implements an optionally environment-restricted correlated directional Gaussian random walk in 3D towards (or away of) an the_environment::spatial class target object. More...
 
subroutine the_environment::spatial_moving_dirwalk_gaussian_step_3d (this, target, meanshift, cv_shift, environment_limits)
 Implements an optionally environment-restricted directional Gaussian random walk in 3D towards a target the_environment::spatial class object. More...
 
real(srp) function updated_position (coord_target, coord_object)
 Calculate a Gaussian random updated coordinate for multidimensional Gaussian targeted random walk along any of the dimensions. The dalta shift has value and variance but may be either forward or backward so as to minimise the distance from the target. More...
 
subroutine the_environment::spatial_moving_dirwalk_gaussian_step_25d (this, target, meanshift_xy, cv_shift_xy, meanshift_depth, cv_shift_depth, environment_limits)
 Implements an optionally environment-restricted directional Gaussian random walk in "2.5"-D towards a target the_environment::spatial class object. i.e. 2D x y with separate walk parameters for the third depth dimension. More...
 
real(srp) function updated_position (coord_target, coord_object, meanshift, cv_shift)
 Calculate a Gaussian random updated coordinate for multidimensional Gaussian targeted random walk along any of the dimensions. The dalta shift has value and variance but may be either forward or backward so as to minimise the distance from the target. More...
 
subroutine the_environment::rwalk3d_array (this, dist_array, cv_array, dist_all, cv_all, environment_limits, n_walks)
 Perform one or several steps of random walk by an array of the_environment::spatial_moving class objects. This is a 3D version with the same walk parameters for the horizontal XxY plane and depth. More...
 
subroutine the_environment::rwalk25d_array (this, dist_array_xy, cv_array_xy, dist_array_depth, cv_array_depth, dist_all_xy, cv_all_xy, dist_all_depth, cv_all_depth, environment_limits, n_walks)
 Perform one or several steps of random walk by an array of the_environment::spatial_moving class objects. This is a 2.5D version with separate walk parameters for the horizontal XxY plane and depth. More...
 
elemental logical function the_environment::spatial_check_located_within_3d (this, environment_limits)
 Function to check if this spatial object is located within an area set by an environmental object (parameter). This should be similar to an analogous function defined for the environment object. More...
 
elemental logical function the_environment::spatial_check_located_below (this, check_object)
 Logical function to check if the argument spatial object(s) (check_object) is (are) located below the this reference spatial object. Elemental function that also works with arrays. Use as: More...
 
elemental logical function the_environment::spatial_check_located_above (this, check_object)
 Logical function to check if the argument spatial object(s) (check_object) is (are) located above the this reference spatial object. Elemental function that also works with arrays. Use as: More...
 
type(spatial) function the_environment::spatial_get_nearest_object (this, neighbours, number)
 Determine the nearest spatial object to this spatial object among an array of other spatial objects. More...
 
integer function the_environment::spatial_get_nearest_id (this, neighbours, object)
 Determine the nearest spatial object to this spatial object among an array of other spatial objects. More...
 
subroutine the_environment::habitat_make_init (this, coord_min, coord_max, label, otherrisks, eggmortality, predators_number, loc_predators, food_abundance, loc_food, sizes_food)
 Make an instance of the habitat object (an environment superset). More...
 
character(len=label_length) function the_environment::habitat_name_get (this)
 Return the name of the habitat. More...
 
real(srp) function the_environment::habitat_get_risk_mortality (this)
 Get the mortality risk associated with this habitat. More...
 
real(srp) function the_environment::habitat_get_risk_mortality_egg (this)
 Get the egg mortality risk associated with this habitat. More...
 
subroutine the_environment::habitat_save_predators_csv (this, csv_file_name, is_success)
 Save the predators with their characteristics into a CSV file. More...
 
subroutine the_environment::save_dynamics (maxdepth, csv_file_name, is_success)
 Save diagnostics data that shows the dynamics of the light and the average depth of the food items, light at the average depth of the food items etc at each time step of the model. More...
 
type(spatial) function the_environment::environment_centre_coordinates_3d (this, nodepth)
 Determine the centroid of the environment. More...
 
real(srp) function, private the_environment::visual_range_scalar (irradiance, prey_area, prey_contrast)
 Wrapper for calculating visual range of a fish predator using the Dag Aksnes's procedures srgetr(), easyr() and deriv(). See srgetr() for computational details. More...
 
real(srp) function, dimension(size(prey_area)), private the_environment::visual_range_vector (irradiance, prey_area, prey_contrast_vect, prey_contrast)
 Wrapper for calculating visual range of a fish predator using the Dag Aksnes's procedures srgetr(), easyr() and deriv(). See srgetr() for computational details. More...
 
elemental real(srp) function the_environment::visual_range_fast (irradiance, prey_area, prey_contrast)
 Wrapper for calculating visual range of a fish predator using the Dag Aksnes's procedures srgetr(), easyr() and deriv(). This is a new elemental and parallel-ready visual range function wrapper making use the elemental-procedures based computational backend. See notes on visual_range_scalar() and srgetr() for computational details. More...
 
elemental real(srp) function, private the_environment::light_surface_deterministic (tstep)
 Calculate deterministic surface light at specific time step of the model. Light (surlig) is calculated from a sine function. Light intensity just beneath the surface is modelled by assuming a 50 % loss by scattering at the surface: More...
 
real(srp) function, private the_environment::light_surface_stochastic_scalar (tstep, is_stochastic)
 Calculate stochastic surface light at specific time step of the model. Light (surlig) is calculated from a sine function. Light intensity just beneath the surface is modelled by assuming a 50 % loss by scattering at the surface: More...
 
real(srp) function, dimension(size(tstep)), private the_environment::light_surface_stochastic_vector (tstep, is_stochastic)
 Calculate stochastic surface light at specific time step of the model. More...
 
real(srp) function, private the_environment::light_depth_integer (depth, surface_light, is_stochastic)
 Calculate underwater light at specific depth given specific surface light. More...
 
real(srp) function, private the_environment::light_depth_real (depth, surface_light, is_stochastic)
 Calculate underwater light at specific depth given specific surface light. More...
 
elemental real(srp) function the_environment::dist_scalar (x1, x2, y1, y2, z1, z2)
 Calculate distance between 3D or 2D points. This is a function engine for use within type bound procedures. Example (dist_scalar): More...
 
pure real(srp) function the_environment::dist_vector_nd (cvector1, cvector2)
 Calculate distance between N-dimensional points. This is a function engine for use within other type bound procedures. More...
 
pure real(srp) function the_environment::dist2_vector (cvector1, cvector2)
 Calculate the squared distance between two N-dimensional points. More...
 
pure real(srp) function the_environment::vect_magnitude (vector)
 Calculate the magnitude of an arbitrary N-dimensional vector. This is a raw vector backend. More...
 
elemental real(srp) function the_environment::dist2step (average_distance, dimensionality)
 Calculate the unit step along a single coordinate axis given the average distance between any two points in a N-dimensional Gaussian random walk. More...
 
elemental subroutine the_environment::food_item_create (this)
 Create a single food item at an undefined position with default size. More...
 
elemental subroutine the_environment::food_item_make (this, location, size, iid)
 Make a single food item, i.e. place it into a specific position in the model environment space and set the size. More...
 
logical function the_environment::food_item_capture_success_stochast (this, prob)
 Stochastic outcome of this food item capture by an agent. Returns TRUE if the food item is captured. More...
 
real(srp) function the_environment::food_item_capture_probability_calc (this, distance, time_step_model)
 Calculate the probability of capture of this food item by a predator agent depending on the distance between the agent and this food item. More...
 
real(srp) function the_environment::food_item_visibility_visual_range (this, object_area, contrast, time_step_model)
 Calculate the visibility range of this food item. Wrapper to the the_environment::visual_range() function. This function calculates the distance from which this food item can be seen by a predator (i.e. the default predator's visual range). More...
 
real(srp) function the_environment::minimum_depth_visibility (target_range, depth_range_min, depth_range_max, object_area, object_contrast, time_step_model)
 Find the depth at which the visibility of a spatial object becomes smaller than a specific distance value target_range. More...
 
real(srp) function visibility_loc (depth)
 This function calculates the visibility range of the spatial object at the depth given by the argument depth. This function is internal to the_environment::minimum_depth_visibility(). More...
 
real(srp) function visibility_loc_diff (depth)
 This is a wrapper function that calculates the visibility range minus target minimum distance. This function is internal to the_environment::minimum_depth_visibility(). More...
 
elemental subroutine the_environment::food_item_disappear (this)
 Make the food item "disappear" and take the "eaten" state, i.e. impossible for consumption by the agents. More...
 
elemental logical function the_environment::food_item_is_eaten_unavailable (this)
 Logical check-indicator function for the food item being eaten and not available. More...
 
elemental logical function the_environment::food_item_is_available (this)
 Logical check-indicator function for the food item being available. More...
 
elemental real(srp) function the_environment::food_item_get_size (this)
 Get the size component of the food item object. More...
 
elemental real(srp) function the_environment::size2mass_food (radius)
 Calculate the mass of a food item, the non-OO backend. More...
 
elemental real(srp) function the_environment::mass2size_food (mass)
 Calculate the size (radius) of a food item, a reverse function of the_environment::size2mass_food(): More...
 
elemental real(srp) function the_environment::food_item_get_mass (this)
 Calculate and get the mass of the food item. More...
 
elemental subroutine the_environment::food_item_set_iid (this, iid)
 Set unique id for the food item object. More...
 
elemental subroutine the_environment::food_item_clone_assign (this, the_other)
 Clone the properties of this food item to another food item. More...
 
elemental integer function the_environment::food_item_get_iid (this)
 Get the unique id of the food item object. More...
 
pure subroutine the_environment::food_resource_make (this, label, abundance, locations, sizes)
 Make food resource object. This class standard constructor. More...
 
elemental integer function the_environment::food_resource_get_abundance (this)
 Get the number of food items in the food resource. More...
 
elemental character(len=label_length) function the_environment::food_resource_get_label (this)
 Get the label of the this food resource. More...
 
pure subroutine the_environment::food_resource_destroy_deallocate (this)
 Delete and deallocate food resource object. This class standard destructor. More...
 
pure type(spatial) function, dimension(size(this%food)) the_environment::food_resource_locate_3d (this)
 Get the location object array (array of SPATIAL objects) of a food resource object. More...
 
real(srp) function the_environment::food_resource_calc_average_distance_items (this, n_sample)
 Calculate the average distance between food items within a resource. e.g. to compare it with the agent's random walk step size. More...
 
subroutine the_environment::food_resource_replenish_food_items_all (this, replace)
 Replenish and restore food resource. The food resource is replenished by substituting randomly selected replace food items or all items if replace is omitted or exceeds the actual number of food items. Unlike the the_environment::food_resource::make() method, the sizes and the positions of the food items within the resource are reused from the previous positions (previously explicitly set set by the the_environment::food_resource::make() method). More...
 
subroutine the_environment::food_resource_migrate_move_items (this, max_depth, time_step_model)
 This subroutine implements the migration of all the food items in the resource according to the plankton migration pattern from the G1 model (HED18). Briefly, the movement of each of the food items has two components: More...
 
subroutine the_environment::food_resource_rwalk_items_default (this)
 Perform a random walk step for all food items within the food resource. The walk is performed with the default parameters: More...
 
subroutine the_environment::migrate_food_vertical (habitats, time_step_model)
 Migrate food items in a whole array of food resources. The array is normally the the_environment::global_habitats_available. More...
 
subroutine the_environment::rwalk_food_step (habitats)
 Perform a random walk of food items in a whole array of food resources. The array is normally the the_environment::global_habitats_available. This procedure is a wrapper for the_environment::food_resource::rwalk() to do a walk on a whole array of habitats and linked food resources. More...
 
real(srp) function the_environment::center_depth_sinusoidal (tstep, depth)
 This function calculates the target depth for the sinusoidal vertical migration pattern of the food items at each time step of the model. See the_environment::food_resource_migrate_move_items() for the calling procedure. More...
 
subroutine the_environment::food_resource_save_foods_csv (this, csv_file_name, is_success)
 Save characteristics of food items in the resource into a CSV file. More...
 
elemental subroutine the_environment::food_resource_sort_by_size (this, reindex)
 Sort the food resource objects within the array by their sizes. The two subroutines below are a variant of the recursive quick-sort algorithm adapted for sorting real components of the the FOOD_RESOURCE object. More...
 
recursive pure subroutine qsort (A)
 qsort and qs_partition_ are the two parts of the recursive sort algorithm qsort is the recursive frontend. Sorts an array of food items by size within the resource object. More...
 
pure subroutine qs_partition_size (A, marker)
 qsort and qs_partition_ are the two parts of the recursive sort algorithm qs_partition_size is a pivot backend, here it sorts food items within the food resource object by real size components. More...
 
pure subroutine the_environment::food_resource_reset_iid_all (this, start_iid)
 Reset individual iid for the food resource. Individual iids must normally coincide with the array order index. If it is changed after sorting, iids no longer reflect the correct index. So this subroutine resets iids to be coinciding with each food item index. More...
 
subroutine the_environment::reindex_food_resources (resource_1, resource_2, resource_3, resource_4, resource_5, resource_6, resource_7, resource_8, resource_9, resource_10, resource_11, resource_12, resource_13, resource_14, resource_15, resource_16, resource_17, resource_18, resource_19, resource_20)
 Reset and reindex iids for an input list of several food resources. As the result of this subroutine all food items across all the resources within the whole list will have unique iids. More...
 
subroutine the_environment::food_resources_collapse (food_resource_collapsed, resource_1, resource_2, resource_3, resource_4, resource_5, resource_6, resource_7, resource_8, resource_9, resource_10, resource_11, resource_12, resource_13, resource_14, resource_15, resource_16, resource_17, resource_18, resource_19, resource_20, reindex, label)
 Collapse several food resources into one. The collapsed resource can then go into the perception system. The properties of the component resources are retained in the collapsed resource. More...
 
type(food_resource) function the_environment::food_resources_collapse_global_object (reindex, label)
 Join food resources into a single global food resource out of the global array the_environment::global_habitats_available. See the_environment::unjoin() for how to unjoin an array of food resources back into an array. The joined resource can then go into the perception system. The properties of the component resources are retained in the collapsed resource. More...
 
subroutine the_environment::food_resources_update_back (food_resource_collapsed, resource_1, resource_2, resource_3, resource_4, resource_5, resource_6, resource_7, resource_8, resource_9, resource_10, resource_11, resource_12, resource_13, resource_14, resource_15, resource_16, resource_17, resource_18, resource_19, resource_20, reindex)
 Transfer back the resulting food resources into their original objects out from a collapsed object from food_resources_collapse. More...
 
subroutine the_environment::food_resources_update_back_global_object (food_resource_collapsed, reindex)
 Transfer the (having been modified) food resource objects from the single united object food_resource_collapsed back to the global array the_environment::global_habitats_available array. See the_environment::join() for how to join an array of food resources into a single global object. More...
 
subroutine the_environment::global_habitats_assemble (habitat_1, habitat_2, habitat_3, habitat_4, habitat_5, habitat_6, habitat_7, habitat_8, habitat_9, habitat_10, habitat_11, habitat_12, habitat_13, habitat_14, habitat_15, habitat_16, habitat_17, habitat_18, habitat_19, habitat_20, reindex)
 Assemble the global habitats objects array the_environment::global_habitats_available from a list of separate habitat objects. This call. More...
 
subroutine the_environment::global_habitats_disassemble (habitat_1, habitat_2, habitat_3, habitat_4, habitat_5, habitat_6, habitat_7, habitat_8, habitat_9, habitat_10, habitat_11, habitat_12, habitat_13, habitat_14, habitat_15, habitat_16, habitat_17, habitat_18, habitat_19, habitat_20, reindex)
 Disassemble the global habitats objects array the_environment::global_habitats_available into separate habitat object. More...
 
subroutine the_environment::spatial_neighbours_distances (this, neighbours, dist, index_vector, ranks, rank_max, error_flag)
 Calculate the distances between this spatial object and an array of its neighbours. Optionally output the distances, sorting index vector and rankings vector for each of these neighbours. Optionally do only partial indexing, up to the order rank_max for computational speed. Procedure ARRAY_INDEX() from HEDTOOLS is used as the computational backend for partial segmented indexing. More...
 
elemental subroutine the_environment::predator_make_init (this, body_size, attack_rate, position, label)
 Initialise a predator object. More...
 
subroutine the_environment::predator_label_set (this, label)
 Set label for the predator, if not provided, set it random. More...
 
elemental real(srp) function the_environment::predator_get_body_size (this)
 Accessor function for the predator body size (length). More...
 
elemental real(srp) function the_environment::predator_get_attack_rate (this)
 Accessor function for the predator attack rate. More...
 
real(srp) function the_environment::predator_capture_risk_calculate_fish (this, prey_spatial, prey_length, prey_distance, is_freezing, time_step_model, debug_plot_file)
 Calculates the risk of capture of the fish with the spatial location defined by prey_spatial and the body length equal to prey_length. This is a backend function bound to the predator rather than prey object. More...
 
subroutine the_environment::predator_capture_risk_calculate_fish_group (this, prey_spatial, prey_length, is_freezing, time_step_model, risk, risk_indexed, index_dist)
 Calculates the risk of capture by a specific predator of an array of the fish agents with the spatial locations array defined by prey_spatial and the body length array prey_length. This subroutine takes account of both the predator dilution and confusion effects and risk adjusted by the distance towards the predator. More...
 
subroutine adjust_risk_nonpar_noadjust ()
 Adjust the predation risk for confusion and dilution effects. More...
 
subroutine adjust_risk_nonpar_fixed ()
 Adjust the predation risk for confusion and dilution effects. More...
 
subroutine adjust_risk_dilute_nofirst ()
 Adjust the predation risk of a group of N prey agents for predator dilution effect. More...
 
subroutine adjust_risk_dilute_all ()
 Adjust the predation risk of a group of N prey agents for predator dilution effect. More...
 
real(srp) function the_environment::predator_visibility_visual_range (this, object_area, contrast, time_step_model)
 Calculate the visibility range of this predator. Wrapper to the the_environment::visual_range() function. This function calculates the distance from which this predator can be seen by a visual object (e.g. the agent). More...
 
real(srp) function the_environment::distance_average (spatial_objects, sample_size)
 Calculates the average nearest neighbour distance amongst an array of spatial objects (class) by sampling sample_size of them. The sample size sample_size is optional, if not provided set to SAMPLE_SIZE_DEFAULT=25. More...
 
Visual range calculation backend.

The subroutines the_environment::srgetr(), the_environment::easyr() and the_environment::deriv() should be better isolated into a separate module or form a submodule, but it is not used here as submodules are a F2008 feature not supported by all compiler systems. Anyway, submodule is not essential here.

Note
Note that all these backend procedures are now pure and therefore parallel-safe.
elemental subroutine, private the_environment::srgetr (r, c, C0, Ap, Vc, Ke, Eb, IER)
 Obtain visual range by solving the non-linear equation by means of Newton-Raphson iteration and derivation in subroutine the_environment::deriv(). Initial value is calculated in the_environment::easyr(). The calculation is based on the model described in Aksnes & Utne (1997) Sarsia 83:137-147. More...
 
elemental subroutine, private the_environment::easyr (r, C0, Ap, Vc, Ke, Eb)
 Obtain a first estimate of visual range by using a simplified expression of visual range. See srgetr() for more details. More...
 
elemental subroutine, private the_environment::deriv (r, F1, FDER, c, C0, Ap, Vc, Ke, Eb)
 Derivation of equation for visual range of a predator. See the_environment::srgetr() for more details. More...
 
Computational geometry backend: <strong>polygon2D</strong>

Rudimentary computational geometry (geo_) procedures, based on 2D polygons (poly2d) with fixed depth or depth ignored.

Note
Manually constructed using 2D X x Y vectors ignoring the depth dimension.
subroutine the_environment::geo_poly2d_dist_point_to_section (point, sectp1, sectp2, min_dist, point_segment)
 Calculates the minimum distance from a the_environment::spatial class object to a line segment delimited by two the_environment::spatial class endpoints in the 2D XY plane (the depth coordinate is ignored). (The algorithm is partially based on this.) More...
 
subroutine the_environment::geo_poly3d_dist_point_to_section (point, sectp1, sectp2, min_dist, point_segment)
 Calculates the minimum distance from a the_environment::spatial class object to a line segment delimited by two the_environment::spatial class endpoints in the 3D XY space. (The algorithm is partially based on this.) More...
 
type(spatial) function the_environment::offset_dist (obj_a, obj_b, offset)
 Calculate a the_environment::spatial target with an offset. More...
 

Variables

character(len= *), parameter, private the_environment::modname = "(THE_ENVIRONMENT)"
 
integer, parameter, private the_environment::dimensionality_default = 3
 Default dimensionality of the environment universe. More...
 
integer, parameter the_environment::dim_environ_corners = 4
 The number of corners for an environment object in the 2D X*x*Y plane. More...
 
type(habitat), dimension(:), allocatable, public the_environment::global_habitats_available
 A list (array) of all the the_environment::habitat objects available to the agents. This single array should encompass all the locations that the agent can potentially be in (e.g. migrate from one to another). More...
 

Detailed Description

The environmental objects of the AHA Model.

Author
Sergey Budaev serge.nosp@m.y.bu.nosp@m.daev@.nosp@m.uib..nosp@m.no
Jarl Giske jarl..nosp@m.gisk.nosp@m.e@uib.nosp@m..no
Date
2016-2017

Definition in file m_env.f90.

Function/Subroutine Documentation

◆ centroid_urandom()

type(spatial) function environment_random_gaussian_spatial_2d::centroid_urandom ( real(srp), optional  fixed_depth)

Make a random centroid with fixed depth bound within this environment.

Definition at line 1596 of file m_env.f90.

Here is the caller graph for this function:

◆ updated_position() [1/2]

real(srp) function spatial_moving_dirwalk_gaussian_step_3d::updated_position ( real(srp), intent(in)  coord_target,
real(srp), intent(in)  coord_object 
)

Calculate a Gaussian random updated coordinate for multidimensional Gaussian targeted random walk along any of the dimensions. The dalta shift has value and variance but may be either forward or backward so as to minimise the distance from the target.

Returns
Updated coordinate.
Parameters
[in]coord_targetcoord_target axis-bound coordinate of the target.
coord_objectactual axis-bound coordinate of the moving spatial object.
[in]coord_objectcoord_target axis-bound coordinate of the target.
coord_objectactual axis-bound coordinate of the moving spatial object.

Definition at line 3349 of file m_env.f90.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ updated_position() [2/2]

real(srp) function spatial_moving_dirwalk_gaussian_step_25d::updated_position ( real(srp)  coord_target,
real(srp)  coord_object,
real(srp)  meanshift,
real(srp)  cv_shift 
)

Calculate a Gaussian random updated coordinate for multidimensional Gaussian targeted random walk along any of the dimensions. The dalta shift has value and variance but may be either forward or backward so as to minimise the distance from the target.

Returns
Updated coordinate.
Parameters
coord_targetcoord_target axis-bound coordinate of the target.
coord_objectactual axis-bound coordinate of the moving spatial object.
coord_objectcoord_target axis-bound coordinate of the target.
coord_objectactual axis-bound coordinate of the moving spatial object.

Implementation details

We first check if the axis-bound distance between the object and the target is less then the mean shift...

If so, we have now reached the target successfully.

If not, first calculate a Gaussian random shift along this coordinate, the absolute value.

Then we should make sure the object is actually approaching the target. So we choose the direction that minimises the new coordinate-bound distance between the object and the target.

Definition at line 3479 of file m_env.f90.

Here is the call graph for this function:

◆ visibility_loc()

real(srp) function minimum_depth_visibility::visibility_loc ( real(srp), intent(in)  depth)

This function calculates the visibility range of the spatial object at the depth given by the argument depth. This function is internal to the_environment::minimum_depth_visibility().

Calculate ambient illumination / irradiance at the depth of this food item at the given time step.

Return the visibility range for this spatial object.

Definition at line 6216 of file m_env.f90.

Here is the caller graph for this function:

◆ visibility_loc_diff()

real(srp) function minimum_depth_visibility::visibility_loc_diff ( real(srp), intent(in)  depth)

This is a wrapper function that calculates the visibility range minus target minimum distance. This function is internal to the_environment::minimum_depth_visibility().

Parameters
[in]depthdepth the depth of the spatial object.

Definition at line 6242 of file m_env.f90.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qsort()

recursive pure subroutine food_resource_sort_by_size::qsort ( type(food_item), dimension(:), intent(inout)  A)

qsort and qs_partition_ are the two parts of the recursive sort algorithm qsort is the recursive frontend. Sorts an array of food items by size within the resource object.

Parameters
<tt>A</tt>has the same type as the individual component objects of the array-object that we are going to sort.

Definition at line 7013 of file m_env.f90.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qs_partition_size()

pure subroutine food_resource_sort_by_size::qs_partition_size ( type(food_item), dimension(:), intent(inout)  A,
integer, intent(out)  marker 
)

qsort and qs_partition_ are the two parts of the recursive sort algorithm qs_partition_size is a pivot backend, here it sorts food items within the food resource object by real size components.

Definition at line 7032 of file m_env.f90.

Here is the caller graph for this function:

◆ adjust_risk_nonpar_noadjust()

subroutine predator_capture_risk_calculate_fish_group::adjust_risk_nonpar_noadjust

Adjust the predation risk for confusion and dilution effects.

In this version, the adjusted risk is equal to the baseline risk, i.e. there are no specific predator confusion or dilution effects.

See the main container procedure the_environment::predator_capture_risk_calculate_fish_group().

Implementation details

The adjusted risk of predation in this version is simplistic and just equals the baseline risk. So no adjustment is actually made.

Note that the adjusted risk is calculated only for a small subarray within the potentially huge input array of spatial prey agents, commondata::predator_risk_group_select_index_partial maximum elements. All other values are nulls.

Definition at line 10170 of file m_env.f90.

◆ adjust_risk_nonpar_fixed()

subroutine predator_capture_risk_calculate_fish_group::adjust_risk_nonpar_fixed

Adjust the predation risk for confusion and dilution effects.

This version is based on a fixed pattern linking the rank of the prey agent within the predator's visual field and the adjusted risk. However, the basic pattern scales independently on the specific number of prey agents that the predator sees.

See the main container procedure the_environment::predator_capture_risk_calculate_fish_group().

PROCNAME is the procedure name for logging and debugging

Notable variables

  • predator_risk_group_dilution_abscissa is the abscissa for the non-parametric function that links the baseline unadjusted predation risk for any prey agent within a group and the risk estimate that takes account of predator confusion and predator dilution effects. The ordinate of the grid is defined by the parameter array commondata::predator_risk_group_dilution_ordinate.

Implementation details

The grid abscissa for the nonparametric function (see below) depends on the number visible prey agents within the visual field of the predator N. It is constructed as a 3-element array (the second point is a middle interval): [ 1.0, 1 + (N-1/2.0), N ]. The ordinate of the grid is defined by the parameter array commondata::predator_risk_group_dilution_ordinate.

  • The estimate of the adjusted predation risk ( $ R_{a} $) for each agent in proximity to this predator then depends on the rank order ( $ r $) of the agent in within the visual field of the predator:

    \[ R_{a} = R_{b} \cdot \varsigma(r) , \]

    where $ R_{b} $ is unadjusted risk and $ \varsigma $ is a non-parametric weighting function that depends on the rank order $ r $ of the prey agent. The weighting function $ \varsigma(r) $ is in turn calculated as a nonlinear nonparametric function defined by the grid arrays:

In this way, the first prey agent (closest distance) is subject to the predation risk equal to the baseline unadjusted risk, whereas the last prey agent (furtherest from the predator in the group) has fully diluted predation risk equal to zero. The agent with the middle rank in the group has the adjusted risk somewhere in between the unadjusted risk and null. Thus, the predator confusion and dilution effects are relative and depend on the agent's position with respect to the predator.

Nonparametric predator confusion/dilution factor

Nonetheless, the pattern is independent on the specific number of prey agents in the group, e.g. it is the same for 3 and 9 agents.

Interpolation plots can be saved in the debug mode using the command: commondata::debug_interpolate_plot_save().

Warning
Involves huge number of plots, should normally be disabled.
This is disabled (commented out) here to allow parallel do concurrent construction. If debug plots are enabled, do concurrent has to be altered to normal do.

Note that the adjusted risk is calculated only for a small subarray within the potentially huge input array of spatial prey agents, commondata::predator_risk_group_select_index_partial maximum elements. All other values are nulls.

Definition at line 10199 of file m_env.f90.

Here is the caller graph for this function:

◆ adjust_risk_dilute_nofirst()

subroutine predator_capture_risk_calculate_fish_group::adjust_risk_dilute_nofirst

Adjust the predation risk of a group of N prey agents for predator dilution effect.

In this version, the nearest agent has a high risk equal to the baseline unadjusted risk whereas the other agents in the group have the risk diluted, on average, by their total number N-1 (the nearest agent is excluded). The risks of the non-nearest agents still depend on the individual rank order. Whereas the average adjusted risk for all non-rank-1 agents is equal to 1/(N-1), each of the agents has specific risk. For the rank-2 agent it is $ R_{b} \cdot 2/(N-1) $ while for the furtherest agent the risk is zero: $ R_{b} \cdot 0.0 $.

See the main container procedure the_environment::predator_capture_risk_calculate_fish_group().

Notable variables

  • predator_risk_dilution is the predator dilution weighting factor array. It is selected such that the average value over the whole array is 1/(N-1) where N is the total number of prey agents in the group including the nearest agent.

Implementation details

Calculate the array of dilution factor that is equally linearly spaced from 2/(N-1) to 0.0 (the furtherest agent). The average dilution factor for this group is therefore 1/(N-1).

Nonetheless, if there is only one prey agent, its risk is calculated as the full baseline risk $ R_{b} $.

If, on the other hand, only two prey agents are visible to the predator, the first (nearest, rank 1) gets the baseline risk $ R_{b} $ and the second $ R_{b} / 2.0 $.

The LINSPACE() procedure for generating linearly equally spaced array from HEDTOOLS is used for calculation of the dilution factor array predator_risk_dilution.

  • The adjusted risk is equal to the baseline risk for the prey agent that has the rank one, i.e. the closest to the predator.
  • However, for all other agents in the group the adjusted risk is diluted by the remaining group size (i.e. excluding the nearest agent N-1).
    Adjustment of the predation risk by dilution factor
    In the example plot above, the baseline risk for the nearest prey agent in a group of 6 is 0.7, it is unchanged. But the risk is diluted for all the remaining (rank>1) prey agents on average by 6-1=5, even though it is still dependent on their rank by a linearly evenly spaced dilution factor predator_risk_dilution (the plot also for simplicity assumes the baseline risk is also $ R_{b}=0.7 $ and is identical for all agents; in real data, the linearly spaced factor is used as a weight for specific baseline risk values $ R_{b} $, so the pattern deviates from the perfect straight line).

Definition at line 10309 of file m_env.f90.

◆ adjust_risk_dilute_all()

subroutine predator_capture_risk_calculate_fish_group::adjust_risk_dilute_all

Adjust the predation risk of a group of N prey agents for predator dilution effect.

In this version, all prey agents in the group have the risk diluted, on average, by their total number N. The risks of the agents are not fixed and depend on the individual rank order. Whereas the average adjusted risk is equal to 1/(N), each of the agents has specific risk. For the rank-1 agent it is $ R_{b} \cdot 2/N $ while for the furtherest agent the risk is zero: $ R_{b} \cdot 0.0 $.

See the main container procedure the_environment::predator_capture_risk_calculate_fish_group().

Notable variables

  • predator_risk_dilution is the predator dilution weighting factor array. It is selected such that the average value over the whole array is 1/N where N is the total number of prey agents in the group including the nearest agent.

Implementation details

Calculate the array of dilution factor that is equally linearly spaced from 2/N (nearest agent) to 0.0 (the furtherest agent). The average dilution factor for this group is therefore 1/N.

Nonetheless, if there is only one prey agent, its risk is calculated as the full baseline risk $ R_{b} $.

If, on the other hand, only two prey agents are visible to the predator, they both get the same risk equal to a half of baseline $ R_{b} / 2.0 $.

The LINSPACE() procedure for generating linearly equally spaced array from HEDTOOLS is used for calculation of the dilution factor array predator_risk_dilution.

  • The average adjusted risk is diluted by the group size N. However, individual prey agents have the adjusted risk values that are weighted by the linearly equally spaced dilution value predator_risk_dilution. Thus, even though individual values of the adjusted risk are ranked by the distance from the predator, their average values for the whole group is diluted by the group size N.

Definition at line 10395 of file m_env.f90.