How to parameterize Fortran format in APDL command objects under Solution?
In below APDL post command, I would like to parametrize *VREAD format “400” as parameter “para”.
Are there any solution?
para=400
row=sepa_y
col=sepa_x
*dim,data_read,array,row,col
*VREAD,data_read(1,1),CuIns(1),txt,,jik,col,row,1
(400f4.0)
*endif
Comments
-
One can use Python Code object under Solution to parametrize this (since 2021R2).
Here are the steps.
Step 1: RMB on Solution --> Insert --> Python Code
Step 2: This Python Code object will have 2 tabs. Script and Property Provider.Step2a: Replace the below script with the existing script for the function reload_props (first function in the list). With this step, we are basically creating a custom parameter (called "Num Columns") for Fortran format, which can be later used in APDL code.
def reload_props(): this.PropertyProvider = None # comment the following return to allow the rest of the function definition to be executed and add properties """ Some sample code is provided below that shows how to: 1. Create an instance of the Provider. The Provider class is used to add custom properties to the details. 2. Use the Provider instance to add custom properties. 3. Configure those custom properties. """ # Create the property instance provider = Provider() # Create a group named Group 1. group = provider.AddGroup("Formatting Parameters") # Create a property with control type Expression and a property with control type Double, and add it to the Group 1 double_prop = group.AddProperty("Num Columns", Control.Double) # Configure the double property to be parameterizable. As a default the property will be an input parameter. # However, by updating the ParameterType property, it can be configured to be a output parameter as well. double_prop.CanParameterize = True # Connects the provider instance back to the object by setting the PropertyProvider member on this, 'this' being the # current instance of the Python Code object. this.PropertyProvider = provider
Step 2b: RMB on Python Code object --> Reload Properties. This should now show a new Property called Num Columns in the details window of the Python Code object (properties window). Provide an input
Step 3: Paste the below script in the Script tab of the python code
Para= int(this.GetCustomPropertyByPath("Formatting Parameters/Num Columns").Value) cmd = """row=sepa_y col=sepa_x *dim,data_read,array,row,col *VREAD,data_read(1,1),CuIns(1),txt,,jik,col,row,1""" solver_input_file.WriteLine(cmd) solver_input_file.WriteLine("(" + str(Para) + "f4.0)") solver_input_file.WriteLine("*endif")
Step 4: Solve
Hope this helps.
0 -
@Rohith Patchigolla Why not just enclose para in % in the formatting statement?
para=400
...
*VREAD,data_read(1,1),CuIns(1),txt,,jik,col,row,1
(%para%f4.0)
*endifOr if you want para to be also a WB parameter, check on the first available ARG parameter in the command object details (say ARG1) then use:
*VREAD,data_read(1,1),CuIns(1),txt,,jik,col,row,1
(%ARG1%f4.0)
*endif0 -
Hi @Mike Rife
Unfortunately, %arg1% (for example) will not work under Formating. One would get a warning message as shown below.*** WARNING *** CP = 2.250 TIME= 10:21:16
Data output error, probably bad FORMAT
(%ARG1%f4.0).0 -
Hi @Rohith Patchigolla
Darn it...had it working in MAPDL and made a bad assumption. Try this instead assuming the command object has ARG1 flagged as parameter and has value of 4:set,last
para = '%ARG1%'
vw = '*vwrite,'
a1 = 'n_list(1),'
a2 = 'n_x(1),'
a3 = 'n_y(1),'
a4 = 'n_z(1)'
a5 = '('
a6 = 'F6.3)'*vget,n_list,node,0,nlist
*vget,n_x,node,0,loc,x
*vget,n_y,node,0,loc,y
*vget,n_z,node,0,loc,z*CFOPEN,%_wb_userfiles_dir(1)%ndata.txt
*vwrite,vw,a1, a2, a3, a4
%C%C%C%C%C
*vwrite,a5,para,a6
%C%C%C*CFCLOS
*cfopen,%_wb_userfiles_dir(1)%nodedata.txt
/input,%_wb_userfiles_dir(1)%ndata.txt
*CFCLOS1 -
Hi @Mike Rife , Thanks for the solution. Another (almost similar) solution Chandra came up with is as shown below for reference.
para=400
para1='('
para2='f4.0)'
parac=strcat(para1,chrval(para))
parac=strcat(parac,para2)
*cfopen,d:\test.inp
*vwrite
*VREAD,data_read(1,1),CuIns(1),txt,,jik,col,row,1
*vwrite,parac
%c
*cfclose/sys, type d:\test.inp
1