Dear Massimo,
yes, you are correct. I am trying to plot the envelope of the maximum (and minimum) accelerations in time for each node. I would like to see a colour map like the Surface Color map but of course without time steps, only the maximum (and minimum)value for each node.
I have corrected the error and now the code seem to work until the point when I print "DONE". In total I have 6502 nodes but here I just put 30 nodes to speed up the calculation. Also, I have 8190 time steps but I am just plotting between 1555 and 1600 also to save time (it takes the strongest part of the accelerogram).
Here is the section of the code that works:
Code: Select all
from PyMpc import *
from PyMpc import MpcOdbVirtualResult as vr
from time import sleep
import traceback
import numpy as np
from PySide2.QtCore import Qt, QObject, Signal, Slot, QThread, QEventLoop
from PySide2.QtWidgets import QDialog, QLabel, QProgressBar, QVBoxLayout, QApplication, QInputDialog
from numpy import genfromtxt
from numpy import argwhere
from numpy import sqrt
App.clearTerminal()
# get document
doc = App.postDocument()
# get first database
if len(doc.databases) == 0:
raise Exception("You need a database with ID = 1 for this test")
db = doc.getDatabase(1)
# create evaluation options
# here we want to extract data for all steps of the last stage
all_stages = db.getStageIDs()
last_stage = all_stages[-1]
all_steps = db.getStepIDs(last_stage)
opt = MpcOdbVirtualResultEvaluationOptions()
opt.stage = last_stage
# for updating every n steps
num_steps = len(all_steps)
# initialization results
ACCELERATIONS_ENV_P = [];
# The worker class. It will run the lengthy function on a working thread
# and emit signals for calling the connected slots on the main thread
# Accelerations
acc = db.getNodalResult("Acceleration", match=MpcOdb.Contains)
class Worker(QObject):
# signals
finished = Signal()
# lengthy function
@Slot()
def run(self):
try:
# forloop for all the nodes in the database
for j in range(30): # Total number of nodes is 6502 but to save time I want to try with 30 nodes first.
print(j+1)
tmp = [];
for i in range(1555, 1600, 1): #Total length = 8190, just taking the strongest part of signal.
opt.step = all_steps[i];
field = acc.evaluate(opt);
row = MpcOdbResultField.node(j+1) # the node field object is the row identifier in the result field
col = 0 # 0 = Ax, 1 = Ay, 2 = Az (the column 0-based index, depends on the result)
AX = field[row, col];
tmp.append(AX);
AX = 0;
ACCELERATIONS_ENV_P.append(max(tmp));
except Exception:
IO.write_cerr(traceback.format_exc())
finally:
self.finished.emit()
# create an event loop that will block the script till the end
loop = QEventLoop()
# create the thread, the worker, and move the worker to the thread
thread = QThread()
worker = Worker()
worker.moveToThread(thread)
# set up worker and thread connections
worker.finished.connect(thread.quit)
worker.finished.connect(worker.deleteLater)
thread.started.connect(worker.run)
thread.finished.connect(thread.deleteLater)
thread.finished.connect(loop.quit)
# start the thread
thread.start()
# run event loop
loop.exec_()
print("DONE")
Now what I am not able to do is to load the results on the editor. I know it should be something like this:
Code: Select all
D1 = db.getNodalResult("Acceleration", match=MpcOdb.Contains)
D1 = D1 + ACCELERATIONS_ENV_P;
D1.setDisplayName("Envelope Max")
D1.setComponentLabels(["Envelope Max"])
db.addVirtualResult(D1)
But I get this error :
Cannot add the virtual results due to the following errors:
("Acceleration" + [0.0954871, 0.0484654, 0.0484654, 0.0954871, 0.0463059, 0.0463059, 0.0242182, 0.0242182, 0.0954288, 0.0951113, 0.094517, 0.0936013, 0.0923038, 0.0905579, 0.0883062, 0.0855173, 0.082202, 0.0784229, 0.0742939, 0.0699697, 0.0656259, 0.0614355, 0.0575467, 0.0540648, 0.0510415, 0.0486235, 0.0487237, 0.048782, 0.0488044, 0.0487954]) -
Operands have different size (2 - 30)
I understand why I get this error but I don't know how to use
db.addVirtualResult correctly to load the results in the STKO post-processor.
Thank you very much