CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Pointwise & Gridgen (https://www.cfd-online.com/Forums/pointwise/)
-   -   Script to export each domain separately (https://www.cfd-online.com/Forums/pointwise/216065-script-export-each-domain-separately.html)

natan March 27, 2019 04:02

Script to export each domain separately
 
Hello,


I need to export each domain in my mesh as a PLOT3D file separately. With many domains this can be a really cumbersome task. Is there a script I could run for this?

dgarlisch March 27, 2019 18:29

you can create your own script.

As a guide, export one or two domains by hand with journaling.

Script, Begin Journaling...
Export one or two domains to Plot3D by hand.
Script, End Journaling

Using this journal as a guide, you can write a script that will grab all domains in model and then export them one by one.

See Glyph docs here.

Example Glyph scripts here.

See also pw::Grid getAll -type pw::DomainStructured to capture structured domains.

natan March 28, 2019 03:28

Thank you. I have consulted those sources and created a script based on the journal. Is there a for loop or something similar so that I can loop through all structured domains instead of changing the domain name every time? Also, is there a way to set a variable so that I can save a file based on the domain name?

dgarlisch March 28, 2019 10:06

1 Attachment(s)
I have attached a skeleton script that you can edit. It loops over all the structured domains in a grid.

I also added a few personal "best practices" to the script for your consideration.

Good luck.

Code:

# Load the Pointwise Glyph library
package require PWI_Glyph


#============================================================================
# Set up the global environment
#============================================================================

# Capture the directory in which the is located
set scriptDir [file dirname [info script]]

if { ![info exists argv] } {
    # must be running from the Pointwise GUI
    set argc 0
    set argv[list]
}


#============================================================================
# Define procs
#============================================================================


#-----------------------------------------------------------------------------
proc main { argv } {
  # if run from the command line, you can pass arguments
  processArgs $argv

  # Capture a list of all structured domains in the current grid
  set allStrDoms [pw::Grid getAll -type pw::DomainStructured]

  # loop through domains and export one at a time
  foreach strDom $allStrDoms {
    doExport $strDom
  }
}


#-----------------------------------------------------------------------------
proc processArgs { argv } {
  # Add command line processing here if needed

  # for now, just print all args to console
  if { 0 == [llength $argv] } {
    puts "No command line arguments found."
  } else {
    puts "argv:"
    foreach arg $argv {
      puts "  '$arg'"
    }
  }
}


#-----------------------------------------------------------------------------
proc doExport { strDom } {
  set domName [$strDom getName]

  # Be careful. The domain name MUST be only contain valid filename chars or the
  # export will fail!

  # The filename is in the same folder as the script.
  set filename [file join $::scriptDir "$domName.x"]

  puts "Exporting $filename ..."

  #####
  ##### put grid export code here
  #####
}


#============================================================================
# Invoke main AFTER all data and procs have been defined.
#============================================================================

main $argv


#============================================================================
# NOTE:
# Calling main as the starting point of a script is a personal preference.
# It is not required by Glyph or Tcl. You could also just put the code from main
# here at the end. I just like having main as the first proc in a script.
#============================================================================



All times are GMT -4. The time now is 08:28.