Exemple #1
0
def test_4():
    # engngModel
    problem = oofempy.linearStatic(nSteps=1, outFile="test4.out")

    # domain (if no engngModel specified to domain, it is asigned to the last one created)
    domain = oofempy.domain(1,
                            1,
                            problem,
                            oofempy.domainType._1dTrussMode,
                            tstep_all=True,
                            dofman_all=True,
                            element_all=True)
    problem.setDomain(1, domain, True)

    ltf1 = oofempy.peakFunction(1, domain, t=1, f_t=1)
    ltfs = (ltf1, )

    # boundary conditions
    # loadTimeFunction parameter can be specified as int value or as LoadTimeFunction itself (valid for all objects with giveNumber() method)
    bc1 = oofempy.boundaryCondition(1,
                                    domain,
                                    loadTimeFunction=1,
                                    prescribedValue=0.0)
    n2 = oofempy.nodalLoad(2,
                           domain,
                           loadTimeFunction=1,
                           components=(1., ),
                           dofs=(1, ))
    bcs = (bc1, n2)

    # nodes
    # if one value is passed as parameter where oofem expects array of values, it must be passed as tuple or list (see load in n4)
    n1 = oofempy.node(1, domain, coords=(0., 0., 0.), bc=(bc1, ))
    n2 = oofempy.node(2, domain, coords=(2.4, 0., 0.), load=(n2, ))
    nodes = (n1, n2)

    # material and cross section
    #mat = oofempy.isoLE(1, domain, d=1., E=30.e6, n=0.2, tAlpha=1.2e-5)
    mat = MyMaterial(1, domain)
    cs = oofempy.simpleCS(1,
                          domain,
                          area=0.5,
                          Iy=0.0,
                          beamShearCoeff=1.e18,
                          thick=0.5)

    # elements
    e1 = oofempy.truss1d(1, domain, nodes=(1, n2), mat=1, crossSect=1)
    # construct OOFEMTXTInputRecord from bp::dict **kw
    elems = (e1, )

    # setup domain
    util.setupDomain(domain, nodes, elems, (mat, ), (cs, ), bcs, ltfs, ())

    print("\nSolving problem")
    problem.checkProblemConsistency()
    problem.init()
    problem.postInitialize()

    # Test user defined material model
    a = oofempy.FloatArray((1.0, ))
    ans = oofempy.FloatArray()

    rule = e1.giveDefaultIntegrationRulePtr()
    rule = e1.giveIntegrationRule(0)
    #print(rule)
    gp = rule.getIntegrationPoint(0)
    #print(gp)
    #print(mat.giveStatus(gp))
    ans = domain.giveMaterial(1).giveRealStressVector_1d(
        a, rule.getIntegrationPoint(0), None)
    #ans.pY()
    assert (round(ans[0] - 1.5, 8) == 0), "Stress value error"

    problem.setRenumberFlag()
    problem.solveYourself()

    #check solution
    u2 = problem.giveUnknownComponent(
        oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain,
        domain.giveDofManager(2).giveDofWithID(oofempy.DofIDItem.D_u))
    assert (round(u2 - 3.2, 8) == 0), "Node 2 dof 1 displacement check failed"

    problem.terminateAnalysis()
    print("\nProblem solved")
Exemple #2
0
def test_2():

    # engngModel
    problem = oofempy.linearStatic(nSteps=3, outFile="test2.out")

    # domain (if no engngModel specified to domain, it is asigned to the last one created)
    domain = oofempy.domain(1,
                            1,
                            problem,
                            oofempy.domainType._2dBeamMode,
                            tstep_all=True,
                            dofman_all=True,
                            element_all=True)
    problem.setDomain(1, domain, True)

    ltf1 = oofempy.peakFunction(1, domain, t=1, f_t=1)
    ltf2 = oofempy.peakFunction(2, domain, t=2, f_t=1)
    ltf3 = oofempy.peakFunction(3, domain, t=3, f_t=1)
    ltfs = (ltf1, ltf2, ltf3)

    # boundary conditions
    # loadTimeFunction parameter can be specified as int value or as LoadTimeFunction itself (valid for all objects with giveNumber() method)
    bc1 = oofempy.boundaryCondition(1,
                                    domain,
                                    loadTimeFunction=1,
                                    prescribedValue=0.0)
    bc2 = oofempy.boundaryCondition(2,
                                    domain,
                                    loadTimeFunction=2,
                                    prescribedValue=-.006e-3)
    eLoad = oofempy.constantEdgeLoad(3,
                                     domain,
                                     loadTimeFunction=1,
                                     components=(0., 10., 0.),
                                     loadType=3,
                                     ndofs=3)
    nLoad = oofempy.nodalLoad(4,
                              domain,
                              loadTimeFunction=1,
                              components=(-18., 24., 0.))
    tLoad = oofempy.structTemperatureLoad(5,
                                          domain,
                                          loadTimeFunction=3,
                                          components=(30., -20.))
    bcs = (bc1, bc2, eLoad, nLoad, tLoad)

    # nodes
    # if one value is passed as parameter where oofem expects array of values, it must be passed as tuple or list (see load in n4)
    n1 = oofempy.node(1, domain, coords=(0., 0., 0.), bc=(0, 1, 0))
    n2 = oofempy.node(2, domain, coords=(2.4, 0., 0.), bc=(0, 0, 0))
    n3 = oofempy.node(3, domain, coords=(3.8, 0., 0.), bc=(0, 0, bc1))
    n4 = oofempy.node(4,
                      domain,
                      coords=(5.8, 0., 1.5),
                      bc=(0, 0, 0),
                      load=(4, ))
    n5 = oofempy.node(5, domain, coords=(7.8, 0., 3.0), bc=(0, 1, 0))
    n6 = oofempy.node(6, domain, coords=(2.4, 0., 3.0), bc=(bc1, 1, bc2))
    nodes = (n1, n2, n3, n4, n5, n6)

    # material and cross section
    mat = oofempy.isoLE(1, domain, d=1., E=30.e6, n=0.2, tAlpha=1.2e-5)
    cs = oofempy.simpleCS(1,
                          domain,
                          area=0.162,
                          Iy=0.0039366,
                          beamShearCoeff=1.e18,
                          thick=0.54)

    # elements
    e1 = oofempy.beam2d(1,
                        domain,
                        nodes=(1, n2),
                        mat=1,
                        crossSect=1,
                        boundaryLoads=(3, 1),
                        bodyLoads=(5, ))
    e2 = oofempy.beam2d(2,
                        domain,
                        nodes=(2, 3),
                        mat=mat,
                        crossSect=1,
                        DofsToCondense=(6, ),
                        bodyLoads=[tLoad])
    e3 = oofempy.beam2d(3,
                        domain,
                        nodes=(n3, 4),
                        mat=1,
                        crossSect=cs,
                        dofstocondense=[3])
    e4 = oofempy.beam2d(4, domain, nodes=(n4, n5), mat=mat, crossSect=cs)
    e5 = oofempy.beam2d(5,
                        domain,
                        nodes=(n6, 2),
                        mat=1,
                        crossSect=1,
                        DofsToCondense=(6, ))
    elems = (e1, e2, e3, e4, e5)

    # add eveything to domain (resize container first to save some time, but it is not necessary 0 see ltfs)
    util.setupDomain(domain, nodes, elems, (mat, ), (cs, ), bcs, ltfs, ())

    print("\nSolving problem")
    problem.checkProblemConsistency()
    problem.init()
    problem.postInitialize()
    problem.setRenumberFlag()
    problem.solveYourself()

    #check solution
    u1 = problem.giveUnknownComponent(
        oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain,
        domain.giveDofManager(1).giveDofWithID(oofempy.DofIDItem.D_u))
    print(u1)
    assert (round(u1 + 8.64000000e-04,
                  8) == 0), "Node 1 dof 1 displacement check failed"
    u4 = problem.giveUnknownComponent(
        oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain,
        domain.giveDofManager(4).giveDofWithID(oofempy.DofIDItem.D_u))
    assert (round(u4 - 9.47333333e-04,
                  8) == 0), "Node 4 dof 1 displacement check failed"

    problem.terminateAnalysis()
    print("\nProblem solved")
Exemple #3
0
def test_5():
    # engngModel
    problem = oofempy.staticStructural(nSteps=3, outFile="test_5.out")

    # domain (if no engngModel specified to domain, it is asigned to the last one created)
    domain = oofempy.domain(1, 1, problem, oofempy.domainType._2dPlaneStressMode, tstep_all=True, dofman_all=True, element_all=True)
    problem.setDomain(1, domain, True)
    
    ltf1 = oofempy.constantFunction(1, domain, f_t=1.)
    ltf2 = oofempy.piecewiseLinFunction(2, domain, t=(1., 5.), f_t= (0., 4.))
    ltfs = (ltf1,ltf2)

    # boundary conditions
    bc1 = oofempy.boundaryCondition(1, domain, loadTimeFunction=1, prescribedValue=0.0)
    n2 = oofempy.nodalLoad(2, domain, loadTimeFunction=2, components=(0.,0.), dofs=(1,2))
    bcs = (bc1, n2)

    # nodes
    n1 = oofempy.node(1, domain, coords=(0.,  0., 0. ), bc=(bc1,bc1))
    n2 = oofempy.node(2, domain, coords=(2.4, 0., 0. ), bc=(0,bc1))
    n3 = oofempy.node(3, domain, coords=(2.4, 0.8, 0.), load=(n2,) )
    nodes = (n1,n2,n3)

    # material and cross section
    mat = oofempy.isoLE(1, domain, d=1., E=30.e3, n=0.2, tAlpha=1.2e-5)
    cs  = oofempy.simpleCS(1, domain, thick=0.5, material=1, set=1)
    
    # elements - assign through sets
    e1 = oofempy.trPlaneStress2d(1, domain, nodes=(1,2,3))
    elems = (e1,)

    set1 = oofempy.createSet(1, domain, elements=(1,)) #Ettringite

    # setup domain
    util.setupDomain(domain, nodes, elems, (cs,), (mat,), bcs, (), ltfs, (set1,))
    
    # add export module for outputting regular VTU files - automatically registered
    vtkxml = oofempy.vtkxml(1, problem, domain_all=True, tstep_all=True, dofman_all=True, element_all=True, vars=(56,), primvars=(6,), stype=1, pythonExport=0)
    
    # add export module for outputting python lists with values - automatically registered
    vtkxmlPy = oofempy.vtkxml(1, problem, domain_all=True, tstep_all=True, dofman_all=True, element_all=True, vars=(56,37), primvars=(6,), cellvars = (47,103), stype=1, pythonExport=1)
    
    #add homogenization module - automatically registered
    homPy1 = oofempy.homExport(3, problem, tstep_all=True, ists=(1,4), regionsets=(1,))
    
   
    
    print("\nSolving problem")
    problem.checkProblemConsistency()
    problem.init()
    problem.postInitialize()
    problem.giveTimer().startTimer(oofempy.EngngModelTimerType.EMTT_AnalysisTimer)
    activeMStep = problem.giveMetaStep(1)
    problem.initMetaStepAttributes(activeMStep);
    
    #Create dummy temperature field, define from where to obtain the values
    f = oofempy.PythonField()
    f.setModuleName('test_5')
    f.setFunctionName('evalField')
    context = problem.giveContext()
    field_man = context.giveFieldManager()
    #register field so OOFEM knows of external temperature. In every iteration, it calls PythonField::evaluateAt() which propagates further to evalField()
    field_man.registerField(f, oofempy.FieldType.FT_Temperature)
    
    for timeStep in range(3):
        problem.preInitializeNextStep()
        problem.giveNextStep()
        currentStep = problem.giveCurrentStep()
        problem.initializeYourself( currentStep )
        problem.solveYourselfAt( currentStep )
        problem.updateYourself( currentStep )
        problem.terminate( currentStep )
        print("TimeStep %d finished" % (timeStep))
        
        #get results at nodes and domain
        primVars = vtkxmlPy.getPrimaryVars()
        print("PrimaryVars Temperature", primVars['Temperature'])
        intVars = vtkxmlPy.getInternalVars()
        print("InternalVars IST_Temperature", intVars['IST_Temperature'])
        cellVars = vtkxmlPy.getCellVars()
        print("CellVars", cellVars)
        nodesVTK = vtkxmlPy.getNodes()
        print("Nodes", nodesVTK)
        elementsVTK = vtkxmlPy.getElementsConnectivity()
        print("Elements", elementsVTK)
        
    problem.terminateAnalysis()

    ##check solution
    v3 = problem.giveUnknownComponent(oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain, domain.giveDofManager(3).giveDofWithID(oofempy.DofIDItem.D_v))
    assert (round (v3-4.608e-4, 8) == 0), "Node 3 dof 2 displacement check failed"
    
    
    t1 = primVars['Temperature'][0][0]
    assert (round (t1-48.0000, 4) == 0), "Export of primary field failed"
    
    problem.terminateAnalysis()
    print("\nProblem solved")
Exemple #4
0
def test_3():
    # engngModel
    problem = oofempy.linearStatic(nSteps=1, outFile="test_3.out")

    # domain (if no engngModel specified to domain, it is asigned to the last one created)
    domain = oofempy.domain(1,
                            1,
                            problem,
                            oofempy.domainType._1dTrussMode,
                            tstep_all=True,
                            dofman_all=True,
                            element_all=True)
    problem.setDomain(1, domain, True)

    ltf1 = oofempy.peakFunction(1, domain, t=1, f_t=1)
    ltf2 = MyFunc(2, domain)  # use custom ltf here
    ltfs = (ltf1, ltf2)

    # boundary conditions
    # loadTimeFunction parameter can be specified as int value or as LoadTimeFunction itself (valid for all objects with giveNumber() method)
    bc1 = oofempy.boundaryCondition(1,
                                    domain,
                                    loadTimeFunction=1,
                                    prescribedValue=0.0)
    n2 = oofempy.nodalLoad(2,
                           domain,
                           loadTimeFunction=2,
                           components=(1., ),
                           dofs=(1, ))
    bcs = (bc1, n2)

    # nodes
    # if one value is passed as parameter where oofem expects array of values, it must be passed as tuple or list (see load in n4)
    n1 = oofempy.node(1, domain, coords=(0., 0., 0.), bc=(bc1, ))
    n2 = oofempy.node(2, domain, coords=(2.4, 0., 0.), load=(n2, ))
    nodes = (n1, n2)

    # material and cross section
    mat = oofempy.isoLE(1, domain, d=1., E=30.e6, n=0.2, tAlpha=1.2e-5)
    cs = oofempy.simpleCS(1,
                          domain,
                          area=0.5,
                          Iy=0.0,
                          beamShearCoeff=1.e18,
                          thick=0.5)

    # elements
    #e1 = oofempy.truss1d(1, domain, nodes=(1,n2),  mat=1,   crossSect=1)
    e1 = MyElement(1, domain)
    e1.setDofManagers((1, 2))
    # construct OOFEMTXTInputRecord from bp::dict **kw
    ir = oofempy.OOFEMTXTInputRecord()
    ir.setRecordString("nodes 2 1 2 mat 1 crosssect 1")
    # pass input record to elem
    e1.initializeFrom(ir)
    elems = (e1, )

    # setup domain
    util.setupDomain(domain, nodes, elems, (cs, ), (mat, ), bcs, (), ltfs, ())

    print("\nSolving problem")
    problem.checkProblemConsistency()
    problem.init()
    problem.postInitialize()
    problem.setRenumberFlag()
    problem.solveYourself()

    #check solution
    u2 = problem.giveUnknownComponent(
        oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain,
        domain.giveDofManager(2).giveDofWithID(oofempy.DofIDItem.D_u))
    assert (round(u2 + 2.5, 8) == 0), "Node 2 dof 1 displacement check failed"

    problem.terminateAnalysis()
    print("\nProblem solved")
Exemple #5
0
# nodes
# if one value is passed as parameter where oofem expects array of values, it must be passed as tuple or list (see load in n4)
n1 = oofempy.node(1, domain, coords=(0., 0., 0.), bc=(0, 1, 0))
n2 = oofempy.node(2, domain, coords=(2.4, 0., 0.), bc=(0, 0, 0))
n3 = oofempy.node(3, domain, coords=(3.8, 0., 0.), bc=(0, 0, bc1))
n4 = oofempy.node(4, domain, coords=(5.8, 0., 1.5), bc=(0, 0, 0), load=(4, ))
n5 = oofempy.node(5, domain, coords=(7.8, 0., 3.0), bc=(0, 1, 0))
n6 = oofempy.node(6, domain, coords=(2.4, 0., 3.0), bc=(bc1, 1, bc2))
nodes = (n1, n2, n3, n4, n5, n6)

# material and cross section
mat = oofempy.isoLE(1, domain, d=1., E=30.e6, n=0.2, tAlpha=1.2e-5)
cs = oofempy.simpleCS(1,
                      domain,
                      area=0.162,
                      Iy=0.0039366,
                      beamShearCoeff=1.e18,
                      thick=0.54)

# elements
e1 = oofempy.beam2d(1,
                    domain,
                    nodes=(1, n2),
                    mat=1,
                    crossSect=1,
                    boundaryLoads=(3, 1),
                    bodyLoads=(5, ))
e2 = oofempy.beam2d(2,
                    domain,
                    nodes=(2, 3),
                    mat=mat,
Exemple #6
0
                                loadTimeFunction=1,
                                prescribedValue=0.0)
n2 = oofempy.nodalLoad(2, domain, loadTimeFunction=2, components=(1., ))
bcs = (bc1, n2)

# nodes
# if one value is passed as parameter where oofem expects array of values, it must be passed as tuple or list (see load in n4)
n1 = oofempy.node(1, domain, coords=(0., 0., 0.), bc=(bc1, ))
n2 = oofempy.node(2, domain, coords=(2.4, 0., 0.), load=(n2, ))
nodes = (n1, n2)

# material and cross section
mat = oofempy.isoLE(1, domain, d=1., E=30.e6, n=0.2, tAlpha=1.2e-5)
cs = oofempy.simpleCS(1,
                      domain,
                      area=0.5,
                      Iy=0.0,
                      beamShearCoeff=1.e18,
                      thick=0.5)

# elements
e1 = oofempy.truss1d(1, domain, nodes=(1, n2), mat=1, crossSect=1)
elems = (e1, )

# add eveything to domain (resize container first to save some time, but it is not necessary 0 see ltfs)
domain.resizeDofManagers(len(nodes))
for n in nodes:
    domain.setDofManager(n.number, n)
domain.resizeElements(len(elems))
for e in elems:
    domain.setElement(e.number, e)
domain.resizeMaterials(1)
Exemple #7
0
def test_6():
    # engngModel
    problem = oofempy.staticStructural(nSteps=1, outFile="test_6.out")

    # domain (if no engngModel specified to domain, it is asigned to the last one created)
    domain = oofempy.domain(1, 1, problem, oofempy.domainType._3dMode, tstep_all=True, dofman_all=True, element_all=True)
    problem.setDomain(1, domain, True)
    # load time functions
    ltf1 = oofempy.constantFunction(1, domain, f_t=1.)
    ltfs = (ltf1,)
    # boundary conditions
    bc1 = oofempy.boundaryCondition(1, domain, loadTimeFunction=1, prescribedValue=0.0)
    dw = oofempy.DeadWeight(2, domain, loadTimeFunction = 1, components=(0.,0.,-10.0))
    bcs = (bc1, dw)
    # nodes
    n1 = oofempy.node(1, domain, coords=(0., 0., 2. ))
    n2 = oofempy.node(2, domain, coords=(0., 2., 2. ))
    n3 = oofempy.node(3, domain, coords=(2., 2., 2. ))
    n4 = oofempy.node(4, domain, coords=(2., 0., 2. ))
    n5 = oofempy.node(5, domain, coords=(0., 0., 0. ), bc=(bc1, bc1, bc1))
    n6 = oofempy.node(6, domain, coords=(0., 2., 0. ), bc=(  0,   0, bc1) )
    n7 = oofempy.node(7, domain, coords=(2., 2., 0. ), bc=(  0,   0, bc1))
    n8 = oofempy.node(8, domain, coords=(2., 0., 0. ), bc=(  0, bc1, bc1))
    #
    nodes = (n1,n2,n3,n4,n5,n6,n7,n8)
    # material and cross section
    mat = oofempy.isoLE(1, domain, d=2., E=100., n=0.01, tAlpha=1.2e-5)
    cs  = oofempy.simpleCS(1, domain)
    # elements - assign through sets
    e1 = oofempy.lspace(1, domain, nodes=(1,2,3,4,5,6,7,8), mat=1, crossSect = 1, bodyloads = (dw,))
    elems = (e1,)
    #sets
    set1 = oofempy.createSet(1, domain, elements=(1,))
    # setup domain
    util.setupDomain(domain, nodes, elems, (cs,), (mat,), bcs, (), ltfs, (set1,))
    # add export module for outputting regular VTU files - automatically registered
#    vtkxml = oofempy.vtkxml(1, problem, domain_all=True, tstep_all=True, dofman_all=True, element_all=True, vars=(56,), primvars=(6,), stype=1, pythonExport=0)
   
    # add export module for outputting python lists with values - automatically registered
    print("\nSolving problem")
    problem.checkProblemConsistency()
    problem.init()
    problem.postInitialize()
    problem.giveTimer().startTimer(oofempy.EngngModelTimerType.EMTT_AnalysisTimer)
    activeMStep = problem.giveMetaStep(1)
    problem.initMetaStepAttributes(activeMStep);
       
    for timeStep in range(1):
        problem.preInitializeNextStep()
        problem.giveNextStep()
        currentStep = problem.giveCurrentStep()
        problem.initializeYourself( currentStep )
        problem.solveYourselfAt( currentStep )
        problem.updateYourself( currentStep )
        problem.terminate( currentStep )
        print("TimeStep %d finished" % (timeStep))

    #check solution
    w3 = problem.giveUnknownComponent(oofempy.ValueModeType.VM_Total, problem.giveCurrentStep(False), domain, domain.giveDofManager(1).giveDofWithID(oofempy.DofIDItem.D_w))
    assert (round (w3+4.000e-1, 8) == 0), "Node 1 dof 3 displacement check failed"
    
        
    problem.terminateAnalysis()
    print("\nProblem solved")