Skip to content

Commit 2e94c43

Browse files
committed
WIP
1 parent 4bf827a commit 2e94c43

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

src/Basis/Constructors.jl

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,100 @@ function TensorH1UniformBasis(
519519
)
520520
end
521521

522+
"""
523+
```julia
524+
H1MPMBasis(numbernodes1d, numbermaterialpoints, numbercomponents, dimension)
525+
```
526+
527+
Tensor product basis on Gauss-Legendre-Lobatto points with randomly placed material (quadrature) points
528+
529+
# Arguments:
530+
531+
- `numbernodes1d::Int`: number of Gauss-Legendre-Lobatto nodes in 1 dimension
532+
- `numbermaterialpoints::Int`: number of material (quadrature) points in cell
533+
- `numbercomponents::Int`: number of components
534+
- `dimension::Int`: dimension of basis
535+
536+
# Returns:
537+
538+
- H1 basis on Gauss-Legendre-Lobatto nodes with randomly spaced material (quadrature) points
539+
540+
# Example:
541+
542+
```jldoctest
543+
# generate H1 Lagrange tensor product basis on uniformly spaced nodes
544+
basis = H1MPMBasis(4, 3, 2, 1);
545+
546+
# verify
547+
println(basis)
548+
549+
# output
550+
551+
tensor product basis:
552+
numbernodes: 4
553+
numberquadraturepoints: 3
554+
numbercomponents: 2
555+
dimension: 1
556+
```
557+
"""
558+
function H1MPMBasis(
559+
numbernodes1d::Int,
560+
numbermaterialpoints::Int,
561+
numbercomponents::Int,
562+
dimension::Int,
563+
)
564+
# check inputs
565+
if numbernodes1d < 2
566+
# COV_EXCL_START
567+
throw(
568+
DomainError(numbernodes1d, "numbernodes1d must be greater than or equal to 2"),
569+
)
570+
# COV_EXCL_STOP
571+
end
572+
if numbermaterialpoints < 1
573+
# COV_EXCL_START
574+
throw(
575+
DomainError(
576+
numberquadraturepoints1d,
577+
"numbermaterialpoints must be greater than or equal to 1",
578+
),
579+
)
580+
# COV_EXCL_STOP
581+
end
582+
if dimension < 1 || dimension > 3
583+
throw(DomainError(dimension, "only 1D, 2D, or 3D bases are supported")) # COV_EXCL_LINE
584+
end
585+
586+
# get nodes and H1 Lagrange quadrature points
587+
nodes1d, = gausslobatto(numbernodes1d)
588+
quadraturepoints1d, _ = gausslegendre(numbernodes1d)
589+
590+
# build 1D interpolation matrix
591+
interpolation1d, _ = buildinterpolationandgradient(nodes1d, quadraturepoints1d)
592+
593+
# build random material points, dummy quadrature weights
594+
numbernodes = numbernodes1d^dimension
595+
materialpoints = rand!(fill(0.0, (dimension * numbermaterialpoints))) * 2.0 .- 1.0
596+
quadratureweights = fill(1.0, (numbermaterialpoints))
597+
598+
# build nD interpolation, gradient matrices
599+
interpolation = []
600+
gradient = []
601+
602+
# use basic constructor
603+
return NonTensorBasis(
604+
numbernodes,
605+
numbermaterialpoints,
606+
numbercomponents,
607+
dimension,
608+
nodes,
609+
materialpoints,
610+
quadratureweights,
611+
interpolation,
612+
gradient,
613+
)
614+
end
615+
522616
# ------------------------------------------------------------------------------
523617
# -- marco element bases
524618
# ------------------------------------------------------------------------------

src/LFAToolkit.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ using FastGaussQuadrature: gausslegendre, gausslobatto
1212
using LinearAlgebra: Diagonal, eigen, eigvals, I, kron
1313
using Polynomials: Polynomial, derivative
1414
using Printf: @printf
15+
using Random: rand
1516
using SparseArrays: dropzeros!, spzeros
1617

1718
# ------------------------------------------------------------------------------

0 commit comments

Comments
 (0)