function pdem = createpde(varargin)
%CREATEPDE - Creates an analysis model
%
% structuralmodel = CREATEPDE('structural',AnalysisType) creates a
% structural analysis model, which can be used to solve static, transient,
% modal, and frequency response problems for solid, plane stress, plane
% strain, and axisymmetric modeling.
%
% thermalmodel = CREATEPDE('thermal',AnalysisType) creates a thermal
% analysis model, which can be used to solve steady-state and transient
% problems for solid, planar, and axisymmetric modeling.
%
% emagmodel = CREATEPDE('electromagnetic',AnalysisType) creates an
% electromagnetic analysis model, which can be used to solve electrostatic
% and magnetostatic problems in the planar and axisymmetric domains.
%
% model = CREATEPDE(PDESystemSize) creates a generic PDE model that defines
% a system of PDEs of size PDESystemSize.
%
% For more information and details on AnalysisType, see documentation for <a
% href="matlab:doc createpde">createpde</a>.
%
% EXAMPLE 1: Create a structural static plane-stress model and import a geometry.
%
%     structuralmodel = createpde('structural','static-planestress')
%     gm = geometryFromEdges(structuralmodel,@squareg)
%
% EXAMPLE 2: Create a transient thermal model and import a geometry.
%
%     thermalmodel = createpde('thermal','transient');
%     gm = importGeometry(thermalmodel,'SquareBeam.stl');
%
% EXAMPLE 3: Create a magnetostatic analysis model and import a geometry.
%
%     emagmodel = createpde('electromagnetic','magnetostatic');
%     gm = importGeometry(emagmodel,'PlateHoleSolid.stl');
%
% EXAMPLE 4: Create a general model for a system of two PDEs and import a geometry.
%
%     model = createpde(2);
%     gm = importGeometry(model,'SquareBeam.stl');
%
%  See also pde.StructuralModel, pde.ThermalModel,
%           pde.ElectromagneticModel, pde.PDEModel

%  Copyright 2014-2021 The MathWorks, Inc.


if nargin > 0
    [varargin{:}] = convertStringsToChars(varargin{:});
end

narginchk(0,2);

if (nargin == 0)
    pdem = pde.PDEModel(1);
    return
end

if (nargin == 1) && isnumeric(varargin{1})
    validateattributes(varargin{1},{'numeric'},{'real', 'finite', 'integer', 'nonsparse', 'nonnan'});
    pdem = pde.PDEModel(double(varargin{1}));
    return
end

if (nargin > 1) && isnumeric(varargin{1})
    error(message('pde:createpde:invalidFirstArg'));
end

if isempty(varargin{1}) % String special cases: '',"",0x1,0x0, as convertStringsToChars returns an empty cell for 0x1,0x0 strings.
    error(message('pde:createpde:unsupportedVertical',''));
end

%Only valid input argument from this point on must be a char/string.
for strInput = varargin
    validateattributes(strInput{:}, {'char','string'},{'scalartext','nonempty'});
end
physics = varargin{1};

if (startsWith("thermal",physics,'IgnoreCase',true) )
    pdem = pde.ThermalModel(varargin{2:end});
elseif (startsWith("structural",physics,'IgnoreCase',true))
    pdem = pde.StructuralModel(varargin{2:end});
elseif (startsWith("electromagnetic",physics,'IgnoreCase',true))
    pdem = pde.ElectromagneticModel(varargin{2:end});
else
    error(message('pde:createpde:unsupportedVertical',physics));
end

end
