@@ -100,7 +100,7 @@ type Problem{P<:AbstractProblem}
100100 dimension :: Int # degrees of freedom per node
101101 parent_field_name :: AbstractString # (optional) name of the parent field e.g. "displacement"
102102 elements :: Vector{Element}
103- dofmap :: Dict{Element, Vector{Int64}} # connects the element local dofs to the global dofs
103+ dofmap :: AbstractDOFMap # connects the element local dofs to the global dofs
104104 assembly :: Assembly
105105 fields :: Dict{String, AbstractField}
106106 postprocess_fields :: Vector{String}
@@ -125,7 +125,13 @@ prob1 = Problem(Elasticity, "this is my problem", 3)
125125
126126"""
127127function Problem {P<:FieldProblem} (:: Type{P} , name:: AbstractString , dimension:: Int64 )
128- return Problem {P} (name, dimension, " none" , [], Dict (), Assembly (), Dict (), Vector (), P ())
128+ dofmap = DOFMap ()
129+ assembly = Assembly ()
130+ local_dof_indices = Dict (Symbol (" u$i " ) => i for i= 1 : dimension)
131+ set_local_dof_indices! (dofmap, local_dof_indices)
132+ problem = Problem {P} (name, dimension, " none" , [], dofmap, assembly,
133+ Dict (), Vector (), P ())
134+ return problem
129135end
130136
131137"""
@@ -139,14 +145,20 @@ julia> bc1 = Problem(Dirichlet, "support", 3, "displacement")
139145solver.
140146"""
141147function Problem {P<:BoundaryProblem} (:: Type{P} , name, dimension, parent_field_name)
142- return Problem {P} (name, dimension, parent_field_name, [], Dict (), Assembly (), Dict (), Vector (), P ())
148+ dofmap = DOFMap ()
149+ assembly = Assembly ()
150+ local_dof_indices = Dict (Symbol (" u$i " ) => i for i= 1 : dimension)
151+ set_local_dof_indices! (dofmap, local_dof_indices)
152+ problem = Problem {P} (name, dimension, parent_field_name, [], dofmap,
153+ assembly, Dict (), Vector (), P ())
154+ return problem
143155end
144156
145157function get_formulation_type (:: Problem )
146158 return :incremental
147159end
148160
149- """
161+ """
150162 get_unknown_field_dimension(problem)
151163
152164Return the dimension of the unknown field of this problem.
@@ -419,35 +431,47 @@ function push!(problem::Problem, elements_::Vector...)
419431end
420432
421433"""
422- set_gdofs!(problem, element)
434+ get_dof_names(problem, element)
435+
436+ Return an iterable containing the abbreviations of dof names for this element
437+ and problem. This could be e.g. `(:u1, :u2, :T)` for two-dimensional problem
438+ having two displacement dofs and temperature dof.
423439
424- Set element global degrees of freedom.
440+ Each new Problem should define this function. If now defined, assumption is that
441+ dofs for problem are (:u1, :u2, ..., :uN) where N is the unknown field dimension.
425442"""
426- function set_gdofs! (problem, element, dofs)
427- problem. dofmap[element] = dofs
443+ function get_dof_names (problem:: Problem{P} , :: Element ) where {P}
444+ dim = get_unknown_field_dimension (problem)
445+ dof_names = (Symbol (" u$i " ) for i= 1 : dim)
446+ warn (" Define function FEMBase.get_dof_names(::Problem{$P }, ::Element)." )
447+ warn (" Assuming that dofs for problem $P are $(collect (dof_names)) ." )
448+ code = quote
449+ function FEMBase. get_dof_names (:: Problem{$P} , :: Element )
450+ return $ dof_names
451+ end
452+ end
453+ eval (code)
454+ return dof_names
455+ end
456+
457+ """
458+ get_dofmap(problem)
459+
460+ Return `DOFMap` for problem.
461+ """
462+ function get_dofmap (problem)
463+ return problem. dofmap
428464end
429465
430466"""
431467 get_gdofs(problem, element)
432468
433469Return the global degrees of freedom for element.
434470
435- First make lookup from problem dofmap. If not defined there, make implicit
436- assumption that dofs follow formula `gdofs = [dim*(nid-1)+j for j=1:dim]`,
437- where `nid` is node id and `dim` is the dimension of problem. This formula
438- arranges dofs so that first comes all dofs of node 1, then node 2 and so on:
439- (u11, u12, u13, u21, u22, u23, ..., un1, un2, un3) for 3 dofs/node setting.
440471"""
441- function get_gdofs (problem:: Problem , element:: Element )
442- if haskey (problem. dofmap, element)
443- return problem. dofmap[element]
444- end
445- conn = get_connectivity (element)
446- if length (conn) == 0
447- error (" element connectivity not defined, cannot determine global " ,
448- " degrees of freedom for element #: $(element. id) " )
449- end
450- dim = get_unknown_field_dimension (problem)
451- gdofs = [dim* (i- 1 )+ j for i in conn for j= 1 : dim]
452- return gdofs
472+ function get_gdofs (problem:: Problem{P} , element:: Element ) where {P}
473+ nodes = get_connectivity (element)
474+ dof_names = get_dof_names (problem, element)
475+ dofmap = get_dofmap (problem)
476+ return get_gdofs (dofmap, nodes, dof_names)
453477end
0 commit comments