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;
425 #endif // if defined(LIBMESH_USE_COMPLEX_NUMBERS) std::string name(const ElemQuality q)
This function returns a string containing some name for q.
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 void assemble() override
Prepares matrix and _dof_map for matrix assembly.
virtual void solve() override
Solves the system for all frequencies.
This is the EquationSystems class.
void clear_all()
The full clear method also clears the frequencies (stored as parameters of the EquationSystems object...
void(* solve_system)(EquationSystems &es, const std::string &name)
Function that computes frequency-dependent data of the system.
bool have_parameter(std::string_view) const
boost::multiprecision::float128 real(const boost::multiprecision::float128 in)
virtual void assemble() override
Assemble the linear system.
unsigned int _n_linear_iterations
The number of linear iterations required to solve the linear system Ax=b.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and linear solvers ...
const EquationSystems & get_equation_systems() const
bool _keep_solution_duplicates
when the solution for each frequency should be stored in an additional vector, then this bool is true...
NumericVector< Number > * rhs
The system matrix.
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.
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.
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.
The libMesh namespace provides an interface to certain functionality in the library.
std::string form_freq_param_name(const unsigned int n) const
FrequencySystem(EquationSystems &es, const std::string &name_in, const unsigned int number_in)
Constructor.
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
Number fptr(const Point &p, const Parameters &, const std::string &libmesh_dbg_var(sys_name), const std::string &unknown_name)
bool _finished_assemble
true when we have finished the assemble() phase.
const T & get(std::string_view) const
virtual ~FrequencySystem()
virtual void init_data() override
Initializes new data members of the system.
virtual void init_data() override
Initializes the member data fields associated with the system, so that, e.g., assemble() may be used...
void remove(std::string_view)
Removes the specified parameter from the list, if it exists.
bool _finished_init
true when we have finished the init() phase.
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
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.
Real _final_linear_residual
The final residual for the linear system Ax=b.
virtual void clear() override
Clear all the data structures associated with the system, but leave the frequencies untouched...
unsigned int n_frequencies() const
T & set(const std::string &)
SparseMatrix< Number > * matrix
The system matrix.
bool _finished_set_frequencies
true when we have frequencies to solve for.
Parameters parameters
Data structure holding arbitrary parameters.
void set_current_frequency(unsigned int n)
Sets the current frequency to the n-th entry in the vector _frequencies.
virtual void clear() override
Clear all the data structures associated with the system.
const std::string & name() const
std::unique_ptr< LinearSolver< Number > > linear_solver
This class handles all the details of interfacing with various linear algebra packages like PETSc or ...
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
std::string form_solu_vec_name(const unsigned int n) const
const NumericVector< Number > & get_vector(std::string_view vec_name) const
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...