コード例 #1
0
    f.write('X2=@X2\n')
with open('external_program.py', 'w') as f:
    f.write('import sys\n')
    f.write('exec(open(sys.argv[1]).read())\n')
    f.write('Y0=X0+X1+X2\n')
    f.write('Y1=X0+X1*X2\n')
    f.write('with open("output.txt", "w") as f:\n')
    f.write('    f.write("Y0=%.17e\\n" % Y0)\n')
    f.write('    f.write("Y1=%.17e\\n" % Y1)\n')

input_file = persalys.CouplingInputFile('input_template.txt')
input_file.setConfiguredPath('input.txt')
input_file.setVariables(['X0', 'X1', 'X2'], ['@X0', '@X1', '@X2'],
                        ['{:10.6f}', '{:10.6f}', '{:10.6f}'])
resource_file = persalys.CouplingResourceFile('external_program.py')
output_file = persalys.CouplingOutputFile('output.txt')
output_file.setVariables(['Y0', 'Y1'], ['Y0=', 'Y1='], [0, 0], [0, 0], [0, 0])
step = persalys.CouplingStep(sys.executable + ' external_program.py input.txt',
                             [input_file], [resource_file], [output_file])
model = persalys.CouplingPhysicalModel('A', [step])

# single evaluation
x = [1.0, 2.0, 3.0]
f = model.getFunction()
y = f(x)
print(y)
ott.assert_almost_equal(y, [6.0, 7.0])

# sampling test
ot_function = model.getFunction()
Y = ot.CompositeRandomVector(ot_function, ot.RandomVector(ot.Normal(3)))
コード例 #2
0
    f.write('X2=@X2\n')
with open('external_program0y.py', 'w') as f:
    f.write('import sys\n')
    f.write('exec(open("input.txt").read())\n')
    f.write('Y0=X0+X1+X2\n')
    f.write('Y1=X0+X1*X2\n')
    f.write('with open("output.txt", "w") as f:\n')
    f.write('    f.write("Y0=%.17e\\n" % Y0)\n')
    f.write('    f.write("Y1=%.17e\\n" % Y1)\n')

input_file = persalys.CouplingInputFile('input_template0y.txt')
input_file.setConfiguredPath('input.txt')
input_file.setVariables(['X0', 'X1', 'X2'], ['@X0', '@X1', '@X2'],
                        ['', '', ''])
resource_file = persalys.CouplingResourceFile('external_program0y.py')
output_file = persalys.CouplingOutputFile('output.txt')
output_file.setVariables(['Y0', 'Y1'], ['Y0=', 'Y1='], [0, 0], [0, 0], [0, 0])
step = persalys.CouplingStep(sys.executable + ' external_program0y.py',
                             [input_file], [resource_file], [output_file])
model = persalys.YACSCouplingPhysicalModel('A', [step])

# single evaluation
x = [1.0, 2.0, 3.0]
f = model.getFunction()
y = f(x)
print(y)
ott.assert_almost_equal(y, [6.0, 7.0])

# sampling test
ot_function = model.getFunction()
Y = ot.CompositeRandomVector(ot_function, ot.RandomVector(ot.Normal(3)))
コード例 #3
0
inputs = [E, F, I, L]
outputs = [deviation]
steps = []
input_files = []
input_file0 = persalys.CouplingInputFile(
    '../python/test/coupling_model/beam_input_template.xml')
input_file0.setConfiguredPath('beam_input.xml')
input_file0.setVariables(['E', 'F', 'I', 'L'], ['@E', '@F', '@I', '@L'],
                         ['{}', '{}', '{}', '{}'])
input_files.append(input_file0)
resource_files = []
resource_file0 = persalys.CouplingResourceFile(
    '../python/test/coupling_model/beam.py')
resource_files.append(resource_file0)
output_files = []
output_file0 = persalys.CouplingOutputFile('beam_output.txt')
output_file0.setVariables(['deviation'], ['deviation='], [0], [0], [0])
output_files.append(output_file0)
step0 = persalys.CouplingStep('python3 beam.py', input_files, resource_files,
                              output_files)
step0.setIsShell(False)
steps.append(step0)
couplingModel = persalys.CouplingPhysicalModel('couplingModel', inputs,
                                               outputs, steps)
couplingModel.setCleanupWorkDirectory(True)
couplingModel.setCacheFiles('', '')
myStudy.add(couplingModel)
filename = 'data.csv'
cDist = ot.ComposedDistribution(
    [ot.Normal(), ot.Gumbel(),
     ot.Normal(), ot.Uniform()],