zhuminjie / OpenSeesPy

OpenSeesPy versions, doc, and pip
Other
173 stars 66 forks source link

Closing Recorders #52

Closed bariserkus closed 4 years ago

bariserkus commented 4 years ago

Hello,

I am using a recorder for a basic analysis. Unfortunately, the output file is not fully closed by the interpreter (Spyder and Jupyter). This leaves the text file incomplete even if the run is complete. The file is fully written by the interpreter when I close the interpreter or record the data to a different file in a new run.

My question is how do we close the recorders?

mhscott commented 4 years ago

Try putting ops.wipe() at the end of your analysis.

bariserkus commented 4 years ago

Try putting ops.wipe() at the end of your analysis.

This will erase everything, no?

bariserkus commented 4 years ago

Try putting ops.wipe() at the end of your analysis.

Didn't work. :(

mhscott commented 4 years ago

You can try ops.record()

Otherwise, you'll have to give a lot more details on what you're doing in your analysis.

bariserkus commented 4 years ago

Thanks for the reply!

Correction: op.wipe() worked; op.record() did not work

However, op.wipe() clears up all the information afaik, and I wouldn't want to do that. Is there a way to close only the output file of the recorder or make Python spit all the data to the output file without closing the output file?

A MWE is attached. Please save it as .py file.

mwe.txt

The code is as follows:

from openseespy import opensees as op

op.wipe()

op.model("basic", "-ndm", 1, "-ndf", 1)

op.node(1, 0.0)
op.node(2, 0.0)
op.fix(1, 1)

op.uniaxialMaterial("Elastic", 1, 1)
op.element("zeroLength", 1, 1, 2, "-mat", 1, '-dir', 1)

op.recorder("Node", "-file", "nodec.out", "timeSeries", 1, "-time", "-node", 2, "-dof", 1, "disp")

op.timeSeries("Linear", 1)
op.pattern("Plain", 1, 1)
op.load(2, 1)

op.system("BandGeneral")
op.numberer("Plain")
op.constraints("Plain")
op.test("NormUnbalance", 1.0e-6, 6)
op.integrator("LoadControl", 0.1)
op.algorithm("Linear")
op.analysis("Static")
op.analyze(5)
op.loadConst('-time', 0.0)

op.pattern("Plain", 2, 1)
op.load(2, 1.0)

op.integrator("DisplacementControl", 2, 1, 0.02)
op.analyze(800)

If I run this script on Spyder (or Jupyter), the node.out file does not appear to be complete output. The output in this case ends with:

...
15.76 16.26
15.78 16.28
15.8 16.3
15.82 16.32
15.84 16.34

which should be

...
15.76 16.26
15.78 16.28
15.8 16.3
15.82 16.32
15.84 16.34
15.86 16.36
15.88 16.38
15.9 16.4
15.92 16.42
15.94 16.44
15.96 16.46
15.98 16.48
16 16.5

This is an issue I have faced with regular Python codes as well. For those, I close the file within the script and that solves the problem. Maybe this specific issue is related to Python?

tcl/tkl OPS mentions about a return handler of the recorder. I tried to get that handler by

tgFile = op.recorder(...)

Then try or use smtg like

op.close(tgFile)

but did not work. The handler was neither an integer nor a defined type.

u-anurag commented 4 years ago

add op.wipe() at the end of the analysis. This will close all the recorders.

bariserkus commented 4 years ago

@u-anurag Thanks for the reply! As I have mentioned in my response, I would not prefer to use wipe() since it will delete all the information in the workspace.

The way I may use the operation of closing a recorder is about using the output file for plotting during the run or for using it along with an external tool such as LaTeX. so I do not want to wipe the workspace.

@zhuminjie @u-anurag Is there a way to get the handler of the recorder so that I can close it?

As I have mentioned in my response, the return value of the op.recorder() function is not a number. The tcl OpenSees help says (at this link):

RETURNS >0 an integer tag that can be used as a handle on the recorder for the remove recorder commmand.

I have checked tcl OPS, and I can get the integer handle and remove the recorder successfully using the remove command. So, is this a bug of OpenSeesPy? I could not look into the code of OpenSeesPy as it uses a .dll file for the opensees class.

Help is appreciated.

zhuminjie commented 4 years ago

First, you can look at OpenSeesPy source codes which are part of the OpenSees respository. There is no such thing called .dll for opensees class. I am curious what is the opensees class.

Yes, currently the op.recorder is not returning a number. I can make that happen. Even without that, there are at least two ways to get around: 1. you can remove all recorders; 2. use the '-closeOnWrite' option for the recorder.

bariserkus commented 4 years ago

First, you can look at OpenSeesPy source codes which are part of the OpenSees respository. There is no such thing called .dll for opensees class. I am curious what is the opensees class.

I mean the opensees.pyd located under the C:\Anaconda3\Lib\site-packages\openseespy\opensees\win . I am using Win10-64 and Anaconda. I thought that you are compiling the OpenSees into a DLL (pyd for Python), and Pyhton calls from this pyd file. Maybe I should have said opensees module, instead of class? Sorry, I am not much familiar how the pyd file is generated.

I am guessing that you are using some sort of a Python wrapper around the DLL, and the source code of all these is not made available under this repo?

So, may I kindly ask if you can make the integer handler (the remove command for that handler) of the recorder available for the next release?

In the mean time,

  1. op.remove('recorders') worked. Thanks!
  2. -closeOnWrite also worked. Thanks!

For now, these solves my problem.

zhuminjie commented 4 years ago

The opensees.pyd is for your convenience. All OpenSeesPy source codes are in the OpenSees repository. There is nothing hidden. You can compile everything yourself. The OpenSeesPy is a native Python module not a wrapper.

Yes, I will add the return number in the next release.

bariserkus commented 4 years ago

This is great! I saw the PythonWrapper.cpp now, which is available under the upstream repo tcl OPS that you subtreed from. I was thinking that only OpenSeesPy had the Python bits till now and never thought of looking into the original OpenSees repo for the Pyhon code. So, it is just compiling the VS solution of OpenSees then (I am a Win user)? I will look into this. Many Thanks!

zhuminjie commented 4 years ago

It's the OpenSeesPy project in the VS solution. The subtree is a copy of the main repo.