From bfd0458f4f6dfa684944e8f3d6b30396f67861dd Mon Sep 17 00:00:00 2001 From: Mohamed Tarek Date: Sun, 4 Feb 2024 00:07:55 +1100 Subject: [PATCH] Fix INP parser and CG solvers (#170) * fix inp parser and test on MBB.inp * fix and test CG solvers * bump version * fix typeof CG abstol * fix typeof CG abstol --- Project.toml | 2 +- src/FEA/assembly_cg_displacement_solvers.jl | 2 +- .../matrix_free_cg_displacement_solvers.jl | 12 +- .../Parser/FeatureExtractors/extract_cload.jl | 2 +- src/TopOptProblems/elementmatrix.jl | 13 - src/Utilities/Utilities.jl | 3 +- src/Utilities/utils.jl | 13 + test/fea/solvers.jl | 10 +- test/inp_parser/MBB.inp | 870 ++++++++++++++++++ test/inp_parser/parser.jl | 29 +- 10 files changed, 925 insertions(+), 31 deletions(-) create mode 100644 test/inp_parser/MBB.inp diff --git a/Project.toml b/Project.toml index 97010245..8af3cb7b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TopOpt" uuid = "53a1e1a5-51bb-58a9-8a02-02056cc81109" authors = ["mohamed82008 ", "yijiangh "] -version = "0.8.2" +version = "0.8.3" [deps] AbstractDifferentiation = "c29ec348-61ec-40c8-8164-b8c60e9d9f3d" diff --git a/src/FEA/assembly_cg_displacement_solvers.jl b/src/FEA/assembly_cg_displacement_solvers.jl index f64c4808..9c45fa37 100644 --- a/src/FEA/assembly_cg_displacement_solvers.jl +++ b/src/FEA/assembly_cg_displacement_solvers.jl @@ -25,7 +25,7 @@ function PCGDisplacementSolver( conv=DefaultCriteria(), xmin=T(1) / 1000, cg_max_iter=700, - abstol=zero(real(T)), + abstol=T(1e-7), penalty=PowerPenalty{T}(1), prev_penalty=deepcopy(penalty), preconditioner=identity, diff --git a/src/FEA/matrix_free_cg_displacement_solvers.jl b/src/FEA/matrix_free_cg_displacement_solvers.jl index c1075a39..f3fc2086 100644 --- a/src/FEA/matrix_free_cg_displacement_solvers.jl +++ b/src/FEA/matrix_free_cg_displacement_solvers.jl @@ -17,7 +17,7 @@ abstract type AbstractMatrixFreeSolver <: AbstractDisplacementSolver end prev_penalty::TP xmin::T cg_max_iter::Integer - tol::T + abstol::T cg_statevars::CGStateVariables{T} preconditioner::Any preconditioner_initialized::Base.RefValue{Bool} @@ -37,7 +37,7 @@ function StaticMatrixFreeDisplacementSolver( conv=DefaultCriteria(), xmin=one(T) / 1000, cg_max_iter=700, - tol=xmin, + abstol=T(1e-7), penalty=PowerPenalty{T}(1), prev_penalty=deepcopy(penalty), preconditioner=identity, @@ -77,7 +77,7 @@ function StaticMatrixFreeDisplacementSolver( prev_penalty, xmin, cg_max_iter, - tol, + abstol, cg_statevars, preconditioner, Ref(false), @@ -114,7 +114,7 @@ function (s::StaticMatrixFreeDisplacementSolver)(; ) @unpack cg_max_iter, cg_statevars = s - @unpack preconditioner_initialized, preconditioner, tol = s + @unpack preconditioner_initialized, preconditioner, abstol = s operator = buildoperator(s) if !(preconditioner === identity) @@ -128,7 +128,7 @@ function (s::StaticMatrixFreeDisplacementSolver)(; lhs, operator, rhs; - tol=tol, + abstol, maxiter=cg_max_iter, log=false, statevars=cg_statevars, @@ -139,7 +139,7 @@ function (s::StaticMatrixFreeDisplacementSolver)(; lhs, operator, rhs; - tol=tol, + abstol, maxiter=cg_max_iter, log=false, statevars=cg_statevars, diff --git a/src/TopOptProblems/IO/INP/Parser/FeatureExtractors/extract_cload.jl b/src/TopOptProblems/IO/INP/Parser/FeatureExtractors/extract_cload.jl index cad8ffa2..f5ce84b4 100644 --- a/src/TopOptProblems/IO/INP/Parser/FeatureExtractors/extract_cload.jl +++ b/src/TopOptProblems/IO/INP/Parser/FeatureExtractors/extract_cload.jl @@ -1,7 +1,7 @@ function extract_cload!( cloads::Dict{TI,Vector{TF}}, file, ::Type{Val{dim}} ) where {TI,TF,dim} - pattern = r"(\d+)\s*,\s*(\d)\s*,\s*(\-?\d+\.\d*E[\+\-]\d{2})" + pattern = r"\s*([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*,\s*([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*,\s*([-+]?\d*\.?\d+(?:[eE][-+]?\d+)?)\s*" line = readline(file) m = match(stopping_pattern, line) while m isa Nothing diff --git a/src/TopOptProblems/elementmatrix.jl b/src/TopOptProblems/elementmatrix.jl index 9d32e9d1..f0020167 100644 --- a/src/TopOptProblems/elementmatrix.jl +++ b/src/TopOptProblems/elementmatrix.jl @@ -142,16 +142,3 @@ function Base.convert( end return element_Kes end - -for TM in (:(StaticMatrix{m,m,T}), :(Symmetric{T,<:StaticMatrix{m,m,T}})) - @eval begin - @generated function sumdiag(K::$TM) where {m,T} - return reduce((ex1, ex2) -> :($ex1 + $ex2), [:(K[$j, $j]) for j in 1:m]) - end - end -end -@doc """ -sumdiag(K::Union{StaticMatrix, Symmetric{<:Any, <:StaticMatrix}}) - -Computes the sum of the diagonal of the static matrix `K`. -""" sumdiag diff --git a/src/Utilities/Utilities.jl b/src/Utilities/Utilities.jl index 3c0dcf8b..274162b3 100644 --- a/src/Utilities/Utilities.jl +++ b/src/Utilities/Utilities.jl @@ -1,6 +1,6 @@ module Utilities -using ForwardDiff, Ferrite, IterativeSolvers, Requires +using ForwardDiff, Ferrite, IterativeSolvers, Requires, StaticArrays, LinearAlgebra export AbstractPenalty, PowerPenalty, @@ -13,6 +13,7 @@ export AbstractPenalty, RaggedArray, @debug, compliance, + sumdiag, meandiag, density, find_black_and_white, diff --git a/src/Utilities/utils.jl b/src/Utilities/utils.jl index cb1b4f55..65ce16ce 100644 --- a/src/Utilities/utils.jl +++ b/src/Utilities/utils.jl @@ -178,3 +178,16 @@ macro forward_property(T, field) end end end + +for TM in (:(StaticMatrix{m,m,T}), :(Symmetric{T,<:StaticMatrix{m,m,T}})) + @eval begin + @generated function sumdiag(K::$TM) where {m,T} + return reduce((ex1, ex2) -> :($ex1 + $ex2), [:(K[$j, $j]) for j in 1:m]) + end + end +end +@doc """ +sumdiag(K::Union{StaticMatrix, Symmetric{<:Any, <:StaticMatrix}}) + +Computes the sum of the diagonal of the static matrix `K`. +""" sumdiag diff --git a/test/fea/solvers.jl b/test/fea/solvers.jl index 4f62a22c..13b96685 100644 --- a/test/fea/solvers.jl +++ b/test/fea/solvers.jl @@ -8,17 +8,17 @@ force = -1.0 problem = PointLoadCantilever(Val{:Linear}, nels, sizes, E, ν, force) solver1 = FEASolver(Direct, problem) # Takes forever to compile -# solver2 = FEASolver(CG, MatrixFree, problem) -solver3 = FEASolver(CG, Assembly, problem) +solver2 = FEASolver(CG, MatrixFree, problem, abstol = 1e-7) +solver3 = FEASolver(CG, Assembly, problem, abstol = 1e-7) x0 = rand(length(solver1.vars)) solver1.vars .= x0 -# solver2.vars .= x0 +solver2.vars .= x0 solver3.vars .= x0 solver1() -# solver2() +solver2() solver3() -#@test solver1.u ≈ solver2.u +@test solver1.u ≈ solver2.u @test solver1.u ≈ solver3.u diff --git a/test/inp_parser/MBB.inp b/test/inp_parser/MBB.inp new file mode 100644 index 00000000..34c0f37d --- /dev/null +++ b/test/inp_parser/MBB.inp @@ -0,0 +1,870 @@ +*Heading +** Job name: SampleAnalysis Model name: Model-1 +*Preprint, echo=NO, model=NO, history=NO, contact=NO +*Node, NSET=Nall +1, 0.0, 0.0 +2, 5.0, 0.0 +3, 10.0, 0.0 +4, 15.0, 0.0 +5, 20.0, 0.0 +6, 25.0, 0.0 +7, 30.0, 0.0 +8, 35.0, 0.0 +9, 40.0, 0.0 +10, 45.0, 0.0 +11, 50.0, 0.0 +12, 55.0, 0.0 +13, 60.0, 0.0 +14, 65.0, 0.0 +15, 70.0, 0.0 +16, 75.0, 0.0 +17, 80.0, 0.0 +18, 85.0, 0.0 +19, 90.0, 0.0 +20, 95.0, 0.0 +21, 100.0, 0.0 +22, 105.0, 0.0 +23, 110.0, 0.0 +24, 115.0, 0.0 +25, 120.0, 0.0 +26, 125.0, 0.0 +27, 130.0, 0.0 +28, 135.0, 0.0 +29, 140.0, 0.0 +30, 145.0, 0.0 +31, 150.0, 0.0 +32, 155.0, 0.0 +33, 160.0, 0.0 +34, 165.0, 0.0 +35, 170.0, 0.0 +36, 175.0, 0.0 +37, 180.0, 0.0 +38, 185.0, 0.0 +39, 190.0, 0.0 +40, 195.0, 0.0 +41, 200.0, 0.0 +42, 0.0, 5.0 +43, 5.0, 5.0 +44, 10.0, 5.0 +45, 15.0, 5.0 +46, 20.0, 5.0 +47, 25.0, 5.0 +48, 30.0, 5.0 +49, 35.0, 5.0 +50, 40.0, 5.0 +51, 45.0, 5.0 +52, 50.0, 5.0 +53, 55.0, 5.0 +54, 60.0, 5.0 +55, 65.0, 5.0 +56, 70.0, 5.0 +57, 75.0, 5.0 +58, 80.0, 5.0 +59, 85.0, 5.0 +60, 90.0, 5.0 +61, 95.0, 5.0 +62, 100.0, 5.0 +63, 105.0, 5.0 +64, 110.0, 5.0 +65, 115.0, 5.0 +66, 120.0, 5.0 +67, 125.0, 5.0 +68, 130.0, 5.0 +69, 135.0, 5.0 +70, 140.0, 5.0 +71, 145.0, 5.0 +72, 150.0, 5.0 +73, 155.0, 5.0 +74, 160.0, 5.0 +75, 165.0, 5.0 +76, 170.0, 5.0 +77, 175.0, 5.0 +78, 180.0, 5.0 +79, 185.0, 5.0 +80, 190.0, 5.0 +81, 195.0, 5.0 +82, 200.0, 5.0 +83, 0.0, 10.0 +84, 5.0, 10.0 +85, 10.0, 10.0 +86, 15.0, 10.0 +87, 20.0, 10.0 +88, 25.0, 10.0 +89, 30.0, 10.0 +90, 35.0, 10.0 +91, 40.0, 10.0 +92, 45.0, 10.0 +93, 50.0, 10.0 +94, 55.0, 10.0 +95, 60.0, 10.0 +96, 65.0, 10.0 +97, 70.0, 10.0 +98, 75.0, 10.0 +99, 80.0, 10.0 +100, 85.0, 10.0 +101, 90.0, 10.0 +102, 95.0, 10.0 +103, 100.0, 10.0 +104, 105.0, 10.0 +105, 110.0, 10.0 +106, 115.0, 10.0 +107, 120.0, 10.0 +108, 125.0, 10.0 +109, 130.0, 10.0 +110, 135.0, 10.0 +111, 140.0, 10.0 +112, 145.0, 10.0 +113, 150.0, 10.0 +114, 155.0, 10.0 +115, 160.0, 10.0 +116, 165.0, 10.0 +117, 170.0, 10.0 +118, 175.0, 10.0 +119, 180.0, 10.0 +120, 185.0, 10.0 +121, 190.0, 10.0 +122, 195.0, 10.0 +123, 200.0, 10.0 +124, 0.0, 15.0 +125, 5.0, 15.0 +126, 10.0, 15.0 +127, 15.0, 15.0 +128, 20.0, 15.0 +129, 25.0, 15.0 +130, 30.0, 15.0 +131, 35.0, 15.0 +132, 40.0, 15.0 +133, 45.0, 15.0 +134, 50.0, 15.0 +135, 55.0, 15.0 +136, 60.0, 15.0 +137, 65.0, 15.0 +138, 70.0, 15.0 +139, 75.0, 15.0 +140, 80.0, 15.0 +141, 85.0, 15.0 +142, 90.0, 15.0 +143, 95.0, 15.0 +144, 100.0, 15.0 +145, 105.0, 15.0 +146, 110.0, 15.0 +147, 115.0, 15.0 +148, 120.0, 15.0 +149, 125.0, 15.0 +150, 130.0, 15.0 +151, 135.0, 15.0 +152, 140.0, 15.0 +153, 145.0, 15.0 +154, 150.0, 15.0 +155, 155.0, 15.0 +156, 160.0, 15.0 +157, 165.0, 15.0 +158, 170.0, 15.0 +159, 175.0, 15.0 +160, 180.0, 15.0 +161, 185.0, 15.0 +162, 190.0, 15.0 +163, 195.0, 15.0 +164, 200.0, 15.0 +165, 0.0, 20.0 +166, 5.0, 20.0 +167, 10.0, 20.0 +168, 15.0, 20.0 +169, 20.0, 20.0 +170, 25.0, 20.0 +171, 30.0, 20.0 +172, 35.0, 20.0 +173, 40.0, 20.0 +174, 45.0, 20.0 +175, 50.0, 20.0 +176, 55.0, 20.0 +177, 60.0, 20.0 +178, 65.0, 20.0 +179, 70.0, 20.0 +180, 75.0, 20.0 +181, 80.0, 20.0 +182, 85.0, 20.0 +183, 90.0, 20.0 +184, 95.0, 20.0 +185, 100.0, 20.0 +186, 105.0, 20.0 +187, 110.0, 20.0 +188, 115.0, 20.0 +189, 120.0, 20.0 +190, 125.0, 20.0 +191, 130.0, 20.0 +192, 135.0, 20.0 +193, 140.0, 20.0 +194, 145.0, 20.0 +195, 150.0, 20.0 +196, 155.0, 20.0 +197, 160.0, 20.0 +198, 165.0, 20.0 +199, 170.0, 20.0 +200, 175.0, 20.0 +201, 180.0, 20.0 +202, 185.0, 20.0 +203, 190.0, 20.0 +204, 195.0, 20.0 +205, 200.0, 20.0 +206, 0.0, 25.0 +207, 5.0, 25.0 +208, 10.0, 25.0 +209, 15.0, 25.0 +210, 20.0, 25.0 +211, 25.0, 25.0 +212, 30.0, 25.0 +213, 35.0, 25.0 +214, 40.0, 25.0 +215, 45.0, 25.0 +216, 50.0, 25.0 +217, 55.0, 25.0 +218, 60.0, 25.0 +219, 65.0, 25.0 +220, 70.0, 25.0 +221, 75.0, 25.0 +222, 80.0, 25.0 +223, 85.0, 25.0 +224, 90.0, 25.0 +225, 95.0, 25.0 +226, 100.0, 25.0 +227, 105.0, 25.0 +228, 110.0, 25.0 +229, 115.0, 25.0 +230, 120.0, 25.0 +231, 125.0, 25.0 +232, 130.0, 25.0 +233, 135.0, 25.0 +234, 140.0, 25.0 +235, 145.0, 25.0 +236, 150.0, 25.0 +237, 155.0, 25.0 +238, 160.0, 25.0 +239, 165.0, 25.0 +240, 170.0, 25.0 +241, 175.0, 25.0 +242, 180.0, 25.0 +243, 185.0, 25.0 +244, 190.0, 25.0 +245, 195.0, 25.0 +246, 200.0, 25.0 +247, 0.0, 30.0 +248, 5.0, 30.0 +249, 10.0, 30.0 +250, 15.0, 30.0 +251, 20.0, 30.0 +252, 25.0, 30.0 +253, 30.0, 30.0 +254, 35.0, 30.0 +255, 40.0, 30.0 +256, 45.0, 30.0 +257, 50.0, 30.0 +258, 55.0, 30.0 +259, 60.0, 30.0 +260, 65.0, 30.0 +261, 70.0, 30.0 +262, 75.0, 30.0 +263, 80.0, 30.0 +264, 85.0, 30.0 +265, 90.0, 30.0 +266, 95.0, 30.0 +267, 100.0, 30.0 +268, 105.0, 30.0 +269, 110.0, 30.0 +270, 115.0, 30.0 +271, 120.0, 30.0 +272, 125.0, 30.0 +273, 130.0, 30.0 +274, 135.0, 30.0 +275, 140.0, 30.0 +276, 145.0, 30.0 +277, 150.0, 30.0 +278, 155.0, 30.0 +279, 160.0, 30.0 +280, 165.0, 30.0 +281, 170.0, 30.0 +282, 175.0, 30.0 +283, 180.0, 30.0 +284, 185.0, 30.0 +285, 190.0, 30.0 +286, 195.0, 30.0 +287, 200.0, 30.0 +288, 0.0, 35.0 +289, 5.0, 35.0 +290, 10.0, 35.0 +291, 15.0, 35.0 +292, 20.0, 35.0 +293, 25.0, 35.0 +294, 30.0, 35.0 +295, 35.0, 35.0 +296, 40.0, 35.0 +297, 45.0, 35.0 +298, 50.0, 35.0 +299, 55.0, 35.0 +300, 60.0, 35.0 +301, 65.0, 35.0 +302, 70.0, 35.0 +303, 75.0, 35.0 +304, 80.0, 35.0 +305, 85.0, 35.0 +306, 90.0, 35.0 +307, 95.0, 35.0 +308, 100.0, 35.0 +309, 105.0, 35.0 +310, 110.0, 35.0 +311, 115.0, 35.0 +312, 120.0, 35.0 +313, 125.0, 35.0 +314, 130.0, 35.0 +315, 135.0, 35.0 +316, 140.0, 35.0 +317, 145.0, 35.0 +318, 150.0, 35.0 +319, 155.0, 35.0 +320, 160.0, 35.0 +321, 165.0, 35.0 +322, 170.0, 35.0 +323, 175.0, 35.0 +324, 180.0, 35.0 +325, 185.0, 35.0 +326, 190.0, 35.0 +327, 195.0, 35.0 +328, 200.0, 35.0 +329, 0.0, 40.0 +330, 5.0, 40.0 +331, 10.0, 40.0 +332, 15.0, 40.0 +333, 20.0, 40.0 +334, 25.0, 40.0 +335, 30.0, 40.0 +336, 35.0, 40.0 +337, 40.0, 40.0 +338, 45.0, 40.0 +339, 50.0, 40.0 +340, 55.0, 40.0 +341, 60.0, 40.0 +342, 65.0, 40.0 +343, 70.0, 40.0 +344, 75.0, 40.0 +345, 80.0, 40.0 +346, 85.0, 40.0 +347, 90.0, 40.0 +348, 95.0, 40.0 +349, 100.0, 40.0 +350, 105.0, 40.0 +351, 110.0, 40.0 +352, 115.0, 40.0 +353, 120.0, 40.0 +354, 125.0, 40.0 +355, 130.0, 40.0 +356, 135.0, 40.0 +357, 140.0, 40.0 +358, 145.0, 40.0 +359, 150.0, 40.0 +360, 155.0, 40.0 +361, 160.0, 40.0 +362, 165.0, 40.0 +363, 170.0, 40.0 +364, 175.0, 40.0 +365, 180.0, 40.0 +366, 185.0, 40.0 +367, 190.0, 40.0 +368, 195.0, 40.0 +369, 200.0, 40.0 +370, 0.0, 45.0 +371, 5.0, 45.0 +372, 10.0, 45.0 +373, 15.0, 45.0 +374, 20.0, 45.0 +375, 25.0, 45.0 +376, 30.0, 45.0 +377, 35.0, 45.0 +378, 40.0, 45.0 +379, 45.0, 45.0 +380, 50.0, 45.0 +381, 55.0, 45.0 +382, 60.0, 45.0 +383, 65.0, 45.0 +384, 70.0, 45.0 +385, 75.0, 45.0 +386, 80.0, 45.0 +387, 85.0, 45.0 +388, 90.0, 45.0 +389, 95.0, 45.0 +390, 100.0, 45.0 +391, 105.0, 45.0 +392, 110.0, 45.0 +393, 115.0, 45.0 +394, 120.0, 45.0 +395, 125.0, 45.0 +396, 130.0, 45.0 +397, 135.0, 45.0 +398, 140.0, 45.0 +399, 145.0, 45.0 +400, 150.0, 45.0 +401, 155.0, 45.0 +402, 160.0, 45.0 +403, 165.0, 45.0 +404, 170.0, 45.0 +405, 175.0, 45.0 +406, 180.0, 45.0 +407, 185.0, 45.0 +408, 190.0, 45.0 +409, 195.0, 45.0 +410, 200.0, 45.0 +411, 0.0, 50.0 +412, 5.0, 50.0 +413, 10.0, 50.0 +414, 15.0, 50.0 +415, 20.0, 50.0 +416, 25.0, 50.0 +417, 30.0, 50.0 +418, 35.0, 50.0 +419, 40.0, 50.0 +420, 45.0, 50.0 +421, 50.0, 50.0 +422, 55.0, 50.0 +423, 60.0, 50.0 +424, 65.0, 50.0 +425, 70.0, 50.0 +426, 75.0, 50.0 +427, 80.0, 50.0 +428, 85.0, 50.0 +429, 90.0, 50.0 +430, 95.0, 50.0 +431, 100.0, 50.0 +432, 105.0, 50.0 +433, 110.0, 50.0 +434, 115.0, 50.0 +435, 120.0, 50.0 +436, 125.0, 50.0 +437, 130.0, 50.0 +438, 135.0, 50.0 +439, 140.0, 50.0 +440, 145.0, 50.0 +441, 150.0, 50.0 +442, 155.0, 50.0 +443, 160.0, 50.0 +444, 165.0, 50.0 +445, 170.0, 50.0 +446, 175.0, 50.0 +447, 180.0, 50.0 +448, 185.0, 50.0 +449, 190.0, 50.0 +450, 195.0, 50.0 +451, 200.0, 50.0 +*Element, TYPE=CPS4, ELSET=EALL +1, 1, 2, 43, 42 +2, 2, 3, 44, 43 +3, 3, 4, 45, 44 +4, 4, 5, 46, 45 +5, 5, 6, 47, 46 +6, 6, 7, 48, 47 +7, 7, 8, 49, 48 +8, 8, 9, 50, 49 +9, 9, 10, 51, 50 +10, 10, 11, 52, 51 +11, 11, 12, 53, 52 +12, 12, 13, 54, 53 +13, 13, 14, 55, 54 +14, 14, 15, 56, 55 +15, 15, 16, 57, 56 +16, 16, 17, 58, 57 +17, 17, 18, 59, 58 +18, 18, 19, 60, 59 +19, 19, 20, 61, 60 +20, 20, 21, 62, 61 +21, 21, 22, 63, 62 +22, 22, 23, 64, 63 +23, 23, 24, 65, 64 +24, 24, 25, 66, 65 +25, 25, 26, 67, 66 +26, 26, 27, 68, 67 +27, 27, 28, 69, 68 +28, 28, 29, 70, 69 +29, 29, 30, 71, 70 +30, 30, 31, 72, 71 +31, 31, 32, 73, 72 +32, 32, 33, 74, 73 +33, 33, 34, 75, 74 +34, 34, 35, 76, 75 +35, 35, 36, 77, 76 +36, 36, 37, 78, 77 +37, 37, 38, 79, 78 +38, 38, 39, 80, 79 +39, 39, 40, 81, 80 +40, 40, 41, 82, 81 +41, 42, 43, 84, 83 +42, 43, 44, 85, 84 +43, 44, 45, 86, 85 +44, 45, 46, 87, 86 +45, 46, 47, 88, 87 +46, 47, 48, 89, 88 +47, 48, 49, 90, 89 +48, 49, 50, 91, 90 +49, 50, 51, 92, 91 +50, 51, 52, 93, 92 +51, 52, 53, 94, 93 +52, 53, 54, 95, 94 +53, 54, 55, 96, 95 +54, 55, 56, 97, 96 +55, 56, 57, 98, 97 +56, 57, 58, 99, 98 +57, 58, 59, 100, 99 +58, 59, 60, 101, 100 +59, 60, 61, 102, 101 +60, 61, 62, 103, 102 +61, 62, 63, 104, 103 +62, 63, 64, 105, 104 +63, 64, 65, 106, 105 +64, 65, 66, 107, 106 +65, 66, 67, 108, 107 +66, 67, 68, 109, 108 +67, 68, 69, 110, 109 +68, 69, 70, 111, 110 +69, 70, 71, 112, 111 +70, 71, 72, 113, 112 +71, 72, 73, 114, 113 +72, 73, 74, 115, 114 +73, 74, 75, 116, 115 +74, 75, 76, 117, 116 +75, 76, 77, 118, 117 +76, 77, 78, 119, 118 +77, 78, 79, 120, 119 +78, 79, 80, 121, 120 +79, 80, 81, 122, 121 +80, 81, 82, 123, 122 +81, 83, 84, 125, 124 +82, 84, 85, 126, 125 +83, 85, 86, 127, 126 +84, 86, 87, 128, 127 +85, 87, 88, 129, 128 +86, 88, 89, 130, 129 +87, 89, 90, 131, 130 +88, 90, 91, 132, 131 +89, 91, 92, 133, 132 +90, 92, 93, 134, 133 +91, 93, 94, 135, 134 +92, 94, 95, 136, 135 +93, 95, 96, 137, 136 +94, 96, 97, 138, 137 +95, 97, 98, 139, 138 +96, 98, 99, 140, 139 +97, 99, 100, 141, 140 +98, 100, 101, 142, 141 +99, 101, 102, 143, 142 +100, 102, 103, 144, 143 +101, 103, 104, 145, 144 +102, 104, 105, 146, 145 +103, 105, 106, 147, 146 +104, 106, 107, 148, 147 +105, 107, 108, 149, 148 +106, 108, 109, 150, 149 +107, 109, 110, 151, 150 +108, 110, 111, 152, 151 +109, 111, 112, 153, 152 +110, 112, 113, 154, 153 +111, 113, 114, 155, 154 +112, 114, 115, 156, 155 +113, 115, 116, 157, 156 +114, 116, 117, 158, 157 +115, 117, 118, 159, 158 +116, 118, 119, 160, 159 +117, 119, 120, 161, 160 +118, 120, 121, 162, 161 +119, 121, 122, 163, 162 +120, 122, 123, 164, 163 +121, 124, 125, 166, 165 +122, 125, 126, 167, 166 +123, 126, 127, 168, 167 +124, 127, 128, 169, 168 +125, 128, 129, 170, 169 +126, 129, 130, 171, 170 +127, 130, 131, 172, 171 +128, 131, 132, 173, 172 +129, 132, 133, 174, 173 +130, 133, 134, 175, 174 +131, 134, 135, 176, 175 +132, 135, 136, 177, 176 +133, 136, 137, 178, 177 +134, 137, 138, 179, 178 +135, 138, 139, 180, 179 +136, 139, 140, 181, 180 +137, 140, 141, 182, 181 +138, 141, 142, 183, 182 +139, 142, 143, 184, 183 +140, 143, 144, 185, 184 +141, 144, 145, 186, 185 +142, 145, 146, 187, 186 +143, 146, 147, 188, 187 +144, 147, 148, 189, 188 +145, 148, 149, 190, 189 +146, 149, 150, 191, 190 +147, 150, 151, 192, 191 +148, 151, 152, 193, 192 +149, 152, 153, 194, 193 +150, 153, 154, 195, 194 +151, 154, 155, 196, 195 +152, 155, 156, 197, 196 +153, 156, 157, 198, 197 +154, 157, 158, 199, 198 +155, 158, 159, 200, 199 +156, 159, 160, 201, 200 +157, 160, 161, 202, 201 +158, 161, 162, 203, 202 +159, 162, 163, 204, 203 +160, 163, 164, 205, 204 +161, 165, 166, 207, 206 +162, 166, 167, 208, 207 +163, 167, 168, 209, 208 +164, 168, 169, 210, 209 +165, 169, 170, 211, 210 +166, 170, 171, 212, 211 +167, 171, 172, 213, 212 +168, 172, 173, 214, 213 +169, 173, 174, 215, 214 +170, 174, 175, 216, 215 +171, 175, 176, 217, 216 +172, 176, 177, 218, 217 +173, 177, 178, 219, 218 +174, 178, 179, 220, 219 +175, 179, 180, 221, 220 +176, 180, 181, 222, 221 +177, 181, 182, 223, 222 +178, 182, 183, 224, 223 +179, 183, 184, 225, 224 +180, 184, 185, 226, 225 +181, 185, 186, 227, 226 +182, 186, 187, 228, 227 +183, 187, 188, 229, 228 +184, 188, 189, 230, 229 +185, 189, 190, 231, 230 +186, 190, 191, 232, 231 +187, 191, 192, 233, 232 +188, 192, 193, 234, 233 +189, 193, 194, 235, 234 +190, 194, 195, 236, 235 +191, 195, 196, 237, 236 +192, 196, 197, 238, 237 +193, 197, 198, 239, 238 +194, 198, 199, 240, 239 +195, 199, 200, 241, 240 +196, 200, 201, 242, 241 +197, 201, 202, 243, 242 +198, 202, 203, 244, 243 +199, 203, 204, 245, 244 +200, 204, 205, 246, 245 +201, 206, 207, 248, 247 +202, 207, 208, 249, 248 +203, 208, 209, 250, 249 +204, 209, 210, 251, 250 +205, 210, 211, 252, 251 +206, 211, 212, 253, 252 +207, 212, 213, 254, 253 +208, 213, 214, 255, 254 +209, 214, 215, 256, 255 +210, 215, 216, 257, 256 +211, 216, 217, 258, 257 +212, 217, 218, 259, 258 +213, 218, 219, 260, 259 +214, 219, 220, 261, 260 +215, 220, 221, 262, 261 +216, 221, 222, 263, 262 +217, 222, 223, 264, 263 +218, 223, 224, 265, 264 +219, 224, 225, 266, 265 +220, 225, 226, 267, 266 +221, 226, 227, 268, 267 +222, 227, 228, 269, 268 +223, 228, 229, 270, 269 +224, 229, 230, 271, 270 +225, 230, 231, 272, 271 +226, 231, 232, 273, 272 +227, 232, 233, 274, 273 +228, 233, 234, 275, 274 +229, 234, 235, 276, 275 +230, 235, 236, 277, 276 +231, 236, 237, 278, 277 +232, 237, 238, 279, 278 +233, 238, 239, 280, 279 +234, 239, 240, 281, 280 +235, 240, 241, 282, 281 +236, 241, 242, 283, 282 +237, 242, 243, 284, 283 +238, 243, 244, 285, 284 +239, 244, 245, 286, 285 +240, 245, 246, 287, 286 +241, 247, 248, 289, 288 +242, 248, 249, 290, 289 +243, 249, 250, 291, 290 +244, 250, 251, 292, 291 +245, 251, 252, 293, 292 +246, 252, 253, 294, 293 +247, 253, 254, 295, 294 +248, 254, 255, 296, 295 +249, 255, 256, 297, 296 +250, 256, 257, 298, 297 +251, 257, 258, 299, 298 +252, 258, 259, 300, 299 +253, 259, 260, 301, 300 +254, 260, 261, 302, 301 +255, 261, 262, 303, 302 +256, 262, 263, 304, 303 +257, 263, 264, 305, 304 +258, 264, 265, 306, 305 +259, 265, 266, 307, 306 +260, 266, 267, 308, 307 +261, 267, 268, 309, 308 +262, 268, 269, 310, 309 +263, 269, 270, 311, 310 +264, 270, 271, 312, 311 +265, 271, 272, 313, 312 +266, 272, 273, 314, 313 +267, 273, 274, 315, 314 +268, 274, 275, 316, 315 +269, 275, 276, 317, 316 +270, 276, 277, 318, 317 +271, 277, 278, 319, 318 +272, 278, 279, 320, 319 +273, 279, 280, 321, 320 +274, 280, 281, 322, 321 +275, 281, 282, 323, 322 +276, 282, 283, 324, 323 +277, 283, 284, 325, 324 +278, 284, 285, 326, 325 +279, 285, 286, 327, 326 +280, 286, 287, 328, 327 +281, 288, 289, 330, 329 +282, 289, 290, 331, 330 +283, 290, 291, 332, 331 +284, 291, 292, 333, 332 +285, 292, 293, 334, 333 +286, 293, 294, 335, 334 +287, 294, 295, 336, 335 +288, 295, 296, 337, 336 +289, 296, 297, 338, 337 +290, 297, 298, 339, 338 +291, 298, 299, 340, 339 +292, 299, 300, 341, 340 +293, 300, 301, 342, 341 +294, 301, 302, 343, 342 +295, 302, 303, 344, 343 +296, 303, 304, 345, 344 +297, 304, 305, 346, 345 +298, 305, 306, 347, 346 +299, 306, 307, 348, 347 +300, 307, 308, 349, 348 +301, 308, 309, 350, 349 +302, 309, 310, 351, 350 +303, 310, 311, 352, 351 +304, 311, 312, 353, 352 +305, 312, 313, 354, 353 +306, 313, 314, 355, 354 +307, 314, 315, 356, 355 +308, 315, 316, 357, 356 +309, 316, 317, 358, 357 +310, 317, 318, 359, 358 +311, 318, 319, 360, 359 +312, 319, 320, 361, 360 +313, 320, 321, 362, 361 +314, 321, 322, 363, 362 +315, 322, 323, 364, 363 +316, 323, 324, 365, 364 +317, 324, 325, 366, 365 +318, 325, 326, 367, 366 +319, 326, 327, 368, 367 +320, 327, 328, 369, 368 +321, 329, 330, 371, 370 +322, 330, 331, 372, 371 +323, 331, 332, 373, 372 +324, 332, 333, 374, 373 +325, 333, 334, 375, 374 +326, 334, 335, 376, 375 +327, 335, 336, 377, 376 +328, 336, 337, 378, 377 +329, 337, 338, 379, 378 +330, 338, 339, 380, 379 +331, 339, 340, 381, 380 +332, 340, 341, 382, 381 +333, 341, 342, 383, 382 +334, 342, 343, 384, 383 +335, 343, 344, 385, 384 +336, 344, 345, 386, 385 +337, 345, 346, 387, 386 +338, 346, 347, 388, 387 +339, 347, 348, 389, 388 +340, 348, 349, 390, 389 +341, 349, 350, 391, 390 +342, 350, 351, 392, 391 +343, 351, 352, 393, 392 +344, 352, 353, 394, 393 +345, 353, 354, 395, 394 +346, 354, 355, 396, 395 +347, 355, 356, 397, 396 +348, 356, 357, 398, 397 +349, 357, 358, 399, 398 +350, 358, 359, 400, 399 +351, 359, 360, 401, 400 +352, 360, 361, 402, 401 +353, 361, 362, 403, 402 +354, 362, 363, 404, 403 +355, 363, 364, 405, 404 +356, 364, 365, 406, 405 +357, 365, 366, 407, 406 +358, 366, 367, 408, 407 +359, 367, 368, 409, 408 +360, 368, 369, 410, 409 +361, 370, 371, 412, 411 +362, 371, 372, 413, 412 +363, 372, 373, 414, 413 +364, 373, 374, 415, 414 +365, 374, 375, 416, 415 +366, 375, 376, 417, 416 +367, 376, 377, 418, 417 +368, 377, 378, 419, 418 +369, 378, 379, 420, 419 +370, 379, 380, 421, 420 +371, 380, 381, 422, 421 +372, 381, 382, 423, 422 +373, 382, 383, 424, 423 +374, 383, 384, 425, 424 +375, 384, 385, 426, 425 +376, 385, 386, 427, 426 +377, 386, 387, 428, 427 +378, 387, 388, 429, 428 +379, 388, 389, 430, 429 +380, 389, 390, 431, 430 +381, 390, 391, 432, 431 +382, 391, 392, 433, 432 +383, 392, 393, 434, 433 +384, 393, 394, 435, 434 +385, 394, 395, 436, 435 +386, 395, 396, 437, 436 +387, 396, 397, 438, 437 +388, 397, 398, 439, 438 +389, 398, 399, 440, 439 +390, 399, 400, 441, 440 +391, 400, 401, 442, 441 +392, 401, 402, 443, 442 +393, 402, 403, 444, 443 +394, 403, 404, 445, 444 +395, 404, 405, 446, 445 +396, 405, 406, 447, 446 +397, 406, 407, 448, 447 +398, 407, 408, 449, 448 +399, 408, 409, 450, 449 +400, 409, 410, 451, 450 +*MATERIAL, NAME=Steel +*ELASTIC +42000.0, 0.2 +*NSET, NSET=roller_support +1 +*NSET, NSET=fixed_support +41 +*BOUNDARY +roller_support, 1 +fixed_support, 1 +fixed_support, 2 +*CLOAD +431, 2, -3 +*End Step diff --git a/test/inp_parser/parser.jl b/test/inp_parser/parser.jl index af134222..251046d2 100644 --- a/test/inp_parser/parser.jl +++ b/test/inp_parser/parser.jl @@ -1,7 +1,5 @@ using TopOpt.TopOptProblems.InputOutput.INP -using Ferrite - -using Test +using Ferrite, Test cube = INP.Parser.import_inp(joinpath(@__DIR__, "testcube.inp")) dh = cube.dh @@ -35,3 +33,28 @@ force_node = collect(keys(raw_inp.cloads))[1] for n in raw_inp.nodesets["FemConstraintDisplacement"] @test raw_inp.node_coords[n][3] == 0 end + +raw_inp = INP.Parser.extract_inp(joinpath(@__DIR__, "MBB.inp")) +# element type +@test raw_inp.celltype == "CPS4" +# node coordinates +@test raw_inp.node_coords[1] == (0.0, 0.0) +@test raw_inp.node_coords[2] == (5.0, 0.0) +@test raw_inp.node_coords[450] == (195.0, 50.0) +@test raw_inp.node_coords[451] == (200.0, 50.0) +# cell connectivity +@test raw_inp.cells[1] == (1, 2, 43, 42) +@test raw_inp.cells[2] == (2, 3, 44, 43) +@test raw_inp.cells[399] == (408, 409, 450, 449) +@test raw_inp.cells[400] == (409, 410, 451, 450) +# Dirichlet boundary conditions +@test raw_inp.nodedbcs["fixed_support"] == [(1, 0.0), (2, 0.0)] +@test raw_inp.nodedbcs["roller_support"] == [(1, 0.0)] +# concentrated load +@test raw_inp.cloads[431] == [0.0, -3.0] +# material density +@test raw_inp.density == 0 +# Young's modulus +@test raw_inp.E == 42000 +# Poisson ratio +@test raw_inp.ν == 0.2