Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add water content as a composition to subducting plates #690

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,163 changes: 7,163 additions & 0 deletions doc/world_builder_declarations.tex

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
Copyright (C) 2018 - 2021 by the authors of the World Builder code.

This file is part of the World Builder.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_MODELS_COMPOSITION_WATER_CONTENT_H
#define WORLD_BUILDER_FEATURES_SUBDUCTING_PLATE_MODELS_COMPOSITION_WATER_CONTENT_H


#include "world_builder/features/subducting_plate_models/composition/interface.h"
#include <mutex>


namespace WorldBuilder
{

namespace Features
{
namespace SubductingPlateModels
{
namespace Composition
{
/**
* This class represents the bound water content in a subducting plate and can implement
* submodules for computing this bound water content. These submodules determine what
* the returned water content will be based on the the temperature and pressure at a point
* within the world.
*/
class WaterContent final: public Interface
{
public:
/**
* constructor
*/
WaterContent(WorldBuilder::World *world);

/**
* Destructor
*/
~WaterContent() override final;

/**
* declare and read in the world builder file into the parameters class
*/
static
void declare_entries(Parameters &prm, const std::string &parent_name = "");

/**
* declare and read in the world builder file into the parameters class
*/
void parse_entries(Parameters &prm) override final;

/**
* Calculates what the maximum bound water content is at a point given a pressure and
* temperature. This can be done for 4 different lithologies, "sediment", "gabbro",
* "MORB", and "peridotite"
*/
// double calculate_water_content(double pressure,
// double temperature,
// unsigned int lithology_ind) const;
/**
* Returns a value for the bound water contend based on the given position, depth in the model,
* gravity, and the temperature at that point.
*/
double get_composition(const Point<3> &position,
const double depth,
const unsigned int composition_number,
double composition,
const double feature_min_depth,
const double feature_max_depth,
const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes &distance_from_planes,
// std::string lithology_str,
const AdditionalParameters &additional_parameters) const override final;


private:
// water_content composition submodule parameters
double min_depth;
double max_depth;
double density;
std::vector<unsigned int> compositions;
Operations operation;

std::vector<double> max_water_contents;
std::string lithology_str;
unsigned int lithology_index;
};
} // namespace Composition
} // namespace SubductingPlateModels
} // namespace Features
} // namespace WorldBuilder

#endif
17 changes: 15 additions & 2 deletions include/world_builder/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ namespace WorldBuilder
segment(NaN::ISNAN),
average_angle(NaN::DSNAN),
depth_reference_surface(NaN::DSNAN),
closest_trench_point(Point<3>(coordinate_system))
closest_trench_point(Point<3>(coordinate_system)),
water_flux(NaN::DSNAN)
{}

/**
Expand Down Expand Up @@ -346,6 +347,11 @@ namespace WorldBuilder
*/
double depth_reference_surface;


std::array<double, 4> water_content;

double water_flux;

/**
* The closest point on the trench line in cartesian coordinates.
*/
Expand Down Expand Up @@ -409,7 +415,9 @@ namespace WorldBuilder
const double start_radius,
const std::unique_ptr<CoordinateSystems::Interface> &coordinate_system,
const bool only_positive,
const Objects::BezierCurve &bezier_curve);
const Objects::BezierCurve &bezier_curve,
bool compute_water = false,
const WorldBuilder::World *world = nullptr);



Expand Down Expand Up @@ -487,6 +495,11 @@ namespace WorldBuilder
std::vector<double>
calculate_effective_trench_and_plate_ages(std::vector<double> ridge_parameters, double distance_along_plane);

double
calculate_water_content(double pressure,
double temperature,
unsigned int lithology_index);

} // namespace Utilities
} // namespace WorldBuilder

Expand Down
1 change: 1 addition & 0 deletions source/world_builder/features/fault.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ namespace WorldBuilder
<< ", starting_depth " << starting_depth
);

std::string lithology_str;
const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes distance_from_planes =
WorldBuilder::Utilities::distance_point_from_curved_planes(position_in_cartesian_coordinates,
position_in_natural_coordinates,
Expand Down
32 changes: 31 additions & 1 deletion source/world_builder/features/subducting_plate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "world_builder/types/segment.h"
#include "world_builder/types/unsigned_int.h"
#include "world_builder/world.h"
#include "world_builder/features/subducting_plate_models/composition/uniform.h"
#include "world_builder/features/subducting_plate_models/composition/water_content.h"
#include <algorithm>

using namespace std;
Expand Down Expand Up @@ -488,6 +490,31 @@
"Internal error: The size of coordinates (" << coordinates.size()
<< ") and one_dimensional_coordinates (" << one_dimensional_coordinates.size() << ") are different.");*/
// todo: explain
bool needs_water_plugin = false;
std::string str_lithology;
for (unsigned int i_property = 0; i_property < properties.size(); ++i_property)
{
if (properties[i_property][0] == 2) // requesting composition
{
for (size_t current_section = 0; current_section < segment_vector.size(); current_section++)
{
for (size_t current_segment = 0; current_segment < segment_vector[current_section].size(); current_segment++)
{
for (const auto &composition_model: segment_vector[current_section][current_segment].composition_systems)
{
needs_water_plugin = dynamic_cast<const WorldBuilder::Features::SubductingPlateModels::Composition::WaterContent *>(composition_model.get()) != NULL;
if (needs_water_plugin)
{
break;

Check warning on line 508 in source/world_builder/features/subducting_plate.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate.cc#L508

Added line #L508 was not covered by tests
}
}
}
}
}
}

// needs_water_plugin = false;
// std::string lithology_str;
const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes distance_from_planes =
WorldBuilder::Utilities::distance_point_from_curved_planes(position_in_cartesian_coordinates,
position_in_natural_coordinates,
Expand All @@ -498,7 +525,9 @@
starting_radius,
this->world->parameters.coordinate_system,
false,
this->bezier_curve);
this->bezier_curve,
needs_water_plugin,
this->world);

const double distance_from_plane = distance_from_planes.distance_from_plane;
const double distance_along_plane = distance_from_planes.distance_along_plane;
Expand Down Expand Up @@ -737,6 +766,7 @@
<< ", starting_depth " << starting_depth
);

std::string str_lithology;
const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes distance_from_planes =
WorldBuilder::Utilities::distance_point_from_curved_planes(position_in_cartesian_coordinates,
position_in_natural_coordinates,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ namespace WorldBuilder
{
if (compositions[i] == composition_number)
{
// return apply_operation(operation,composition,distance_from_plane.water_content);
// return apply_operation(operation,composition,fractions[i]);
return apply_operation(operation,composition,fractions[i]);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
/*
Copyright (C) 2018 - 2021 by the authors of the World Builder code.

This file is part of the World Builder.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#include "world_builder/features/subducting_plate_models/composition/water_content.h"

#include "world_builder/nan.h"
#include "world_builder/types/array.h"
#include "world_builder/types/double.h"
#include "world_builder/types/object.h"
#include "world_builder/types/unsigned_int.h"
#include "world_builder/utilities.h"


namespace WorldBuilder
{

using namespace Utilities;

namespace Features
{
namespace SubductingPlateModels
{
namespace Composition
{
WaterContent::WaterContent(WorldBuilder::World *world_)

Check warning on line 41 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L41

Added line #L41 was not covered by tests
:
min_depth(NaN::DSNAN),
max_depth(NaN::DSNAN),
density(NaN::DSNAN)

Check warning on line 45 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L43-L45

Added lines #L43 - L45 were not covered by tests
{
this->world = world_;
this->name = "water content";
}

Check warning on line 49 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L47-L49

Added lines #L47 - L49 were not covered by tests

WaterContent::~WaterContent()

Check warning on line 51 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L51

Added line #L51 was not covered by tests
= default;

void
WaterContent::declare_entries(Parameters &prm, const std::string & /*unused*/)
{
// Document plugin and require entries if needed.
// Add compositions to the required parameters.
prm.declare_entry("", Types::Object({"compositions"}),
"WaterContent compositional model. Sets constant compositional field.");

// Declare entries of this plugin
prm.declare_entry("min distance slab top", Types::Double(0),
"todo The depth in meters from which the composition of this feature is present.");
prm.declare_entry("max distance slab top", Types::Double(std::numeric_limits<double>::max()),
"todo The depth in meters to which the composition of this feature is present.");
prm.declare_entry("density", Types::Double(3000.0),
"The reference density used to estimate the lithostatic pressure for calculating "
"the bound water content.");
prm.declare_entry("compositions", Types::Array(Types::UnsignedInt(),0),
"A list with the labels of the composition which are present there.");
prm.declare_entry("lithology", Types::String("peridotite"),
"The lithology used to determine which polynomials to use for calculating the water content.");
prm.declare_entry("initial water contents", Types::Array(Types::Double(5)),
"The value of the initial water content (in wt%) for the lithology at the trench. This is essentially the "
"max value applied to this lithology.");
prm.declare_entry("operation", Types::String("replace", std::vector<std::string> {"replace", "replace defined only", "add", "subtract"}),
"Whether the value should replace any value previously defined at this location (replace) or "
"add the value to the previously define value. Replacing implies that all compositions not "
"explicitly defined are set to zero. To only replace the defined compositions use the replace only defined option.");

}

void
WaterContent::parse_entries(Parameters &prm)

Check warning on line 85 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L85

Added line #L85 was not covered by tests
{
min_depth = prm.get<double>("min distance slab top");
max_depth = prm.get<double>("max distance slab top");
density = prm.get<double>("density");
compositions = prm.get_vector<unsigned int>("compositions");
max_water_contents = prm.get_vector<double>("initial water contents");
lithology_str = prm.get<std::string>("lithology");
operation = string_operations_to_enum(prm.get<std::string>("operation"));
}

Check warning on line 94 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L87-L94

Added lines #L87 - L94 were not covered by tests


double
WaterContent::get_composition(const Point<3> &position_in_cartesian_coordinates,

Check warning on line 98 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L98

Added line #L98 was not covered by tests
const double depth,
const unsigned int composition_number,
double composition,
const double /*feature_min_depth*/,
const double /*feature_max_depth*/,
const WorldBuilder::Utilities::PointDistanceFromCurvedPlanes &distance_from_plane,
// std::string lithology_str,
const AdditionalParameters & /*additional_parameters*/) const
{
if (distance_from_plane.distance_from_plane <= max_depth && distance_from_plane.distance_from_plane >= min_depth)

Check warning on line 108 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L108

Added line #L108 was not covered by tests
{
unsigned int lithology_index;
double max_water_value;
if (lithology_str == "peridotite")

Check warning on line 112 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L112

Added line #L112 was not covered by tests
{
lithology_index = 0;
max_water_value = max_water_contents[0];

Check warning on line 115 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L114-L115

Added lines #L114 - L115 were not covered by tests
}
if (lithology_str == "gabbro")

Check warning on line 117 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L117

Added line #L117 was not covered by tests
{
lithology_index = 1;
max_water_value = max_water_contents[1];

Check warning on line 120 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L119-L120

Added lines #L119 - L120 were not covered by tests
}
if (lithology_str == "MORB")

Check warning on line 122 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L122

Added line #L122 was not covered by tests
{
lithology_index = 2;
max_water_value = max_water_contents[2];

Check warning on line 125 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L124-L125

Added lines #L124 - L125 were not covered by tests
}
if (lithology_str == "sediment")

Check warning on line 127 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L127

Added line #L127 was not covered by tests
{
lithology_index = 3;
max_water_value = max_water_contents[3];

Check warning on line 130 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L129-L130

Added lines #L129 - L130 were not covered by tests
}

for (unsigned int i = 0; i < compositions.size(); ++i)

Check warning on line 133 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L133

Added line #L133 was not covered by tests
{
if (compositions[i] == composition_number)

Check warning on line 135 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L135

Added line #L135 was not covered by tests
{
// return apply_operation(operation,composition, partition_coefficient);
return apply_operation(operation,composition,std::min(max_water_value, distance_from_plane.water_content[lithology_index]));

Check warning on line 138 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L138

Added line #L138 was not covered by tests
}
}

if (operation == Operations::REPLACE)

Check warning on line 142 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L142

Added line #L142 was not covered by tests
{
return 0.0;

Check warning on line 144 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L144

Added line #L144 was not covered by tests
}
}
return composition;

Check warning on line 147 in source/world_builder/features/subducting_plate_models/composition/water_content.cc

View check run for this annotation

Codecov / codecov/patch

source/world_builder/features/subducting_plate_models/composition/water_content.cc#L147

Added line #L147 was not covered by tests
}
WB_REGISTER_FEATURE_SUBDUCTING_PLATE_COMPOSITION_MODEL(WaterContent, water content)
} // namespace Composition
} // namespace SubductingPlateModels
} // namespace Features
} // namespace WorldBuilder


Loading
Loading