Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
time_harmonic_maxwell.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2025-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#ifndef lethe_time_harmonic_maxwell_h
5#define lethe_time_harmonic_maxwell_h
6
8#include <core/parameters.h>
11#include <core/vector.h>
12
14#include <solvers/copy_data.h>
19
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>
24
25#include <deal.II/distributed/tria_base.h>
26
27#include <deal.II/fe/fe_dgq.h>
28#include <deal.II/fe/fe_nedelec.h>
29#include <deal.II/fe/fe_values.h>
30
31#include <deal.II/grid/grid_tools.h>
32
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>
38
39#include <deal.II/numerics/data_out.h>
40#include <deal.II/numerics/error_estimator.h>
41#include <deal.II/numerics/solution_transfer.h>
42
43#include <algorithm>
44#include <complex>
45#include <memory>
46#include <ranges>
47
48
49/**
50 * @class TimeHarmonicMaxwell Auxiliary physics solver for the time harmonic
51 * form of the Maxwell equations.
52 * This class implements an auxiliary physics solver for the ultraweak
53 * formulation of the time-harmonic Maxwell equations using the Discontinuous
54 * Petrov-Galerkin (DPG) method. The solver is designed to work in
55 * three-dimensional spaces and requires the 3 sets of Finite Element spaces
56 * that define the DPG method: the interior trial space that is discontinuous
57 * between elements, the skeleton trace space that lives on the faces of the
58 * mesh elements and connects the interior solutions of adjacent elements, and
59 * the test space that is enriched compared to the trial space and is also
60 * discontinuous between elements.
61 **/
62
64
66 TimeHarmonicMaxwellBoundaryConditionMissing,
67 types::boundary_id,
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.");
70
72 TimeHarmonicMaxwellDimensionNotSupported,
73 int,
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.");
76
77template <int dim>
78class TimeHarmonicMaxwell : public AuxiliaryPhysics<dim, VectorType>
79{
80public:
81 /**
82 * @brief Constructor
83 *
84 * @param multiphysics_interface Interface to the auxiliary physics that will be
85 * solved on top of a computational fluid dynamic simulation.
86 * @param p_simulation_parameters Contains the simulation parameter file
87 * information.
88 * @param p_triangulation Contains the mesh information. In a
89 * parallel::DistributedTriangulationBase<dim> not every detail may be known
90 * on each processor. The mesh is distributed between the processors.
91 * @param p_simulation_control Object responsible for the control of
92 * steady-state and transient simulations. Contains all the information
93 * related to time stepping and the stopping criteria.
94 *
95 */
97 MultiphysicsInterface<dim> *multiphysics_interface,
98 const SimulationParameters<dim> &p_simulation_parameters,
99 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
100 &p_triangulation,
101 std::shared_ptr<SimulationControl> p_simulation_control);
102
103 /**
104 * @brief TimeHarmonicMaxwell - Base destructor. At the present
105 * moment this is an interface with nothing.
106 */
107 virtual ~TimeHarmonicMaxwell() = default;
108
109 /**
110 * @brief Gather and return vector of output structs that are particular to some applications.
111 *
112 * @return Vector of OutputStructs that will be used to write the output results as VTU files.
113 */
114 virtual std::vector<OutputStruct<dim, VectorType>>
115 gather_output_hook() override;
116
117 /**
118 * @brief Calculates the L2 error of the solution. It returns a vector of doubles containing the L2 errors of the real and imaginary parts of the electric and magnetic fields in the order [E_real, E_imag, H_real, H_imag].
119 */
120 std::vector<double>
122
123 /**
124 * @brief Carry out the operations required to finish a simulation correctly.
125 */
126 virtual void
127 finish_simulation() override;
128
129 /**
130 * @brief Carry out the operations required to rearrange the values of the
131 * previous solution at the end of a time step
132 */
133 virtual void
134 percolate_time_vectors() override;
135
136 /**
137 * @brief Carry out modifications on the auxiliary physics solution.
138 * To be defined for some physics only (eg. free surface, see cls.h).
139 */
140 virtual void
141 modify_solution() override;
142
143 /**
144 * @brief Updates non zero constraints if the boundary is time-dependent
145 */
146 virtual void
148
149 /**
150 * @brief Postprocess the auxiliary physics results. Post-processing this case implies
151 * the calculation of all derived quantities using the solution vector of the
152 * physics. It does not concern the output of the solution using the
153 * DataOutObject, which is accomplished through the attach_solution_to_output
154 * function
155 */
156 virtual void
157 postprocess(bool first_iteration) override;
158
159 /**
160 * @brief Output the per iteration wallclock times.
161 */
162 void
164
165 /**
166 * @brief pre_mesh_adaption Prepares the auxiliary physics variables for a
167 * mesh refinement/coarsening
168 */
169 virtual void
170 pre_mesh_adaptation() override;
171
172 /**
173 * @brief post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
174 */
175 virtual void
176 post_mesh_adaptation() override;
177
178 /**
179 * @brief Prepares auxiliary physics to write checkpoint
180 */
181 virtual void
182 write_checkpoint() override;
183
184 /**
185 * @brief Set solution vector of Auxiliary Physics using checkpoint
186 */
187 virtual void
188 read_checkpoint() override;
189
190 /**
191 * @brief Returns a vector of references to TableHandler objects that needs to
192 * be serialized/deserialized for a given TimeHarmonicMaxwell solver.
193 *
194 * @return Structure containing the TableHandler objects and their corresponding file names.
195 */
196 virtual std::vector<OutputStructTableHandler>
197 gather_tables() override;
198
199 /**
200 * @brief Compute the error estimator selected in the parameters for adaptive mesh refinement.
201 *
202 * @param[in] ivar The current element of the map
203 * simulation_parameters.mesh_adaptation.variables
204 *
205 * @param[in,out] estimated_error_per_cell The deal.II vector of
206 * estimated_error_per_cell
207 */
208 void
210 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
211 &ivar,
212 dealii::Vector<float> &estimated_error_per_cell) override;
213
214 /**
215 * @brief Compute the Kelly error estimator on the electromagnetic variable for mesh refinement.
216 * See :
217 * https://www.dealii.org/current/doxygen/deal.II/classKellyErrorEstimator.html
218 * for more information on the Kelly error estimator.
219 *
220 * @param[in,out] estimated_error_per_cell The deal.II vector of
221 * estimated_error_per_cell
222 * @param[in] component_mask The component mask corresponding to the
223 * electromagnetic variable
224 */
225 void
226 compute_kelly(dealii::Vector<float> &estimated_error_per_cell,
227 const ComponentMask &component_mask);
228
229 /**
230 * @brief Compute the DPG error estimator based on the energy norm residual used to refine mesh of the TimeHarmonicMaxwell physics.
231 *
232 * @param[in] ivar The current element of the map
233 * simulation_parameters.mesh_adaptation.variables
234 *
235 * @param[in,out] estimated_error_per_cell The deal.II vector of
236 * estimated_error_per_cell
237 */
238 virtual void
239 compute_dpg_error(dealii::Vector<float> &estimated_error_per_cell);
240
241 /**
242 * @brief Sets up the DofHandler and the degree of freedom associated with the physics.
243 */
244 virtual void
245 setup_dofs() override;
246
247 /**
248 * @brief Sets up the initial conditions associated with the physics. Generally, most physics
249 * only support imposing nodal values, but some physics additionally support
250 * the use of L2 projection or steady-state solutions.
251 */
252 virtual void
253 set_initial_conditions() override;
254
255 /**
256 * @brief Sets up preconditioner of the system matrix.
257 */
258 void
259 setup_preconditioner() override;
260
261 /**
262 * @brief Define the constraints for the TimeHarmonicMaxwell solver. This is equivalent to the define_non_zero_constraints method in other physics solvers, but here there is no need to separate zero and non-zero constraints.
263 */
264 void
266
267 /**
268 * @brief Solve the linear system using the CG solver.
269 *
270 * The CG solver is initialized with the solution from the previous linear
271 * system solve, stored in the `initial_guess_iterative_solver` vector. The
272 * initial guess is set to zero for the first solve of a simulation, after
273 * restarting from a checkpoint, and after mesh adaptation.
274 *
275 * The `present_solution_skeleton` vector cannot be used directly as an
276 * initial guess because it is rescaled according to the user-defined
277 * parameters. Consequently, its rescaled values generally provide a poor
278 * initial guess for the CG solver. Storing the initial guess separately
279 * avoids the need to perform an inverse scaling of
280 * `present_solution_skeleton`. It also ensures that the interior and skeleton
281 * solutions remain synchronized in the same scaling. The
282 * `initial_guess_iterative_solver` vector is updated after each linear system
283 * solve.
284 */
285 void
286 solve_linear_system() override;
287
288 /**
289 * @brief Getter method to access the private attribute dof_handler for the
290 * physics currently solved. NB : The dof_handler that is returned by this
291 * function is the one for the interior trial space of the DPG system. It is
292 * where the interior solution lives and therefore is the one we are
293 * interested in. The other two DoFHandlers of the class are used for
294 * computation to obtain the interior of the cell solution.
295 */
296 virtual const DoFHandler<dim> &
298 {
300 }
301
302 /**
303 * @brief Getter method to access the private attribute evaluation_point for
304 * the currently solved physics.
305 *
306 * @return The vector at which the evaluation is performed.
307 */
310 {
311 AssertThrow(
312 false,
313 ExcMessage(
314 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
315 }
316
317 /**
318 * @brief Getter method to access the private attribute
319 * local_evaluation_point for the physic currently solved.
320 *
321 * @return The local evaluation point. Ghosts cells are not considered in
322 * this evaluation.
323 */
326 {
327 AssertThrow(
328 false,
329 ExcMessage(
330 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
331 }
332
333 /**
334 * @brief Getter method to access the private attribute
335 * newton_update for the currently solved physics.
336 *
337 * @return The direction used to perform the newton iteration.
338 */
341 {
342 AssertThrow(
343 false,
344 ExcMessage(
345 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
346 }
347
348 /**
349 * @brief Getter method to access the private attribute
350 * present_solution for the currently solved physics. NB : present_solution is
351 * now passed to the multiphysics interface at the end of the setup_dofs
352 * method. In the case of TimeHarmonicMaxwell, it corresponds to the solution
353 * in the interior trial space.
354 *
355 * @return A vector containing all the values of the solution.
356 */
359 {
360 return *present_solution;
361 }
362
363
364 /**
365 * @brief Getter method to access the private attribute
366 * present_solution_skeleton for the currently solved physics. NB :
367 * present_solution_skeleton is only defined for the currently solved physics
368 * and is not passed to the multiphysics interface at the end of the
369 * setup_dofs method.
370 *
371 * @return A vector containing all the values of the solution.
372 */
378
379
380 /**
381 * @brief Getter method to access the private attribute
382 * system_rhs for the currently solved physics.
383 *
384 * @return Reference to the right hand side vector.
385 */
387 get_system_rhs() override
388 {
389 return system_rhs;
390 }
391
392 /**
393 * @brief Getter method to access the private attribute
394 * nonzero_constraints for the currently solved physics.
395 *
396 * @return The nonzero constraints that arise from several sources such
397 * as boundary conditions and hanging nodes in the mesh. See the deal.II
398 * documentation on constraints on degrees of freedom for more information.
399 */
400 AffineConstraints<double> &
402 {
403 return nonzero_constraints;
404 }
405
406 /**
407 * @brief Output the L2 and Linfty norms of the correction vector.
408 */
409 void
411 {
412 AssertThrow(
413 false,
414 ExcMessage(
415 "The TimeHarmonicMaxwell solver is linear, this method should not be called."));
416 }
417
418 /**
419 * @brief Return the metric for residual rescaling. By default, should return 1.
420 * If the rescale_residual_by_volume is set to true, the method
421 * returns the global volume of the triangulation.
422 *
423 * @return Rescale metric.
424 */
425 double
427 {
429 .rescale_residual_by_volume ?
430 std::sqrt(
431 GridTools::volume(*this->triangulation, *this->mapping)) :
432 1.;
433 }
434
435 /**
436 * @brief Manage if the auxiliary physics should be solved at the current iteration. By default, auxiliary physics are solved at every iteration.
437 */
438 bool
440
441 /**
442 * @brief Updates the containers that store the properties from which the material properties of the time-harmonic Maxwell equations can depend on.
443 */
444 void
446
447private:
448 /**
449 * @brief Verify consistency of the input parameters for boundary
450 * conditions to ensure that for every boundary id within the
451 * triangulation, a boundary condition has been specified in the input file.
452 */
453 void
455 {
456 // Sanity check all of the boundary conditions of the triangulation to
457 // ensure that they have a type.
458 std::vector<types::boundary_id> boundary_ids_in_triangulation =
459 this->triangulation->get_boundary_ids();
460 for (auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
461 {
462 AssertThrow(
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));
469 }
470 }
471
472 /**
473 * @brief Assemble the matrix associated with the solver
474 */
475 void
476 assemble_system_matrix() override;
477
478 /**
479 * @brief Assemble the rhs associated with the solver
480 */
481 void
482 assemble_system_rhs() override;
483
484 /**
485 * @brief Reconstruct the interior solution from the skeleton solution after solving
486 * the linear system on the skeleton only. The local DPG system of each cell
487 * is assembled again to compute the interior solution
488 * \f$u_h = M_1^{-1} (G^{-1} B)^\dagger (l - \hat{B}\hat{u}_h)\f$ and the
489 * DPG residual
490 * \f$\Psi = G^{-1}(l - B u_h - \hat{B}\hat{u}_h)\f$ when the DPG error
491 * estimate on the cell and is not stored anywhere else.
492 */
493 void
495
496 /**
497 * @brief Set up the cell and face assemblers of the DPG system according to
498 * the simulation parameters.
499 */
500 void
502
503 /**
504 * @brief Assemble the uncondensed local DPG system (\f$G\f$, \f$B\f$,
505 * \f$\hat{B}\f$ and \f$l\f$) of a cell with the cell and face assemblers,
506 * and compute the condensation operators that are common to the assembly
507 * and to the interior reconstruction: the Cholesky factorizations of the
508 * Gram matrix \f$G\f$ and of \f$M_1 = B^\dagger G^{-1}B\f$, and the matrix
509 * \f$G^{-1}B\f$.
510 *
511 * @param[in] cell The cell of the interior trial space DoFHandler.
512 *
513 * @param[in,out] scratch_data Scratch data reinitialized on the cell and on
514 * each of its faces.
515 *
516 * @param[out] copy_data Copy data in which the local system and the
517 * condensation operators are stored.
518 */
519 void
521 const typename DoFHandler<dim>::active_cell_iterator &cell,
523 DPGCopyData &copy_data);
524
525 /**
526 * @brief Assemble the local DPG system of a cell using the function
527 * `assemble_local_dpg_system` and condense it on the
528 * skeleton unknowns. The condensed matrix is \f$M_3 - M_2^\dagger M_1^{-1}
529 * M_2\f$ and the condensed right-hand side is \f$(M_5 - M_2^\dagger
530 * M_1^{-1} M_4) l\f$. The operators \f$M_2 = B^\dagger G^{-1}\hat{B}\f$ and
531 * \f$M_4 l = B^\dagger G^{-1} l\f$ are computed here since only the
532 * condensed system needs them.
533 *
534 * @param[in] cell The cell of the interior trial space DoFHandler.
535 *
536 * @param[in,out] scratch_data (see assemble_local_dpg_system)
537 *
538 * @param[out] copy_data Copy data in which the condensed skeleton system is
539 * stored.
540 */
541 void
543 const typename DoFHandler<dim>::active_cell_iterator &cell,
545 DPGCopyData &copy_data);
546
547 /**
548 * @brief Distribute the condensed skeleton system of a cell in the global
549 * system matrix and right-hand side.
550 *
551 * @param[in] copy_data Copy data containing the condensed skeleton system.
552 */
553 void
555
556 /**
557 * @brief WorkStream worker of the interior reconstruction. It assembles the
558 * local DPG system of a cell with `assemble_local_dpg_system()` and uses the
559 * skeleton solution of the cell \f$\hat{u}_h\f$ to compute:
560 * - the interior solution of the cell
561 * \f$u_h = M_1^{-1} (G^{-1} B)^\dagger (l - \hat{B}\hat{u}_h)\f$, which is
562 * equal to \f$M_1^{-1} (M_4 l - M_2 \hat{u}_h)\f$ since \f$G\f$ is
563 * symmetric, but does not require the matrix \f$M_2\f$;
564 * - if the DPG error estimator is activated, the error representation
565 * function of the cell, which is the Riesz representation of the residual
566 * in the test space (it solves \f$G \Psi = R\f$),
567 * \f$\Psi = G^{-1}(l - B u_h - \hat{B}\hat{u}_h)\f$, and the squared
568 * energy norm of the residual
569 * \f$\|R\|^2_V = R^\dagger G^{-1} R = (l - B u_h -
570 * \hat{B}\hat{u}_h)^\dagger \Psi\f$.
571 *
572 * @param[in] cell The cell of the interior trial space DoFHandler.
573 *
574 * @param[in,out] scratch_data (see assemble_local_dpg_system)
575 *
576 * @param[out] copy_data Copy data in which the interior solution, the
577 * squared norm of the DPG residual and the dof indices of the cell are
578 * stored.
579 */
580 void
582 const typename DoFHandler<dim>::active_cell_iterator &cell,
584 DPGCopyData &copy_data);
585
586 /**
587 * @brief WorkStream copier of the interior reconstruction. It adds the
588 * interior solution of a cell, computed by
589 * `reconstruct_local_interior_solution`, in the global vector
590 * `locally_owned_solution_interior`. This is done with the dof indices of the
591 * cell stored in the copy data, which is
592 * equivalent to cell->distribute_local_to_global(local_vector,
593 * global_vector), since the copier does not have access to the cell. If the
594 * DPG error estimator is activated, it also stores the error indicator of
595 * the cell in `local_estimated_error_per_cell` and adds its squared norm to
596 * `squared_residual_L2_norm`.
597 *
598 * @param[in] copy_data Copy data containing the interior solution, the
599 * squared norm of the DPG residual and the dof indices of the cell.
600 */
601 void
603
604 /**
605 * @brief This helper function helps to compute the memory consumption of different
606 * objects on each rank and print it out. It is useful to debug memory issues
607 * and understand the memory distribution across ranks.
608 *
609 * @param pcout The output stream to print the memory consumption information.
610 * @param str The name of the object for which the memory consumption is being printed. This is used for clarity in the output.
611 * @param n_rank The total number of ranks in the MPI communicator.
612 * @param memory_object The object containing the memory information to be printed.
613 */
614 void inline print_memory_consumption(const dealii::ConditionalOStream &pcout,
615 const std::string &str,
616 const unsigned int n_rank,
617 const std::vector<double> &memory_object)
618 {
619 announce_string(pcout, "Memory consumption of " + str + " (GB) :");
620 for (unsigned int i = 0; i < n_rank; ++i)
621 {
622 pcout << " Rank " << i << " : " << memory_object[i] << std::endl;
623 }
624 }
625
626 /**
627 * @brief Print memory usage diagnostics after the THM setup.
628 * @note The sparsity pattern is passed in because it is a local variable in
629 * setup_dofs and is not stored as a class member.
630 */
631 void
633 const TrilinosWrappers::SparsityPattern &sparsity_pattern);
634
635 /**
636 * @brief Compute the electromagnetic scaling factor used to non-dimensionalize the time-harmonic Maxwell system from the type of scaling required from the user. This is factor will be based on the electric field and obtained :
637 * - directly from parameters (if ElectromagneticScalingType::electric_field);
638 * - by converting the magnetic field also obtained from parameters (if
639 * ElectromagneticScalingType::magnetic_field);
640 * - or by taking the maximum of all the electric field intensity across all
641 * inlets in the problem, calculated from each inlet's input power (if
642 * ElectromagneticScalingType::power). The scaling factor will be stored in
643 * the class attribute electromagnetic_scaling.
644 *
645 * @param[in] physical_properties_manager The object that manages the physical
646 * properties of the problem and provides them at any given position of the
647 * domain.
648 */
649 void
651 const PhysicalPropertiesManager &physical_properties_manager);
652
653 /**
654 * @brief Scale the solution components by the electromagnetic scaling factor to recover the physical values of the solution after solving the non-dimensionalized system. This function is called at the end of the solve_linear_system method after reconstructing the interior solution from the skeleton solution.
655 * @param[in] dof_handler The degree of freedom handler for the mesh
656 * associated with the solution.
657 * @param[in,out] solution The solution vector to be scaled.
658 */
659 void
660 scale_solution_components(const DoFHandler<dim> &dof_handler,
661 GlobalVectorType &solution);
662
663 /**
664 * Pointer to the multiphysics interface that manages the coupling
665 * between the different physics solvers.
666 */
668
669 /**
670 * Store information related to the computing time such as CPU times or
671 * wall time.
672 */
673 TimerOutput computing_timer;
674
675 /**
676 * Contain the simulation parameter file information.
677 */
679
680
681 /**
682 * Collection of cells that cover the domain on which one wants to
683 * solve a partial differential equation.
684 */
685 std::shared_ptr<parallel::DistributedTriangulationBase<dim>> triangulation;
686
687 /**
688 * Responsible for the control of steady-state and transient
689 * simulations. Contains all the information related to time stepping and the
690 * stopping criteria. See simulation_control abstract class for more
691 * information.
692 */
693 std::shared_ptr<SimulationControl> simulation_control;
694
695 /**
696 * Given a triangulation and a description of a finite element, this
697 * class enumerates degrees of freedom on all vertices, edges, faces, and
698 * cells of the triangulation of the trial space for the interior dofs. NB:
699 * Since it is based on DG elements, there are no dofs on vertices, edges or
700 * faces.
701 */
702 std::shared_ptr<DoFHandler<dim>> dof_handler_trial_interior;
703
704 /**
705 * Given a triangulation and a description of a finite element, this
706 * class enumerates degrees of freedom on all vertices, edges, faces, and
707 * cells of the triangulation of the trial space for the skeleton dofs. NB:
708 * This DoFHandler is based on global FE spaces with frozen interior dofs, so
709 * the dofs effectively live only on faces, edges and vertices.
710 */
711 std::shared_ptr<DoFHandler<dim>> dof_handler_trial_skeleton;
712
713 /**
714 * Given a triangulation and a description of a finite element, this
715 * class enumerates degrees of freedom on all vertices, edges, faces, and
716 * cells of the triangulation of the test space dofs. NB: in DPG, the
717 * test space is not split into interior and skeleton dofs in opposition to
718 * the trial space and therefore manages vertices, edges, faces and cells
719 * dofs.
720 */
721 std::shared_ptr<DoFHandler<dim>> dof_handler_test;
722
723 /**
724 * The base class for finite elements. This class will manage everything
725 * related to the shape functions of the trial interior space.
726 */
727 std::shared_ptr<FiniteElement<dim>> fe_trial_interior;
728
729 /**
730 * The base class for finite elements. This class will manage everything
731 * related to the shape functions of the trial skeleton space.
732 */
733 std::shared_ptr<FiniteElement<dim>> fe_trial_skeleton;
734
735 /**
736 * The base class for finite elements. This class will manage everything
737 * related to the shape functions of the test space.
738 */
739 std::shared_ptr<FiniteElement<dim>> fe_test;
740
741 /**
742 * Preconditioner for the linear solver. At the present moment, this is an
743 * identity preconditioner.
744 */
745 std::shared_ptr<TrilinosWrappers::PreconditionIdentity> preconditioner;
746
747 /**
748 * Cell assemblers of the local DPG system.
749 */
750 std::vector<std::shared_ptr<TimeHarmonicMaxwellAssemblerBase<dim>>>
752
753 /**
754 * Face assemblers of the local DPG system.
755 */
756 std::vector<std::shared_ptr<TimeHarmonicMaxwellFaceAssemblerBase<dim>>>
758
759 /**
760 * Store some convergence data, such as residuals of the cg-method,
761 * or some evaluated <i>L<sup>2</sup></i>-errors of discrete solutions.
762 * Evaluate convergence rates or orders.
763 */
764 ConvergenceTable error_table;
765
766 /**
767 * Transformation which maps point in the reference cell to
768 * points in the actual grid cell.
769 */
770 std::shared_ptr<Mapping<dim>> mapping;
771
772 /**
773 * Approximate an integral over a cell by evaluating the integrand at specific
774 * points and summing the point values with specific weights.
775 */
776 std::shared_ptr<Quadrature<dim>> cell_quadrature;
777
778 /**
779 * Approximate an integral over a cell's face by evaluating the integrand at
780 * specific points and summing the point values with specific weights.
781 */
782 std::shared_ptr<Quadrature<dim - 1>> face_quadrature;
783
784 /**
785 * IndexSet of the owned degrees of freedom for the interior trial space.
786 */
788
789 /**
790 * IndexSet of the relevant degrees of freedom for the interior trial space.
791 */
793
794 /**
795 * IndexSet of the owned degrees of freedom for the skeleton trial space.
796 */
798
799 /**
800 * IndexSet of the relevant degrees of freedom for the skeleton trial space.
801 */
803
804 /**
805 * The system matrix.
806 */
807 TrilinosWrappers::SparseMatrix system_matrix;
808
809 /**
810 * A vector containing all the values of the solution in the interior trial
811 * space.
812 */
813 std::shared_ptr<GlobalVectorType> present_solution;
814
815 /**
816 * A vector containing all the values of the solution on the skeleton for the
817 * trial space.
818 */
819 std::shared_ptr<GlobalVectorType> present_solution_skeleton;
820
821 /**
822 * A vector containing the values of the dpg error estimator for each cell of
823 * the triangulation. This is used for mesh adaptation based on the DPG error
824 * estimator.
825 */
827
828 /**
829 * Non-ghosted vector in which the interior solution is assembled cell by
830 * cell during the reconstruction. It is needed because `present_solution` is
831 * a ghosted vector, which can only be read. It is a class member so the
832 * WorkStream copier can access it, but it is only allocated during
833 * reconstruct_interior_solution() to avoid keeping it in memory between the
834 * solves.
835 */
837
838 /**
839 * Squared L2 norm of the DPG residual, accumulated over the locally owned
840 * cells during the reconstruction when the dpg error estimator is activated.
841 */
843
844 /**
845 * The right hand side vector.
846 */
848
849 /**
850 * A vector containing the initial guess `x_0` for the iterative solver when
851 * solving for \f$ Ax = b \f$.
852 */
854
855 /**
856 * Store the nonzero constraints that arise from several sources such
857 * as boundary conditions and hanging nodes in the mesh. See the deal.II
858 * documentation on constraints on degrees of freedom for more information.
859 * The zero constraints are not used in this solver as it solve a linear
860 * system.
861 */
862 AffineConstraints<double> nonzero_constraints;
863
864 /**
865 * SolutionTransfer<dim, GlobalVectorType>> is
866 * used to implement the transfer of a discrete FE function
867 * (e.g. a solution vector) from one mesh to another. This Deal.ii class is
868 * used for mesh_refinement and simulation restarts. This transfer the
869 * interior solution.
870 */
871 std::shared_ptr<SolutionTransfer<dim, GlobalVectorType>> solution_transfer;
872
873 /**
874 * Extractor for the real part of the electric field vector.
875 */
876 const FEValuesExtractors::Vector extractor_E_real;
877
878 /**
879 * Extractor for the imaginary part of the electric field vector.
880 */
881 const FEValuesExtractors::Vector extractor_E_imag;
882
883 /**
884 * Extractor for the real part of the magnetic field vector.
885 */
886 const FEValuesExtractors::Vector extractor_H_real;
887
888 /**
889 * Extractor for the imaginary part of the magnetic field vector.
890 */
891 const FEValuesExtractors::Vector extractor_H_imag;
892
893 /**
894 * The time-harmonic Maxwell DPG system of equation is solved in dimensionless
895 * form. However, to be able to recover the physical solution, the physical
896 * amplitude of the electromagnetic fields needs to be calculated from the
897 * input power provided and the associated scaling factor is the maximum of
898 * those field amplitudes across all the inlets in the problem. This way, the
899 * electromagnetic fields remain with an amplitude of order 1 (for the inlet
900 * with the highest input power) or less (for the other inlets) in the
901 * dimensionless system.
902 *
903 */
905
906 /**
907 * A vector containing the electric amplitudes of all the waveguide ports. It
908 * is define as the : \f$ \sqrt{P_\mathrm{input}/P_\mathrm{port}} \f$, where
909 * \f$P_\mathrm{input}\f$ is the input power provided by the user for a given
910 * waveguide port and \f$P_\mathrm{port}\f$ is the power computed from
911 * integrating the Poynting vector of the electromagnetic fields at the inlet
912 * associated with the waveguide port condition.
913 */
915
916
917 /**
918 * A boolean variable that indicates whether the time-harmonic Maxwell solver
919 * needs to define temperature-dependent variables and store the temperature
920 * solution from the last solve.
921 */
923
924 /**
925 * A boolean variable that indicates whether the time-harmonic Maxwell solver
926 * needs to evaluate the void fraction field, i.e., if the electromagnetic
927 * properties of at least one effective medium depend on the void fraction.
928 */
930
931 /**
932 * A boolean variable that indicates whether the time-harmonic Maxwell solver
933 * needs to compute the value of the DPG error estimator.
934 */
936
937 /**
938 * A vector containing all the values of the temperature solution when the
939 * last solve of the time-harmonic Maxwell system was performed. This is used
940 * to determine the physical properties of the materials in the domain when
941 * they are temperature-dependent.
942 */
944
945
946 /**
947 * SolutionTransfer<dim, GlobalVectorType>> is
948 * used to implement the transfer of a discrete FE function
949 * (e.g. a solution vector) from one mesh to another. This Deal.ii class is
950 * used for mesh_refinement and simulation restarts. The temperature field
951 * last solved needs its own solution transfer since it does not have the same
952 * dof handler than the time-harmonic Maxwell physics.
953 */
954 std::shared_ptr<SolutionTransfer<dim, GlobalVectorType>>
956};
957
958
959
960#endif
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...
Definition copy_data.h:232
Class that manages the physical properties model which are required to calculate the various physical...
ConditionalOStream pcout
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
IndexSet locally_relevant_dofs_trial_interior
void copy_local_matrix_to_global_matrix(const DPGCopyData &copy_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 &copy_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 &copy_data)
Assemble the uncondensed local DPG system ( , , and ) of a cell with the cell and face assemblers,...
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.
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...
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.
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
void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
AffineConstraints< double > nonzero_constraints
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 &copy_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 &copy_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
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...
Definition utilities.h:500
@ 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
Definition vector.h:17