Main Content

electromagneticBC

Apply boundary conditions to electromagnetic model

    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 More About.

    Use this syntax with any of the input arguments from previous syntaxes.

    example

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

    Examples

    collapse all

    Create an electromagnetic model for electrostatic analysis.

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

    Import and plot the geometry representing a plate with a hole.

    gm = importGeometry(emagmodel,'PlateHoleSolid.stl');
    pdegplot(gm,'FaceLabels','on','FaceAlpha',0.3)

    Figure contains an axes object. The axes object contains 3 objects of type quiver, patch, line.

    Apply the voltage boundary condition on the side faces of the geometry.

    bc1 = electromagneticBC(emagmodel,'Voltage',0,'Face',3:6)
    bc1 = 
      ElectromagneticBCAssignment with properties:
    
               RegionType: 'Face'
                 RegionID: [3 4 5 6]
                  Voltage: 0
        MagneticPotential: []
               Vectorized: 'off'
    
    

    Apply the voltage boundary condition on the face bordering the hole.

    bc2 = electromagneticBC(emagmodel,'Voltage',1000,'Face',7)
    bc2 = 
      ElectromagneticBCAssignment with properties:
    
               RegionType: 'Face'
                 RegionID: 7
                  Voltage: 1000
        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 functionV(x,y)=x2.

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

    Input Arguments

    collapse all

    Electromagnetic model, specified as an ElectromagneticModel object. The model contains a 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' for a 2-D model or 'Face' for a 3-D model.

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

    Data Types: char | string

    Region ID, specified as a vector of positive integers. Find the edge or face IDs by using pdegplot with the 'EdgeLabels' or 'FaceLabels' 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. For details, see More About.

    Data Types: double | function_handle

    Magnetic potential, 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 the magnetic potential that depends on the coordinates. For details, see More About.

    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.

    More About

    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:

    emagVal = @(location,~) myfunWithAdditionalArgs(location,arg1,arg2...)
    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