def test_CADRE(self): n, m, h, setd = load_validation_data(idx='0') prob = Problem(CADRE(n=n, m=m)) prob.setup(check=verbose) input_data = [ 'CP_P_comm', 'LD', 'cellInstd', 'CP_gamma', 'finAngle', 'lon', 'CP_Isetpt', 'antAngle', 't', 'r_e2b_I0', 'lat', 'alt', 'iSOC' ] for inp in input_data: prob[inp] = setd[inp] prob.run_driver() if verbose: inputs = prob.model.list_inputs() outputs = prob.model.list_outputs() else: inputs = prob.model.list_inputs(out_stream=None) outputs = prob.model.list_outputs(out_stream=None) good = [] fail = [] for varpath, meta in inputs + outputs: var = varpath.split('.')[-1] if var in setd: actual = setd[var] computed = prob[var] if isinstance(computed, np.ndarray): rel = np.linalg.norm(actual - computed) / np.linalg.norm(actual) else: rel = np.abs(actual - computed) / np.abs(actual) if np.mean(actual) > 1e-3 or np.mean(computed) > 1e-3: if rel > 1e-3: fail.append(varpath) if verbose: print(varpath, 'failed:\n', computed, '\n---\n', actual, '\n') else: good.append(varpath) if verbose: print(varpath, 'is good.') elif verbose: print(var, 'not in data.') fails = len(fail) total = fails + len(good) self.assertEqual( fails, 0, '%d (of %d) mismatches with validation data:\n%s' % (fails, total, '\n'.join(sorted(fail))))
import unittest import numpy as np from openmdao.api import Problem from openmdao.utils.assert_utils import assert_check_partials from CADRE.rw_dymos.rw_group import ReactionWheelGroup from CADRE.rw_dymos.rw_motor import ReactionWheelMotorComp from CADRE.rw_dymos.rw_power import ReactionWheelPowerComp from CADRE.test.util import load_validation_data # # load saved data from John's CMF implementation. # n, m, h, setd = load_validation_data(idx='5') class TestReactionWheel(unittest.TestCase): def test_ReactionWheelMotorComp(self): prob = Problem() comp = prob.model.add_subsystem('comp', ReactionWheelMotorComp(num_nodes=1500), promotes=['*']) prob.setup() prob['T_RW'] = setd['T_RW'].T prob['w_B'] = setd['w_B'].T prob['w_RW'] = setd['w_RW'].T
""" Time CADRE's execution and derivative calculations. """ from __future__ import print_function import time from openmdao.api import Problem from CADRE.CADRE_group import CADRE from CADRE.test.util import load_validation_data n, m, h, setd = load_validation_data(idx='0') # instantiate Problem with CADRE model t0 = time.time() model = CADRE(n=n, m=m) prob = Problem(model) print("Instantiation: ", time.time() - t0, 's') # do problem setup t0 = time.time() prob.setup(check=False) print("Problem Setup: ", time.time() - t0, 's') # set initial values from validation data input_data = [ 'CP_P_comm', 'LD', 'cellInstd',