# electromagneticBC

Apply boundary conditions to electromagnetic model

## Syntax

``electromagneticBC(emagmodel,RegionType,RegionID,'Voltage',V)``
``electromagneticBC(emagmodel,RegionType,RegionID,'MagneticPotential',A)``
``electromagneticBC(___,'Vectorized','on')``
``emagBC = electromagneticBC(___)``

## Description

example

````electromagneticBC(emagmodel,RegionType,RegionID,'Voltage',V)` adds a voltage boundary condition to `emagmodel`. The boundary condition applies to regions of type `RegionType` with ID numbers in `RegionID`.```

example

````electromagneticBC(emagmodel,RegionType,RegionID,'MagneticPotential',A)` adds a magnetic potential boundary condition to `emagmodel`. The boundary condition applies to regions of type `RegionType` with ID numbers in `RegionID`.```
````electromagneticBC(___,'Vectorized','on')` uses vectorized function evaluation when you pass a function handle as an argument. If your function handle computes in a vectorized fashion, then using this argument saves time. See Vectorization. For details on this evaluation, see Nonconstant Boundary Conditions.Use this syntax with any of the input arguments from previous syntaxes.```

example

````emagBC = electromagneticBC(___)` returns the electromagnetic boundary condition object.```

## Examples

collapse all

Apply voltage boundary conditions on two edges of a square.

```emagmodel = createpde('electromagnetic','electrostatic'); geometryFromEdges(emagmodel,@squareg); bc1 = electromagneticBC(emagmodel,'Edge',1,'Voltage',100)```
```bc1 = ElectromagneticBCAssignment with properties: RegionType: 'Edge' RegionID: 1 Voltage: 100 MagneticPotential: [] Vectorized: 'off' ```
`bc3 = electromagneticBC(emagmodel,'Edge',3,'Voltage',200)`
```bc3 = ElectromagneticBCAssignment with properties: RegionType: 'Edge' RegionID: 3 Voltage: 200 MagneticPotential: [] Vectorized: 'off' ```

Apply a magnetic potential boundary condition on the boundary of a circle.

```emagmodel = createpde('electromagnetic','magnetostatic'); geometryFromEdges(emagmodel,@circleg); electromagneticBC(emagmodel,'Edge',1,'MagneticPotential',0)```
```ans = ElectromagneticBCAssignment with properties: RegionType: 'Edge' RegionID: 1 Voltage: [] MagneticPotential: 0 Vectorized: 'off' ```

Use a function handle to specify a boundary condition that depends on the coordinates.

Create an electromagnetic model for electrostatic analysis.

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

Create the geometry and include it in the model.

`geometryFromEdges(emagmodel,@circleg);`

Specify the electrostatic potential at the boundary using the function$\text{\hspace{0.17em}}\mathit{V}\left(\mathit{x},\mathit{y}\right)={\mathit{x}}^{2}$.

```bc = @(region,~)region.x.^2; electromagneticBC(emagmodel,'Edge',1:emagmodel.Geometry.NumEdges,'Voltage',bc)```
```ans = ElectromagneticBCAssignment with properties: RegionType: 'Edge' RegionID: [1 2 3 4] Voltage: @(region,~)region.x.^2 MagneticPotential: [] Vectorized: 'off' ```

## Input Arguments

collapse all

Electromagnetic model, specified as an `ElectromagneticModel` object. The model contains a 2-D geometry, a mesh, electromagnetic properties of the materials, the electromagnetic sources, and the boundary conditions.

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

Geometric region type, specified as `'Edge'`.

Example: `electromagneticBC(emagmodel,'Edge',1,'Voltage',100)`

Data Types: `char` | `string`

Edge ID, specified as a vector of positive integers. Find the edge IDs by using `pdegplot` with the `'EdgeLabels'` name-value argument set to `'on'`.

Data Types: `double`

Voltage, specified as a real number or a function handle. Use a function handle to specify a voltage that depends on the coordinates or on the solution. For details, see Specifying Nonconstant Parameters of Electromagnetic Model.

Data Types: `double` | `function_handle`

Magnetic potential, specified as a real number or a function handle. Use a function handle to specify the magnetic potential that depends on the coordinates or on the solution. For details, see Specifying Nonconstant Parameters of Electromagnetic Model.

Data Types: `double` | `function_handle`

## Output Arguments

collapse all

Handle to the electromagnetic boundary condition, returned as an `ElectromagneticBCAssignment` object. For more information, see ElectromagneticBCAssignment 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 or solution:

• 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,state)`

The solver passes the `location` and `state` data to your function:

• `location` — 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 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

• `state` — A structure containing these fields for nonlinear problems:

• `state.u` — Electric or magnetic potential at the corresponding points of the location structure

• `state.ux` — Estimates of the x-component of the electric or magnetic field at the corresponding points of the location structure

• `state.uy` — Estimates of the y-component of the electric or magnetic field at the corresponding points of the location structure

• `state.uz` — For an axisymmetric geometry, estimates of the z-component of the electric or magnetic field at the corresponding points of the location structure

• `state.ur` — For an axisymmetric geometry, estimates of the r-component of the electric or magnetic field at the corresponding points of the location structure

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

• `state.u`, `state.ux`, `state.uy`, `state.uz`, `state.ur`

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`

• `state.u`

If properties depend on the electric or magnetic potential, ensure that your function returns a matrix of `NaN` of the correct size when `state.u` is `NaN`. Solvers check whether a problem is nonlinear by passing `NaN` state values and looking for returned `NaN` values.

Introduced in R2021a

## Support

#### Try MATLAB, Simulink, and Other Products

Get trial now