|
| 1 | +/* |
| 2 | + Copyright (C) 2018-2024 by the authors of the World Builder code. |
| 3 | +
|
| 4 | + This file is part of the World Builder. |
| 5 | +
|
| 6 | + This program is free software: you can redistribute it and/or modify |
| 7 | + it under the terms of the GNU Lesser General Public License as published |
| 8 | + by the Free Software Foundation, either version 2 of the License, or |
| 9 | + (at your option) any later version. |
| 10 | +
|
| 11 | + This program is distributed in the hope that it will be useful, |
| 12 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + GNU Lesser General Public License for more details. |
| 15 | +
|
| 16 | + You should have received a copy of the GNU Lesser General Public License |
| 17 | + along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +#include "world_builder/features/oceanic_plate_models/velocity/euler_pole.h" |
| 21 | + |
| 22 | +#include "world_builder/assert.h" |
| 23 | +#include "world_builder/consts.h" |
| 24 | +#include "world_builder/coordinate_system.h" |
| 25 | +#include "world_builder/nan.h" |
| 26 | +#include "world_builder/types/array.h" |
| 27 | +#include "world_builder/types/double.h" |
| 28 | +#include "world_builder/types/object.h" |
| 29 | +#include "world_builder/types/one_of.h" |
| 30 | +#include "world_builder/types/value_at_points.h" |
| 31 | +#include "world_builder/utilities.h" |
| 32 | + |
| 33 | + |
| 34 | +namespace WorldBuilder |
| 35 | +{ |
| 36 | + |
| 37 | + using namespace Utilities; |
| 38 | + |
| 39 | + namespace Features |
| 40 | + { |
| 41 | + namespace OceanicPlateModels |
| 42 | + { |
| 43 | + namespace Velocity |
| 44 | + { |
| 45 | + EulerPole::EulerPole(WorldBuilder::World *world_) |
| 46 | + : |
| 47 | + min_depth(NaN::DSNAN), |
| 48 | + max_depth(NaN::DSNAN), |
| 49 | + euler_pole(NaN::DSNAN,NaN::DSNAN,NaN::DSNAN,CoordinateSystem::invalid), |
| 50 | + operation(Operations::REPLACE) |
| 51 | + { |
| 52 | + this->world = world_; |
| 53 | + this->name = "euler pole"; |
| 54 | + } |
| 55 | + |
| 56 | + EulerPole::~EulerPole() |
| 57 | + = default; |
| 58 | + |
| 59 | + void |
| 60 | + EulerPole::declare_entries(Parameters &prm, const std::string & /*unused*/) |
| 61 | + { |
| 62 | + // Document plugin and require entries if needed. |
| 63 | + // Add `velocity` and to the required parameters. |
| 64 | + prm.declare_entry("", Types::Object({"euler pole"}), |
| 65 | + "Uniform velocity model. Set the velocity to a constant value."); |
| 66 | + |
| 67 | + // Declare entries of this plugin |
| 68 | + prm.declare_entry("min depth", Types::OneOf(Types::Double(0), |
| 69 | + Types::Array(Types::ValueAtPoints(0.,2)), |
| 70 | + Types::String("")), |
| 71 | + "The depth in meters from which the composition of this feature is present."); |
| 72 | + |
| 73 | + prm.declare_entry("max depth", Types::OneOf(Types::Double(std::numeric_limits<double>::max()), |
| 74 | + Types::Array(Types::ValueAtPoints(std::numeric_limits<double>::max(),2)), |
| 75 | + Types::String("")), |
| 76 | + "The depth in meters to which the composition of this feature is present."); |
| 77 | + |
| 78 | + |
| 79 | + prm.declare_entry("euler pole", Types::Array(Types::Double(0.0),2,2), |
| 80 | + "The euler pole for the plate (longitude, latitude) in degree."); |
| 81 | + |
| 82 | + prm.declare_entry("angular velocity", Types::Double(0.0), "The angular velocity of the Euler pole in degree/Myr."); |
| 83 | + |
| 84 | + } |
| 85 | + |
| 86 | + void |
| 87 | + EulerPole::parse_entries(Parameters &prm, const std::vector<Point<2>> &coordinates) |
| 88 | + { |
| 89 | + constexpr double year_in_seconds = 60*60*24*365.2425; |
| 90 | + WBAssertThrow(prm.coordinate_system->natural_coordinate_system() == CoordinateSystem::spherical, |
| 91 | + "The Euler pole velocity model can only be used in a spherical coordinate system."); |
| 92 | + min_depth_surface = Objects::Surface(prm.get("min depth",coordinates)); |
| 93 | + min_depth = min_depth_surface.minimum; |
| 94 | + max_depth_surface = Objects::Surface(prm.get("max depth",coordinates)); |
| 95 | + max_depth = max_depth_surface.maximum; |
| 96 | + operation = string_operations_to_enum(prm.get<std::string>("operation")); |
| 97 | + std::vector<double> euler_pole_degree = prm.get_vector<double>("euler pole"); |
| 98 | + const double angular_speed = (1e-6/year_in_seconds)*sin(prm.get<double>("angular velocity")*Consts::PI/180.); |
| 99 | + const double longitude = euler_pole_degree[0]*Consts::PI/180.; |
| 100 | + const double latitude = euler_pole_degree[1]*Consts::PI/180.; |
| 101 | + euler_pole[0] = angular_speed*cos(latitude)*cos(longitude); |
| 102 | + euler_pole[1] = angular_speed*cos(latitude)*sin(longitude); |
| 103 | + euler_pole[2] = angular_speed*sin(latitude); |
| 104 | + } |
| 105 | + |
| 106 | + |
| 107 | + std::array<double,3> |
| 108 | + EulerPole::get_velocity(const Point<3> &position_in_cartesian_coordinates, |
| 109 | + const Objects::NaturalCoordinate &position_in_natural_coordinates, |
| 110 | + const double depth, |
| 111 | + const double /*gravity*/, |
| 112 | + std::array<double,3> velocity_, |
| 113 | + const double /*feature_min_depth*/, |
| 114 | + const double /*feature_max_depth*/) const |
| 115 | + { |
| 116 | + |
| 117 | + if (depth <= max_depth && depth >= min_depth) |
| 118 | + { |
| 119 | + const double min_depth_local = min_depth_surface.constant_value ? min_depth : min_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value; |
| 120 | + const double max_depth_local = max_depth_surface.constant_value ? max_depth : max_depth_surface.local_value(position_in_natural_coordinates.get_surface_point()).interpolated_value; |
| 121 | + if (depth <= max_depth_local && depth >= min_depth_local) |
| 122 | + { |
| 123 | + const double position_norm = position_in_cartesian_coordinates.norm(); |
| 124 | + const Point<3> position_normalized = position_in_cartesian_coordinates/position_norm; |
| 125 | + const Point<3> euler_velocity = position_norm * Utilities::cross_product(euler_pole, position_normalized); |
| 126 | + //std::terminate(); |
| 127 | + return {{ |
| 128 | + apply_operation(operation,velocity_[0],euler_velocity[0]), |
| 129 | + apply_operation(operation,velocity_[1],euler_velocity[1]), |
| 130 | + apply_operation(operation,velocity_[2],euler_velocity[2]) |
| 131 | + } |
| 132 | + }; |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + return velocity_; |
| 137 | + } |
| 138 | + |
| 139 | + WB_REGISTER_FEATURE_OCEANIC_PLATE_VELOCITY_MODEL(EulerPole, euler pole) |
| 140 | + } // namespace Velocity |
| 141 | + } // namespace OceanicPlateModels |
| 142 | + } // namespace Features |
| 143 | +} // namespace WorldBuilder |
| 144 | + |
0 commit comments