Ejemplo n.º 1
0
def importFlavia(fn=None):
    """Import a flavia file and select it as the current results.

    Flavia files are the postprocessing format used by GiD pre- and
    postprocessor, and can also be written by the FE program calix.
    There usually are two files named 'BASE.flavia.msh' and 'BASE.flavia.res'
    which hold the FE mesh and results, respectively.

    This functions asks the user to select a flavia file (either mesh or
    results), will then read both the mesh and corrseponding results files,
    and store the results in a FeResult instance, which will be set as the
    current results database for the postprocessing menu.
    """
    from plugins.flavia import readFlavia
    if fn is None:
        types = [utils.fileDescription('flavia'), utils.fileDescription('all')]
        fn = askFilename(pf.cfg['workdir'], types)
    if fn:
        chdir(fn)
        if fn.endswith('.msh'):
            meshfile = fn
            resfile = utils.changeExt(fn, 'res')
        else:
            resfile = fn
            meshfile = utils.changeExt(fn, 'msh')

        db = readFlavia(meshfile, resfile)
        if not isinstance(db, FeResult):
            warning(
                "!Something went wrong during the import of the flavia database %s"
                % fn)
            return

        ### ok: export and select the DB
        name = os.path.splitext(os.path.basename(fn))[0].replace('.flavia', '')
        export({name: db})
        db.printSteps()
        print(db.R)
        print(db.datasize)

        selection.set([name])
        selectDB(db)
Ejemplo n.º 2
0
def importFlavia(fn=None):
    """Import a flavia file and select it as the current results.

    Flavia files are the postprocessing format used by GiD pre- and
    postprocessor, and can also be written by the FE program calix.
    There usually are two files named 'BASE.flavia.msh' and 'BASE.flavia.res'
    which hold the FE mesh and results, respectively.
    
    This functions asks the user to select a flavia file (either mesh or
    results), will then read both the mesh and corrseponding results files,
    and store the results in a FeResult instance, which will be set as the
    current results database for the postprocessing menu.
    """
    from plugins.flavia import readFlavia
    if fn is None:
        types = [ utils.fileDescription('flavia'), utils.fileDescription('all') ]
        fn = askFilename(pf.cfg['workdir'],types)
    if fn:
        chdir(fn)
        if fn.endswith('.msh'):
            meshfile = fn
            resfile = utils.changeExt(fn,'res')
        else:
            resfile = fn
            meshfile = utils.changeExt(fn,'msh')
            
        db = readFlavia(meshfile,resfile)
        if not isinstance(db,FeResult):
            warning("!Something went wrong during the import of the flavia database %s" % fn)
            return

        ### ok: export and select the DB
        name = os.path.splitext(os.path.basename(fn))[0].replace('.flavia','')
        export({name:db})
        db.printSteps()
        print db.R
        print db.datasize
        
        selection.set([name])
        selectDB(db)
Ejemplo n.º 3
0
    # Done: Close data file
    fil.close()
    showFile(filnam,mono=True)

    if ack("Shall I run the Calix analysis?"):
        # Run the analysis
        outfile = utils.changeExt(filnam,'res')
        cmd = "calix %s %s" % (filnam,outfile)
        utils.runCommand(cmd)
        showFile(outfile,mono=True)
        
        if ack("Shall I read the results for postprocessing?"):
            from plugins import flavia
            meshfile = utils.changeExt(filnam,'flavia.msh')
            resfile = utils.changeExt(filnam,'flavia.res')
            DB = flavia.readFlavia(meshfile,resfile)
            postproc_menu.setDB(DB)
            export({name:DB})
            if showInfo("The results have been exported as %s\nYou can now use the postproc menu to display results" % name,actions=['Cancel','OK']) == 'OK':
                postproc_menu.selection.set(name)
                postproc_menu.selectDB(DB)
                postproc_menu.open_results_dialog()
    

##############################################################################

def runCalpyAnalysis(jobname=None,verbose=False,flavia=False):
    """Create data for Calpy analysis module and run Calpy on the data.

    While we could write an analysis file in the Calpy format and then
    run the Calpy program on it (like we did with Abaqus), we can (and do)
Ejemplo n.º 4
0
def createCalixInput():
    """Write the Calix input file."""

    checkWorkdir()

    if model is None:
        warn()
        return
    
    # ask job name from user
    res = askItems([
        _I('jobname',feresult_name.next(),text='Job Name'),
        _I('header','A Calix example',text='Header Text'),
        _I('zem','3',text='ZEM control',itemtype='radio',choices=['0','3','6'],),
        ])
    if not res:
        return

    jobname = res['jobname']
    header = res['header']
    nzem = int(res['zem'])
    if not jobname:
        print("No Job Name: writing to sys.stdout")
        jobname = None

    filnam = jobname+'.dta'
    print("Writing calix data file %s in %s" % (filnam,os.getcwd()))
    fil = open(filnam,'w')
    
    nnodes = model.coords.shape[0]
    nelems = model.celems[-1]
    nplex = [ e.shape[1] for e in model.elems ]
    if min(nplex) != max(nplex):
        print([ e.shape for e in model.elems ])
        warning("All parts should have same element type")
        return
    nodel = nplex[0]

    # Get materials
    secprops = PDB.getProp(kind='e',attr=['section'])
    print(secprops)
    # need E, nu, thickness, rho
    mats = array([[sec.young_modulus,
                   sec.poisson_ratio,
                   sec.thickness,
                   sec.density,
                   ] for sec in secprops]) 
    matnr = zeros(nelems,dtype=int32)
    for i,mat in enumerate(secprops):  # proces in same order as above!
        matnr[mat.set] = i+1
    print(matnr)
    nmats = mats.shape[0]
    
    # Header
    fil.write("""; calix data file generated by %s
; jobname=%s
start: %s
;use cmdlog 'calix.log'
;use for messages cmdlog
file open 'femodel.tmp' write da 1
yes cmdlog
;yes debug
use for cmdlog output
femodel elast stress 2
use for cmdlog cmdlog
;-----------------------------------------
; Aantal knopen:   %s
; Aantal elementen:   %s
; Aantal materialen:     %s
; Aantal belastingsgevallen: %s
"""% (pf.Version,jobname,header,nnodes,nelems,nmats,nsteps))
    # Nodal coordinates
    fil.write(""";-----------------------------------------
; Knopen
;--------
nodes coord %s 1
""" % nnodes)
    fil.write('\n'.join(["%5i%10.2f%10.2f"%(i,x[0],x[1]) for i,x in zip(arange(nnodes)+1,model.coords)]))
    fil.write('\n\n')
    # Boundary conditions
    fil.write(""";-----------------------------------------
; Verhinderde verplaatsingen
;-------------------------
bound bcon
plane
""")
    for p in PDB.getProp(kind='n',attr=['bound']):
        bnd = "%5i" + "%5i"*2 % (p.bound[0],p.bound[1])
        if p.set is None:
            nod = arange(model.nnodes)
        else:
            nod = array(p.set)
        fil.write('\n'.join([ bnd % i for i in nod+1 ]))
        fil.write('\n')
    fil.write('\n')
    fil.write("""print bcon 3
                           $$$$$$$$$$$$$$$$$$$$$$$
                           $$      D O F S      $$
                           $$$$$$$$$$$$$$$$$$$$$$$
""")
    
    # Materials
    fil.write(""";-----------------------------------------
; Materialen
;-----------
array mat    %s 4
""" % len(mats))
    print(mats)
    fil.write('\n'.join([ "%.4e "*4 % tuple(m) for m in mats]))
    fil.write('\n\n')
    fil.write("""print mat 3
                           $$$$$$$$$$$$$$$$$$$$$$$
                           $$ M A T E R I A L S $$
                           $$$$$$$$$$$$$$$$$$$$$$$
""")
    
    # Elements
    for igrp,grp in enumerate(model.elems):
        nelems,nplex = grp.shape
        fil.write(""";-----------------------------------------
; Elementen
;----------
elements elems-%s matnr-%s  %s %s 1
""" % (igrp,igrp,nplex,nelems))
        fil.write('\n'.join(["%5i"*(nplex+2) % tuple([i,1]+e.tolist()) for i,e in zip(arange(nelems)+1,grp+1)]))
        fil.write('\n\n')
        fil.write("""plane plane-%s coord bcon elems-%s matnr-%s 2 2
""" % (igrp,igrp,igrp))
        
    #########################
    # Nodal Loads
    cloads = [ p for p in PDB.getProp('n',attr=['cload']) ]
    fil.write("""text 3 1
                           $$$$$$$$$$$$$$$$$$$$
                           $$  NODAL  LOADS  $$
                           $$$$$$$$$$$$$$$$$$$$
loads f bcon 1
""")
    if len(cloads) > 0:
        for p in cloads:
            loadcase = loadcaseFromTag(p)
            if p.set is None:
                nodeset = range(calpyModel.nnodes)
            else:
                nodeset = p.set
            F = [0.0,0.0]
            for i,v in p.cload:
                if i in [0,1]:
                    F[i] = v
            fil.write(''.join(["%5i%5i%10.2f%10.2f\n" % (n+1,loadcase,F[0],F[1]) for n in nodeset]))
    fil.write('\n')
    
    #########################
    # Distributed loads
    eloads = [ p for p in PDB.getProp('e',attr=['eload']) ]
    if len(eloads) > 0:
        fil.write("""text 4 1
                           $$$$$$$$$$$$$$$$$$$$$$$$$$
                           $$  BOUNDARY  ELEMENTS  $$
                           $$$$$$$$$$$$$$$$$$$$$$$$$$
   elem  loadnr  localnodes
""")
        # get the data from database, group by group
        for igrp in range(len(model.elems)):
            geloads = [ p for p in eloads if p.group==igrp ]
            neloads = len(geloads)
            loaddata = []
            fil.write("array randen integer   %s 4 0 1\n" % neloads)
            i = 1
            for p in geloads:
                loadcase = loadcaseFromTag(p)
                xload = yload = 0.
                if p.label == 'x':
                    xload = p.value
                elif p.label == 'y':
                    yload = p.value
                # Save the load data for later
                loaddata.append((i,loadcase,xload,yload))
                # Because of the way we constructed the database, the set will
                # contain only one element, but let's loop over it anyway in
                # case one day we make the storage more effective
                for e in p.set:
                    fil.write(("%5s"*4+"\n")%(e+1,i,p.edge+1,(p.edge+1)%4+1))
                i += 1
            fil.write("""print randen
tran randen tranden
boundary  rand-%s coord bcon elems-%s matnr-%s tranden 1
""" % ((igrp,)*3))
            fil.write("""text 3 1
                           $$$$$$$$$$$$$$$$$$$$$$$
                           $$  BOUNDARY  LOADS  $$
                           $$$$$$$$$$$$$$$$$$$$$$$
loadvec boundary rand-%s f 1
""" % igrp)
            for eload in loaddata:
                fil.write("%5s%5s%10s%10s\n" % eload)
            fil.write('\n')

    #########################
    # Print total load vector
    fil.write("""
print f 3
                           $$$$$$$$$$$$$$$$$$$$
                           $$  LOAD  VECTOR  $$
                           $$$$$$$$$$$$$$$$$$$$
;
""")
    # Assemble
    for igrp in range(len(model.elems)):
        fil.write("assemble plane-%s mat s 0 0 0 %s\n" % (igrp,nzem))

    # Solve and output
    fil.write(""";------------------------------------------------solve+output
flavia mesh '%s.flavia.msh' %s
flavia nodes coord
""" %  (jobname,nplex))
    for igrp in range(len(model.elems)):
        fil.write("flavia elems elems-%s matnr-%s %s\n" % (igrp,igrp,nplex))
    fil.write("flavia results '%s.flavia.res'\n" % jobname)
    fil.write("""
solbnd s f
delete s
text named 1
"Displacement" "Elastic Analysis"
text typed 1
Vector OnNodes
text names 1
"Stress" "Elastic Analysis"
text types 1
Matrix OnNodes
intvar set 1 1
loop 1
  displ f bcon displ $1 1
  tran displ disp
  flavia result named typed disp $1
""")
    for igrp in range(len(model.elems)):
        fil.write("""
  stress plane-%s mat f stresg $1 1
  gp2nod plane-%s stresg strese 0 1
  nodavg plane-%s elems-%s strese stren nval 1
  tran stren stre
  flavia result names types stre $1
""" % ((igrp,)*4))
    fil.write("""       
  intvar add 1 1
next
stop
""")

    # Done: Close data file
    fil.close()
    showFile(filnam,mono=True)

    if ack("Shall I run the Calix analysis?"):
        # Run the analysis
        outfile = utils.changeExt(filnam,'res')
        cmd = "calix %s %s" % (filnam,outfile)
        utils.runCommand(cmd)
        showFile(outfile,mono=True)
        
        if ack("Shall I read the results for postprocessing?"):
            from plugins import flavia
            meshfile = utils.changeExt(filnam,'flavia.msh')
            resfile = utils.changeExt(filnam,'flavia.res')
            DB = flavia.readFlavia(meshfile,resfile)
            postproc_menu.setDB(DB)
            export({name:DB})
            if showInfo("The results have been exported as %s\nYou can now use the postproc menu to display results" % name,actions=['Cancel','OK']) == 'OK':
                postproc_menu.selection.set(name)
                postproc_menu.selectDB(DB)
                postproc_menu.open_dialog()