How can I use user defined response from SimLab?
Hello,
I want to release the response about pressure drop using user defined response.
But I don't know how Python code works.
Maybe I think I should make a expression like difference between inlet total pressure and outlet total pressure.
I tried to search the method that I can refer, but I couldn't find it.
Answers
-
Hello GyeongJun Lee,
What you need is available in the SimLab help documentation. You can access it by pressing F1 while in SimLab. Go to the Automation section, then to Script Utilities, followed by Post Processing, and there you will find
getResponseValue
. There are many more options under Post Processing that you could use. Here’s an example: I wanted to extract solar radiation, but I couldn't directly get that value. So, I retrieved the heat flux response from the surface and then divided it by the surface area to obtain the desired value. Here’s my code:Here’s an example: I wanted to extract solar radiation, but I couldn't directly get that value. So, I retrieved the heat flux response from the surface and then divided it by the surface area to obtain the desired value. Here’s my code:
# Create a response with the same name string_value = simlab.getResponseValue("Heat_flux", "Flow") # Split string to get the numeric value numeric_value = string_value.split()[0] # Convert string to float and invert the sign heat_flux = -float(numeric_value) # Get the width parameter (assuming it's in mm and converting to meters) width = simlab.getDoubleParameter("$M1_width")/1000 # Calculate the area area = width * width # Calculate the irradiance irradiance = heat_flux / area # Return the calculated irradiance value return irradiance
Explanation:getResponseValue("Heat_flux", "Flow")
: This function retrieves the response value. You need to input the name of the response (e.g., "Heat_flux") and the name of the solution (e.g., "Flow"). The solution name appears when you create a solution in SimLab.- The retrieved value is a string, so we split it to isolate the numeric part.
- The numeric value is then converted to a float, and in this case, the sign is inverted.
- We obtain the width parameter from SimLab, assuming it’s in millimeters, and convert it to meters.
- The area is calculated based on the width, and then the irradiance is computed by dividing the heat flux by the area.
Additional Advice: I recommend that you first test your code in the Python console, which you can display by going to View and then selecting Python Console. There, you can gradually build and test your code before finally placing it in the User Defined Response. Also, make sure to save the code you create in User Defined Response in a text editor because, after saving, you won’t be able to view it again. This happened to me when I did it.
Hope this helps!
Best regards,
Jorge1 -
Jorge Mario Ceballos said:
Hello GyeongJun Lee,
What you need is available in the SimLab help documentation. You can access it by pressing F1 while in SimLab. Go to the Automation section, then to Script Utilities, followed by Post Processing, and there you will find
getResponseValue
. There are many more options under Post Processing that you could use. Here’s an example: I wanted to extract solar radiation, but I couldn't directly get that value. So, I retrieved the heat flux response from the surface and then divided it by the surface area to obtain the desired value. Here’s my code:Here’s an example: I wanted to extract solar radiation, but I couldn't directly get that value. So, I retrieved the heat flux response from the surface and then divided it by the surface area to obtain the desired value. Here’s my code:
# Create a response with the same name string_value = simlab.getResponseValue("Heat_flux", "Flow") # Split string to get the numeric value numeric_value = string_value.split()[0] # Convert string to float and invert the sign heat_flux = -float(numeric_value) # Get the width parameter (assuming it's in mm and converting to meters) width = simlab.getDoubleParameter("$M1_width")/1000 # Calculate the area area = width * width # Calculate the irradiance irradiance = heat_flux / area # Return the calculated irradiance value return irradiance
Explanation:getResponseValue("Heat_flux", "Flow")
: This function retrieves the response value. You need to input the name of the response (e.g., "Heat_flux") and the name of the solution (e.g., "Flow"). The solution name appears when you create a solution in SimLab.- The retrieved value is a string, so we split it to isolate the numeric part.
- The numeric value is then converted to a float, and in this case, the sign is inverted.
- We obtain the width parameter from SimLab, assuming it’s in millimeters, and convert it to meters.
- The area is calculated based on the width, and then the irradiance is computed by dividing the heat flux by the area.
Additional Advice: I recommend that you first test your code in the Python console, which you can display by going to View and then selecting Python Console. There, you can gradually build and test your code before finally placing it in the User Defined Response. Also, make sure to save the code you create in User Defined Response in a text editor because, after saving, you won’t be able to view it again. This happened to me when I did it.
Hope this helps!
Best regards,
JorgeHello,
Thanks for your advise.
I successfully make my own defined response because of the help documentations.
0