Git Product home page Git Product logo

pyccx's Introduction

PyCCX - Python Library for Calculix

image

Documentation Status

image

Chat on Gitter

Provides a library for creating and running 3D FEA simulations using the opensource Calculix FEA Package.

The aims of this project was to provide a simple framework for implemented 3D FEA Analysis using the opensource Calculix solver. The analysis is complimented by use of the recent introduction of the GMSH-SDK , an extension to GMSH to provide API bindings for different programming languages by the project authors to provide sophisticated 3D FEA mesh generation outside of the GUI implementation. This project aims to provide an integrated approach for generating full 3D FEA analysis for use in research, development and prototyping in a Python environment. Along with setting up and processing the analysis, convenience functions are included.

The inception of this project was a result of finding no native Python/Matlab package available to perfom full non-linear FEA analysis of 3D CAD models in order to prototype a concept related to 3D printing. The project aims to compliment the work of the PyCalculix project, which currently is limited to providing capabilities to generate 2D Meshes and FEA analysis for 2D planar structures. The potential in the future is to provide a more generic extensible framework compatible with different opensource and commercial FEA solvers (e.g. Abaqus, Marc, Z88, Elmer).

An interface that built upon GMSH was required to avoid the use of the GUI, and the domain specific .geo scripts. Learn more.

Structure

PyCCX framework consists of classes for specifying common components on the pre-processing phase, including the following common operations:

  • Mesh generation
  • Creating and applying boundary conditions
  • Creating load cases
  • Creating and assigning material models
  • Performing the simulation

In addition, a meshing class provides an interface with GMSH for performing the meshing routines and for associating boundary conditions with the elements/faces generated from geometrical CAD entities. The Simulation class assembles the analysis and performs the execution to the Calculix Solver. Results obtained upon completion of the analysis can be processed. Currently the analysis is unit-less, therefore the user should ensure that all constant, material paramters, and geometric lengths are consistent - by default GMSH assumes 'mm' units.

Current Features

Meshing:

  • Integration with GMSH for generation 3D FEA Meshes (Tet4, Tet10 currently supported)
  • Merging CAD assemblies using GMSH
  • Attaching boundary conditions to Geometrical CAD entities

FEA Capabilities:

  • Boundary Conditions (Acceleration, Convection, Fixed Displacements, Forces, Fluxes, Pressure, Radiation)
  • Loadcase Types (Structural Static, Thermal, Coupled Thermo-Mechanical)
  • Materials (Non-linear Elasto-Plastic Material)

Results Processing:

  • Element and Nodal Results can be obtained across timesteps

Installation

Installation is currently supported on Windows, all this further support will be added for Linux environments. PyCCX can be installed along with dependencies for GMSH automatically using.

pip install pyccx

Depending on your environment, you will need to install the latest version of Calculix. This can be done through the conda-forge calculix package in the Anaconda distribution,

conda install -c conda-forge calculix

or alternatively downloading the package directly. On Windows platforms the path of the executable needs to be initialised before use.

from pyccx.core import Simulation

# Set the path for Calculix in Windows
Simulation.setCalculixPath('Path')

Usage

The following code excerpt shows an example for creating and running a steady state thermal analysis of model using PyCCX of an existing mesh generated using the pyccx.mesh.mesher class.

from pyccx.core import DOF, ElementSet, NodeSet, SurfaceSet, Simulation
from pyccx.results import ElementResult, NodalResult, ResultProcessor
from pyccx.loadcase import  LoadCase, LoadCaseType
from pyccx.material import ElastoPlasticMaterial

# Set the path for Calculix in Windows
Simulation.setCalculixPath('Path')

# Create a thermal load case and set the timesettings
thermalLoadCase = LoadCase('Thermal Load Case')

# Set the loadcase type to thermal - eventually this will be individual analysis classes with defaults
thermalLoadCase.setLoadCaseType(LoadCaseType.THERMAL)

# Set the thermal analysis to be a steady state simulation
thermalLoadCase.isSteadyState = True

# Attach the nodal and element result options to each loadcase
# Set the nodal and element variables to record in the results (.frd) file
nodeThermalPostResult = NodalResult('VolumeNodeSet')
nodeThermalPostResult.useNodalTemperatures = True

elThermalPostResult = ElementResult('Volume1')
elThermalPostResult.useHeatFlux = True

# Add the result configurations to the loadcase
thermalLoadCase.resultSet = [nodeThermalPostResult, elThermalPostResult]

# Set thermal boundary conditions for the loadcase using specific NodeSets
thermalLoadCase.boundaryConditions.append(
    {'type': 'fixed', 'nodes': 'surface6Nodes', 'dof': [DOF.T], 'value': [60]})

thermalLoadCase.boundaryConditions.append(
    {'type': 'fixed', 'nodes': 'surface1Nodes', 'dof': [DOF.T], 'value': [20]})

# Material
# Add a elastic material and assign it to the volume.
# Note ensure that the units correctly correspond with the geometry length scales
steelMat = ElastoPlasticMaterial('Steel')
steelMat.density = 1.0    # Density
steelMat.cp =  1.0        # Specific Heat
steelMat.k = 1.0          # Thermal Conductivity

analysis.materials.append(steelMat)

# Assign the material the volume (use the part name set for geometry)
analysis.materialAssignments = [('PartA', 'Steel')]

# Set the loadcases used in sequential order
analysis.loadCases = [thermalLoadCase]

# Analysis Run #
# Run the analysis
analysis.run()

# Open the results  file ('input') is currently the file that is generated by PyCCX
results = analysis.results()
results.load()

The basic usage is split between the meshing facilities provided by GMSH and analysing a problem using the Calculix Solver. Documented examples are provided in examples .

pyccx's People

Contributors

drlukeparry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyccx's Issues

Please, move to the Calculix organization

Hi,

I'm trying to develop CalculiX organization on the GitHub to unite all developers and tools in one place. As I can see, you're a member of the organization. So, please, could you move there your amazing library?

All your permissions will be kept, so do not afraid. Old URL will be kept also, new URL will be github.com/calculix/pyccx.

In your project Settings go to Options -> Danger Zone -> Transfer ownership. Click on ‘Transfer’ button, then type ‘calculix’ as user.

Thank you in advance!

Implement Axisymmetric Elements

Axisymmetric Elements are available but implementation and testing within Calculix.

This will assume elements with a 2D cross-section projected by revolution around an axis.

Simulation.results does not take into account working directory

It appears that in the Simulation class (pyccx/analysis/analysis.py), the working directory that was set on object creation is not taken into account when trying to retrieve the results using the results() function. This causes a file not found error when trying to retrieve the results of an analysis when the working directory is not the same as the directory the python script was executed from.

Changing line 500 from: return ResultProcessor('input')
To: return ResultProcessor(os.path.join(self._workingDirectory, 'input'))

Appears to resolve this issue.

Crash on import: ValueError: setting an array element with a sequence.

Hello there!

When trying to import pyccx, the statement 'import pyccx' causes a crash. This is done similarly as the example python file.

Simply commenting out the WEDGE6 class in mesher.py appears to fix it for now for me, but this class is presumably needed somewhere and should probably be fixed.

Traceback (most recent call last):
  File "/mnt/c/Users/CRGam/Documents/tandwielen/calculate.py", line 1, in <module>
    import pyccx
  File "/mnt/c/Users/CRGam/Documents/tandwielen/pyccx/pyccx/__init__.py", line 2, in <module>
    from . import mesh
  File "/mnt/c/Users/CRGam/Documents/tandwielen/pyccx/pyccx/mesh/__init__.py", line 1, in <module>
    from .mesher import ElementType, Mesher, MeshingAlgorithm
  File "/mnt/c/Users/CRGam/Documents/tandwielen/pyccx/pyccx/mesh/mesher.py", line 19, in <module>
    class ElementType:
  File "/mnt/c/Users/CRGam/Documents/tandwielen/pyccx/pyccx/mesh/mesher.py", line 79, in ElementType
    class WEDGE6:
  File "/mnt/c/Users/CRGam/Documents/tandwielen/pyccx/pyccx/mesh/mesher.py", line 84, in WEDGE6
    faces = np.array([[1,2,3], [4,5,6], [1,2,5,4], [2,3,6,5], [3,1,4,6]])
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

Implement a Parview .vtk export function from the ResultsReader

A paraview .vtk export option to view the results from Calculix would be useful to post-process the results and provide a better presentation of the results.

It is possible to visualise the results using Matplotlib, however, the performance is inadaquate for large mesh sizes

Update: The exported .frd files will be transformed within the ResultsProcessor and a separator exporter translator method will become available for conversion to Paraview .vtu format

Update 2: An additional function has been created to export the .pvd XML file that are used for exporting the complete timestep / increment history generated from Calculix.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.