def generate_output_xml(self): root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_y1, 0.) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file='LC-output-loc.xml'): """Computes the maximum stresses across all load cases.""" doc_in = etree.parse(in_file) sigmas = 4 * [np.ndarray((0, ))] for i in range(1, LoadCaseSpecific.get_n_loadcases(doc_in) + 1): for j in range(4): data = np.array(doc_in.xpath(x_sigmas_in[j] % i)[0].text.split(';'), dtype=float) if i == 1: sigmas[j] = data else: sigmas[j] = np.maximum(sigmas[j], data) # Write results to output XML file root = etree.Element('cpacs') doc_out = etree.ElementTree(root) for i in range(4): xml_safe_create_element(doc_out, x_sigmas_out[i], sigmas[i]) doc_out.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def write_input_file(self, file, inputs, discrete_inputs=None): # type: (Union[str, etree._ElementTree], Vector, Optional[dict]) -> None """Write the current input values to an input XML file. Parameters ---------- file : str or :obj:`etree._ElementTree` Path to or :obj:`etree._ElementTree` of an input XML file. inputs : Vector Input vector of this `Component`. discrete_inputs : dict Discrete (i.e. not treated as floats) inputs. """ # Create new root element and an ElementTree root = etree.Element( param_to_xpath(list(self.inputs_from_xml)[0]).split('/')[1]) doc = etree.ElementTree(root) # Convert all XML param names to XPaths and add new elements to the tree correspondingly for param in self.inputs_from_xml: if param in inputs: xml_safe_create_element(doc, param_to_xpath(param), inputs[param]) elif param in discrete_inputs: xml_safe_create_element(doc, param_to_xpath(param), discrete_inputs[param]) # Write the tree to an XML file doc.write(file, pretty_print=True, xml_declaration=True, encoding='utf-8')
def execute(in_file, out_file): """Call the Matlab function dAEDalusSteadyAerodynamicAnalysis() and store the resulting value of C_D_i and a link to the aerodynamic forces for each load case. """ doc_in = etree.parse(in_file) root = etree.Element('cpacs') doc_out = etree.ElementTree(root) n_lc = LoadCaseSpecific.get_n_loadcases(doc_in) futures = n_lc * [None] for i in range(1, n_lc + 1): engine_id = int(float(doc_in.xpath(x_ml_id % i)[0].text)) if engine_id not in _mles: break else: grid = 3 * [None] s = 0. for j in range(3): g = np.array(doc_in.xpath(x_grid[j] % i)[0].text.split(';'), dtype=float).tolist() s += np.sum(np.square(g)) grid[j] = g if s == 0: for j in range(3): grid[j] = np.array(doc_in.xpath(x_grid_initial[j] % i)[0].text.split(';'), dtype=float).tolist() C_L = float(doc_in.xpath(x_CL % i)[0].text) futures[ i - 1] = _mles[engine_id].dAEDalusSteadyAerodynamicAnalysis( matlab.double(grid), float(C_L), nargout=1, async=True) for j in range(3): xml_safe_create_element(doc_out, x_grid_guess[j] % i, np.array(grid[j])) for i, future in enumerate(futures): if future is None: break else: try: C_D_i = future.result() xml_safe_create_element(doc_out, x_CDi % (i + 1), C_D_i) except MatlabExecutionError: break doc_out.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_output_xml(self): # type: () -> str root = etree.Element('cpacs') doc = etree.ElementTree(root) xml_safe_create_element(doc, x_CD, 0) xml_safe_create_element(doc, x_LD, 0) xml_safe_create_element(doc, x_fwe_CL, 0) xml_safe_create_element(doc, x_m_fuel, 0) xml_safe_create_element(doc, x_m_mtow, 0) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc = etree.parse(in_file) z1 = float(doc.xpath(x_z1)[0].text) z2 = float(doc.xpath(x_z2)[0].text) y1 = float(doc.xpath(x_y1)[0].text) y2 = abs(y1)**.5 + z1 + z2 root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_y2, y2) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc = etree.parse(in_file) y2 = float(doc.xpath(x_y2)[0].text) g2 = y2 / 24. - 1. root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_g2, g2) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc = etree.parse(in_file) x0 = float(doc.xpath(x_x0)[0].text) x1 = x0 root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_x1, x1) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc = etree.parse(in_file) y1 = float(doc.xpath(x_y1)[0].text) g1 = 1. - y1 / 3.16 root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_g1, g1) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): """Call the Matlab function dAEDalusSteadyStructuralAnalysis() and store the resulting values of the stresses (sigma_*) and the deflected grid in the corresponding unknowns. """ doc_in = etree.parse(in_file) root = etree.Element('cpacs') doc_out = etree.ElementTree(root) n_lc = LoadCaseSpecific.get_n_loadcases(doc_in) futures = n_lc * [None] for i in range(1, n_lc + 1): engine_id = int(float(doc_in.xpath(x_ml_id % i)[0].text)) if engine_id not in _mles: break else: futures[i - 1] = _mles[engine_id].dAEDalusSteadyStructuralAnalysis( nargout=5, async=True) for i, future in enumerate(futures): if future is None: break else: try: sigma_fs, sigma_rs, sigma_ts, sigma_bs, deflected_grid = future.result( ) sigmas = [ np.array(sigma_fs), np.array(sigma_rs), np.array(sigma_ts), np.array(sigma_bs) ] deflected_grid = np.array(deflected_grid) for j in range(4): xml_safe_create_element(doc_out, x_sigmas_in[j] % (i + 1), sigmas[j]) for j in range(3): xml_safe_create_element(doc_out, x_grid[j] % (i + 1), deflected_grid[j]) except MatlabExecutionError: break doc_out.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_input_xml(self): # type: () -> str """Input is a CPACS file with the lift coefficient and deflected grid of the wing for each load case, as well as links to the geometric and aerodynamic models. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_CL % i, 0.) xml_safe_create_element(doc, x_ml_id % i, 0) for j in range(3): xml_safe_create_element( doc, x_grid_initial[j] % i, np.zeros(2 * (n_seg_x + 1) * (n_seg_y + 1) * self.n_wing_segments)) xml_safe_create_element( doc, x_grid[j] % i, np.zeros(2 * (n_seg_x + 1) * (n_seg_y + 1) * self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc = etree.parse(in_file) c = float(doc.xpath(x_c)[0].text) z1 = float(doc.xpath(x_z1)[0].text) z2 = float(doc.xpath(x_z2)[0].text) x1 = float(doc.xpath(x_x1)[0].text) y2 = float(doc.xpath(x_y2)[0].text) y1 = c*(z1**2. + x1 + z2 - .2*y2) root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_y1, y1) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_output_xml(self): # type: () -> str """Output is a CPACS file containing a predefined number of load cases. Each load case will be assigned pseudo-variables allowing for subsequent disciplines to connect to this discipline (geometric and structural model), as well as the name of the shared Matlab engine and its timestamp of creation. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) xml_safe_create_element(doc, x_m_wing, 0.) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_ml_id % i, 0) xml_safe_create_element(doc, x_ml_timestamp % i, 0.) for j in range(3): xml_safe_create_element( doc, x_grid_initial[j] % i, np.zeros(2 * (n_seg_x + 1) * (n_seg_y + 1) * self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def run(input_xml_file, output_xml_file): # Load input file tree = etree.parse(input_xml_file) root = tree.getroot() # Load input parameters for this discipline y1 = float(root.find('./analyses/y1').text) # "Run" the discipline calculations g1 = (y1 / 3.16) - 1. # Write the output xml_safe_create_element(tree, '/dataSchema/output/g1', str(g1)) tree.write(output_xml_file)
def generate_input_xml(self): # type: () -> str """Input is a CPACS file with the name of the Matlab shared engine and links to the geometric model, aerodynamic model and aerodynamic forces for each load case. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_ml_id % i, 0) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def run(input_xml_file, output_xml_file): # Load input file tree = etree.parse(input_xml_file) root = tree.getroot() # Load input parameters for this discipline y2 = float(root.find('./analyses/y2').text) # "Run" the discipline calculations g2 = 1. - (y2 / 24.) # Write the output xml_safe_create_element(tree, '/dataSchema/output/g2', str(g2)) tree.write(output_xml_file)
def execute(in_file, out_file): doc = etree.parse(in_file) z2 = float(doc.xpath(x_z2)[0].text) x1 = float(doc.xpath(x_x1)[0].text) y1 = float(doc.xpath(x_y1)[0].text) y2 = float(doc.xpath(x_y2)[0].text) f1 = x1**2. + z2 + y1 + exp(-y2) root = etree.Element(root_tag) doc = etree.ElementTree(root) xml_safe_create_element(doc, x_f1, f1) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_output_xml(self): # type: () -> str """Output is a CPACS file containing the lift- and friction drag coefficient for each load case, as well as a link to the aerodynamic model. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_CL % i, 0.) xml_safe_create_element(doc, x_CDf % i, 0.) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_output_xml(self): # type: () -> str """Output is a CPACS file containing the maximum stresses in the front/rear spars and in the top/bottom skins across all load cases. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for x_sigma in x_sigmas_out: xml_safe_create_element(doc, x_sigma, np.zeros(self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file='FWE-output-loc.xml'): # Obtain data from XML file tree = etree.parse(in_file) M = H = C_D_f = C_D_i = C_L = 0 for i in range(1, LoadCaseSpecific.get_n_loadcases(tree) + 1): M = float(tree.xpath(x_M % i)[0].text) # Mach number, [-] H = float(tree.xpath(x_H % i)[0].text) # Altitude, [m] C_D_f = float(tree.xpath(x_CDf % i)[0].text) # Friction drag coefficient, [-] C_D_i = float(tree.xpath(x_CDi % i)[0].text) # Induced drag coefficient, [-] C_L = float(tree.xpath(x_CL % i)[0].text) # Lift coefficient, [-] if round(float(tree.xpath(x_n % i)[0].text)) == 1.: break C_D_fus = float(tree.xpath(x_CDfus)[0].text) # Fuselage drag coefficient, [-] C_D_other = float(tree.xpath(x_CDother)[0].text) # Remaining drag coefficient, [-] R = float(tree.xpath(x_R)[0].text) # Range, [m] SFC = float(tree.xpath(x_SFC)[0].text) # Specific fuel consumption, [kg/N/s] m_fuel_res = float(tree.xpath(x_m_fuel_res)[0].text) # Reserve fuel weight, [kg] m_fixed = float(tree.xpath(x_m_fixed)[0].text) # Fixed weight, [kg] m_wing = float(tree.xpath(x_m_wing)[0].text) # Wing weight, [kg] # Perform calculations C_D = C_D_i + C_D_f + C_D_fus + C_D_other # Total drag coefficient, [-] L_D = C_L/C_D # Aerodynamic efficiency, L/D, [-] LW = m_fixed + m_wing + m_fuel_res # Landing weight, [kg] T = T0 + beta * H # Temperature at altitude, [K] a = sqrt(kappa * R_air * T) # Speed of sound at altitude, [m/s] if L_D == 0: m_fuel = 0. else: m_fuel = LW * expm1(R * g0 * SFC / (a * M) / L_D) # Required fuel weight, [kg] m_mtow = m_fuel + LW m_fuel = m_fuel + m_fuel_res # Write results to output XML file root = etree.Element('cpacs') doc = etree.ElementTree(root) xml_safe_create_element(doc, x_CD, C_D) xml_safe_create_element(doc, x_LD, L_D) xml_safe_create_element(doc, x_fwe_CL, C_L) xml_safe_create_element(doc, x_m_fuel, m_fuel) xml_safe_create_element(doc, x_m_mtow, m_mtow) doc.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def run(input_xml_file, output_xml_file): # Load input file tree = etree.parse(input_xml_file) root = tree.getroot() # Load input parameters for this discipline z1 = float(root.find('./variables/z1').text) z2 = float(root.find('./variables/z2').text) y1 = float(root.find('./analyses/y1').text) # "Run" the discipline calculations y2 = math.sqrt(y1) + z1 + z2 # Write the output xml_safe_create_element(tree, '/dataSchema/analyses/y2', str(y2)) tree.write(output_xml_file)
def generate_input_xml(self): # type: () -> str """Input is a CPACS file with the stresses in the front/rear spars and in the top/bottom skins for each load case. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): for x_sigma in x_sigmas_in: xml_safe_create_element(doc, x_sigma % i, np.zeros(self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_output_xml(self): # type: () -> str """Output is a CPACS file with the normalized y-coordinates and corresponding normalized section lift forces for each load case. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_y_norm % i, np.zeros(n_seg_y * self.n_wing_segments)) xml_safe_create_element(doc, x_l_norm % i, np.zeros(n_seg_y * self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def run(input_xml_file, output_xml_file): # Load input file tree = etree.parse(input_xml_file) root = tree.getroot() # Load input parameters for this discipline x1 = float(root.find('./variables/x1').text) z2 = float(root.find('./variables/z2').text) y1 = float(root.find('./analyses/y1').text) y2 = float(root.find('./analyses/y2').text) # "Run" the discipline calculations f = x1**2 + z2 + y1 + math.exp(-y2) # Write the output xml_safe_create_element(tree, '/dataSchema/output/f', str(f)) tree.write(output_xml_file)
def generate_output_xml(self): # type: () -> str """Output is a CPACS file with the induced drag coefficient and link to the aerodynamic forces.""" root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_CDi % i, 0.) for j in range(3): xml_safe_create_element( doc, x_grid_guess[j] % i, np.zeros(2 * (n_seg_x + 1) * (n_seg_y + 1) * self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc_in = etree.parse(in_file) root = etree.Element('cpacs') doc_out = etree.ElementTree(root) xml_safe_create_element( doc_out, x_obj_m_fuel, float(doc_in.xpath(x_m_fuel)[0].text) / float(doc_in.xpath(x_m_fuel_init)[0].text)) xml_safe_create_element( doc_out, x_obj_m_wing, float(doc_in.xpath(x_m_wing)[0].text) / float(doc_in.xpath(x_m_wing_init)[0].text)) doc_out.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_input_xml(self): # type: () -> str """Input is a CPACS file containing the name of the Matlab shared engine, the links to all three models (geometric, structural, and aerodynamic), and the link the the aerodynamic forces for each load case. """ root = etree.Element('cpacs') doc = etree.ElementTree(root) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_ml_id % i, 0) for j in range(3): xml_safe_create_element( doc, x_grid_guess[j] % i, np.zeros(2 * (n_seg_x + 1) * (n_seg_y + 1) * self.n_wing_segments)) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_input_xml(self): # type: () -> str """Input is a CPACS file with at least a fully defined wing. It is possible to specify a timeout for Matlab, the name of a Matlab sharedEngine, and the timestamp at which this engine was shared. However, the Matlab engine should normally be left under the control of this discipline. """ wd = WingObjectModel(self.n_wing_segments) s = wd.generate_output_xml() parser = etree.XMLParser(remove_blank_text=True, encoding='utf-8') doc = etree.fromstring(s, parser) for i in range(1, self.n_load_cases + 1): xml_safe_create_element(doc, x_ml_timeout % i, self.MATLAB_TIMEOUT) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)
def execute(in_file, out_file): doc_in = etree.parse(in_file) sigma_yield = float(doc_in.xpath(x_sigma_yield)[0].text) root = etree.Element('cpacs') doc_out = etree.ElementTree(root) for i in range(4): xml_safe_create_element( doc_out, x_con_sigmas[i], np.array(doc_in.xpath(x_sigmas_out[i])[0].text.split(';'), dtype=float) / sigma_yield - 1.) MTOW = float(doc_in.xpath(x_m_mtow)[0].text) S = float(doc_in.xpath(x_ref_area)[0].text) WS_init = float(doc_in.xpath(x_WS_init)[0].text) con_ws = MTOW / S / WS_init - 1. xml_safe_create_element(doc_out, x_con_WS, con_ws) xml_safe_create_element( doc_out, x_con_buffet, float(doc_in.xpath(x_fwe_CL)[0].text) / float(doc_in.xpath(x_CL_buffet)[0].text) - 1.) doc_out.write(out_file, encoding='utf-8', pretty_print=True, xml_declaration=True)
def generate_input_xml(self): # type: () -> str root = etree.Element('cpacs') doc = etree.ElementTree(root) xml_safe_create_element(doc, x_m_fuel_init, 1.) xml_safe_create_element(doc, x_m_fuel, 1.) xml_safe_create_element(doc, x_m_wing_init, 1.) xml_safe_create_element(doc, x_m_wing, 1.) return etree.tostring(doc, encoding='utf-8', pretty_print=True, xml_declaration=True)