World Ocean Simulation System (WOSS) library
woss.h
Go to the documentation of this file.
1/* WOSS - World Ocean Simulation System -
2 *
3 * Copyright (C) 2009 2025 Federico Guerra
4 * and regents of the SIGNET lab, University of Padova
5 *
6 * Author: Federico Guerra - WOSS@guerra-tlc.com
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation;
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
32#ifndef WOSS_PROGRAM_DEFINITIONS_H
33#define WOSS_PROGRAM_DEFINITIONS_H
34
35
36#include <set>
37#include <map>
38#include <climits>
39#ifdef WOSS_MULTITHREAD
40#include <atomic>
41#endif // WOSS_MULTITHREAD
43#include <time-definitions.h>
46#include "res-reader.h"
47
48
49namespace woss {
50
51 class WossDbManager;
52
56 using FreqSet = std::set< double >;
57 using FreqSIt = FreqSet::iterator;
58 using FreqSCIt = FreqSet::const_iterator;
59 using FreqSRIt = FreqSet::reverse_iterator;
60 using FreqSCRIt = FreqSet::const_reverse_iterator;
61
62 static constexpr inline int WOSS_MIN_DEPTH = 0;
64 static constexpr inline int WOSS_MAX_DEPTH = INT_MAX;
66 static constexpr inline int WOSS_MIN_RANGE = -INT_MAX;
68 static constexpr inline int WOSS_MAX_RANGE = INT_MAX;
76 class Woss {
77
78 public:
79
83 Woss();
84
95 Woss( const CoordZ& tx, const CoordZ& rx, const Time& start_t, const Time& end_t, double start_freq, double end_freq, double freq_step ) ;
96
97 virtual ~Woss();
98
103 virtual bool initialize() = 0;
104
110 virtual bool run() = 0;
111
117 virtual bool timeEvolve( const Time& time_value ) = 0;
118
123 virtual bool isValid() const = 0;
124
135 virtual std::unique_ptr<Pressure> getAvgPressure( double frequency, double tx_depth, double start_rx_depth = WOSS_MIN_DEPTH, double start_rx_range = WOSS_MIN_RANGE, double end_rx_depth = WOSS_MAX_DEPTH , double end_rx_range = WOSS_MAX_RANGE ) const = 0;
136
145 virtual std::unique_ptr<Pressure> getPressure( double frequency, double tx_depth, double rx_depth, double rx_range ) const = 0;
146
155 virtual std::unique_ptr<TimeArr> getTimeArr( double frequency, double tx_depth, double rx_depth, double rx_range ) const = 0;
156
162 Woss& setDebug( bool flag ) { debug = flag; return *this; }
163
169 Woss& setCleanWorkDir( bool flag ) { clean_workdir = flag; return *this; }
170
176 Woss& setWorkDirPath( const std::string& path ) { work_dir_path = path; return *this; }
177
183 Woss& setWossDbManager( const std::shared_ptr<WossDbManager>& ptr ) { db_manager = ptr; return *this; }
184
190 Woss& insertFrequency( double freq ) { frequencies.emplace(freq); return *this; }
191
199 Woss& insertFrequencies( double freq_start, double freq_end, double freq_step );
200
206 Woss& setFrequencies( const FreqSet& freq_set ) { frequencies = freq_set; return *this; }
207
213 Woss& eraseFrequency( double freq ) { frequencies.erase(freq); return *this; }
214
219 Woss& clearFrequencies() { frequencies.clear(); return *this; }
220
226 Woss& setTotalRuns( int runs ) { total_runs = runs; return *this; }
227
233 Woss& setTxCoordZ( const CoordZ& coordz ) { tx_coordz = coordz; return *this; }
234
240 Woss& setRxCoordZ( const CoordZ& coordz ) { rx_coordz = coordz; return *this; }
241
247 Woss& setStartTime( const Time& start_t ) { start_time = start_t; return *this; }
248
254 Woss& setEndTime( const Time& end_t ) { end_time = end_t; return *this; }
255
261 Woss& setEvolutionTimeQuantum( double value ) { evolution_time_quantum = value; return *this; }
262
267 int getWossId() const { return woss_id; }
268
273 std::string getWorkDirPath() const { return work_dir_path; }
274
279 const FreqSet& getFrequencies() const { return frequencies; }
280
285 double getMinFrequency() const { return( *( frequencies.begin() ) ); }
286
291 double getMaxFrequency() const { return( *( frequencies.rbegin() ) ); }
292
297 FreqSCIt freq_begin() const { return( frequencies.begin() ); }
298
303 FreqSCIt freq_end() const { return( frequencies.end() ); }
304
309 FreqSCRIt freq_rbegin() const { return( frequencies.rbegin() ); }
310
315 FreqSCRIt freq_rend() const { return( frequencies.rend() ); }
316
322 FreqSCIt freq_lower_bound( double frequency ) const { return( frequencies.lower_bound( frequency ) ); }
323
329 FreqSCIt freq_upper_bound( double frequency ) const { return( frequencies.upper_bound( frequency ) ); }
330
335 int getTotalRuns() const { return total_runs; }
336
341 CoordZ getTxCoordZ() const { return tx_coordz; }
342
347 CoordZ getRxCoordZ() const { return rx_coordz; }
348
353 Time getStartTime() const { return start_time; }
354
359 Time getCurrentTime() const { return current_time; }
360
365 Time getEndTime() const { return end_time; }
366
372
379
384 double getDistance() const { return total_distance; }
385
390 double getBearing() const { return bearing; }
391
395 bool usingDebug() const { return debug; }
396
400 virtual bool isRunning() const;
401
402 protected:
403
404#if defined (WOSS_MULTITHREAD)
408 static std::atomic<int> woss_counter;
409#else
413 static int woss_counter;
414#endif // defined (WOSS_MULTITHREAD)
418 int woss_id;
419
423 std::string work_dir_path;
424
428 std::shared_ptr<WossDbManager> db_manager;
429
434
439
444
451
456
461
466
471 double bearing;
472
478
484
489
493 bool debug;
494
495#if defined (WOSS_MULTITHREAD)
496 std::atomic<bool> has_run_once;
497
501 std::atomic<bool> is_running;
502#else
504
508 volatile bool is_running;
509#endif // defined (WOSS_MULTITHREAD)
510
515
522 virtual bool mkWorkDir( double curr_frequency, int curr_run = 0 );
523
530 virtual bool rmWorkDir( double curr_frequency, int curr_run = 0 );
531
532 virtual bool rmWorkDir();
533
534 };
535
539 using ResReaderMap = std::map< double, std::unique_ptr<ResReader> >;
540 using RRMIter = ResReaderMap::iterator;
541 using RRMRIter = ResReaderMap::reverse_iterator;
542 using RRMCIter = ResReaderMap::const_iterator;
543 using RRMCRIter = ResReaderMap::const_reverse_iterator;
544 using RRMPair = std::pair< RRMIter, bool >;
545
546
553 class WossResReader : public Woss {
554
555 public:
556
560 WossResReader() = default;
561
572 WossResReader( const CoordZ& tx, const CoordZ& rx, const Time& start_t, const Time& end_t,
573 double start_freq, double end_freq, double freq_step )
574 : Woss( tx, rx, start_t, end_t, start_freq, end_freq, freq_step ) { }
575
576 virtual ~WossResReader() override = default;
577
583 virtual bool initResReader( double curr_frequency ) = 0;
584
585 protected:
586
591
595 void clearResReaderMap();
596
597 };
598
599}
600
601#endif /* WOSS_PROGRAM_DEFINITIONS_H */
602
603
3D-Coordinates (lat, long, depth) class definitions and functions library
Definition coordinates-definitions.h:384
a class for time date manipulation
Definition time-definitions.h:83
Woss class with ResReader objects for reading simulated results.
Definition woss.h:553
WossResReader()=default
virtual ~WossResReader() override=default
ResReaderMap res_reader_map
Definition woss.h:590
void clearResReaderMap()
Definition woss.cpp:225
virtual bool initResReader(double curr_frequency)=0
WossResReader(const CoordZ &tx, const CoordZ &rx, const Time &start_t, const Time &end_t, double start_freq, double end_freq, double freq_step)
Definition woss.h:572
Abstract class that provides the interface for initializing and running a channel simulator.
Definition woss.h:76
std::shared_ptr< WossDbManager > db_manager
Definition woss.h:428
Woss & setStartTime(const Time &start_t)
Definition woss.h:247
virtual bool mkWorkDir(double curr_frequency, int curr_run=0)
Definition woss.cpp:146
CoordZ getRxCoordZ() const
Definition woss.h:347
Time getStartTime() const
Definition woss.h:353
double getDistance() const
Definition woss.h:384
Woss & insertFrequencies(double freq_start, double freq_end, double freq_step)
Definition woss.cpp:109
double evolution_time_quantum
Definition woss.h:450
FreqSCRIt freq_rbegin() const
Definition woss.h:309
virtual std::unique_ptr< Pressure > getAvgPressure(double frequency, double tx_depth, double start_rx_depth=WOSS_MIN_DEPTH, double start_rx_range=WOSS_MIN_RANGE, double end_rx_depth=WOSS_MAX_DEPTH, double end_rx_range=WOSS_MAX_RANGE) const =0
Woss & setCleanWorkDir(bool flag)
Definition woss.h:169
virtual std::unique_ptr< TimeArr > getTimeArr(double frequency, double tx_depth, double rx_depth, double rx_range) const =0
virtual bool run()=0
double bearing
Definition woss.h:471
CoordZ tx_coordz
Definition woss.h:455
static std::atomic< int > woss_counter
Definition woss.h:408
int getWossId() const
Definition woss.h:267
FreqSCRIt freq_rend() const
Definition woss.h:315
Woss & setRxCoordZ(const CoordZ &coordz)
Definition woss.h:240
Woss & setFrequencies(const FreqSet &freq_set)
Definition woss.h:206
Woss & setTxCoordZ(const CoordZ &coordz)
Definition woss.h:233
virtual ~Woss()
Definition woss.cpp:101
CoordZ getTxCoordZ() const
Definition woss.h:341
int getTotalRuns() const
Definition woss.h:335
const FreqSet & getFrequencies() const
Definition woss.h:279
Woss & setEndTime(const Time &end_t)
Definition woss.h:254
virtual bool isRunning() const
Definition woss.cpp:220
double getMaxFrequency() const
Definition woss.h:291
std::atomic< bool > has_run_once
Definition woss.h:496
bool debug
Definition woss.h:493
static int woss_counter
Definition woss.h:413
FreqSCIt freq_begin() const
Definition woss.h:297
Woss & clearFrequencies()
Definition woss.h:219
virtual bool initialize()=0
Definition woss.cpp:206
Woss & insertFrequency(double freq)
Definition woss.h:190
Woss()
Definition woss.cpp:47
Time current_time
Definition woss.h:438
FreqSCIt freq_upper_bound(double frequency) const
Definition woss.h:329
FreqSet frequencies
Definition woss.h:465
Time end_time
Definition woss.h:443
Time start_time
Definition woss.h:433
Woss & setWorkDirPath(const std::string &path)
Definition woss.h:176
volatile bool is_running
Definition woss.h:508
Woss & setWossDbManager(const std::shared_ptr< WossDbManager > &ptr)
Definition woss.h:183
bool has_run_once
Definition woss.h:503
double total_great_circle_distance
Definition woss.h:477
FreqSCIt freq_end() const
Definition woss.h:303
double getMinFrequency() const
Definition woss.h:285
Woss & setDebug(bool flag)
Definition woss.h:162
Woss & setEvolutionTimeQuantum(double value)
Definition woss.h:261
double getGreatCircleDistance() const
Definition woss.h:378
virtual std::unique_ptr< Pressure > getPressure(double frequency, double tx_depth, double rx_depth, double rx_range) const =0
int total_runs
Definition woss.h:488
bool usingDebug() const
Definition woss.h:395
std::string work_dir_path
Definition woss.h:423
bool clean_workdir
Definition woss.h:514
std::string getWorkDirPath() const
Definition woss.h:273
std::atomic< bool > is_running
Definition woss.h:501
Woss & setTotalRuns(int runs)
Definition woss.h:226
Time getEndTime() const
Definition woss.h:365
double getBearing() const
Definition woss.h:390
int woss_id
Definition woss.h:418
virtual bool rmWorkDir()
Definition woss.cpp:120
CoordZ rx_coordz
Definition woss.h:460
virtual bool isValid() const =0
double total_distance
Definition woss.h:483
virtual bool timeEvolve(const Time &time_value)=0
Woss & eraseFrequency(double freq)
Definition woss.h:213
double getEvolutionTimeQuantum() const
Definition woss.h:371
Time getCurrentTime() const
Definition woss.h:359
FreqSCIt freq_lower_bound(double frequency) const
Definition woss.h:322
Provides the interface for the woss::Coord and woss::CoordZ classes.
Definition ac-toolbox-arr-asc-reader.h:44
ResReaderMap::iterator RRMIter
Definition woss.h:540
FreqSet::const_reverse_iterator FreqSCRIt
Definition woss.h:60
std::map< double, std::unique_ptr< ResReader > > ResReaderMap
Definition woss.h:539
FreqSet::reverse_iterator FreqSRIt
Definition woss.h:59
FreqSet::iterator FreqSIt
Definition woss.h:57
std::set< double > FreqSet
Definition woss.h:56
ResReaderMap::reverse_iterator RRMRIter
Definition woss.h:541
std::pair< RRMIter, bool > RRMPair
Definition woss.h:544
ResReaderMap::const_iterator RRMCIter
Definition woss.h:542
FreqSet::const_iterator FreqSCIt
Definition woss.h:58
ResReaderMap::const_reverse_iterator RRMCRIter
Definition woss.h:543
Definitions and library for woss::Pressure class.
Provides the interface for woss::ResReader class.
Definitions and library for woss::TimeArr class.
Definitions and library for woss::Time, woss::SimTime, woss::TimeReference and woss::TimeReferenceTcl...