MFEM v4.7.0
Finite element discretization library
Loading...
Searching...
No Matches
pml.hpp
Go to the documentation of this file.
1// Copyright (c) 2010-2024, Lawrence Livermore National Security, LLC. Produced
2// at the Lawrence Livermore National Laboratory. All Rights reserved. See files
3// LICENSE and NOTICE for details. LLNL-CODE-806117.
4//
5// This file is part of the MFEM library. For more information and source code
6// availability visit https://mfem.org.
7//
8// MFEM is free software; you can redistribute it and/or modify it under the
9// terms of the BSD-3 license. We welcome feedback and contributions, see file
10// CONTRIBUTING.md for details.
11
12#include "mfem.hpp"
13
14namespace mfem
15{
16
17/// Class for setting up a simple Cartesian PML region
19{
20private:
21 Mesh *mesh;
22
23 /** 2D array of size (dim,2) representing the length of the PML
24 region in each direction */
25 Array2D<real_t> length;
26
27 /// 2D array of size (dim,2) representing the Computational Domain Boundary
28 Array2D<real_t> comp_dom_bdr;
29
30 /// 2D array of size (dim,2) representing the Domain Boundary
31 Array2D<real_t> dom_bdr;
32
33 /** Integer Array identifying elements in the pml
34 0: in the pml, 1: not in the pml */
35 Array<int> elems;
36
37 /// Compute Domain and Computational Domain Boundaries
38 void SetBoundaries();
39
40public:
41 /** Constructor of the PML region using the mesh @a mesh_ and
42 the 2D array of size (dim,2) @a length_ which represents the
43 length of the PML in each direction. */
44 CartesianPML(Mesh *mesh_, const Array2D<real_t> &length_);
45
46 int dim;
48 // Default values for Maxwell
50 real_t mu = 1.0;
51 /// Return Computational Domain Boundary
52 const Array2D<real_t> & GetCompDomainBdr() {return comp_dom_bdr;}
53
54 /// Return Domain Boundary
55 const Array2D<real_t> & GetDomainBdr() {return dom_bdr;}
56
57 /// Return Marker list for elements
58 const Array<int> & GetMarkedPMLElements() {return elems;}
59
60 /// Mark element in the PML region
61 void SetAttributes(Mesh *mesh_, Array<int> * attrNonPML = nullptr,
62 Array<int> * attrPML = nullptr);
63
64 void SetOmega(real_t omega_) {omega = omega_;}
65 void SetEpsilonAndMu(real_t epsilon_, real_t mu_)
66 {
67 epsilon = epsilon_;
68 mu = mu_;
69 }
70 /// PML complex stretching function
71 void StretchFunction(const Vector &x, std::vector<std::complex<real_t>> &dxs);
72};
73
74
76{
77private:
78 CartesianPML * pml = nullptr;
79 real_t (*Function)(const Vector &, CartesianPML * );
80public:
82 : pml(pml_), Function(F)
83 {}
85 {
86 real_t x[3];
87 Vector transip(x, 3);
88 T.Transform(ip, transip);
89 return ((*Function)(transip, pml));
90 }
91};
92
94{
95private:
96 CartesianPML * pml = nullptr;
97 void (*Function)(const Vector &, CartesianPML *, DenseMatrix &);
98public:
99 PmlMatrixCoefficient(int dim, void(*F)(const Vector &, CartesianPML *,
100 DenseMatrix &),
101 CartesianPML * pml_)
102 : MatrixCoefficient(dim), pml(pml_), Function(F)
103 {}
105 const IntegrationPoint &ip)
106 {
107 real_t x[3];
108 Vector transip(x, 3);
109 T.Transform(ip, transip);
110 K.SetSize(height, width);
111 (*Function)(transip, pml, K);
112 }
113};
114
115/// PML stretching functions: See https://doi.org/10.1006/jcph.1994.1159
116// Helmholtz
117real_t detJ_r_function(const Vector & x, CartesianPML * pml);
118real_t detJ_i_function(const Vector & x, CartesianPML * pml);
119real_t abs_detJ_2_function(const Vector & x, CartesianPML * pml);
120
121void Jt_J_detJinv_r_function(const Vector & x, CartesianPML * pml,
122 DenseMatrix & M);
123void Jt_J_detJinv_i_function(const Vector & x, CartesianPML * pml,
124 DenseMatrix & M);
125void abs_Jt_J_detJinv_2_function(const Vector & x, CartesianPML * pml,
126 DenseMatrix & M);
127
128// Maxwell
129// |J| J^-1 J^-T
130void detJ_Jt_J_inv_r_function(const Vector &x, CartesianPML * pml,
131 DenseMatrix &M);
132void detJ_Jt_J_inv_i_function(const Vector &x, CartesianPML * pml,
133 DenseMatrix &M);
134void abs_detJ_Jt_J_inv_2_function(const Vector &x, CartesianPML * pml,
135 DenseMatrix &M);
136
137} // namespace mfem
Dynamic 2D array using row-major layout.
Definition: array.hpp:372
Class for setting up a simple Cartesian PML region.
Definition: pml.hpp:19
void SetEpsilonAndMu(real_t epsilon_, real_t mu_)
Definition: pml.hpp:65
const Array< int > & GetMarkedPMLElements()
Return Marker list for elements.
Definition: pml.hpp:58
void SetAttributes(Mesh *mesh_, Array< int > *attrNonPML=nullptr, Array< int > *attrPML=nullptr)
Mark element in the PML region.
Definition: pml.cpp:70
void StretchFunction(const Vector &x, std::vector< std::complex< real_t > > &dxs)
PML complex stretching function.
Definition: pml.cpp:130
real_t omega
Definition: pml.hpp:47
void SetOmega(real_t omega_)
Definition: pml.hpp:64
const Array2D< real_t > & GetDomainBdr()
Return Domain Boundary.
Definition: pml.hpp:55
real_t epsilon
Definition: pml.hpp:49
const Array2D< real_t > & GetCompDomainBdr()
Return Computational Domain Boundary.
Definition: pml.hpp:52
Base class Coefficients that optionally depend on space and time. These are used by the BilinearFormI...
Definition: coefficient.hpp:42
Data type dense matrix using column-major storage.
Definition: densemat.hpp:24
void SetSize(int s)
Change the size of the DenseMatrix to s x s.
Definition: densemat.hpp:105
virtual void Transform(const IntegrationPoint &, Vector &)=0
Transform integration point from reference coordinates to physical coordinates and store them in the ...
Class for integration point with weight.
Definition: intrules.hpp:35
Base class for Matrix Coefficients that optionally depend on time and space.
Mesh data type.
Definition: mesh.hpp:56
virtual real_t Eval(ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the coefficient in the element described by T at the point ip.
Definition: pml.hpp:84
PmlCoefficient(real_t(*F)(const Vector &, CartesianPML *), CartesianPML *pml_)
Definition: pml.hpp:81
PmlMatrixCoefficient(int dim, void(*F)(const Vector &, CartesianPML *, DenseMatrix &), CartesianPML *pml_)
Definition: pml.hpp:99
virtual void Eval(DenseMatrix &K, ElementTransformation &T, const IntegrationPoint &ip)
Evaluate the matrix coefficient in the element described by T at the point ip, storing the result in ...
Definition: pml.hpp:104
Vector data type.
Definition: vector.hpp:80
int dim
Definition: ex24.cpp:53
real_t detJ_r_function(const Vector &x, CartesianPML *pml)
PML stretching functions: See https://doi.org/10.1006/jcph.1994.1159.
Definition: pml.cpp:160
void Jt_J_detJinv_r_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:191
void abs_Jt_J_detJinv_2_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:223
void detJ_Jt_J_inv_r_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:242
void Jt_J_detJinv_i_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:207
float real_t
Definition: config.hpp:43
real_t abs_detJ_2_function(const Vector &x, CartesianPML *pml)
Definition: pml.cpp:180
real_t detJ_i_function(const Vector &x, CartesianPML *pml)
Definition: pml.cpp:170
void abs_detJ_Jt_J_inv_2_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:276
void detJ_Jt_J_inv_i_function(const Vector &x, CartesianPML *pml, DenseMatrix &M)
Definition: pml.cpp:259