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:
|
2 |
Create a mesh line:
|
3 |
Save and close the command file:
|
Stage 1: file explanation
The command file CreateMeshLine.py containing the saved sequence is presented as follows:
Element | Function |
---|---|
|
indication on the executable program (the #! symbol) this file was saved by |
|
creation of a Mesh Line with the following characteristics of the Flux command:
|
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 |
---|---|
|
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) |
|
carrying out a for loop to reiterate on the values of the sequence [0, …, 7] |
|
creation of a variable name which takes for successive values the strings: A1, A2, …, A8 (the method str() converts the numerical type in string) |
|
creation of a series of Mesh lines with the following characteristics:
|
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