コード例 #1
0
def invoke(focusObject, rootObject, componentParameters, udmProject, **kwargs):
    if focusObject is not None and focusObject.type.name == "ParameterStudy":
        focusObject = focusObject.parent
    if focusObject is None or focusObject.type.name != "ParametricExploration":
        raise CyPhyPython.ErrorMessageException("Run on ParametricExploration")

    mga_project = focusObject.convert_udm2gme().Project

    for index, gme_id in [(key, value) for key, value in six.iteritems(componentParameters) if key.startswith('unit_id_')]:
        unit_fco = mga_project.GetFCOByID(gme_id)

        def set_units(units):
            componentParameters[index + "_ret"] = units

        set_unit(unit_fco, set_units)
コード例 #2
0
 def log(s):
     CyPhyPython.log(cgi.escape(s))
コード例 #3
0
 def log_formatted(s):
     CyPhyPython.log(s)
コード例 #4
0
 def log(s):
     CyPhyPython.log(s)
コード例 #5
0
 def log_formatted(s):
     CyPhyPython.log(cgi.escape(s))
コード例 #6
0
 def log(s):
     CyPhyPython.log(cgi.escape(s))
コード例 #7
0
ファイル: sum_arrays.py プロジェクト: dyao-vu/meta-core
 def log_formatted(s):
     CyPhyPython.log(s)
コード例 #8
0
ファイル: runLSDyna.py プロジェクト: cephdon/meta-core
 def log(s):
     CyPhyPython.log(s)
コード例 #9
0
def invoke(focusObject, rootObject, componentParameters, udmProject, **kwargs):
    if focusObject is not None and focusObject.type.name == "ParameterStudy":
        focusObject = focusObject.parent
    if focusObject is None or focusObject.type.name != "ParametricExploration":
        raise CyPhyPython.ErrorMessageException("Run on ParametricExploration")

    parameterStudy = [
        c for c in focusObject.children() if c.type.name == "ParameterStudy"
    ]
    if not parameterStudy:
        raise CyPhyPython.ErrorMessageException(
            "Must contain a ParameterStudy")
    parameterStudy = parameterStudy[0]
    designVariables = [
        c for c in parameterStudy.children() if c.type.name == "DesignVariable"
    ]
    var_dict = {}
    for desVar in designVariables:
        var_dict[desVar.attr("name")] = desVar.Range

    project_dir = os.path.dirname(
        focusObject.convert_udm2gme().Project.ProjectConnStr[len("MGA="):])
    try:
        pet_config_filename = componentParameters.get(
            "pet_config_filename",
            os.path.join(project_dir, "results", "pet_config_refined.json"))
        with open(pet_config_filename, "rb") as input_json:
            args = json.load(input_json)
    except IOError as e:
        if e.errno == 2:
            raise CyPhyPython.ErrorMessageException(
                "Produce the file results/pet_config_refined.json first.")
        raise

    driver_details = copy.deepcopy(args["drivers"].values()[0]["details"])
    for varName, var in args["drivers"].values(
    )[0]["designVariables"].iteritems():
        if var.get("type") == "enum":
            var_dict[varName] = ";".join(map(json.dumps, var["items"]))
        else:
            var_dict[varName] = repr(var["RangeMin"]) + "," + repr(
                var["RangeMax"])
    # TODO: optimizer constraints

    testing_and_pets = {}
    queue = collections.deque()

    def get_path(folder):
        ret = tuple()
        while folder != folder.Project.RootFolder:
            ret = (folder.Name, ) + ret
            folder = folder.ParentFolder
        return ret

    # create copy of PET as specified in NewPETName (if present) re-use Testing and ParametricExplorationFolder
    # FIXME: this code doesn't handle more than one missing folder
    mga_project = focusObject.convert_udm2gme().Project
    queue.append(mga_project.RootFolder)
    while queue:
        folder = queue.pop()
        testing_and_pets[get_path(folder)] = folder
        for child_folder in (f for f in folder.ChildFolders
                             if f.MetaBase.Name in (
                                 "ParametricExplorationFolder", "Testing")):
            queue.append(child_folder)

    new_name = componentParameters.get(
        "NewPETName",
        "/" + "/".join(get_path(focusObject.convert_udm2gme().ParentFolder)) +
        "/" + focusObject.name + "_Refined")
    new_folders = tuple(new_name.split("/")[1:-1])
    pet_folder, testing_folder = None, None
    for i in range(len(new_folders), 0, -1):
        pet_folder = testing_and_pets.get(new_folders[:i])
        if pet_folder is not None and pet_folder.MetaBase.Name == "ParametricExplorationFolder":
            break
        else:
            pet_folder = None
        testing_folder = testing_and_pets.get(new_folders[:i - 1])
        if testing_folder is not None and testing_folder.MetaBase.Name in (
                "ParametricExplorationFolder", "Testing"):
            pet_folder = testing_folder.CreateFolder(
                mga_project.RootMeta.RootFolder.GetDefinedFolderByNameDisp(
                    "ParametricExplorationFolder", True))
            pet_folder.Name = new_name.split("/")[-2]
            break

    gmeCopy = pet_folder.CopyFCODisp(focusObject.convert_udm2gme())
    gmeCopy.Name = new_name.split("/")[-1]
    focusObject = udmProject.convert_gme2udm(gmeCopy)
    parameterStudy = [
        c for c in focusObject.children() if c.type.name == "ParameterStudy"
    ][0]
    parameterStudy.Code = driver_details["Code"]
    parameterStudy.SurrogateType = driver_details["SurrogateType"]
    parameterStudy.DOEType = driver_details["DOEType"]
    designVariables = [
        c for c in parameterStudy.children() if c.type.name == "DesignVariable"
    ]
    for desVar in designVariables:
        if desVar.name not in var_dict:
            # probably it is an output
            # log("Couldn't find Design Variable '{}' in model".format(desVar.name))
            continue
        # log("{}.Range = {}".format(desVar.name, var_dict[desVar.name]))
        desVar.Range = var_dict[desVar.name]

    componentParameters["NewPETID"] = gmeCopy.ID

    gme = [c for c in gmeCopy.Project.Clients if c.Name == "GME.Application"]
    if gme:
        gme = gme[0].OLEServer
        gmeCopy.Project.CommitTransaction()
        gme.ShowFCO(gmeCopy, False)
        READ_ONLY = 1
        gmeCopy.Project.BeginTransactionInNewTerr(READ_ONLY)