我试图从FMU中得到模型Jacobian矩阵,根据下面的文献,我可以使用fmi2GetDirectionalDerivative来完成这个任务,但是我不确定我需要做什么。
我的问题是:
,
,
https://ep.liu.se/ecp/132/091/ecp17132831.pdf

发布于 2020-09-17 16:21:55
我不熟悉在MATLAB中调用DLL函数,但这是Python中的一个例子。FMPy (https://github.com/CATIA-Systems/FMPy)有这些包装器,用于在python中运行FMU。
我在这里编写了一个简单的模型(How to access model jacobian from FMU or Dymola without analytical jacobian),对此进行了测试。在这种情况下,已知是状态或输入的值引用,未知数是导数或输出的值引用。
我已经成功地提取雅可比时,通过Dymola作为模型交换FMU,但没有共同模拟FMU出口。
def get_jacobian(fmu, vr_knowns, vr_unknowns):
"""
populates jacobian from list of knowns and unknowns
can be only called after the current sim time and inputs are set
"""
jacobian = []
try:
for vr_known in vr_knowns:
for vr_unknown in vr_unknowns:
jacobian.extend(
fmu.getDirectionalDerivative(
vUnknown_ref=[vr_unknown],
vKnown_ref=[vr_known],
dvKnown=[1.0]
))
print_status(f'Jacobian Elements: {jacobian}')
except Exception as e:
print("[ERROR] cannot compute jacobian at current timestep")
print(f"[ERROR] {e}")我使用这个代码片段来使用FMPy收集状态和导数的值引用:
# get FMU model description object
model_description = fmpy.read_model_description(
os.path.join(fmu_path, fmu_filename)
)
# collect the value references
vrs = {}
for variable in model_description.modelVariables:
vrs[variable.name] = variable.valueReference
# collect list of states and derivatives
states = []
derivatives = []
for derivative in model_description.derivatives:
derivatives.append(derivative.variable.name)
states.append(re.findall('^der\((.*)\)$',derivative.variable.name)[0])
# collect the value references for states and derivatives
vr_states = [vrs[x] for x in states]
vr_derivatives = [vrs[x] for x in derivatives]发布于 2020-10-02 08:47:05
三菱电气在最近举行的2020年不结盟运动Modelica会议上发表了一篇可能与此相关的论文。
https://stackoverflow.com/questions/63924021
复制相似问题