Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge Iframe embedding
swh:1:cnt:a4dc3926eb6c12f77831a0882b5252b5e587a9bf

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
from FemObject import *
from CubeObject import *


if __name__ == '__main__':

    # volume fraction, default is 0.5
    alpha = 0.5

    # show intermediate results
    showResults = False

    # also evaluate materialized tri/tet inputs
    evalInput =  False

    # examples included in the paper
    objNames = ['cube', 'femur', 'fertility', 'kitten', 'spot', 'venus']
    #objNames = ['JEB', 'buddhaDown', 'buddhaBack', 'buddhaBelly']

    # uncomment to compute only 2D examples (quicker)
    #objNames = ['spot2D', 'bunny2D', 'bar2D']

    res = [['object', 'type', 'method', 'nVerts', 'nCells', 'v/v0', 'c/c0', 'ASJ', 'MSJ']]  
    for objName in objNames:
        # setup input FEM object and apply loads
        fInObj = FemObject('data/%s.frc'%objName, False)
        c0 = fInObj.computeCompliance()
        res.append([objName, fInObj.mTypeInit, None, fInObj.nVerts, fInObj.nElems, 1, 1])

        # write stress file
        fInObj.exportToStress()

        # show applied forces
        if showResults:
            fInObj.showForces()

        # materialize input and evaluate
        if evalInput:
            fInObj.materialize(alpha, False)
            c1 = fInObj.computeCompliance(complianceOnly = True)
            res.append([objName, fInObj.mTypeInit+'_b', False, fInObj.nVerts, fInObj.nElems, fInObj.vol / fInObj.volInit, c1 / c0])

            if fInObj.nDim == 3:
                fInObj = FemObject('data/%s.frc'%objName, False)
                c0 = fInObj.computeCompliance()
                fInObj.materialize(alpha, True)
                c1 = fInObj.computeCompliance(complianceOnly = True)
                res.append([objName, fInObj.mTypeInit+'_w', False, fInObj.nVerts, fInObj.nElems, fInObj.vol / fInObj.volInit, c1 / c0])

        # setup cubification object and optimize
        cfgParams = ConfigParams.fromFile('data/%s.cfg'%objName)
        cObj = CubeObject(cfgParams)
        cObj.optimize()
        cObj.saveState()

        # show deformation
        if showResults:
            cVis = CubeVisual()
            cVis.showPlot(cObj)

        #cObj.loadState()
        cObj.fillGrid()
        cObj.padHull()
        cObj.restoreInitShape()

        # show the optimized deformation
        if showResults:
            cObj.evalAlignment()
            cObj.show(False, False)
            mlab.show()

        # export result lattice
        cObj.exportCellsToMesh()

        # load the aligned structure as FEM input
        fResObj = FemObject('data/%s.frc'%objName, True)
        c1 = fResObj.computeCompliance(complianceOnly = True)
        SJs = fResObj.evalScaledJacobians(False)
        res.append([objName, fResObj.mTypeInit, None, len(cObj.gVerts), len(cObj.cells), fResObj.volInit / fInObj.volInit, c1 / c0, SJs.mean(), SJs.min()])

        # materialize with different modi
        for walled in [False] + [True] * (cObj.nDim == 3):
            for useOpti in [False, True]:
                fResObj = FemObject('data/%s.frc'%objName, True)
                c0 = fResObj.computeCompliance(complianceOnly = True)
                if useOpti:
                    weights = None if objName != 'spot2D' else icdf(fResObj.vmStress)**2 # experimental
                    fResObj.materializeOpti(alpha, walled, weights = weights)
                else:
                    fResObj.materialize(alpha, walled)
                c1 = fResObj.computeCompliance(complianceOnly = True)
                SJs = fResObj.evalScaledJacobians(False)
                mTag = 'w' if walled else 'b'
                res.append([objName, fResObj.mTypeInit + '_' + mTag, useOpti, fResObj.nVerts, fResObj.nElems, fResObj.vol / fResObj.volInit, c1 / c0, SJs.mean(), SJs.min()])

    with open(logDir + 'examples.log', 'w') as fh:
        ln = ', '.join(['% 9s'%s for s in res[0]])
        print(ln)
        fh.write(ln+'\n')
        for r in res[1:]:
            method = ('tau' + '*' * r[2]) if r[2] is not None else ''
            ln = ', '.join(['% 9s'%s for s in [r[0], r[1], method]])
            ln += ', ' + ', '.join(['% 9d'%d for d in [r[3],r[4]]])
            ln += ', ' + ', '.join(['% 0.6f'%f for f in r[5:]])
            print(ln)
            fh.write(ln+'\n')

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API