Is there an example for custom load extension demonstrating APDL commands encapsulation on a multist

Options
Pernelle Marone-Hitz
Pernelle Marone-Hitz Member, Moderator, Employee Posts: 810
First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member

Is there an example for custom load extension demonstrating APDL commands encapsulation on a multistep problem.?

Answers

  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 810
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Options

    Here is an example.

    .xml file:

    <extension version="1" name="multiStep">
    <guid shortid="multiStep">66F87991-B66E-425E-B2E6-D2C5C1DF31D9</guid>
      <script src="main.py" />
      <interface context="Mechanical">
        <images>images</images>
        <toolbar name="multiStep" caption="multiStep">
          <entry name="multiStep_Check" icon="Thermal">
            <callbacks>
              <onclick>createLoad</onclick>
            </callbacks>
          </entry>
        </toolbar>
      </interface>
      <simdata context="Mechanical">
        <load name="multiStep" version="1" caption="multiStep_Check" icon="Thermal" issupport="false" isload="true" color="#0000FF">
          <callbacks>
            <getcommands location="solve">writeLoad</getcommands>
          </callbacks>      
          <property name="Geometry"  caption= "Geometry" control="scoping">
            <attributes selection_filter="face" />
          </property>
        </load>
      </simdata>  
    </extension>
    

    main.py file:

    def createLoad(currentAnalysis):
        load = currentAnalysis.CreateLoadObject("multiStep", "multiStep")
    
    
    def writeLoad(load, solverData, stream):
        # Direct
        # if solverData.CurrentStep == 1:
        #     stream.Write("D, All, UZ,5" + "\n")
        # elif solverData.CurrentStep == 2:
        #     stream.Write("D, All, UZ,10" + "\n")
    
        ###########Using readlines#######
        #Scope only named selections##
    
        SourceDir = ExtAPI.ExtensionManager.CurrentExtension.InstallDir
        macFile1 = "step1.inp"
        macFile2 = "step2.inp"
        ns = load.Properties["Geometry"].Value.SolverName
        ExtAPI.Log.WriteMessage('2nd Method')
        if solverData.CurrentStep == 1:
            stream.Write("cmsel,s," + ns + "\n")
            fs1 = open(os.path.join(SourceDir, macFile1), "r")
            allLines1 = fs1.readlines()
            fs1.close()
            stream.Write("".join(allLines1))
        elif solverData.CurrentStep == 2:
            stream.Write("cmsel,s," + ns + "\n")
            fs2 = open(os.path.join(SourceDir, macFile2), "r")
            allLines2 = fs2.readlines()
            fs2.close()
            stream.Write("".join(allLines2))
    

    step1.inp:

    /solu
    D, All, UZ,5
    allsel,all
    

    step2.inp:

    /solu
    DDELE,ALL,ALL
    D, All, UZ,10
    allsel,all