Variables
HyperShape.Variables — Module
HyperShape.VariablesDesign variables at three linked levels:
| Level | Object | What it is |
|---|---|---|
| z | OptVariables | what the optimiser sees: one vector made of blocks, with bounds |
| x | DesignFields | design fields on the design mesh (cell-wise P0 or nodal P1) |
| θ | PhysicalFields | physical fields read by the weak forms at the quadrature points |
Each level is built from the previous one, and only HyperShape writes them (in place). The maps x → θ (HelmholtzFilter, TanhProjection, Identity) are composed with ∘ in the mathematical order: TanhProjection(β = 1.0, η = 0.5) ∘ HelmholtzFilter(dΩ; rmin, ls) filters first and projects after.
Sensitivities travel backwards with design_gradient!: a linear form in δθ for each physical field gives the derivative with respect to z.
The vectors HyperShape assembles (load vector of a filter, sensitivities) use backend = :compiled by default (HyperFEMKernels: forms compiled once into threaded kernels) or backend = :lazy (Gridap's assembler); see HelmholtzFilter and PhysicalFields. Both give the same vectors up to rounding. The compiled backend is faster from tens of thousands of cells on, already with one thread, and scales with the threads (julia -t N); on meshes of about a thousand cells both take well under a millisecond per vector.
HyperShape.Variables.CellMean — Type
CellMean(dΩ; backend = :compiled)Mean of the input field over each cell of the triangulation of dΩ: a P0 field, x̄_K = ∫_K x dΩ / |K| (with the quadrature of dΩ). On a measure over part of the domain the field is the mean on those cells and its integrals over the whole domain only see that part (Gridap's rule for fields on a sub-triangulation). After a filter it gives the density of codes such as top88 (xPhys = TF'·K⁻¹·TF·x): one value per element instead of the filtered field at the quadrature points. Linear in its input (a volume after it stays a linear constraint); no solve. backend assembles its vectors (:compiled, HyperFEMKernels, or :lazy, Gridap).
θ = PhysicalFields(x; ρ = CellMean(dΩ) ∘ HelmholtzFilter(dΩ; rmin, ls = LUSolver()))HyperShape.Variables.DesignFields — Type
DesignFields(z::OptVariables)
DesignFields(z::OptVariables; name = Identity(), ...)Design fields x built from the blocks of z, one per block and with the same name. The map z → x of each block is Identity, the only one available for now: DesignFields(z) takes it for every block, and writing name = Identity() for each block is the same. Read a field as x.ρ (a Gridap FEFunction, updated in place).
HyperShape.Variables.DesignMeasures — Type
DesignMeasuresWhat design_measures returns: domain (a Measure); solid, void and interface are reserved for cut cells.
HyperShape.Variables.Ersatz — Type
Ersatz(; backend = :compiled)Interface map of the classical ersatz material (Allaire, Jouve and Toader, 2004): the material of each cell is the fraction of the cell where the input φ is ≥ 0, χ_K = |{φ_h ≥ 0} ∩ K| / |K|, a cell-wise (P0) field. Exact for the linear interpolant of φ on simplices; quadrilaterals and hexahedra are split into 4 triangles and 24 tetrahedra around their centre (whose value is the mean of the nodes), so the fraction is exact for that subdivision (not for the bilinear interpolant: up to about 0.08 on a cell with values in a saddle) and O(h²) with respect to a smooth interface. Continuous in φ, with its exact derivative (closed forms, no cancellation). The input must be a nodal P1 scalar field: the design field or the output of a filter (Ersatz() ∘ HelmholtzFilter(…)); triangles, quadrilaterals, tetrahedra and hexahedra. A volume of the material is exact with any quadrature.
The derivative is nonzero only on the cells cut by the interface: a design without interface (uniform φ, or φ at a bound everywhere) does not move, and holes are not nucleated by this derivative. Interface maps are for interface methods (reaction–diffusion): DensityMethod refuses them when the run starts. A cell with φ ≡ 0 counts as material (derivative zero). With a frozen zone φ = 1 the cells next to it are partly material too (its nodes on their boundary have φ = 1). Cost (one thread, Mac M5 Max): about 12 ns per quadrilateral and 7 ns per tetrahedron to update or pull back; a hexahedron cut by the interface about 350 ns (24 tetrahedra), one without interface a few ns. backend assembles the forms on the cell-wise basis (:compiled, HyperFEMKernels, or :lazy, Gridap). Not lazy: the fractions are computed when the design changes (a loop over the cells, no solve).
θ = PhysicalFields(x; ρ = :φ => Ersatz() ∘ HelmholtzFilter(dΩ; rmin, ls = LUSolver()))
dΩ = design_measures(θ; degree = 2)HyperShape.Variables.FieldMap — Type
FieldMapSupertype of the maps x → θ. Compose them with ∘ in the mathematical order: (g ∘ f)(x) = g(f(x)).
HyperShape.Variables.FieldVariable — Type
FieldVariable(V; bounds, init, frozen = nothing)Block of OptVariables holding the free values of a scalar design field in the space V (cell-wise P0 or nodal P1 Lagrangian; the bounds act on the free values, which bound the field only for these two spaces). bounds = (lb, ub) with lb < ub; init is a number, a vector of the length of the free values or a function of the coordinates (interpolated on V), inside the bounds. Both are mandatory.
Frozen zones (solid or void that the optimisation cannot change, such as the material under a load or at a support): build V with dirichlet_tags on the zones and give their values in frozen (a number, one number per tag in the order of dirichlet_tags, or a function of the coordinates), inside the bounds:
add_tag_from_vertex_filter!(labels, "solid", model, x -> x[2] ≥ ny - 2 && x[1] ≤ 2)
Vρ = TestFESpace(model, ReferenceFE(lagrangian, Float64, 0); conformity = :L2, dirichlet_tags = "solid")
z, x, θ = single_field_design(:ρ, Vρ; bounds = (0.0, 1.0), init = 0.5, frozen = 1.0, map = …)The values of the zones are not variables (z holds the free ones only), the design field x has the frozen values there, and every physical field built from it takes, on the cells of the zones, the image of the frozen value by the pointwise maps of its chain (projection and pointwise maps; filters and cell means leave it as it is): the zone is real material whatever the filter (see PhysicalFields). A zone is made of whole cells: every Dirichlet value must belong to a cell all of whose values are frozen (a tag of vertices made with add_tag_from_vertex_filter! gives that for P0 and P1; a line of nodes on a boundary does not, and is an error: turn a boundary tag into the cells next to it with tag_adjacent_cells!; in P1 a cell outside the tags whose nodes are all frozen, such as a hole of one cell inside a zone, belongs to the zone too), and its value is one number per cell (zones with different values must not touch; a function of the coordinates must be constant on each frozen cell). Spaces with periodic conditions are fine; spaces with other linear constraints (symmetries) are not supported yet. With a frozen zone the space of the block is the TrialFESpace with the frozen values (what metric_weights of a metric of the user receives).
HyperShape.Variables.HelmholtzFilter — Type
HelmholtzFilter(dΩ; rmin, order = 1, backend = :compiled, model_backend = <default>, solve = <default>, kwargs...)
HelmholtzFilter(op::LinearOperator, dΩ; backend = :compiled)PDE filter (Lazarov and Sigmund, 2011): the filtered field ρ̃ solves a(ρ̃, v) = ∫(x v) dΩ for all v.
- Short form (the usual filter):
a(ρ̃, v) = ∫(r² ∇ρ̃⋅∇v + ρ̃ v)dΩwithr = rmin / (2√3), homogeneous Neumann conditions, on a Lagrangian space of degreeorder(continuous) over the triangulation ofdΩ.kwargsgo to HyperFEM'sStaticLinearModel(for examplels = LUSolver(),ls = CGSolver(…)or a PETSc solver; withoutls,LUSolver()),model_backendis passed to it as itsbackend(who assembles the matrix; HyperFEM's default if omitted) andsolvegoes to theLinearOperator(default: assemble when the matrix changes). - General form:
opis aLinearOperatorwhose model carries the bilinear form and the solver written by the user (Robin terms, Dirichlet conditions, anisotropy…). The bilinear form must be symmetric (the same solve gives the transpose for the sensitivities; checked bycheck_consistency) and the trial space may only have homogeneous Dirichlet values (checked).
The output is a field of the trial space of the filter (usually P1), also for a P0 design field. backend selects who assembles the load vectors of the filter: :compiled (default, HyperFEMKernels) or :lazy (Gridap); it is independent of the backend of the filter model, which assembles the matrix.
Cost: one assembly of a load vector and one solve each time the design changes, and the same for each sensitivity pulled back.
HyperShape.Variables.Identity — Type
Identity()Identity map (z → x or x → θ).
HyperShape.Variables.OptVariables — Type
OptVariables(; name = FieldVariable(...), ...)What the optimiser sees: one vector z made of named blocks, with bounds. Read it with get_values(z) and get_bounds(z). After writing into get_values(z) in place, call changed!(z) so that the design and physical fields are updated; set_values!(z, v) does both.
HyperShape.Variables.PhysicalFields — Type
PhysicalFields(x::DesignFields; name = map, other = :source => map, ..., backend = :compiled)
PhysicalFields(x::DesignFields; other = :source, ...)
PhysicalFields(x::DesignFields)Physical fields θ, the ones the weak forms read. Each one comes from one design field through a map (a FieldMap, possibly composed with ∘): ρ = map uses the design field ρ; E = :ρ => map uses the design field ρ under another name, so several physical fields can come from the same design field (their sensitivities are added). Without a map the field is the design field itself (Identity): E = :ρ is E = :ρ => Identity(), and PhysicalFields(x) (no fields) is ρ = Identity() for every design field, with its name. Every design field must be used. The constructor brings the fields up to date once, calling the solve functions of the operators with ctx = OptContext(:setup). Read a field as θ.ρ: a fixed object (an FEFunction or a CellField) updated in place, so the weak forms can capture it.
A frozen zone of the design field (see FieldVariable) is imposed at the end of every chain: on its cells θ is the image of the frozen value by the pointwise maps of the chain (ρ = 1 gives θ = 1 through a projection; through Ersatz(), the step of the value), whatever the filters, and its derivative vanishes there. It costs no solve and keeps a linear chain linear. With a frozen zone, θ.ρ is an operation on fields (not the FEFunction of the last map), so read it as a CellField.
backend (a reserved name: no physical field can be called backend) selects who assembles the sensitivities on the design spaces: :compiled (default, HyperFEMKernels) or :lazy (Gridap).
HyperShape.Variables.PointwiseMap — Type
PointwiseMap(f, df; parameters = ())Map applied point by point at the quadrature points, θ = f(input), with its derivative df written by the user (no automatic differentiation; check it with check_consistency): for example a projection or a threshold of the user's own. f and df are functions of one number. If they read Parameters (or other objects with a state_version), list them in parameters, so the physical fields count as changed when they change (continuation). The value of a frozen zone through the map is also recomputed only then. Lazy, like TanhProjection: nothing is recomputed, the forms evaluate f and df when they are assembled.
const p = Parameter(8.0) # const: closures that read it do not allocate
smooth_step = PointwiseMap(ρ -> 1 / (1 + exp(-p[] * (ρ - 0.5))),
ρ -> (s = 1 / (1 + exp(-p[] * (ρ - 0.5))); p[] * s * (1 - s)); parameters = (p,))
θ = PhysicalFields(x; ρ = smooth_step ∘ HelmholtzFilter(dΩ; rmin, ls))HyperShape.Variables.Step — Type
Step()Interface map: the material is the Heaviside step of the input at each quadrature point, χ = 1 where φ ≥ 0 and 0 elsewhere (the abrupt step of the ersatz material of Li et al. 2023). The material of a cell cut by the interface depends on which quadrature points fall on each side: integrate with a higher degree to smooth the jumps (see design_measures). It has no derivative with respect to φ: a method that differentiates through the maps (DensityMethod) refuses it when the run starts, and check_consistency reports the derivative checks as not applicable; use Ersatz() to check the derivatives of the forms (they are the same). Lazy, point by point (a frozen zone φ = 1 gives χ = 1). The refusal looks at the whole PhysicalFields: a field through Step() next to differentiable ones goes in a PhysicalFields of its own.
HyperShape.Variables.TanhProjection — Type
TanhProjection(; β, η)Smooth approximation of the Heaviside step (Wang, Lazarov and Sigmund, 2011), applied point by point at the quadrature points:
H(ρ) = (tanh(βη) + tanh(β(ρ - η))) / (tanh(βη) + tanh(β(1 - η)))β > 0 (sharpness) and 0 < η < 1 (threshold) are mandatory. β can be changed during the optimisation with set_beta! (continuation); every field and form built from this object sees the new value, and the physical fields that use it count as changed.
HyperShape.Operators.state_version — Method
state_version(θ::PhysicalFields)Counter of changes of the physical fields. It grows in update_fields! when z or a parameter of a map changed (set_beta!, a Parameter of a PointwiseMap or of a filter's operator). Note that the fields themselves read β lazily (except a frozen zone, whose value is refreshed by update_fields!): forms assembled after set_beta! already see the new value, but operators that depend on θ only notice the change after update_fields!. Two PhysicalFields built on the same DesignFields are independent: each one is brought up to date by its own update_fields!.
HyperShape.Variables.add_forms! — Method
add_forms!(θ::PhysicalFields, forms::NamedTuple, w, ctx; key = 0) -> θAdds w times the derivative given by forms ((ρ = δ -> ∫(… * δ)dΩ, …), one entry per physical field; missing fields contribute nothing) to the reverse sweep started by reset_sink!. Projections and pointwise maps act inside the integrals now; filters only accumulate, and are solved once by finish_sink!. key identifies the forms for the compiled backend (see design_gradient!).
HyperShape.Variables.cell_fraction — Method
cell_fraction(φ::NTuple{3,Float64}) -> (f, ∂f/∂φ)
cell_fraction(φ::NTuple{4,Float64}) -> (f, ∂f/∂φ)Fraction of a triangle (3 values) or a tetrahedron (4 values) where the linear interpolant of the vertex values φ is ≥ 0, and its derivative with respect to them. A cell without interface has derivative zero; φ ≡ 0 gives 1.
HyperShape.Variables.changed! — Method
changed!(z::OptVariables)Marks the values of z as changed (after writing into get_values(z) in place). Throws if a value is outside the bounds or not finite.
HyperShape.Variables.design_gradient! — Method
design_gradient!(gz, θ::PhysicalFields, forms::NamedTuple, ctx; key = 0) -> gzDerivative with respect to z of a quantity whose derivative with respect to the physical fields is given as linear forms: forms = (ρ = δ -> ∫(… * δ)dΩ, …), one entry per physical field it depends on (missing fields contribute nothing). The forms are pulled back through the maps x → θ (transposed filters, derivatives of the projections), assembled on the design spaces, added over the physical fields that share a design field, and mapped to z. Writes gz (a vector of the length of z). It is reset_sink!, add_forms! with weight one and finish_sink!.
key identifies the quantity for the compiled backend, which keeps the compiled forms of the last keys used: with a different key for each quantity (objective, each constraint) the forms are only rebound at every call; forms of different structure under one key are correct too, their kernels are compiled again at each call (a few milliseconds). Avoid creating the Measure inside a form or capturing a new FEFunction at every call: both change the structure of the form.
HyperShape.Variables.design_measures — Method
design_measures(θ::PhysicalFields; degree, field = nothing) -> DesignMeasuresThe measures on which the weak forms integrate over the design region, given by HyperShape so that a later treatment of the interface by cut cells changes the quadrature without changing the forms. dΩ.domain is the Measure of degree degree (mandatory) on the triangulation of the design field of the physical field field (needed when θ has several fields); with Step() a higher degree smooths the jumps of the material of the cut cells. dΩ.solid, dΩ.void and dΩ.interface are reserved for cut cells (later).
dΩ = design_measures(θ; degree = 2)
a(u, v) = ∫(… θ.ρ …)dΩ.domain
Vol = Volume(θ, dΩ; max_fraction = 0.4)HyperShape.Variables.filter_operators — Method
filter_operators(θ::PhysicalFields) -> VectorThe LinearOperators of the filters in the maps of the physical fields, each one once.
HyperShape.Variables.finish_sink! — Method
finish_sink!(gz, θ::PhysicalFields, ctx) -> gzEnds a reverse sweep: pulls the accumulated sensitivities back through the filters (one transposed solve per filter with something accumulated), adds them over the physical fields that share a design field, maps them to z and writes gz (a vector of the length of z).
HyperShape.Variables.frozen_indicator — Method
frozen_indicator(x::DesignFields, name) -> CellFieldIndicator of the cells of the frozen zones of the design field name (1 on them, 0 elsewhere; a P0 field), for example to write them with the results. Throws if the field has no frozen zone (see FieldVariable).
HyperShape.Variables.get_bounds — Method
get_bounds(z::OptVariables) -> (lb, ub)Lower and upper bounds of every entry of the design vector.
HyperShape.Variables.get_values — Method
get_values(z::OptVariables) -> Vector{Float64}The design vector, all blocks in order (the same object, not a copy). After writing into it in place call changed!(z); or use set_values!.
HyperShape.Variables.hole_centers — Method
hole_centers(V; radius, spacing = 4radius, pattern = :hex, margin = radius, exclude = (), rng = nothing,
origin = nothing, jitter = 0.0, symmetry = nothing, nholes = nothing,
min_distance = nothing) -> Vector{NTuple{D,Float64}}The centres of the holes that hole_seed places with the same arguments (not exported; for tests and plots). pattern = :poisson (internal) gives the random points at least spacing apart that start :cvt with rng.
HyperShape.Variables.hole_seed — Method
hole_seed(V; radius, spacing = 4radius, pattern = :hex, margin = radius, exclude = (), connect = exclude,
base = nothing, bounds = (-1.0, 1.0), width = radius, frozen = nothing, rng = nothing, origin = nothing,
jitter = 0.0, symmetry = nothing, nholes = nothing, min_distance = nothing,
verbose = false) -> Vector{Float64}The free values of a design field with holes: the init of FieldVariable (same space V, same bounds, same frozen):
φ0 = hole_seed(Vφ; radius = 0.05, spacing = 0.2, exclude = "clamp", connect = ("clamp", "load"))
z = OptVariables(φ = FieldVariable(Vφ; bounds = (-1.0, 1.0), init = φ0, frozen = 1.0))Two uses:
- A starting design for a method that nucleates holes, such as
ReactionDiffusionwith an interface map (Ersatz(),Step()) (optional; Yamada et al. 2010 start from perforated designs too): studies of the dependence of the design on the start. A solid start is still the default of the examples. - The start of a method that only moves the boundary and cannot create holes (the double-well reaction–diffusion
ReactionDiffusion(…; reaction = DoubleWell())withbounds = (0.0, 1.0); Takezawa et al. 2010): there the holes of the seed are all the holes the design can have, and the seed is mandatory.
Holes of radius radius (a length, in the units of the mesh) about spacing apart:
pattern = :hex(default): the close-packed lattice with nearest neighboursspacingapart, a hole at the centre of the bounding box of the mesh: staggered rows√3/2 spacingapart in 2D (the seeds of Takezawa et al.), face-centred cubic in 3D.jitter ∈ [0, 1)moves each centre at random (rng, seed 1 if not given) inside a ball of radiusjitter (spacing − 2radius)/2, so that two holes never touch (the solid between them is at least(1 − jitter)(spacing − 2radius)); the sequence of Julia's generators may change between versions of Julia, so a reference saved withjittermay change too.pattern = :lattice: square (cubic) lattice of stepspacing, symmetric in the bounding box (withjittertoo).pattern = :cvt: a centroidal Voronoi tessellation of the cells where a hole may go (Lloyd's relaxation): the centres spread evenly over any geometry, away from the excluded zones.spacingis the mean distance from a centre to its nearest neighbour: the number of holes starts as that of:hexwith the samespacingover that region (its measure over√3/2 spacing²in 2D,spacing³/√2in 3D), the mean distance is measured after the relaxation and the number corrected from the holes obtained, at most twice (up to three relaxations; the closest run is kept; one hole is not corrected). Measured: 0.96–1.03spacingon a 2 × 1 plate, in a cube and in a torus whose tube is 1.5spacingthick, 0.93 on a strip 1.5spacingwide. So:cvtgives fewer holes than:hexwith the samespacing(plate 2 × 1: 46 against 73; cube: 58 against 159, which counts the holes cut by the boundary), and slender parts fewer than their measure suggests (the torus: 12 against 24); the void fractions of the two seeds differ.nholesfixes the number of holes instead (one relaxation): an error when they cannot fitmin_distanceapart in the region, a warning when fewer are placed; with a symmetry the holes come in whole orbits, so the number is rounded to them (the warning gives the number placed). Neighbours are at leastmin_distanceapart (default2radius + (spacing − 2radius)/2, half the solid of:hexbetween two holes; above2radius, and at mostspacingunlessnholesis given): after each Lloyd step the centres closer than that are pushed apart, and an orbit is dropped only where the minimum cannot be met. It starts from the centres of:hex(deterministic) or, withrng(an integer seed or anAbstractRNG), from random points at leastspacingapart, thinned or completed by farthest points; at most 60 Lloyd steps per relaxation, until no centre moves more than 5 % of the mean cell size. Its centres are inside the region (near a centroid of a cell where a hole may go), not cut by the boundary as those of:hexmay be. The sequence of Julia's generators may change between versions of Julia: give references withoutrng.nholesandmin_distanceare options of:cvtonly.
origin (:hex, :lattice, and the start of :cvt) is a point of the lattice. A hole is kept when the centroid of some cell is inside it (meshes that do not fill their bounding box), and holes cut by the boundary are kept (a periodic pattern); to keep them inside, exclude the boundary tag. The holes keep radius + margin from the vertices of the frozen zones of V (cells whose values are all Dirichlet values: read from V, nothing to give) and of the tags in exclude (loads, supports), so that the solid is at least margin thick there. The distance is measured to the vertices of those cells and tags: between two vertices h apart the distance to the entity can be up to R − √(R² − h²/4) shorter (R = radius + margin; 3 % of R with h = R/2), which matters only on coarse meshes.
symmetry: one symmetry or a tuple of them, each a named tuple: (point = p, normal = n) a reflection in the plane (line in 2D) through p normal to n; (point = p, order = n) a rotation of order n about p in 2D and (point = p, axis = a, order = n) about the axis through p along a in 3D. The seed is built in a fundamental region of the group they generate and replicated: the centres are exactly symmetric, a centre closer to a plane (or an axis) than the distance between holes goes onto it, and every replica keeps the distance between holes and the margins (an orbit that does not is dropped whole). The geometry, the frozen zones and the excluded tags must be symmetric too: a warning says so when the mesh (to the largest cell size) or the keep-out points are not. With :hex and :lattice the symmetry should also map the lattice onto itself (the planes of the default lattices through the centre of the box, rotations of order 2 about it, and of order 4 for :lattice; origin moves the lattice): if it does not, the replicas meet along seams where orbits are dropped and gaps are left, and a warning says how many; :cvt has no such seams.
hole_seed(Vφ; radius = 0.05, spacing = 0.2, symmetry = (point = (1.0, 0.5), normal = (0.0, 1.0))) # y = 0.5
hole_seed(Vt; radius = 0.1, pattern = :cvt, symmetry = (point = (0, 0, 0), axis = (0, 0, 1), order = 4))The value at a point at distance d from the nearest centre goes from lb at d = radius − width to the interface level (lb + ub)/2 at d = radius and ub at d = radius + width (linear in d, clamped: a clipped distance for a level set in (-1, 1), a density in (0, 1) with 0.5 on the edge of the holes), and is then the minimum with base (default ub; a number, a vector of free values or a function of the coordinates).
Checks: an ArgumentError when no hole fits, no value of the field falls inside a hole or every value is inside a hole (whatever base does); warnings when more than half of the values are inside the holes, when some holes contain no value of the field (the mesh does not resolve them: refine or enlarge them), when the solid between two holes is thinner than two cells, and when the solid (the cells whose mean value is at least the level, the frozen cells with the values frozen, by default ub) does not join the tags of connect (by default exclude; nothing skips the check) through faces. verbose = true prints the number of holes and the fraction of values in them.
Void fraction of a periodic pattern with spacing = 4radius: :hex 23 % in 2D and 9 % in 3D, :lattice 20 % and 7 %; in 2D the best designs measured came from about four rows of holes across the smaller side of the domain (spacing ≈ L_min/4). A pattern of cosines (Oka, Misawa, Yamada) is one line of the user, init = x -> clamp(-cos(2π x[1]/s) * cos(2π x[2]/s) + c, -1, 1), without the margins.
P0 and P1 Lagrangian spaces (and other scalar Lagrangian spaces: the values sit at the nodes), any mesh in 2D and 3D. With periodic conditions the pattern is not periodic: the distance between holes is not kept across the periodic sides. The cells of the model outside the triangulation of V (a design space on part of the model) count as solid in the check of connect. The cost is linear in the cells and the values (a few microseconds per value; :cvt that times its Lloyd steps, up to three relaxations). Sequential (not for distributed spaces yet).
HyperShape.Variables.is_differentiable_field — Method
is_differentiable_field(θ::PhysicalFields, name) -> BoolWhether the physical field name has a derivative with respect to its design field (false through Step()).
HyperShape.Variables.is_linear_field — Method
is_linear_field(θ::PhysicalFields, name) -> BoolWhether the physical field name depends linearly on its design field: every map of its chain is linear (Identity, HelmholtzFilter, CellMean); a TanhProjection or a PointwiseMap is not.
HyperShape.Variables.reset_sink! — Method
reset_sink!(θ::PhysicalFields) -> θStarts a reverse sweep: the design sensitivities and the accumulators of the filters are set to zero.
HyperShape.Variables.set_beta! — Method
set_beta!(h::TanhProjection, β)Changes the sharpness of the projection.
HyperShape.Variables.set_values! — Method
set_values!(z::OptVariables, v)Copies v into z and marks it as changed (values must be inside the bounds).
HyperShape.Variables.single_field_design — Method
single_field_design(name, V; bounds, init, map, frozen = nothing, backend = :compiled) -> (z, x, θ)Shortcut for one design field and its physical fields with the same name:
z, x, θ = single_field_design(:ρ, Vρ; bounds = (0.0, 1.0), init = 0.5,
map = TanhProjection(β = 1.0, η = 0.5) ∘ HelmholtzFilter(dΩ; rmin, ls))is OptVariables(ρ = FieldVariable(Vρ; bounds, init, frozen)), DesignFields(z; ρ = Identity()) and PhysicalFields(x; ρ = map, backend): map is the chain from the design field to the physical one.
HyperShape.Variables.tag_adjacent_cells! — Method
tag_adjacent_cells!(labels, newtag, model, tag; layers = 1) -> labelsAdds to labels the tag newtag (arguments in the order of add_tag_from_vertex_filter!): the cells of model that contain an entity of tag (a surface, an edge or a vertex: the faces where a load or a support acts; if tag has cells, those cells), and layers − 1 more layers of cells around them (cells that share a vertex with the previous layer), with all their faces, edges and vertices. It turns a boundary tag into a frozen zone of whole cells (see FieldVariable), for P0 and P1 design spaces and any mesh:
tag_adjacent_cells!(labels, "load_zone", model, "load") # the layer of cells under the load
Vρ = TestFESpace(model, ReferenceFE(lagrangian, Float64, 1); conformity = :H1, dirichlet_tags = "load_zone")HyperShape.Variables.update_fields! — Method
update_fields!(x::DesignFields, ctx)Brings the design fields up to date with their OptVariables; does nothing if z has not changed.
HyperShape.Variables.update_fields! — Method
update_fields!(θ::PhysicalFields, ctx)Brings the design and physical fields up to date with the OptVariables and with the parameters of the maps (filters solved again, version increased); does nothing if nothing changed. ctx is passed to the solve functions of the operators.