World Builder  1.1.0-pre
A geodynamic initial conditions generator
WorldBuilder::Utilities Namespace Reference

Classes

class  interpolation
 
struct  PointDistanceFromCurvedPlanes
 

Enumerations

enum  InterpolationType {
  InterpolationType::None, InterpolationType::Linear, InterpolationType::MonotoneSpline, InterpolationType::ContinuousMonotoneSpline,
  InterpolationType::Invalid
}
 

Functions

bool polygon_contains_point (const std::vector< Point< 2 > > &point_list, const Point< 2 > &point)
 
bool polygon_contains_point_implementation (const std::vector< Point< 2 > > &point_list, const Point< 2 > &point)
 
double fraction_from_ellipse_center (const Point< 2 > &ellipse_center, const double semi_major_axis, const double eccentricity, const double theta, const Point< 2 > &point)
 
double signed_distance_to_polygon (const std::vector< Point< 2 > > &point_list, const Point< 2 > &point)
 
std::array< double, 3 > cartesian_to_spherical_coordinates (const Point< 3 > &position)
 
Point< 3 > spherical_to_cartesian_coordinates (const std::array< double, 3 > &scoord)
 
CoordinateSystem string_to_coordinate_system (const std::string &coordinate_system)
 
template<unsigned int dim>
std::array< double, dim > convert_point_to_array (const Point< dim > &point_)
 
double string_to_double (const std::string &string)
 
int string_to_int (const std::string &string)
 
unsigned int string_to_unsigned_int (const std::string &string)
 
Point< 3 > cross_product (const Point< 3 > &a, const Point< 3 > &b)
 
PointDistanceFromCurvedPlanes distance_point_from_curved_planes (const Point< 3 > &check_point, const Objects::NaturalCoordinate &natural_coordinate, const Point< 2 > &reference_point, const std::vector< Point< 2 > > &point_list, const std::vector< std::vector< double > > &plane_segment_lengths, const std::vector< std::vector< Point< 2 > > > &plane_segment_angles, const double start_radius, const std::unique_ptr< CoordinateSystems::Interface > &coordinate_system, const bool only_positive, const Objects::BezierCurve &bezier_curve)
 
double wrap_angle (const double angle)
 
double interpolate_angle_across_zero (const double angle_1, const double angle_2, const double fraction)
 
std::array< double, 3 > euler_angles_from_rotation_matrix (const std::array< std::array< double, 3 >, 3 > &rotation_matrix)
 
std::array< std::array< double, 3 >, 3 > euler_angles_to_rotation_matrix (double phi1_d, double theta_d, double phi2_d)
 
std::string read_and_distribute_file_content (const std::string &filename)
 
template std::array< double, 2 > convert_point_to_array< 2 > (const Point< 2 > &point_)
 
template std::array< double, 3 > convert_point_to_array< 3 > (const Point< 3 > &point_)
 
std::vector< double > calculate_ridge_distance_and_spreading (std::vector< std::vector< Point< 2 >>> mid_oceanic_ridges, std::vector< std::vector< double >> mid_oceanic_spreading_velocities, const std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > &coordinate_system, const Objects::NaturalCoordinate &position_in_natural_coordinates_at_min_depth, const std::vector< std::vector< double >> &subducting_plate_velocities, const std::vector< double > &ridge_migration_times)
 
std::vector< double > calculate_effective_trench_and_plate_ages (std::vector< double > ridge_parameters, double distance_along_plane)
 
std::array< std::array< double, 3 >, 3 > multiply_3x3_matrices (const std::array< std::array< double, 3 >, 3 > mat1, const std::array< std::array< double, 3 >, 3 > mat2)
 
bool approx (double a, double b, double error_factor=1e4)
 
std::array< double, 3 > cartesian_to_ellipsoidal_coordinates (const Point< 3 > &position, const double semi_major_axis_a, const double eccentricity)
 
Point< 3 > ellipsoidal_to_cartesian_coordinates (const std::array< double, 3 > &phi_theta_d, const double semi_major_axis_a, const double eccentricity)
 

Enumeration Type Documentation

◆ InterpolationType

Enum class for interolation type

Enumerator
None 
Linear 
MonotoneSpline 
ContinuousMonotoneSpline 
Invalid 

Definition at line 176 of file utilities.h.

Function Documentation

◆ approx()

bool WorldBuilder::Utilities::approx ( double  a,
double  b,
double  error_factor = 1e4 
)
inline

provide a short way to test if two doubles are equal. Based on https://stackoverflow.com/a/4010279. Removed a==b test since it triggers warnings. If used in performance critical parts where this could matter, a fast version could be added.

Definition at line 48 of file utilities.h.

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

◆ calculate_effective_trench_and_plate_ages()

std::vector< double > WorldBuilder::Utilities::calculate_effective_trench_and_plate_ages ( std::vector< double >  ridge_parameters,
double  distance_along_plane 
)

Calculate the effective plate ages of a point on the slab surface, and also calculates the effective trench ages at the start of subduction.

Parameters
ridge_parametersThe distance and spreading velocity relative to a mid ocean ridge
distance_along_planeThe distance along the slab surface plane
Returns
The effective plate age and the trench age

Definition at line 1483 of file utilities.cc.

Here is the caller graph for this function:

◆ calculate_ridge_distance_and_spreading()

std::vector< double > WorldBuilder::Utilities::calculate_ridge_distance_and_spreading ( std::vector< std::vector< Point< 2 >>>  mid_oceanic_ridges,
std::vector< std::vector< double >>  mid_oceanic_spreading_velocities,
const std::unique_ptr< WorldBuilder::CoordinateSystems::Interface > &  coordinate_system,
const Objects::NaturalCoordinate position_in_natural_coordinates_at_min_depth,
const std::vector< std::vector< double >> &  subducting_plate_velocities,
const std::vector< double > &  ridge_migration_times 
)

Calculate the distance of a point from a mid oceanic ridge, and also calculate the spreading velocity of the ridge at this point. TODO: make the spreading velocity spatially/temporally variable

Parameters
mid_oceanic_ridgesThe coordinates of the mid oceanic ridges
mid_oceanic_spreading_velocitiesThe spreading rate of the mid oceanic ridges at each ridge coordinate
coordinate_systemThe coordinate system
position_in_natural_coordinates_at_min_depththe current position in natural_coordinates
subducting_plate_velocitiesthe subducting plate velocities, currently this is only an optional parameter that can be used in the mass conserving subducting plate temperature model. This parameter allows the user to track the effect of ridge migration on the slab thermal structure
ridge_migration_timesthe times that the corresponding section of the ridge has been moving, in years. This is used in combination with subducting_plate_velocities, and mid_oceanic_spreading_velocities to compute the distance that the spreading center has migrated. This vector is obtained from the input parameter "spreading velocity" in the mass conserving model when "spreading velocity" has the form: [ [t1,[[v11, v12, ...]], [t2,[[v21, v22, ...]], ... ]. where tn is the time that ridge section n has been moving.
Returns
The content of the file.

Definition at line 1290 of file utilities.cc.

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

◆ cartesian_to_ellipsoidal_coordinates()

std::array<double,3> WorldBuilder::Utilities::cartesian_to_ellipsoidal_coordinates ( const Point< 3 > &  position,
const double  semi_major_axis_a,
const double  eccentricity 
)

Returns ellipsoidal coordinates of a Cartesian point. The returned array is filled with phi, theta and radius.

Here is the caller graph for this function:

◆ cartesian_to_spherical_coordinates()

std::array< double, 3 > WorldBuilder::Utilities::cartesian_to_spherical_coordinates ( const Point< 3 > &  position)

Returns spherical coordinates of a Cartesian point. The returned array is filled with radius, phi and theta (polar angle). If the dimension is set to 2 theta is omitted. Phi is always normalized to [0,2*pi].

Definition at line 255 of file utilities.cc.

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

◆ convert_point_to_array()

template<unsigned int dim>
std::array< double, dim > WorldBuilder::Utilities::convert_point_to_array ( const Point< dim > &  point)

Convert point to array

Definition at line 301 of file utilities.cc.

Here is the caller graph for this function:

◆ convert_point_to_array< 2 >()

template std::array<double,2> WorldBuilder::Utilities::convert_point_to_array< 2 > ( const Point< 2 > &  point_)
Here is the caller graph for this function:

◆ convert_point_to_array< 3 >()

template std::array<double,3> WorldBuilder::Utilities::convert_point_to_array< 3 > ( const Point< 3 > &  point_)
Here is the caller graph for this function:

◆ cross_product()

Point< 3 > WorldBuilder::Utilities::cross_product ( const Point< 3 > &  a,
const Point< 3 > &  b 
)

Cross product between two 3d points.

Definition at line 370 of file utilities.cc.

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

◆ distance_point_from_curved_planes()

PointDistanceFromCurvedPlanes WorldBuilder::Utilities::distance_point_from_curved_planes ( const Point< 3 > &  check_point,
const Objects::NaturalCoordinate check_point_natural,
const Point< 2 > &  reference_point,
const std::vector< Point< 2 > > &  point_list,
const std::vector< std::vector< double > > &  plane_segment_lengths,
const std::vector< std::vector< Point< 2 > > > &  plane_segment_angles,
const double  start_radius,
const std::unique_ptr< CoordinateSystems::Interface > &  coordinate_system,
const bool  only_positive,
const Objects::BezierCurve bezier_curve 
)

Computes the distance of a point to a curved plane. TODO: add more info on how this works/is implemented.

Parameters
check_pointThis is the cartesian point of which we want to know the distance to the curved planes
check_point_naturalthe check_point in the natural coordinates of the current coordinate system.
reference_pointThis is a 2d point in natural coordinates at the surface which the curved planes dip towards. Natural coordinates are in cartesian (x,y,z) in meters and in spherical radius in meters and longitude and latitude in radians.
point_listThis is a vector of 2d Points in natural coordinates at the surface which define the line along the surface at which the curved planes start. Natural coordinates are in cartesian (x,y,z) in meters and in spherical radius in meters and longitude and latitude in radians.
plane_segment_lengthsThis is a vector of vectors of doubles. It contains the length of every segment at point in the point_list (in the same order as the point_list.
plane_segment_anglesThis is a vector of vectors of 2d points. It contains the begin and end angle of every segment at point in the point_list (in the same order as the point_list.
start_radiusThis value contains the radius or height from bottom of the box at which the plane starts. This means that the start_radius effectively becomes the surface for this slab.
coordinate_systemThis is a reference to the coordinate system of the World Builder. This is used to convert cartesian to natural coordinates and back.
only_positiveThis value determines whether only the part below the plane should count as distance or both sides of the plane. It is called only_positive because the area below the plane, the distance is positive, and above the plane the distance is negative.
interpolation_typeThis value determines what interpolation type should be used when determining the location with respect to the curved plane.
spline_xthe spline representing the x coordinate.
spline_ythe spline representing the y coordinate.
global_x_listThis is a list of one dimensional coorindates, with zero or the amount of coordinates entries, used for interpolation. An empty list is interpreted as a list filled with {0,1,2,...,number of coordinates}. Filling this list with other values changes the returned section fraction. It allows for, for example, adding extra coordinates automatically, and still reference the user provided coordinates by the original number. Note that no whole numbers may be skipped. So for a list of 4 points, {0,0.5,1,2} is allowed, but {0,2,3,4} is not.

The function returns a struct that contains which segment and section of the curved planes the point is closest to, what fraction of those segment and section lies before the point (looking from the start of segment/section), the distance of the point from the plane and the distance of the point along the plane, and the average angle of the closest segment/section.

Definition at line 380 of file utilities.cc.

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

◆ ellipsoidal_to_cartesian_coordinates()

Point<3> WorldBuilder::Utilities::ellipsoidal_to_cartesian_coordinates ( const std::array< double, 3 > &  phi_theta_d,
const double  semi_major_axis_a,
const double  eccentricity 
)

Return the Cartesian point of a ellipsoidal position defined by phi, phi and radius.

Here is the caller graph for this function:

◆ euler_angles_from_rotation_matrix()

std::array< double, 3 > WorldBuilder::Utilities::euler_angles_from_rotation_matrix ( const std::array< std::array< double, 3 >, 3 > &  rotation_matrix)

Transform a rotation matrix into euler angles

Definition at line 1119 of file utilities.cc.

Here is the call graph for this function:

◆ euler_angles_to_rotation_matrix()

std::array< std::array< double, 3 >, 3 > WorldBuilder::Utilities::euler_angles_to_rotation_matrix ( double  phi1,
double  theta,
double  phi2 
)

Transform euler angles into a rotation matrix

Definition at line 1147 of file utilities.cc.

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

◆ fraction_from_ellipse_center()

double WorldBuilder::Utilities::fraction_from_ellipse_center ( const Point< 2 > &  ellipse_center,
const double  semi_major_axis,
const double  eccentricity,
const double  rotation_angle,
const Point< 2 > &  point 
)

Given a 2d point, a semi-major axis, and an eccentricity, computes where the point falls within the ellipse. If the fraction is larger than 1, the point is outside the ellipse.

Definition at line 167 of file utilities.cc.

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

◆ interpolate_angle_across_zero()

double WorldBuilder::Utilities::interpolate_angle_across_zero ( const double  angle_1,
const double  angle_2,
const double  fraction 
)

Interpolate between two angles (angle1 and angle2), with fraction defining the weighting between the two, taking into account we might cross over from 360 to 0 degrees.

Definition at line 1095 of file utilities.cc.

Here is the caller graph for this function:

◆ multiply_3x3_matrices()

std::array< std::array< double, 3 >, 3 > WorldBuilder::Utilities::multiply_3x3_matrices ( const std::array< std::array< double, 3 >, 3 >  mat1,
const std::array< std::array< double, 3 >, 3 >  mat2 
)

Definition at line 1510 of file utilities.cc.

Here is the caller graph for this function:

◆ polygon_contains_point()

bool WorldBuilder::Utilities::polygon_contains_point ( const std::vector< Point< 2 > > &  point_list,
const Point< 2 > &  point 
)

Given a 2d point and a list of points which form a polygon, computes if the point falls within the polygon. For spherical coordinates it will return true if the point or the point where the longitude is shifted by 2 * PI is inside on of the polygons. It calls polygon_contains_point_implementation to do the real work.

Definition at line 46 of file utilities.cc.

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

◆ polygon_contains_point_implementation()

bool WorldBuilder::Utilities::polygon_contains_point_implementation ( const std::vector< Point< 2 > > &  point_list,
const Point< 2 > &  point 
)

Given a 2d point and a list of points which form a polygon, computes if the point falls within the polygon.

This code has been based on http://geomalgorithms.com/a03-_inclusion.html, and therefore requires the following copyright notice:

Copyright 2000 softSurfer, 2012 Dan Sunday This code may be freely used and modified for any purpose providing that this copyright notice is included with it. SoftSurfer makes no warranty for this code, and cannot be held liable for any real or imagined damage resulting from its use. Users of this code must verify correctness for their application.

The main functional difference between the original code and this code is that all the boundaries are considered to be inside the polygon. One should of course realize that with floating point arithmetic no guarantees can be made for the borders, but for exact arithmetic this algorithm would work (also see polygon in point test).

Definition at line 63 of file utilities.cc.

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

◆ read_and_distribute_file_content()

std::string WorldBuilder::Utilities::read_and_distribute_file_content ( const std::string &  filename)

Read a file and distribute the content over all MPI processes. If WB_WITH_MPI is not defined, this function will just read the file.

Parameters
filenameThe name of the file to read.
Returns
The content of the file.

Definition at line 1172 of file utilities.cc.

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

◆ signed_distance_to_polygon()

double WorldBuilder::Utilities::signed_distance_to_polygon ( const std::vector< Point< 2 > > &  point_list_,
const Point< 2 > &  point_ 
)

Given a 2d point and a list of points which form a polygon, compute the smallest distance of the point to the polygon. The sign is negative for points outside of the polygon and positive for points inside the polygon.

This code is based on http://geomalgorithms.com/a02-_lines.html#Distance-to-Infinite-Line, and therefore requires the following copyright notice:

Copyright 2000 softSurfer, 2012 Dan Sunday This code may be freely used and modified for any purpose providing that this copyright notice is included with it. SoftSurfer makes no warranty for this code, and cannot be held liable for any real or imagined damage resulting from its use. Users of this code must verify correctness for their application.

Definition at line 191 of file utilities.cc.

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

◆ spherical_to_cartesian_coordinates()

Point< 3 > WorldBuilder::Utilities::spherical_to_cartesian_coordinates ( const std::array< double, 3 > &  scoord)

Return the Cartesian point of a spherical position defined by radius, phi and theta (polar angle). If the dimension is set to 2 theta is omitted.

Definition at line 274 of file utilities.cc.

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

◆ string_to_coordinate_system()

CoordinateSystem WorldBuilder::Utilities::string_to_coordinate_system ( const std::string &  )

A function that takes a string representation of the name of a coordinate system (as represented by the CoordinateSystem enum) and returns the corresponding value.

Definition at line 287 of file utilities.cc.

Here is the caller graph for this function:

◆ string_to_double()

double WorldBuilder::Utilities::string_to_double ( const std::string &  string)

Converts a string to a double

Definition at line 310 of file utilities.cc.

Here is the caller graph for this function:

◆ string_to_int()

int WorldBuilder::Utilities::string_to_int ( const std::string &  string)

Converts a string to a int

Definition at line 329 of file utilities.cc.

Here is the caller graph for this function:

◆ string_to_unsigned_int()

unsigned int WorldBuilder::Utilities::string_to_unsigned_int ( const std::string &  string)

Converts a string to a unsigned int

Definition at line 349 of file utilities.cc.

Here is the caller graph for this function:

◆ wrap_angle()

double WorldBuilder::Utilities::wrap_angle ( const double  angle)

Ensure angle is between 0 and 360 degrees

Definition at line 1090 of file utilities.cc.

Here is the caller graph for this function: