The Application Argument Node
To add an Application Argument node (), right-click the Inputs node () and choose Application Argument, or click the Application Argument button () on the Home toolbar. Use an Application Argument node to define an input argument for an application. You can add several Application Argument nodes to support multiple input arguments to the application. The order is not important because it is the name that is used to map the command-line arguments.
About Command-Line Arguments
To specify command-line arguments when running an application, you specify the names using appargnames and the corresponding values using appargvalues. This syntax makes it possible to mix both general built-in arguments supported for all applications and custom arguments supported for a specific application. The following example shows a command line where the renderer is set to DirectX and the custom application arguments width and height are also specified:
comsol -run myapp.mph -3drend dx9 -appargnames width,height -appargvalues 12.3,7.4
For specifying values that are arrays, the same syntax as when specifying the initial values for the corresponding declarations is supported. That is, use { and } to specify the start and end of arrays or rows in 2D arrays and then commas to separate the individual values.
In addition to specifying arguments individually on the command line, you can also specify them in a file using the -appargsfile argument. The format of the file must use Java property file syntax as in the following example:
width = 1.7
height = 4.3
voltages = {4,6.7,11.2}
intmatrix = {{1,5,6},{7,9,1}}
inputFile = 'C:\data\functions\simpleinterp.txt'
Setting arguments from a file can also be combined with setting some arguments explicitly from the command line as shown in the following example:
comsol -run myapp.mph -appargsfile inputFile.txt -appargnames width,height -appargvalues 12.3,7.4
If an argument appears both in the file and explicitly using -appargvalues, the value given using -appargvalues overrides the value given in the file. Passing the value of the -appargsfile as a text file instead of an inline argument is recommended when the argument contains special characters such as backslash characters in a file path.
When an input file contains
To use several files with values, use the command-line parameters -appargvarlist and -appargfilelist. You can use them in a similar way as -appargnames and -appargvalues. The only difference is that -appargfilelist is a comma-separated list of files. In this case, the file only contains the values and does not need to contain the name of the input parameter to assign the values to. This approach has the advantage that files exported on the spreadsheet format from COMSOL Multiphysics can be directly be passed as input. The following command line shows an example of this:
comsol -run myapp.mph -appargvarlist temperature,voltage -appargfilelist
<path to file with temperature data>,<path to file with voltage data>
Command-line arguments for applications can also use a file declaration as the target. The argument value has to be a file on the client file system. For example, consider an application file_argument.mph, which has an argument interpfile that points to a file declaration file1. Such an application can include an interpolation function that uses a file upload:///file1. You can then start the application using, for example, the following command-line arguments, using a text file called simpleinterp.txt on the local file system:
comsol.exe -run file_arguments.mph -appargnames interpfile -appargvalues 'C:\data\functions\simpleinterp.txt'
About the Settings Window
In the Name field, specify a name for this node that also becomes the name of the input argument.
In addition, the Settings window includes the following sections:
Source
This section contains a tree with a filtered view of the trees in the Application Builder window. The nodes either represent some sort of data or have children that do. For an Application Argument, the tree contains all the declarations in the application (that is, all primitive declarations such as Boolean, integer, double, and string scalar and array data types). The value for a command-line argument with the given name will end up in the declaration that you select. The input data will also be automatically converted to the data type of the declaration. An error will occur if the conversion fails, such as if the user of the application specifies 3.7 as the value for a command-line argument where an integer is expected. When you select a node that represents data, the Use as Source toolbar button below the tree becomes enabled. You can click it or, alternatively, press Enter, double-click, or right-click the node and choose Use as Source to add it as the selected source. You can also click the Create New Declaration and Use It as Source button () in the Source section header to create a new variable declaration for the application argument and use it as the source. A Create and Use Declaration dialog box opens, so that you can select the data type of the source (if applicable) and its name and initial value. The name cannot be in conflict with any existing variable declaration. Click the Edit Node toolbar button () below the tree to move to the corresponding node.
After selecting a node as the source, the node appears as the selected source under Selected source.
Help Text
In the text field in this section you can add some text that will appear as a help text when a user calls the application from the command line using the -help argument. For example, if the application’s name is myapp.mph, the following command displays the help for the application’s input arguments:
comsol -help myapp.mph