4#ifndef lethe_time_harmonic_maxwell_h
5#define lethe_time_harmonic_maxwell_h
20#include <deal.II/base/convergence_table.h>
21#include <deal.II/base/numbers.h>
22#include <deal.II/base/tensor.h>
23#include <deal.II/base/timer.h>
25#include <deal.II/distributed/tria_base.h>
27#include <deal.II/fe/fe_dgq.h>
28#include <deal.II/fe/fe_nedelec.h>
29#include <deal.II/fe/fe_values.h>
31#include <deal.II/grid/grid_tools.h>
33#include <deal.II/lac/solver_control.h>
34#include <deal.II/lac/sparsity_pattern.h>
35#include <deal.II/lac/trilinos_precondition.h>
36#include <deal.II/lac/trilinos_sparse_matrix.h>
37#include <deal.II/lac/trilinos_vector.h>
39#include <deal.II/numerics/data_out.h>
40#include <deal.II/numerics/error_estimator.h>
41#include <deal.II/numerics/solution_transfer.h>
66 TimeHarmonicMaxwellBoundaryConditionMissing,
68 <<
"The boundary id: " << arg1
69 <<
" is defined in the triangulation, but not as a boundary condition for the TimeHarmonicMaxwell physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.");
72 TimeHarmonicMaxwellDimensionNotSupported,
74 <<
"The time-harmonic Maxwell solver does not support dimension: " << arg1
75 <<
". Currently, only 3D problems are supported as the 2D version of curls and cross products have completely different definitions than their 3D counterparts.");
99 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
101 std::shared_ptr<SimulationControl> p_simulation_control);
114 virtual std::vector<OutputStruct<dim, VectorType>>
196 virtual std::vector<OutputStructTableHandler>
210 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
212 dealii::Vector<float> &estimated_error_per_cell)
override;
226 compute_kelly(dealii::Vector<float> &estimated_error_per_cell,
227 const ComponentMask &component_mask);
296 virtual const DoFHandler<dim> &
314 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
330 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
345 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
400 AffineConstraints<double> &
415 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
429 .rescale_residual_by_volume ?
458 std::vector<types::boundary_id> boundary_ids_in_triangulation =
460 for (
auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
464 .boundary_conditions_time_harmonic_electromagnetics.type.find(
465 boundary_id_in_tria) !=
467 .boundary_conditions_time_harmonic_electromagnetics.type.end(),
468 TimeHarmonicMaxwellBoundaryConditionMissing(boundary_id_in_tria));
521 const typename DoFHandler<dim>::active_cell_iterator &cell,
543 const typename DoFHandler<dim>::active_cell_iterator &cell,
582 const typename DoFHandler<dim>::active_cell_iterator &cell,
615 const std::string &str,
616 const unsigned int n_rank,
617 const std::vector<double> &memory_object)
620 for (
unsigned int i = 0; i < n_rank; ++i)
622 pcout <<
" Rank " << i <<
" : " << memory_object[i] << std::endl;
633 const TrilinosWrappers::SparsityPattern &sparsity_pattern);
750 std::vector<std::shared_ptr<TimeHarmonicMaxwellAssemblerBase<dim>>>
756 std::vector<std::shared_ptr<TimeHarmonicMaxwellFaceAssemblerBase<dim>>>
954 std::shared_ptr<SolutionTransfer<dim, GlobalVectorType>>
AuxiliaryPhysics(const Parameters::NonLinearSolver non_linear_solver_parameters)
AuxiliaryPhysics - Base constructor for Auxiliary physics. This constructor builds an auxiliary physi...
Class responsible for storing the local system of an ultraweak Discontinuous Petrov-Galerkin (DPG) di...
Class that manages the physical properties model which are required to calculate the various physical...
Class that stores the information required by the assembly of the Discontinuous Petrov-Galerkin (DPG)...
MultiphysicsInterface< dim > * multiphysics
std::shared_ptr< TrilinosWrappers::PreconditionIdentity > preconditioner
virtual void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
void compute_electromagnetic_scaling(const PhysicalPropertiesManager &physical_properties_manager)
Compute the electromagnetic scaling factor used to non-dimensionalize the time-harmonic Maxwell syste...
std::shared_ptr< DoFHandler< dim > > dof_handler_test
TimerOutput computing_timer
IndexSet locally_relevant_dofs_trial_interior
void copy_local_matrix_to_global_matrix(const DPGCopyData ©_data)
Distribute the condensed skeleton system of a cell in the global system matrix and right-hand side.
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
void output_per_iteration_timer() override
Output the per iteration wallclock times.
virtual void pre_mesh_adaptation() override
pre_mesh_adaption Prepares the auxiliary physics variables for a mesh refinement/coarsening
virtual void compute_dpg_error(dealii::Vector< float > &estimated_error_per_cell)
Compute the DPG error estimator based on the energy norm residual used to refine mesh of the TimeHarm...
void scale_solution_components(const DoFHandler< dim > &dof_handler, GlobalVectorType &solution)
Scale the solution components by the electromagnetic scaling factor to recover the physical values of...
virtual void post_mesh_adaptation() override
post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
GlobalVectorType & get_newton_update() override
Getter method to access the private attribute newton_update for the currently solved physics.
void setup_preconditioner() override
Sets up preconditioner of the system matrix.
GlobalVectorType & get_present_solution() override
Getter method to access the private attribute present_solution for the currently solved physics....
void copy_local_interior_solution_to_global(const DPGCopyData ©_data)
WorkStream copier of the interior reconstruction. It adds the interior solution of a cell,...
void assemble_local_dpg_system(const typename DoFHandler< dim >::active_cell_iterator &cell, TimeHarmonicMaxwellScratchData< dim > &scratch_data, DPGCopyData ©_data)
Assemble the uncondensed local DPG system ( , , and ) of a cell with the cell and face assemblers,...
GlobalVectorType system_rhs
GlobalVectorType & get_evaluation_point() override
Getter method to access the private attribute evaluation_point for the currently solved physics.
bool should_solve_auxiliary_physics() override
Manage if the auxiliary physics should be solved at the current iteration. By default,...
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
IndexSet locally_relevant_dofs_trial_skeleton
void assemble_system_matrix() override
Assemble the matrix associated with the solver.
const SimulationParameters< dim > & simulation_parameters
GlobalVectorType locally_owned_solution_interior
GlobalVectorType & get_local_evaluation_point() override
Getter method to access the private attribute local_evaluation_point for the physic currently solved.
virtual void setup_dofs() override
Sets up the DofHandler and the degree of freedom associated with the physics.
virtual void update_boundary_conditions() override
Updates non zero constraints if the boundary is time-dependent.
IndexSet locally_owned_dofs_trial_skeleton
virtual void read_checkpoint() override
Set solution vector of Auxiliary Physics using checkpoint.
GlobalVectorType & get_system_rhs() override
Getter method to access the private attribute system_rhs for the currently solved physics.
void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell) override
Compute the error estimator selected in the parameters for adaptive mesh refinement.
virtual std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for a...
bool needs_dpg_error_estimator
virtual void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
void print_THM_setup_memory(const TrilinosWrappers::SparsityPattern &sparsity_pattern)
Print memory usage diagnostics after the THM setup.
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
std::shared_ptr< FiniteElement< dim > > fe_trial_skeleton
virtual std::vector< OutputStruct< dim, VectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
double squared_residual_L2_norm
virtual void percolate_time_vectors() override
Carry out the operations required to rearrange the values of the previous solution at the end of a ti...
const FEValuesExtractors::Vector extractor_E_real
GlobalVectorType & get_present_solution_skeleton()
Getter method to access the private attribute present_solution_skeleton for the currently solved phys...
const FEValuesExtractors::Vector extractor_E_imag
std::vector< double > waveguide_ports_electric_amplitudes
std::shared_ptr< SimulationControl > simulation_control
std::shared_ptr< GlobalVectorType > present_solution_skeleton
IndexSet locally_owned_dofs_trial_interior
void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
AffineConstraints< double > nonzero_constraints
double electromagnetic_scaling
GlobalVectorType initial_guess_iterative_solver
void update_material_properties_dependencies()
Updates the containers that store the properties from which the material properties of the time-harmo...
void define_constraints()
Define the constraints for the TimeHarmonicMaxwell solver. This is equivalent to the define_non_zero_...
void print_memory_consumption(const dealii::ConditionalOStream &pcout, const std::string &str, const unsigned int n_rank, const std::vector< double > &memory_object)
This helper function helps to compute the memory consumption of different objects on each rank and pr...
virtual void write_checkpoint() override
Prepares auxiliary physics to write checkpoint.
std::shared_ptr< DoFHandler< dim > > dof_handler_trial_interior
void reconstruct_local_interior_solution(const typename DoFHandler< dim >::active_cell_iterator &cell, TimeHarmonicMaxwellScratchData< dim > &scratch_data, DPGCopyData ©_data)
WorkStream worker of the interior reconstruction. It assembles the local DPG system of a cell with as...
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > temperature_last_solved_solution_transfer
TimeHarmonicMaxwell(MultiphysicsInterface< dim > *multiphysics_interface, const SimulationParameters< dim > &p_simulation_parameters, const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &p_triangulation, std::shared_ptr< SimulationControl > p_simulation_control)
Constructor.
virtual ~TimeHarmonicMaxwell()=default
TimeHarmonicMaxwell - Base destructor. At the present moment this is an interface with nothing.
virtual void set_initial_conditions() override
Sets up the initial conditions associated with the physics. Generally, most physics only support impo...
void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, TimeHarmonicMaxwellScratchData< dim > &scratch_data, DPGCopyData ©_data)
Assemble the local DPG system of a cell using the function assemble_local_dpg_system and condense it ...
std::shared_ptr< Quadrature< dim > > cell_quadrature
std::shared_ptr< FiniteElement< dim > > fe_test
void compute_kelly(dealii::Vector< float > &estimated_error_per_cell, const ComponentMask &component_mask)
Compute the Kelly error estimator on the electromagnetic variable for mesh refinement....
const FEValuesExtractors::Vector extractor_H_real
ConvergenceTable error_table
Vector< float > local_estimated_error_per_cell
const FEValuesExtractors::Vector extractor_H_imag
void solve_linear_system() override
Solve the linear system using the CG solver.
std::shared_ptr< FiniteElement< dim > > fe_trial_interior
std::vector< double > calculate_L2_error()
Calculates the L2 error of the solution. It returns a vector of doubles containing the L2 errors of t...
std::shared_ptr< DoFHandler< dim > > dof_handler_trial_skeleton
virtual void modify_solution() override
Carry out modifications on the auxiliary physics solution. To be defined for some physics only (eg....
TrilinosWrappers::SparseMatrix system_matrix
virtual const DoFHandler< dim > & get_dof_handler() override
Getter method to access the private attribute dof_handler for the physics currently solved....
void setup_assemblers()
Set up the cell and face assemblers of the DPG system according to the simulation parameters.
std::shared_ptr< GlobalVectorType > present_solution
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
std::vector< std::shared_ptr< TimeHarmonicMaxwellFaceAssemblerBase< dim > > > face_assemblers
std::vector< std::shared_ptr< TimeHarmonicMaxwellAssemblerBase< dim > > > assemblers
AffineConstraints< double > & get_nonzero_constraints() override
Getter method to access the private attribute nonzero_constraints for the currently solved physics.
void reconstruct_interior_solution()
Reconstruct the interior solution from the skeleton solution after solving the linear system on the s...
std::shared_ptr< Mapping< dim > > mapping
GlobalVectorType temperature_last_solved_solution
void announce_string(const ConditionalOStream &pcout, const std::string &expression, const char delimiter='-')
Prints a string and then adds a line above and below made with dashes containing as many dashes as th...
@ electromagnetics
Time-harmonic electromagnetics (Electric field, Magnetic field).
Simulation control classes for managing time-stepping and iteration control in Lethe.
GlobalVectorType VectorType
DeclException1(TimeHarmonicMaxwellBoundaryConditionMissing, types::boundary_id,<< "The boundary id: "<< arg1<< " is defined in the triangulation, but not as a boundary condition for the TimeHarmonicMaxwell physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.")
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType