Skip to content

Commit efdb609

Browse files
fix default value
1 parent c3b5bb3 commit efdb609

4 files changed

Lines changed: 23 additions & 18 deletions

File tree

include/world_builder/features/subducting_plate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ namespace WorldBuilder
221221
* A vector on the surface that indicates the direction of convergence
222222
* of the subducting plate relative to the trench.
223223
*/
224-
Point<2> obliquity_vector;
224+
// Point<2> obliquity_vector;
225+
std::vector<double> obliquity_vector;
225226

226227
std::vector<std::vector<double> > slab_segment_lengths;
227228
std::vector<std::vector<Point<2> > > slab_segment_thickness;

include/world_builder/utilities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ namespace WorldBuilder
410410
const std::unique_ptr<CoordinateSystems::Interface> &coordinate_system,
411411
const bool only_positive,
412412
const Objects::BezierCurve &bezier_curve,
413-
Point<2> obliquity_vector = Point<2>(NaN::DSNAN, NaN::DSNAN, CoordinateSystem::cartesian));
413+
std::vector<double> obliquity_vector = {std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()});
414414

415415

416416

source/world_builder/features/subducting_plate.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ namespace WorldBuilder
4141
{
4242
SubductingPlate::SubductingPlate(WorldBuilder::World *world_)
4343
:
44-
reference_point(0,0,cartesian),
45-
obliquity_vector(NaN::DSNAN, NaN::DSNAN, cartesian)
44+
reference_point(0,0,cartesian)
4645
{
4746
this->world = world_;
4847
this->name = "subducting plate";
@@ -107,7 +106,7 @@ namespace WorldBuilder
107106
"The depth to which this feature is present");
108107
prm.declare_entry("dip point", Types::Point<2>(),
109108
"The depth to which this feature is present");
110-
prm.declare_entry("obliquity vector", Types::Point<2>(),
109+
prm.declare_entry("obliquity vector", Types::Array(Types::Double(std::numeric_limits<double>::infinity()),2),
111110
"A vector on the surface that indicates the direction of convergence of the subducting plate relative to the trench.");
112111
/*prm.declare_entry("segments", Types::Array(Types::Segment(0,Point<2>(0,0,invalid),Point<2>(0,0,invalid),Point<2>(0,0,invalid),
113112
Types::PluginSystem("", Features::SubductingPlateModels::Temperature::Interface::declare_entries, {"model"}),
@@ -174,13 +173,14 @@ namespace WorldBuilder
174173

175174
reference_point = prm.get<Point<2> >("dip point");
176175

177-
obliquity_vector = prm.get<Point<2>>("obliquity vector");
176+
obliquity_vector = prm.get_vector<double>("obliquity vector");
178177

179178
if (coordinate_system == spherical)
180179
{
181180
// When spherical, input is in degrees, so change to radians for internal use.
182181
reference_point *= (Consts::PI/180.);
183-
obliquity_vector *= (Consts::PI/180.);
182+
for (double &value : obliquity_vector)
183+
value *= (Consts::PI/180.);
184184
}
185185

186186

source/world_builder/utilities.cc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ namespace WorldBuilder
387387
const std::unique_ptr<CoordinateSystems::Interface> &coordinate_system,
388388
const bool only_positive,
389389
const Objects::BezierCurve &bezier_curve,
390-
Point<2> obliquity_vector)
390+
std::vector<double> obliquity_vector)
391391
{
392392
// Initialize variables that this function will return
393393
double distance = std::numeric_limits<double>::infinity();
@@ -431,18 +431,22 @@ namespace WorldBuilder
431431
Objects::ClosestPointOnCurve closest_point_on_curve = bezier_curve.closest_point_on_curve_segment(check_point_surface_2d);
432432
Point<2> closest_point_on_line_2d = closest_point_on_curve.point;
433433

434-
// If the obliquity_vector is not a NAN, this means that the user has specified an obliquity vector.
434+
// If the obliquity_vector is not infinite, this means that the user has specified an obliquity vector.
435435
// This will require a potential modification of the `closest_point_on_line_2d` variable. We will take
436436
// the check point and use it with the obliquity vector to parameterize a line and see where this line
437437
// intersects the Bezier curve. If it does intersect the Bezier curve, then this intersection point will
438438
// become the new `closest_point_on_line_2d`, otherwise it will be set to NaN.
439-
if (!std::isnan(obliquity_vector[0]))
439+
// if (obliquity_vector_point.norm() > std::numeric_limits<double>::min())
440+
if (std::isfinite(obliquity_vector[0]))
440441
{
442+
Point<2> obliquity_vector_point(obliquity_vector[0], obliquity_vector[1], natural_coordinate_system);
443+
// Normalize the vector
444+
obliquity_vector_point = obliquity_vector_point / obliquity_vector_point.norm();
445+
441446
// Check if the bezier_curve has found a point on the curve that is closest to the checkpoint (without considering the obliquity vector).
442447
// If so, we need to check whether this point is on the correct side of the curve, given the reference point.
443448
// If the bezier_curve has not found a point on the curve that is closest to the checkpoint, check to see if the point will still
444449
// intersect the trench given the obliquity_vector.
445-
obliquity_vector = obliquity_vector / obliquity_vector.norm();
446450
if (!std::isnan(closest_point_on_line_2d[0]))
447451
{
448452
Point<2> check_point_surface_2d_temp_ob = check_point_surface_2d;
@@ -489,11 +493,11 @@ namespace WorldBuilder
489493
// If the sign of the dot product of the obliquity vector and the normal vector of the closest point on
490494
// the curve is positive, then we want to move along the obliquity vector in the negative direction,
491495
// otherwise in the positive direction.
492-
line_factor = obliquity_vector * iterable_closest_point_on_curve.normal > 0 ? -1.0 : 1.0;
496+
line_factor = obliquity_vector_point * iterable_closest_point_on_curve.normal > 0 ? -1.0 : 1.0;
493497

494498
// Parameterize a line through the checkpoint along the obliquity vector.
495-
Point<2> parameterized_line(iterable_check_point_surface_2d[0] + line_factor * old_dist * obliquity_vector[0],
496-
iterable_check_point_surface_2d[1] + line_factor * old_dist * obliquity_vector[1],
499+
Point<2> parameterized_line(iterable_check_point_surface_2d[0] + line_factor * old_dist * obliquity_vector_point[0],
500+
iterable_check_point_surface_2d[1] + line_factor * old_dist * obliquity_vector_point[1],
497501
natural_coordinate_system);
498502

499503
// Check where the closest point on the Bezier curve is relative to the new check point (after moving along the
@@ -564,7 +568,7 @@ namespace WorldBuilder
564568
second_closest_point_idx = dist_prev < dist_next ? closest_point_idx - 1 : closest_point_idx + 1;
565569
}
566570

567-
// const Point<2> second_closest_point = point_list[second_closest_point_idx];
571+
const Point<2> second_closest_point = point_list[second_closest_point_idx];
568572
// std::vector<Point<2> > closest_points;
569573
// closest_points.push_back(closest_point);
570574
// closest_points.push_back(second_closest_point);
@@ -601,15 +605,15 @@ namespace WorldBuilder
601605
// If both lines are parameterized with l_i = x_i + t_i * v_i, then since we know the points x_i and the
602606
// vectors v_i, we can solve for t_1 and t_2 when l_1 = l_2. This works out to be:
603607
const double numerator = trench_uv[0] * (trench_point1[1] - check_point_surface_2d[1]) + trench_uv[1] * (check_point_surface_2d[0] - trench_point1[0]);
604-
const double denominator = obliquity_vector[1] * trench_uv[0] - obliquity_vector[0] * trench_uv[1];
608+
const double denominator = obliquity_vector_point[1] * trench_uv[0] - obliquity_vector_point[0] * trench_uv[1];
605609
const double t_val = numerator / denominator;
606610

607611
// If the two lines are parallel, t_val will be infinite. Check to see that this is not the case.
608612
if (std::isfinite(t_val))
609613
{
610614
// t_val is finite, now determine where the intersection point is, and see if this lies within the trench extents.
611-
const Point<2> intersection_point(check_point_surface_2d[0] + t_val * obliquity_vector[0],
612-
check_point_surface_2d[1] + t_val * obliquity_vector[1],
615+
const Point<2> intersection_point(check_point_surface_2d[0] + t_val * obliquity_vector_point[0],
616+
check_point_surface_2d[1] + t_val * obliquity_vector_point[1],
613617
natural_coordinate_system);
614618

615619
if (intersection_point[0] >= min_along_x && intersection_point[0] <= max_along_x

0 commit comments

Comments
 (0)