How to create a user-defined macro for the post-processing of time-stepping simulations?
Hi all,
I would like to create a user-defined macro to perform calculations on the B field at the nodes of the mesh of a rotating electrical machine (Flux2D model). Then, I would like to extract the results on a DEX file.
I successfully created the .py file of the macro by modifying an existing one available in Flux. As a result, I can load the macro in Flux.
What I would like to do now with this macro is to select manually the time steps of my solved scenario between which I would like to perform my calculations.
For instance, imagine that I have a time-stepping simulation that solves my model from time=0 to time=0.2 s with 1000 steps. Now, I would like to extract the B field at nodes only from time=0.1 s to time=0.2 s.
I do believe that I have to write some piece of code when defining the parameters as well as the function in the .py file of the macro, but I don't know how to do that. Is there anyone that can help me?
Thank you in advance!
Marco
Answers
-
Hi Marco,
For this I suggest you to add in the input of the macro two input parameters allowing to defined the minimum time step (0.1s) and the maximum time step (0.2s) defining the interval for the export.
From this two parameters you will be able to find the Index of the two steps and create a loop between this two index. Find attached an example.
For information you can find all the PyFlux methods that can be applied to get or reach a step of a scenario in the local documentation of Flux in the 'How to Documents' accessible from the supervisor of Flux by clicking on the Question mark
I hope this helps.
Cyril
1 -
Cyril Favre_21925 said:
Hi Marco,
For this I suggest you to add in the input of the macro two input parameters allowing to defined the minimum time step (0.1s) and the maximum time step (0.2s) defining the interval for the export.
From this two parameters you will be able to find the Index of the two steps and create a loop between this two index. Find attached an example.
For information you can find all the PyFlux methods that can be applied to get or reach a step of a scenario in the local documentation of Flux in the 'How to Documents' accessible from the supervisor of Flux by clicking on the Question mark
I hope this helps.
Cyril
Dear Cyril,
thank you very much for attaching this example, I am finding it very helpful!
Can you please explain better where I can find all those PyFlux methods? Which document exactly shall I refer to?
I also have another question for you: I see from your macro that you are extracting in your DEX file only one formula.
Is it possible to extract two formulas in the same DEX file, e.g., Bx and By (therefore Comp(1,B) and Comp(2,B))? I tried but I can't figure it out!Thank you in advance,
Marco
0 -
Dear Marco,
The document is named 'How to get the steps of a scenario' it is accessible from the supervisor of Flux By clicking on the question mark in the top right corner and selecting Altair Flux Local Documentation in the section "How to " Documents. Or it is also accessible online with the following link:
https://2021.help.altair.com/2021.2/flux/Flux/Help/english/UserGuide/English/topics/HowTo.htm
Concerning the DEX export, when I use the formula B all the components are exported so finally Flux export a file with 6 columns corresponding to
Column 1 - X coordinate of the node
Column 2 - Y coordinate of the node
Column 3 - Z coordinate of the node (0 in 2D)
Column 4 - X component of B
Column 5 - Y component of B
Column 6 - Z component of B (0 in 2D)
So in this case it export in the same DEX file Comp(1,B) and Comp(2,B)
I hope this helps.
Cyril
1 -
Cyril Favre_21925 said:
Dear Marco,
The document is named 'How to get the steps of a scenario' it is accessible from the supervisor of Flux By clicking on the question mark in the top right corner and selecting Altair Flux Local Documentation in the section "How to " Documents. Or it is also accessible online with the following link:
https://2021.help.altair.com/2021.2/flux/Flux/Help/english/UserGuide/English/topics/HowTo.htm
Concerning the DEX export, when I use the formula B all the components are exported so finally Flux export a file with 6 columns corresponding to
Column 1 - X coordinate of the node
Column 2 - Y coordinate of the node
Column 3 - Z coordinate of the node (0 in 2D)
Column 4 - X component of B
Column 5 - Y component of B
Column 6 - Z component of B (0 in 2D)
So in this case it export in the same DEX file Comp(1,B) and Comp(2,B)
I hope this helps.
Cyril
Dear Cyril,
thank you very much again!
By the way, I tried to run your macro, but I got the following error:
I am running your macro using Flux 2D 2019.1.1. Do you have any idea about this?
Thanks again,
Marco
0