21#include "libmesh/libmesh_config.h"
24#if defined(LIBMESH_USE_COMPLEX_NUMBERS)
27#include "libmesh/frequency_system.h"
29#include "libmesh/equation_systems.h"
30#include "libmesh/int_range.h"
31#include "libmesh/libmesh_logging.h"
32#include "libmesh/linear_solver.h"
33#include "libmesh/numeric_vector.h"
39 const std::string & name_in,
40 const unsigned int number_in) :
42 solve_system (nullptr),
43 _finished_set_frequencies (false),
44 _keep_solution_duplicates (true),
45 _finished_init (false),
46 _finished_assemble (false)
91 unsigned int n_freq = es.
parameters.
get<
unsigned int>(
"n_frequencies");
92 for (
unsigned int n=0; n < n_freq; n++)
107 LOG_SCOPE(
"init()",
"FrequencySystem");
117 libmesh_not_implemented_msg(
"ERROR: Setting the n_frequencies parameter on the system is not supported");
125 const unsigned int n_freq =
128 libmesh_assert_greater (n_freq, 0);
135 libmesh_error_msg(
"ERROR: Need to set frequencies before calling init().");
150 LOG_SCOPE(
"assemble()",
"FrequencySystem");
167 const unsigned int n_freq,
168 const bool allocate_solution_duplicates)
181 for (
unsigned int n=0; n<n_freq; n++)
185 base_freq +
Number(n) * freq_step;
202 const unsigned int n_freq,
203 const bool allocate_solution_duplicates)
209 libmesh_assert_greater (n_freq, 0);
219 for (
unsigned int n=0; n<n_freq; n++)
223 min_freq +
static_cast<Number>(n)*(max_freq-min_freq)/
static_cast<Number>(n_freq-1);
239 const bool allocate_solution_duplicates)
241 libmesh_deprecated();
252 es.
parameters.
set<
unsigned int>(
"n_frequencies") = frequencies.size();
273 const bool allocate_solution_duplicates)
275 libmesh_deprecated();
286 es.
parameters.
set<
unsigned int>(
"n_frequencies") = frequencies.size();
327 const unsigned int n_stop)
349 for (
unsigned int n=n_start; n<= n_stop; n++)
355 LOG_CALL(
"user_pre_solve()",
"FrequencySystem", this->
solve_system(es, this->
name()));
358 const std::pair<unsigned int, Real> rval =
378 const std::string & name))
402 libmesh_assert_less (n, 9999);
403 std::string nstr = std::to_string(n);
404 constexpr std::size_t digits = 4;
405 const int zeros = digits - std::min(digits,nstr.size());
406 nstr.insert(0, zeros,
'0');
407 return "frequency "+nstr;
414 libmesh_assert_less (n, 9999);
415 std::string nstr = std::to_string(n);
416 constexpr std::size_t digits = 4;
417 const int zeros = digits - std::min(digits,nstr.size());
418 nstr.insert(0, zeros,
'0');
419 return "solution "+nstr;
This is the EquationSystems class.
Parameters parameters
Data structure holding arbitrary parameters.
NumericVector< Number > * rhs
The system matrix.
bool _finished_init
true when we have finished the init() phase.
bool _keep_solution_duplicates
when the solution for each frequency should be stored in an additional vector, then this bool is true...
bool _finished_assemble
true when we have finished the assemble() phase.
std::string form_freq_param_name(const unsigned int n) const
virtual void clear() override
Clear all the data structures associated with the system, but leave the frequencies untouched.
virtual void solve() override
Solves the system for all frequencies.
unsigned int n_frequencies() const
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used.
void set_current_frequency(unsigned int n)
Sets the current frequency to the n-th entry in the vector _frequencies.
std::vector< std::pair< unsigned int, Real > > vec_rval
The number of iterations and the final residual when the Ax=b is solved for multiple frequencies.
bool _finished_set_frequencies
true when we have frequencies to solve for.
void set_frequencies_by_range(const Number min_freq, const Number max_freq, const unsigned int n_freq, const bool allocate_solution_duplicates=true)
Set the frequency range for which the system should be solved.
virtual void assemble() override
Assemble the linear system.
void clear_all()
The full clear method also clears the frequencies (stored as parameters of the EquationSystems object...
FrequencySystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
std::string form_solu_vec_name(const unsigned int n) const
void set_frequencies_by_steps(const Number base_freq, const Number freq_step=0., const unsigned int n_freq=1, const bool allocate_solution_duplicates=true)
Set the frequency range for which the system should be solved.
void(* solve_system)(EquationSystems &es, const std::string &name)
Function that computes frequency-dependent data of the system.
virtual ~FrequencySystem()
void set_frequencies(const std::vector< Real > &frequencies, const bool allocate_solution_duplicates=true)
Set the frequency range by simply copying the values from frequencies.
void attach_solve_function(void fptr(EquationSystems &es, const std::string &name))
Register a required user function to use in assembling/solving the system.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
SparseMatrix< Number > * matrix
The system matrix.
std::unique_ptr< LinearSolver< Number > > linear_solver
This class handles all the details of interfacing with various linear algebra packages like PETSc or ...
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
virtual void init_data() override
Initializes new data members of the system.
unsigned int _n_linear_iterations
The number of linear iterations required to solve the linear system Ax=b.
Real _final_linear_residual
The final residual for the linear system Ax=b.
virtual void assemble() override
Prepares matrix and _dof_map for matrix assembly.
virtual void clear() override
Clear all the data structures associated with the system.
void remove(std::string_view)
Removes the specified parameter from the list, if it exists.
bool have_parameter(std::string_view) const
T & set(const std::string &)
const T & get(std::string_view) const
const std::string & name() const
NumericVector< Number > & add_vector(std::string_view vec_name, const bool projections=true, const ParallelType type=PARALLEL)
Adds the additional vector vec_name to this system.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
const EquationSystems & get_equation_systems() const
const NumericVector< Number > & get_vector(std::string_view vec_name) const
The libMesh namespace provides an interface to certain functionality in the library.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)