block_selector_test.cc File Reference
#include "generic.h"

Functions

int main (int argc, char *argv[])
 Driver code: Testing BlockSelector class. More...
 

Function Documentation

◆ main()

int main ( int argc  ,
char argv[] 
)

Driver code: Testing BlockSelector class.

36 {
37  // Store command line arguments
38  CommandLineArgs::setup(argc,argv);
39 
41  "--test_default_constructor");
43  "--test_constructor_with_param");
45  "--test_select_block_function");
47  "--test_want_block_function");
49  "--test_do_not_want_block_function");
51  "--test_do_not_want_block_function_replace");
53  "--test_set_row_index_function");
55  "--test_set_column_index_function");
56 
57 
58  // Parse the above flags.
61 
62 
63 
64 
65  // Testing the default constructor.
66  // This sets the Replacement_block_pt to 0
67  // then calls BlockSelector::build(0,0,false)
68  //
69  // Which sets Row_index = 0
70  // Column_index = 0
71  // Wanted = false
72  //
73  // We check this.
75  "--test_default_constructor"))
76  {
77  // Create the output file.
78  std::ostringstream out_stream_name;
79  out_stream_name << "OUTFILE_default_constructor_test";
80  std::ofstream out_file;
81  out_file.open(out_stream_name.str().c_str());
82 
83  BlockSelector block_selector_default;
84  out_file << block_selector_default << "\n";
85 
86  out_file.close();
87  }
88  // Testing the constructor with parameters but no replacement block.
89  // We test both wanted and not wanted versions.
91  "--test_constructor_with_param"))
92  {
93  // Create the output file.
94  std::ostringstream out_stream_name1;
95  out_stream_name1 << "OUTFILE_constructor_with_param_wanted";
96  std::ofstream out_file1;
97  out_file1.open(out_stream_name1.str().c_str());
98 
99  BlockSelector block_selector_with_param_wanted(1,2,true);
100  out_file1 << block_selector_with_param_wanted << "\n";
101 
102  out_file1.close();
103 
104 
105  // Create the output file.
106  std::ostringstream out_stream_name2;
107  out_stream_name2 << "OUTFILE_constructor_with_param_not_wanted";
108  std::ofstream out_file2;
109  out_file2.open(out_stream_name2.str().c_str());
110 
111  BlockSelector block_selector_with_param_not_wanted(3,4,false);
112  out_file2 << block_selector_with_param_not_wanted << "\n";
113 
114  out_file2.close();
115 
116 
117  // Create the output file.
118  std::ostringstream out_stream_name3;
119  out_stream_name3 << "OUTFILE_constructor_with_param_replace";
120  std::ofstream out_file3;
121  out_file3.open(out_stream_name3.str().c_str());
122 
123  CRDoubleMatrix testmat;
124  BlockSelector block_selector_with_param_replace(5,6,true,&testmat);
125  out_file3 << block_selector_with_param_replace << "\n";
126  block_selector_with_param_replace.null_replacement_block_pt();
127 
128  out_file3.close();
129  }
130  // Once the BlockSelector is constructed, you can use the select_block()
131  // function to select the block you want. We test this.
133  "--test_select_block_function"))
134  {
135  // Create the output file.
136  std::ostringstream out_stream_name1;
137  out_stream_name1 << "OUTFILE_select_block_wanted";
138  std::ofstream out_file1;
139  out_file1.open(out_stream_name1.str().c_str());
140 
141  BlockSelector block_selector_wanted;
142  block_selector_wanted.select_block(1,2,true);
143  out_file1 << block_selector_wanted << "\n";
144  out_file1.close();
145 
146 
147  // Create the output file.
148  std::ostringstream out_stream_name2;
149  out_stream_name2 << "OUTFILE_select_block_not_wanted";
150  std::ofstream out_file2;
151  out_file2.open(out_stream_name2.str().c_str());
152 
153  BlockSelector block_selector_not_wanted;
154  block_selector_not_wanted.select_block(3,4,false);
155  out_file2 << block_selector_not_wanted << "\n";
156  out_file2.close();
157 
158 
159  // Create the output file.
160  std::ostringstream out_stream_name3;
161  out_stream_name3 << "OUTFILE_select_block_replace";
162  std::ofstream out_file3;
163  out_file3.open(out_stream_name3.str().c_str());
164 
165  CRDoubleMatrix testmat;
166  BlockSelector block_selector_replace;
167  block_selector_replace.select_block(5,6,true,&testmat);
168  out_file3 << block_selector_replace << "\n";
169  block_selector_replace.null_replacement_block_pt();
170  out_file3.close();
171  }
172  // Testing BlockSelector::want_block().
174  "--test_want_block_function"))
175  {
176  // Create the output file.
177  std::ostringstream out_stream_name;
178  out_stream_name << "OUTFILE_want_block";
179  std::ofstream out_file;
180  out_file.open(out_stream_name.str().c_str());
181 
182  BlockSelector block_selector(1,2,false);
183  block_selector.want_block();
184  out_file << block_selector << "\n";
185  out_file.close();
186  }
187  // Testing BlockSelector::do_not_want_block().
188  // There are two tests:
189  // If no replacement block is set, then calling do_not_want_block simply
190  // sets Wanted to false.
191  // If a replacement block is set, it nulls the pointer, gives a warning
192  // (if paranoid is turned on), then sets Wanted to false.
194  "--test_do_not_want_block_function"))
195  {
196  // Create the output file.
197  std::ostringstream out_stream_name;
198  out_stream_name << "OUTFILE_do_not_want_block";
199  std::ofstream out_file;
200  out_file.open(out_stream_name.str().c_str());
201 
202  BlockSelector block_selector(1,2,true);
203  block_selector.do_not_want_block();
204  out_file << block_selector << "\n";
205  out_file.close();
206  }
208  "--test_do_not_want_block_function_replace"))
209  {
210  // Create the output file.
211  std::ostringstream out_stream_name;
212  out_stream_name << "OUTFILE_do_not_want_block_replace";
213  std::ofstream out_file;
214  out_file.open(out_stream_name.str().c_str());
215 
216  CRDoubleMatrix testmat;
217  BlockSelector block_selector(1,2,true,&testmat);
218  block_selector.do_not_want_block();
219  out_file << block_selector << "\n";
220  out_file.close();
221  }
222  // Testing BlockSelector::set_row_index().
224  "--test_set_row_index_function"))
225  {
226  // Create the output file.
227  std::ostringstream out_stream_name;
228  out_stream_name << "OUTFILE_set_row_index";
229  std::ofstream out_file;
230  out_file.open(out_stream_name.str().c_str());
231 
232  BlockSelector block_selector;
233  block_selector.set_row_index(42);
234  out_file << block_selector << "\n";
235  out_file.close();
236  }
237  // Testing BlockSelector::set_row_index().
239  "--test_set_column_index_function"))
240  {
241  // Create the output file.
242  std::ostringstream out_stream_name;
243  out_stream_name << "OUTFILE_set_column_index";
244  std::ofstream out_file;
245  out_file.open(out_stream_name.str().c_str());
246 
247  BlockSelector block_selector;
248  block_selector.set_column_index(42);
249  out_file << block_selector << "\n";
250  out_file.close();
251  }
252  else
253  {
254  std::ostringstream err_msg;
255  err_msg << "No test is recognised.\n"
256  << "Please set the appropriate command line flag."
257  << std::endl;
258 
259  throw OomphLibError(err_msg.str(),
262  }
263 
264  return(EXIT_SUCCESS);
265 } // end_of_main
Definition: block_preconditioner.h:124
void null_replacement_block_pt()
Set Replacement_block_pt to null.
Definition: block_preconditioner.h:241
void select_block(const unsigned &row_index, const unsigned &column_index, const bool &wanted, CRDoubleMatrix *replacement_block_pt=0)
Select a block.
Definition: block_preconditioner.h:188
void set_column_index(const unsigned &column_index)
Set the column index.
Definition: block_preconditioner.h:284
void set_row_index(const unsigned &row_index)
Set the row index.
Definition: block_preconditioner.h:272
Definition: matrices.h:888
Definition: oomph_definitions.h:222
void setup(Time *time_pt)
Create all GeomObjects needed to define the cylinder and the flag.
Definition: turek_flag_non_fsi.cc:277
bool command_line_flag_has_been_set(const std::string &flag)
Definition: oomph_utilities.cc:501
void specify_command_line_flag(const std::string &command_line_flag, const std::string &doc)
Specify possible argument-free command line flag.
Definition: oomph_utilities.cc:451
void parse_and_assign(int argc, char *argv[], const bool &throw_on_unrecognised_args)
Definition: oomph_utilities.cc:760
void doc_specified_flags()
Document specified command line flags.
Definition: oomph_utilities.cc:610
#define OOMPH_EXCEPTION_LOCATION
Definition: oomph_definitions.h:61
#define OOMPH_CURRENT_FUNCTION
Definition: oomph_definitions.h:86

References oomph::CommandLineArgs::command_line_flag_has_been_set(), oomph::BlockSelector::do_not_want_block(), oomph::CommandLineArgs::doc_specified_flags(), oomph::BlockSelector::null_replacement_block_pt(), OOMPH_CURRENT_FUNCTION, OOMPH_EXCEPTION_LOCATION, oomph::CommandLineArgs::parse_and_assign(), oomph::BlockSelector::select_block(), oomph::BlockSelector::set_column_index(), oomph::BlockSelector::set_row_index(), oomph::CommandLineArgs::setup(), oomph::CommandLineArgs::specify_command_line_flag(), and oomph::BlockSelector::want_block().