예제 #1
0
    def test_Init(self):

        V = PQ.PhysicalQuantity('3.6 km/h')
        velocity = V.inBaseUnits()
        self.assertTrue(velocity.value == 1.0)
        self.assertEqual(velocity.getUnitName(), 'm/s')

        try:
            V = PQ.PhysicalQuantity('s m s')
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')


        try:
            V = PQ.PhysicalQuantity('2 m s')
        except SyntaxError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')
예제 #2
0
    def __init__(self, metaData={}):
        MD = {
            'Name':
            'Simple application cummulating time steps',
            'ID':
            'N/A',
            'Description':
            'Cummulates time steps',
            'Model_refs_ID': ['SimulationTimer-1'],
            'Inputs': [{
                'Type': 'mupif.Property',
                'Type_ID': 'mupif.PropertyID.PID_Time_step',
                'Name': 'Time step',
                'Description': 'Time step',
                'Units': 's',
                'Origin': 'Simulated',
                'Required': True
            }],
            'Outputs': [{
                'Type': 'mupif.Property',
                'Type_ID': 'mupif.PropertyID.PID_Time',
                'Name': 'Cummulative time',
                'Description': 'Cummulative time',
                'Units': 's',
                'Origin': 'Simulated'
            }]
        }

        super(Example04, self).__init__(metaData=MD)
        self.updateMetadata(metaData)

        # locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost,
                                        nsport=cfg.nsport,
                                        hkey=cfg.hkey)
        # connect to JobManager running on (remote) server and create a tunnel to it
        self.jobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey)
        log.info('Connected to JobManager')
        self.app1 = None
        self.contrib = Property.ConstantProperty((0., ), PropertyID.PID_Time,
                                                 ValueType.Scalar, 's',
                                                 PQ.PhysicalQuantity(0., 's'))
        self.retprop = Property.ConstantProperty((0., ), PropertyID.PID_Time,
                                                 ValueType.Scalar, 's',
                                                 PQ.PhysicalQuantity(0., 's'))

        try:
            self.app1 = PyroUtil.allocateApplicationWithJobManager(
                ns, self.jobMan, cfg.jobNatPorts[0], cfg.hkey,
                PyroUtil.SSHContext(sshClient=cfg.sshClient,
                                    options=cfg.options,
                                    sshHost=cfg.sshHost))
            log.info(self.app1)
        except Exception as e:
            log.exception(e)

            appsig = self.app1.getApplicationSignature()
            log.info("Working application 1 on server " + appsig)
예제 #3
0
    def test_Neg(self):
        F = PQ.PhysicalQuantity('2 m')
        mF = PQ.PhysicalQuantity('-2 m')

        nF = F.__neg__()
        nmF = mF.__neg__()

        self.assertEqual(F, nmF)
        self.assertEqual(mF, nF)
예제 #4
0
def main():

    #locate nameserver
    ns = PyroUtil.connectNameServer(nshost=cfg.nshost,
                                    nsport=cfg.nsport,
                                    hkey=cfg.hkey)
    #connect to JobManager running on (remote) server
    thermalJobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey)
    thermalSolver = None

    #allocate the application instances
    try:
        thermalSolver = PyroUtil.allocateApplicationWithJobManager(
            ns, thermalJobMan, cfg.jobNatPorts[0], cfg.hkey,
            PyroUtil.SSHContext(sshClient=cfg.sshClient,
                                options=cfg.options,
                                sshHost=cfg.sshHost))
        log.info('Created thermal job')

    except Exception as e:
        log.exception(e)
    else:
        if ((thermalSolver is not None)):
            thermalSolverSignature = thermalSolver.getApplicationSignature()
            log.info("Working thermal solver on server " +
                     thermalSolverSignature)

            log.info("Uploading input files to servers")
            pf = thermalJobMan.getPyroFile(thermalSolver.getJobID(),
                                           "input.in", 'wb')
            PyroUtil.uploadPyroFile("inputT.in", pf, cfg.hkey)
        else:
            log.debug("Connection to server failed, exiting")

    time = PQ.PhysicalQuantity(0., 's')
    dt = PQ.PhysicalQuantity(1., 's')
    targetTime = PQ.PhysicalQuantity(1., 's')
    istep = TimeStep.TimeStep(time, dt, targetTime)

    start = timeT.time()
    log.info('Timer started')
    log.info("Solving thermal problem")
    thermalSolver.solveStep(istep)
    #timeT.sleep(20)
    log.info("Thermal problem solved")
    # get temperature field
    temperatureField = thermalSolver.getField(FieldID.FID_Temperature,
                                              istep.getTime())
    temperatureField.field2VTKData().tofile('T_distributed')
    #terminate
    log.info("Time consumed %f s" % (timeT.time() - start))

    thermalSolver.terminate()
    thermalJobMan.terminate()

    log.info("Test OK")
예제 #5
0
 def test_Lower(self):
     V1 = PQ.PhysicalQuantity('1 m/s')
     V2 = PQ.PhysicalQuantity('2 m/s')
     V3 = PQ.PhysicalQuantity('3.6 km/h')
     self.assertTrue(V1 < V2)
     self.assertFalse(V1 > V2)
     self.assertFalse(V1 == V2)
     self.assertTrue(V3 < V2)
     self.assertFalse(V3 > V2)
     self.assertTrue(V1 == V3)
예제 #6
0
    def test_tan(self):
        A = PQ.PhysicalQuantity('4 N')
        try:
            B = A.tan()
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')

        A = PQ.PhysicalQuantity('3.14159265358979323846264 rad')
        B = A.tan()
        self.assertAlmostEqual(B, 0)
예제 #7
0
    def test_Pow(self):
        V = PQ.PhysicalQuantity('1 km/h')
        F = PQ.PhysicalQuantity('20 m')
        try:
            A = V**F
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')

        r = PQ.PhysicalQuantity('400 m*m')
        t = F**2
        self.assertEqual(r, r)
예제 #8
0
파일: xstream.py 프로젝트: xyuan/mupif
    def getCriticalTimeStep(self):
        """
          Get the critical time step.
          This step is given in the X-Stream case file. It is the normal application
          time step.
          
          :return: float
          
        """
        self.__config()
        #gets the timestep from the .cas file
        lines = open(self.workdir + '/' + self.config['caseFile'],
                     'r').readlines()
        found_tstep = False
        for line in lines:
            if (not line.lstrip().startswith('!')):
                if re.search(r"TIME_STEP ", line, re.IGNORECASE):
                    found_tstep = True
                    value = float(line.split()[1])
                    self.log.info("The critical time step in X-stream is %f" %
                                  value)
                    return PQ.PhysicalQuantity(value, "s")

        if (found_tstep == False):
            raise APIError.APIError(
                'The timestep (keyword TIME_STEP) can not be found')
예제 #9
0
파일: Example18.py 프로젝트: xyuan/mupif
    def __init__(self, targetTime=PQ.PhysicalQuantity(0., 's')):
        super(Demo18, self).__init__(file='',
                                     workdir='',
                                     targetTime=targetTime)

        #locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost,
                                        nsport=cfg.nsport,
                                        hkey=cfg.hkey)
        #connect to JobManager running on (remote) server and create a tunnel to it
        self.thermalJobMan = PyroUtil.connectJobManager(
            ns, cfg.jobManName, cfg.hkey)
        self.thermal = None

        try:
            self.thermal = PyroUtil.allocateApplicationWithJobManager(
                ns, self.thermalJobMan, cfg.jobNatPorts[0], cfg.hkey,
                PyroUtil.SSHContext(sshClient=cfg.sshClient,
                                    options=cfg.options,
                                    sshHost=cfg.sshHost))
            log.info(self.thermal)
            #self.thermal = PyroUtil.allocateApplicationWithJobManager( ns, self.thermalJobMan, jobNatport )
        except Exception as e:
            log.exception(e)

        appsig = self.thermal.getApplicationSignature()
        log.info("Working thermal server " + appsig)
        self.mechanical = PyroUtil.connectApp(ns, 'mechanical')
        appsig = self.mechanical.getApplicationSignature()
        log.info("Working mechanical server " + appsig)
예제 #10
0
파일: Workflow.py 프로젝트: xyuan/mupif
    def solve(self, runInBackground=False):
        """ 
        Solves the workflow.

        The default implementation solves the problem
        in series of time steps using solveStep method (inheritted) until the final time is reached.

        :param bool runInBackground: optional argument, default False. If True, the solution will run in background (in separate thread or remotely).

        """
        time = PQ.PhysicalQuantity(0., timeUnits)
        timeStepNumber = 0

        while (abs(time.inUnitsOf(timeUnits).getValue()-self.targetTime.inUnitsOf(timeUnits).getValue()) > 1.e-6):
            dt = self.getCriticalTimeStep()
            time=time+dt
            if (time > self.targetTime):
                         time = self.targetTime
            timeStepNumber = timeStepNumber+1
            istep=TimeStep.TimeStep(time, dt, self.targetTime, n=timeStepNumber)
        
            log.debug("Step %g: t=%g dt=%g"%(timeStepNumber,time.inUnitsOf(timeUnits).getValue(),dt.inUnitsOf(timeUnits).getValue()))

            self.solveStep(istep)
            self.finishStep(istep)
        self.terminate()
예제 #11
0
    def __init__(self, targetTime=PQ.PhysicalQuantity('1 s')):
        super(Demo06, self).__init__(file='',
                                     workdir='',
                                     targetTime=targetTime)

        #locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost,
                                        nsport=cfg.nsport,
                                        hkey=cfg.hkey)
        #connect to JobManager running on (remote) server and create a tunnel to it
        self.jobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey)
        log.info('Connected to JobManager')
        self.app1 = None

        try:
            self.app1 = PyroUtil.allocateApplicationWithJobManager(
                ns, self.jobMan, cfg.jobNatPorts[0], cfg.hkey,
                PyroUtil.SSHContext(sshClient=cfg.sshClient,
                                    options=cfg.options,
                                    sshHost=cfg.sshHost))
            log.info(self.app1)
        except Exception as e:
            log.exception(e)

            appsig = self.app1.getApplicationSignature()
            log.info("Working application 1 on server " + appsig)
예제 #12
0
    def initialize(self,
                   file='',
                   workdir='',
                   targetTime=PQ.PhysicalQuantity(0., 's'),
                   metaData={},
                   validateMetaData=True,
                   **kwargs):
        """
        Initializes application, i.e. all functions after constructor and before run.
        
        :param str file: Name of file
        :param str workdir: Optional parameter for working directory
        :param PhysicalQuantity targetTime: target simulation time
        :param dict metaData: Optional dictionary used to set up metadata (can be also set by setMetadata() )
        :param bool validateMetaData: Defines if the metadata validation will be called
        :param named_arguments kwargs: Arbitrary further parameters
        """
        self.updateMetadata(metaData)

        # print (targetTime)
        if PQ.isPhysicalQuantity(targetTime):
            self.targetTime = targetTime
        else:
            raise TypeError('targetTime is not PhysicalQuantity')

        self.file = file
        if workdir == '':
            self.workDir = os.getcwd()
        else:
            self.workDir = workdir

        if validateMetaData:
            self.validateMetadata(WorkflowSchema)
예제 #13
0
파일: Example16.py 프로젝트: xyuan/mupif
    def __init__(self, targetTime=PQ.PhysicalQuantity(0., 's')):
        """
        Initializes the workflow. As the workflow is non-stationary, we allocate individual 
        applications and store them within a class.
        """
        super(Demo16, self).__init__(file='',
                                     workdir='',
                                     targetTime=targetTime)
        #locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost,
                                        nsport=cfg.nsport,
                                        hkey=cfg.hkey)
        #connect to JobManager running on (remote) server
        self.thermalJobMan = PyroUtil.connectJobManager(
            ns, cfg.jobManName, cfg.hkey)
        self.thermal = None
        self.mechanical = None

        try:
            self.thermal = PyroUtil.allocateApplicationWithJobManager(
                ns, self.thermalJobMan, cfg.jobNatPorts[0], cfg.hkey,
                PyroUtil.SSHContext(sshClient=cfg.sshClient,
                                    options=cfg.options,
                                    sshHost=cfg.sshHost))
            log.info('Created thermal job')
        except Exception as e:
            log.exception(e)

        self.mechanical = PyroUtil.connectApp(ns, 'mechanical')

        thermalSignature = self.thermal.getApplicationSignature()
        log.info("Working thermal server " + thermalSignature)
        mechanicalSignature = self.mechanical.getApplicationSignature()
        log.info("Working mechanical server " + mechanicalSignature)
예제 #14
0
 def setProperty(self, property, objectID=0):
     if (property.getPropertyID() == PropertyID.PID_UserTimeStep):
         # remember the mapped value
         self.userDT = PQ.PhysicalQuantity(property.getValue()[0],
                                           property.getUnits())
     else:
         raise APIError.APIError('Unknown property ID')
예제 #15
0
    def __init__(self, targetTime=PQ.PhysicalQuantity('0 s')):
        super(Demo03, self).__init__(file='',
                                     workdir='',
                                     targetTime=targetTime)

        self.app1 = application1(None)
        self.app3 = application3(None)
예제 #16
0
    def initialize(self,
                   file='',
                   workdir='',
                   targetTime=PQ.PhysicalQuantity('0 s'),
                   metaData={},
                   validateMetaData=True,
                   **kwargs):
        super(Example06, self).initialize(file=file,
                                          workdir=workdir,
                                          targetTime=targetTime,
                                          metaData=metaData,
                                          validateMetaData=validateMetaData,
                                          **kwargs)

        passingMD = {
            'Execution': {
                'ID': self.getMetadata('Execution.ID'),
                'Use_case_ID': self.getMetadata('Execution.Use_case_ID'),
                'Task_ID': self.getMetadata('Execution.Task_ID')
            }
        }

        self.thermalSolver.initialize('inputT10.in', '.', metaData=passingMD)
        self.mechanicalSolver.initialize('inputM10.in',
                                         '.',
                                         metaData=passingMD)
예제 #17
0
    def test_Init(self):

        time = 0.0
        dt = 0.5
        targetTime = 2.0
        timestepnumber = 0

        try:
            istep = TimeStep.TimeStep(time, dt, time + dt, None,
                                      timestepnumber)
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')

        time = PQ.PhysicalQuantity('0.0 s')
        try:
            istep = TimeStep.TimeStep(time, dt, targetTime, None,
                                      timestepnumber)
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')

        dt = PQ.PhysicalQuantity('0.5 s')

        try:
            istep = TimeStep.TimeStep(time, dt, targetTime, None,
                                      timestepnumber)
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')

        time = 0.0
        dt = 0.5
        targetTime = 2.0
        timestepnumber = 0

        # @todo what sould this do?
        istep = TimeStep.TimeStep(time, dt, time + dt, 'm', timestepnumber)
예제 #18
0
    def __init__(self, targetTime=PQ.PhysicalQuantity(3., 's')):
        super(Demo13, self).__init__(file='',
                                     workdir='',
                                     targetTime=targetTime)

        self.thermal = demoapp.thermal_nonstat('inputT13.in', '.')
        self.mechanical = demoapp.mechanical('inputM13.in', '.')
        self.matPlotFig = None
예제 #19
0
 def initialize(self,
                file='',
                workdir='',
                targetTime=PQ.PhysicalQuantity(0., 's'),
                metaData={},
                validateMetaData=True,
                **kwargs):
     super(Workflow02, self).initialize(file, workdir, targetTime, metaData,
                                        validateMetaData, **kwargs)
예제 #20
0
def main():

    # generate field and corresponding mesh
    mesh = Mesh.UnstructuredMesh()
    vertices=[]
    values1 = []
    values2 = []
    num=0
    for i in range(40):
        for j in range (15):
            vertices.append(Vertex.Vertex((i*15)+j,(i*15)+j+1, (float(i),float(j),0.0)))
            values1.append((num,))
            num+=0.5
    cells = []
    num=0
    for i in range(39):
        for j in range (14):
            cells.append(Cell.Quad_2d_lin(mesh, num, num, ((i*15)+j, (i+1)*15+j, (i+1)*15+j+1, ((i*15)+j+1))))
            values2.append((num,))
            num+=1

    mesh.setup(vertices, cells)

    #Check saving a mesh
    mesh.dumpToLocalFile('mesh.dat')
    Mesh.Mesh.loadFromLocalFile('mesh.dat')

    time = PQ.PhysicalQuantity(1.0, 's')
    # field1 is vertex based, i.e., field values are provided at vertices
    field1 = Field.Field(mesh, FieldID.FID_Temperature, ValueType.Scalar, temperatureUnit, time, values1)
    #field1.field2Image2D(title='Field', barFormatNum='%.0f')
    # field2 is cell based, i.e., field values are provided for cells
    field2 = Field.Field(mesh, FieldID.FID_Temperature, ValueType.Scalar, temperatureUnit, time, values2, Field.FieldType.FT_cellBased)

    # evaluate field at given point
    position=(20.1, 7.5, 0.0)
    value1=field1.evaluate(position) #correct answer 154.5
    log.debug("Field1 value at position "+str(position)+" is "+str(value1))
    position=(20.1, 8.5, 0.0)
    value2=field2.evaluate(position) #correct answer 287.0
    log.debug("Field2 value at position "+str(position)+" is "+str(value2))

    field1.field2VTKData().tofile('example1')
    field2.field2VTKData().tofile('example2')

    #Test pickle module - serialization
    field1.dumpToLocalFile('field.dat')
    field3 = Field.Field.loadFromLocalFile('field.dat')
    position=(20.1, 9.5, 0.0)
    value3 = field3.evaluate(position) #correct answer 155.5

    if ((abs(value1.getValue()[0]-154.5) <= 1.e-4) and (abs(value2.getValue()[0]-288.0) <= 1.e-4) and (abs(value3.getValue()[0]-155.5) <= 1.e-4)):
        log.info("Test OK")
    else:
        log.error("Test FAILED")
        import sys
        sys.exit(1)
예제 #21
0
 def test_Rpow(self):
     F = PQ.PhysicalQuantity('2 m')
     try:
         A = 2**F
     except TypeError:
         pass
     except Exception as e:
         self.fail('Unexpected exception raised:', e)
     else:
         self.fail('Exception not raised')
예제 #22
0
 def __init__(self, metaData={}):
     MD = {
         'Name':
         'Simple application cummulating time steps',
         'ID':
         'N/A',
         'Description':
         'Cummulates time steps',
         'Physics': {
             'Type': 'Other',
             'Entity': 'Other'
         },
         'Solver': {
             'Software': 'Python script',
             'Language': 'Python3',
             'License': 'LGPL',
             'Creator': 'Borek',
             'Version_date': '02/2019',
             'Type': 'Summator',
             'Documentation': 'Nowhere',
             'Estim_time_step_s': 1,
             'Estim_comp_time_s': 0.01,
             'Estim_execution_cost_EUR': 0.01,
             'Estim_personnel_cost_EUR': 0.01,
             'Required_expertise': 'None',
             'Accuracy': 'High',
             'Sensitivity': 'High',
             'Complexity': 'Low',
             'Robustness': 'High'
         },
         'Inputs': [{
             'Type': 'mupif.Property',
             'Type_ID': 'mupif.PropertyID.PID_Time_step',
             'Name': 'Time step',
             'Description': 'Time step',
             'Units': 's',
             'Origin': 'Simulated',
             'Required': True
         }],
         'Outputs': [{
             'Type': 'mupif.Property',
             'Type_ID': 'mupif.PropertyID.PID_Time',
             'Name': 'Cummulative time',
             'Description': 'Cummulative time',
             'Units': 's',
             'Origin': 'Simulated'
         }]
     }
     super(application2, self).__init__(metaData=MD)
     self.updateMetadata(metaData)
     self.value = 0.0
     self.count = 0.0
     self.contrib = Property.ConstantProperty((0., ), PropertyID.PID_Time,
                                              ValueType.Scalar, 's',
                                              PQ.PhysicalQuantity(0., 's'))
예제 #23
0
    def test_SumFail(self):
        V = PQ.PhysicalQuantity('3.6 km/h')
        F = PQ.PhysicalQuantity('20 N')
        try:
            V._sum(F, 1, 1)
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:',e)
        else:
            self.fail('Exception not raised')

        try:
            V._sum(10, 1, 1)
        except TypeError:
            pass
        except Exception as e:
            self.fail('Unexpected exception raised:', e)
        else:
            self.fail('Exception not raised')
예제 #24
0
    def __init__(self, t, dt, targetTime, units=None, n=1):
        """
        Initializes time step.

        :param t: Time(time at the end of time step)
        :type t: PQ.PhysicalQuantity
        :param dt: Step length (time increment), type depends on 'units'
        :type dt: PQ.PhysicalQuantity
        :param targetTime: target simulation time (time at the end of simulation, not of a single TimeStep)
        :type targetTime: PQ.PhysicalQuantity. targetTime is not related to particular time step rather to the material model (load duration, relaxation spectra etc.)
        :param PQ.PhysicalUnit or str units: optional units for t, dt, targetTime if given as float values
        :param int n: Optional, solution time step number, default = 1
        """
        self.number = n  # solution step number, dimensionless

        if units is None:
            if not PQ.isPhysicalQuantity(t):
                raise TypeError(str(t) + ' is not physical quantity')

            if not PQ.isPhysicalQuantity(dt):
                raise TypeError(str(dt) + ' is not physical quantity')

            if not PQ.isPhysicalQuantity(targetTime):
                raise TypeError(str(targetTime) + ' is not physical quantity')

            self.time = t
            self.dt = dt
            self.targetTime = targetTime
        else:
            if PQ.isPhysicalUnit(units):
                units_temp = units
            else:
                units_temp = PQ.findUnit(units)

            self.time = PQ.PhysicalQuantity(t, units_temp)
            self.dt = PQ.PhysicalQuantity(dt, units_temp)
            self.targetTime = PQ.PhysicalQuantity(targetTime, units_temp)
예제 #25
0
    def initialize(self, file='', workdir='', targetTime=PQ.PhysicalQuantity(0., 's'), metaData={}, validateMetaData=True, **kwargs):
        # locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost, nsport=cfg.nsport, hkey=cfg.hkey)    
        # connect to JobManager running on (remote) server
        self.thermalJobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey)
        
        try:
            self.thermal = PyroUtil.allocateApplicationWithJobManager(
                ns, self.thermalJobMan,
                cfg.jobNatPorts[0],
                cfg.hkey, PyroUtil.SSHContext(sshClient=cfg.sshClient, options=cfg.options, sshHost=cfg.sshHost)
            )
            log.info('Created thermal job')
        except Exception as e:
            log.exception(e)
            self.terminate()

        # Connecting directly to mechanical instance, not using jobManager
        self.mechanical = PyroUtil.connectApp(ns, 'mechanical', cfg.hkey)

        thermalSignature = self.thermal.getApplicationSignature()
        log.info("Working thermal server " + thermalSignature)
        mechanicalSignature = self.mechanical.getApplicationSignature()
        log.info("Working mechanical server " + mechanicalSignature)

        super(Example08, self).initialize(file=file, workdir=workdir, targetTime=targetTime, metaData=metaData, validateMetaData=validateMetaData, **kwargs)

        # To be sure update only required passed metadata in models
        passingMD = {
            'Execution': {
                'ID': self.getMetadata('Execution.ID'),
                'Use_case_ID': self.getMetadata('Execution.Use_case_ID'),
                'Task_ID': self.getMetadata('Execution.Task_ID')
            }
        }

        pf = self.thermalJobMan.getPyroFile(self.thermal.getJobID(), "inputT.in", 'wb')
        PyroUtil.uploadPyroFile('..'+os.path.sep+'Example06-stacTM-local'+os.path.sep+'inputT10.in', pf, cfg.hkey)

        self.thermal.initialize(
            file='inputT.in',
            workdir=self.thermalJobMan.getJobWorkDir(self.thermal.getJobID()),
            metaData=passingMD
        )
        self.mechanical.initialize(
            file='..' + os.path.sep + 'Example06-stacTM-local' + os.path.sep + 'inputM10.in',
            workdir='.',
            metaData=passingMD
        )
예제 #26
0
    def __init__(self, targetTime=PQ.PhysicalQuantity('1 s')):
        """
		Initializes the workflow. As the workflow is non-stationary, we allocate individual 
		applications and store them within a class.
		"""
        super(INSAWorkflow, self).__init__(file='',
                                           workdir='',
                                           targetTime=targetTime)
        #list of recognized input porperty IDs
        self.myInputPropIDs = [
            PropertyID.PID_ExtensionalInPlaneStiffness,
            PropertyID.PID_ExtensionalOutOfPlaneStiffness,
            PropertyID.PID_ShearInPlaneStiffness,
            PropertyID.PID_ShearOutOfPlaneStiffness,
            PropertyID.PID_LocalBendingStiffness
        ]
        # list of compulsory IDs
        self.myCompulsoryPropIDs = self.myInputPropIDs
        #list of recognized output property IDs
        self.myOutPropIDs = [PropertyID.PID_CriticalLoadLevel]
        #dictionary of input properties (values)
        self.myInputProps = {}
        #dictionary of output properties (values)
        self.myOutProps = {}
        self.mesh = None
        self.displacement = None
        self.fibreOrientation = None
        self.domainNumber = None
        #locate nameserver
        ns = PyroUtil.connectNameServer(nshost=Cfg.nshost,
                                        nsport=Cfg.nsport,
                                        hkey=Cfg.hkey)
        self.JobMan = PyroUtil.connectJobManager(ns, Cfg.jobManName, Cfg.hkey)
        self.INSASolver = None
        #allocate the application instances
        try:
            self.INSASolver = PyroUtil.allocateApplicationWithJobManager(
                ns, self.JobMan, None, Cfg.hkey, sshContext=None)
            log.info('Created INSA job')
        except Exception as e:
            log.exception(e)
        else:
            if (self.INSASolver is not None):
                INSASolverSignature = self.INSASolver.getApplicationSignature()
                log.info("Working INSA solver on server " +
                         INSASolverSignature)
            else:
                log.debug("Connection to server failed, exiting")
예제 #27
0
파일: Example11.py 프로젝트: xyuan/mupif
    def __init__ (self, targetTime=PQ.PhysicalQuantity('0 s')):
        """
        Initializes the workflow. As the workflow is non-stationary, we allocate individual 
        applications and store them within a class.
        """
        super(Demo11, self).__init__(file='', workdir='', targetTime=targetTime)

        #locate nameserver
        ns = PyroUtil.connectNameServer(nshost=cfg.nshost, nsport=cfg.nsport, hkey=cfg.hkey)
        #connect to JobManager running on (remote) server
        if(mode == 1):
            self.thermalJobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey, PyroUtil.SSHContext(userName = cfg.serverUserName,sshClient=cfg.sshClient, options=cfg.options, sshHost=cfg.sshHost) )
            self.mechanicalJobMan = PyroUtil.connectJobManager(ns,mCfg.jobManName, cfg.hkey,PyroUtil.SSHContext(userName = mCfg.serverUserName, sshClient=mCfg.sshClient, options=mCfg.options, sshHost=mCfg.sshHost) )
        else:
            self.thermalJobMan = PyroUtil.connectJobManager(ns, cfg.jobManName, cfg.hkey)
            self.mechanicalJobMan = PyroUtil.connectJobManager(ns, mCfg.jobManName, cfg.hkey)

        self.thermalSolver = None
        self.mechanicalSolver = None

        #allocate the application instances
        try:
            self.thermalSolver = PyroUtil.allocateApplicationWithJobManager( ns, self.thermalJobMan, cfg.jobNatPorts[0], cfg.hkey, PyroUtil.SSHContext(userName = cfg.serverUserName,sshClient=cfg.sshClient, options=cfg.options, sshHost=cfg.sshHost) )
            log.info('Created thermal job')
            self.mechanicalSolver = PyroUtil.allocateApplicationWithJobManager( ns, self.mechanicalJobMan, mCfg.jobNatPorts[0], mCfg.hkey, PyroUtil.SSHContext(userName = mCfg.serverUserName,sshClient=mCfg.sshClient, options=mCfg.options, sshHost=mCfg.sshHost ))
            log.info('Created mechanical job')
            log.info('Creating reverse tunnel')
            
            #Create a reverse tunnel so mechanical server can access thermal server directly
            self.appsTunnel = PyroUtil.connectApplicationsViaClient(PyroUtil.SSHContext(userName = mCfg.serverUserName, sshClient=mCfg.sshClient, options=mCfg.options, sshHost=PyroUtil.getNSConnectionInfo(ns, mCfg.jobManName)[0]), self.mechanicalSolver, self.thermalSolver)
        except Exception as e:
            log.exception(e)
        else:
            if ((self.thermalSolver is not None) and (self.mechanicalSolver is not None)):
                thermalSolverSignature=self.thermalSolver.getApplicationSignature()
                log.info("Working thermal solver on server " + thermalSolverSignature)

                mechanicalSolverSignature=self.mechanicalSolver.getApplicationSignature()
                log.info("Working mechanical solver on server " + mechanicalSolverSignature)

                log.info("Uploading input files to servers")
                pf = self.thermalJobMan.getPyroFile(self.thermalSolver.getJobID(), "input.in", 'wb')
                PyroUtil.uploadPyroFile("inputT.in", pf, cfg.hkey)
                mf = self.mechanicalJobMan.getPyroFile(self.mechanicalSolver.getJobID(), "input.in", 'wb')
                PyroUtil.uploadPyroFile("inputM.in", mf, mCfg.hkey)
            else:
                log.debug("Connection to server failed, exiting")
예제 #28
0
 def test_TrueDiv(self):
     # division with a number
     len = PQ.PhysicalQuantity('1 m')
     len2 = len / 2
     lenTest = PQ.PhysicalQuantity('0.5 m')
     self.assertEqual(len2, lenTest)
     # division with a physical quantity without units
     len = PQ.PhysicalQuantity('1 m')
     len2 = PQ.PhysicalQuantity('2 none')
     lenTest1 = len / len2
     lenTest2 = PQ.PhysicalQuantity('0.5 m')
     self.assertEqual(lenTest1, lenTest2)
     # division with a physical quantity with units
     len = PQ.PhysicalQuantity('1 m')
     time = PQ.PhysicalQuantity('2 s')
     w = len / time
     ms = PQ.PhysicalQuantity('0.5 m/s')
     self.assertEqual(w, ms)
예제 #29
0
    def test_Mul(self):
        # multiplication with a number
        len = PQ.PhysicalQuantity('1 m')
        len2 = 2*len
        lenTest = PQ.PhysicalQuantity('2 m')
        self.assertEqual(len2, lenTest)
        # multiplication with a physical quantity without units
        len = PQ.PhysicalQuantity('1 m')
        len2 = PQ.PhysicalQuantity('2 none')
        lenTest1 = len*len2
        lenTest2 = PQ.PhysicalQuantity('2 m')
        self.assertEqual(lenTest1, lenTest2)
        # multiplication with a physical quantity with units
        len = PQ.PhysicalQuantity('1 m')
        time = PQ.PhysicalQuantity('2 s')
        w = len*time
        ms = PQ.PhysicalQuantity('2 m*s')
        self.assertEqual(w,ms)

        w = len * 5
        len5 = PQ.PhysicalQuantity('5 m')
        self.assertEqual(w, len5)
예제 #30
0
    def initialize(self,
                   file='',
                   workdir='',
                   targetTime=PQ.PhysicalQuantity('1 s'),
                   metaData={},
                   validateMetaData=True,
                   **kwargs):
        super().initialize(targetTime=targetTime, metaData=metaData)

        passingMD = {
            'Execution': {
                'ID': self.getMetadata('Execution.ID'),
                'Use_case_ID': self.getMetadata('Execution.Use_case_ID'),
                'Task_ID': self.getMetadata('Execution.Task_ID')
            }
        }
        self.app1.initialize(metaData=passingMD)