Code Node Repo

As we’ve seen in most of the examples, the DOE node will set the MFiX variables (inputs) and run all of the simulations and the Response Surface node will create a surrogate model of system response (outputs). At present, it is left to the user to calculate their system response through some combination of user defined functions, post-processing with postmfix, third-party data analysis software and/or user developed codes/scripts. If the user is familiar with python programming, much or all of the data processing may be performed in the Nodeworks tab. If the user is new to python, even importing completely processed data back into Nodeworks may seem challenging. Included below are two primary types of Code node example scripts which can be easily adapted to import processed response data into Nodeworks.

Directory Loop

In the most idea situation, user defined functions can be written and compiled into the mfixsolver used for each simulation run by the DOE node which writes an output file containing a single value which is the system response quantity of interest. In this case, we need to connect the DOE Selected Output terminal to the input terminal of the Code node which we will specify as sims by setting the arguments:

sims

Now, the argument can be used within the code function:

import os
import numpy as np
sims.sort()

f = []
for ii in sims:
  outputFile = os.path.join(ii, 'data.txt')
  if os.path.exists(outputFile):
    fii = np.loadtxt(outputFile)
    f.append(float(fii))
  else:
    f.append(-1.0)
returnOut = f

The sims argument is used to both size the for loop and provide the path to the data files. This example can be imported directly into Code node by opening examples/code_node_repo/import_data/one_file_per_folder_0.txt

A slight variant of this case is if there happens to be additional data or header text in the data files. In this case a simple extension of the nympy loadtxt function can be used to skip lines and columns to select the correct response

fii = np.loadtxt(outputFile, skiprows = 1, usecols = 1)

Note that the usecols=1 command is actually taking the second entry of the array of data on the second line of the text file. This example can be imported directly into Code node by opening examples/code_node_repo/import_data/one_file_per_folder_1.txt

Single File

Another common scenario is that all simulations have been post-processed together and the response data is most easily exported as an array into a single text file. In this case, the arguments of the code node is not used and can be left blank or set to a dummy variable. If the data file is placed in the directory where the Nodeworks sheet is located, it can be imported with the simple function:

sims
import numpy as np
import os

dir = os.getcwd()
f = np.loadtxt(os.path.join(dir, 'data.txt'))
returnOut = f

If the data file is located somewhere else, the path can be set by instead specifying

dir = '/path/to/your/file/'

This example can be imported directly into Code node by opening examples/code_node_repo/import_data/one_file_array_0.txt