Closed echatziz closed 4 years ago
You can provide the updated py file here, or you can try to suggest a change by submitting a pull request to the code. It's actually not that hard to do and you might find it quite rewarding!
opto_thermal_steady-state_issue.txt volume_data.txt
The opto_thermal_steady-state_issue is the source code file, can't really copy a .py file here and the volume_data.txt the load file that is read.
I am not familiar with pull requests and can't even use github at its fullest, my institute's network settings are nightmarish. But if you could provide directions, I wouldn't mind trying.
But if you could provide a fix or tell me what's wrong with the issue I am having, I would really appreciate it
What exactly is the issue? Your script seems to work fine for me. What did you need to change, to make it work?
My problem is that it doesn't create the file element_temperatures.txt, namely the file with the stored temperatures in POST1. I was just playing around, frustrated that it wouldn't create the file, and at some point it worked just once. For the time it worked, it was saying at the console that some exception was ignored.
Didn't really change anything, just played with the line ansys.Run("(F8.4)"). I had this sort of issue before, that sth wouldn't work in my system, but it seemed to work elsewhere. In that case, it was some path included in " " instead of ' ' or the opposite
Ok, so this might be difficult to track. I had also some issues with getting data from ANSYS in the past, thats why I prefer to keep as much data as possible inside python. In your case you could try to use get_float() to read out your data in a Python list and save it to a file with python.
That would be great, I don't so much need to create a file, but store the temperature data in some array. I haven't figure how to store data from an ansys array to a python array.
So, with *vget I can get the values from POST1, but don't know how to store that in a python array. Can you suggest sth? How to use this get_float() you're talking about? There's sth wrong with the documentation page for some time now
I'm quite new to python and ansys myself (so maybe there is a more elegant way to do this). get_float is similar to the get() method, but without the first argument (the parameter used to store the value in ANSYS). Instead it returns this value (if it is possible to convert it to float). Have a look at #120. Also #146 might be interessting. So in your case I would store maxnode in python:
maxnode = ansys.get_float("NODE", 0, "NUM", "MAX")
and than use a python loop to fill your list with all the needed values.
for i in range(1, maxnode+1):
my_list.append(ansys.get_float(...))
Right now a similar functionality for vget() is not implemented, because I don't know how to use regular expressions to extract an array (might come in the future), so you are limited to get().
I get a message that 'ANSYS' object has no attribute 'get_float'. When did you have this included? What version of Pyansys?
What exactly are the arguments? How can I get element temperatures or node temperatures? For elements for example with apdl I would use sth like: VGET, temp_elem(1), ELEM, 1, ETAB, TEMP and for nodes VGET, temp_node(1), NODE, 1, TEMP
I am more interested in elements than nodes to be honest
I think it was added in 0.39.1
From ANSYS doc: *GET, Par, Entity, ENTNUM, Item1, IT1NUM, Item2, IT2NUM Retrieves a value and stores it as a scalar parameter or part of an array parameter.
ansys.get_float() has the same arguments (and internally calls *get) beside Par, which is omitted. As I mentioned, I'm no expert in ANSYS, but I guess it should look like:
for i in range(1, maxnode+1):
my_list1.append(ansys.get_float("NODE", i, "TEMP"))
for i in range(1, maxelement+1):
my_list2.append(ansys.get_float("ELEM", i, "ETAB", "TEMP"))
It doesn't work for me. The code is as shown below. For the maximum number of elements and nodes it works, but for the temperature it doesn't. I also did it with the python list as you suggest, that's not the issue here
ansys.Run("/POST1")
maxnode = ansys.get_float("NODE", 0, "NUM", "MAX")
print("The no of nodes", maxnode)
maxelem = int(ansys.get_float("ELEM", 0, "NUM", "MAX"))
print("The no of elements", maxelem)
temp_elem = np.zeros(maxelem)
for i in range(maxelem):
temp_elem[i] = ansys.get_float("ELEM", i+1, "ETAB", "TEMP")
print("The temperatures per element: ", temp_elem)
Btw I tried to save nodal temperatures and for that it worked, but I'd really prefer to use element as well. In that case I also noticed an issue I had in the past, the ansys commands run before the precedent "pure" python commands are finished. Eg. in the following code
ansys.Run("/POST1")
maxnode = int(ansys.get_float("NODE", 0, "NUM", "MAX"))
print("The no of nodes", maxnode)
maxelem = int(ansys.get_float("ELEM", 0, "NUM", "MAX"))
print("The no of elements", maxelem)
start_time = time.time()
temp_nodes = np.zeros(maxnode)
for i in range(maxnode):
temp_nodes[i] = ansys.get_float("NODE", i+1, "TEMP")
np.savetxt('temperatures.txt', temp_nodes)
elapsed_time = time.time() - start_time
print("The elapsed time is: ", elapsed_time)
ansys.Run("/GFILE, 2400")
ansys.View(1, 1, 1, 1)
ansys.Run("/EDGE,,1")
ansys.Run("PLNSOL,TEMP")
ansys.Run("FINISH")
for some reason the temperature profile with ansys.Run("PLNSOL,TEMP") is created before the loop is finished and the elapse time is printed. Last time I was told it wasn't a pyansys issue, but I guess there is a timer somewhere and if sth takes too long the next line is executed without waiting for the previous one to finish
for some reason the temperature profile with ansys.Run("PLNSOL,TEMP") is created before the loop is finished and the elapse time is printed. Last time I was told it wasn't a pyansys issue, but I guess there is a timer somewhere and if sth takes too long the next line is executed without waiting for the previous one to finish
I think thats more about print() - see https://stackoverflow.com/questions/107705/disable-output-buffering About the elements, I guess thats not an issue with pyansys, but more an issue with an incorrect ansys command. Can you try to open ANSYS and test the *get command there to get temperature for one element? What error is shown? If there is no error, its also possible that the loop range is wrong.
Btw. for me your initial aproach with
*VGET, temp_elem(1), ELEM, 1, ETAB, TEMP
is also not working, with the same error message in ansys (LABEL TEMP not recognized).
for some reason the temperature profile with ansys.Run("PLNSOL,TEMP") is created before the loop is finished and the elapse time is printed. Last time I was told it wasn't a pyansys issue, but I guess there is a timer somewhere and if sth takes too long the next line is executed without waiting for the previous one to finish
I think thats more about print() - see https://stackoverflow.com/questions/107705/disable-output-buffering About the elements, I guess thats not an issue with pyansys, but more an issue with an incorrect ansys command. Can you try to open ANSYS and test the *get command there to get temperature for one element? What error is shown? If there is no error, its also possible that the loop range is wrong.
In the case I am referring to there wasn't a print command, just some do loop in the solution processor with the ansys.non_interactive tag. It wouldn't wait for the loop to finish and entered the pre-processor before, so I wasn't getting any results.
I'll try the *get command in ansys, thank you for the suggestion
Ok, I figured out what was wrong. Been reading the ansys manual wrong. I had to define the ETABLE with the property I wanted first and then just refer to it
ansys.Etable("etemp", "TEMP")
temp_elem = np.zeros(maxelem)
for i in range(maxelem):
temp_elem[i] = ansys.get_float("ELEM", i+1, "ETAB", "etemp")
The ansys.non_interactive version doesn't work in either case
Closing this issue as it seems solved.
After running my simulation I want to export a file with temperatures. I've tried this a couple of times, without changing the source code, just some minor change in vwrite options, and it worked only once when some exception was ignored.
The variable maxnode, the maximum no of nodes in the mesh, I've defined in the pre-processor.
What can I do to resolve this problem? I can provide the .py file if it helps.
Thank you