Setup
Setup API
FerriteAssembly.DomainSpec — TypeDomainSpec(sdh::SubDofHandler, material, fe_values; set=_getcellset(sdh), colors_or_chunks=nothing, user_data=nothing)
DomainSpec(dh::DofHandler, material, fe_values; set=1:getncells(dh), colors=nothing, chunks=nothing, user_data=nothing)Create a DomainSpec that can be used to set up a domain buffer.
sdh/dh: Give theDofHandlerfor the domain in question, or aSubDofHandlerin case there are more than one inDofHandler(SeeFerrite.jl's documentation)material: Used for dispatch on the utilizedworker's function.fe_values:CellValuesorFacetValuesdepending on the type of domain.set: The items in the domain, the element type determines the type of domain- Cell domain:
Int - Facet domain:
FacetIndex
- Cell domain:
colors::Vector{Vector{I}}: used to avoid race conditions when multithreading. For cell domains,I=Int, and for facet domains,Ican be eitherInt(denoting cell numbers) orFacetIndexfor actual facets. IfI=Int, it will be converted toFacetIndexinternally. Ifcolors=nothingandchunks=nothing,Ferrite.jl's default coloring algorithm is used.chunks::Vector{Vector{Vector{I}}}. During multithreading, each task works with items in onechunk::Vector{I}at a time. Items inchunks[k][i]andchunks[k][j]should be independent (i.e. not share dofs). If given, this input takes precedence overcolors. Forchunks,Imust beIntfor cell domains andFacetIndexfor facet domains.user_data: Can be whatever the user wants to and is passed along by reference everywhere. It is accessible from theItemBuffer(e.g.CellBuffer) given to theworker's function via theget_user_datafunction. However, since it is passed by reference, modifying values during work, care must be taken to ensure thread safety. To avoid allocations, caches can be created separately withallocate_cell_cacheandallocate_facet_cache.
FerriteAssembly.setup_domainbuffer — Functionsetup_domainbuffer(domain::DomainSpec; a=nothing, threading=false, autodiffbuffer=false, num_tasks=Threads.nthreads())Setup a domain buffer for a single grid domain, domain.
a::Vector: The global degree of freedom values are used to pass the local element dof values to thecreate_cell_statefunction, making it possible to create the initial state dependent on the initial conditions for the field variables.threading: Should aThreadedDomainBufferbe created to work the grid multithreaded if supported by the usedworker?num_tasks: The number of tasks to spawn during threaded assembly. Only applicable forthreading = true.autodiffbuffer: Should a custom itembuffer be used to speed up the automatic differentiation (if supported by the itembuffer)
FerriteAssembly.setup_domainbuffers — Functionsetup_domainbuffers(domains::Dict{String,DomainSpec}, suppress_warnings = false; kwargs...)Setup multiple domain buffers, one for each DomainSpec in domains. Set suppress_warnings = true to suppress warnings checking for typical input errors when setting up multiple domains. See setup_domainbuffer for description of the keyword arguments.
AbstractDomainBuffer
The domain buffer be a DomainBuffer, ThreadedDomainBuffer, or a Dict{String} with eltype of one of the former. The following functions are defined for these buffers:
FerriteAssembly.get_material — Methodget_material(dbs::Dict{String,AbstractDomainBuffer}, domain::String)
get_material(db::AbstractDomainBuffer)
get_material(sim::Simulation)Get the material for the domain represented by db or dbs[domain].
FerriteAssembly.get_dofhandler — Methodget_dofhandler(dbs::Dict{String,AbstractDomainBuffer})
get_dofhandler(db::AbstractDomainBuffer)
get_dofhandler(sim::Simulation)Get the dofhandler stored in db. Note that this is the global dofhandler, and not the SubDofHandler that is local to a specific domain.
FerriteAssembly.get_state — Methodget_state(dbs::Dict{String,AbstractDomainBuffer}, domain::String)
get_state(db::Union{AbstractDomainBuffer,Dict{String,AbstractDomainBuffer}})
get_state(sim::Simulation[, domain::String])Get the states::Dict{Int,S}, where S type of the state for each entity in the domain, stored in the db or dbs[domain]. If no domain is given for multiple domains, a Dict{String} is returned with state variables for each domain
FerriteAssembly.get_old_state — Methodget_old_state(dbs::Dict{String,AbstractDomainBuffer}, domain::String)
get_old_state(db::Union{AbstractDomainBuffer,Dict{String,AbstractDomainBuffer}})
get_old_state(sim::Simulation[, domain::String])Get the states::Dict{Int,S}, where S type of the state for each entity in the domain, stored in the db or dbs[domain]. If no domain is given for multiple domains, a Dict{String} is returned with state variables for each domain
FerriteAssembly.getset — Functiongetset(dbs::Dict{String,AbstractDomainBuffer}, domain::String)
getset(db::AbstractDomainBuffer)
getset(sim::Simulation[, domain::String])Get the set of items stored in db or dbs[domain]
FerriteAssembly.update_states! — Methodupdate_states!(db::Dict{String,AbstractDomainBuffer}; mode::Symbol = :copy)
update_states!(db::AbstractDomainBuffer; mode::Symbol = :copy)
update_states!(sim::Simulation; mode::Symbol = :copy)Update the states such that old_states = states (the just-converged values) for the states stored in db.
mode selects how this is done:
mode = :copy(default): copies the values fromstatesintoold_states;statesitself is left untouched. This means bothold_statesandstatescorrectly hold the just-converged values directly after the call — safe to read (e.g. for postprocessing) immediately afterwards. Ifcreate_cell_statereturns a mutableAbstractArray, this reuses that array's own storage (no allocation for the array itself, though copying non-isbitselements into it may still allocate — unlessFerriteAssembly.copy_state!is overloaded for the element type, see below), and it must therefore keep the same axes between calls (ArgumentErrorotherwise). Any other non-isbitscell state must have aFerriteAssembly.copy_stateorFerriteAssembly.copy_state!method — otherwise aMethodErroris thrown. This is a breaking change from previous releases (which behaved likemode = :flip): a mutable, non-array cell state without acopy_state/copy_state!overload that used to work now throws; usemode = :flipto keep the old behavior for such states.mode = :flip: cheaply swaps the references ofold_statesandstates(no copying, no allocation, and nocopy_staterequirement — this is the behavior ofupdate_states!in releases prior to this change). After the call,states(the "new" container) holds the stale values from before this step, not the just-converged ones.Warning Under
mode = :flip,statesmust not be read again until it has been overwritten by the next call towork!— including implicitly, e.g. via a defaultQuadPointEvaluatorreadingget_state/sduring postprocessing right afterupdate_states!. Reading it earlier silently observes the previous step's data. If you need to read the just-converged state after updating (e.g. for postprocessing), use the defaultmode = :copyinstead.
FerriteAssembly.revert_states! — Methodrevert_states!(db::Dict{String,AbstractDomainBuffer})
revert_states!(db::AbstractDomainBuffer)
revert_states!(sim::Simulation)Update the states such that states = old_states for the states stored in db, i.e. the opposite direction of update_states!. This is useful when retrying a time increment after a non-converged solution, when the current (new) state is used as an initial guess (typical in staggered solution schemes). Requires FerriteAssembly.copy_state or FerriteAssembly.copy_state! for non isbits with the same requirements as stated in update_states! with mode = :copy.
FerriteAssembly.set_time_increment! — Methodset_time_increment!(db::Dict{String,AbstractDomainBuffer}, Δt)
set_time_increment!(db::AbstractDomainBuffer, Δt)
set_time_increment!(sim::Simulation, Δt)Update the time increment stored in db, which is passed on to the stored AbstractItemBuffer
Coupled simulations
The Simulation type contains an abstract domain buffer, along with (optionally) the global degree of freedom values, which are used to get the local values for each item. The main purpose is to conveniently collect these when passing into work!, especially in the case of CoupledSimulations.
The idea behind the coupled simulation setup is to give access to values from a different simulation at the item level. For example, when solving two separate problems in parallel, and using staggered iterations. See the Phase-field fracture tutorial for an example.
FerriteAssembly.Simulation — TypeSimulation(db, a = nothing, aold = nothing)A Simulation is a collection of the simulation domain(s) db, and the global degree of freedom vectors, a and aold.
Note: If a or aold are not provided, the local vectors will have NaN values.
FerriteAssembly.couple_buffers — Functioncouple_buffers(dbs::Dict{String, <:AbstractDomainBuffer}; kwargs::Dict{String, <:AbstractDomainBuffer}...)
couple_buffers(db::AbstractDomainBuffer; kwargs::AbstractDomainBuffer...)Return new buffer(s) that are coupled with the buffers provided as keyword arguments. The key is used in get_coupled_buffer to get the coupled itembuffer, such that its values may be queried.
FerriteAssembly.CoupledSimulations — TypeCoupledSimulations(; key1 = sim1::Simulation, key2 = sim2::Simulation, ...)Setup the collection of coupled simulations to allow values (such as state variables and local dof-values from these simulations to be available when work!ing another simulation, if the buffers have been coupled with couple_buffers. The coupled itembuffer on the local level is accessed with get_coupled_buffer.