Sharing parameters between PY and PRO
Dear Developers and Users,
I'm looking for a way to share parameters between a PY file and a PRO file without using gmsh GUI.
I create a geometry and mesh through python API of Gmsh, i.e., by running python geometry.py
.
Then, I run getdp main.pro -msh MESH.msh ...
to run a solver and output results. All work fine.
My problem is as the following:
I have a bulky set of parameters defined in geometry.py
, for example freq = 3e9
and so on. These parameters are also used in main.pro
, so, for now, I just copy&paste the relevant portion of codes from the PY file to PRO.
What is a good way to share all these parameters between codes ?
Refering to this tutorial wiki (ONELAB-onelab.py-module and ONELAB-syntax-for-Gmsh-and-GetDP), I tried to make use of ONELAB.py.
Simplified codes are shown below, attempting to share a parameter freq
but no success.
"""geometry.py"""
import onelab
c = onelab.client(__file__)
c.defineNumber("freq", value=3e9) # or c.setNumber("freq", value=3e9)
c.run(name="geometry", command="getdp main.pro")
// main.pro
DefineConstant [ freq = { 1, Name "freq" }]; // I want to update this value programmatically
Printf("FREQ: %f", freq); // this returns "Freq: 1.000000"
Then, from a terminal I can run the above two codes.
>> python geometry.py
I have a feeling that I'm using an onelab client in a wrong way. Could someone please enlighten me? Thank you so much in advance.
On a side note, if I use GEO scripts (.geo) than python scripts to generate a geometry, I don't have a problem because GEO scripts can be included in a PRO file and all parameters are shared.
The versions I use: GetDP 3.5.0 Gmsh 4.12.2 on Windows 11.
Tom