示例#1
0
class statsFileTool(tools.PythonTool):
    name = 'asd'
    inputParameters = {
        'data': process.Parameter(name='data', parameterType='list')
    }
    outputParameters = {
        'mean':
        process.Parameter(name='mean', parameterType='caeml.files.file.File'),
        'max':
        process.Parameter(name='max', parameterType='caeml.files.file.File'),
        'min':
        process.Parameter(name='min', parameterType='caeml.files.file.File')
    }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        data = inputs['data']
        minval = min(data)
        maxval = max(data)
        meanval = sum(data) / len(data)

        with open('min.txt', 'w') as fileWriter:
            fileWriter.write(str(minval) + "\n")

        with open('max.txt', 'w') as fileWriter:
            fileWriter.write(str(maxval) + "\n")

        with open('mean.txt', 'w') as fileWriter:
            fileWriter.write(str(meanval) + "\n")

        return {'min': 'min.txt', 'max': 'max.txt', 'mean': 'mean.txt'}
示例#2
0
class ParaviewSurfaceGridX3DTool(PythonTool):
    name = 'ParaviewSurfaceGridX3DTool'
    inputParameters = {
        'mesh':
        process.Parameter(name='mesh', parameterType='caeml.files.file.File')
    }

    outputParameters = {
        'script_file':
        process.Parameter(name='script_file',
                          parameterType='caeml.files.file.File')
    }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        mesh = inputs['mesh']

        absPath = os.path.abspath(os.path.join('/data', mesh.path))

        env = Environment(
            loader=PackageLoader('pkg_codeaster.tools', 'templates'))

        templatePara = env.get_template('paraview_surfacegrid_template.py')

        with open('surfacegrid_output_script.py', 'w') as file:
            file.write(templatePara.render(input_mesh=absPath))

        return {'script_file': 'surfacegrid_output_script.py'}
示例#3
0
class StepAnalyzer(tools.PythonTool):
    name = 'asd'
    inputParameters = {
        'input_step':
        process.Parameter(name='input_step',
                          parameterType='caeml.files.file.File')
    }
    outputParameters = {
        'step':
        process.Parameter(
            name='step',
            parameterType='pkg_step.data_model.types.StepGeometry')
    }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        helper.runContainer(
            'renumics/python-occ',
            mounts=[helper.dockerMountDict(tmpStore, '/data')],
            args=(
                "python3 /scripts/surfaceGroupsFromColoredStep.py /data/input/"
                + os.path.basename(inputs['input_step'].path)).split(' '))

        yamlFile = open(os.path.join(tmpStore, 'stepMeta.yml'), 'r')
        yml = yaml.load(yamlFile)
        yamlFile.close()
        groups = {v['name']: v['surfaces'] for v in yml['surfaceGroups']}

        #get flat list of all surfaces stored in groups
        # surfaces = [surface for surfaceList in [k for v, k in groups.items()] for surface in surfaceList]
        surfaces = yml['surfaces']

        step = StepGeometry(geomFile=yml['filename'],
                            surfaces=surfaces,
                            surfaceGroups=groups)
        return {'step': step}
示例#4
0
文件: add.py 项目: YKJIN/CAEML
class add(tools.PythonTool):
    name = 'add'
    inputParameters = {'addend1': process.Parameter(name='addend1', parameterType='float'),
                       'addend2': process.Parameter(name='addend2', parameterType='float')}
    outputParameters = {'sum': process.Parameter(name='sum', parameterType='float')}

    def launchCmd(self, inputs, tmpStore, stdout_file):
        return {'sum': inputs['addend1'] + inputs['addend2']}

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
示例#5
0
class statsTool(tools.PythonTool):
    name = 'asd'
    inputParameters = {
        'data': process.Parameter(name='data', parameterType='list')
    }
    outputParameters = {
        'mean': process.Parameter(name='mean', parameterType='float'),
        'max': process.Parameter(name='max', parameterType='float'),
        'min': process.Parameter(name='min', parameterType='float')
    }  # TODO:allow real tpyes

    def launchCmd(self, inputs, tmpStore, stdout_file):
        data = inputs['data']
        minval = min(data)
        maxval = max(data)
        meanval = sum(data) / len(data)
        return {'mean': meanval, 'max': maxval, 'min': minval}
示例#6
0
class CodeAsterStressExtractionTool(PythonTool):
    name = 'CodeAsterStressExtractionTool'
    inputParameters = {'resu_file': process.Parameter(name='mesh', parameterType='caeml.files.file.File'),
                       }
    outputParameters = {'stress_value': process.Parameter(name='comm_file', parameterType='float'),
                        }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        resu_file = inputs['resu_file']

        with open(resu_file.path, 'r') as file:
            content = file.read()

        start = content.find('LA VALEUR MAXIMALE DE INVA_2   EST ') + len('LA VALEUR MAXIMALE DE INVA_2   EST    ')
        end = content.find('EN', start)
        value = float(content[start:end].strip())

        return {'stress_value': value}
示例#7
0
class SurfaceGroupsToGeo(tools.PythonTool):
    name = 'asd'
    inputParameters = {
        'geom_desc':
        process.Parameter(name='geom_desc',
                          parameterType='pkg_step.data_model.types.Geometry')
    }
    outputParameters = {
        'geo_file':
        process.Parameter(name='geo_file',
                          parameterType='caeml.files.file.File')
    }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        inputGeometry = inputs['geom_desc']
        assert isinstance(inputGeometry, Geometry)
        geom = pg.Geometry()
        geom.add_merge(inputGeometry.geomFile)
        surfaces = [
            surface_base.SurfaceBase(item) for item in inputGeometry.surfaces
        ]
        loop = geom.add_surface_loop(surfaces)
        geom.add_volume(loop)

        for group in inputGeometry.surfaceGroups:
            surfaces = []
            for surface in group.surfaceIds:
                surfaces.append(surface_base.SurfaceBase(surface))
            geom.add_physical_surface(surfaces, label=group.name)

        out = geom.get_code()
        with open(tmpStore + '/test.geo', 'w') as f:
            f.write(out)
        logging.getLogger('process_data').debug(
            'Writing: {}'.format(tmpStore + '/test.geo'))
        return {'geo_file': os.path.join(tmpStore + '/test.geo')}
示例#8
0
class CodeAsterBeamDemoTool(PythonTool):
    name = 'codeAsterBeamDemo'
    inputParameters = {
        'youngs_modulus':
        process.Parameter(name='youngs_modulus', parameterType='float'),
        'mesh':
        process.Parameter(name='mesh', parameterType='caeml.files.file.File'),
        'force':
        process.Parameter(name='force', parameterType='float'),
    }
    outputParameters = {
        'comm_file':
        process.Parameter(name='comm_file',
                          parameterType='caeml.files.file.File'),
        'export_file':
        process.Parameter(name='export_file',
                          parameterType='caeml.files.file.File'),
    }

    def launchCmd(self, inputs, tmpStore, stdout_file):
        mesh = inputs['mesh']

        this_folder = os.path.dirname(__file__)
        aModel = CodeAster_commFile_Model(
            os.path.join(this_folder, 'templates/comm/comm_beam.comm'))

        beam_data_model_dict = aModel.beam_data_model.asDict()

        # build .comm file
        material_defintions = [
            p for p in beam_data_model_dict['paragraphs'].paragraphs
            if p.operator_name == 'DEFI_MATERIAU'
        ]
        youngs = material_defintions[
            0].keyword_arguments.findValueForKeyRecursive('E').expression
        youngs.value = inputs['youngs_modulus']
        meca_def = [
            p for p in beam_data_model_dict['paragraphs'].paragraphs
            if p.operator_name == 'AFFE_CHAR_MECA'
        ]
        FY = meca_def[0].keyword_arguments.findValueForKeyRecursive(
            'FY').expression
        FY.value = inputs['force']

        output = beam_data_model_dict['paragraphs'].ca_repr()

        with open('beam_bending_aster.comm', 'w') as file:
            file.write(output)

        # build .export file
        env = Environment(
            loader=PackageLoader('pkg_codeaster.tools', 'templates'))
        templateExport = env.get_template('export_template.export')
        with open('beam_bending_aster.export', 'w') as file:
            file.write(templateExport.render(input_deck='F comm /data/input/beam_bending_aster.comm D  1', \
                                             input_mesh='F mmed /data/' + mesh.path + ' D  20', \
                                             output_1='F mess /data/output.mess R  6', \
                                             output_2='F resu /data/output.resu R  8', \
                                             output_3='F rmed /data/output.rmed R  80', \
                                             output_4='R base /data/output.base RC 0'))

        return {
            'comm_file': 'beam_bending_aster.comm',
            'export_file': 'beam_bending_aster.export'
        }
示例#9
0
class MeshGeoGmsh(tools.PythonTool):
    name = 'asd'
    inputParameters = {'geo': process.Parameter(name='geo', parameterType='caeml.files.file.File'),
                       'mergedFile': process.Parameter(name='mergedFile', parameterType='caeml.files.file.File'),
                       'clscale': process.Parameter(name='clscale', parameterType='float')}
    outputParameters = {'med': process.Parameter(name='med', parameterType='caeml.files.file.File'),
                        'mesh': process.Parameter(name='mesh', parameterType='caeml.files.file.File'),
                        'msh': process.Parameter(name='msh', parameterType='caeml.files.file.File'),
                        'ply2': process.Parameter(name='ply2', parameterType='caeml.files.file.File'),
                        'stl': process.Parameter(name='stl', parameterType='caeml.files.file.File'),
                        'unv': process.Parameter(name='unv', parameterType='caeml.files.file.File'),
                        'vrml': process.Parameter(name='vrml', parameterType='caeml.files.file.File'),
                        'elemCount': process.Parameter(name='elem_count', parameterType='int'),
                        'vertCount': process.Parameter(name='vert_count', parameterType='int')}

    def launchCmd(self, inputs, tmpStore, stdout_file):

        gmshCommand = "gmsh -3 {} -v 10 -clscale {:f} -o /data/mesh.msh".format('/data/input/' + os.path.basename(inputs['geo'].path),
                                                                               inputs['clscale'])

        helper.runContainer('renumics/gmsh', mounts=[helper.dockerMountDict(tmpStore, '/data')],
                            args=gmshCommand.split(' '), stdout_file=stdout_file)

        with open(stdout_file, 'r') as stdoutF:
            res = stdoutF.read()

        regexp = re.compile('(\d+) vertices (\d+) elements')
        m = re.findall(regexp, res)
        vertsCount = m[-1][0]
        elemCount = m[-1][1]

        # convert to other output files
        gmshCommand = "gmsh /data/mesh.msh /scripts/convert -"

        helper.runContainer('renumics/gmsh', mounts=[helper.dockerMountDict(tmpStore, '/data')],
                            args=gmshCommand.split(' '), stdout_file=stdout_file)

        return {'med': os.path.join(tmpStore, 'mesh.med'),
                'mesh': os.path.join(tmpStore, 'mesh.mesh'),
                'msh': os.path.join(tmpStore, 'mesh.msh'),
                'ply2': os.path.join(tmpStore, 'mesh.ply2'),
                'stl': os.path.join(tmpStore, 'mesh.stl'),
                'unv': os.path.join(tmpStore, 'mesh.unv'),
                'vrml': os.path.join(tmpStore, 'mesh.vrml'),
                'elemCount': elemCount, 'vertCount': vertsCount}