def load_external_libs(): try: global tixi_h tixi_h = tixi3wrapper.Tixi3() print("TIXI version: ", tixi_h.version) except Exception as e: print("Could not load TIXI! Error message is: {}".format(e))
def main(): logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) parser = argparse.ArgumentParser(description='Converts a CPACS file from Version 2 to Version 3.') parser.add_argument('input_file', help='Input CPACS 2 file') parser.add_argument('-o', metavar='output_file', help='Name of the output file.') parser.add_argument('--fix-errors', '-f', help='try to fix empty and duplicate uids/elements', action="store_true") parser.add_argument('--target-version', '-v', default="3.1") args = parser.parse_args() filename = args.input_file cpacs_file = tixi3wrapper.Tixi3() cpacs_file.open(filename) cpacs_file.setCacheEnabled(1) cpacs_file.usePrettyPrint(1) # get all uids uid_manager.register_all_uids(cpacs_file) version_new = args.target_version vu = VersionUpdater() vu.update(cpacs_file, args, version_new) add_changelog(cpacs_file, "Converted to CPACS %s using cpacs2to3" % version_new) logging.info("Done") output_file = args.o if output_file is not None: logging.info("Saving file to '" + output_file + "'") cpacs_file.save(output_file) else: logging.info(cpacs_file.exportDocumentAsString())
def cpacs_generate(aircraftname, tot_len, nose_frac=0.1, tail_frac=0.1): """Generates a new CPACS file with a fuselage defined in it Parameters ---------- aircraftname : str The name of the aircraft and filename of the output CPACS file tot_len : float Total length of the fuselage nose_frac : float, default = 0.1 Fraction of the total length that comprises the nose section tail_frac : float, default = 0.1 Fraction of the total length that comprises the tail section Outputs ------- A CPACS file named aircraftname.xml """ # Instantiate class and create handle for it tixi_handle = tixi.Tixi3() tixi.Tixi3.create(tixi_handle, rootElementName='cpacs') # Generate CPACS XML tag structure tixi_handle = generate_cpacs_structure(tixi_handle, aircraftname) # Create fuselage tixi_handle = build_fuselage(tixi_handle, tot_len, nose_frac, tail_frac, 'Fuselage') # Check that CPACS file matches schema tixi_handle.schemaValidateFromFile('cpacs_schema.xsd') close_tixi(tixi_handle, f"cpacs/{aircraftname}.xml")
def main(): logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.DEBUG) parser = argparse.ArgumentParser( description='Fixed problems on a cpacs file.') parser.add_argument('input_file', help='Input CPACS file') parser.add_argument('-o', metavar='output_file', help='Name of the output file.') parser.add_argument( '-i', help='Modify file in place, i.e. overwrite the input file.', action="store_true") args = parser.parse_args() cpacs_file = tixi3wrapper.Tixi3() filename = args.input_file output_file = args.o in_place = args.i cpacs_file.open(filename) cpacs_file.setCacheEnabled(1) cpacs_file.usePrettyPrint(1) uid_manager.register_all_uids(cpacs_file) changelog = "" if uid_manager.fix_invalid_uids(cpacs_file): changelog += "Fixed invalid uIDs. " if fix_empty_elements(cpacs_file): changelog += "Removed empty elements. " if add_missing_uids(cpacs_file): changelog += "Added missing UIDs. " if fix_wing_profiles(cpacs_file): changelog += "Fixed order of wing profiles. " if changelog != "": add_changelog(cpacs_file, changelog.strip(), "fix_errors.py") logging.info("Done") if in_place: output_file = filename if output_file is not None: logging.info("Saving " + output_file) cpacs_file.save(output_file) else: logging.info(cpacs_file.exportDocumentAsString())
def display_wing_cell_geom(display, start_eta, end_eta): display.eraseAll() tixi_h = tixi3wrapper.Tixi3() tigl_h = tigl3wrapper.Tigl3() dir_path = os.path.dirname(os.path.realpath(__file__)) tixi_h.open(resource_dir_cpacs + "/temp.xml") tigl_h.open(tixi_h, "") mgr = tigl3.configuration.CCPACSConfigurationManager_get_instance() config = mgr.get_configuration(tigl_h._handle.value) lifting_surfaces = update_surface_lower_3d(config) for part, loft in lifting_surfaces.items(): display.add(loft, color="blue", transparency=0.8)
def open_cpacs(filename): tixi_h = tixi3wrapper.Tixi3() tixi_h.open(filename) value = tixi_h._handle.value tigl_h = tigl3wrapper.Tigl3() print("value" + str(value)) print("version" + str(tixi_h.getDoubleElement("/cpacs/header/cpacsVersion"))) tigl_h.open(tixi_h, "") return [tigl_h, tixi_h]
def main(): tixi_handle = tixi3wrapper.Tixi3() tigl_handle = tigl3wrapper.Tigl3() print ("Using TiGL Version:", tigl_handle.version) dir_path = os.path.dirname(os.path.realpath(__file__)) tixi_handle.open(dir_path + "/../../tests/unittests/TestData/simpletest.cpacs.xml") tigl_handle.open(tixi_handle, "") # cpacs indexing starts at 1 wing_shape = get_wing_shape(tigl_handle, 1) box_shape = create_box() export_shapes([wing_shape, box_shape], "simpletest.igs")
def simple_test(): file_name = "tests/TestData/simpletest.cpacs.xml" old_cpacs_file = tixiwrapper.Tixi() new_cpacs_file = tixi3wrapper.Tixi3() new_cpacs_file.open(file_name) new_cpacs_file.setCacheEnabled(1) new_cpacs_file.usePrettyPrint(1) uid_manager.register_all_uids(new_cpacs_file) uid_manager.fix_invalid_uids(new_cpacs_file) fix_empty_elements(new_cpacs_file) old_cpacs_file.openString(new_cpacs_file.exportDocumentAsString()) return TestCase(file_name, old_cpacs_file, new_cpacs_file)
def create_space_shipe(): tixi_h = tixi3wrapper.Tixi3() tigl_h = tigl3wrapper.Tigl3() tixi_h.open("Data/simpletest.cpacs.xml") tigl_h.open(tixi_h, "") # get the configuration manager mgr = tigl3.configuration.CCPACSConfigurationManager_get_instance() aircraft = mgr.get_configuration(tigl_h._handle.value) wing0 = aircraft.get_wing(1); sym = wing0.get_symmetry(); wings = aircraft.get_wings(); create_round_wing(wings, "roundW", 29, 10,sym); create_round_wing(wings, "roundW2", 13, 7,sym); create_round_wing(wings, "roundW3", 3, 8,sym); wing3 = aircraft.get_wing("roundW3") wing3.set_root_leposition(geometry.CTiglPoint(10,0,-4)) save(tixi_h, aircraft, "out-test.xml")
def open_tixi(cpacs_path): """ Create TIXI handles for a CPACS file and return this handle. Function 'open_tixi' return the TIXI Handle of a CPACS file given as input by its path. If this operation is not possible, it returns 'None' Source : * TIXI functions: http://tixi.sourceforge.net/Doc/index.html Args: cpacs_path (str): Path to the CPACS file Returns:: tixi_handle (handles): TIXI Handle of the CPACS file """ tixi_handle = tixi3wrapper.Tixi3() tixi_handle.open(cpacs_path) log.info('TIXI handle has been created.') return tixi_handle
# get the configuration manager mgr = CCPACSConfigurationManager_get_instance() # get the CPACS configuration, defined by the tigl handle # we need to access the underlying tigl handle (that is used in the C/C++ API) config = mgr.get_configuration(tigl_handle._handle.value) fuselage_shape = config.get_fuselage(1).get_loft() wing_shape = config.get_wing(1).get_loft() wing_m_shape = config.get_wing(1).get_mirrored_loft() # fuse the shapes fused_shape = CFuseShapes(fuselage_shape, [wing_shape, wing_m_shape]).named_shape() print ("Done!") return fused_shape if __name__ == '__main__': tixi_h = tixi3wrapper.Tixi3() tigl_h = tigl3wrapper.Tigl3() dir_path = os.path.dirname(os.path.realpath(__file__)) tixi_h.open(dir_path + "/../../tests/unittests/TestData/simpletest.cpacs.xml") tigl_h.open(tixi_h, "") fused_ac = get_fused_shape(tigl_h) export_shapes([fused_ac], "simpletest.stp")
def main(): names = ["straightWing"] logger.info("Program started") # Aircraft variables # [m] Wing span span = 50.0 # [-] sweep angle in degrees. aft if negative sweep = 0 # [-] diheadral angle in degree - anhedral if negative diheadral = 0 # [m] root chord root_c = 20 # [m] tip chord tip_c = 20 # Airfoil profile naca_profile = "NACA 2412" # Number of wing sections nWingSections = 2 # CPACS variables aircraft_name = "FlyingWing" creator = "Jean-Philippe Kuntzer" version = "1" description = "Test for aeroelatic deformation" cpacsVersion = "3.0" for i in range(len(names)): # Tigl and Tixi handles tixi_h = tixi3wrapper.Tixi3() tigl_h = tigl3wrapper.Tigl3() # Create a new document for writing with root element named # "plane". A file name is attributed to this document on saving. CPACS_name = "cpacs" tixi_h.create(CPACS_name) # First a header containing the tool name and version and the author # of the file is added. A timestamp is added automatically, as well. tixi_h.addCpacsHeader(aircraft_name, creator, version, description, cpacsVersion) # defines a CPACS structres and give the miinum setup cpacs_Structre(tixi_h, aircraft_name) cpacs_Aircraft(tixi_h, naca_profile) # Links tixi handler to CPACS files tigl_h.open(tixi_h, aircraft_name) # Uploads tixi handel information into tigl information mgr = tigl3.configuration.CCPACSConfigurationManager_get_instance() aircraft = mgr.get_configuration(tigl_h._handle.value) # cst2 = np.linspace(0,0.5,len(names)) cst2 = [0.0] # cst2 = 0.5*np.ones(len(names)) # np.linspace(0,0.5,len(names)) filename = names[i] + ".xml" # wing_builder(span, # root_c, # tip_c, # sweep, # diheadral, # nWingSections, # names[i], # aircraft, # naca_profile, # cst2[i], # filename,tixi_h) # # fuselage_builder(aircraft) # cpacs_save(aircraft,tixi_h,filename) x, y, z, nx, ny, nz, chords = pointsWingType2() # chords = 0.2*(1-y)*np.ones(len(x)) wing_builder2(x, y, z, nx, ny, nz, chords, names, aircraft, naca_profile, filename, tixi_h) cpacs_save(aircraft, tixi_h, filename) logger.debug("Program ended")
#!/usr/bin/python # # @file # @brief Demo Python script to show how TIXI opens a xml file and includes all # XML files that are linked in. # @author Markus Litz, DLR/SC, 2008-06-23 # from tixi3 import tixi3wrapper # define handles tixi = tixi3wrapper.Tixi3() xmlInputFilename = "MainFile.xml" xmlOutputFilename = "Result_out.xml" # Open a CPACS configuration file. First open the CPACS-XML file # with TiXI to get a tixi handle. tixi.open(xmlInputFilename, recursive=True) # remove an Element from the main xml file: tixi.removeElement("/plane/aPoint") # add an element to a node that is located in a external satellite file tixi.addTextElement("/plane/testNode/aVeryTest/testNode/aVeryTest3/point", "y", "123.45") # export document as string xmlDocumentString = tixi.exportDocumentAsString() print("---------------------------------") print(xmlDocumentString) print("---------------------------------")
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. @file @brief Demo Python script to show how to use TIXI routoines in python scripts @author Markus Litz, DLR/SC, 2008-06-10 """ from tixi3 import tixi3wrapper from tixi3.tixi3wrapper import Tixi3Exception # define handles and open the tixi document tixi_handle = tixi3wrapper.Tixi3() tixi_handle.open("../Demo/howtoin.xml") # ---------------------------------------------------------------------------- # now read some xml data from a file.... # ---------------------------------------------------------------------------- # text element ... print(tixi_handle.getTextElement("/plane/name")) # double element print(tixi_handle.getDoubleElement("/plane/coordinateOrigin/x")) # get the number of wing subelements of element wings parent_name = "/plane/wings" sub_element_name = "wing"