electromagneticSource

Specify current density or charge density for electromagnetic model

Description

example

electromagneticSource(emagmodel,'CurrentDensity',J) specifies current density for a magnetostatic model.

example

electromagneticSource(emagmodel,'ChargeDensity',rho) specifies charge density for an electrostatic model.

example

electromagneticSource(___,RegionType,RegionID) specifies the current or charge density for the specified geometry region. Use this syntax with any of the input arguments from previous syntaxes.

example

emagSource = electromagneticSource(___) returns the electromagnetic source object.

Examples

collapse all

Specify current density on the entire geometry for a magnetostatic analysis.

emagmodel = createpde('electromagnetic','magnetostatic');
importGeometry(emagmodel,'PlateHoleSolid.stl');
electromagneticSource(emagmodel,'CurrentDensity',[0;0;10])
ans =
ElectromagneticSourceAssignment with properties:

RegionType: 'Cell'
RegionID: 1
ChargeDensity: []
CurrentDensity: [3x1 double]

Specify charge density on individual faces in an electrostatic analysis.

Create an electromagnetic model for an electrostatic analysis.

emagmodel = createpde('electromagnetic','electrostatic');

Create a 2-D geometry with two faces. First, import and plot a 2-D geometry representing a plate with a hole.

gm = importGeometry(emagmodel,'PlateHolePlanar.stl');
pdegplot(gm,'EdgeLabels','on','FaceLabels','on') Then, fill the hole by adding a face and plot the resulting geometry.

pdegplot(gm,'FaceLabels','on') Specify charge density values separately for faces 1 and 2.

sc1 = electromagneticSource(emagmodel,'Face',1,'ChargeDensity',0.3)
sc1 =
ElectromagneticSourceAssignment with properties:

RegionType: 'Face'
RegionID: 1
ChargeDensity: 0.3000
CurrentDensity: []

sc2 = electromagneticSource(emagmodel,'Face',2,'ChargeDensity',0.28)
sc2 =
ElectromagneticSourceAssignment with properties:

RegionType: 'Face'
RegionID: 2
ChargeDensity: 0.2800
CurrentDensity: []

Use a function handle to specify a charge density that depends on the coordinates.

Create an electromagnetic model for electrostatic analysis.

emagmodel = createpde('electromagnetic','electrostatic');

Create a unit circle geometry and include it in the model.

geometryFromEdges(emagmodel,@circleg);

Specify the charge density as a function of the x- and y-coordinates, $\rho =0.3\sqrt{{\mathit{x}}^{2}+{\mathit{y}}^{2}}$.

rho = @(location,~)0.3.*sqrt(location.x.^2 + location.y.^2);
electromagneticSource(emagmodel,'ChargeDensity',rho)
ans =
ElectromagneticSourceAssignment with properties:

RegionType: 'Face'
RegionID: 1
ChargeDensity: @(location,~)0.3.*sqrt(location.x.^2+location.y.^2)
CurrentDensity: []

Input Arguments

collapse all

Electromagnetic model, specified as an ElectromagneticModel object. The model contains a geometry, a mesh, the electromagnetic properties of the material, the electromagnetic sources, and the boundary conditions.

Example: emagmodel = createpde('electromagnetic','electrostatic')

Current density, specified as a real number, a column vector of 3 elements for a 3-D model, or a function handle. Use a function handle to specify a current density that depends on the coordinates.

The output returned by the function handle must be 1-by-NumPoints vector for a 2-D problem and 3-by-NumPoints for a 3-D problem. Here NumPoints is the number of points.

Data Types: double | function_handle

Charge density, specified as a real number or a function handle. Use a function handle to specify a charge density that depends on the coordinates. For details, see More About.

Data Types: double | function_handle

Geometric region type, specified as 'Face' for a 2-D model or 'Cell' for a 3-D model.

Data Types: char | string

Region ID, specified as a vector of positive integers. Find the face or cell IDs by using pdegplot with the 'FaceLabels' or 'CellLabels' name-value argument set to 'on'.

Example: electromagneticSource(emagmodel,'CurrentDensity',10,'Face',1:3)

Data Types: double

Output Arguments

collapse all

Handle to the electromagnetic source, returned as an ElectromagneticSourceAssignment object. For more information, see ElectromagneticSourceAssignment Properties.

collapse all

Specifying Nonconstant Parameters of Electromagnetic Model

In Partial Differential Equation Toolbox™, use a function handle to specify these electromagnetic parameters when they depend on the coordinates:

• Relative permittivity of the material

• Relative permeability of the material

• Charge density as source

• Current density as source

• Voltage at the boundary

• Magnetic potential at the boundary

For example, use function handles to specify the relative permittivity, charge density, and voltage at the boundary for this model.

electromagneticProperties(emagmodel, ...
'RelativePermittivity', ...
@myfunPermittivity)
electromagneticSource(emagmodel, ...
'ChargeDensity',@myfunCharge, ...
'Face',2)
electromagneticBC(emagmodel, ...
'Voltage',@myfunBC, ...
'Edge',2)

The function must be of the form:

function emagVal = myfun(location,~)

The solver computes and populates the data in the location structure array and passes this data to your function. You can define your function so that its output depends on this data. You can use any name instead of location. To use additional arguments in your function, wrap your function (that takes additional arguments) with an anonymous function that takes only the location argument. For example:

electromagneticBC(model,'Edge',3,'Voltage',emagVal)

If you call electromagneticBC with Vectorized set to 'on', then location can contain several evaluation points. If you do not set Vectorized or use Vectorized,'off', then solvers pass just one evaluation point in each call.

The location data is a structure containing these fields:

• location.x — The x-coordinate of the point or points

• location.y — The y-coordinate of the point or points

• location.z — For a 3-D or an axisymmetric geometry, the z-coordinate of the point or points

• location.r — For an axisymmetric geometry, the r-coordinate of the point or points

Electromagnetic material properties (relative permittivity or relative permeability) and electromagnetic source (charge density or current density) get these data from the solver:

• location.x, location.y, location.z, location.r

• Subdomain ID

Boundary conditions (voltage or magnetic potential on the boundary) get these data from the solver:

• location.x, location.y, location.z, location.r

• location.nx, location.ny, location.nz, location.nr

For the nonconstant relative permittivity, relative permeability, and charge density, the output returned by the function handle must be of size 1-by-Np, where Np = numel(location.x) is the number of points.

For the nonconstant current density and magnetic potential on the boundary, the output returned by the function handle must be of size 1-by-Np for a 2-D problem and 3-by-Np for a 3-D problem.

Introduced in R2021a

Partial Differential Equation Toolbox Documentation Try MATLAB, Simulink, and Other Products

Get trial now