Example 2: Defining operators and assembling them into matrices for more customized integral equations. Repeats the computations in Example 1, but with user-defined setup of the integral operators and their assembly into matrices, for more customization. Assumes knowledge from Example 1.
#include <iostream>
#include <string>
int main(int argc, char** argv)
{
std::cout << "\n====================================================" << std::endl;
std::cout << "OpenBEM example 2" << std::endl;
std::cout << "====================================================\n" << std::endl;
std::size_t path_pos = std::string(__FILE__).find_last_of("/");
std::string path = std::string(__FILE__).substr(0, path_pos) + "/";
std::string msh_filename = path + "msh/sphere.msh";
std::cout <<
"Number of vertices: " << structure.
mesh().num_verts() << std::endl;
std::cout <<
"Number of triangles: " << structure.
mesh().num_elems() << std::endl;
std::cout <<
"Number of edges: " << structure.
mesh().num_edges() << std::endl;
MatrixType L, K, I;
L.scale(-
bem::J * bem::two_pi * f * mu);
K.add_ax(I, 0.5);
MatrixType A;
A.set_axpby(L, K, alpha, 1.0 - alpha);
MatrixType inc_e;
MatrixType inc_h;
MatrixType b;
b.set_axpby(inc_e, inc_h, alpha, 1.0 - alpha);
MatrixType x;
A.mat_solve(x, b);
MatrixType x_tefie;
A_tefie.mat_solve(x_tefie, inc_e);
projection_points.
set_polar_data(arc_begin, arc_end, center, num_pts);
MatrixType Lproj;
proj_assembler.
assemble(Lproj, L_projector, k);
Lproj.scale(-
bem::J * bem::two_pi * f * mu);
MatrixType e_cfie;
e_cfie.set_mat_mul(Lproj, x);
MatrixType e_tefie;
e_tefie.set_mat_mul(tefie_proj, x_tefie);
e_cfie.raw_matrix() = e_cfie.raw_matrix().reshaped(3, 100);
e_tefie.raw_matrix() = e_tefie.raw_matrix().reshaped(3, 100);
MatrixType e_cfie_mag;
e_cfie_mag.raw_matrix() = e_cfie.raw_matrix().colwise().norm();
MatrixType e_tefie_mag;
e_tefie_mag.raw_matrix() = e_tefie.raw_matrix().colwise().norm();
MatrixType rcs_cfie;
rcs_cfie.raw_matrix() = Eigen::pow(e_cfie_mag.raw_matrix().array(), 2) * bem::four_pi * std::pow(dist, 2);
MatrixType rcs_tefie;
rcs_tefie.raw_matrix() = Eigen::pow(e_tefie_mag.raw_matrix().array(), 2) * bem::four_pi * std::pow(dist, 2);
MatrixType rcs_error;
rcs_error.raw_matrix() = (rcs_cfie.raw_matrix() - rcs_tefie.raw_matrix()).array().abs();
MatrixType rcs_relative_error;
rcs_relative_error.raw_matrix() = rcs_error.raw_matrix().array() / rcs_tefie.raw_matrix().array().abs();
bem::Float rcs_max_relative_error = rcs_relative_error.raw_matrix().array().abs().maxCoeff();
std::cout << "CFIE vs. TEFIE RCS maximum relative error: "
<< rcs_max_relative_error * 100
<< " %" << std::endl;
x,
structure.
mesh().elem_centroids(),
false
).array().real();
return 0;
}
Eigen-based dense matrix wrapper.
virtual Complex k(const Float f) const
Returns the frequency-dependent complex wavenumber.
virtual Complex mu() const
Returns the permeability.
static void read_gmsh_v2(Structure< TriangleMesh< 3 > > &structure, const std::string msh_filename, const bool decoupled_edges=false)
Reads a GMSH v2 mesh file and populates a TriangleMesh in a Structure.
static void write_gmsh_v2_vector_field(const Structure< TriangleMesh< 3 > > &structure, const std::string msh_filename, ConstEigRef< EigMatNX< Float, 3 > > field, std::string field_name="vector_field")
Writes a GMSH v2 mesh file from a TriangleMesh in a Structure with a superimposed vector field.
void set_polar_data(ConstEigRef< EigColVecN< Float, dim > > start, ConstEigRef< EigColVecN< Float, dim > > stop, ConstEigRef< EigColVecN< Float, dim > > center, ConstEigRef< EigColVecN< Index, dim > > num_pts)
Sets PointCloud data as points of a polar grid.
Class that defines a structure.
const Material & background_material() const
Returns the background material of the structure.
MeshType & mesh()
Returns the mesh associated with the structure in editable form.
Class for generating excitation matrices for RWG-based BEM systems with RWG testing functions.
void assemble(MatrixBase< Complex > &mat, ExcitationBase< 3 > &exc, const Complex k) override
Assembles the excitation matrix for a given excitation object and observation triangle mesh.
Class for generating operator matrices for RWG observation and source functions.
Class for generating projector matrices for edge-based RWG source functions.
void assemble(MatrixBase< Complex > &mat, ProjectorBase< 3 > &op, const Complex k) override
Assembles the projector matrix for edge-based RWG source functions.
Class for computing plane wave excitation vector coefficients when tested with rotated RWG functions.
void assemble(MatrixBase< Complex > &mat, OperatorType op, const Complex k)
Assembles the operator matrix for a given operator object and source and observation meshes.
Class for computing the rotationally-tested vector double-layer potential operator in a principal val...
Class for computing plane wave excitation vector coefficients when tested with RWG functions.
Class for computing the RWG identity operator.
static EigMatNX< Complex, 3 > reconstruct_field(const TriangleMesh< 3 > &mesh, const MatrixBase< Complex > &coeffs, ConstEigRef< EigMatNX< Float, 3 > > points, const bool rotated=false)
Reconstructs a vector field expressed with RWG functions on a given triangle mesh.
Class defining the RWG-based TEFIE.
MatrixType j_projector(const Float f, const Material &material, const PointCloud< 3 > &points)
Returns the projector matrix associated with the electric surface current density.
MatrixType j_matrix(const Float f, const Material &material)
Returns the operator matrix associated with the electric surface current density.
Class for computing the vector hypersingular operator.
Class for computing the vector hypersingular potential projector.
const Complex J
Imaginary unit.
const Float c0
Vacuum wave speed.
const Float eta0
Vacuum wave impedance.
double Float
Floating point number.
std::complex< Float > Complex
Complex floating point number.
Eigen::Matrix< T, N, 1 > EigColVecN
Fixed-size column vector of size N containing type T.
Eigen::Matrix< T, N, Eigen::Dynamic > EigMatNX
Fixed-height matrix with N rows containing type T.