<?xml version="1.0" encoding="utf-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.ansys.com/setup" 
            xmlns="http://www.ansys.com/setup"
            elementFormDefault="unqualified" >

    <!-- Use the 'schemaVersion' attribute for versioning within the namespace -->
    
    <xsd:element name="Setup" type="Setup" />

    <!-- Type declarations -->

    <xsd:complexType name="Setup">
        <xsd:sequence>            
            <!-- General -->
            <xsd:element name="Fadapt" type="xsd:double" maxOccurs="1" />
            <xsd:element name="MaxNumPasses" type="xsd:nonNegativeInteger" default="10" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MaxMagDeltaS" type="PosDbl"  default="0.02" minOccurs="0" maxOccurs="1" />
            <xsd:element name="SaveCurrentsLastAdaptive" type="xsd:boolean" default="false" minOccurs="0" maxOccurs="1" />
            
            <!-- Options -->
            <xsd:element name="DoLambdaRefinement" type="xsd:boolean" default="true" minOccurs="0" maxOccurs="1" />
            <xsd:element name="UseDefaultLambdaTarget" type="xsd:boolean" default="true" minOccurs="0" maxOccurs="1" />
            <xsd:element name="LambdaTarget" type="PosDbl" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MaxRefinementPerPass" type="xsd:nonNegativeInteger" default="30" minOccurs="0" maxOccurs="1" />
            <xsd:element name="DoMaxRefinement" type="xsd:boolean" default="false" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MaxRefinement" type="xsd:nonNegativeInteger" default="1000000" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MinNumPasses" type="xsd:nonNegativeInteger" default="1" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MinConvergedPasses" type="xsd:nonNegativeInteger" default="1" minOccurs="0" maxOccurs="1" />

            <!-- Advanced -->
            <xsd:element name="FormPolygonUnionsBeforeMeshing" type="xsd:boolean" default="true" minOccurs="0" maxOccurs="1" />
            <xsd:element name="UsePolygonDefeaturing" type="xsd:boolean" default="true" minOccurs="0" maxOccurs="1" />
            <xsd:element name="PolygonDefeaturingTolRatio" type="PosDbl" default="0.0" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ViaNumSides" type="xsd:positiveInteger" default="6" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ViaMaterialDefault" type="xsd:string" default="copper" minOccurs="0" maxOccurs="1" />

            <!-- Advanced Meshing-->
            <xsd:element name="ArcStepSize" type="xsd:positiveInteger" default="30" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ArcStartAzimuth" type="xsd:nonNegativeInteger" default="0" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ArcMaxPoints" type="xsd:positiveInteger" default="8" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ArcUseChordErrorApprox" type="xsd:boolean" default="false" minOccurs="0" maxOccurs="1" />
            <xsd:element name="ArcMaxChordError" type="PosDbl" default="0" minOccurs="0" maxOccurs="1" />

            <!-- Solver -->
            <xsd:element name="MaxDeltaZ0" type="xsd:positiveInteger" default="2" minOccurs="0" maxOccurs="1" />
            <xsd:element name="SetTrianglesForWavePort" type="xsd:boolean" default="false" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MinTrianglesForWavePort" type="xsd:positiveInteger" default="100" minOccurs="0" maxOccurs="1" />
            <xsd:element name="MaxTrianglesForWavePort" type="xsd:positiveInteger" default="500" minOccurs="0" maxOccurs="1" />
            <xsd:element name="SignalLayerThicknessThreshold" type="PosDbl" default="0" minOccurs="0" maxOccurs="1" />
            <xsd:element name="DielectricLayerThicknessThreshold" type="PosDbl" default="0" minOccurs="0" maxOccurs="1" />
            <xsd:element name="BasisOrder" type="BasisOrderType" default="Mixed" minOccurs="0" maxOccurs="1" />
            <xsd:element name="UseIterativeSolver" type="xsd:boolean" default="false" minOccurs="0" maxOccurs="1" />
            <xsd:element name="IterativeSolverRelativeResidual" type="PosDbl" default="0.0001" minOccurs="0" maxOccurs="1" />

            <xsd:element name="FreqSweep" type="FreqSweep" minOccurs="0" maxOccurs="unbounded"/>

        </xsd:sequence>
        <xsd:attribute name="Name" type="xsd:string" />
        <xsd:attribute name="schemaVersion" type="xsd:decimal" use="required" fixed="1.0" />
    </xsd:complexType>
    
    <xsd:simpleType name="PosDbl">
        <xsd:restriction base="xsd:double">
            <xsd:minInclusive value="0" />
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:simpleType name="BasisOrderType">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="Zero" />
            <xsd:enumeration value="First" />
            <xsd:enumeration value="Second" />
            <xsd:enumeration value="Mixed" />
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:complexType name="FreqSweep">
        <xsd:choice>
            <xsd:element name="Discrete" type="DiscreteSweep" />
            <xsd:element name="Interpolating" type="InterpolatingSweep" />
        </xsd:choice>
        <xsd:attribute name="Name" use="required" />
        <xsd:attribute name="UseQ3DForDC" type="xsd:boolean" default="false" />
    </xsd:complexType>

    <xsd:complexType name="DiscreteSweep">
        <xsd:choice>
            <xsd:element name="Single" type="PosDbl" />
            <xsd:element name="LinearStep" type="LinearStep" />
            <xsd:element name="LinearCount" type="LinearCount" />
            <xsd:element name="DecadeCount" type="DecadeCount" />
        </xsd:choice>
        <xsd:attribute name="GenerateSurfaceCurrents" type="xsd:boolean" default="false" />
    </xsd:complexType>
    
    <xsd:complexType name="InterpolatingSweep">
        <xsd:choice>
            <xsd:element name="Single" type="PosDbl" />
            <xsd:element name="LinearStep" type="LinearStep" />
            <xsd:element name="LinearCount" type="LinearCount" />
            <xsd:element name="DecadeCount" type="DecadeCount" />
        </xsd:choice>
        <xsd:attribute name="RelativeErrorS" type="PosDbl" default="0.5" />
        <xsd:attribute name="UseErrorZ0" type="xsd:boolean" default="false" />
        <xsd:attribute name="PercentErrorZ0" type="xsd:positiveInteger" default="1" />
        <xsd:attribute name="EnforceCausality" type="xsd:boolean" default="true" />
        <xsd:attribute name="EnforcePassivity" type="xsd:boolean" default="true" />
        <xsd:attribute name="PassivityTolerance" type="xsd:double" default="0.0001" />
    </xsd:complexType>

    <xsd:complexType name="LinearStep">
        <xsd:attribute name="Start" type="PosDbl" use="required" />
        <xsd:attribute name="Stop" type="PosDbl" use="required" />
        <xsd:attribute name="Step" type="PosDbl" use="required" />
    </xsd:complexType>

    <xsd:complexType name="LinearCount">
        <xsd:attribute name="Start" type="PosDbl" use="required" />
        <xsd:attribute name="Stop" type="PosDbl" use="required" />
        <xsd:attribute name="Count" type="xsd:positiveInteger" use="required" />
    </xsd:complexType>

    <xsd:complexType name="DecadeCount">
        <xsd:attribute name="Start" type="PosDbl" use="required" />
        <xsd:attribute name="Stop" type="PosDbl" use="required" />
        <xsd:attribute name="Count" type="xsd:positiveInteger" use="required" />
    </xsd:complexType>

</xsd:schema>
