Пример #1
0
#!/usr/bin/env python
#coding=utf-8
import onelab

modelName = 'coin'

OL = onelab.client()
print('\nStarting METAMODEL - Action = %s' % (OL.getString('python/Action')))

print __file__

A = OL.defineNumber('A', value=10)
B = OL.defineNumber('Group/B', value=0, min=-10, max=10, step=1)
C = OL.defineNumber('Group/C',
                    value=2,
                    choices=[0, 1, 2, 3],
                    attributes={'Highlight': 'Pink'})
D = OL.defineNumber('Group/D',
                    value=3,
                    labels={
                        0: 'zero',
                        1: 'un',
                        2: 'deux',
                        3: 'trois'
                    },
                    attributes={'Highlight': 'Blue'})

OL.reloadGeometry(modelName + '.geo')
OL.preProcess(modelName + '.txt.ol')

if OL.action == 'compute':
Пример #2
0
Файл: sub.py Проект: bbboco/gmsh
#!/usr/bin/env python
# coding=utf-8

import onelab

OL = onelab.client()

A = OL.getNumber("A")
print "A= %f" % (A)
OL.setNumber("Group/B", value=20)
Пример #3
0
#!/bin/python

## Imports
import onelab
import numpy

## ONELAB
ol = onelab.client()

## Gmsh geometry
ol.openProject('cavity_haroche_2D.geo')
freq   = float(ol.getNumber(name = 'Input/00Haroche/00Frequency'))
target = (freq * 2 * numpy.pi) ** 2

## For remote mesh
S_PML = int(ol.getNumber(name = 'Input/01Geometry/00PML size'))
D_PML = int(ol.getNumber(name = 'Input/01Geometry/01PML distance'))
MSH_A = int(ol.getNumber(name = 'Input/02Mesh/00Size Air'))
MSH_P = int(ol.getNumber(name = 'Input/02Mesh/00Size PML'))
MSH_M = int(ol.getNumber(name = 'Input/02Mesh/00Size Mirror'))
ORDER = int(ol.getNumber(name = 'Input/02Mesh/01Order'))
TYPE  = int(ol.getNumber(name = 'Input/02Mesh/02Type'))

## Get SmallFEM data
femOrder = ol.defineNumber(name = 'Input/03FEM/00Order',        value = 1)
nEig     = ol.defineNumber(name = 'Input/03FEM/01Eigenvalue',   value = 4)
sym      = ol.defineNumber(name = 'Input/03FEM/02Symmetry',     choices = {0,1})
nProc    = ol.defineNumber(name = 'Input/04Solver/00Process',   value = 12)
tol      = ol.defineNumber(name = 'Input/04Solver/01Tolerance', value = 1e-6)
maxit    = ol.defineNumber(name = 'Input/04Solver/02Iteration', value = 10000)
postpro  = ol.defineNumber(name = 'Input/05Post-Pro/00Draw',    choices = {0,1})
Пример #4
0
#!/usr/bin/env python
#coding=utf-8

# 1) Launch "gmsh pend.py", or open "pend.py" with Gmsh's File->Open menu
# 2) Click on "Run" in the left Gmsh panel
# 3) there is no number 3... :-)

# To interact with ONELAB, the script must first import the onelab.py module:
import onelab
import math, os

# The script then creates a ONELAB client with:
c = onelab.client(__file__)

# Creating the client connects the script to the onelab server, through a
# socket. The __file__ argument is a python variable. It tells ONELAB in which
# directory the script being executed is located.


def exportMsh(le1, le2):
    mshFile = open(c.getPath("pend.msh"), 'w')
    mshFile.write('$MeshFormat\n2.2 0 8\n$EndMeshFormat\n')
    mshFile.write('$Nodes\n3\n1 0 0 0\n2 0 %s 0\n3 0 %s 0\n$EndNodes\n' %
                  (-le1, -le1 - le2))
    mshFile.write(
        '$Elements\n3\n1 1 2 0 1 1 2\n2 1 2 0 1 2 3\n3 15 2 0 2 3\n$EndElements\n'
    )
    mshFile.close()


def exportMshOpt():
Пример #5
0
#!/usr/bin/env python
#coding=utf-8

# 1) launch "gmsh pend.py"
# 2) there is no 2... :-)

import onelab
import math, os

c = onelab.client(__file__)

def exportMsh(le1,le2):
   mshFile = open(c.getPath("pend.msh"), 'w')
   mshFile.write('$MeshFormat\n2.2 0 8\n$EndMeshFormat\n')
   mshFile.write('$Nodes\n3\n1 0 0 0\n2 0 %s 0\n3 0 %s 0\n$EndNodes\n' %(-le1, -le1-le2))
   mshFile.write('$Elements\n3\n1 1 2 0 1 1 2\n2 1 2 0 1 2 3\n3 15 2 0 2 3\n$EndElements\n')
   mshFile.close()

def exportMshOpt():
   optFile = open(c.getPath("pend.msh.opt"),'w')
   optFile.write('n = PostProcessing.NbViews - 1;\n')
   optFile.write('If(n >= 0)\nView[n].ShowScale = 0;\nView[n].VectorType = 5;\n')
   optFile.write('View[n].ExternalView = 0;\nView[n].DisplacementFactor = 1 ;\n')
   optFile.write('View[n].PointType = 1;\nView[n].PointSize = 5;\n')
   optFile.write('View[n].LineWidth = 2;\nEndIf\n')
   optFile.close()

def exportIter(iter,t,x1,y1,x2,y2):
   mshFile = open(c.checkPath("pend.msh"),'a')
   mshFile.write('$NodeData\n1\n"motion"\n1\n\t%f\n3\n\t%d\n3\n' % (t, iter))
   mshFile.write('\t3\n\t1 0 0 0\n\t2 %f %f 0\n\t3 %f %f 0\n$EndNodeData\n' %(x1,y1,x2,y2))
Пример #6
0
    printCurrIterate(clientOnelab, printTerminal, xval, fval, change, loop,
                     opt)
    printCurrIterate(clientOnelab, printGmsh, xval, fval, change, loop, opt)

    # output data
    xopt = np.copy(xval)
    objOpt = np.copy(fval[0])
    constrOpt = np.copy(fval[1:])

    return xopt, objOpt, constrOpt


if __name__ == "__main__":

    # Create a onelab client
    clientOnelab = onelab.client(__file__)
    if clientOnelab.action == 'check': exit(0)

    # Set options for both optimization problem and CAD/FEM model
    options = setOptions(
        clientOnelab, {
            'CADFEMOptions': {
                'Input/Geometry/00Mesh size factor': 1,
                'Input/0Type of analysis': 0,
                'Optimization/Desired fundamental frequency [Hz]': 2.5e05
            },
            'file': clientOnelab.getPath('magnetometer'),
            'structuredGrid': 1,
            'resolution': 'Analysis',
            'objective': 'Output/diffEigenFreqNorm',
            'constraints': [],