World Builder  1.1.0-pre
A geodynamic initial conditions generator
segment.cc
Go to the documentation of this file.
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 
21 
22 
23 namespace WorldBuilder
24 {
25  namespace Features
26  {
27  namespace FaultModels
28  {
29  namespace Composition
30  {
31  class Interface;
32  } // namespace Composition
33  namespace Grains
34  {
35  class Interface;
36  } // namespace Grains
37  namespace Temperature
38  {
39  class Interface;
40  } // namespace Temperature
41  namespace Velocity
42  {
43  class Interface;
44  } // namespace Velocity
45  } // namespace FaultModels
46  namespace SubductingPlateModels
47  {
48  namespace Composition
49  {
50  class Interface;
51  } // namespace Composition
52  namespace Grains
53  {
54  class Interface;
55  } // namespace Grains
56  namespace Temperature
57  {
58  class Interface;
59  } // namespace Temperature
60  namespace Velocity
61  {
62  class Interface;
63  } // namespace Velocity
64  } // namespace SubductingPlateModels
65  } // namespace Features
66 
67  namespace Types
68  {
69  Segment::Segment(const double default_length_,
70  const WorldBuilder::Point<2> &default_thickness_,
71  const WorldBuilder::Point<2> &default_top_truncation_,
72  const WorldBuilder::Point<2> &default_angle_,
73  const Types::Interface &temperature_plugin_system_,
74  const Types::Interface &composition_plugin_system_,
75  const Types::Interface &grains_plugin_system_,
76  const Types::Interface &velocity_plugin_system_)
77  :
78  value_length(default_length_),
79  default_length(default_length_),
80  value_thickness(default_thickness_),
81  default_thickness(default_thickness_),
82  default_top_truncation(default_top_truncation_),
83  value_angle(default_angle_),
84  default_angle(default_angle_),
85  temperature_plugin_system(temperature_plugin_system_.clone()),
86  composition_plugin_system(composition_plugin_system_.clone()),
87  grains_plugin_system(grains_plugin_system_.clone()),
88  velocity_plugin_system(velocity_plugin_system_.clone())
89  {
91  }
92 
93 
94  Segment::Segment(Segment const &other)
95  :
101  value_angle(other.default_angle),
107  {
109  }
110 
111 
113  = default;
114 
115 
116 
117  void
119  const std::string &name,
120  const std::string &documentation) const
121  {
122  using namespace rapidjson;
123  prm.enter_subsection(name);
124  {
125  Document &declarations = prm.declarations;
126  std::string base = prm.get_full_json_path();
127 
128  Pointer((base + "/type").c_str()).Set(declarations,"object");
129  Pointer((base + "/additionalProperties").c_str()).Set(declarations,false);
130  Pointer((base + "/description").c_str()).Set(declarations,documentation.c_str());
131  std::vector<std::string> restricted_values = {"length", "thickness", "angle"};
132  for (unsigned int i = 0; i < restricted_values.size(); ++i)
133  {
134  if (!restricted_values[i].empty())
135  {
136  if (i == 0 && Pointer((base + "/required").c_str()).Get(declarations) == nullptr)
137  {
138  // The enum array doesn't exist yet, so we create it and fill it.
139  Pointer((base + "/required/0").c_str()).Create(declarations);
140  Pointer((base + "/required/0").c_str()).Set(declarations, restricted_values[i].c_str());
141  }
142  else
143  {
144  // The enum array already exist yet, so we add an element to the end.
145  Pointer((base + "/required/-").c_str()).Set(declarations, restricted_values[i].c_str());
146  }
147  }
148  }
149 
150  prm.enter_subsection("properties");
151  {
152  base = prm.get_full_json_path();
153  Pointer((base + "/length/type").c_str()).Set(declarations,"number");
154 
155  Pointer((base + "/thickness/type").c_str()).Set(declarations,"array");
156  Pointer((base + "/thickness/minItems").c_str()).Set(declarations,1);
157  Pointer((base + "/thickness/maxItems").c_str()).Set(declarations,2);
158  Pointer((base + "/thickness/items/type").c_str()).Set(declarations,"number");
159 
160  Pointer((base + "/top truncation/type").c_str()).Set(declarations,"array");
161  Pointer((base + "/top truncation/minItems").c_str()).Set(declarations,1);
162  Pointer((base + "/top truncation/maxItems").c_str()).Set(declarations,2);
163  Pointer((base + "/top truncation/items/type").c_str()).Set(declarations,"number");
164 
165  Pointer((base + "/angle/type").c_str()).Set(declarations,"array");
166  Pointer((base + "/angle/minItems").c_str()).Set(declarations,1);
167  Pointer((base + "/angle/maxItems").c_str()).Set(declarations,2);
168  Pointer((base + "/angle/items/type").c_str()).Set(declarations,"number");
169 
170  temperature_plugin_system->write_schema(prm, "temperature models", "");
171  composition_plugin_system->write_schema(prm, "composition models", "");
172  grains_plugin_system->write_schema(prm, "grains models", "");
173  velocity_plugin_system->write_schema(prm, "velocity models", "");
174  }
175  prm.leave_subsection();
176  }
177  prm.leave_subsection();
178 
179  }
180  } // namespace Types
181 } // namespace WorldBuilder
182 
WorldBuilder::Point< 2 > value_angle
Definition: segment.h:84
WorldBuilder::Point< 2 > value_thickness
Definition: segment.h:81
virtual std::unique_ptr< Interface > clone() const
Definition: interface.h:71
void write_schema(Parameters &prm, const std::string &name, const std::string &documentation) const override final
Definition: segment.cc:118
void enter_subsection(const std::string &name)
Definition: parameters.cc:1871
std::unique_ptr< Types::Interface > temperature_plugin_system
Definition: segment.h:86
std::unique_ptr< Types::Interface > velocity_plugin_system
Definition: segment.h:89
std::string get_full_json_path(size_t max_size=std::numeric_limits< size_t >::max()) const
Definition: parameters.cc:1933
WorldBuilder::Point< 2 > default_thickness
Definition: segment.h:82
WorldBuilder::Point< 2 > default_top_truncation
Definition: segment.h:83
WorldBuilder::Point< 2 > default_angle
Definition: segment.h:85
std::unique_ptr< Types::Interface > grains_plugin_system
Definition: segment.h:88
std::unique_ptr< Types::Interface > composition_plugin_system
Definition: segment.h:87
Segment(const double default_length, const WorldBuilder::Point< 2 > &default_thickness, const WorldBuilder::Point< 2 > &default_top_truncation, const WorldBuilder::Point< 2 > &default_angle, const Types::Interface &temperature_plugin_system, const Types::Interface &composition_plugin_system, const Types::Interface &grains_plugin_system_, const Types::Interface &gvelocity_plugin_system_)
Definition: segment.cc:69
rapidjson::Document declarations
Definition: parameters.h:248