General

General

I am writing an ACT extension to encapsulate a custom result and need to take the derivative of that nodal result with respect to time. Is it possible to build in a derivative in ACT like this?

    • FAQFAQ
      Participant

      There are two main options here: Create the derivative yourself in Python, or call out to APDL to invoke the DERIV command.

      If creating the derivative yourself, it will require some numerical programming as (unfortunately) ACT’s Python does not have access to SciPy. If calling APDL, note that ansys.RunANSYS() might not won’t work in an Evaluate or Generate callback due to a threading issue. It probably will, but if not, here is how to do it without “import ansys” capabilities:

      —————
      import Ansys.Utilities
      from Ansys.Utilities import ApplicationConfiguration

      import System
      from System.Diagnostics import Process
      from System.Diagnostics import ProcessStartInfo
      from System.Diagnostics import ProcessWindowStyle

      # Create a tmp bat file in this path
      bat_file = System.IO.Path.Combine(apdlDir,’tmp.bat’);
      info = System.IO.StreamWriter(bat_file)
      a = ApplicationConfiguration.DefaultConfiguration.AwpRootEnvironmentVariableValue
      b = System.IO.Path.Combine(a,’ansys’)
      c = System.IO.Path.Combine(b,’bin’)
      d = System.IO.Path.Combine(c,ApplicationConfiguration.DefaultConfiguration.AnsysPlatform)
      e = System.IO.Path.Combine(d,’ansys162.exe’)
      commandLine = ‘”‘+e+'” -dir “‘+apdlDir+'” -j “file” -b -i “‘+apdlInput+'” -o “‘+apdlOutput+'”‘
      info.WriteLine(commandLine)
      info.Close()

      # Run the bat file now
      startInfo = ProcessStartInfo(bat_file, None)
      startInfo.WindowStyle = ProcessWindowStyle.Minimized

      p = Process.Start(startInfo)
      p.WaitForExit()

      # Delete the tmp bat file
      System.IO.File.Delete(bat_file)
      —————

      In this code, we create a tmp file with the command we want, and execute it with ANSYS. A nice way to get any APDL functionality in your ACT code.