Example 1: automatic creation of a series of mesh lines

Objective

The objective is to show, in a simple example, how to write a command file to automatically create a series of mesh lines.

Example description

The command file allows the creation of eight Mesh lines A1, …, A8 of the arithmetic type with 1, …, 8 elements for different Flux projects (2D / 3D).

Process

The process includes the following stages:

Stage Description Context
1 Saving in a *.py file the sequence of creation of a Mesh line Flux
2 Modification of the previous command file using the PyFlux language Text editor
3 Executing this file to test it Flux

Stage 1

To save in a command file the sequence of creation of a Mesh Line :

Step Action
1

Create a new command file from a Flux project:

  • in the Project menu, point on Command file

    and click on New

  • in the dialog box, enter the file name CreateMeshLine.py
2

Create a mesh line:

  • in the data tree, double-click on Mesh Line
  • in the New Mesh line dialog box, fill out different zones:

  • click on OK
  • in the new dialog box, click on Cancel
3

Save and close the command file:

  • in the Project menu, point on Command file and click on Close

Stage 1: file explanation

The command file CreateMeshLine.py containing the saved sequence is presented as follows:

Element Function
#! Preflu3D 9.33
indication on the executable program (the #! symbol) this file was saved by
MeshLineArithmetic
   (name=A1,
   color=Color['White'],
   number=1)

creation of a Mesh Line with the following characteristics of the Flux command:

  • name = A1;
  • color = white;
  • number = 1

Stage 2

To modify the previous command file using the PyFlux syntax:

Step Action
1 Rewrite the command file CreateMeshLine.py by using a for loop and a variable
2 Save the file

Stage 2: file explanation

The command file CreateMeshLine.py containing the new instructions is presented as follows:

Element Function
#! Preflu2D 10.3
#! Preflu3D 10.3

indication on the two programs with which this file can be executed

(the Preflu2D program is added to use this command file in Flux 2D)

for i in range(8) :
carrying out a for loop to reiterate on the values of the sequence [0, …, 7]
name ='A'+ str(i+1)

creation of a variable name which takes for successive values the strings:

A1, A2, …, A8

(the method str() converts the numerical type in string)

MeshLineArithmetic
   (name=name,
   color=Color[i+1],
   number=i+1)

creation of a series of Mesh lines with the following characteristics:

  • name = A1; A2; A3; A4; A5; A6; A7; A8
  • color = black; white; yellow; blue; turquoise; magenta; red; green
  • number = 1; 2; 3; 4; 5; 6; 7; 8

Stage 3

Run the command file form a Flux project:

  • in the Project menu, point on Command file and click on Run a python file
  • in the dialog box, select the file name CreateMeshLine.py

Stage 3: final result

After running the command file, the user will have 8 mesh line entities available in the current Flux project: A1 = 1, A2 = 2, …, A8 = 8