Example #1
0
 def __init__(self, orb, poa, cid, cname, instn, intfn):
     log.debug("ASTER.__init__ called")
     Component.__init__(self, orb, poa, cid, cname, instn, intfn, 0)
     self._astds = {}
     # attributes for OpenTurns interface
     self._otcase = None
     if salome.lcc is None:
         salome.lcc = LifeCycleCORBA(orb)
Example #2
0
 def AddCase(self, name, corba_case_type):
     """Add an Aster study case"""
     study_cases = self._study_cases
     names = [scase.ReadName() for scase in study_cases]
     if name not in names:
         case = self.inst.add_case(name, self._case_types[corba_case_type])
         study_case = StudyCase(case)
         study_cases.append(study_case)
         log.debug("AddCase: new CORBA StudyCase created, name = %s", name)
Example #3
0
 def Run(self):
     """Run the Aster solver"""
     log.debug("StudyCase.Run: enter")
     try:
         job = Job(self.inst.run())
         self._jobs.append(job)
     except Exception, e:
         traceback.print_exc()
         _raiseSalomeException(e.__str__())
Example #4
0
 def find_groups(self, mesh):
     """Find the group names on the given mesh"""
     grps = []
     dim = mesh.give_dim()
     if dim:
         ctypes = self._dct[dim]
         grps = self._exp.find_groups_from_ctypes(mesh, ctypes)
     log.debug(
         "GroupExplorator.find_groups for mesh %s returns %s with dim %s and dct %s",
         mesh, grps, dim, self._dct)
     return grps
Example #5
0
 def ResultFileName(self, corba_elt_type):
     """Return the filename of the result of the given element type"""
     log.debug("StudyCase.ResultFileName: enter")
     elt_type = self._get_elt_type(corba_elt_type)
     elt = self.inst.get(elt_type)
     log.debug("found element is %s", elt)
     if elt is None:
         fname = ""
     else:
         fname = elt.read_fname()
     return fname
Example #6
0
 def find_groups_from_ctypes(self, mesh, tags):
     """Find the group names on a SMESH node according to the
     given tags"""
     node = mesh.node
     grp_names = []
     for tag in tags:
         tag_node = node.get_subnode(tag)
         if not tag_node:
             continue
         for grp_node in tag_node.get_children():
             grp_names.append(grp_node.read_name())
     log.debug("SMeshExplorator.find_groups_from_ctypes returns %s",
               grp_names)
     return grp_names
Example #7
0
def _raiseSalomeException(userMessage):
    """
    This function throws a SALOME exception based on the last exception raised,
    and with the specified message as user information to be displayed.
    """
    exc_type, exc_obj, exc_tb = sys.exc_info()
    filename = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    linenumber = exc_tb.tb_lineno
    logmessage = (exc_type, filename, linenumber)
    log.debug("An exception is raised " + str(logmessage) + ": " +
              str(userMessage))

    raise SALOME.SALOME_Exception(
        SALOME.ExceptionStruct(SALOME.INTERNAL_ERROR, userMessage, filename,
                               linenumber))
Example #8
0
 def AttachTo(self, sstd):
     """Return an Aster study"""
     astds = self._astds
     sidx = sstd._get_StudyId()
     if sidx not in astds:
         astd = Study(sstd)
         astds[sidx] = astd
         log.debug("AttachTo: new CORBA Study created, study id is %s",
                   sidx)
     else:
         astd = astds[sidx]
         log.debug(
             "AttachTo: existing CORBA Study returned, study id is %s",
             sidx)
     return astd._this()
Example #9
0
 def GetFilesToTransfer(self, studyId, caseEntry):
     """This method is an implementation for the ASTER interface.
     This method can be used to specify files to transfer to the
     computation resource.
     """
     log.debug("ASTER.GetFilesToTransfer: studyId = %d - caseEntry = %s",
               studyId, caseEntry)
     try:
         case = aster_s.load_case_from_studyId_and_entry(studyId, caseEntry)
         acs = case.build_astk_case()
         resudir, prof, relocated = create_probabilistic_profil(acs)
         log.info("GetFilesToTransfer:\n%s", prof)
         log.debug("resudir: %s", resudir)
         inputFiles = [entry.path for entry in prof.get_data()]
         outputFiles = [
             entry.path
             for entry in relocated.get_type('repe').get_result()
         ]
         log.info("GetFilesToTransfer:\ninputs : %s\n outputs : %s",
                  inputFiles, outputFiles)
         return inputFiles, outputFiles
Example #10
0
 def has_changed(self):
     """Compute the new signature of the case and returns if
     it changed since last call."""
     cur_sign = self.line.load_attr("signature")
     new_sign = self.signature()
     log.debug("AS.Case.has_changed:")
     log.debug("old signature : %s", cur_sign)
     log.debug("new signature : %s", new_sign)
     if new_sign == "" or new_sign == cur_sign:
         return False
     self.line.store_attr("signature", new_sign)
     return True
Example #11
0
 def run(self):
     """Run the Aster case"""
     log.debug("study.Case.run")
     self.update_icon("PEND")
     log.debug("Case.run: build_astk_case")
     acs = self.build_astk_case()
     job = Job(acs, self._display_results)
     log.debug("Case.run: run case")
     acs.run(job)
     self._build_results()
     self.results.clear()
     self.results.use(AC.JobId(pid=job.pid))
     return job
Example #12
0
 def Init(self, studyId, caseEntry):
     """This method is an implementation for the ASTER interface.
     It sets the component with some deterministic parametrization.
     """
     log.debug("ASTER.Init: enter")
     log.debug("ASTER.Init: studyId = %d - caseEntry = %s", studyId,
               caseEntry)
     # load aster case
     try:
         self._otcase = aster_s.load_case_from_studyId_and_entry(
             studyId, caseEntry)
     except Exception:
         traceback.print_exc()
         log.error(
             "[ERROR] can not load Aster case from study Id = %s"
             " and case entry = %s", studyId, caseEntry)
         self._raiseSalomeError()
     log.debug("ASTER.Init: exit")
Example #13
0
    def __init__(self, sstd):
        self.inst = aster_s.attach_study_to(sstd)
        self._study_cases = []

    def AddCase(self, name, corba_case_type):
        """Add an Aster study case"""
        study_cases = self._study_cases
        names = [scase.ReadName() for scase in study_cases]
        if name not in names:
            case = self.inst.add_case(name, self._case_types[corba_case_type])
            study_case = StudyCase(case)
            study_cases.append(study_case)
            log.debug("AddCase: new CORBA StudyCase created, name = %s", name)
        else:
            study_case = study_cases[names.index(name)]
            log.debug("AddCase: existing CORBA StudyCase returned, name = %s",
                      name)
        return study_case._this()

    def GiveCases(self):
        """Return the added cases"""
        return [scase._this() for scase in self._study_cases]


class ASTER(ASTER_Gen, Component, Driver):
    """Allow to load the ASTER component
    """
    def __init__(self, orb, poa, cid, cname, instn, intfn):
        log.debug("ASTER.__init__ called")
        Component.__init__(self, orb, poa, cid, cname, instn, intfn, 0)
        self._astds = {}
        # attributes for OpenTurns interface
Example #14
0
    # mode under the Openturns job.
    profil['mode'] = 'interactif'
    calc = AsterCalcParametric(run,
                               label,
                               prof=profil,
                               pid=pid,
                               values=values,
                               keywords={},
                               resudir=resudir)
    return calc.prof


def build_probabilistic_case(case,
                             values,
                             caseId=None,
                             newdir=None,
                             mode='batch'):
    """Build a new astk.Case using the dict of values provided."""
    if mode != 'batch':
        mode = 'interactif'
    in_profil = _get_profil_from_case(case)
    resudir, profil, relocated = add_result_to_profil(in_profil, newdir, mode)
    prof = create_new_profil(relocated, resudir, values, caseId)
    log.debug("New profile content :\n%s", prof)

    jobname = prof.get_jobname()
    new_acs = astk.FromProfil(jobname)
    new_acs.use_profil(prof)
    new_acs.use_fname(prof.get_filename())
    return new_acs
Example #15
0
 def update_icon(self, status):
     """Update icon to reflect the job status"""
     log.debug("AS.Case:update_icon: status=%s", status)
     icon_name = _icon_from_status(status)
     self.line.store_icon(icon_name)
Example #16
0
 def fill_astk_case(self, astk_case, study_case):
     """Fill the ASTK case with the configuration found in the object
     browser"""
     log.debug("AstkParams.fill_astk_case")
     astk_case.use(self.get_cfg())
Example #17
0
 def fill_astk_case(self, astk_case, study_case):
     """Fill the ASTK case (aster.astk.Case) from input data
     stored in this object browser section."""
     for elt in self.get_all_elts():
         log.debug("add element to astk_case : %s", elt)
         elt.fact.add_to(astk_case, study_case, elt)
Example #18
0
    def Exec(self, paramInput):
        """This method is an implementation for the ASTER interface.
        It runs the component with some new parameters compared with the deterministic ones.
        """
        log.debug("ASTER.Exec: enter")
        if self._otcase is None:
            log.error("ASTER.Exec: Init not run")
            self._raiseSalomeError()
        log.debug("ASTER.Exec: inputVarList: %s" % paramInput.inputVarList)
        log.debug("ASTER.Exec: outputVarList: %s" % paramInput.outputVarList)
        log.debug("ASTER.Exec: inputValues: %s" % paramInput.inputValues)
        wrkdir = os.getcwd()
        log.debug("ASTER.Exec: workdir: %s" % wrkdir)
        values = create_input_dict({}, paramInput)
        log.debug("ASTER.Exec: dict of values: %s" % values)
        caseId = None
        mode = 'batch'
        for parameter in paramInput.specificParameters:
            log.debug("ASTER p.nam : %s : %s", parameter.name, parameter.value)
            if parameter.name == "id":
                caseId = parameter.value
            if parameter.name == "executionMode":
                mode = parameter.value
        log.debug("ASTER.Exec: caseId: %s" % caseId)

        try:
            log.debug("ASTER.Exec: build astk case from %s", self._otcase)
            acs = self._otcase.build_astk_case()
            log.debug(
                "ASTER.Exec: build probabilistic case from %s and values (%s)",
                acs, values)
            new_acs = build_probabilistic_case(acs, values, caseId, wrkdir,
                                               mode)
            jobname = new_acs._name
        except Exception:
            traceback.print_exc()
            return create_error_parametric_output(
                "[ERROR] unabled to build the probabilistic case")

        try:
            log.debug("ASTER.Exec: start job %s", jobname)
            job = new_acs.run()
            log.debug("ASTER.Exec: waiting result...")
            job.wait_result()
            log.debug("ASTER.Exec: job %s ended", jobname)
        except Exception:
            traceback.print_exc()
            return create_error_parametric_output(
                "[ERROR] unabled to run the probabilistic case")

        try:
            log.debug("ASTER.Exec: status %s", job.status())
            log.debug("ASTER.Exec: res_status %s", job.res_status())
            assert job.status() is aster_s.ENDED
            assert job.res_status() in (aster_s.SUCCESS, aster_s.ALARM)
        except AssertionError:
            return create_error_parametric_output("[ERROR] case %s ends with status %s" \
                % (jobname, job.res_status()))

        computedValues = {}
        try:
            mess = new_acs.get_result(astk.MessFile)
            log.debug("ASTER.Exec: reading %s", mess.fname)
            varlist = paramInput.outputVarList
            try:
                computedValues = get_values_from_mess(mess.fname, varlist)
            except AssertionError, exc:
                log.error("[ERROR] %s", str(exc))
                self._raiseSalomeError()
            log.info("[OK] Job %s successfully ended", jobname)
            log.info("INPUT  : %s", paramInput.inputValues)
            paramOutput = create_normal_parametric_output(
                computedValues, paramInput)
            log.info("OUTPUT: %s", paramOutput.outputValues)
            return paramOutput
Example #19
0
 def Finalize(self):
     """This method is an implementation for the ASTER interface.
     It cleans everything set so far.
     """
     log.debug("ASTER.Finalize : pass")
     return