我可以在openmdao的solve_非线性中更改参数值吗

我可以在openmdao的solve_非线性中更改参数值吗,openmdao,Openmdao,我可以在组件的解非线性函数中设置未知数和残差。我还可以设置参数的值吗?为什么 编辑 下面是我对纯python读写器组件的尝试。我的问题是我无法从顶层读取/写入参数 $ cat test.py from openmdao.api import Component, Group, Problem class reader(): def __init__(self): self.file_to_read = 'test.in' self.file_data = 0

我可以在组件的解非线性函数中设置未知数和残差。我还可以设置参数的值吗?为什么

编辑

下面是我对纯python读写器组件的尝试。我的问题是我无法从顶层读取/写入参数

$ cat test.py 
from openmdao.api import Component, Group, Problem

class reader():
   def __init__(self):
      self.file_to_read = 'test.in'
      self.file_data = 0
   def execute(self):
      dat = open(self.file_to_read, 'r')
      self.file_data = dat.read()

class writer():
   def  __init__(self):
      self.file_to_write = 'test.out'
      self.data = -99
   def execute(self):
      dat = open(self.file_to_write, 'w')
      dat.write(str(self.data))

class ReadWriteComp(Component):
   def __init__(self):
      super(ReadWriteComp, self).__init__()
      self.reader = reader()
      self.writer = writer()
      self.reader.execute()

   def solve_nonlinear(self, params, unknowns, resids):
      self.writer.data = self.reader.file_data
      self.writer.execute()

root = Group()
root.add('testio', ReadWriteComp())
prob = Problem(root)
prob.setup()
prob['testio.writer.file_to_write'] = 'newname' # "Variable 'testio.writer.file_to_write' not found."
prob.run()


$ cat test.in 
8

参数是组件的传入值。它们是外部提供的信息。因为这种外部性,你不能/不应该改变它们

另一种说法是:
如果有传入连接,则参数的值由该上游组件的输出源定义。更改参数就像更改上游组件的输出一样

我无法发表评论,因为我的代表级别太低,但这更多是对读/写组件的评论,而不是对问题的回答。我建议将读/写类和包装类设置为纯python,然后只在顶层使用openmdao,让一个组件同时执行这三个类,如果需要并行化案例,可能需要包装一个组。

Hmm我从未尝试过。我怀疑你这样做最终会破坏衍生信息。这听起来像是你在问一个关于解决更普遍问题的具体方法的问题。你到底想做什么?@robfalk我正在为模拟代码构建一个包装器,它是一个包含读、写和包装组件的组。我正在尽力模仿1.X中的vartrees。我的问题是,在这个vartree fst_vt对象中,未知数是参数:它们必须由读取器设置并由编写器使用。我的问题是我的未知数是参数。我希望一个组件读取模板文件并相应地设置参数,另一个组件使用这些参数编写输入文件。有很多参数,我想将其模块化,因为只有一组内容需要编辑才能添加到阅读/写作过程中…我更新我的问题以显示我的问题。我无法从顶层设置写入参数。我习惯于读取vartree的输出,并使用相同的vartree编写输出。看起来这不再是一个选项,需要一个更复杂的方案从顶层设置写入参数。testio实例的路径将是prob.root.testio.writer.file\u to\u write。我猜一些要写入的输入将取决于上游组件计算的输出,为此,我只需将这些作为参数显式添加到ReadWriteComp中。