1919
2020#include " world_builder/wrapper_c.h"
2121
22+ #include " world_builder/assert.h"
2223#include " world_builder/world.h"
24+ #include < vector>
2325
2426extern " C" {
2527 /* *
2628 * This function creates an object of the world builder and returns a pointer
2729 * to it. This pointer can then be used to call the temperature and composition
2830 * functions. When done call the release world function to destroy the object.
2931 */
30- void create_world (void **ptr_ptr_world, const char *world_builder_file, const bool *has_output_dir_, const char *output_dir_, const unsigned long random_number_seed)
32+ void create_world (void **ptr_ptr_world, const char *world_builder_file,
33+ const bool *has_output_dir_, const char *output_dir_,
34+ const unsigned long random_number_seed)
3135 {
3236 bool has_output_dir = false ;
3337
@@ -42,67 +46,135 @@ extern "C" {
4246 output_dir = *output_dir_;
4347 }
4448
45- WorldBuilder::World *a = new WorldBuilder::World (std::string (world_builder_file), has_output_dir, output_dir,random_number_seed);
49+ WorldBuilder::World *a =
50+ new WorldBuilder::World (std::string (world_builder_file), has_output_dir,
51+ output_dir, random_number_seed);
4652
4753 *ptr_ptr_world = reinterpret_cast <void *>(a);
4854 }
4955
50-
51- /* *
52- * This function return the temperature at a specific location given x, z, depth and
53- * gravity.
54- */
55- void temperature_2d (void *ptr_ptr_world, double x, double z, double depth, double *temperature)
56+ unsigned int properties_output_size (void *ptr_ptr_world,const unsigned int properties_[][3 ],
57+ const unsigned int n_properties)
5658 {
57- WorldBuilder::World *a = reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
58- const std::array<double ,2 > position = {{x,z}};
59- *temperature = a->temperature (position,depth);
59+ WorldBuilder::World *a =
60+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
61+ std::vector<std::array<unsigned int , 3 >> properties (n_properties);
62+ for (size_t i = 0 ; i < n_properties; ++i)
63+ {
64+ properties[i][0 ] = properties_[i][0 ];
65+ properties[i][1 ] = properties_[i][1 ];
66+ properties[i][2 ] = properties_[i][2 ];
67+ }
68+ return a->properties_output_size (properties);
6069 }
6170
71+ void properties_2d (void *ptr_ptr_world, const double x, const double z,
72+ const double depth, const unsigned int properties_[][3 ],
73+ const unsigned int n_properties, double values[])
74+ {
75+ WorldBuilder::World *a =
76+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
77+ const std::array<double , 2 > position = {{x, z}};
78+ std::vector<std::array<unsigned int , 3 >> properties (n_properties);
79+ for (size_t i = 0 ; i < n_properties; ++i)
80+ {
81+ properties[i][0 ] = properties_[i][0 ];
82+ properties[i][1 ] = properties_[i][1 ];
83+ properties[i][2 ] = properties_[i][2 ];
84+ }
85+ std::vector<double > returned_values = a->properties (position, depth, properties);
86+ for (unsigned i = 0 ; i < returned_values.size (); ++i)
87+ {
88+ values[i] = returned_values[i];
89+ }
90+ }
6291
63- /* *
64- * This function return the temperature at a specific location given x, y, z, depth and
65- * gravity.
66- */
67- void temperature_3d (void *ptr_ptr_world, double x, double y, double z, double depth, double *temperature)
92+ void properties_3d (void *ptr_ptr_world,
93+ const double x,
94+ const double y,
95+ const double z,
96+ const double depth,
97+ const unsigned int properties_[][3 ],
98+ const unsigned int n_properties,
99+ double values[])
68100 {
69101 WorldBuilder::World *a = reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
70102 const std::array<double ,3 > position = {{x,y,z}};
71- *temperature = a->temperature (position,depth);
103+ std::vector<std::array<unsigned int ,3 >> properties (n_properties);
104+ for (size_t i = 0 ; i < n_properties; ++i)
105+ {
106+ properties[i][0 ] = properties_[i][0 ];
107+ properties[i][1 ] = properties_[i][1 ];
108+ properties[i][2 ] = properties_[i][2 ];
109+ }
110+ std::vector<double > returned_values = a->properties (position, depth, properties);
111+ for (unsigned i = 0 ; i < returned_values.size (); ++i)
112+ {
113+ values[i] = returned_values[i];
114+ }
72115 }
73116
74-
75117 /* *
76- * This function return the composition at a specific location given x, z, depth and
77- * composition number .
118+ * This function return the temperature at a specific location given x, z, depth
119+ * and gravity .
78120 */
79- void composition_2d (void *ptr_ptr_world, double x, double z, double depth, unsigned int composition_number, double *composition)
121+ void temperature_2d (void *ptr_ptr_world, double x, double z, double depth,
122+ double *temperature)
80123 {
81- WorldBuilder::World *a = reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
82- const std::array<double ,2 > position = {{x,z}};
83- *composition = a->composition (position,depth,composition_number);
124+ WorldBuilder::World *a =
125+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
126+ const std::array<double , 2 > position = {{x, z}};
127+ *temperature = a->temperature (position, depth);
84128 }
85129
130+ /* *
131+ * This function return the temperature at a specific location given x, y, z,
132+ * depth and gravity.
133+ */
134+ void temperature_3d (void *ptr_ptr_world, double x, double y, double z,
135+ double depth, double *temperature)
136+ {
137+ WorldBuilder::World *a =
138+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
139+ const std::array<double , 3 > position = {{x, y, z}};
140+ *temperature = a->temperature (position, depth);
141+ }
86142
87143 /* *
88- * This function return the composition at a specific location given x, y, z, depth and
89- * composition number.
144+ * This function return the composition at a specific location given x, z, depth
145+ * and composition number.
90146 */
91- void composition_3d (void *ptr_ptr_world, double x, double y, double z, double depth, unsigned int composition_number, double *composition)
147+ void composition_2d (void *ptr_ptr_world, double x, double z, double depth,
148+ unsigned int composition_number, double *composition)
92149 {
93- WorldBuilder::World *a = reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
94- const std::array<double ,3 > position = {{x,y,z}};
95- *composition = a->composition (position,depth,composition_number);
150+ WorldBuilder::World *a =
151+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
152+ const std::array<double , 2 > position = {{x, z}};
153+ *composition = a->composition (position, depth, composition_number);
96154 }
97155
156+ /* *
157+ * This function return the composition at a specific location given x, y, z,
158+ * depth and composition number.
159+ */
160+ void composition_3d (void *ptr_ptr_world, double x, double y, double z,
161+ double depth, unsigned int composition_number,
162+ double *composition)
163+ {
164+ WorldBuilder::World *a =
165+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
166+ const std::array<double , 3 > position = {{x, y, z}};
167+ *composition = a->composition (position, depth, composition_number);
168+ }
98169
99170 /* *
100- * The destructor for the world builder class. Call this function when done with the
101- * world builder.
171+ * The destructor for the world builder class. Call this function when done with
172+ * the world builder.
102173 */
103174 void release_world (void *ptr_ptr_world)
104175 {
105- WorldBuilder::World *a = reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
176+ WorldBuilder::World *a =
177+ reinterpret_cast <WorldBuilder::World *>(ptr_ptr_world);
106178 delete a;
107179 }
108180}
0 commit comments