World Builder  1.1.0-pre
A geodynamic initial conditions generator
wrapper_c.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 #include "world_builder/assert.h"
23 #include "world_builder/world.h"
24 #include <vector>
25 
26 extern "C" {
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)
35  {
36  bool has_output_dir = false;
37 
38  if (has_output_dir_ != nullptr)
39  {
40  has_output_dir = *has_output_dir_;
41  }
42 
43  std::string output_dir;
44  if (output_dir_ != nullptr)
45  {
46  output_dir = *output_dir_;
47  }
48 
50  new WorldBuilder::World(std::string(world_builder_file), has_output_dir,
51  output_dir, random_number_seed);
52 
53  *ptr_ptr_world = reinterpret_cast<void *>(a);
54  }
55 
56  unsigned int properties_output_size(void *ptr_ptr_world,const unsigned int properties_[][3],
57  const unsigned int n_properties)
58  {
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);
69  }
70 
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  {
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  }
91 
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[])
100  {
101  WorldBuilder::World *a = reinterpret_cast<WorldBuilder::World *>(ptr_ptr_world);
102  const std::array<double,3> position = {{x,y,z}};
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  }
115  }
116 
121  void temperature_2d(void *ptr_ptr_world, double x, double z, double depth,
122  double *temperature)
123  {
125  reinterpret_cast<WorldBuilder::World *>(ptr_ptr_world);
126  const std::array<double, 2> position = {{x, z}};
127  *temperature = a->temperature(position, depth);
128  }
129 
134  void temperature_3d(void *ptr_ptr_world, double x, double y, double z,
135  double depth, double *temperature)
136  {
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  }
142 
147  void composition_2d(void *ptr_ptr_world, double x, double z, double depth,
148  unsigned int composition_number, double *composition)
149  {
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);
154  }
155 
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  {
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  }
169 
174  void release_world(void *ptr_ptr_world)
175  {
177  reinterpret_cast<WorldBuilder::World *>(ptr_ptr_world);
178  delete a;
179  }
180 }
void temperature_3d(void *ptr_ptr_world, double x, double y, double z, double depth, double *temperature)
Definition: wrapper_c.cc:134
double composition(const std::array< double, 2 > &point, const double depth, const unsigned int composition_number) const
Definition: world.cc:520
void temperature_2d(void *ptr_ptr_world, double x, double z, double depth, double *temperature)
Definition: wrapper_c.cc:121
void properties_3d(void *ptr_ptr_world, const double x, const double y, const double z, const double depth, const unsigned int properties_[][3], const unsigned int n_properties, double values[])
This function returns 3D properties.
Definition: wrapper_c.cc:92
std::vector< double > properties(const std::array< double, 2 > &point, const double depth, const std::vector< std::array< unsigned int, 3 >> &properties) const
Definition: world.cc:315
void composition_2d(void *ptr_ptr_world, double x, double z, double depth, unsigned int composition_number, double *composition)
Definition: wrapper_c.cc:147
unsigned int properties_output_size(const std::vector< std::array< unsigned int, 3 >> &properties) const
Definition: world.cc:274
double temperature(const std::array< double, 2 > &point, const double depth) const
Definition: world.cc:490
void properties_2d(void *ptr_ptr_world, const double x, const double z, const double depth, const unsigned int properties_[][3], const unsigned int n_properties, double values[])
This function returns 2D properties.
Definition: wrapper_c.cc:71
void release_world(void *ptr_ptr_world)
Definition: wrapper_c.cc:174
void composition_3d(void *ptr_ptr_world, double x, double y, double z, double depth, unsigned int composition_number, double *composition)
Definition: wrapper_c.cc:160
unsigned int properties_output_size(void *ptr_ptr_world, const unsigned int properties_[][3], const unsigned int n_properties)
Definition: wrapper_c.cc:56
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)
Definition: wrapper_c.cc:32