1 #ifndef VTESTBED_CORE_TESTBED_HH 2 #define VTESTBED_CORE_TESTBED_HH 7 #include <vtestbed/base/blitz.hh> 8 #include <vtestbed/core/gerstner.hh> 9 #include <vtestbed/core/ship_motion_solver.hh> 10 #include <vtestbed/core/ship.hh> 11 #include <vtestbed/core/statistics.hh> 12 #include <vtestbed/core/types.hh> 13 #include <vtestbed/core/velocity_potential.hh> 14 #include <vtestbed/core/wave_numbers.hh> 15 #include <vtestbed/core/wave_pressure.hh> 16 #include <vtestbed/core/plain_wave_generator.hh> 17 #include <vtestbed/core/wetted_surface_solver.hh> 18 #include <vtestbed/core/arma_wind_solver.hh> 19 #include <vtestbed/core/anlt_wind_solver.hh> 25 enum Solver_type {regular_solver, gerstner_solver};
32 template <
class T,
int N>
45 using vertex_field_3d = blitz::Array<blitz::TinyVector<T,3>,3>;
54 using array_type = Array<T,N>;
55 using phi_array_type = Array<T,N+1>;
56 using domain3 = blitz::RectDomain<N>;
57 using domain4 = blitz::RectDomain<N+1>;
59 using array2 = Array<T,2>;
60 using array3 = Array<T,3>;
61 using vec3 = Vector3<T>;
71 using irregular_surface_type = Array<vec3, 3>;
72 using irregular_surface_type_2d = Array<vec3, 2>;
83 vertex_field_3d _wind_field;
87 domain3 _wpdomain_xyz;
88 array_type _wavysurface;
90 phi_array_type _vpotential;
94 irregular_surface_type _irregular_wavysurface;
95 vertex_field_3d _water_velocity;
96 Solver_type _solver_type = Solver_type::gerstner_solver;
107 inline void set_solver_type(Solver_type type) { this->_solver_type = type; }
108 inline Solver_type get_solver_type()
const {
return this->_solver_type; }
110 inline const ship_type& ship()
const {
return this->_ship; }
111 inline ship_type& ship() {
return this->_ship; }
112 inline void ship(
ship_type&& rhs) { this->_ship = std::move(rhs); }
113 inline void ship(
const ship_type& rhs) { this->_ship = rhs; }
117 this->_gerstner_solver = std::move(rhs);
118 set_solver_type(Solver_type::gerstner_solver);
123 return this->_gerstner_solver.get();
127 gerstner_solver()
const {
128 return this->_gerstner_solver.get();
133 this->_wsgenerator = std::move(rhs);
134 set_solver_type(Solver_type::regular_solver);
138 wavy_surface_generator()
const noexcept {
139 return this->_wsgenerator.get();
143 wavy_surface_generator() noexcept {
144 return this->_wsgenerator.get();
149 this->_vpsolver = std::move(rhs);
153 velocity_potential_solver()
const noexcept {
154 return this->_vpsolver.get();
158 velocity_potential_solver() noexcept {
159 return this->_vpsolver.get();
164 this->_wpsolver = std::move(rhs);
168 wave_pressure_solver()
const noexcept {
169 return this->_wpsolver.get();
173 wave_pressure_solver() noexcept {
174 return this->_wpsolver.get();
179 this->_wssolver = std::move(rhs);
183 wetted_surface_solver() {
184 return this->_wssolver.get();
188 wetted_surface_solver()
const {
189 return this->_wssolver.get();
196 inline const array_type&
198 return this->_wavysurface;
201 inline const grid4 grid()
const {
return this->_grid_txyz; }
204 wavy_surface_2d() const noexcept {
205 int t_idx = this->_grid_txyz.
extent(0)-1;
206 const auto& _ = blitz::Range::all();
207 return this->_wavysurface(t_idx,_,_);
210 inline irregular_surface_type
211 irregular_wavy_surface() {
212 return this->_irregular_wavysurface;
215 inline irregular_surface_type_2d
216 irregular_wavy_surface_2d()
const {
217 int t_idx = this->_grid_txyz.
extent(0)-1;
218 const auto& _ = blitz::Range::all();
219 return this->_irregular_wavysurface(t_idx,_,_).copy();
226 inline const phi_array_type&
228 return this->_vpotential;
232 velocity_potential_3d() const noexcept {
233 int t_idx = std::max(0, this->_vpgrid_tzxy.
extent(0)-1);
234 const auto& _ = blitz::Range::all();
235 return this->_vpotential(t_idx,_,_,_);
250 inline ship_motion_solver_type*
251 ship_motion_solver() {
252 return this->_ship_motion_solver.get();
255 inline const ship_motion_solver_type*
256 ship_motion_solver()
const {
257 return this->_ship_motion_solver.get();
265 this->_grid_txyz.
lbound(1) = rhs.lbound(0);
266 this->_grid_txyz.
lbound(2) = rhs.lbound(1);
267 this->_grid_txyz.
ubound(1) = rhs.ubound(0);
268 this->_grid_txyz.
ubound(2) = rhs.ubound(1);
269 this->_grid_txyz.
begin(1) = rhs.begin(0);
270 this->_grid_txyz.
begin(2) = rhs.begin(1);
271 this->_grid_txyz.
end(1) = rhs.end(0);
272 this->_grid_txyz.
end(2) = rhs.end(1);
281 return this->_grid_txyz.select(0,1,2);
289 return this->_grid_txyz.select(1,2);
298 return this->_vpgrid_tzxy;
302 velocity_potential_grid_3d() const noexcept {
303 return this->_vpgrid_tzxy.select(1,2,3);
309 inline const grid4& grid_txyz()
const {
return this->_grid_txyz; }
312 inline const panel_array&
314 return this->_wssolver->wetted_panels();
317 inline const panel_array&
318 dry_panels() const noexcept {
319 return this->_wssolver->dry_panels();
323 has_wetted_panels() const noexcept {
328 has_wave_pressure_domain() const noexcept {
329 return !blitz::empty(this->_wpdomain_xyz);
332 void record_statistics(statistics_type& stats);
333 inline const statistics_type& statistics()
const {
return this->_statistics; }
334 inline statistics_type& statistics() {
return this->_statistics; }
336 inline const vertex_field_3d& wind_field()
const {
return this->_wind_field; }
337 inline const grid3& wind_grid()
const {
return this->_wind_grid; }
339 inline const vertex_field_3d&
340 water_velocity_field()
const {
341 return this->_water_velocity;
345 arma_wind_solver(arma_wind_solver_ptr&& rhs) {
346 this->_arma_wind_solver = std::move(rhs);
350 anlt_wind_solver(anlt_wind_solver_ptr&& rhs) {
351 this->_anlt_wind_solver = std::move(rhs);
354 inline const anlt_wind_solver_type*
355 wind_solver()
const {
356 return this->_anlt_wind_solver.get();
359 inline const waterline_type&
361 return this->_wssolver->waterline();
364 void openmp_solvers();
365 void opencl_solvers();
366 void opencl_context(
void* ptr);
371 void step_irregular();
372 auto wave_number_grid_2d() const -> grid2;
373 void clamp_grid_to_wetted_panels();
374 void compute_velocity_potential();
375 void compute_wave_numbers();
376 void compute_wave_pressure();
377 void compute_wetted_panels_regular();
378 void compute_wetted_panels_irregular();
380 void generate_waves();
383 inline friend bstream&
384 operator<<(bstream& out, const Testbed& rhs) {
386 out << rhs._grid_txyz;
387 out << rhs._wavysurface;
388 out << rhs._vpotential;
392 inline friend bstream&
393 operator>>(bstream& in, Testbed& rhs) {
395 in >> rhs._grid_txyz;
396 in >> rhs._wavysurface;
397 in >> rhs._vpotential;
407 #endif // vim:filetype=cpp
Rigid ship with a mass and translational and angular velocity.
int extent(int i) const noexcept
The number of points for dimension i.
const panel_array & wetted_panels() const noexcept
Wetted ship hull faces that comprise underwater part of the hull.
const int_n & end() const noexcept
End indices (exclusive).
Base class for all wave pressure solvers.
grid4 velocity_potential_grid() const noexcept
const vec & lbound() const noexcept
Lower bound of the region.
grid2 wavy_surface_grid_2d() const noexcept
void wavy_surface_grid(const grid2 &rhs) noexcept
const array_type & wavy_surface() const noexcept
A region defined by start and end index and lower and upper bound for each dimension.
Triangular ship hull panel (face).
const int_n & begin() const noexcept
Start indices (inclusive).
Base class for all velocity potential solvers.
Main class for interacting with virtual testbed.
T time_instant() const noexcept
Current time instant in seconds.
const phi_array_type & velocity_potential() const noexcept
grid3 wavy_surface_grid() const noexcept
const vec & ubound() const noexcept
Upper bound of the region.
Base class for wavy surface generators.
void reset()
Reset simulation to the initial state and retain solver configuration.