无法为声明的输入执行整数

  • 本文关键字:执行 整数 声明 openmdao
  • 更新时间 :
  • 英文 :


我尝试用默认整数声明输入,但似乎不可能。我是在犯一个错误还是在OpenMDAO核心中实施了浮动。

这是我尝试过的代码片段;

预期输出类似:阵列([1,1,1])

收到的输出:[1。1. 1。]

from openmdao.api import ExplicitComponent,  Problem, IndepVarComp
import numpy as np
class CompAddWithArrayIndices(ExplicitComponent):
    """Component for tests for declaring with array val and array indices."""
    def setup(self):
        self.add_input('x_a', val=np.ones(6,dtype=int))
        self.add_input('x_b', val=[1]*5)
        self.add_output('y')
p = Problem(model=CompAddWithArrayIndices())
p.setup()
p.run_model()
print(p['x_a'])        
print(p['x_b'])   
#%%
from openmdao.api import ExplicitComponent,  Problem, IndepVarComp
import numpy as np
class CompAddWithArrayIndices(ExplicitComponent):
    """Component for tests for declaring with array val and array indices."""
    def setup(self):
        self.add_input('x_a', val=np.zeros(3,dtype=int))
        self.add_output('y')
prob = Problem()
ivc=IndepVarComp()
prob.model.add_subsystem('ivc', ivc,promotes=['*'])
ivc.add_output('x_a', val=np.ones(3,dtype=int))
prob.model.add_subsystem('comp1', CompAddWithArrayIndices(),promotes=['*'])
prob.setup()
prob.run_model()
print(prob['x_a'])

通过add_inputsadd_outputs添加的变量将转换为浮点或浮点数组。如果您希望变量是INT或任何其他离散类型,则必须使用add_discrete_inputadd_discrete_output。这些变量将根据连接信息在系统之间传递,但不会尝试计算其衍生产品。

在OpenMDAO v2.5中添加了离散变量支持作为实验特征(它仍在开发中)。在主分支机构上,在那里提交ID 709401E535CF693215ABD942D4B4D4B4D49D49DBF61B2B已解决促销问题已解决。

最新更新