Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Kenneth-T-Moore/1ef89a0a6ad3fa3d5cf1382284d73a7c to your computer and use it in GitHub Desktop.
Save Kenneth-T-Moore/1ef89a0a6ad3fa3d5cf1382284d73a7c to your computer and use it in GitHub Desktop.
import numpy as np
import openmdao.api as om
from openmdao.components.interp_util.interp_semi import InterpNDSemi
grid = np.array([
[1.0, 5.0, 8.0],
[1.0, 5.0, 9.0],
[1.0, 5.0, 10.0],
[1.0, 5.0, 20.0],
[1.0, 5.3, 8.0],
[1.0, 5.3, 9.0],
[1.0, 5.3, 10.0],
[1.0, 5.3, 20.0],
[1.0, 5.6, 8.0],
[1.0, 5.6, 9.0],
[1.0, 5.6, 10.0],
[1.0, 5.6, 20.0],
[1.0, 6.0, 8.0],
[1.0, 6.0, 9.0],
[1.0, 6.0, 10.0],
[1.0, 6.0, 20.0],
[2.0, 7.0, 13.0],
[2.0, 7.0, 14.0],
[2.0, 7.0, 15.0],
[2.0, 7.0, 16.0],
[2.0, 8.0, 13.0],
[2.0, 8.0, 14.0],
[2.0, 8.0, 15.0],
[2.0, 8.0, 16.0],
[2.0, 8.5, 13.0],
[2.0, 8.5, 14.0],
[2.0, 8.5, 15.0],
[2.0, 8.5, 16.0],
[2.0, 9.0, 13.0],
[2.0, 9.0, 14.0],
[2.0, 9.0, 15.0],
[2.0, 9.0, 16.0],
])
values = 15.0 + 2 * np.random.random(32)
prob = om.Problem()
model = prob.model
interp = om.MetaModelSemiStructuredComp(vec_size=3, training_data_gradients=True)
interp.add_input('x')
interp.add_input('y')
interp.add_input('z')
interp.add_output('f', grid_points=grid, training_data=values)
model.add_subsystem('interp', interp)
prob.setup(force_alloc_complex=True)
prob.set_val('interp.x', np.array([1.1, 1.5, 1.9]))
prob.set_val('interp.y', np.array([5.1, 6.5, 8.75]))
prob.set_val('interp.z', np.array([18.5, 11.0, 15.1]))
prob.run_model()
print(prob.get_val('interp.f'))
print('done')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment