65{
66
68
69#ifndef LIBMESH_USE_COMPLEX_NUMBERS
70 libmesh_example_requires(false, "--enable-complex");
71#else
72
73#if !defined(LIBMESH_HAVE_XDR)
74
75 libmesh_example_requires(false, "--enable-xdr");
76#elif defined(LIBMESH_DEFAULT_SINGLE_PRECISION)
77
78 libmesh_example_requires(false, "--disable-singleprecision");
79#elif defined(LIBMESH_DEFAULT_TRIPLE_PRECISION)
80
81
82 libmesh_example_requires(false, "double precision");
83#endif
84
86
87#ifdef LIBMESH_HAVE_PETSC
88
89
90 GetPot input(argc, argv);
91
92
93#if PETSC_VERSION_LESS_THAN(3,9,0)
94 if (input.search("-pc_factor_mat_solver_type"))
95 {
96 libMesh::out <<
"LibMesh was configured with PETSc < 3.9, but command-line options "
97 << "use syntax understood by later versions only. Skipping this example."
98 << std::endl;
99 return 77;
100 }
101 input.search("-pc_factor_mat_solver_package");
102#else
103 if (input.search("-pc_factor_mat_solver_package"))
104 {
105 libMesh::out <<
"LibMesh was configured with PETSc >= 3.9, but command-line options "
106 << "use deprecated syntax. Skipping now."
107 << std::endl;
108 return 77;
109 }
110 input.search("-pc_factor_mat_solver_type");
111#endif
112
113
114 std::string solver;
115 solver = input.next("invalid_solver");
116 if (solver == "mumps")
117 {
118#ifndef LIBMESH_PETSC_HAVE_MUMPS
119 libmesh_example_requires(false, "PETSc compiled with MUMPS support");
120#endif
121 }
122 else if (solver == "superlu")
123 {
124#ifndef LIBMESH_PETSC_HAVE_SUPERLU_DIST
125 libmesh_example_requires(false, "PETSc compiled with SuperLU support");
126#endif
127 }
128 else
129 {
130 libMesh::err <<
"Error: Solver " << solver <<
" is unknown."
131 << std::endl;
132 return 1;
133 }
134
135#endif
136
137
138 libmesh_example_requires(2 <= LIBMESH_DIM, "2D support");
139
140
141 std::string parameters_filename = "reduced_basis_ex7.in";
142 GetPot infile(parameters_filename);
143
144 const unsigned int dim = 2;
145
146 bool store_basis_functions = infile("store_basis_functions", true);
147
148
149 const int online_mode =
151
152
155
156
158
159
160
163
164
165 equation_systems.
init ();
166
167
168 equation_systems.print_info();
170
171
172
173
175
176
177
179
180 if (!online_mode)
181 {
182
184
185
187
188
189
190
192
193
194
195
196 libmesh_try
197 {
199 }
201 {
203 << "********************************************************************************\n"
204 << "Training reduced basis failed, this example requires a direct solver.\n"
205 << "Try running with -ksp_type preonly -pc_type lu instead.\n"
206 << "********************************************************************************"
207 << std::endl;
208 return 77;
209 }
210
211
212#if defined(LIBMESH_HAVE_CAPNPROTO)
214 rb_eval_writer.write_to_file("rb_eval.bin");
215#else
217#endif
218
219
220 if (store_basis_functions)
221 {
222
224 }
225
226
227
229 }
230 else
231 {
232
233#if defined(LIBMESH_HAVE_CAPNPROTO)
235 rb_eval_reader.read_from_file("rb_eval.bin", true);
236#else
237 rb_eval.legacy_read_offline_data_from_files();
238#endif
239
240
241 Real online_frequency = infile(
"online_frequency", 0.);
243 online_mu.
set_value(
"frequency", online_frequency);
244 rb_eval.set_parameters(online_mu);
245 rb_eval.print_parameters();
246
247
248 rb_eval.rb_solve(rb_eval.get_n_basis_functions());
249
250 if (store_basis_functions)
251 {
252
253 rb_eval.read_in_basis_functions(rb_con);
254
255
257
258
260 }
261
262
263 std::ofstream reflection_coeffs_out("reflection_coefficients.dat");
264
265 Real n_frequencies = infile(
"n_frequencies", 0.);
266 Real delta_f = (rb_eval.get_parameter_max(
"frequency") - rb_eval.get_parameter_min(
"frequency")) / (n_frequencies-1);
267 for (unsigned int freq_i=0; freq_i<n_frequencies; freq_i++)
268 {
269 Real frequency = rb_eval.get_parameter_min(
"frequency") + freq_i * delta_f;
270 online_mu.
set_value(
"frequency", frequency);
271 rb_eval.set_parameters(online_mu);
272 rb_eval.rb_solve(rb_eval.get_n_basis_functions());
273
274 Number complex_one(1., 0.);
275 reflection_coeffs_out << frequency << " " << std::abs(rb_eval.RB_outputs[0] - complex_one) << std::endl;
276 }
277 reflection_coeffs_out.close();
278
279 }
280
281#endif
282
283 return 0;
284}
This is the EquationSystems class.
The ExodusII_IO class implements reading meshes in the ExodusII file format from Sandia National Labs...
virtual void write_equation_systems(const std::string &fname, const EquationSystems &es, const std::set< std::string > *system_names=nullptr) override
Writes out the solution for no specific time or timestep.
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
A class to represent the internal "this should never happen" errors, to be thrown by "libmesh_error()...
virtual void read(const std::string &name, void *mesh_data=nullptr, bool skip_renumber_nodes_and_elements=false, bool skip_find_neighbors=false, bool skip_detect_interior_parents=false)=0
Interfaces for reading/writing a mesh to/from a file.
void print_info(std::ostream &os=libMesh::out, const unsigned int verbosity=0, const bool global=true) const
Prints relevant information about the mesh.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
const Parallel::Communicator & comm() const
void print_basis_function_orthogonality() const
Print out a matrix that shows the orthogonality of the RB basis functions.
void set_rb_evaluation(RBEvaluation &rb_eval_in)
Set the RBEvaluation object.
virtual void print_info() const
Print out info that describes the current setup of this RBConstruction.
RBEvaluation & get_rb_evaluation()
Get a reference to the RBEvaluation object.
virtual void initialize_rb_construction(bool skip_matrix_assembly=false, bool skip_vector_assembly=false)
Allocate all the data structures necessary for the construction stage of the RB method.
virtual Real train_reduced_basis(const bool resize_rb_eval_data=true)
Train the reduced basis.
virtual void load_rb_solution()
Load the RB solution from the most recent solve with rb_eval into this system's solution vector.
virtual void process_parameters_file(const std::string ¶meters_filename)
Read in from the file specified by parameters_filename and set the this system's member variables acc...
This class de-serializes an RBEvaluation object using the Cap'n Proto library.
This class serializes an RBEvaluation object using the Cap'n Proto library.
virtual void legacy_write_offline_data_to_files(const std::string &directory_name="offline_data", const bool write_binary_data=true)
Write out all the data to text files in order to segregate the Offline stage from the Online stage.
virtual void write_out_basis_functions(System &sys, const std::string &directory_name="offline_data", const bool write_binary_basis_functions=true)
Write out all the basis functions to file.
This class is part of the rbOOmit framework.
void set_value(const std::string ¶m_name, Real value)
Set the value of the specified parameter.
void init()
Initializes degrees of freedom on the current mesh.
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
SolverPackage default_solver_package()
T command_line_next(std::string name, T default_value)
Use GetPot's search()/next() functions to get following arguments from the command line.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real