Navigation

Main Page
Download
Support
Installation
Tutorial
Examples
Reference Manual
   Version 1.0.6dev
      Class Index
      File List
   Version 1.0.6
   Version 1.0.5new_solver
   Version 1.0.5dev
   Version 1.0.5b
   Version 1.0.4dev
   Version 1.0.4
Publications


Hosted by Get Ion Beam Simulator at SourceForge.net. Fast, secure and Free Open Source software downloads
ibsimu.hpp
Go to the documentation of this file.
1 
5 /* Copyright (c) 2010-2012 Taneli Kalvas. All rights reserved.
6  *
7  * You can redistribute this software and/or modify it under the terms
8  * of the GNU General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this library (file "COPYING" included in the package);
19  * if not, write to the Free Software Foundation, Inc., 51 Franklin
20  * Street, Fifth Floor, Boston, MA 02110-1301 USA
21  *
22  * If you have questions about your rights to use or distribute this
23  * software, please contact Berkeley Lab's Technology Transfer
24  * Department at TTD@lbl.gov. Other questions, comments and bug
25  * reports should be sent directly to the author via email at
26  * taneli.kalvas@jyu.fi.
27  *
28  * NOTICE. This software was developed under partial funding from the
29  * U.S. Department of Energy. As such, the U.S. Government has been
30  * granted for itself and others acting on its behalf a paid-up,
31  * nonexclusive, irrevocable, worldwide license in the Software to
32  * reproduce, prepare derivative works, and perform publicly and
33  * display publicly. Beginning five (5) years after the date
34  * permission to assert copyright is obtained from the U.S. Department
35  * of Energy, and subject to any subsequent five (5) year renewals,
36  * the U.S. Government is granted for itself and others acting on its
37  * behalf a paid-up, nonexclusive, irrevocable, worldwide license in
38  * the Software to reproduce, prepare derivative works, distribute
39  * copies to the public, perform publicly and display publicly, and to
40  * permit others to do so.
41  */
42 
43 
44 #ifndef IBSIMU_HPP
45 #define IBSIMU_HPP 1
46 
47 
48 #include <stdint.h>
49 #include <stdarg.h>
50 #include <string>
51 #include <iostream>
52 #include <fstream>
53 #include <sstream>
54 
55 
56 class Timer;
57 
58 
63 #define MSG_COUNT 5
64 
68  MSG_VERBOSE = 0,
69  MSG_WARNING,
70  MSG_ERROR,
71  MSG_DEBUG_GENERAL,
72  MSG_DEBUG_DXF
73 };
74 
75 
78 enum rng_type_e {
79  RNG_SOBOL = 0,
80  RNG_MT
81 };
82 
83 
89 class IBSimu
90 {
91  Timer *_t;
92 
93  bool _hello;
94  uint32_t _threadcount;
95  rng_type_e _rng;
96 
97  struct nullstream: std::ostream {
98  struct nullbuf: std::streambuf {
99  int overflow( int c ) { return( traits_type::not_eof(c) ); }
100  } m_sbuf;
101  nullstream(): std::ios(&m_sbuf), std::ostream(&m_sbuf) {}
102  };
103 
104  std::stringstream _ss;
105  nullstream _ns;
106  std::ofstream _fo;
107  std::ostream *_os; // Message output stream
108 
109  int32_t _indent;
110  int32_t _message_threshold[MSG_COUNT];
111 
116  IBSimu( const IBSimu &ibs );
117 
118  const IBSimu &operator=( const IBSimu &ibs ) { return( *this ); }
119 
120  size_t convert_stringstream_to_lines( const std::stringstream &ss,
121  size_t indentation,
122  std::string &target,
123  bool &lineunfinished );
124 
125 public:
126 
129  IBSimu();
130 
133  ~IBSimu();
134 
140  std::ostream &set_message_output( std::ostream &os );
141 
150  std::ostream &set_message_output( const std::string &filename );
151 
159  std::ostream &message( message_type_e type, int32_t level );
160 
161  std::ostream &message( int32_t level );
162 
163  void flush( bool finishlines = true );
164 
167  void inc_indent( void );
168 
171  void dec_indent( void );
172 
175  bool output_is_cout();
176 
186  void set_message_threshold( message_type_e type, int32_t level );
187 
192  int32_t get_message_threshold( message_type_e type );
193 
194 
195 
196 
199  void set_thread_count( uint32_t threadcount );
200 
203  uint32_t get_thread_count( void ) { return( _threadcount ); }
204 
205 
206 
213  void set_rng_type( rng_type_e type );
214 
217  rng_type_e get_rng_type( void ) { return( _rng ); }
218 
219 
220 
225  void halt( void );
226 };
227 
228 
231 extern IBSimu ibsimu;
232 
233 
234 #endif
235 
Main class for IBSimu.
Definition: ibsimu.hpp:90
rng_type_e get_rng_type(void)
Get the random number generator type.
Definition: ibsimu.hpp:217
void halt(void)
Halt execution.
int32_t get_message_threshold(message_type_e type)
Get message threshold level.
Definition: ibsimu.cpp:206
void set_rng_type(rng_type_e type)
Set the random number generator to use.
Definition: ibsimu.cpp:280
uint32_t get_thread_count(void)
Get the number of threads used for calculation.
Definition: ibsimu.hpp:203
void set_message_threshold(message_type_e type, int32_t level)
Set message threshold level.
Definition: ibsimu.cpp:190
void dec_indent(void)
Decrease message indentation.
Definition: ibsimu.cpp:143
bool output_is_cout()
Return if message output file is stdout.
Definition: ibsimu.cpp:184
IBSimu()
Default constructor.
Definition: ibsimu.cpp:61
std::ostream & set_message_output(std::ostream &os)
Set message output to stream os.
Definition: ibsimu.cpp:150
~IBSimu()
Default destructor.
Definition: ibsimu.cpp:96
std::ostream & message(message_type_e type, int32_t level)
Print message output.
Definition: ibsimu.cpp:111
void set_thread_count(uint32_t threadcount)
Set the number of threads used for calculation.
Definition: ibsimu.cpp:272
void inc_indent(void)
Increase message indentation.
Definition: ibsimu.cpp:136
Class for measuring code runtime in cpu time and realtime.
Definition: timer.hpp:54
message_type_e
Output type.
Definition: ibsimu.hpp:67
rng_type_e
Output type.
Definition: ibsimu.hpp:78
#define MSG_COUNT
Message type count.
Definition: ibsimu.hpp:63
IBSimu ibsimu
Global instance of class IBSimu.
Definition: ibsimu.cpp:289
Definition: ibsimu.hpp:98


Reference manual for Ion Beam Simulator 1.0.6dev
Generated by Doxygen 1.9.1 on Thu Sep 11 2025 09:37:24.