hd

package module
v0.0.0-...-7143788 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 12 Imported by: 0

README

Coverage Status Build Status Go Report Card GoDoc GitHub license

hd

FEM(finite element method) for structural engineer

Specific of truss:
* Generally truss finite element and beam finite element with moment free on node is not the same.
for truss stiffiner matrix look like that
⎡ * 0 0 * 0 0 ⎤
⎢ 0 0 0 0 0 0 ⎥
⎢ 0 0 0 0 0 0 ⎥
⎢ * 0 0 * 0 0 ⎥
⎢ 0 0 0 0 0 0 ⎥
⎣ 0 0 0 0 0 0 ⎦
for beam with moment free on nodes stiffiner matrix look like that
⎡ * 0 0 * 0 0 ⎤
⎢ 0 * 0 0 * 0 ⎥
⎢ 0 0 0 0 0 0 ⎥
⎢ * 0 0 * 0 0 ⎥
⎢ 0 * 0 0 * 0 ⎥
⎣ 0 0 0 0 0 0 ⎦
So, if we have 2 free moment, then also add free by Y direction for bith beam points
Coverage
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out

or on one line:

go test -coverprofile=coverage.out ./... ; go tool cover -html=coverage.out ; rm coverage.out
Benchmark

In folder mod run:

go test -v -run=Benchmark -bench=Benchmark -benchmem -cpuprofile cpu.prof -memprofile mem.prof
goos: linux
goarch: amd64
pkg: github.com/Konstantin8105/hd/mod
BenchmarkRun/____1-cases20-4         	    5184	    202061 ns/op	   95197 B/op	    1052 allocs/op
BenchmarkRun/____2-cases20-4         	    3676	    275535 ns/op	  134711 B/op	    1288 allocs/op
BenchmarkRun/____4-cases20-4         	    2658	    446752 ns/op	  226851 B/op	    1778 allocs/op
BenchmarkRun/____8-cases20-4         	    1460	    807288 ns/op	  440599 B/op	    2738 allocs/op
BenchmarkRun/___16-cases20-4         	     687	   1736805 ns/op	  928967 B/op	    4640 allocs/op
BenchmarkRun/___32-cases20-4         	     230	   5137632 ns/op	 2239788 B/op	    8456 allocs/op
BenchmarkRun/___64-cases20-4         	      57	  18934656 ns/op	 6173719 B/op	   16063 allocs/op
BenchmarkRun/__128-cases20-4         	      10	 105636607 ns/op	18726030 B/op	   31323 allocs/op
PASS
ok  	github.com/Konstantin8105/hd/mod	11.064s

Documentation

Overview

Example
package main

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"os"

	"github.com/Konstantin8105/hd"
	"github.com/pmezard/go-difflib/difflib"
)

func main() {

	m := hd.Model{
		Points: [][2]float64{
			{0.0, 0.0},
			{1.0, 0.0},
		},
		Beams: []hd.BeamProp{
			{N: [2]int{0, 1}, A: 12e-4, J: 120e-6, E: 2.0e11},
		},
		Pins: [][6]bool{
			{false, false, false, false, false, true},
		},
		Supports: [][3]bool{
			{true, true, true},
			{false, false, false},
		},
	}
	lcs := []hd.LoadCase{
		{
			LoadNodes: []hd.LoadNode{
				{N: 1, Forces: [3]float64{0, 2.3, 0}},
				{N: 1, Forces: [3]float64{-10, 0, 0}},
			},
			AmountLinearBuckling: 1,
		},
		{ // test for 2 cases with different positions
			LoadNodes: []hd.LoadNode{
				{N: 1, Forces: [3]float64{-10, 0, 0}},
				{N: 1, Forces: [3]float64{0, 2.3, 0}},
			},
			AmountLinearBuckling: 2,
		},
	}
	mcs := []hd.ModalCase{
		{
			ModalMasses: []hd.ModalMass{{N: 1, Mass: 10000}},
		},
	}

	var b bytes.Buffer
	if err := hd.Run(&b, &m, lcs, mcs); err != nil {
		fmt.Fprintf(os.Stdout, "Cannot calculate : %v", err)
		return
	}

	expect, err := ioutil.ReadFile("./example/testdata/model.String")
	if err != nil {
		panic(fmt.Errorf("Cannot read file : %v", err))
	}

	if bytes.Equal(expect, b.Bytes()) {
		fmt.Fprintf(os.Stdout, "same")
	} else {
		fmt.Fprintln(os.Stdout, b.String())

		// show a diff between files
		diff := difflib.UnifiedDiff{
			A:        difflib.SplitLines(string(expect)),
			B:        difflib.SplitLines(string(b.Bytes())),
			FromFile: "Original",
			ToFile:   "Current",
			Context:  30000,
		}
		text, _ := difflib.GetUnifiedDiffString(diff)
		fmt.Fprintf(os.Stdout, text)

		fmt.Fprintf(os.Stdout, "not same")
	}

}
Output:

same

Index

Examples

Constants

View Source
const Gravity float64 = 9.80665

Gravity is Earth gravity constant, m/sq.sec.

Variables

View Source
var ErrorAmountModel = goerrors.New("Model isn`t single calculation model")

ErrorAmountModel error if calculation model is not single. Calculate calculation models separetaly.

View Source
var ErrorBeamAmount = goerrors.New("Zero beams with non-zero amount of points")

ErrorBeamAmount error if calculation model have points, but haven`t beams.

Functions

func LinearStatic

func LinearStatic(out io.Writer, m *Model, lcs ...*LoadCase) (err error)

LinearStatic run linear static analysis.

func Modal(out io.Writer, m *Model, mc *ModalCase) (err error)

Modal function calcualate all modal frequency with all modal shape.

Selfweigth are ignored.

func Run

func Run(out io.Writer, m *Model, lcs []LoadCase, mcs []ModalCase) (err error)

Types

type BeamProp

type BeamProp struct {
	// Start and end point index
	//
	//	[0] - start of beam
	//	[1] - end of beam
	//
	N [2]int

	// A cross-section area
	// Unit : sq. meter.
	A float64

	// J is moment inertia
	// Unit : meter^4
	J float64

	// E is modulus of elasticity
	// Unit : Pa
	E float64
}

BeamProp is beam property

type BucklingResult

type BucklingResult struct {
	// Buckling factor
	// Return data.
	Factor float64

	// Point displacement in global system coordinate.
	// Return data.
	//
	// first index is point index
	//
	//	[0] - X
	//	[1] - Y
	//	[2] - M
	//
	// Unit: relative
	PointDisplacementGlobal [][3]float64
}

BucklingResult is result of buckling calculation

type ErrorBeam

type ErrorBeam struct {
	BeamIndex int
	Detail    string
	Err       error
}

ErrorBeam error in beam data

func (ErrorBeam) Error

func (e ErrorBeam) Error() string

type ErrorLoad

type ErrorLoad struct {
	LoadPos int
	Err     error
}

ErrorLoad error in load data

func (ErrorLoad) Error

func (e ErrorLoad) Error() string

type ErrorModal

type ErrorModal struct {
	ModalPos int
	Err      error
}

ErrorModal error in modal case data

func (ErrorModal) Error

func (e ErrorModal) Error() string

type ErrorPin

type ErrorPin struct {
	Beam int
	Err  error
}

ErrorPin error in pin data

func (ErrorPin) Error

func (e ErrorPin) Error() string

type ErrorPoint

type ErrorPoint struct {
	PointIndex int
	CoordIndex int
	Err        error
}

ErrorPoint error in point data

func (ErrorPoint) Error

func (e ErrorPoint) Error() string

type LoadCase

type LoadCase struct {
	// LoadNodes is node loads in global system coordinate
	LoadNodes []LoadNode

	// Point displacement in global system coordinate.
	// Return data.
	//
	// first index is point index
	//
	//	[0] - X
	//	[1] - Y
	//	[2] - M
	//
	// Unit: meter and rad.
	PointDisplacementGlobal [][3]float64

	// BeamForces is beam forces in local system coordinate.
	// Return data.
	//
	// first index is beam index
	//
	//	[0] - Fx on start point
	//	[1] - Fy on start point
	//	[2] - M  on start point
	//	[3] - Fx on end point
	//	[4] - Fy on end point
	//	[5] - M  on end point
	//
	// Unit: N and N*m
	BeamForces [][6]float64

	// Reactions is reaction loads in support points.
	// Return data.
	//
	// first index is point index
	//
	//	[0] - Fx
	//	[1] - Fy
	//	[2] - M
	//
	// Unit: N and N*m
	Reactions [][3]float64

	// Amount of calculated forms.
	// If Amount is zero or less zero, then no calculate.
	// LinearBuckling is linear buckling calculation
	AmountLinearBuckling uint16

	// Result of linear buckling calculation
	LinearBucklingResult []BucklingResult
}

LoadCase is summary combination of loads

func (LoadCase) String

func (lc LoadCase) String() (out string)

type LoadNode

type LoadNode struct {
	// N is point index
	N int

	// Forces is node loads on each direction
	//
	//	[0] - X , Unit: N. Positive direction from left to right.
	//	[1] - Y , Unit: N. Positive direction from down to top.
	//	[2] - M , Unit: N*m. Positive direction is counter-clockwise direction.
	//
	Forces [3]float64
}

LoadNode is node load on specific point in global system coordinate

type ModalCase

type ModalCase struct {
	// ModalMasses is modal masses
	ModalMasses []ModalMass

	// Result of modal calculation
	Result []ModalResult
}

ModalCase is modal calculation case

func (ModalCase) String

func (m ModalCase) String() (out string)

type ModalMass

type ModalMass struct {
	// N is point index
	N int

	// Mass of point
	// Unit: N
	Mass float64
}

ModalMass is mass of point

type ModalResult

type ModalResult struct {
	// Natural frequency
	Hz float64

	// Modal displacament in global system coordinate
	//
	// first index is point index
	//
	//	[0] - X direction
	//	[1] - Y direction
	//	[2] - M direction
	//
	// Unit: Dimensionless
	ModalDisplacement [][3]float64
}

ModalResult is result of modal calculation

type Model

type Model struct {
	// Points is slice of point coordinate
	//
	//	[0] - X coordinate
	//	[1] - Y coordinate
	//
	Points [][2]float64

	// Beams is slice of point index and beam property
	Beams []BeamProp

	// Pins is slice of pins for beams in local system coordinate.
	// Len of support must be same amount of beam.
	// Or if len is zero, then all DoF(degree of freedom) is rigid.
	//
	// first index is point index
	//
	//	[0] - X on start point
	//	[1] - Y on start point
	//	[2] - M on start point
	//	[3] - X on end point
	//	[4] - Y on end point
	//	[5] - M on end point
	//
	// if `true` then free degree of freedom
	Pins [][6]bool

	// Supports is slice of fixed supports.
	// Len of support must be same amount of Points
	//
	// first index is point index
	//
	//	[0] - X
	//	[1] - Y
	//	[2] - M
	//
	Supports [][3]bool
}

Model is structural calculation model

func (Model) String

func (m Model) String() (out string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL