18#ifndef BEM_RWG_LUMPED_ELEM_BASE_H
19#define BEM_RWG_LUMPED_ELEM_BASE_H
49template <
typename MatrixType = EigenDenseMatrix<Complex>>
66 const std::vector<std::array<Index, 2>>&
ports,
91 const std::vector<std::array<Index, 2>>&
ports,
111 {
return ports().size(); };
157 return MeshView(structure_.mesh(), elem_inds,
"port_mesh");
174 return MeshView(structure_.mesh(), elem_inds,
"port_mesh");
285 MatrixType
mat (structure_.mesh().num_elems(),
view.elem_inds().size());
304 area += structure_.mesh().elem_primitive(
elem).area();
312 const std::vector<MeshView<TriangleMesh<3>>>&
terminals()
const {
return terminals_; };
318 const std::vector<std::array<Index, 2>>&
ports()
const {
return ports_; };
324 const std::vector<Complex>&
impedances()
const {
return impedances_; };
340 if (ports_.size() != impedances_.size() && impedances_.size() != 1)
341 throw std::invalid_argument(
"LumpedElementBase(): Number of `impedances` must equal number of `ports`, or be a single value.");
342 if (impedances_.size() == 1 && ports_.size() > 1)
345 impedances_.resize(ports_.size(),
imp);
369 for (
Index jj = 0;
jj < structure_.components().size(); ++
jj)
373 for (
Index kk = 0;
kk < structure_.components()[
jj].mesh_view().elem_inds().size(); ++
kk)
375 Triangle<3> tri = structure_.mesh().elem_primitive(structure_.components()[
jj].mesh_view().elem_inds()[
kk]);
384 term_elems.push_back(structure_.components()[
jj].mesh_view().elem_inds()[
kk]);
385 terminal_components_[
ii].push_back(
jj);
390 throw std::runtime_error(
391 "LumpedElementBase::set_terminals_from_polygons(): No mesh triangles found for terminal " + std::to_string(
ii)
410 terminal_components_[
ii] = { terminal_components_[
ii][
term_elem] };
413 std::sort(terminal_components_[
ii].
begin(), terminal_components_[
ii].
end());
414 auto iter = std::unique(terminal_components_[
ii].
begin(), terminal_components_[
ii].
end());
415 terminal_components_[
ii].erase(
iter, terminal_components_[
ii].
end());
419 terminals_.push_back(
view);
427 const std::vector<EigMatNX<Float, 3>> terminal_polygons_;
428 const std::vector<std::array<Index, 2>> ports_;
429 std::vector<MeshView<TriangleMesh<3>>> terminals_;
430 std::vector<std::vector<Index>> terminal_components_;
431 std::vector<Complex> impedances_;
Geometry operations class.
Class that provides a lightweight view into a MeshBase object.
Class that defines a structure.
Base class for generating excitation coefficients and coupling matrices for lumped ports.
virtual MatrixType voltage_mapping_matrix() const
Returns the matrix that maps the scalar potential on terminal triangles to the average voltage on the...
virtual MatrixType exc_matrix(const Float f) const
Returns the right-hand side excitation matrix to set a voltage source at each lumped element.
void set_terminals_from_polygons(const std::vector< EigMatNX< Float, 3 > > &terminal_polygons, const bool single_element=false)
Populates terminals_ by finding mesh elements inside each terminal polygon.
void check_impedances()
Ensures correct number of impedances are set.
virtual MatrixType current_mapping_matrix() const
Returns the matrix that maps the total port currents to the volume current densities on terminal tria...
Index num_ports() const
Returns the number of excitations (right-hand sides), which equals the number of ports.
virtual MatrixType current_matrix(const Float f) const =0
Returns the matrix associated with terminal currents.
LumpedElementBase(const Structure< TriangleMesh< 3 > > &structure, const std::vector< MeshView< TriangleMesh< 3 > > > &terminals, const std::vector< std::vector< Index > > &terminal_components, const std::vector< std::array< Index, 2 > > &ports, const std::vector< Complex > &impedances)
Constructs a LumpedElementBase object.
virtual MatrixType voltage_matrix(const Float f) const =0
Returns the matrix associated with the potential differences between terminals.
const std::vector< MeshView< TriangleMesh< 3 > > > & terminals() const
Returns a read-only reference to the terminal mesh views.
LumpedElementBase(const Structure< TriangleMesh< 3 > > &structure, const std::vector< EigMatNX< Float, 3 > > &terminal_polygons, const std::vector< std::array< Index, 2 > > &ports, const std::vector< Complex > &impedances, const bool single_element=false)
Constructs a LumpedElementBase object.
const std::vector< std::array< Index, 2 > > & ports() const
Returns a read-only reference to the port map.
virtual MatrixType terminal_mapping_matrix() const
Returns the matrix that maps terminal triangles to their parent mesh triangles.
Index num_port_elems(Index idx) const
Returns the number of mesh elements associated with a given port.
MeshView< TriangleMesh< 3 > > port_mesh_view() const
Returns a mesh view consisting of all elements associated with the ports.
Index num_port_elems() const
Returns the number of mesh elements associated with ports.
Float terminal_area(const MeshView< TriangleMesh< 3 > > &terminal) const
Returns the total area spanned by the mesh triangles associated with a given terminal.
const std::vector< std::vector< Index > > & terminal_components() const
Returns a read-only reference to the components associated with each terminal.
MeshView< TriangleMesh< 3 > > port_mesh_view(Index idx) const
Returns a mesh view consisting of all elements associated with a given port.
virtual MatrixType coupling_matrix(const Float f) const =0
Returns the matrix the couples the port current to the integral equation.
const std::vector< Complex > & impedances() const
Returns a read-only reference to the lumped impedances.
Eigen::Matrix< T, 1, Eigen::Dynamic > EigRowVec
Dynamic-size row vector containing type T.
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.
std::size_t Index
Unsigned integer type for indices and container sizes.
Namespace for RWG-based BEM functionality.