OpenCMISS-Iron Internal API Documentation
solver_mapping_routines.f90
Go to the documentation of this file.
1 
43 
46 
47  USE base_routines
51  USE domain_mappings
53  USE field_routines
54  USE input_output
57  USE kinds
58  USE lists
59  USE matrix_vector
61  USE strings
62  USE types
63 
64 #include "macros.h"
65 
66  IMPLICIT NONE
67 
68  PRIVATE
69 
70  !Module parameters
71 
76  INTEGER(INTG), PARAMETER :: solver_mapping_equations_dynamic_matrix=1
77  INTEGER(INTG), PARAMETER :: solver_mapping_equations_linear_matrix=2
78  INTEGER(INTG), PARAMETER :: solver_mapping_equations_nonlinear_matrix=3
80 
85  INTEGER(INTG), PARAMETER :: solver_mapping_equations_equations_set=1
86  INTEGER(INTG), PARAMETER :: solver_mapping_equations_interface_condition=2
87  INTEGER(INTG), PARAMETER :: solver_mapping_equations_interface_transpose=3
89 
90  !Module types
91 
92  !Module variables
93 
94  !Interfaces
95 
97 
99 
101 
103 
105 
107 
109 
111 
112 CONTAINS
113 
114  !
115  !=================================================================================================================================
116  !
117 
119  SUBROUTINE solver_mapping_calculate(SOLVER_MAPPING,ERR,ERROR,*)
121  !Argument variables
122  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
123  INTEGER(INTG), INTENT(OUT) :: ERR
124  TYPE(varying_string), INTENT(OUT) :: ERROR
125  !Local Variables
126  INTEGER(INTG) :: column_idx,COLUMN_LIST_ITEM(5),COLUMN_RANK,dof_idx,dof_type,equation_type, &
127  & equations_column,equations_idx,equations_idx2,equations_matrix,equations_matrix_idx,equations_row_number, &
128  & equations_set_idx,EQUATIONS_VARIABLE_LIST_ITEM(3),global_column,global_dof,global_dof_idx,GLOBAL_DOFS_OFFSET, &
129  & global_row,global_row_idx,interface_column,interface_col_number,interface_condition_idx,interface_condition_idx2, &
130  & INTERFACE_EQUATIONS_LIST_ITEM(2),interface_idx,interface_matrix_idx,interface_row,interface_row_number,jacobian_column, &
131  & local_column,local_dof,LOCAL_DOFS_OFFSET,local_row,matrices_type,matrix_number,matrix_type,matrix_type_idx, &
132  & matrix_variable_idx,myrank,NUMBER_OF_COLUMNS,NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES,NUMBER_OF_EQUATIONS_COLUMNS, &
133  & NUMBER_OF_EQUATIONS_SETS,NUMBER_OF_EQUATIONS_VARIABLES,NUMBER_OF_INTERFACES,NUMBER_OF_INTERFACE_COLUMNS, &
134  & NUMBER_OF_INTERFACE_ROWS,NUMBER_OF_INTERFACE_VARIABLES,NUMBER_OF_GLOBAL_SOLVER_DOFS,NUMBER_OF_GLOBAL_SOLVER_ROWS, &
135  & NUMBER_OF_LINEAR_EQUATIONS_MATRICES,NUMBER_OF_LOCAL_SOLVER_DOFS,NUMBER_OF_LOCAL_SOLVER_ROWS,NUMBER_OF_RANK_COLS, &
136  & NUMBER_OF_RANK_ROWS,NUMBER_OF_VARIABLES,rank,rank_idx,row_idx,ROW_LIST_ITEM(4),ROW_RANK,solver_global_dof, &
137  & solver_matrix_idx,solver_variable_idx,TOTAL_NUMBER_OF_LOCAL_SOLVER_DOFS,variable_idx, &
138  & VARIABLE_LIST_ITEM(3),variable_position_idx,variable_type, &
139  & numberRowEquationsRows,numberColEquationsCols,rowEquationsRowIdx,colEquationsColIdx, &
140  & globalDofCouplingNumber,equationsRow,eqnLocalDof
141  INTEGER(INTG) :: temp_offset, solver_variable_idx_temp
142  INTEGER(INTG), ALLOCATABLE :: EQUATIONS_SET_VARIABLES(:,:),EQUATIONS_VARIABLES(:,:),INTERFACE_EQUATIONS_LIST(:,:), &
143  & INTERFACE_VARIABLES(:,:),RANK_GLOBAL_ROWS_LIST(:,:),RANK_GLOBAL_COLS_LIST(:,:),solver_local_dof(:)
144  INTEGER(INTG), ALLOCATABLE :: NUMBER_OF_VARIABLE_GLOBAL_SOLVER_DOFS(:),NUMBER_OF_VARIABLE_LOCAL_SOLVER_DOFS(:), &
145  & TOTAL_NUMBER_OF_VARIABLE_LOCAL_SOLVER_DOFS(:),SUB_MATRIX_INFORMATION(:,:,:),SUB_MATRIX_LIST(:,:,:),VARIABLE_TYPES(:)
146  REAL(DP) :: couplingCoefficient
147  LOGICAL :: FOUND,INCLUDE_COLUMN,INCLUDE_ROW,CONSTRAINED_DOF
148  LOGICAL, ALLOCATABLE :: VARIABLE_PROCESSED(:),VARIABLE_RANK_PROCESSED(:,:)
149  TYPE(boundary_conditions_type), POINTER :: BOUNDARY_CONDITIONS
150  TYPE(boundary_conditions_variable_type), POINTER :: BOUNDARY_CONDITIONS_VARIABLE
151  TYPE(domain_mapping_type), POINTER :: COL_DOMAIN_MAPPING,COL_DOFS_MAPPING,ROW_DOMAIN_MAPPING,ROW_DOFS_MAPPING
152  TYPE(equations_type), POINTER :: EQUATIONS
153  TYPE(equations_mapping_type), POINTER :: EQUATIONS_MAPPING
154  TYPE(equations_mapping_dynamic_type), POINTER :: DYNAMIC_MAPPING
155  TYPE(equations_mapping_linear_type), POINTER :: LINEAR_MAPPING
156  TYPE(equations_mapping_nonlinear_type), POINTER :: NONLINEAR_MAPPING
157  TYPE(equations_mapping_rhs_type), POINTER :: RHS_MAPPING
158  TYPE(equations_mapping_source_type), POINTER :: SOURCE_MAPPING
159  TYPE(equations_set_type), POINTER :: EQUATIONS_SET
160  TYPE(equations_to_solver_maps_type), POINTER :: EQUATIONS_TO_SOLVER_MAP
161  TYPE(field_type), POINTER :: DEPENDENT_FIELD,LAGRANGE_FIELD
162  TYPE(field_variable_type), POINTER :: DEPENDENT_VARIABLE,LAGRANGE_VARIABLE,VARIABLE
163  TYPE(integer_intg_ptr_type), POINTER :: DOF_MAP(:)
164  TYPE(interface_condition_type), POINTER :: INTERFACE_CONDITION
165  TYPE(interface_dependent_type), POINTER :: INTERFACE_DEPENDENT
166  TYPE(interface_equations_type), POINTER :: INTERFACE_EQUATIONS
167  TYPE(interface_mapping_type), POINTER :: INTERFACE_MAPPING
168  TYPE(interface_to_solver_maps_type), POINTER :: INTERFACE_TO_SOLVER_MAP
169  TYPE(jacobian_to_solver_map_type), POINTER :: JACOBIAN_TO_SOLVER_MAP
170  TYPE(list_type), POINTER :: EQUATIONS_SET_VARIABLE_LIST
171  TYPE(list_ptr_type), ALLOCATABLE :: INTERFACE_EQUATIONS_LISTS(:),RANK_GLOBAL_ROWS_LISTS(:,:), &
172  & RANK_GLOBAL_COLS_LISTS(:,:,:,:),VARIABLES_LIST(:)
173  TYPE(solver_equations_type), POINTER :: SOLVER_EQUATIONS
174  TYPE(boundaryconditionsdofconstraintstype), POINTER :: dofConstraints
175  TYPE(boundaryconditionscoupleddofstype), POINTER :: rowEquationRows,colEquationCols
176  TYPE(boundaryconditionscoupleddofstype), TARGET :: dummyDofCoupling
177  TYPE(solvermappingdofcouplingstype) :: rowCouplings
178  TYPE(solvermappingdofcouplingstype) :: columnCouplings
179  TYPE(varying_string) :: LOCAL_ERROR
180 
181  enters("SOLVER_MAPPING_CALCULATE",err,error,*999)
182 
183  IF(ASSOCIATED(solver_mapping)) THEN
184  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE)) THEN
185  solver_equations=>solver_mapping%SOLVER_EQUATIONS
186  IF(ASSOCIATED(solver_equations)) THEN
187  boundary_conditions=>solver_equations%BOUNDARY_CONDITIONS
188  IF(.NOT.ASSOCIATED(boundary_conditions)) THEN
189  CALL flagerror("The solver equations boundary conditions are not associated.",err,error,*999)
190  END IF
191 
192  !
193  !--- Equations set <-> interface conditions ---
194  !
195  ! 1. Calculate the list interface conditions that influence an equations set and vice versa.
196  !
197 
198  !Allocate equations set to solver map
199  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
200  IF(err/=0) CALL flagerror("Could not allocate solver mapping equations set to solver map.",err,error,*999)
201  !Allocate interface condition to solver map
202  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS),stat=err)
203  IF(err/=0) CALL flagerror("Could not allocate solver mapping interface condition to solver map.",err,error,*999)
204  !
205  ! Allocate and initialise
206  !
207  ALLOCATE(interface_equations_lists(solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS),stat=err)
208  IF(err/=0) CALL flagerror("Could not allocate equations set list.",err,error,*999)
209  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
210  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
211  IF(ASSOCIATED(interface_condition)) THEN
212  interface_equations=>interface_condition%INTERFACE_EQUATIONS
213  IF(ASSOCIATED(interface_equations)) THEN
214  CALL solvermapping_interfacetosolvermapinitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
215  & interface_condition_idx),err,error,*999)
216  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_CONDITION_INDEX= &
217  & interface_condition_idx
218  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%SOLVER_MAPPING=>solver_mapping
219  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_EQUATIONS=>interface_equations
220  NULLIFY(interface_equations_lists(interface_condition_idx)%PTR)
221  CALL list_create_start(interface_equations_lists(interface_condition_idx)%PTR,err,error,*999)
222  CALL list_data_type_set(interface_equations_lists(interface_condition_idx)%PTR,list_intg_type,err,error,*999)
223  CALL list_data_dimension_set(interface_equations_lists(interface_condition_idx)%PTR,2,err,error,*999)
224  CALL list_create_finish(interface_equations_lists(interface_condition_idx)%PTR,err,error,*999)
225  ELSE
226  CALL flagerror("Interface condition interface equations is not associated.",err,error,*999)
227  ENDIF
228  ELSE
229  CALL flagerror("Interface condition is not associated.",err,error,*999)
230  ENDIF
231  ENDDO !interface_condition_idx
232  !
233  ! Loop over equations sets
234  !
235  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
236  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
237  IF(ASSOCIATED(equations_set)) THEN
238  equations=>equations_set%EQUATIONS
239  IF(ASSOCIATED(equations)) THEN
240  CALL solvermapping_equationssettosolvermapinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
241  & equations_set_idx),err,error,*999)
242  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_SET_INDEX=equations_set_idx
243  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%SOLVER_MAPPING=>solver_mapping
244  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS=>equations
245  !Set up list of interface conditions affecting this equations set
246  CALL list_detach_and_destroy(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR, &
247  & number_of_interfaces,interface_equations_list,err,error,*999)
248  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
249  & equations_to_solver_matrix_maps_interface(number_of_interfaces),stat=err)
250  IF(err/=0) CALL flagerror("Could not allocate equations to solver maps interface.",err,error,*999)
251  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%NUMBER_OF_INTERFACE_CONDITIONS=number_of_interfaces
252  DO interface_idx=1,number_of_interfaces
253  CALL solvermapping_equationstosolverinterfaceinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
254  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE(interface_idx),err,error,*999)
255  interface_condition_idx=interface_equations_list(1,interface_idx)
256  interface_matrix_idx=interface_equations_list(2,interface_idx)
257  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
258  IF(ASSOCIATED(interface_condition)) THEN
259  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE( &
260  & interface_idx)%INTERFACE_CONDITION_INDEX=interface_condition_idx
261  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE( &
262  & interface_idx)%INTERFACE_CONDITION=>interface_condition
263  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE( &
264  & interface_idx)%INTERFACE_MATRIX_NUMBER=interface_matrix_idx
265  interface_equations_list_item(1)=equations_set_idx
266  interface_equations_list_item(2)=interface_matrix_idx
267  CALL list_item_add(interface_equations_lists(interface_condition_idx)%PTR,interface_equations_list_item, &
268  & err,error,*999)
269  ELSE
270  CALL flagerror("Interface condition is not associated.",err,error,*999)
271  ENDIF
272  ENDDO !interface_condition_idx
273  IF(ALLOCATED(interface_equations_list)) DEALLOCATE(interface_equations_list)
274  ELSE
275  CALL flagerror("Equations set equations is not associated.",err,error,*999)
276  ENDIF
277  ELSE
278  CALL flagerror("Equations set is not associated.",err,error,*999)
279  ENDIF
280  ENDDO !equations_set_idx
281  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
282  CALL list_detach_and_destroy(interface_equations_lists(interface_condition_idx)%PTR,number_of_equations_sets, &
283  interface_equations_list,err,error,*999)
284  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
285  & interface_to_solver_matrix_maps_equations(number_of_equations_sets),stat=err)
286  IF(err/=0) CALL flagerror("Could not allocate interface to solver maps equations.",err,error,*999)
287  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%NUMBER_OF_EQUATIONS_SETS= &
288  & number_of_equations_sets
289  DO equations_idx=1,number_of_equations_sets
290  CALL solvermapping_interfacetosolverequationsinitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
291  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_EQUATIONS(equations_idx),err,error,*999)
292  equations_set_idx=interface_equations_list(1,equations_idx)
293  interface_matrix_idx=interface_equations_list(2,equations_idx)
294  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
295  IF(ASSOCIATED(equations_set)) THEN
296  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
297  & interface_to_solver_matrix_maps_equations(equations_idx)%EQUATIONS_SET_INDEX=equations_set_idx
298  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
299  & interface_to_solver_matrix_maps_equations(equations_idx)%EQUATIONS_SET=>equations_set
300  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
301  & interface_to_solver_matrix_maps_equations(equations_idx)%INTERFACE_MATRIX_INDEX=interface_matrix_idx
302  ELSE
303  CALL flagerror("Equations set is not associated.",err,error,*999)
304  ENDIF
305  ENDDO !equations_idx
306  IF(ALLOCATED(interface_equations_list)) DEALLOCATE(interface_equations_list)
307  ENDDO !interface_condition_idx
308  !
309  !--- Row mappings ---
310  !
311  ! 2. Determine the number of rows in the solver matrix. Do this the by setting up a list of rows for each rank.
312  ! We can then later arrange the rows in rank order by looping over the ranks in the list and then the rows
313  ! for each rank.
314  !
315  !Calculate the row mappings.
316  myrank=computational_environment%MY_COMPUTATIONAL_NODE_NUMBER
317  number_of_global_solver_rows=0
318  number_of_local_solver_rows=0
319  !Add in the rows from any equations sets that have been added to the solver equations
320  !Presort the row numbers by rank.
321  !
322  !Allocate and initialise the rank lists.
323  ALLOCATE(rank_global_rows_lists(solver_mapping%NUMBER_OF_EQUATIONS_SETS+solver_mapping% &
324  & number_of_interface_conditions,0:computational_environment%NUMBER_COMPUTATIONAL_NODES-1),stat=err)
325  IF(err/=0) CALL flagerror("Could not allocate rank global rows lists.",err,error,*999)
326  CALL solverdofcouplings_initialise(rowcouplings,err,error,*999)
327  DO rank=0,computational_environment%NUMBER_COMPUTATIONAL_NODES-1
328  equations_idx=0
329  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
330  equations_idx=equations_idx+1
331  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
332  IF(ASSOCIATED(equations_set)) THEN
333  equations=>equations_set%EQUATIONS
334  IF(ASSOCIATED(equations)) THEN
335  equations_mapping=>equations%EQUATIONS_MAPPING
336  IF(ASSOCIATED(equations_mapping)) THEN
337  NULLIFY(rank_global_rows_lists(equations_idx,rank)%PTR)
338  CALL list_create_start(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
339  CALL list_data_type_set(rank_global_rows_lists(equations_idx,rank)%PTR,list_intg_type,err,error,*999)
340  CALL list_initial_size_set(rank_global_rows_lists(equations_idx,rank)%PTR,int(equations_mapping% &
341  & number_of_global_rows/computational_environment%NUMBER_COMPUTATIONAL_NODES,intg), &
342  & err,error,*999)
343  CALL list_data_dimension_set(rank_global_rows_lists(equations_idx,rank)%PTR,4,err,error,*999)
344  CALL list_key_dimension_set(rank_global_rows_lists(equations_idx,rank)%PTR,1,err,error,*999)
345  CALL list_create_finish(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
346  ELSE
347  CALL flagerror("Equations equations mapping is not associated",err,error,*999)
348  ENDIF
349  ELSE
350  CALL flagerror("Equations set equations is not associated.",err,error,*999)
351  ENDIF
352  ELSE
353  CALL flagerror("Equations set is not associated.",err,error,*999)
354  ENDIF
355  ENDDO !equations_set_idx
356  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
357  equations_idx=equations_idx+1
358  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
359  IF(ASSOCIATED(interface_condition)) THEN
360  SELECT CASE(interface_condition%METHOD)
362  interface_equations=>interface_condition%INTERFACE_EQUATIONS
363  IF(ASSOCIATED(interface_equations)) THEN
364  interface_mapping=>interface_equations%INTERFACE_MAPPING
365  IF(ASSOCIATED(interface_mapping)) THEN
366  NULLIFY(rank_global_rows_lists(equations_idx,rank)%PTR)
367  CALL list_create_start(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
368  CALL list_data_type_set(rank_global_rows_lists(equations_idx,rank)%PTR,list_intg_type,err,error,*999)
369  CALL list_initial_size_set(rank_global_rows_lists(equations_idx,rank)%PTR, &
370  & int(interface_mapping%NUMBER_OF_GLOBAL_COLUMNS/computational_environment%NUMBER_COMPUTATIONAL_NODES, &
371  & intg),err,error,*999)
372  CALL list_data_dimension_set(rank_global_rows_lists(equations_idx,rank)%PTR,4,err,error,*999)
373  CALL list_key_dimension_set(rank_global_rows_lists(equations_idx,rank)%PTR,1,err,error,*999)
374  CALL list_create_finish(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
375  ELSE
376  CALL flagerror("Interface equations interface mapping is not associated.",err,error,*999)
377  ENDIF
378  ELSE
379  CALL flagerror("Interface condition interface equations is not associated.",err,error,*999)
380  ENDIF
382  CALL flagerror("Not implemented.",err,error,*999)
384  CALL flagerror("Not implemented.",err,error,*999)
385  CASE DEFAULT
386  local_error="The interface condition method of "// &
387  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))// &
388  & " is invalid."
389  CALL flagerror(local_error,err,error,*999)
390  END SELECT
391  ELSE
392  CALL flagerror("Interface condition is not associated.",err,error,*999)
393  ENDIF
394  ENDDO !interface_condition_idx
395  ENDDO !rank
396  !Calculate the number of local and global rows. Do this by looking at the boundary conditions for field variables
397  !involved in the row. If all the variables are set as a fixed boundary condition then do not include the row. If
398  !any variable is not fixed then include the row.
399  equations_idx=0
400  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
401  equations_idx=equations_idx+1
402  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
403  IF(ASSOCIATED(equations_set)) THEN
404  equations=>equations_set%EQUATIONS
405  IF(ASSOCIATED(equations)) THEN
406  equations_mapping=>equations%EQUATIONS_MAPPING
407  IF(ASSOCIATED(equations_mapping)) THEN
408  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
409  linear_mapping=>equations_mapping%LINEAR_MAPPING
410  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
411  rhs_mapping=>equations_mapping%RHS_MAPPING
412  source_mapping=>equations_mapping%SOURCE_MAPPING
413  row_dofs_mapping=>equations_mapping%ROW_DOFS_MAPPING
414  IF(ASSOCIATED(row_dofs_mapping)) THEN
415  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
416  IF(ASSOCIATED(dependent_field)) THEN
417  !Loop over the global rows for this equations set
418  DO global_row=1,equations_mapping%NUMBER_OF_GLOBAL_ROWS
419  !Find the rank that owns this global row
420  row_rank=-1
421  DO rank_idx=1,row_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_row)%NUMBER_OF_DOMAINS
422  IF(row_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_row)%LOCAL_TYPE(rank_idx)/=domain_local_ghost) THEN
423  row_rank=row_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_row)%DOMAIN_NUMBER(rank_idx)
424  local_row=row_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_row)%LOCAL_NUMBER(rank_idx)
425  EXIT
426  ENDIF
427  ENDDO !rank_idx
428  IF(row_rank>=0) THEN
429  include_row=.true.
430  constrained_dof=.false.
431  globaldofcouplingnumber=0
432  IF(ASSOCIATED(dynamic_mapping)) THEN
433  dependent_variable=>dynamic_mapping%DYNAMIC_VARIABLE
434  CALL boundary_conditions_variable_get(boundary_conditions,dependent_variable, &
435  & boundary_conditions_variable,err,error,*999)
436  IF(ASSOCIATED(boundary_conditions_variable)) THEN
437  !This is wrong as we only have the mappings for the local rank not the global ranks.
438  !For now assume 1-1 mapping between rows and dofs.
439  global_dof=global_row
440  include_row=include_row.AND.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
442  constrained_dof=constrained_dof.OR.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
444  IF(ASSOCIATED(boundary_conditions_variable%dofConstraints)) THEN
445  dofconstraints=>boundary_conditions_variable%dofConstraints
446  IF(dofconstraints%numberOfConstraints>0) THEN
447  IF(ALLOCATED(dofconstraints%dofCouplings)) THEN
448  IF(ASSOCIATED(dofconstraints%dofCouplings(global_dof)%ptr)) THEN
449  !This equations row is the owner of a solver row that is mapped to
450  !multiple other equations rows, add it to the list of global row
451  !couplings and remember the index into the global list for this solver row
452  CALL solverdofcouplings_addcoupling(rowcouplings, &
453  & dofconstraints%dofCouplings(global_dof)%ptr, &
454  & globaldofcouplingnumber,err,error,*999)
455  END IF
456  ELSE
457  CALL flagerror("DOF constraints DOF couplings are not allocated.",err,error,*999)
458  END IF
459  END IF
460  END IF
461  ELSE
462  CALL flagerror("Boundary condition variable is not associated.",err,error,*999)
463  ENDIF
464  ENDIF
465  IF(ASSOCIATED(nonlinear_mapping)) THEN
466  !Look at the boundary conditions for nonlinear variables for this row
467  !Just look at first residual variable for now
468  dependent_variable=>nonlinear_mapping%JACOBIAN_TO_VAR_MAP(1)%VARIABLE
469  CALL boundary_conditions_variable_get(boundary_conditions,dependent_variable, &
470  & boundary_conditions_variable,err,error,*999)
471  IF(ASSOCIATED(boundary_conditions_variable)) THEN
472  global_dof=global_row
473  include_row=include_row.AND.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
475  constrained_dof=constrained_dof.OR.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
477  IF(ASSOCIATED(boundary_conditions_variable%dofConstraints)) THEN
478  dofconstraints=>boundary_conditions_variable%dofConstraints
479  IF(dofconstraints%numberOfConstraints>0) THEN
480  IF(ALLOCATED(dofconstraints%dofCouplings)) THEN
481  IF(ASSOCIATED(dofconstraints%dofCouplings(global_dof)%ptr)) THEN
482  CALL solverdofcouplings_addcoupling(rowcouplings, &
483  & dofconstraints%dofCouplings(global_dof)%ptr, &
484  & globaldofcouplingnumber,err,error,*999)
485  END IF
486  ELSE
487  CALL flagerror("DOF constraints DOF couplings are not allocated.",err,error,*999)
488  END IF
489  END IF
490  END IF
491  ELSE
492  CALL flagerror("Boundary condition variable is not associated.",err,error,*999)
493  ENDIF
494  ENDIF
495  IF(ASSOCIATED(linear_mapping)) THEN
496  !Loop over the variables in the equations set. Don't include the row in the solver matrices if
497  !all the variable dofs associated with this equations row are fixed.
498  DO equations_matrix_idx=1,linear_mapping%NUMBER_OF_LINEAR_MATRIX_VARIABLES
499  dependent_variable=>linear_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(equations_matrix_idx)% &
500  & variable
501  CALL boundary_conditions_variable_get(boundary_conditions,dependent_variable, &
502  & boundary_conditions_variable,err,error,*999)
503  IF(ASSOCIATED(boundary_conditions_variable)) THEN
504  !\todo This is wrong as we only have the mappings for the local rank not the global ranks. See below
505  !\todo For now assume 1-1 mapping between rows and dofs.
506  global_dof=global_row
507  include_row=include_row.AND.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
509  constrained_dof=constrained_dof.OR.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
511  IF(ASSOCIATED(boundary_conditions_variable%dofConstraints)) THEN
512  dofconstraints=>boundary_conditions_variable%dofConstraints
513  IF(dofconstraints%numberOfConstraints>0) THEN
514  IF(ALLOCATED(dofconstraints%dofCouplings)) THEN
515  IF(ASSOCIATED(dofconstraints%dofCouplings(global_dof)%ptr)) THEN
516  CALL solverdofcouplings_addcoupling(rowcouplings, &
517  & dofconstraints%dofCouplings(global_dof)%ptr, &
518  & globaldofcouplingnumber,err,error,*999)
519  END IF
520  ELSE
521  CALL flagerror("DOF constraints DOF couplings are not allocated.",err,error,*999)
522  END IF
523  END IF
524  END IF
525  ELSE
526  CALL flagerror("Boundary condition variable is not associated.",err,error,*999)
527  ENDIF
528  ENDDO !matrix_idx
529  ENDIF
530  row_list_item(1)=global_row
531  row_list_item(2)=local_row
532  row_list_item(4)=globaldofcouplingnumber
533  IF(include_row) THEN
534  row_list_item(3)=1
535  number_of_global_solver_rows=number_of_global_solver_rows+1
536  !Don't need to worry about ghosted rows.
537  IF(row_rank==myrank) number_of_local_solver_rows=number_of_local_solver_rows+1 !1-1 mapping
538  ELSE IF(constrained_dof) THEN
539  row_list_item(3)=2
540  ELSE
541  row_list_item(3)=0
542  ENDIF !include row
543  CALL list_item_add(rank_global_rows_lists(equations_idx,row_rank)%PTR,row_list_item,err,error,*999)
544  ELSE
545  CALL flagerror("Global row is not owned by a domain.",err,error,*999)
546  ENDIF
547  ENDDO !global_row
548  ELSE
549  CALL flagerror("Equations set dependent field is not associated.",err,error,*999)
550  ENDIF
551  ELSE
552  CALL flagerror("Equations set row degree of freedom mappings is not associated.",err,error,*999)
553  ENDIF
554  ELSE
555  CALL flagerror("Equations equations mapping is not associated",err,error,*999)
556  ENDIF
557  ELSE
558  CALL flagerror("Equations set equations is not associated.",err,error,*999)
559  ENDIF
560  ELSE
561  CALL flagerror("Equations set is not associated.",err,error,*999)
562  ENDIF
563  ENDDO !equations set idx
564  !Now add in rows from any interface matrices
565  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
566  equations_idx=equations_idx+1
567  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
568  IF(ASSOCIATED(interface_condition)) THEN
569  SELECT CASE(interface_condition%METHOD)
571  interface_equations=>interface_condition%INTERFACE_EQUATIONS
572  IF(ASSOCIATED(interface_equations)) THEN
573  interface_mapping=>interface_equations%INTERFACE_MAPPING
574  IF(ASSOCIATED(interface_mapping)) THEN
575  col_dofs_mapping=>interface_mapping%COLUMN_DOFS_MAPPING
576  IF(ASSOCIATED(col_dofs_mapping)) THEN
577  lagrange_field=>interface_condition%LAGRANGE%LAGRANGE_FIELD
578  IF(ASSOCIATED(lagrange_field)) THEN
579  boundary_conditions=>solver_equations%BOUNDARY_CONDITIONS
580  IF(ASSOCIATED(boundary_conditions)) THEN
581  !\todo Lagrange variable type set to the first variable type for now
582  variable_type=1
583  lagrange_variable=>lagrange_field%VARIABLE_TYPE_MAP(variable_type)%PTR
584  CALL boundary_conditions_variable_get(boundary_conditions,lagrange_variable, &
585  & boundary_conditions_variable,err,error,*999)
586  IF(ASSOCIATED(boundary_conditions_variable)) THEN
587  !Loop over the global columns for this interface equation
588  DO global_column=1,interface_mapping%NUMBER_OF_GLOBAL_COLUMNS
589  !Find the rank that owns this global column
590  column_rank=-1
591  DO rank_idx=1,col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_column)%NUMBER_OF_DOMAINS
592  IF(col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_column)% &
593  & local_type(rank_idx)/=domain_local_ghost) THEN
594  column_rank=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_column)%DOMAIN_NUMBER(rank_idx)
595  local_column=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_column)%LOCAL_NUMBER(rank_idx)
596  EXIT
597  ENDIF
598  ENDDO !rank_idx
599  IF(column_rank>=0) THEN
600  include_column=.true.
601  !\todo This is wrong as we only have the mappings for the local rank not the global ranks. See above
602  !\todo For now assume 1-1 mapping between rows and dofs.
603  global_dof=global_column
604  include_column=include_column.AND.(boundary_conditions_variable%DOF_TYPES(global_dof)== &
606  row_list_item(1)=global_column
607  row_list_item(2)=local_column
608  IF(include_column) THEN
609  row_list_item(3)=1
610  number_of_global_solver_rows=number_of_global_solver_rows+1
611  !Don't need to worry about ghosted rows.
612  IF(column_rank==myrank) number_of_local_solver_rows=number_of_local_solver_rows+1 !1-1 mapping
613  ELSE
614  row_list_item(3)=0
615  ENDIF !include column
616  CALL list_item_add(rank_global_rows_lists(equations_idx,column_rank)%PTR,row_list_item, &
617  & err,error,*999)
618  ELSE
619  CALL flagerror("Global row is not owned by a domain.",err,error,*999)
620  ENDIF
621  ENDDO !global_column
622  ELSE
623  CALL flagerror("Boundary condition variable is not associated.",err,error,*999)
624  ENDIF
625  ELSE
626  CALL flagerror("Equations set boundary conditions is not associated.",err,error,*999)
627  ENDIF
628  ELSE
629  CALL flagerror("Interface equations Lagrange field is not associated.",err,error,*999)
630  ENDIF
631  ELSE
632  CALL flagerror("Interface condition column degree of freedom mappings is not associated.",err,error,*999)
633  ENDIF
634  ELSE
635  CALL flagerror("Interface equations interface mapping is not associated.",err,error,*999)
636  ENDIF
637  ELSE
638  CALL flagerror("Interface condition interface equations is not associated.",err,error,*999)
639  ENDIF
641  CALL flagerror("Not implemented.",err,error,*999)
643  CALL flagerror("Not implemented.",err,error,*999)
644  CASE DEFAULT
645  local_error="The interface condition method of "// &
646  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))//" is invalid."
647  CALL flagerror(local_error,err,error,*999)
648  END SELECT
649  ELSE
650  CALL flagerror("Interface condition is not associated.",err,error,*999)
651  ENDIF
652  ENDDO !interface_condition_idx
653 
654  !Sanity check.
655  IF(number_of_local_solver_rows==0) &
656  & CALL flagerror("Invalid problem setup. The number of local solver rows is zero.",err,error,*999)
657  IF(number_of_global_solver_rows==0) &
658  & CALL flagerror("Invalid problem setup. The number of global solver rows is zero.",err,error,*999)
659 
660  !
661  ! 3. We now know how many local and global rows are in the solver matrix. Loop over the rows in rank order and calculate
662  ! the row mappings.
663  !
664  ! 3a Allocate and initialise the data structures
665  !
666 
667  !Allocate memory for the rows mapping
668  !Allocate the solver rows to equations set maps
669  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows),stat=err)
670  IF(err/=0) CALL flagerror("Could not allocate solver mapping solver row to equation rows map.",err,error,*999)
671  !Set the number of rows
672  solver_mapping%NUMBER_OF_ROWS=number_of_local_solver_rows
673  solver_mapping%NUMBER_OF_GLOBAL_ROWS=number_of_global_solver_rows
674  !Allocate the solver rows domain mapping
675  ALLOCATE(solver_mapping%ROW_DOFS_MAPPING,stat=err)
676  IF(err/=0) CALL flagerror("Could not allocate solver mapping row dofs mapping.",err,error,*999)
677 !!TODO: what is the real number of domains for a solver???
678  CALL domain_mappings_mapping_initialise(solver_mapping%ROW_DOFS_MAPPING,computational_environment% &
679  & number_computational_nodes,err,error,*999)
680  row_domain_mapping=>solver_mapping%ROW_DOFS_MAPPING
681  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows),stat=err)
682  IF(err/=0) CALL flagerror("Could not allocate row dofs mapping global to local map.",err,error,*999)
683  row_domain_mapping%NUMBER_OF_GLOBAL=number_of_global_solver_rows
684 
685  !Initialise the equations sets to solver maps
686  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
687 
688  !Note that pointers have been checked for association above
689  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
690  equations=>equations_set%EQUATIONS
691  equations_mapping=>equations%EQUATIONS_MAPPING
692 
693  !Allocate the equations set to solver maps for solver matrix (sm) indexing
694  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
695  & solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
696  IF(err/=0) CALL flagerror("Could not allocate equations set to solver map equations to solver matrix maps sm.", &
697  & err,error,*999)
698  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
699  CALL solvermapping_equatstosolmatmapssminitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
700  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx),err,error,*999)
701  ENDDO !solver_matrix_idx
702 
703  !Allocate the equations row to solver rows maps
704  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
705  & equations_mapping%TOTAL_NUMBER_OF_ROWS),stat=err)
706  IF(err/=0) CALL flagerror("Could not allocate equations set to solver map equations row to solver rows maps.", &
707  & err,error,*999)
708  DO equations_row_number=1,equations_mapping%TOTAL_NUMBER_OF_ROWS
709  !Initialise
710  CALL solvermapping_equatsrowtosolrowsmapinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
711  & equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS(equations_row_number),err,error,*999)
712  ENDDO
713 
714  ENDDO !equations_set_idx
715 
716  !Initialise the interface condition to solver maps
717  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
718 
719  !Note that pointers have been checked for association above
720  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
721  interface_equations=>interface_condition%INTERFACE_EQUATIONS
722  interface_mapping=>interface_equations%INTERFACE_MAPPING
723 
724  !Allocate the interface to solver maps for solver matrix (sm) indexing
725  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
726  & solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
727  IF(err/=0) CALL flagerror("Could not allocate interface to solver map interface to solver matrix maps sm.", &
728  & err,error,*999)
729  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
730  CALL solvermapping_interftosolmatmapssminitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
731  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx),err,error,*999)
732  ENDDO !solver_matrix_idx
733 
734  !Allocate the interface to solver maps for interface matrix (im) indexing
735  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
736  & interface_to_solver_matrix_maps_im(interface_mapping%NUMBER_OF_INTERFACE_MATRICES),stat=err)
737  IF(err/=0) &
738  & CALL flagerror("Could not allocate interface to solver map equations to solver matrix maps im.", &
739  & err,error,*999)
740  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
741  CALL solvermapping_interftosolmatmapsiminitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
742  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM(interface_matrix_idx),err,error,*999)
743 
744  !Allocate the interfafce row to solver row maps
745  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
746  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
747  & interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%TOTAL_NUMBER_OF_ROWS),stat=err)
748  IF(err/=0) CALL flagerror("Could not allocate interface condition to solver map interface row to solver row map.", &
749  & err,error,*999)
750  DO interface_row_number=1,interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx) &
751  & %TOTAL_NUMBER_OF_ROWS
752  CALL solvermapping_interfrowtosolrowsmapinitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
753  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM(interface_matrix_idx)% &
754  & interface_row_to_solver_rows_map(interface_row_number),err,error,*999)
755  ENDDO !interface_row_number
756 
757  ENDDO !interface_matrix_idx
758 
759  !Allocate the interface column to solver row maps
760  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
761  & interface_column_to_solver_rows_maps(interface_mapping%TOTAL_NUMBER_OF_COLUMNS),stat=err)
762  IF(err/=0) &
763  & CALL flagerror("Could not allocate interface condition to solver map interface column to solver row map.", &
764  & err,error,*999)
765  DO interface_col_number=1,interface_mapping%TOTAL_NUMBER_OF_COLUMNS
766  !Initialise
767  CALL solvermapping_interfcoltosolrowsmapinitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
768  & interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS(interface_col_number),err,error,*999)
769  ENDDO !interface_col_number
770 
771  ENDDO !interface condition_idx
772 
773  !
774  ! 3b Now calculate the mappings for each solver row <-> equations row & interface row/column in rank order.
775  !
776 
777  number_of_global_solver_rows=0
778  !Make a "dof coupling" for rows that aren't coupled
779  ALLOCATE(dummydofcoupling%globalDofs(1),stat=err)
780  IF(err/=0) CALL flagerror("Could not allocate dummy DOF coupling DOFs.",err,error,*999)
781  ALLOCATE(dummydofcoupling%localDofs(1),stat=err)
782  IF(err/=0) CALL flagerror("Could not allocate dummy DOF coupling local Dofs.",err,error,*999)
783  ALLOCATE(dummydofcoupling%coefficients(1),stat=err)
784  IF(err/=0) CALL flagerror("Could not allocate dummy DOF coupling values.",err,error,*999)
785  dummydofcoupling%numberOfDofs=1
786  !Loop over the ranks to ensure that the lowest ranks have the lowest numbered solver variables
787  DO rank=0,computational_environment%NUMBER_COMPUTATIONAL_NODES-1
788  number_of_local_solver_rows=0
789 
790  !Calculate the solver row <-> equations row & interface row mappings.
791  equations_idx=0
792  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
793  equations_idx=equations_idx+1
794 
795  !Get rows list
796  CALL list_sort(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
797  CALL list_detach_and_destroy(rank_global_rows_lists(equations_idx,rank)%PTR,number_of_rank_rows, &
798  & rank_global_rows_list,err,error,*999)
799 
800  !Note that pointers have been checked for association above
801  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
802  equations=>equations_set%EQUATIONS
803  equations_mapping=>equations%EQUATIONS_MAPPING
804  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
805  linear_mapping=>equations_mapping%LINEAR_MAPPING
806  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
807 
808  !Loop over the global rows for this rank.
809  DO global_row_idx=1,number_of_rank_rows
810  global_row=rank_global_rows_list(1,global_row_idx)
811  local_row=rank_global_rows_list(2,global_row_idx)
812  include_row=rank_global_rows_list(3,global_row_idx)==1
813  constrained_dof=rank_global_rows_list(3,global_row_idx)==2
814  globaldofcouplingnumber=rank_global_rows_list(4,global_row_idx)
815  IF(globaldofcouplingnumber>0) THEN
816  rowequationrows=>rowcouplings%dofCouplings(globaldofcouplingnumber)%ptr
817  IF(ASSOCIATED(rowequationrows)) THEN
818  numberrowequationsrows=rowequationrows%numberOfDofs
819  ELSE
820  CALL flagerror("Dof coupling is not associated for global dof coupling number "// &
821  & trim(numbertovstring(globaldofcouplingnumber,"*",err,error))//".",err,error,*999)
822  END IF
823  ELSE
824  numberrowequationsrows=1
825  dummydofcoupling%globalDofs(1)=global_row
826  dummydofcoupling%localDofs(1)=local_row
827  dummydofcoupling%coefficients(1)=1.0_dp
828  rowequationrows=>dummydofcoupling
829  END IF
830 
831  IF(include_row) THEN
832  number_of_global_solver_rows=number_of_global_solver_rows+1
833  number_of_local_solver_rows=number_of_local_solver_rows+1
834  !Set up the row domain mappings.
835  !There are no ghosted rows for the solver matrices so there is only one domain for the global to local map.
836  !Initialise
837  CALL domain_mappings_mapping_global_initialise(row_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
838  & number_of_global_solver_rows),err,error,*999)
839  !Allocate the global to local map arrays
840  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_NUMBER(1),stat=err)
841  IF(err/=0) CALL flagerror("Could not allocate row global to local map local number.",err,error,*999)
842  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%DOMAIN_NUMBER(1),stat=err)
843  IF(err/=0) CALL flagerror("Could not allocate row global to local map domain number.",err,error,*999)
844  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_TYPE(1),stat=err)
845  IF(err/=0) CALL flagerror("Could not allocate row global to local map local type.",err,error,*999)
846  !Set the global to local mappings
847  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%NUMBER_OF_DOMAINS=1
848  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_NUMBER(1)= &
849  & number_of_local_solver_rows
850  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%DOMAIN_NUMBER(1)=rank
851  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_TYPE(1)=domain_local_internal
852  IF(rank==myrank) THEN
853  !If this is my rank then set up the solver->equations and equations->solver row mappings
854 
855  !Set up the solver row -> equations row mappings. Will need to look
856  !At the interface conditions for this equations set later.
857  !Initialise
858  CALL solvermapping_solrowtoequationsmapsinitialise(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP( &
859  & number_of_local_solver_rows),err,error,*999)
860 
861  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
862  & equations_index(numberrowequationsrows),stat=err)
863  IF(err/=0) CALL flagerror("Could not allocate solver row to equations rows equations index.",err,error,*999)
864  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
865  & rowcol_number(numberrowequationsrows),stat=err)
866  IF(err/=0) &
867  & CALL flagerror("Could not allocate solver row to equations rows row/col number.",err,error,*999)
868  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
869  & coupling_coefficients(numberrowequationsrows),stat=err)
870  IF(err/=0) CALL flagerror("Could not allocate solver row to equations rows coupling coefficients.", &
871  & err,error,*999)
872  !Set the mappings for the first equations DOF, the rest will be set up later using the DOF constraints
873  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
874  & number_of_equations_set_rows=numberrowequationsrows
875  DO rowequationsrowidx=1,numberrowequationsrows
876  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
877  & equations_index(rowequationsrowidx)=equations_set_idx
878  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
879  & rowcol_number(rowequationsrowidx)=rowequationrows%localDofs(rowequationsrowidx)
880  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
881  & coupling_coefficients(rowequationsrowidx)=rowequationrows%coefficients(rowequationsrowidx)
882  END DO
883  !Set up the equations row -> solver row mappings
884  DO rowequationsrowidx=1,numberrowequationsrows
885  equationsrow=rowequationrows%localDofs(rowequationsrowidx)
886  !Allocate the equations row to solver row mappings arrays
887  IF(ALLOCATED(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
888  & equations_row_to_solver_rows_maps(equationsrow)%SOLVER_ROWS)) THEN
889  CALL flagerror("Equations row to solver row map is already allocated, "// &
890  & "mapping an equations row to multiple solver rows is not yet implemented.",err,error,*999)
891  END IF
892  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
893  & equationsrow)%SOLVER_ROWS(1),stat=err)
894  IF(err/=0) CALL flagerror("Could not allocate equations row to solver rows maps solver rows.", &
895  & err,error,*999)
896  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
897  & equationsrow)%COUPLING_COEFFICIENTS(1),stat=err)
898  IF(err/=0) CALL flagerror("Could not allocate equations row to solver rows maps solver rows.", &
899  & err,error,*999)
900  !Set the mappings
901  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
902  & equationsrow)%NUMBER_OF_SOLVER_ROWS=1
903  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
904  & equationsrow)%SOLVER_ROWS(1)=number_of_local_solver_rows
905  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
906  & equationsrow)%COUPLING_COEFFICIENTS(1)=rowequationrows%coefficients(rowequationsrowidx)
907  !Now set up any interface condition rows to solver rows that affect this equations set.
908  DO interface_condition_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
909  & number_of_interface_conditions
910  interface_condition_idx2=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
911  & equations_to_solver_matrix_maps_interface(interface_condition_idx)%INTERFACE_CONDITION_INDEX
912  interface_matrix_idx=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
913  & equations_to_solver_matrix_maps_interface(interface_condition_idx)%INTERFACE_MATRIX_NUMBER
914  !Set the mappings
915  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx2)% &
916  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
917  & equationsrow)%NUMBER_OF_SOLVER_ROWS=1
918  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx2)% &
919  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
920  & equationsrow)%SOLVER_ROW=number_of_local_solver_rows
921  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx2)% &
922  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
923  & equationsrow)%COUPLING_COEFFICIENT=rowequationrows%coefficients(rowequationsrowidx)
924  ENDDO !interface_condition_idx
925  END DO
926 
927  ENDIF !rank==my rank
928  ELSE IF(constrained_dof) THEN
929  !Do nothing, the row mapping for this equations row will be set up with
930  !the first equations row mapped to the solver row
931  ELSE
932  !Note that in this case these mappings are set to zero since these equation rows don't appear in the solver matrices
933  IF(rank==myrank) THEN
934  !Set the mappings
935  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS( &
936  & local_row)%NUMBER_OF_SOLVER_ROWS=0
937  !Now set up any interface condition rows to solver rows that affect this equations set.
938  DO interface_condition_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
939  & number_of_interface_conditions
940  interface_condition_idx2=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
941  & equations_to_solver_matrix_maps_interface(interface_condition_idx)%INTERFACE_CONDITION_INDEX
942  interface_matrix_idx=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
943  & equations_to_solver_matrix_maps_interface(interface_condition_idx)%INTERFACE_MATRIX_NUMBER
944  !Set the mappings
945  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx2)% &
946  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
947  & local_row)%NUMBER_OF_SOLVER_ROWS=0
948  ENDDO !interface_condition_idx
949  ENDIF !rank==my rank
950  ENDIF !include row
951  ENDDO !global_row_idx
952  IF(ALLOCATED(rank_global_rows_list)) DEALLOCATE(rank_global_rows_list)
953  ENDDO !equations_set_idx
954 
955  !Calculate the solver row <-> interface column/row mappings
956  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
957  equations_idx=equations_idx+1
958 
959  !Get rows list
960  CALL list_sort(rank_global_rows_lists(equations_idx,rank)%PTR,err,error,*999)
961  CALL list_detach_and_destroy(rank_global_rows_lists(equations_idx,rank)%PTR,number_of_rank_rows, &
962  & rank_global_rows_list,err,error,*999)
963 
964  !Note that pointers have been checked for association above
965  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
966  interface_equations=>interface_condition%INTERFACE_EQUATIONS
967  interface_mapping=>interface_equations%INTERFACE_MAPPING
968 
969  !Loop over the global rows for this rank.
970  DO global_row_idx=1,number_of_rank_rows
971  global_column=rank_global_rows_list(1,global_row_idx)
972  local_column=rank_global_rows_list(2,global_row_idx)
973  include_column=rank_global_rows_list(3,global_row_idx)==1
974  constrained_dof=rank_global_rows_list(3,global_row_idx)==2
975  IF(include_column) THEN
976  number_of_global_solver_rows=number_of_global_solver_rows+1
977  number_of_local_solver_rows=number_of_local_solver_rows+1
978  !Set up the row domain mappings.
979  !There are no ghosted rows for the solver matrices so there is only one domain for the global to local map.
980  !Initialise
981  CALL domain_mappings_mapping_global_initialise(row_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
982  & number_of_global_solver_rows),err,error,*999)
983  !Allocate the global to local map arrays
984  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_NUMBER(1),stat=err)
985  IF(err/=0) CALL flagerror("Could not allocate row global to local map local number.",err,error,*999)
986  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%DOMAIN_NUMBER(1),stat=err)
987  IF(err/=0) CALL flagerror("Could not allocate row global to local map domain number.",err,error,*999)
988  ALLOCATE(row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_TYPE(1),stat=err)
989  IF(err/=0) CALL flagerror("Could not allocate row global to local map local type.",err,error,*999)
990  !Set the global to local mappings
991  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%NUMBER_OF_DOMAINS=1
992  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_NUMBER(1)= &
993  & number_of_local_solver_rows
994  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%DOMAIN_NUMBER(1)=rank
995  row_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_rows)%LOCAL_TYPE(1)=domain_local_internal
996  !If this is my rank then set up the solver->equations and equations->solver row mappings
997  IF(rank==myrank) THEN
998  !Set the interface column/row -> solver row mappings
999  !Note that for populating SOLVER_MAPPING%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(NUMBER_OF_LOCAL_SOLVER_ROWS)%ROWCOL_NUMBER(i)
1000  !If the row are equations set rows this is the i'th row number that the solver row is mapped to.
1001 
1002  !If the rows are interface rows (which is the case here) then this is the i'th column number that the solver row is mapped to.
1003  !Initialise
1004  CALL solvermapping_solrowtoequationsmapsinitialise(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP( &
1005  & number_of_local_solver_rows),err,error,*999)
1006  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
1007  & rowcol_number(1),stat=err)
1008  IF(err/=0) &
1009  & CALL flagerror("Could not allocate solver row to equations rows row/col number.",err,error,*999)
1010  ALLOCATE(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)% &
1011  & coupling_coefficients(1),stat=err)
1012  IF(err/=0) CALL flagerror("Could not allocate solver row to equations rows coupling coefficients.", &
1013  & err,error,*999)
1014  !Set up the interface column -> solver row mappings
1015  !/todo the SOLVER_ROW_TO_EQUATIONS_ROWS_MAP may need to be renamed for clarity
1016  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)%INTERFACE_CONDITION_INDEX= &
1017  & interface_condition_idx
1018  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)%ROWCOL_NUMBER(1)= &
1019  & local_column
1020  solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(number_of_local_solver_rows)%COUPLING_COEFFICIENTS(1)= &
1021  & 1.0_dp
1022  !Set the mappings
1023  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1024  & interface_column_to_solver_rows_maps(local_column)%NUMBER_OF_SOLVER_ROWS=1
1025  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1026  & interface_column_to_solver_rows_maps(local_column)%SOLVER_ROW=number_of_local_solver_rows
1027  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1028  & interface_column_to_solver_rows_maps(local_column)%COUPLING_COEFFICIENT=1.0_dp
1029  SELECT CASE(interface_condition%METHOD)
1031  !Set up the solver row <-> interface row mappings
1032  !Penalty matrix is the last interface matrix
1033  interface_matrix_idx=interface_mapping%NUMBER_OF_INTERFACE_MATRICES
1034  !Set the mappings
1035  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1036  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
1037  & local_column)%NUMBER_OF_SOLVER_ROWS=1
1038  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1039  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
1040  & local_column)%SOLVER_ROW=number_of_local_solver_rows
1041  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1042  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
1043  & local_column)%COUPLING_COEFFICIENT=1.0_dp
1044  ENDSELECT
1045  ENDIF !rank==my rank
1046  ELSE IF(constrained_dof) THEN
1047  CALL flagerror("Constrained DOFs have not been implemented for Lagrange variables.",err,error,*999)
1048  ELSE
1049  !Set the interface column/row -> solver row mappings
1050  IF(rank==myrank) THEN
1051  !Set up the solver row <-> interface column mappings
1052  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1053  & interface_column_to_solver_rows_maps(local_column)%NUMBER_OF_SOLVER_ROWS=0
1054  SELECT CASE(interface_condition%METHOD)
1056  !Set up the solver row <-> interface row mappings
1057  !Penalty matrix is the last interface matrix
1058  interface_matrix_idx=interface_mapping%NUMBER_OF_INTERFACE_MATRICES
1059  !Set the mappings
1060  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1061  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP( &
1062  & local_column)%NUMBER_OF_SOLVER_ROWS=0
1063  ENDSELECT
1064  ENDIF
1065  ENDIF
1066  ENDDO !global_row_idx
1067  IF(ALLOCATED(rank_global_rows_list)) DEALLOCATE(rank_global_rows_list)
1068  ENDDO !interface_condition_idx
1069  ENDDO !rank
1070  CALL solverdofcouplings_finalise(rowcouplings,err,error,*999)
1071 
1072  CALL domain_mappings_local_from_global_calculate(row_domain_mapping,err,error,*999)
1073  !
1074  !--- Column mappings ---
1075  !
1076  ! 4. Calculate the number of local and global columns in the solver matrix. Do this by calculating the list of columns
1077  ! for each rank so that we can determine the column numbers in rank order.
1078  !
1079  !Allocate solver column to equations sets mapping array
1080  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
1081  IF(err/=0) CALL flagerror("Could not allocate solver mapping solver column to equations column maps.",err,error,*999)
1082  ALLOCATE(solver_mapping%VARIABLES_LIST(solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
1083  IF(err/=0) CALL flagerror("Could not allocate solver mapping variables list.",err,error,*999)
1084  CALL solverdofcouplings_initialise(columncouplings,err,error,*999)
1085 
1086  !Calculate the column mappings for each solver matrix
1087  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
1088 
1089  !Initialise the variables list
1090  CALL solver_mapping_variables_initialise(solver_mapping%VARIABLES_LIST(solver_matrix_idx),err,error,*999)
1091  !
1092  ! 4a Calculate the list of field variables involved in the columns of the solver matrix
1093  !
1094  !Compute the order of variables for the solver matrices
1095  CALL list_detach_and_destroy(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
1096  & number_of_equations_variables,equations_variables,err,error,*999)
1097  CALL list_detach_and_destroy(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
1098  & number_of_interface_variables,interface_variables,err,error,*999)
1099  ALLOCATE(solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(number_of_equations_variables+ &
1100  & number_of_interface_variables),stat=err)
1101  IF(err/=0) CALL flagerror("Could not allocate variables list variables.",err,error,*999)
1102  solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES=number_of_equations_variables+ &
1103  & number_of_interface_variables
1104  ALLOCATE(variables_list(number_of_equations_variables+number_of_interface_variables),stat=err)
1105  IF(err/=0) CALL flagerror("Could not allocate variables list.",err,error,*999)
1106  ALLOCATE(variable_processed(number_of_equations_variables+number_of_interface_variables),stat=err)
1107  IF(err/=0) CALL flagerror("Could not allocate variable processed.",err,error,*999)
1108  variable_processed=.false.
1109  solver_variable_idx=0
1110  DO variable_idx=1,number_of_equations_variables
1111  solver_variable_idx=solver_variable_idx+1
1112  CALL solver_mapping_variable_initialise(solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
1113  & variables(solver_variable_idx),err,error,*999)
1114  equations_set_idx=equations_variables(1,variable_idx)
1115  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
1116  IF(ASSOCIATED(equations_set)) THEN
1117  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
1118  IF(ASSOCIATED(dependent_field)) THEN
1119  variable_type=equations_variables(2,variable_idx)
1120  variable=>dependent_field%VARIABLE_TYPE_MAP(variable_type)%PTR
1121  IF(ASSOCIATED(variable)) THEN
1122  solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE=> &
1123  & variable
1124  solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE_TYPE= &
1125  & variable_type
1126  NULLIFY(variables_list(solver_variable_idx)%PTR)
1127  CALL list_create_start(variables_list(solver_variable_idx)%PTR,err,error,*999)
1128  CALL list_data_type_set(variables_list(solver_variable_idx)%PTR,list_intg_type,err,error,*999)
1129  CALL list_data_dimension_set(variables_list(solver_variable_idx)%PTR,3,err,error,*999)
1130  CALL list_key_dimension_set(variables_list(solver_variable_idx)%PTR,1,err,error,*999)
1131  CALL list_create_finish(variables_list(solver_variable_idx)%PTR,err,error,*999)
1132  ELSE
1133  CALL flagerror("Dependent field variable is not associated.",err,error,*999)
1134  ENDIF
1135  ELSE
1136  CALL flagerror("Equations set dependent field is not associated.",err,error,*999)
1137  ENDIF
1138  ELSE
1139  CALL flagerror("Equations set is not associated.",err,error,*999)
1140  ENDIF
1141  ENDDO !variable_idx
1142  IF(ALLOCATED(equations_variables)) DEALLOCATE(equations_variables)
1143  DO variable_idx=1,number_of_interface_variables
1144  solver_variable_idx=solver_variable_idx+1
1145  CALL solver_mapping_variable_initialise(solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
1146  & variables(solver_variable_idx),err,error,*999)
1147  interface_condition_idx=interface_variables(1,variable_idx)
1148  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
1149  IF(ASSOCIATED(interface_condition)) THEN
1150  IF(ASSOCIATED(interface_condition%LAGRANGE)) THEN
1151  lagrange_field=>interface_condition%LAGRANGE%LAGRANGE_FIELD
1152  IF(ASSOCIATED(lagrange_field)) THEN
1153  variable_type=interface_variables(2,variable_idx)
1154  variable=>lagrange_field%VARIABLE_TYPE_MAP(variable_type)%PTR
1155  IF(ASSOCIATED(variable)) THEN
1156  solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE=> &
1157  & variable
1158  solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE_TYPE= &
1159  & variable_type
1160  NULLIFY(variables_list(solver_variable_idx)%PTR)
1161  CALL list_create_start(variables_list(solver_variable_idx)%PTR,err,error,*999)
1162  CALL list_data_type_set(variables_list(solver_variable_idx)%PTR,list_intg_type,err,error,*999)
1163  CALL list_data_dimension_set(variables_list(solver_variable_idx)%PTR,3,err,error,*999)
1164  CALL list_key_dimension_set(variables_list(solver_variable_idx)%PTR,1,err,error,*999)
1165  CALL list_create_finish(variables_list(solver_variable_idx)%PTR,err,error,*999)
1166  ELSE
1167  CALL flagerror("Lagrange field variable is not associated.",err,error,*999)
1168  ENDIF
1169  ELSE
1170  CALL flagerror("Interface condition Lagrange field is not associated.",err,error,*999)
1171  ENDIF
1172  ELSE
1173  CALL flagerror("Interface condition Lagrange is not associated.",err,error,*999)
1174  ENDIF
1175  ELSE
1176  CALL flagerror("Interface condition is not associated.",err,error,*999)
1177  ENDIF
1178  ENDDO !variable_idx
1179  IF(ALLOCATED(interface_variables)) DEALLOCATE(interface_variables)
1180 
1181  !Initialise solver column to equations sets mapping array
1182  CALL solvermapping_solcoltoequationsmapsinitialise(solver_mapping% &
1183  & solver_col_to_equations_cols_map(solver_matrix_idx),err,error,*999)
1184  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_MATRIX_NUMBER=solver_matrix_idx
1185  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_MAPPING=>solver_mapping
1186  !Allocate the solver col to equations set maps array
1187  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1188  & solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
1189  IF(err/=0) CALL flagerror("Could not allocate solver col to equations map solver col to equation set maps.", &
1190  & err,error,*999)
1191  !Allocate the solver col to interface maps array
1192  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_INTERFACE_MAPS( &
1193  & solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS),stat=err)
1194  IF(err/=0) CALL flagerror("Could not allocate solver col to equations map solver col to interface maps.", &
1195  & err,error,*999)
1196  !Presort the column numbers by rank.
1197  !RANK_GLOBAL_COLS_LISTS(dof_type, equations_idx, variable_idx, rank_idx)
1198  !dof_type is 1 for domain local DOFs and 2 for ghost DOFs
1199  ALLOCATE(rank_global_cols_lists(2,solver_mapping%NUMBER_OF_EQUATIONS_SETS+solver_mapping% &
1200  & number_of_interface_conditions,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES, &
1201  & 0:computational_environment%NUMBER_COMPUTATIONAL_NODES-1),stat=err)
1202  IF(err/=0) CALL flagerror("Could not allocate rank global columns lists.",err,error,*999)
1203  DO rank=0,computational_environment%NUMBER_COMPUTATIONAL_NODES-1
1204  DO solver_variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
1205  DO equations_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS+solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
1206  DO dof_type=1,2
1207  NULLIFY(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR)
1208  CALL list_create_start(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR, &
1209  & err,error,*999)
1210  CALL list_data_type_set(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR, &
1211  & list_intg_type,err,error,*999)
1212  !Set approximate size for the number of columns per variable.
1213  CALL list_initial_size_set(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR, &
1214  & solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE% &
1215  & total_number_of_dofs,err,error,*999)
1216  CALL list_data_dimension_set(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR,5, &
1217  & err,error,*999)
1218  CALL list_key_dimension_set(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR,1, &
1219  & err,error,*999)
1220  CALL list_create_finish(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR, &
1221  & err,error,*999)
1222  ENDDO !dof_type
1223  ENDDO !equations_idx
1224  ENDDO !solver_variable_set_idx
1225  ENDDO !rank
1226 
1227  !Allocate sub-matrix information
1228  !SUB_MATRIX_INFORMATION(1,equations_idx,variable_idx) = The equations type, see SOLVER_MAPPING_EquationsTypes
1229  !SUB_MATRIX_INFORMATION(2,equations_idx,variable_idx) = The equations set or interface condition index
1230  !SUB_MATRIX_INFORMATION(3,equations_idx,variable_idx) = The interface matrix index, or 0 for an equations set matrix
1231  !equations_idx goes from 1 to the number of equations sets + interface conditions
1232  !variable_idx goes from 1 to the number of variables mapped to this solver matrix
1233  ALLOCATE(sub_matrix_information(3,solver_mapping%NUMBER_OF_EQUATIONS_SETS+ &
1234  & solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS,solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
1235  & number_of_variables),stat=err)
1236  IF(err/=0) CALL flagerror("Could not allocate sub matrix information.",err,error,*999)
1237  sub_matrix_information=0
1238  !Allocate sub-matrix list information
1239  ALLOCATE(sub_matrix_list(0:3,solver_mapping%NUMBER_OF_EQUATIONS_SETS+ &
1240  & solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS,solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
1241  & number_of_variables),stat=err)
1242  IF(err/=0) CALL flagerror("Could not allocate sub matrix list.",err,error,*999)
1243  sub_matrix_list=0
1244 
1245  !
1246  ! 4b Calculate the number of columns
1247  !
1248 
1249  !Calculate the number of solver dofs
1250  ALLOCATE(number_of_variable_global_solver_dofs(solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES), &
1251  & stat=err)
1252  IF(err/=0) CALL flagerror("Could not allocate number of global solver dofs.",err,error,*999)
1253  ALLOCATE(number_of_variable_local_solver_dofs(solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES), &
1254  & stat=err)
1255  IF(err/=0) CALL flagerror("Could not allocate number of local solver dofs.",err,error,*999)
1256  ALLOCATE(total_number_of_variable_local_solver_dofs(solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
1257  & number_of_variables),stat=err)
1258  IF(err/=0) CALL flagerror("Could not allocate total number of local solver dofs.",err,error,*999)
1259 
1260  number_of_variable_global_solver_dofs=0
1261  number_of_variable_local_solver_dofs=0
1262  total_number_of_variable_local_solver_dofs=0
1263 
1264  equations_idx=0
1265  !Loop over the equations sets
1266  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
1267  equations_idx=equations_idx+1
1268  !The pointers below have been checked for association above.
1269  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
1270  equations=>equations_set%EQUATIONS
1271  equations_mapping=>equations%EQUATIONS_MAPPING
1272  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
1273  linear_mapping=>equations_mapping%LINEAR_MAPPING
1274  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
1275  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
1276  NULLIFY(equations_set_variable_list)
1277  CALL list_create_start(equations_set_variable_list,err,error,*999)
1278  CALL list_data_type_set(equations_set_variable_list,list_intg_type,err,error,*999)
1279  CALL list_data_dimension_set(equations_set_variable_list,3,err,error,*999)
1280  CALL list_key_dimension_set(equations_set_variable_list,1,err,error,*999)
1281  CALL list_create_finish(equations_set_variable_list,err,error,*999)
1282  IF(ASSOCIATED(dynamic_mapping)) THEN
1283  equations_variable_list_item(1)=solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(equations_set_idx)
1284  equations_variable_list_item(2)=solver_mapping_equations_dynamic_matrix
1285  equations_variable_list_item(3)=0
1286  CALL list_item_add(equations_set_variable_list,equations_variable_list_item,err,error,*999)
1287  ENDIF
1288  IF(ASSOCIATED(linear_mapping)) THEN
1289  DO variable_idx=1,solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0,equations_set_idx,solver_matrix_idx)
1290  equations_variable_list_item(1)=solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES( &
1291  & variable_idx,equations_set_idx,solver_matrix_idx)
1292  equations_variable_list_item(2)=solver_mapping_equations_linear_matrix
1293  equations_variable_list_item(3)=variable_idx
1294  CALL list_item_add(equations_set_variable_list,equations_variable_list_item,err,error,*999)
1295  ENDDO
1296  ENDIF
1297  IF(ASSOCIATED(nonlinear_mapping)) THEN
1298  DO variable_idx=1,solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(0,equations_set_idx)
1299  equations_variable_list_item(1)=solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES( &
1300  & variable_idx,equations_set_idx)
1301  equations_variable_list_item(2)=solver_mapping_equations_nonlinear_matrix
1302  equations_variable_list_item(3)=variable_idx
1303  CALL list_item_add(equations_set_variable_list,equations_variable_list_item,err,error,*999)
1304  ENDDO
1305  ENDIF
1306  CALL list_remove_duplicates(equations_set_variable_list,err,error,*999)
1307  CALL list_detach_and_destroy(equations_set_variable_list,number_of_variables,equations_set_variables,err,error,*999)
1308  !Initialise equations set to solver map (sm)
1309  CALL solvermapping_equatstosolmatmapssminitialise(solver_mapping% &
1310  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx), &
1311  & err,error,*999)
1312  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1313  & solver_matrix_idx)%SOLVER_MATRIX_NUMBER=solver_matrix_idx
1314  !Allocate the equations set to solver map variables arrays
1315  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1316  & solver_matrix_idx)%VARIABLE_TYPES(number_of_variables),stat=err)
1317  IF(err/=0) &
1318  & CALL flagerror("Could not allocate equations to solver matrix maps sm variable types.",err,error,*999)
1319  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1320  & solver_matrix_idx)%VARIABLES(number_of_variables),stat=err)
1321  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps sm variables.",err,error,*999)
1322  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1323  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(number_of_variables),stat=err)
1324  IF(err/=0) &
1325  & CALL flagerror("Could not allocate equations to solver matrix maps sm variables to solver col maps.", &
1326  & err,error,*999)
1327  !Setup
1328  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1329  & solver_matrix_idx)%NUMBER_OF_VARIABLES=number_of_variables
1330  number_of_dynamic_equations_matrices=0
1331  number_of_linear_equations_matrices=0
1332  !Loop over the variables in this equations set.
1333  DO variable_idx=1,number_of_variables
1334  variable_type=equations_set_variables(1,variable_idx)
1335  matrices_type=equations_set_variables(2,variable_idx)
1336  matrix_variable_idx=equations_set_variables(3,variable_idx)
1337  dependent_variable=>dependent_field%VARIABLE_TYPE_MAP(variable_type)%PTR
1338  IF(ASSOCIATED(dependent_variable)) THEN
1339  !Find the variable in the list of solver variables
1340  found=.false.
1341  DO variable_position_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
1342  IF(ASSOCIATED(dependent_variable,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
1343  & variable_position_idx)%VARIABLE)) THEN
1344  found=.true.
1345  EXIT
1346  ENDIF
1347  ENDDO !variable_position_idx
1348  IF(found) THEN
1349  !Add the equations set variable to the list of equations involving the solver variable
1350  variable_list_item(1)=equations_set_idx
1351  variable_list_item(2)=variable_type
1352  variable_list_item(3)=solver_mapping_equations_equations_set
1353  CALL list_item_add(variables_list(variable_position_idx)%PTR,variable_list_item,err,error,*999)
1354  col_dofs_mapping=>dependent_variable%DOMAIN_MAPPING
1355  IF(ASSOCIATED(col_dofs_mapping)) THEN
1356  CALL boundary_conditions_variable_get(boundary_conditions,dependent_variable,boundary_conditions_variable, &
1357  & err,error,*999)
1358  IF(ASSOCIATED(boundary_conditions_variable)) THEN
1359  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1360  & solver_matrix_idx)%VARIABLE_TYPES(variable_idx)=variable_type
1361  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1362  & solver_matrix_idx)%VARIABLES(variable_idx)%PTR=>dependent_variable
1363  !Allocate the variable to solver col maps arrays
1364  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
1365  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)% &
1366  & column_numbers(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1367  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps column numbers.", &
1368  & err,error,*999)
1369  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
1370  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)% &
1371  & coupling_coefficients(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1372  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps coupling coefficients.", &
1373  & err,error,*999)
1374  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
1375  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)% &
1376  & additive_constants(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1377  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps additive constants.", &
1378  & err,error,*999)
1379  !Setup
1380  !Set the sub-matrix information
1381  sub_matrix_information(1,equations_idx,variable_position_idx)=solver_mapping_equations_equations_set
1382  sub_matrix_information(2,equations_idx,variable_position_idx)=equations_set_idx
1383  !Set the sub-matrix lists
1384  IF(ASSOCIATED(dynamic_mapping)) THEN
1385  number_of_dynamic_equations_matrices=number_of_dynamic_equations_matrices+ &
1386  & dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)%NUMBER_OF_EQUATIONS_MATRICES
1387  IF(dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)%NUMBER_OF_EQUATIONS_MATRICES>0) THEN
1388  sub_matrix_list(0,equations_idx,variable_position_idx)= &
1389  sub_matrix_list(0,equations_idx,variable_position_idx)+1
1390  sub_matrix_list(sub_matrix_list(0,equations_idx,variable_position_idx), &
1391  & equations_idx,variable_position_idx)=solver_mapping_equations_dynamic_matrix
1392  ENDIF
1393  ENDIF
1394  IF(ASSOCIATED(linear_mapping)) THEN
1395  number_of_linear_equations_matrices=number_of_linear_equations_matrices+ &
1396  & linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)%NUMBER_OF_EQUATIONS_MATRICES
1397  IF(linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)%NUMBER_OF_EQUATIONS_MATRICES>0) THEN
1398  sub_matrix_list(0,equations_idx,variable_position_idx)= &
1399  sub_matrix_list(0,equations_idx,variable_position_idx)+1
1400  sub_matrix_list(sub_matrix_list(0,equations_idx,variable_position_idx), &
1401  & equations_idx,variable_position_idx)=solver_mapping_equations_linear_matrix
1402  ENDIF
1403  ENDIF
1404  IF(ASSOCIATED(nonlinear_mapping)) THEN
1405  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
1406  IF(nonlinear_mapping%VAR_TO_JACOBIAN_MAP(equations_matrix_idx)%VARIABLE_TYPE==variable_type) THEN
1407  sub_matrix_list(0,equations_idx,variable_position_idx)= &
1408  sub_matrix_list(0,equations_idx,variable_position_idx)+1
1409  sub_matrix_list(sub_matrix_list(0,equations_idx,variable_position_idx), &
1410  & equations_idx,variable_position_idx)=solver_mapping_equations_nonlinear_matrix
1411  ENDIF
1412  ENDDO
1413  ENDIF
1414  !Loop over the global dofs for this variable.
1415  DO global_dof=1,dependent_variable%NUMBER_OF_GLOBAL_DOFS
1416  DO rank_idx=1,col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%NUMBER_OF_DOMAINS
1417  local_dof=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_NUMBER(rank_idx)
1418  dof_type=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_TYPE(rank_idx)
1419  column_rank=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%DOMAIN_NUMBER(rank_idx)
1420  include_column=boundary_conditions_variable%DOF_TYPES(global_dof)==boundary_condition_dof_free
1421  constrained_dof=boundary_conditions_variable%DOF_TYPES(global_dof)==boundary_condition_dof_constrained
1422  globaldofcouplingnumber=0
1423  IF(ASSOCIATED(boundary_conditions_variable%dofConstraints)) THEN
1424  dofconstraints=>boundary_conditions_variable%dofConstraints
1425  IF(dofconstraints%numberOfConstraints>0) THEN
1426  IF(ALLOCATED(dofconstraints%dofCouplings)) THEN
1427  IF(ASSOCIATED(dofconstraints%dofCouplings(global_dof)%ptr)) THEN
1428  CALL solverdofcouplings_addcoupling(columncouplings, &
1429  & dofconstraints%dofCouplings(global_dof)%ptr, &
1430  & globaldofcouplingnumber,err,error,*999)
1431  END IF
1432  ELSE
1433  CALL flagerror("DOF constraints DOF couplings are not allocated.",err,error,*999)
1434  END IF
1435  END IF
1436  END IF
1437  column_list_item(1)=global_dof
1438  column_list_item(2)=local_dof
1439  column_list_item(5)=globaldofcouplingnumber
1440  IF(dof_type/=domain_local_ghost) THEN
1441  !DOF is not a ghost dof
1442  IF(include_column) THEN
1443  column_list_item(3)=1
1444  IF(.NOT.variable_processed(variable_position_idx)) THEN
1445  number_of_variable_global_solver_dofs(variable_position_idx)= &
1446  & number_of_variable_global_solver_dofs(variable_position_idx)+1
1447  IF(column_rank==myrank) THEN
1448  number_of_variable_local_solver_dofs(variable_position_idx)= &
1449  & number_of_variable_local_solver_dofs(variable_position_idx)+1
1450  total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1451  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1452  ENDIF
1453  ENDIF
1454  ELSE IF(constrained_dof) THEN
1455  column_list_item(3)=2
1456  ELSE
1457  column_list_item(3)=0
1458  ENDIF
1459  column_list_item(4)=variable_idx
1460  CALL list_item_add(rank_global_cols_lists(1,equations_idx,variable_position_idx,column_rank)%PTR, &
1461  & column_list_item,err,error,*999)
1462  ELSE
1463  !DOF is a ghost dof
1464  IF(include_column) THEN
1465  column_list_item(3)=1
1466  IF(.NOT.variable_processed(variable_position_idx)) THEN
1467  IF(column_rank==myrank) total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1468  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1469  ENDIF
1470  ELSE IF(constrained_dof) THEN
1471  column_list_item(3)=2
1472  ELSE
1473  column_list_item(3)=0
1474  ENDIF
1475  column_list_item(4)=variable_idx
1476  CALL list_item_add(rank_global_cols_lists(2,equations_idx,variable_position_idx,column_rank)%PTR, &
1477  & column_list_item,err,error,*999)
1478  ENDIF
1479  ENDDO !rank_idx
1480  ENDDO !global_dof
1481  ELSE
1482  CALL flagerror("Boundary condition variable not associated.",err,error,*999)
1483  ENDIF
1484  ELSE
1485  CALL flagerror("Equations matrix columns degree of freedom mapping is not associated.",err,error,*999)
1486  ENDIF
1487  variable_processed(variable_position_idx)=.true.
1488  ELSE
1489  CALL flagerror("Dependent variable does not exist in the list of solver variables.",err,error,*999)
1490  ENDIF
1491  ELSE
1492  CALL flagerror("Dependent variable is not associated.",err,error,*999)
1493  ENDIF
1494  ENDDO !variable_idx
1495  IF(ALLOCATED(equations_set_variables)) DEALLOCATE(equations_set_variables)
1496  ENDDO !equations_set_idx
1497  !Calculate the number of columns for the interface conditions
1498  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
1499  equations_idx=equations_idx+1
1500  !The pointers below have been checked for association above.
1501  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
1502  SELECT CASE(interface_condition%METHOD)
1504  interface_equations=>interface_condition%INTERFACE_EQUATIONS
1505  interface_mapping=>interface_equations%INTERFACE_MAPPING
1506  interface_dependent=>interface_condition%DEPENDENT
1507  !Initialise interface condition to solver map (sm)
1508  CALL solvermapping_interftosolmatmapssminitialise(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
1509  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx), &
1510  & err,error,*999)
1511  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
1512  & solver_matrix_idx)%SOLVER_MATRIX_NUMBER=solver_matrix_idx
1513  !Allocate the interface to solver map variables arrays
1514  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1515  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TYPES( &
1516  & interface_mapping%NUMBER_OF_INTERFACE_MATRICES),stat=err)
1517  IF(err/=0) &
1518  & CALL flagerror("Could not allocate interface to solver matrix maps sm dependent variable types.", &
1519  & err,error,*999)
1520  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1521  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLES(interface_mapping% &
1522  & number_of_interface_matrices),stat=err)
1523  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps sm variables.",err,error,*999)
1524  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1525  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
1526  & interface_mapping%NUMBER_OF_INTERFACE_MATRICES),stat=err)
1527  IF(err/=0) CALL flagerror("Could not allocate interface to solver matrix maps sm dependent variables "// &
1528  & "to solver col maps.",err,error,*999)
1529  !First add in the Lagrange to solver variables
1530  lagrange_field=>interface_condition%LAGRANGE%LAGRANGE_FIELD
1531  !\todo Lagrange variable type set to the first variable type for now
1532  variable_type=1
1533  lagrange_variable=>lagrange_field%VARIABLE_TYPE_MAP(variable_type)%PTR
1534  IF(ASSOCIATED(lagrange_variable)) THEN
1535  !Find the variable in the list of solver variables
1536  found=.false.
1537  DO variable_position_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
1538  IF(ASSOCIATED(lagrange_variable,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
1539  & variable_position_idx)%VARIABLE)) THEN
1540  found=.true.
1541  EXIT
1542  ENDIF
1543  ENDDO !variable_position_idx
1544  IF(found) THEN
1545  !Add the interface condition variable to the list of equations involving the solver variable
1546  variable_list_item(1)=interface_condition_idx
1547  variable_list_item(2)=variable_type
1548  variable_list_item(3)=solver_mapping_equations_interface_condition
1549  CALL list_item_add(variables_list(variable_position_idx)%PTR,variable_list_item,err,error,*999)
1550  col_dofs_mapping=>lagrange_variable%DOMAIN_MAPPING
1551  IF(ASSOCIATED(col_dofs_mapping)) THEN
1552  CALL boundary_conditions_variable_get(boundary_conditions,lagrange_variable,boundary_conditions_variable, &
1553  & err,error,*999)
1554  IF(ASSOCIATED(boundary_conditions_variable)) THEN
1555  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1556  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TYPE=variable_type
1557  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1558  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE=>lagrange_variable
1559  !Allocate the variable to solver col maps arrays
1560  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1561  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
1562  & column_numbers(lagrange_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1563  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps column numbers.", &
1564  & err,error,*999)
1565  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1566  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
1567  & coupling_coefficients(lagrange_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1568  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps coupling coefficients.", &
1569  & err,error,*999)
1570  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1571  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
1572  & additive_constants(lagrange_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1573  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps additive constants.", &
1574  & err,error,*999)
1575  DO equations_idx2=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1576  & number_of_equations_sets
1577  equations_set_idx=solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1578  & interface_to_solver_matrix_maps_equations(equations_idx2)%EQUATIONS_SET_INDEX
1579  interface_matrix_idx=solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1580  & interface_to_solver_matrix_maps_equations(equations_idx2)%INTERFACE_MATRIX_INDEX
1581  !Set the sub-matrix information
1582  sub_matrix_information(1,equations_set_idx,variable_position_idx)= &
1584  sub_matrix_information(2,equations_set_idx,variable_position_idx)=interface_condition_idx
1585  sub_matrix_information(3,equations_set_idx,variable_position_idx)=interface_matrix_idx
1586  !Loop over the global dofs for this variable.
1587  DO global_dof=1,lagrange_variable%NUMBER_OF_GLOBAL_DOFS
1588  DO rank_idx=1,col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%NUMBER_OF_DOMAINS
1589  local_dof=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_NUMBER(rank_idx)
1590  dof_type=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_TYPE(rank_idx)
1591  column_rank=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%DOMAIN_NUMBER(rank_idx)
1592  include_column=boundary_conditions_variable%DOF_TYPES(global_dof)==boundary_condition_dof_free
1593  column_list_item(1)=global_dof
1594  column_list_item(2)=local_dof
1595  IF(dof_type/=domain_local_ghost) THEN
1596  !DOF is not a ghost dof
1597  IF(include_column) THEN
1598  column_list_item(3)=1
1599  IF(.NOT.variable_processed(variable_position_idx)) THEN
1600  number_of_variable_global_solver_dofs(variable_position_idx)= &
1601  & number_of_variable_global_solver_dofs(variable_position_idx)+1
1602  IF(column_rank==myrank) THEN
1603  number_of_variable_local_solver_dofs(variable_position_idx)= &
1604  & number_of_variable_local_solver_dofs(variable_position_idx)+1
1605  total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1606  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1607  ENDIF
1608  ENDIF
1609  ELSE
1610  column_list_item(3)=0
1611  ENDIF
1612  column_list_item(4)=variable_idx
1613  CALL list_item_add(rank_global_cols_lists(1,equations_set_idx,variable_position_idx, &
1614  & column_rank)%PTR,column_list_item,err,error,*999)
1615  ELSE
1616  !DOF is a ghost dof
1617  IF(include_column) THEN
1618  column_list_item(3)=1
1619  IF(.NOT.variable_processed(variable_position_idx)) THEN
1620  IF(column_rank==myrank) total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1621  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1622  ENDIF
1623  ELSE
1624  column_list_item(3)=0
1625  ENDIF
1626  column_list_item(4)=variable_idx
1627  CALL list_item_add(rank_global_cols_lists(2,equations_set_idx,variable_position_idx, &
1628  & column_rank)%PTR,column_list_item,err,error,*999)
1629  ENDIF
1630  ENDDO !rank_idx
1631  ENDDO !global_dof
1632  variable_processed(variable_position_idx)=.true.
1633  ENDDO !equations_idx2
1634  ELSE
1635  CALL flagerror("Boundary condition variable not associated.",err,error,*999)
1636  ENDIF
1637  ELSE
1638  CALL flagerror("Columns degree of freedom mapping is not associated.",err,error,*999)
1639  ENDIF
1640  ELSE
1641  CALL flagerror("Lagrange variable does not exist in the list of solver variables.",err,error,*999)
1642  ENDIF
1643  ELSE
1644  CALL flagerror("Lagrange variable is not associated.",err,error,*999)
1645  ENDIF
1646  !Now add in the Dependent variables
1647  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
1648  & solver_matrix_idx)%NUMBER_OF_DEPENDENT_VARIABLES=interface_mapping%NUMBER_OF_INTERFACE_MATRICES
1649  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
1650  dependent_variable=>interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%VARIABLE
1651  IF(ASSOCIATED(dependent_variable)) THEN
1652  variable_type=dependent_variable%VARIABLE_TYPE
1653  !Find the variable in the list of solver variables
1654  found=.false.
1655  DO variable_position_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
1656  IF(ASSOCIATED(dependent_variable,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
1657  & variable_position_idx)%VARIABLE)) THEN
1658  found=.true.
1659  EXIT
1660  ENDIF
1661  ENDDO !variable_position_idx
1662  IF(found) THEN
1663  equations_set=>interface_dependent%EQUATIONS_SETS(interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS( &
1664  & interface_matrix_idx)%MESH_INDEX)%PTR
1665  !Note that EQUATIONS_SET and INTERFACE_EQUATIONS has already been checked for association above and this check is just to see if either an equation set or interface equations are present.
1666  IF(ASSOCIATED(equations_set).OR.ASSOCIATED(interface_equations)) THEN
1667  col_dofs_mapping=>dependent_variable%DOMAIN_MAPPING
1668  IF(ASSOCIATED(col_dofs_mapping)) THEN
1669  CALL boundary_conditions_variable_get(boundary_conditions,dependent_variable, &
1670  & boundary_conditions_variable,err,error,*999)
1671  IF(ASSOCIATED(boundary_conditions_variable)) THEN
1672  !Setup
1673  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1674  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TYPES( &
1675  & interface_matrix_idx)=variable_type
1676  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1677  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLES(interface_matrix_idx)% &
1678  & ptr=>dependent_variable
1679  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1680  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
1681  & interface_matrix_idx)%COLUMN_NUMBERS(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1682  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps column numbers.", &
1683  & err,error,*999)
1684  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1685  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
1686  & interface_matrix_idx)%COUPLING_COEFFICIENTS(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1687  IF(err/=0) &
1688  & CALL flagerror("Could not allocate variables to solver column maps coupling coefficients.", &
1689  & err,error,*999)
1690  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
1691  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
1692  & interface_matrix_idx)%ADDITIVE_CONSTANTS(dependent_variable%TOTAL_NUMBER_OF_DOFS),stat=err)
1693  IF(err/=0) CALL flagerror("Could not allocate variables to solver column maps additive constants.", &
1694  & err,error,*999)
1695  !Set the sub-matrix information
1696  sub_matrix_information(1,equations_idx,variable_position_idx)= &
1698  sub_matrix_information(2,equations_idx,variable_position_idx)=interface_condition_idx
1699  sub_matrix_information(3,equations_idx,variable_position_idx)=interface_matrix_idx
1700  !Loop over the global dofs for this variable.
1701  DO global_dof=1,dependent_variable%NUMBER_OF_GLOBAL_DOFS
1702  DO rank_idx=1,col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%NUMBER_OF_DOMAINS
1703  local_dof=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_NUMBER(rank_idx)
1704  dof_type=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%LOCAL_TYPE(rank_idx)
1705  column_rank=col_dofs_mapping%GLOBAL_TO_LOCAL_MAP(global_dof)%DOMAIN_NUMBER(rank_idx)
1706  include_column=boundary_conditions_variable%DOF_TYPES(global_dof)==boundary_condition_dof_free
1707  constrained_dof=boundary_conditions_variable%DOF_TYPES(global_dof)== &
1709  globaldofcouplingnumber=0
1710  IF(ASSOCIATED(boundary_conditions_variable%dofConstraints)) THEN
1711  dofconstraints=>boundary_conditions_variable%dofConstraints
1712  IF(dofconstraints%numberOfConstraints>0) THEN
1713  IF(ALLOCATED(dofconstraints%dofCouplings)) THEN
1714  IF(ASSOCIATED(dofconstraints%dofCouplings(global_dof)%ptr)) THEN
1715  CALL solverdofcouplings_addcoupling(columncouplings, &
1716  & dofconstraints%dofCouplings(global_dof)%ptr, &
1717  & globaldofcouplingnumber,err,error,*999)
1718  END IF
1719  ELSE
1720  CALL flagerror("DOF constraints DOF couplings are not allocated.",err,error,*999)
1721  END IF
1722  END IF
1723  END IF
1724  column_list_item(1)=global_dof
1725  column_list_item(2)=local_dof
1726  column_list_item(5)=globaldofcouplingnumber
1727  IF(dof_type/=domain_local_ghost) THEN
1728  !DOF is not a ghost dof
1729  IF(include_column) THEN
1730  column_list_item(3)=1
1731  IF(.NOT.variable_processed(variable_position_idx)) THEN
1732  number_of_variable_global_solver_dofs(variable_position_idx)= &
1733  & number_of_variable_global_solver_dofs(variable_position_idx)+1
1734  IF(column_rank==myrank) THEN
1735  number_of_variable_local_solver_dofs(variable_position_idx)= &
1736  & number_of_variable_local_solver_dofs(variable_position_idx)+1
1737  total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1738  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1739  ENDIF
1740  ENDIF
1741  ELSE IF(constrained_dof) THEN
1742  column_list_item(3)=2
1743  ELSE
1744  column_list_item(3)=0
1745  ENDIF
1746  column_list_item(4)=variable_idx
1747  CALL list_item_add(rank_global_cols_lists(1,equations_idx,variable_position_idx, &
1748  & column_rank)%PTR,column_list_item,err,error,*999)
1749  ELSE
1750  !DOF is a ghost dof
1751  IF(include_column) THEN
1752  column_list_item(3)=1
1753  IF(.NOT.variable_processed(variable_position_idx)) THEN
1754  IF(column_rank==myrank) total_number_of_variable_local_solver_dofs(variable_position_idx)= &
1755  & total_number_of_variable_local_solver_dofs(variable_position_idx)+1
1756  ENDIF
1757  ELSE IF(constrained_dof) THEN
1758  column_list_item(3)=2
1759  ELSE
1760  column_list_item(3)=0
1761  ENDIF
1762  column_list_item(4)=variable_idx
1763  CALL list_item_add(rank_global_cols_lists(2,equations_idx,variable_position_idx, &
1764  & column_rank)%PTR,column_list_item,err,error,*999)
1765  ENDIF
1766  ENDDO !rank_idx
1767  ENDDO !global_dof
1768  ELSE
1769  CALL flagerror("Boundary condition variable not associated.",err,error,*999)
1770  ENDIF
1771  ELSE
1772  CALL flagerror("Interface matrix columns degree of freedom mapping is not associated.",err,error,*999)
1773  ENDIF
1774  ELSE
1775  CALL flagerror("Interface dependent equations set is not associated.",err,error,*999)
1776  ENDIF
1777  variable_processed(variable_position_idx)=.true.
1778  ELSE
1779  CALL flagerror("Dependent variable does not exist in the list of solver variables.",err,error,*999)
1780  ENDIF
1781  ELSE
1782  CALL flagerror("Dependent variable is not associated.",err,error,*999)
1783  ENDIF
1784  ENDDO !matrix_idx
1786  CALL flagerror("Not implemented.",err,error,*999)
1788  CALL flagerror("Not implemented.",err,error,*999)
1789  CASE DEFAULT
1790  local_error="The interface condition method of "// &
1791  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))// &
1792  & " is invalid."
1793  CALL flagerror(local_error,err,error,*999)
1794  END SELECT
1795  ENDDO !interface_idx
1796 
1797  IF(ALLOCATED(variable_processed)) DEALLOCATE(variable_processed)
1798 
1799  number_of_local_solver_dofs=0
1800  total_number_of_local_solver_dofs=0
1801  number_of_global_solver_dofs=0
1802  DO solver_variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
1803  number_of_local_solver_dofs=number_of_local_solver_dofs+number_of_variable_local_solver_dofs(solver_variable_idx)
1804  total_number_of_local_solver_dofs=total_number_of_local_solver_dofs+total_number_of_variable_local_solver_dofs( &
1805  & solver_variable_idx)
1806  number_of_global_solver_dofs=number_of_global_solver_dofs+number_of_variable_global_solver_dofs(solver_variable_idx)
1807  ENDDO !solver_variable_idx
1808 
1809  !Sanity check
1810  IF(number_of_local_solver_dofs==0) THEN
1811  local_error="Invalid problem setup. The number of local solver DOFs for solver matrix "// &
1812  & trim(number_to_vstring(solver_matrix_idx,"*",err,error))//" is zero."
1813  CALL flagerror(local_error,err,error,*999)
1814  ENDIF
1815  IF(number_of_global_solver_dofs==0) THEN
1816  local_error="Invalid problem setup. The number of global solver DOFs for solver matrix "// &
1817  & trim(number_to_vstring(solver_matrix_idx,"*",err,error))//" is zero."
1818  CALL flagerror(local_error,err,error,*999)
1819  ENDIF
1820 
1821  !
1822  ! 4c Set up, allocate and initialise column mappings
1823  !
1824 
1825  !Allocate memory for this solver matrix
1826  !Allocate solver columns to equations sets maps
1827  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
1828  & total_number_of_local_solver_dofs),stat=err)
1829  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps.",err,error,*999)
1830  !Set the number of columns
1831  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%NUMBER_OF_COLUMNS=number_of_global_solver_dofs
1832  !Set the number of variables
1833  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%NUMBER_OF_DOFS=number_of_local_solver_dofs
1834  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%TOTAL_NUMBER_OF_DOFS= &
1835  & total_number_of_local_solver_dofs
1836  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%NUMBER_OF_GLOBAL_DOFS=number_of_global_solver_dofs
1837  !Allocate the columns domain mapping
1838  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%COLUMN_DOFS_MAPPING,stat=err)
1839  IF(err/=0) CALL flagerror("Could not allocate solver col to equations sets map column dofs mapping.",err,error,*999)
1840 !!TODO: what is the real number of domains for a solver???
1841  CALL domain_mappings_mapping_initialise(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
1842  & column_dofs_mapping,computational_environment%NUMBER_COMPUTATIONAL_NODES,err,error,*999)
1843  col_domain_mapping=>solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%COLUMN_DOFS_MAPPING
1844  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(number_of_global_solver_dofs),stat=err)
1845  IF(err/=0) CALL flagerror("Could not allocate column dofs mapping global to local.",err,error,*999)
1846  col_domain_mapping%NUMBER_OF_GLOBAL=number_of_global_solver_dofs
1847  ALLOCATE(variable_rank_processed(solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES, &
1848  & 0:computational_environment%NUMBER_COMPUTATIONAL_NODES-1),stat=err)
1849  IF(err/=0) CALL flagerror("Could not allocate variable rank processed.",err,error,*999)
1850  variable_rank_processed=.false.
1851  !Calculate the column mappings
1852  number_of_columns=number_of_global_solver_dofs
1853 
1854  !Initialise
1855  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
1856 
1857  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
1858  equations=>equations_set%EQUATIONS
1859  equations_mapping=>equations%EQUATIONS_MAPPING
1860  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
1861  linear_mapping=>equations_mapping%LINEAR_MAPPING
1862  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
1863 
1864  IF(ASSOCIATED(dynamic_mapping)) THEN
1865  !Allocate the equations set to solver maps for equations matrix (em) indexing
1866  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
1867  & dynamic_mapping%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES),stat=err)
1868  IF(err/=0) &
1869  & CALL flagerror("Could not allocate equations set to solver map equations to solver matrix maps em.", &
1870  & err,error,*999)
1871  DO equations_matrix_idx=1,dynamic_mapping%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES
1872  CALL solvermapping_equatstosolmatmapseminitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
1873  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx),err,error,*999)
1874  ENDDO !equations_matrix_idx
1875  IF(ASSOCIATED(nonlinear_mapping)) THEN
1876  !Allocate the equations set to solver maps for Jacobian matrix (jm) indexing
1877  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM( &
1878  & nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES),stat=err)
1879  IF(err/=0) &
1880  & CALL flagerror("Could not allocate equations set to solver map equations to solver matrix maps jm.", &
1881  & err,error,*999)
1882  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
1883  NULLIFY(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM( &
1884  & equations_matrix_idx)%PTR)
1885  ENDDO
1886  ENDIF
1887  ELSE
1888  IF(ASSOCIATED(linear_mapping)) THEN
1889  !Allocate the equations set to solver maps for equations matrix (em) indexing
1890  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
1891  & linear_mapping%NUMBER_OF_LINEAR_EQUATIONS_MATRICES),stat=err)
1892  IF(err/=0) &
1893  & CALL flagerror("Could not allocate equations set to solver map equations to solver matrix maps em.", &
1894  & err,error,*999)
1895  DO equations_matrix_idx=1,linear_mapping%NUMBER_OF_LINEAR_EQUATIONS_MATRICES
1896  CALL solvermapping_equatstosolmatmapseminitialise(solver_mapping% &
1897  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
1898  & equations_matrix_idx),err,error,*999)
1899  ENDDO !equations_matrix_idx
1900  ENDIF
1901  IF(ASSOCIATED(nonlinear_mapping)) THEN
1902  !Allocate the equations set to solver maps for Jacobian matrix (jm) indexing
1903  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM( &
1904  & nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES),stat=err)
1905  IF(err/=0) &
1906  & CALL flagerror("Could not allocate equations set to solver map equations to solver matrix maps jm.", &
1907  & err,error,*999)
1908  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
1909  NULLIFY(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM( &
1910  & equations_matrix_idx)%PTR)
1911  ENDDO
1912  ENDIF
1913  ENDIF
1914 
1915  !Initialise solver columns to equations set map
1916  CALL solvermapping_solcoltoequatssetmapinitialise(solver_mapping% &
1917  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1918  & equations_set_idx),err,error,*999)
1919 
1920  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
1921  IF(ASSOCIATED(dynamic_mapping)) THEN
1922  number_of_variables=1
1923  ELSE
1924  IF(ASSOCIATED(nonlinear_mapping)) THEN
1925  number_of_variables=solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(0,equations_set_idx)
1926  ELSE
1927  number_of_variables=solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0,equations_set_idx, &
1928  & solver_matrix_idx)
1929  ENDIF
1930  ENDIF
1931 
1932  !Allocate the solver columns to equations set map arrays
1933  IF(ASSOCIATED(dynamic_mapping)) THEN
1934  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1935  & equations_set_idx)%HAVE_DYNAMIC=.true.
1936  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1937  & equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS(number_of_columns),stat=err)
1938  IF(err/=0) CALL flagerror("Could not allocate solver columns to dynamic equations map.",err,error,*999)
1939  ELSE
1940  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1941  & equations_set_idx)%HAVE_STATIC=.true.
1942  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1943  & equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS(number_of_columns),stat=err)
1944  IF(err/=0) CALL flagerror("Could not allocate solver columns to static equations map.",err,error,*999)
1945  ENDIF
1946  !Set the solver column to equations set map
1947  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
1948  & equations_set_idx)%EQUATIONS=>equations
1949 
1950  !Allocate the equations to solver matrix maps sm equations to solver maps
1951  IF(ASSOCIATED(dynamic_mapping)) THEN
1952  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1953  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(number_of_dynamic_equations_matrices),stat=err)
1954  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps sm dynamic equations "// &
1955  & "to solver matrix maps.",err,error,*999)
1956  !Set up dynamic arrays
1957  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1958  & solver_matrix_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES=number_of_dynamic_equations_matrices
1959  DO equations_matrix_idx=1,number_of_dynamic_equations_matrices
1960  NULLIFY(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1961  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR)
1962  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1963  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR,stat=err)
1964  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps.",err,error,*999)
1965  CALL solvermapping_equationstosolvermapsinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
1966  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
1967  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR,err,error,*999)
1968  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1969  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
1971  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
1972  & equations_matrix_idx)%EQUATIONS_MATRIX_NUMBER=equations_matrix_idx
1973  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
1974  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
1975  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES+1
1976  ENDDO !equations_matrix_idx
1977  !Set up nonlinear arrays
1978  IF(ASSOCIATED(nonlinear_mapping)) THEN
1979  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1980  & solver_matrix_idx)%NUMBER_OF_EQUATIONS_JACOBIANS=nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
1981  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1982  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES),stat=err)
1983  IF(err/=0) CALL flagerror("Could not allocate Jacobian to solver matrix maps.",err,error,*999)
1984  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
1985  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
1986  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR,stat=err)
1987  IF(err/=0) CALL flagerror("Could not allocate Jacobian to solver matrix map.",err,error,*999)
1988  CALL solvermapping_jacobiantosolvermapinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
1989  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
1990  & jacobian_to_solver_matrix_maps(equations_matrix_idx)%PTR,err,error,*999)
1991  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM &
1992  & (equations_matrix_idx)%PTR=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
1993  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
1994  & equations_matrix_idx)%PTR
1995  ENDDO
1996  ENDIF
1997  ELSE
1998  IF(ASSOCIATED(linear_mapping)) THEN
1999  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2000  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(number_of_linear_equations_matrices),stat=err)
2001  IF(err/=0) &
2002  & CALL flagerror("Could not allocate equations to solver matrix maps sm equations to solver matrix maps.", &
2003  & err,error,*999)
2004  !Set up linear arrays
2005  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2006  & solver_matrix_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES=number_of_linear_equations_matrices
2007  DO equations_matrix_idx=1,number_of_linear_equations_matrices
2008  NULLIFY(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2009  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR)
2010  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2011  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR,stat=err)
2012  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps.",err,error,*999)
2013  CALL solvermapping_equationstosolvermapsinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
2014  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
2015  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR,err,error,*999)
2016  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2017  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2019  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
2020  & equations_matrix_idx)%EQUATIONS_MATRIX_NUMBER=equations_matrix_idx
2021  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
2022  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
2023  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES+1
2024  ENDDO !equations_matrix_idx
2025  ELSE
2026  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2027  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(0),stat=err)
2028  IF(err/=0) &
2029  & CALL flagerror("Could not allocate equations to solver matrix maps sm equations to solver matrix maps.", &
2030  & err,error,*999)
2031  !Set up linear arrays
2032  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2033  & solver_matrix_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES=0
2034  ENDIF
2035  !Set up nonlinear arrays
2036  IF(ASSOCIATED(nonlinear_mapping)) THEN
2037  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2038  & solver_matrix_idx)%NUMBER_OF_EQUATIONS_JACOBIANS=nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
2039  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2040  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES),stat=err)
2041  IF(err/=0) CALL flagerror("Could not allocate Jacobian to solver matrix maps.",err,error,*999)
2042  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
2043  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2044  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR,stat=err)
2045  IF(err/=0) CALL flagerror("Could not allocate Jacobian to solver matrix map.",err,error,*999)
2046  CALL solvermapping_jacobiantosolvermapinitialise(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
2047  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
2048  & jacobian_to_solver_matrix_maps(equations_matrix_idx)%PTR,err,error,*999)
2049  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM &
2050  & (equations_matrix_idx)%PTR=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2051  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2052  & equations_matrix_idx)%PTR
2053  ENDDO
2054  ENDIF
2055  ENDIF
2056  DO variable_idx=1,number_of_variables
2057  IF(ASSOCIATED(dynamic_mapping)) THEN
2058  variable_type=solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(equations_set_idx)
2059  number_of_dynamic_equations_matrices=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2060  & number_of_equations_matrices
2061  ELSE
2062  IF(ASSOCIATED(nonlinear_mapping)) THEN
2063  variable_type=solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(variable_idx,equations_set_idx)
2064  ELSE
2065  variable_type=solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(variable_idx,equations_set_idx, &
2066  & solver_matrix_idx)
2067  number_of_linear_equations_matrices=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2068  & number_of_equations_matrices
2069  ENDIF
2070  ENDIF
2071 
2072  dependent_variable=>dependent_field%VARIABLE_TYPE_MAP(variable_type)%PTR
2073  col_dofs_mapping=>dependent_variable%DOMAIN_MAPPING
2074  IF(ASSOCIATED(dynamic_mapping)) THEN
2075  !Allocate dynamic equations to solver matrix maps equations column to solver columns maps
2076  DO equations_matrix_idx=1,number_of_dynamic_equations_matrices
2077  matrix_number=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2078  & equations_matrix_numbers(equations_matrix_idx)
2079  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2080  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2081  & solver_matrix_number=solver_matrix_idx
2082  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2083  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2084  & equations_matrix_number=matrix_number
2085  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2086  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2087  & equations_matrix=>dynamic_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(matrix_number)%EQUATIONS_MATRIX
2088  number_of_equations_columns=dynamic_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(matrix_number)%NUMBER_OF_COLUMNS
2089  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2090  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
2091  & equations_matrix_idx)%PTR%EQUATIONS_COL_TO_SOLVER_COLS_MAP(number_of_equations_columns),stat=err)
2092  IF(err/=0) CALL flagerror("Could not allocate dynamic equations column to solver columns map.", &
2093  & err,error,*999)
2094  ENDDO !equations_matrix_idx
2095  ELSE
2096  !Allocate linear equations to solver matrix maps equations column to solver columns maps
2097  IF(ASSOCIATED(linear_mapping)) THEN
2098  DO equations_matrix_idx=1,number_of_linear_equations_matrices
2099  matrix_number=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2100  & equations_matrix_numbers(equations_matrix_idx)
2101  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2102  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2103  & solver_matrix_number=solver_matrix_idx
2104  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2105  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2106  & equations_matrix_number=matrix_number
2107  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2108  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2109  & equations_matrix=>linear_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(matrix_number)%EQUATIONS_MATRIX
2110  number_of_equations_columns=linear_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(matrix_number)%NUMBER_OF_COLUMNS
2111  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2112  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
2113  & equations_matrix_idx)%PTR%EQUATIONS_COL_TO_SOLVER_COLS_MAP(number_of_equations_columns),stat=err)
2114  IF(err/=0) CALL flagerror("Could not allocate linear equations column to solver columns map.", &
2115  & err,error,*999)
2116  ENDDO !equations_matrix_idx
2117  ENDIF
2118  ENDIF
2119  ENDDO !variable_idx
2120  IF(ASSOCIATED(nonlinear_mapping)) THEN
2121  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
2122  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2123  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR%SOLVER_MATRIX_NUMBER= &
2124  & solver_matrix_idx
2125  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2126  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR%JACOBIAN_MATRIX=> &
2127  & nonlinear_mapping%JACOBIAN_TO_VAR_MAP(equations_matrix_idx)%JACOBIAN
2128  number_of_equations_columns=nonlinear_mapping%JACOBIAN_TO_VAR_MAP(equations_matrix_idx)%NUMBER_OF_COLUMNS
2129  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2130  & solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
2131  & jacobian_col_to_solver_cols_map(number_of_equations_columns),stat=err)
2132  IF(err/=0) CALL flagerror("Could not allocate Jacobian column to solver columns map.",err,error,*999)
2133  ENDDO
2134  ENDIF
2135  ENDDO !equations_set_idx
2136 
2137  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
2138 
2139  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
2140  interface_equations=>interface_condition%INTERFACE_EQUATIONS
2141  interface_mapping=>interface_equations%INTERFACE_MAPPING
2142 
2143  SELECT CASE(interface_condition%METHOD)
2145 
2146  !Initialise solver columns to interface condition map
2147  CALL solvermapping_solcoltointerfmapinitialise(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
2148  & solver_matrix_idx)%SOLVER_COL_TO_INTERFACE_MAPS(interface_condition_idx),err,error,*999)
2149 
2150  !Allocate the solver columns to equations set map arrays
2151  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_INTERFACE_MAPS( &
2152  & interface_condition_idx)%SOLVER_COL_TO_INTERFACE_EQUATIONS_MAPS(number_of_columns),stat=err)
2153  IF(err/=0) CALL flagerror("Could not allocate solver columns to interface equations map.",err,error,*999)
2154 
2155  !Allocate the interface to solver matrix maps sm interface to solver maps
2156  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2157  &interface_to_solver_matrix_maps_sm( &
2158  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_mapping%NUMBER_OF_INTERFACE_MATRICES), &
2159  & stat=err)
2160  IF(err/=0) CALL flagerror("Could not allocate interface to solver matrix maps sm interface equations "// &
2161  & "to solver matrix maps.",err,error,*999)
2162 
2163  !Set up interface arrays
2164  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2165  & solver_matrix_idx)%NUMBER_OF_INTERFACE_MATRICES=interface_mapping%NUMBER_OF_INTERFACE_MATRICES
2166  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
2167  NULLIFY(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2168  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
2169  & interface_matrix_idx)%PTR)
2170  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2171  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
2172  & interface_matrix_idx)%PTR,stat=err)
2173  IF(err/=0) CALL flagerror("Could not allocate interface to solver matrix maps.",err,error,*999)
2174  CALL solvermapping_interfacetosolvermapsinitialise(solver_mapping% &
2175  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2176  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_matrix_idx)%PTR,err,error,*999)
2177  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
2178  & interface_matrix_idx)%INTERFACE_MATRIX_NUMBER=interface_matrix_idx
2179  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
2180  & interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=1
2181 
2182  dependent_variable=>interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%VARIABLE
2183  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2184  & solver_matrix_idx)%DEPENDENT_VARIABLES(interface_matrix_idx)%PTR=>dependent_variable
2185  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2186  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_matrix_idx)%PTR% &
2187  & solver_matrix_number=solver_matrix_idx
2188  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2189  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_matrix_idx)%PTR% &
2190  & interface_matrix_number=interface_matrix_idx
2191  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
2192  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_matrix_idx)%PTR% &
2193  & interface_matrix=>interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%INTERFACE_MATRIX
2194  number_of_interface_rows=interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%NUMBER_OF_ROWS
2195  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2196  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
2197  & interface_matrix_idx)%PTR%INTERFACE_ROW_TO_SOLVER_COLS_MAP(number_of_interface_rows),stat=err)
2198  IF(err/=0) CALL flagerror("Could not allocate interface column to solver columns map.",err,error,*999)
2199  ENDDO !interface_matrix_idx
2200  number_of_interface_columns=interface_mapping%NUMBER_OF_COLUMNS
2201  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2202  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2203  & number_of_interface_columns),stat=err)
2204  IF(err/=0) CALL flagerror("Could not allocate interface column to solver columns map.",err,error,*999)
2206  CALL flagerror("Not implemented.",err,error,*999)
2208  CALL flagerror("Not implemented.",err,error,*999)
2209  CASE DEFAULT
2210  local_error="The interface condition method of "// &
2211  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))// &
2212  & " is invalid."
2213  CALL flagerror(local_error,err,error,*999)
2214  END SELECT
2215  ENDDO !interface_condition_idx
2216 
2217  !Loop over the ranks to ensure that the lowest ranks have the lowest numbered solver variables
2218 
2219  !Allocate dof map to record column reordering
2220  ALLOCATE(dof_map(solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES),stat=err)
2221  IF(err/=0) CALL flagerror("Could not allocate dof map.",err,error,*999)
2222  DO solver_variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
2223  ALLOCATE(dof_map(solver_variable_idx)%PTR(solver_mapping%VARIABLES_LIST(solver_matrix_idx)% &
2224  & variables(solver_variable_idx)%VARIABLE%NUMBER_OF_GLOBAL_DOFS),stat=err)
2225  IF(err/=0) CALL flagerror("Could not allocate dof map global dof map.",err,error,*999)
2226  dof_map(solver_variable_idx)%PTR=0
2227  ENDDO !solver_variable_idx
2228 
2229  ALLOCATE(solver_local_dof(0:computational_environment%NUMBER_COMPUTATIONAL_NODES-1),stat=err)
2230  IF(err/=0) CALL flagerror("Could not allocate solver local dof array.",err,error,*999)
2231 
2232  !
2233  ! 4d Now calculate the solver mappings for each column in rank order
2234  !
2235 
2236  number_of_global_solver_dofs=0
2237  solver_global_dof=0
2238  solver_local_dof=0
2239  DO dof_type=1,2
2240  DO rank=0,computational_environment%NUMBER_COMPUTATIONAL_NODES-1
2241 
2242  DO solver_variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
2243 
2244  IF (solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS>0) THEN
2245  ! Ensure that the dof_offset is calculated as a sum of the number of dofs in the diagonal entries of the solver
2246  ! matrix (ie the sum of the number of solver dofs in each equation set).
2247  ! Note that this may not work when running problems in parallel, however, note that interfaces can not currently
2248  ! be used in parallel either, and the following code only executes if there are interface conditions present.
2249  temp_offset = 0
2250  DO solver_variable_idx_temp=1,solver_variable_idx
2251  DO global_dof=1,SIZE(dof_map(solver_variable_idx_temp)%PTR)
2252  IF (dof_map(solver_variable_idx_temp)%PTR(global_dof)>0) THEN
2253  temp_offset=temp_offset+1
2254  ENDIF
2255  ENDDO
2256  ENDDO
2257  global_dofs_offset=temp_offset
2258  local_dofs_offset=temp_offset
2259  ELSE
2260  global_dofs_offset=solver_global_dof
2261  local_dofs_offset=solver_local_dof(rank)
2262  ENDIF
2263 
2264  variable_type=solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)%VARIABLE_TYPE
2265 
2266  DO equations_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS+solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
2267 
2268  !Get columns list
2269  CALL list_sort(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR,err,error,*999)
2270  CALL list_detach_and_destroy(rank_global_cols_lists(dof_type,equations_idx,solver_variable_idx,rank)%PTR, &
2271  & number_of_rank_cols,rank_global_cols_list,err,error,*999)
2272 
2273  IF(number_of_rank_cols>0) THEN
2274 
2275  solver_global_dof=global_dofs_offset
2276  solver_local_dof(rank)=local_dofs_offset
2277 
2278  equation_type=sub_matrix_information(1,equations_idx,solver_variable_idx)
2279  SELECT CASE(equation_type)
2281 
2282  equations_set_idx=sub_matrix_information(2,equations_idx,solver_variable_idx)
2283 
2284  !The pointers below have been checked for association above.
2285  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
2286  equations=>equations_set%EQUATIONS
2287  equations_mapping=>equations%EQUATIONS_MAPPING
2288  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
2289  linear_mapping=>equations_mapping%LINEAR_MAPPING
2290  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
2291  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
2292 
2293  number_of_dynamic_equations_matrices=0
2294  number_of_linear_equations_matrices=0
2295  IF(ASSOCIATED(dynamic_mapping)) number_of_dynamic_equations_matrices=dynamic_mapping% &
2296  & var_to_equations_matrices_maps(variable_type)%NUMBER_OF_EQUATIONS_MATRICES
2297  IF(ASSOCIATED(linear_mapping)) number_of_linear_equations_matrices=linear_mapping% &
2298  & var_to_equations_matrices_maps(variable_type)%NUMBER_OF_EQUATIONS_MATRICES
2299 
2300  !Loop over the variables
2301 
2302  dependent_variable=>solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)% &
2303  & variable
2304  col_dofs_mapping=>dependent_variable%DOMAIN_MAPPING
2305 
2306  DO global_dof_idx=1,number_of_rank_cols
2307  global_dof=rank_global_cols_list(1,global_dof_idx)
2308  local_dof=rank_global_cols_list(2,global_dof_idx)
2309  !dof_type=RANK_GLOBAL_COLS_LIST(3,global_dof_idx)
2310  include_column=rank_global_cols_list(3,global_dof_idx)==1
2311  constrained_dof=rank_global_cols_list(3,global_dof_idx)==2
2312  variable_idx=rank_global_cols_list(4,global_dof_idx)
2313  globaldofcouplingnumber=rank_global_cols_list(5,global_dof_idx)
2314  IF(globaldofcouplingnumber>0) THEN
2315  colequationcols=>columncouplings%dofCouplings(globaldofcouplingnumber)%ptr
2316  IF(ASSOCIATED(colequationcols)) THEN
2317  numbercolequationscols=colequationcols%numberOfDofs
2318  ELSE
2319  CALL flagerror("Dof coupling is not associated for global dof coupling number "// &
2320  & trim(numbertovstring(globaldofcouplingnumber,"*",err,error))//".",err,error,*999)
2321  END IF
2322  ELSE
2323  numbercolequationscols=1
2324  dummydofcoupling%globalDofs(1)=global_dof
2325  dummydofcoupling%localDofs(1)=local_dof
2326  dummydofcoupling%coefficients(1)=1.0_dp
2327  colequationcols=>dummydofcoupling
2328  END IF
2329 
2330  IF(include_column) THEN
2331  !DOF is not fixed so map the variable/equation dof to a new solver dof
2332 
2333  IF(dof_type==2) THEN
2334  solver_global_dof=dof_map(solver_variable_idx)%PTR(global_dof)
2335  ELSE
2336  solver_global_dof=solver_global_dof+1
2337  dof_map(solver_variable_idx)%PTR(global_dof)=solver_global_dof
2338  ENDIF
2339 
2340  solver_local_dof(rank)=solver_local_dof(rank)+1
2341 
2342  IF(rank==myrank) THEN
2343 
2344  IF(.NOT.variable_rank_processed(solver_variable_idx,rank)) THEN
2345 
2346  !Set up the column domain mappings.
2347  CALL domain_mappings_mapping_global_initialise(col_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
2348  & solver_global_dof),err,error,*999)
2349  !There are no ghosted cols for the solver matrices so there is only 1 domain for the global to
2350  !local map.
2351  !Allocate the global to local map arrays
2352  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1),stat=err)
2353  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map local number.", &
2354  & err,error,*999)
2355  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1),stat=err)
2356  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map domain number.", &
2357  & err,error,*999)
2358  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1),stat=err)
2359  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map domain number.", &
2360  & err,error,*999)
2361  !Set up the global to local mappings
2362  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%NUMBER_OF_DOMAINS=1
2363  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1)= &
2364  & solver_local_dof(rank)
2365  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1)=rank
2366  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1)=domain_local_internal
2367 
2368  !Set up the solver dofs -> variable dofs map
2369  !Initialise
2370  CALL solvermapping_solverdoftovariablemapinitialise(solver_mapping% &
2371  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2372  & solver_local_dof(rank)),err,error,*999)
2373  !Allocate the solver dofs to variable dofs arrays
2374  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2375  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2376  & equations_types(numbercolequationscols),stat=err)
2377  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps equations types.", &
2378  & err,error,*999)
2379  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2380  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2381  & equations_indices(numbercolequationscols),stat=err)
2382  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps equations indices.", &
2383  & err,error,*999)
2384  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2385  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2386  & variable(numbercolequationscols),stat=err)
2387  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps variable type.", &
2388  & err,error,*999)
2389  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2390  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2391  & variable_dof(numbercolequationscols),stat=err)
2392  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps variable dof.", &
2393  & err,error,*999)
2394  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2395  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2396  & variable_coefficient(numbercolequationscols),stat=err)
2397  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps variable coefficient.", &
2398  & err,error,*999)
2399  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2400  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2401  & additive_constant(numbercolequationscols),stat=err)
2402  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps additive constant.", &
2403  & err,error,*999)
2404  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2405  & solver_local_dof(rank))%NUMBER_OF_EQUATION_DOFS=numbercolequationscols
2406  !Set the solver -> equations mappings
2407  DO colequationscolidx=1,numbercolequationscols
2408  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2409  & solver_local_dof(rank))%EQUATIONS_TYPES(colequationscolidx)= &
2411  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2412  & solver_local_dof(rank))%EQUATIONS_INDICES(colequationscolidx)=equations_set_idx
2413  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2414  & solver_local_dof(rank))%VARIABLE(colequationscolidx)%PTR=>dependent_variable
2415  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2416  & solver_local_dof(rank))%VARIABLE_DOF(colequationscolidx)= &
2417  & colequationcols%localDofs(colequationscolidx)
2418  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2419  & solver_local_dof(rank))%VARIABLE_COEFFICIENT(colequationscolidx)= &
2420  & colequationcols%coefficients(colequationscolidx)
2421  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2422  & solver_local_dof(rank))%ADDITIVE_CONSTANT(colequationscolidx)=0.0_dp
2423  END DO
2424  ENDIF
2425  !Set up the equations variables -> solver columns mapping
2426  DO colequationscolidx=1,numbercolequationscols
2427  eqnlocaldof=colequationcols%localDofs(colequationscolidx)
2428  couplingcoefficient=colequationcols%coefficients(colequationscolidx)
2429  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2430  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COLUMN_NUMBERS(eqnlocaldof)= &
2431  & solver_global_dof
2432  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2433  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COUPLING_COEFFICIENTS( &
2434  & eqnlocaldof)=couplingcoefficient
2435  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2436  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%ADDITIVE_CONSTANTS( &
2437  & eqnlocaldof)=0.0_dp
2438  !Set up the equations columns -> solver columns mapping
2439  DO matrix_type_idx=1,sub_matrix_list(0,equations_idx,solver_variable_idx)
2440  matrix_type=sub_matrix_list(matrix_type_idx,equations_idx,solver_variable_idx)
2441  SELECT CASE(matrix_type)
2443  !Dynamic matrix
2444  DO equations_matrix_idx=1,number_of_dynamic_equations_matrices
2445  matrix_number=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2446  & equations_matrix_numbers(equations_matrix_idx)
2447  equations_column=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2448  & dof_to_columns_maps(equations_matrix_idx)%COLUMN_DOF(eqnlocaldof)
2449  !Allocate the equation to solver map column items.
2450  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2451  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2452  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2453  & equations_col_to_solver_cols_map(equations_column)%SOLVER_COLS(1), &
2454  & stat=err)
2455  IF(err/=0) &
2456  & CALL flag_error("Could not allocate dynamic equations column to solver columns map "// &
2457  & "solver colums.",err,error,*999)
2458  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2459  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2460  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2461  & equations_col_to_solver_cols_map(equations_column)%COUPLING_COEFFICIENTS(1),stat=err)
2462  IF(err/=0) &
2463  & CALL flagerror("Could not allocate dynamic equations column to solver columns map "// &
2464  & "coupling coefficients.",err,error,*999)
2465  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2466  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2467  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2468  & equations_col_to_solver_cols_map(equations_column)%NUMBER_OF_SOLVER_COLS=1
2469  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2470  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2471  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2472  & equations_col_to_solver_cols_map(equations_column)%SOLVER_COLS(1)=solver_global_dof
2473  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2474  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2475  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2476  & equations_col_to_solver_cols_map(equations_column)%COUPLING_COEFFICIENTS(1)= &
2477  & couplingcoefficient
2478  ENDDO !equations_matrix_idx
2480  DO equations_matrix_idx=1,number_of_linear_equations_matrices
2481  matrix_number=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2482  & equations_matrix_numbers(equations_matrix_idx)
2483  equations_column=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2484  & dof_to_columns_maps(equations_matrix_idx)%COLUMN_DOF(eqnlocaldof)
2485  !Allocate the equation to solver map column items.
2486  !No coupling yet so the mapping is 1-1
2487  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2488  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2489  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2490  & equations_col_to_solver_cols_map(equations_column)%SOLVER_COLS(1), &
2491  & stat=err)
2492  IF(err/=0) &
2493  & CALL flagerror("Could not allocate linear equations column to solver columns map "// &
2494  & "solver colums.",err,error,*999)
2495  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2496  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2497  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2498  & equations_col_to_solver_cols_map(equations_column)%COUPLING_COEFFICIENTS(1),stat=err)
2499  IF(err/=0) &
2500  & CALL flagerror("Could not allocate linear equations column to solver columns map "// &
2501  & "coupling coefficients.",err,error,*999)
2502  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2503  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2504  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2505  & equations_col_to_solver_cols_map(equations_column)%NUMBER_OF_SOLVER_COLS=1
2506  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2507  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2508  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2509  & equations_col_to_solver_cols_map(equations_column)%SOLVER_COLS(1)=solver_global_dof
2510  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2511  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2512  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2513  & equations_col_to_solver_cols_map(equations_column)%COUPLING_COEFFICIENTS(1)= &
2514  & couplingcoefficient
2515  ENDDO !equations_matrix_idx
2517  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
2518  IF(nonlinear_mapping%VAR_TO_JACOBIAN_MAP(equations_matrix_idx)%VARIABLE_TYPE==variable_type) &
2519  & EXIT
2520  ENDDO
2521  jacobian_column=nonlinear_mapping%VAR_TO_JACOBIAN_MAP(equations_matrix_idx)% &
2522  & dof_to_columns_map(eqnlocaldof)
2523  !Allocate the Jacobian to solver map column items.
2524  !No coupling yet so the mapping is 1-1
2525  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2526  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2527  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)%SOLVER_COLS(1), &
2528  & stat=err)
2529  IF(err/=0) &
2530  & CALL flagerror("Could not allocate Jacobian column to solver columns map solver colums.", &
2531  & err,error,*999)
2532  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2533  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2534  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)% &
2535  & coupling_coefficients(1),stat=err)
2536  IF(err/=0) THEN
2537  local_error="Could not allocate Jacobian column to solver columns map coupling coefficients."
2538  CALL flagerror(local_error,err,error,*999)
2539  ENDIF
2540  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2541  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2542  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)% &
2543  & number_of_solver_cols=1
2544  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2545  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2546  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)%SOLVER_COLS(1)= &
2547  & solver_global_dof
2548  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2549  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2550  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)% &
2551  & coupling_coefficients(1)=couplingcoefficient
2552  CASE DEFAULT
2553  local_error="The equations matrix type of "// &
2554  & trim(number_to_vstring(matrix_type,"*",err,error))// &
2555  & " is invalid."
2556  CALL flagerror(local_error,err,error,*999)
2557  END SELECT
2558  ENDDO !matrix_type_idx
2559  END DO !colEquationsColIdx
2560  ELSE !rank /= myrank
2561 
2562  IF(.NOT.variable_rank_processed(solver_variable_idx,rank)) THEN
2563 
2564  !Set up the column domain mappings.
2565  CALL domain_mappings_mapping_global_initialise(col_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
2566  & solver_global_dof),err,error,*999)
2567  !There are no ghosted cols for the solver matrices so there is only 1 domain for the global to
2568  !local map.
2569  !Allocate the global to local map arrays
2570  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1),stat=err)
2571  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map local number.", &
2572  & err,error,*999)
2573  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1),stat=err)
2574  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map domain number.", &
2575  & err,error,*999)
2576  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1),stat=err)
2577  IF(err/=0) CALL flagerror("Could not allocate column domain global to local map domain number.", &
2578  & err,error,*999)
2579  !Set up the global to local mappings
2580  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%NUMBER_OF_DOMAINS=1
2581  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1)= &
2582  & solver_local_dof(rank)
2583  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1)=rank
2584  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1)=domain_local_internal
2585 
2586  ENDIF
2587 
2588  ENDIF !rank == myrank
2589  ELSE IF(constrained_dof) THEN
2590  !Do nothing, this is set up above
2591  ELSE
2592  IF(rank==myrank) THEN
2593  !Set up the equations variables -> solver columns mapping
2594  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2595  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COLUMN_NUMBERS(local_dof)=0
2596  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2597  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COUPLING_COEFFICIENTS( &
2598  & local_dof)=0.0_dp
2599  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
2600  & solver_matrix_idx)%VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%ADDITIVE_CONSTANTS( &
2601  & local_dof)=0.0_dp
2602  DO matrix_type_idx=1,sub_matrix_list(0,equations_idx,solver_variable_idx)
2603  matrix_type=sub_matrix_list(matrix_type_idx,equations_idx,solver_variable_idx)
2604  SELECT CASE(matrix_type)
2606  !Set up the equations columns -> solver columns mapping
2607  DO equations_matrix_idx=1,number_of_dynamic_equations_matrices
2608  matrix_number=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2609  & equations_matrix_numbers(equations_matrix_idx)
2610  equations_column=dynamic_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2611  & dof_to_columns_maps(equations_matrix_idx)%COLUMN_DOF(local_dof)
2612  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2613  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2614  & dynamic_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2615  & equations_col_to_solver_cols_map(equations_column)%NUMBER_OF_SOLVER_COLS=0
2616  ENDDO !equations_matrix_idx
2618  !Set up the equations columns -> solver columns mapping
2619  DO equations_matrix_idx=1,number_of_linear_equations_matrices
2620  matrix_number=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2621  & equations_matrix_numbers(equations_matrix_idx)
2622  equations_column=linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
2623  & dof_to_columns_maps(equations_matrix_idx)%COLUMN_DOF(local_dof)
2624  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2625  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2626  & linear_equations_to_solver_matrix_maps(equations_matrix_idx)%PTR% &
2627  & equations_col_to_solver_cols_map(equations_column)%NUMBER_OF_SOLVER_COLS=0
2628  ENDDO !equations_matrix_idx
2630  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
2631  IF(nonlinear_mapping%VAR_TO_JACOBIAN_MAP(equations_matrix_idx)%VARIABLE_TYPE==variable_type) &
2632  EXIT
2633  ENDDO
2634  jacobian_column=nonlinear_mapping%VAR_TO_JACOBIAN_MAP(equations_matrix_idx)% &
2635  & dof_to_columns_map(local_dof)
2636  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
2637  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS( &
2638  & equations_matrix_idx)%PTR%JACOBIAN_COL_TO_SOLVER_COLS_MAP(jacobian_column)% &
2639  & number_of_solver_cols=0
2640  CASE DEFAULT
2641  local_error="The equations matrix type of "// &
2642  & trim(number_to_vstring(matrix_type,"*",err,error))//" is invalid."
2643  CALL flagerror(local_error,err,error,*999)
2644  END SELECT
2645  ENDDO !matrix_type_idx
2646  ENDIF !rank == myrank
2647  ENDIF !include_column
2648  ENDDO !global_dof
2649 
2651 
2652  !Now handle the interface condition rows and columns
2653 
2654  interface_condition_idx=sub_matrix_information(2,equations_idx,solver_variable_idx)
2655  interface_matrix_idx=sub_matrix_information(3,equations_idx,solver_variable_idx)
2656 
2657  !The pointers below have been checked for association above.
2658  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
2659 
2660  SELECT CASE(interface_condition%METHOD)
2662  interface_equations=>interface_condition%INTERFACE_EQUATIONS
2663  interface_mapping=>interface_equations%INTERFACE_MAPPING
2664 
2665  !Loop over the variables
2666  ! This is not only a Lagrange variable (it could be a equationset variable) - rename for clarity.
2667 
2668  lagrange_variable=>solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES(solver_variable_idx)% &
2669  & variable
2670 
2671  DO global_dof_idx=1,number_of_rank_cols
2672  global_dof=rank_global_cols_list(1,global_dof_idx)
2673  local_dof=rank_global_cols_list(2,global_dof_idx)
2674  !dof_type=RANK_GLOBAL_COLS_LIST(3,global_dof_idx)
2675  include_column=rank_global_cols_list(3,global_dof_idx)==1
2676  constrained_dof=rank_global_cols_list(3,global_dof_idx)==2
2677  globaldofcouplingnumber=rank_global_cols_list(5,global_dof_idx)
2678 
2679  IF(globaldofcouplingnumber>0) THEN
2680  colequationcols=>columncouplings%dofCouplings(globaldofcouplingnumber)%ptr
2681  IF(ASSOCIATED(colequationcols)) THEN
2682  numbercolequationscols=colequationcols%numberOfDofs
2683  ELSE
2684  CALL flagerror("Dof coupling is not associated for global dof coupling number "// &
2685  & trim(numbertovstring(globaldofcouplingnumber,"*",err,error))//".",err,error,*999)
2686  END IF
2687  ELSE
2688  numbercolequationscols=1
2689  dummydofcoupling%globalDofs(1)=global_dof
2690  dummydofcoupling%localDofs(1)=local_dof
2691  dummydofcoupling%coefficients(1)=1.0_dp
2692  colequationcols=>dummydofcoupling
2693  END IF
2694 
2695  IF(include_column) THEN
2696  !DOF is not fixed so map the variable/equation dof to a new solver dof
2697 
2698  IF(dof_type==2) THEN
2699  !Ghosted, reuse global dof
2700  solver_global_dof=dof_map(solver_variable_idx)%PTR(global_dof)
2701  ELSE
2702  solver_global_dof=solver_global_dof+1
2703  dof_map(solver_variable_idx)%PTR(global_dof)=solver_global_dof
2704  ENDIF
2705 
2706  solver_local_dof(rank)=solver_local_dof(rank)+1
2707 
2708  IF(rank==myrank) THEN
2709 
2710  IF(.NOT.variable_rank_processed(solver_variable_idx,rank)) THEN
2711 
2712  !Set up the column domain mappings.
2713  CALL domain_mappings_mapping_global_initialise(col_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
2714  & solver_global_dof),err,error,*999)
2715  !There are no ghosted cols for the solver matrices so there is only 1 domain for the global to
2716  !local map.
2717  !Allocate the global to local map arrays
2718  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1),stat=err)
2719  IF(err/=0) &
2720  & CALL flagerror("Could not allocate column domain global to local map local number.", &
2721  & err,error,*999)
2722  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1),stat=err)
2723  IF(err/=0) &
2724  & CALL flagerror("Could not allocate column domain global to local map domain number.", &
2725  & err,error,*999)
2726  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1),stat=err)
2727  IF(err/=0) &
2728  & CALL flagerror("Could not allocate column domain global to local map domain number.", &
2729  & err,error,*999)
2730  !Set up the global to local mappings
2731  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%NUMBER_OF_DOMAINS=1
2732  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1)= &
2733  & solver_local_dof(rank)
2734  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1)=rank
2735  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1)=domain_local_internal
2736 
2737  !Set up the solver column -> equations column mappings.
2738  !Set up the solver dofs -> variable dofs map
2739  !Initialise
2740  CALL solvermapping_solverdoftovariablemapinitialise(solver_mapping% &
2741  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2742  & solver_local_dof(rank)),err,error,*999)
2743  !Allocate the solver dofs to variable dofs arrays
2744  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2745  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2746  & equations_types(numbercolequationscols),stat=err)
2747  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps equations types.", &
2748  & err,error,*999)
2749  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2750  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2751  & equations_indices(numbercolequationscols),stat=err)
2752  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps equations indices.", &
2753  & err,error,*999)
2754  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2755  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2756  & variable(numbercolequationscols),stat=err)
2757  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps variable type.", &
2758  & err,error,*999)
2759  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2760  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2761  & variable_dof(numbercolequationscols),stat=err)
2762  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps variable dof.", &
2763  & err,error,*999)
2764  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2765  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2766  & variable_coefficient(numbercolequationscols),stat=err)
2767  IF(err/=0) &
2768  & CALL flagerror("Could not allocate solver dof to variable maps variable coefficient.", &
2769  & err,error,*999)
2770  ALLOCATE(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
2771  & solver_dof_to_variable_maps(solver_local_dof(rank))% &
2772  & additive_constant(numbercolequationscols),stat=err)
2773  IF(err/=0) CALL flagerror("Could not allocate solver dof to variable maps additive constant.", &
2774  & err,error,*999)
2775  !Setup
2776  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
2777  & solver_local_dof(rank))%NUMBER_OF_EQUATION_DOFS=numbercolequationscols
2778  DO colequationscolidx=1,numbercolequationscols
2779  eqnlocaldof=colequationcols%localDofs(colequationscolidx)
2780  couplingcoefficient=colequationcols%coefficients(colequationscolidx)
2781  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2782  & solver_local_dof(rank))%EQUATIONS_TYPES(colequationscolidx)= &
2784  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2785  & solver_local_dof(rank))%EQUATIONS_INDICES(colequationscolidx)=interface_condition_idx
2786  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2787  & solver_local_dof(rank))%VARIABLE(colequationscolidx)%PTR=>lagrange_variable
2788  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2789  & solver_local_dof(rank))%VARIABLE_DOF(colequationscolidx)=eqnlocaldof
2790  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2791  & solver_local_dof(rank))%VARIABLE_COEFFICIENT(colequationscolidx)=couplingcoefficient
2792  solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(&
2793  & solver_local_dof(rank))%ADDITIVE_CONSTANT(1)=0.0_dp
2794  END DO
2795  END IF
2796  DO colequationscolidx=1,numbercolequationscols
2797  eqnlocaldof=colequationcols%localDofs(colequationscolidx)
2798  couplingcoefficient=colequationcols%coefficients(colequationscolidx)
2799  IF(equation_type==solver_mapping_equations_interface_condition) THEN
2800  IF(.NOT.variable_rank_processed(solver_variable_idx,rank)) THEN
2801  !Set up the equations variables -> solver columns mapping
2802  !No coupling yet so the mapping is 1-1
2803  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2804  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
2805  & column_numbers(eqnlocaldof)=solver_global_dof
2806  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2807  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
2808  & coupling_coefficients(eqnlocaldof)=couplingcoefficient
2809  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2810  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP% &
2811  & additive_constants(eqnlocaldof)=0.0_dp
2812  !Set up the equations columns -> solver columns mapping
2813  interface_column=interface_mapping%LAGRANGE_DOF_TO_COLUMN_MAP(local_dof)
2814  !Allocate the equation to solver map column items.
2815  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2816  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2817  & interface_column)%SOLVER_COLS(1),stat=err)
2818  IF(err/=0) CALL flag_error("Could not allocate interface column to solver columns map "// &
2819  & "solver colums.",err,error,*999)
2820  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2821  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2822  & interface_column)%COUPLING_COEFFICIENTS(1),stat=err)
2823  IF(err/=0) CALL flagerror("Could not allocate interface column to solver columns map "// &
2824  & "coupling coefficients.",err,error,*999)
2825  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2826  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2827  & interface_column)%NUMBER_OF_SOLVER_COLS=1
2828  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2829  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2830  & interface_column)%SOLVER_COLS(1)=solver_global_dof
2831  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2832  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2833  & interface_column)%COUPLING_COEFFICIENTS(1)=couplingcoefficient
2834  ENDIF
2835  ELSE
2836  !Set up the equations variables -> solver columns mapping
2837  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2838  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
2839  & interface_matrix_idx)%COLUMN_NUMBERS(eqnlocaldof)=solver_global_dof
2840  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2841  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
2842  & interface_matrix_idx)%COUPLING_COEFFICIENTS(eqnlocaldof)=couplingcoefficient
2843  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2844  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS( &
2845  & interface_matrix_idx)%ADDITIVE_CONSTANTS(eqnlocaldof)=0.0_dp
2846  !Set up the equations columns -> solver columns mapping
2847  interface_row=interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)% &
2848  & variable_dof_to_row_map(eqnlocaldof)
2849  !Allocate the equation to solver map column items.
2850  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2851  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2852  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2853  & interface_row_to_solver_cols_map(interface_row)%SOLVER_COLS(1),stat=err)
2854  IF(err/=0) &
2855  & CALL flagerror("Could not allocate interface equations row to solver columns map "// &
2856  & "solver colums.",err,error,*999)
2857  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2858  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2859  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2860  & interface_row_to_solver_cols_map(interface_row)%COUPLING_COEFFICIENTS(1),stat=err)
2861  IF(err/=0) &
2862  & CALL flagerror("Could not allocate interface equations row to solver columns map "// &
2863  & "coupling coefficients.",err,error,*999)
2864  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2865  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2866  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2867  & interface_row_to_solver_cols_map(interface_row)%NUMBER_OF_SOLVER_COLS=1
2868  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2869  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2870  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2871  & interface_row_to_solver_cols_map(interface_row)%SOLVER_COLS(1)=solver_global_dof
2872  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2873  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2874  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2875  & interface_row_to_solver_cols_map(interface_row)%COUPLING_COEFFICIENTS(1)= &
2876  & interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%MATRIX_COEFFICIENT
2877  ENDIF
2878  END DO
2879  ELSE !rank /= myrank
2880  IF(.NOT.variable_rank_processed(solver_variable_idx,rank)) THEN
2881 
2882  !Set up the column domain mappings.
2883  CALL domain_mappings_mapping_global_initialise(col_domain_mapping%GLOBAL_TO_LOCAL_MAP( &
2884  & solver_global_dof),err,error,*999)
2885  !There are no ghosted cols for the solver matrices so there is only 1 domain for the global to
2886  !local map.
2887  !Allocate the global to local map arrays
2888  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1),stat=err)
2889  IF(err/=0) &
2890  & CALL flagerror("Could not allocate column domain global to local map local number.", &
2891  & err,error,*999)
2892  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1),stat=err)
2893  IF(err/=0) &
2894  & CALL flagerror("Could not allocate column domain global to local map domain number.", &
2895  & err,error,*999)
2896  ALLOCATE(col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1),stat=err)
2897  IF(err/=0) &
2898  & CALL flagerror("Could not allocate column domain global to local map domain number.", &
2899  & err,error,*999)
2900  !Set up the global to local mappings
2901  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%NUMBER_OF_DOMAINS=1
2902  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_NUMBER(1)= &
2903  & solver_local_dof(rank)
2904  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%DOMAIN_NUMBER(1)=rank
2905  col_domain_mapping%GLOBAL_TO_LOCAL_MAP(solver_global_dof)%LOCAL_TYPE(1)=domain_local_internal
2906 
2907  ENDIF
2908  ENDIF !rank == myrank
2909  ELSE IF(constrained_dof) THEN
2910  !Do nothing, this is set up above
2911  ELSE
2912  IF(rank==myrank) THEN
2913  IF(equation_type==solver_mapping_equations_interface_condition) THEN
2914  !Set up the equations variables -> solver columns mapping
2915  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2916  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2917  & lagrange_variable_to_solver_col_map%COLUMN_NUMBERS(local_dof)=0
2918  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2919  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2920  & lagrange_variable_to_solver_col_map%COUPLING_COEFFICIENTS(local_dof)=0.0_dp
2921  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2922  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2923  & lagrange_variable_to_solver_col_map%ADDITIVE_CONSTANTS(local_dof)=0.0_dp
2924  interface_column=interface_mapping%LAGRANGE_DOF_TO_COLUMN_MAP(local_dof)
2925  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2926  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_COL_TO_SOLVER_COLS_MAP( &
2927  & interface_column)%NUMBER_OF_SOLVER_COLS=0
2928  ELSE
2929  !Set up the equations variables -> solver columns mapping
2930  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2931  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2932  & dependent_variable_to_solver_col_maps(interface_matrix_idx)%COLUMN_NUMBERS(local_dof)=0
2933  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2934  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2935  & dependent_variable_to_solver_col_maps(interface_matrix_idx)% &
2936  & coupling_coefficients(local_dof)=0.0_dp
2937  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2938  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2939  & dependent_variable_to_solver_col_maps(interface_matrix_idx)% &
2940  & additive_constants(local_dof)=0.0_dp
2941  !Set up the equations columns -> solver columns mapping
2942  interface_row=interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)% &
2943  & variable_dof_to_row_map(local_dof)
2944  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
2945  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)% &
2946  & interface_equations_to_solver_matrix_maps(interface_matrix_idx)%PTR% &
2947  & interface_row_to_solver_cols_map(interface_row)%NUMBER_OF_SOLVER_COLS=0
2948  ENDIF
2949  ENDIF !rank==myrank
2950  ENDIF !include_column
2951  ENDDO !global_dof
2953  CALL flagerror("Not implemented.",err,error,*999)
2955  CALL flagerror("Not implemented.",err,error,*999)
2956  CASE DEFAULT
2957  local_error="The interface condition method of "// &
2958  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))// &
2959  & " is invalid."
2960  CALL flagerror(local_error,err,error,*999)
2961  END SELECT
2962  CASE DEFAULT
2963  local_error="The equation type of "//trim(number_to_vstring(equation_type,"*",err,error))// &
2964  & " is invalid."
2965  CALL flagerror(local_error,err,error,*999)
2966  END SELECT
2967  variable_rank_processed(solver_variable_idx,rank)=.true.
2968  ENDIF !Number of rank columns > 0
2969  IF(ALLOCATED(rank_global_cols_list)) DEALLOCATE(rank_global_cols_list)
2970  ENDDO !equation_idx
2971 
2972  ENDDO !solver_variable_idx
2973  ENDDO !rank
2974  ENDDO !dof_type
2975 
2976  !Deallocate dof map
2977  DO solver_variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
2978  DEALLOCATE(dof_map(solver_variable_idx)%PTR)
2979  ENDDO !solver_variable_idx
2980  DEALLOCATE(dof_map)
2981  !Deallocate solver local dof
2982  IF(ALLOCATED(solver_local_dof)) DEALLOCATE(solver_local_dof)
2983 
2984  CALL domain_mappings_local_from_global_calculate(col_domain_mapping,err,error,*999)
2985 
2986  IF(ALLOCATED(sub_matrix_information)) DEALLOCATE(sub_matrix_information)
2987  IF(ALLOCATED(sub_matrix_list)) DEALLOCATE(sub_matrix_list)
2988  IF(ALLOCATED(variable_rank_processed)) DEALLOCATE(variable_rank_processed)
2989  IF(ALLOCATED(number_of_variable_global_solver_dofs)) DEALLOCATE(number_of_variable_global_solver_dofs)
2990  IF(ALLOCATED(number_of_variable_local_solver_dofs)) DEALLOCATE(number_of_variable_local_solver_dofs)
2991  IF(ALLOCATED(total_number_of_variable_local_solver_dofs)) DEALLOCATE(total_number_of_variable_local_solver_dofs)
2992  DO solver_variable_idx=1,number_of_equations_variables+number_of_interface_variables
2993  CALL list_destroy(variables_list(solver_variable_idx)%PTR,err,error,*999)
2994  ENDDO
2995  ENDDO !solver_matrix_idx
2996  IF(ALLOCATED(dummydofcoupling%globalDofs)) DEALLOCATE(dummydofcoupling%globalDofs)
2997  IF(ALLOCATED(dummydofcoupling%localDofs)) DEALLOCATE(dummydofcoupling%localDofs)
2998  IF(ALLOCATED(dummydofcoupling%coefficients)) DEALLOCATE(dummydofcoupling%coefficients)
2999  CALL solverdofcouplings_finalise(columncouplings,err,error,*999)
3000 
3001  !
3002  ! 5. Set up the column mappings such that the solver matrix (sm) and equations matrix (em) orderings are the same.
3003  !
3004 
3005  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
3006  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
3007  equations=>equations_set%EQUATIONS
3008  equations_mapping=>equations%EQUATIONS_MAPPING
3009  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
3010  linear_mapping=>equations_mapping%LINEAR_MAPPING
3011  IF(ASSOCIATED(dynamic_mapping)) THEN
3012  DO equations_matrix_idx=1,dynamic_mapping%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES
3013  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3014  & equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3015  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES), &
3016  & stat=err)
3017  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps.",err,error,*999)
3018  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3019  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=0
3020  ENDDO !equations_matrix_idx
3021  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3022  DO equations_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3023  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES
3024  IF(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
3025  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
3026  & solver_matrix_number==solver_matrix_idx) THEN
3027  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3028  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3029  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES+1
3030  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3031  & equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3032  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES)% &
3033  & ptr=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
3034  & solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR
3035  ENDIF
3036  ENDDO !equations_matrix_idx
3037  ENDDO !solver_matrix_idx
3038  ELSE IF(ASSOCIATED(linear_mapping)) THEN
3039  DO equations_matrix_idx=1,linear_mapping%NUMBER_OF_LINEAR_EQUATIONS_MATRICES
3040  ALLOCATE(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3041  & equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3042  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES), &
3043  & stat=err)
3044  IF(err/=0) CALL flagerror("Could not allocate equations to solver matrix maps.",err,error,*999)
3045  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3046  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=0
3047  ENDDO !equations_matrix_idx
3048  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3049  DO equations_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3050  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES
3051  IF(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
3052  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR% &
3053  & solver_matrix_number==solver_matrix_idx) THEN
3054  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3055  & equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3056  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES+1
3057  solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM( &
3058  & equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP( &
3059  & equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES)% &
3060  & ptr=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM( &
3061  & solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR
3062  ENDIF
3063  ENDDO !equations_matrix_idx
3064  ENDDO !solver_matrix_idx
3065  ENDIF
3066  ENDDO !equations_set_idx
3067  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
3068  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
3069  SELECT CASE(interface_condition%METHOD)
3071  interface_equations=>interface_condition%INTERFACE_EQUATIONS
3072  interface_mapping=>interface_equations%INTERFACE_MAPPING
3073  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
3074  ALLOCATE(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3075  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS(solver_mapping% &
3076  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3077  & interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES),stat=err)
3078  IF(err/=0) CALL flagerror("Could not allocate interface to solver matrix maps.",err,error,*999)
3079  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3080  & interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=0
3081  ENDDO !interface_matrix_idx
3082  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3083  DO interface_matrix_idx=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3084  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_INTERFACE_MATRICES
3085  IF(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3086  & solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS(interface_matrix_idx)%PTR% &
3087  & solver_matrix_number==solver_matrix_idx) THEN
3088  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3089  & interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES=solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
3090  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM(interface_matrix_idx)% &
3091  & number_of_solver_matrices+1
3092  solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3093  & interface_matrix_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
3094  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM(interface_matrix_idx)%&
3095  & number_of_solver_matrices)%PTR=>solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3096  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3097  & interface_matrix_idx)%PTR
3098  ENDIF
3099  ENDDO !interface_matrix_idx
3100  ENDDO !solver_matrix_idx
3102  CALL flagerror("Not implemented.",err,error,*999)
3104  CALL flagerror("Not implemented.",err,error,*999)
3105  CASE DEFAULT
3106  local_error="The interface condition method of "// &
3107  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))//" is invalid."
3108  CALL flagerror(local_error,err,error,*999)
3109  END SELECT
3110 
3111  ENDDO !interface_condition_idx
3112  ELSE
3113  CALL flagerror("The solver mapping solver equations are not associated.",err,error,*999)
3114  ENDIF
3115  ELSE
3116  CALL flagerror("Solver mapping create values cache is not associated.",err,error,*999)
3117  ENDIF
3118  ELSE
3119  CALL flagerror("Solver mapping is not associated.",err,error,*999)
3120  ENDIF
3121 
3122  IF(diagnostics1) THEN
3123  CALL write_string(diagnostic_output_type,"Solver mappings:",err,error,*999)
3124  CALL write_string_value(diagnostic_output_type," Number of solver matrices = ",solver_mapping% &
3125  & number_of_solver_matrices,err,error,*999)
3126  CALL write_string(diagnostic_output_type," Equation sets:",err,error,*999)
3127  CALL write_string_value(diagnostic_output_type," Number of equations sets = ",solver_mapping% &
3128  & number_of_equations_sets,err,error,*999)
3129  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
3130  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
3131  CALL write_string_value(diagnostic_output_type," Equations set index : ",equations_set_idx,err,error,*999)
3132  CALL write_string_value(diagnostic_output_type," Region user number = ",equations_set%REGION%USER_NUMBER, &
3133  & err,error,*999)
3134  CALL write_string_value(diagnostic_output_type," Equations set user number = ",equations_set%USER_NUMBER, &
3135  & err,error,*999)
3136  ENDDO !equations_set_idx
3137  CALL write_string(diagnostic_output_type," Interface conditions:",err,error,*999)
3138  CALL write_string_value(diagnostic_output_type," Number of interface conditions = ",solver_mapping% &
3139  & number_of_interface_conditions,err,error,*999)
3140  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
3141  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
3142  CALL write_string_value(diagnostic_output_type," Interface condition index : ",interface_condition_idx, &
3143  & err,error,*999)
3144  CALL write_string_value(diagnostic_output_type," Parent region user number = ",interface_condition%INTERFACE% &
3145  & parent_region%USER_NUMBER,err,error,*999)
3146  CALL write_string_value(diagnostic_output_type," Interface condition user number = ",interface_condition%USER_NUMBER, &
3147  & err,error,*999)
3148  ENDDO !equations_set_idx
3149  CALL write_string(diagnostic_output_type," Equations variables list:",err,error,*999)
3150  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3151  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3152  CALL write_string_value(diagnostic_output_type," Number of variables = ",solver_mapping%VARIABLES_LIST( &
3153  & solver_matrix_idx)%NUMBER_OF_VARIABLES,err,error,*999)
3154  DO variable_idx=1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%NUMBER_OF_VARIABLES
3155  CALL write_string_value(diagnostic_output_type," Variable : ",variable_idx,err,error,*999)
3156  CALL write_string_value(diagnostic_output_type," Variable type = ",solver_mapping%VARIABLES_LIST( &
3157  & solver_matrix_idx)%VARIABLES(variable_idx)%VARIABLE_TYPE,err,error,*999)
3158  CALL write_string_value(diagnostic_output_type," Number of equations = ",solver_mapping%VARIABLES_LIST( &
3159  & solver_matrix_idx)%VARIABLES(variable_idx)%NUMBER_OF_EQUATIONS,err,error,*999)
3160  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
3161  & variable_idx)%NUMBER_OF_EQUATIONS,5,5,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
3162  & variable_idx)%EQUATION_TYPES,'(" Equation types :",5(X,I13))','(26X,5(X,I13))',err,error,*999)
3163  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
3164  & variable_idx)%NUMBER_OF_EQUATIONS,5,5,solver_mapping%VARIABLES_LIST(solver_matrix_idx)%VARIABLES( &
3165  & variable_idx)%EQUATION_TYPES,'(" Equation indices :",5(X,I13))','(26X,5(X,I13))',err,error,*999)
3166  ENDDO !variable_idx
3167  ENDDO !solver_matrix_idx
3168  CALL write_string(diagnostic_output_type," Solver row to equations rows mappings:",err,error,*999)
3169  CALL write_string_value(diagnostic_output_type," Number of rows = ",solver_mapping%NUMBER_OF_ROWS,err,error,*999)
3170  CALL write_string_value(diagnostic_output_type," Number of global rows = ",solver_mapping%NUMBER_OF_GLOBAL_ROWS, &
3171  & err,error,*999)
3172  IF(diagnostics2) THEN
3173  DO row_idx=1,solver_mapping%NUMBER_OF_ROWS
3174  CALL write_string_value(diagnostic_output_type," Solver row : ",row_idx,err,error,*999)
3175  CALL write_string_value(diagnostic_output_type," Number of equations set rows mapped to = ",solver_mapping% &
3176  & solver_row_to_equations_rows_map(row_idx)%NUMBER_OF_EQUATIONS_SET_ROWS,err,error,*999)
3177  CALL write_string_value(diagnostic_output_type," Interface condition index = ",solver_mapping% &
3178  & solver_row_to_equations_rows_map(row_idx)%INTERFACE_CONDITION_INDEX,err,error,*999)
3179  IF(solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)%INTERFACE_CONDITION_INDEX==0) THEN
3180  !Row is an equations set row
3181  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)% &
3182  & number_of_equations_set_rows,5,5,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)%EQUATIONS_INDEX, &
3183  & '(" Equations indices :",5(X,I13))','(30X,5(X,I13))',err,error,*999)
3184  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)% &
3185  & number_of_equations_set_rows,5,5,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)%ROWCOL_NUMBER, &
3186  & '(" Equations row numbers :",5(X,I13))','(30X,5(X,I13))',err,error,*999)
3187  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)% &
3188  & number_of_equations_set_rows,5,5,solver_mapping%SOLVER_ROW_TO_EQUATIONS_ROWS_MAP(row_idx)%COUPLING_COEFFICIENTS, &
3189  & '(" Coupling coefficients :",5(X,E13.6))','(30X,5(X,E13.6))',err,error,*999)
3190  ELSE
3191  !Row is an interface condition row
3192 !!TODO: format better
3193  CALL write_string_fmt_value(diagnostic_output_type," Interface col numbers : ",solver_mapping% &
3194  & solver_row_to_equations_rows_map(row_idx)%ROWCOL_NUMBER(1),"(I13)",err,error,*999)
3195  CALL write_string_fmt_value(diagnostic_output_type," Coupling coefficients : ",solver_mapping% &
3196  & solver_row_to_equations_rows_map(row_idx)%COUPLING_COEFFICIENTS(1),"(E13.6)",err,error,*999)
3197  ENDIF
3198  ENDDO !row_idx
3199  ENDIF
3200  CALL write_string(diagnostic_output_type," Solver column to equations column mappings:",err,error,*999)
3201  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3202  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3203  CALL write_string_value(diagnostic_output_type," Number of columns = ",solver_mapping% &
3204  & solver_col_to_equations_cols_map(solver_matrix_idx)%NUMBER_OF_COLUMNS,err,error,*999)
3205  IF(diagnostics2) THEN
3206  CALL write_string(diagnostic_output_type," Solver column to equations set columns mappings:",err,error,*999)
3207  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
3208  CALL write_string_value(diagnostic_output_type," Equations set index : ",equations_set_idx,err,error,*999)
3209  DO column_idx=1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%NUMBER_OF_COLUMNS
3210  CALL write_string_value(diagnostic_output_type, " Solver column : ",column_idx,err,error,*999)
3211  IF(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3212  & equations_set_idx)%HAVE_DYNAMIC) THEN
3213  CALL write_string_value(diagnostic_output_type," Number of dynamic equations matrices mapped to = ", &
3214  & solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3215  & equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS(column_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES, &
3216  & err,error,*999)
3217  IF(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3218  & equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS(column_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES>0) THEN
3219  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3220  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3221  & column_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES,5,5,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3222  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3223  & column_idx)%EQUATIONS_MATRIX_NUMBERS,'(" Equation matrices numbers :",5(X,I13))', &
3224  & '(39X,5(X,I13))',err,error,*999)
3225  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3226  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3227  & column_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES,5,5,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3228  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3229  & column_idx)%EQUATIONS_COL_NUMBERS,'(" Equation column numbers :",5(X,I13))', &
3230  & '(39X,5(X,I13))',err,error,*999)
3231  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3232  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3233  & column_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES,5,5,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3234  & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_DYNAMIC_EQUATIONS_MAPS( &
3235  & column_idx)%COUPLING_COEFFICIENTS,'(" Coupling coefficients :",5(X,E13.6))', &
3236  & '(39X,5(X,E13.6))',err,error,*999)
3237  ENDIF
3238  ELSE
3239  CALL write_string_value(diagnostic_output_type," Number of dynamic equations matrices mapped to = ", &
3240  & 0_intg,err,error,*999)
3241  ENDIF
3242 !!TODO what about dynamic nonlinear mappings???
3243  IF(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3244  & equations_set_idx)%HAVE_STATIC) THEN
3245  CALL write_string_value(diagnostic_output_type, " Number of linear equations matrices mapped to = ", &
3246  & solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3247  & equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS(column_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES, &
3248  & err,error,*999)
3249  IF(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3250  & equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS(column_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES>0) THEN
3251  !CALL WRITE_STRING_VECTOR(DIAGNOSTIC_OUTPUT_TYPE,1,1,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3252  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3253  ! & column_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES,5,5,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3254  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3255  ! & column_idx)%EQUATIONS_MATRIX_NUMBERS,'(" Equation matrices numbers :",5(X,I13))', &
3256  ! & '(36X,5(X,I13))',ERR,ERROR,*999)
3257  !CALL WRITE_STRING_VECTOR(DIAGNOSTIC_OUTPUT_TYPE,1,1,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3258  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3259  ! & column_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES,5,5,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3260  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3261  ! & column_idx)%EQUATIONS_COL_NUMBERS,'(" Equation column numbers :",5(X,I13))', &
3262  ! & '(36X,5(X,I13))',ERR,ERROR,*999)
3263  !CALL WRITE_STRING_VECTOR(DIAGNOSTIC_OUTPUT_TYPE,1,1,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3264  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3265  ! & column_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES,5,5,SOLVER_MAPPING%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3266  ! & solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS(equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS( &
3267  ! & column_idx)%COUPLING_COEFFICIENTS,'(" Coupling coefficients :",5(X,E13.6))', &
3268  ! & '(36X,5(X,E13.6))',ERR,ERROR,*999)
3269  ENDIF
3270  CALL write_string_value(diagnostic_output_type," Jacobian column number = ", &
3271  & solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3272  & equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS(column_idx)%JACOBIAN_COL_NUMBER,err,error,*999)
3273  CALL write_string_value(diagnostic_output_type," Jacobian coupling coeff = ", &
3274  & solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_COL_TO_EQUATIONS_SET_MAPS( &
3275  & equations_set_idx)%SOLVER_COL_TO_STATIC_EQUATIONS_MAPS(column_idx)%JACOBIAN_COUPLING_COEFFICIENT,err,error,*999)
3276  ELSE
3277  CALL write_string_value(diagnostic_output_type," Number of static equations matrices mapped to = ", &
3278  & 0_intg,err,error,*999)
3279  ENDIF
3280  ENDDO !column_idx
3281  ENDDO !equations_set_idx
3282  ENDIF
3283  ENDDO !solver_matrix_idx
3284  CALL write_string(diagnostic_output_type," Solver DOF to field DOFs mappings:",err,error,*999)
3285  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3286  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3287  CALL write_string_value(diagnostic_output_type," Number of DOFs = ",solver_mapping% &
3288  & solver_col_to_equations_cols_map(solver_matrix_idx)%NUMBER_OF_DOFS,err,error,*999)
3289  CALL write_string_value(diagnostic_output_type," Total number of DOFs = ",solver_mapping% &
3290  & solver_col_to_equations_cols_map(solver_matrix_idx)%TOTAL_NUMBER_OF_DOFS,err,error,*999)
3291  CALL write_string_value(diagnostic_output_type," Number of global DOFs = ",solver_mapping% &
3292  & solver_col_to_equations_cols_map(solver_matrix_idx)%NUMBER_OF_GLOBAL_DOFS,err,error,*999)
3293  ALLOCATE(variable_types(solver_mapping%NUMBER_OF_EQUATIONS_SETS+solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS),stat=err)
3294  IF(err/=0) CALL flagerror("Could not allocate variable types.",err,error,*999)
3295  DO dof_idx=1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%TOTAL_NUMBER_OF_DOFS
3296  CALL write_string_value(diagnostic_output_type," Solver local DOF : ",dof_idx,err,error,*999)
3297  CALL write_string_value(diagnostic_output_type," Number of equations DOFs mapped to = ",solver_mapping% &
3298  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)% &
3299  & number_of_equation_dofs,err,error,*999)
3300  IF(solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)% &
3301  & number_of_equation_dofs>0) THEN
3302  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3303  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,solver_mapping% &
3304  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%EQUATIONS_INDICES, &
3305  & '(" Equations types :",5(X,I13))','(31X,5(X,I13))',err,error,*999)
3306  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3307  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,solver_mapping% &
3308  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%EQUATIONS_INDICES, &
3309  & '(" Equations indices :",5(X,I13))','(31X,5(X,I13))',err,error,*999)
3310  DO variable_idx=1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS( &
3311  & dof_idx)%NUMBER_OF_EQUATION_DOFS
3312  variable_types(variable_idx)=solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP(solver_matrix_idx)% &
3313  & solver_dof_to_variable_maps(dof_idx)%VARIABLE(variable_idx)%PTR%VARIABLE_TYPE
3314  ENDDO !variable_idx
3315  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3316  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,variable_types, &
3317  & '(" Variable types :",5(X,I13))','(31X,5(X,I13))',err,error,*999)
3318  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3319  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,solver_mapping% &
3320  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%VARIABLE_DOF, &
3321  & '(" Variable DOFs :",5(X,I13))','(31X,5(X,I13))',err,error,*999)
3322  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3323  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,solver_mapping% &
3324  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)% &
3325  & variable_coefficient, &
3326  & '(" Variable coefficients :",5(X,E13.6))','(31X,5(X,E13.6))',err,error,*999)
3327  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%SOLVER_COL_TO_EQUATIONS_COLS_MAP( &
3328  & solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)%NUMBER_OF_EQUATION_DOFS,5,5,solver_mapping% &
3329  & solver_col_to_equations_cols_map(solver_matrix_idx)%SOLVER_DOF_TO_VARIABLE_MAPS(dof_idx)% &
3330  & additive_constant, &
3331  & '(" Additive constants :",5(X,E13.6))','(31X,5(X,E13.6))',err,error,*999)
3332  ENDIF
3333  ENDDO !dof_idx
3334  IF(ALLOCATED(variable_types)) DEALLOCATE(variable_types)
3335  ENDDO !solver_matrix_idx
3336  CALL write_string(diagnostic_output_type," Equation sets to solver mappings:",err,error,*999)
3337  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
3338  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
3339  equations=>equations_set%EQUATIONS
3340  equations_mapping=>equations%EQUATIONS_MAPPING
3341  dynamic_mapping=>equations_mapping%DYNAMIC_MAPPING
3342  linear_mapping=>equations_mapping%LINEAR_MAPPING
3343  nonlinear_mapping=>equations_mapping%NONLINEAR_MAPPING
3344  rhs_mapping=>equations_mapping%RHS_MAPPING
3345  source_mapping=>equations_mapping%SOURCE_MAPPING
3346  CALL write_string_value(diagnostic_output_type," Equations set index : ",equations_set_idx,err,error,*999)
3347  CALL write_string(diagnostic_output_type," Equations sets rows to solver rows mappings:",err,error,*999)
3348  CALL write_string_value(diagnostic_output_type, " Number of equations set rows = ",equations_mapping% &
3349  & total_number_of_rows,err,error,*999)
3350  DO row_idx=1,equations_mapping%TOTAL_NUMBER_OF_ROWS
3351  CALL write_string_value(diagnostic_output_type," Equations set row : ",row_idx,err,error,*999)
3352  CALL write_string_value(diagnostic_output_type," Number of solver rows mapped to = ",solver_mapping% &
3353  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS(row_idx)%NUMBER_OF_SOLVER_ROWS, &
3354  & err,error,*999)
3355  IF(solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS(row_idx)% &
3356  & number_of_solver_rows>0) THEN
3357  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3358  & equations_row_to_solver_rows_maps(row_idx)%NUMBER_OF_SOLVER_ROWS,5,5,solver_mapping% &
3359  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS(row_idx)%SOLVER_ROWS, &
3360  & '(" Solver row numbers :",5(X,I13))','(33X,5(X,I13))',err,error,*999)
3361  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3362  & equations_row_to_solver_rows_maps(row_idx)%NUMBER_OF_SOLVER_ROWS,5,5,solver_mapping% &
3363  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS(row_idx)%COUPLING_COEFFICIENTS, &
3364  & '(" Coupling coefficients :",5(X,E13.6))','(33X,5(X,E13.6))',err,error,*999)
3365  ENDIF
3366  ENDDO !row_idx
3367  CALL write_string(diagnostic_output_type," Solver matrix indexing:",err,error,*999)
3368  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3369  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3370  CALL write_string(diagnostic_output_type," Interface conditions affecting:", &
3371  & err,error,*999)
3372  CALL write_string_value(diagnostic_output_type," Number of interface conditions = ",solver_mapping% &
3373  & equations_set_to_solver_map(equations_set_idx)%NUMBER_OF_INTERFACE_CONDITIONS,err,error,*999)
3374  DO interface_condition_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)%NUMBER_OF_INTERFACE_CONDITIONS
3375  CALL write_string_value(diagnostic_output_type," Interface condition : ",interface_condition_idx, &
3376  & err,error,*999)
3377  CALL write_string_value(diagnostic_output_type," Interface condition index = ",solver_mapping% &
3378  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE( &
3379  & interface_condition_idx)%INTERFACE_CONDITION_INDEX,err,error,*999)
3380  CALL write_string_value(diagnostic_output_type," Interface matrix number = ",solver_mapping% &
3381  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE( &
3382  & interface_condition_idx)%INTERFACE_MATRIX_NUMBER,err,error,*999)
3383  ENDDO !interface_condition_idx
3384  IF(ASSOCIATED(dynamic_mapping)) THEN
3385  CALL write_string(diagnostic_output_type," Dynamic equations matrix columns to solver matrix columns:", &
3386  & err,error,*999)
3387  CALL write_string_value(diagnostic_output_type," Number of dynamic equations matrices = ",solver_mapping% &
3388  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3389  & number_of_dynamic_equations_matrices,err,error,*999)
3390  DO equations_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3391  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES
3392  equations_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3393  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%DYNAMIC_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3394  & equations_matrix_idx)%PTR
3395  CALL write_string_value(diagnostic_output_type," Equations matrix index : ",equations_matrix_idx, &
3396  & err,error,*999)
3397  equations_matrix=equations_to_solver_map%EQUATIONS_MATRIX_NUMBER
3398  CALL write_string_value(diagnostic_output_type," Equations matrix number = ",equations_matrix, &
3399  & err,error,*999)
3400  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",equations_to_solver_map% &
3401  & solver_matrix_number,err,error,*999)
3402  DO column_idx=1,dynamic_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(equations_matrix)%NUMBER_OF_COLUMNS
3403  CALL write_string_value(diagnostic_output_type," Equations matrix column : ",column_idx, &
3404  & err,error,*999)
3405  CALL write_string_value(diagnostic_output_type," Number of solver columns mapped to = ", &
3406  & equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS,err,error,*999)
3407  IF(equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS>0) THEN
3408  CALL write_string_vector(diagnostic_output_type,1,1,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3409  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)% &
3410  & solver_cols,'(" Solver columns :",5(X,I13))','(42X,5(X,I13))',err,error,*999)
3411  CALL write_string_vector(diagnostic_output_type,1,1,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3412  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)% &
3413  & coupling_coefficients,'(" Coupling coefficients :",5(X,E13.6))','(42X,5(X,E13.6))', &
3414  & err,error,*999)
3415  ENDIF
3416  ENDDO !column_idx
3417  ENDDO !equations_matrix_idx
3418  ELSE
3419  IF(ASSOCIATED(linear_mapping)) THEN
3420  CALL write_string(diagnostic_output_type," Linear equations matrix columns to solver matrix columns:", &
3421  & err,error,*999)
3422  CALL write_string_value(diagnostic_output_type," Number of liner equations matrices = ",solver_mapping% &
3423  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3424  & number_of_linear_equations_matrices,err,error,*999)
3425  DO equations_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3426  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_LINEAR_EQUATIONS_MATRICES
3427  equations_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3428  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%LINEAR_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3429  & equations_matrix_idx)%PTR
3430  CALL write_string_value(diagnostic_output_type," Equations matrix index : ",equations_matrix_idx, &
3431  & err,error,*999)
3432  equations_matrix=equations_to_solver_map%EQUATIONS_MATRIX_NUMBER
3433  CALL write_string_value(diagnostic_output_type," Equations matrix number = ",equations_matrix, &
3434  & err,error,*999)
3435  CALL write_string_value(diagnostic_output_type," Solver matrix number = ", &
3436  & equations_to_solver_map%SOLVER_MATRIX_NUMBER,err,error,*999)
3437  DO column_idx=1,linear_mapping%EQUATIONS_MATRIX_TO_VAR_MAPS(equations_matrix)%NUMBER_OF_COLUMNS
3438  CALL write_string_value(diagnostic_output_type," Equations matrix column : ",column_idx, &
3439  & err,error,*999)
3440  CALL write_string_value(diagnostic_output_type," Number of solver columns mapped to = ", &
3441  & equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS,err,error,*999)
3442  IF(equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS>0) THEN
3443  CALL write_string_vector(diagnostic_output_type,1,1,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3444  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3445  & column_idx)%SOLVER_COLS,'(" Solver columns :",5(X,I13))','(40X,5(X,I13))', &
3446  & err,error,*999)
3447  CALL write_string_vector(diagnostic_output_type,1,1,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3448  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP( &
3449  & column_idx)%COUPLING_COEFFICIENTS, &
3450  & '(" Coupling coefficients :",5(X,E13.6))','(40X,5(X,E13.6))',err,error,*999)
3451  ENDIF
3452  ENDDO !column_idx
3453  ENDDO !equations_matrix_idx
3454  ENDIF
3455  IF(ASSOCIATED(nonlinear_mapping)) THEN
3456  CALL write_string(diagnostic_output_type," Jacobian equations matrix columns to solver matrix columns:", &
3457  & err,error,*999)
3458  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
3459  jacobian_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3460  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%JACOBIAN_TO_SOLVER_MATRIX_MAPS(equations_matrix_idx)%PTR
3461  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",jacobian_to_solver_map% &
3462  & solver_matrix_number,err,error,*999)
3463  DO column_idx=1,nonlinear_mapping%JACOBIAN_TO_VAR_MAP(equations_matrix_idx)%NUMBER_OF_COLUMNS
3464  CALL write_string_value(diagnostic_output_type," Equations matrix column : ",column_idx,err,error,*999)
3465  CALL write_string_value(diagnostic_output_type," Number of solver columns mapped to = ", &
3466  & jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS,err,error,*999)
3467  IF(jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP(column_idx)%NUMBER_OF_SOLVER_COLS>0) THEN
3468  CALL write_string_vector(diagnostic_output_type,1,1,jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP( &
3469  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP(column_idx)% &
3470  & solver_cols,'(" Solver columns :",5(X,I13))','(38X,5(X,I13))',err,error,*999)
3471  CALL write_string_vector(diagnostic_output_type,1,1,jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP( &
3472  & column_idx)%NUMBER_OF_SOLVER_COLS,5,5,jacobian_to_solver_map%JACOBIAN_COL_TO_SOLVER_COLS_MAP(column_idx)% &
3473  & coupling_coefficients,'(" Coupling coefficients :",5(X,E13.6))','(38X,5(X,E13.6))', &
3474  & err,error,*999)
3475  ENDIF
3476  ENDDO !column_idx
3477  ENDDO !equations_matrix_idx
3478  ENDIF
3479  ENDIF
3480  CALL write_string(diagnostic_output_type," Variable DOFs to solver matrix DOFs:",err,error,*999)
3481  CALL write_string_value(diagnostic_output_type," Number of variables = ",solver_mapping% &
3482  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3483  & number_of_variables,err,error,*999)
3484  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3485  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_VARIABLES,5,5,solver_mapping% &
3486  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3487  & variable_types,'(" Variable types :",5(X,I13))','(28X,5(X,I13))',err,error,*999)
3488  DO variable_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3489  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_VARIABLES
3490  dependent_variable=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3491  & equations_to_solver_matrix_maps_sm(solver_matrix_idx)%VARIABLES(variable_idx)%PTR
3492  CALL write_string_value(diagnostic_output_type," Variable index : ",variable_idx,err,error,*999)
3493  CALL write_string_value(diagnostic_output_type," Number of variable DOFs = ",dependent_variable% &
3494  & number_of_dofs,err,error,*999)
3495  DO local_dof=1,dependent_variable%TOTAL_NUMBER_OF_DOFS
3496  CALL write_string_value(diagnostic_output_type," Variable DOF : ",local_dof,err,error,*999)
3497  CALL write_string_value(diagnostic_output_type," Solver column number = ",solver_mapping% &
3498  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3499  & variable_to_solver_col_maps(variable_idx)%COLUMN_NUMBERS(local_dof),err,error,*999)
3500  CALL write_string_value(diagnostic_output_type," Coupling coefficient = ",solver_mapping% &
3501  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3502  & variable_to_solver_col_maps(variable_idx)%COUPLING_COEFFICIENTS(local_dof),err,error,*999)
3503  CALL write_string_value(diagnostic_output_type," Additive constant = ",solver_mapping% &
3504  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3505  & variable_to_solver_col_maps(variable_idx)%ADDITIVE_CONSTANTS(local_dof),err,error,*999)
3506  ENDDO !local_dof
3507  ENDDO !variable_idx
3508  ENDDO !solver_matrix_idx
3509  IF(ASSOCIATED(dynamic_mapping)) THEN
3510  CALL write_string(diagnostic_output_type," Dynamic equations matrix indexing:",err,error,*999)
3511  DO equations_matrix_idx=1,dynamic_mapping%NUMBER_OF_DYNAMIC_EQUATIONS_MATRICES
3512  CALL write_string_value(diagnostic_output_type," Equations matrix : ",equations_matrix_idx,err,error,*999)
3513  CALL write_string_value(diagnostic_output_type," Number of solver matrices = ",solver_mapping% &
3514  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)% &
3515  & number_of_solver_matrices,err,error,*999)
3516  DO solver_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3517  & equations_to_solver_matrix_maps_em(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES
3518  equations_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3519  & equations_to_solver_matrix_maps_em(equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3520  & solver_matrix_idx)%PTR
3521  CALL write_string_value(diagnostic_output_type," Solver matrix index : ",solver_matrix_idx,err,error,*999)
3522  CALL write_string_value(diagnostic_output_type," Equations matrix number = ",equations_to_solver_map% &
3523  & equations_matrix_number,err,error,*999)
3524  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",equations_to_solver_map% &
3525  & solver_matrix_number,err,error,*999)
3526  ENDDO !solver_matrix_idx
3527  ENDDO !equations_matrix_idx
3528  ELSE
3529  IF(ASSOCIATED(linear_mapping)) THEN
3530  CALL write_string(diagnostic_output_type," Linear equations matrix indexing:",err,error,*999)
3531  DO equations_matrix_idx=1,linear_mapping%NUMBER_OF_LINEAR_EQUATIONS_MATRICES
3532  CALL write_string_value(diagnostic_output_type," Equations matrix : ",equations_matrix_idx,err,error,*999)
3533  CALL write_string_value(diagnostic_output_type," Number of solver matrices = ",solver_mapping% &
3534  & equations_set_to_solver_map(equations_set_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM(equations_matrix_idx)% &
3535  & number_of_solver_matrices,err,error,*999)
3536  DO solver_matrix_idx=1,solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3537  & equations_to_solver_matrix_maps_em(equations_matrix_idx)%NUMBER_OF_SOLVER_MATRICES
3538  equations_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3539  & equations_to_solver_matrix_maps_em(equations_matrix_idx)%EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3540  & solver_matrix_idx)%PTR
3541  CALL write_string_value(diagnostic_output_type," Solver matrix index : ",solver_matrix_idx,err,error,*999)
3542  CALL write_string_value(diagnostic_output_type," Equations matrix number = ",equations_to_solver_map% &
3543  & equations_matrix_number,err,error,*999)
3544  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",equations_to_solver_map% &
3545  & solver_matrix_number,err,error,*999)
3546  ENDDO !solver_matrix_idx
3547  ENDDO !equations_matrix_idx
3548  ENDIF
3549  IF(ASSOCIATED(nonlinear_mapping)) THEN
3550  CALL write_string(diagnostic_output_type," Jacobian matrix indexing:",err,error,*999)
3551  DO equations_matrix_idx=1,nonlinear_mapping%NUMBER_OF_RESIDUAL_VARIABLES
3552  jacobian_to_solver_map=>solver_mapping%EQUATIONS_SET_TO_SOLVER_MAP(equations_set_idx)% &
3553  & equations_to_solver_matrix_maps_jm(equations_matrix_idx)%PTR
3554  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",jacobian_to_solver_map% &
3555  & solver_matrix_number,err,error,*999)
3556  ENDDO
3557  ENDIF
3558  ENDIF
3559  ENDDO !equations_set_idx
3560  IF(solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS>0) THEN
3561  CALL write_string(diagnostic_output_type," Interface conditions to solver mappings:",err,error,*999)
3562  DO interface_condition_idx=1,solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS
3563  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
3564  interface_equations=>interface_condition%INTERFACE_EQUATIONS
3565  interface_mapping=>interface_equations%INTERFACE_MAPPING
3566  CALL write_string(diagnostic_output_type," Interface to equations sets mapping:",err,error,*999)
3567  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3568  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3569  CALL write_string_value(diagnostic_output_type," Number of equations sets = ",solver_mapping% &
3570  & interface_condition_to_solver_map(interface_condition_idx)%NUMBER_OF_EQUATIONS_SETS,err,error,*999)
3571  DO equations_set_idx=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3572  & number_of_equations_sets
3573  CALL write_string_value(diagnostic_output_type," Equations set : ",equations_set_idx,err,error,*999)
3574  CALL write_string_value(diagnostic_output_type," Equations set index = ",solver_mapping% &
3575  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_EQUATIONS( &
3576  & equations_set_idx)%EQUATIONS_SET_INDEX,err,error,*999)
3577  CALL write_string_value(diagnostic_output_type," Interface matrix number = ",solver_mapping% &
3578  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_EQUATIONS( &
3579  & equations_set_idx)%INTERFACE_MATRIX_INDEX,err,error,*999)
3580  ENDDO !equations_set_idx
3581  ENDDO !solver_matrix_idx
3582  CALL write_string(diagnostic_output_type," Interface condition rows to solver rows mappings:",err,error,*999)
3583  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
3584  CALL write_string_value(diagnostic_output_type," Interface matrix idx : ",interface_matrix_idx,err,error,*999)
3585  CALL write_string_value(diagnostic_output_type," Number of interface rows = ",interface_mapping% &
3586  & interface_matrix_rows_to_var_maps(interface_matrix_idx)%TOTAL_NUMBER_OF_ROWS,err,error,*999)
3587  DO row_idx=1,interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%TOTAL_NUMBER_OF_ROWS
3588  CALL write_string_value(diagnostic_output_type," Interface row : ",row_idx,err,error,*999)
3589  CALL write_string_value(diagnostic_output_type," Number of solver rows mapped to = ",solver_mapping% &
3590  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3591  & interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP(row_idx)%NUMBER_OF_SOLVER_ROWS,err,error,*999)
3592  IF(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3593  & interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP(row_idx)%NUMBER_OF_SOLVER_ROWS>0) THEN
3594  CALL write_string_fmt_value(diagnostic_output_type," Solver row numbers : ",solver_mapping% &
3595  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3596  & interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP(row_idx)%SOLVER_ROW,"(I13)",err,error,*999)
3597  CALL write_string_fmt_value(diagnostic_output_type," Coupling coefficients : ",solver_mapping% &
3598  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3599  & interface_matrix_idx)%INTERFACE_ROW_TO_SOLVER_ROWS_MAP(row_idx)%COUPLING_COEFFICIENT,"(E13.6)",err,error,*999)
3600  ENDIF
3601  ENDDO !row_idx
3602  ENDDO !interface_matrix_idx
3603  CALL write_string(diagnostic_output_type," Interface condition column to solver rows mappings:", &
3604  & err,error,*999)
3605  CALL write_string_value(diagnostic_output_type," Number of interface condition columns = ",interface_mapping% &
3606  & total_number_of_columns,err,error,*999)
3607  DO column_idx=1,interface_mapping%TOTAL_NUMBER_OF_COLUMNS
3608  CALL write_string_value(diagnostic_output_type," Interface condition column : ",column_idx,err,error,*999)
3609  CALL write_string_value(diagnostic_output_type," Number of rows mapped to = ",solver_mapping% &
3610  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS(column_idx)% &
3611  & number_of_solver_rows,err,error,*999)
3612  IF(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3613  & interface_column_to_solver_rows_maps(column_idx)%NUMBER_OF_SOLVER_ROWS>0) THEN
3614  CALL write_string_fmt_value(diagnostic_output_type," Solver row number : ",solver_mapping% &
3615  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS(column_idx)% &
3616  & solver_row, "(I13)",err,error,*999)
3617  CALL write_string_fmt_value(diagnostic_output_type," Coupling coefficient : ",solver_mapping% &
3618  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS(column_idx)% &
3619  & coupling_coefficient, "(E13.6)",err,error,*999)
3620  ENDIF
3621  ENDDO !column_idx
3622  CALL write_string(diagnostic_output_type," Solver matrix indexing:",err,error,*999)
3623  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3624  CALL write_string_value(diagnostic_output_type," Solver matrix : ",solver_matrix_idx,err,error,*999)
3625  CALL write_string(diagnostic_output_type," Interface equations matrix rows to solver matrix columns:", &
3626  & err,error,*999)
3627  CALL write_string_value(diagnostic_output_type," Number of interface matrices = ",solver_mapping% &
3628  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3629  & number_of_interface_matrices,err,error,*999)
3630  DO interface_matrix_idx=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3631  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_INTERFACE_MATRICES
3632  interface_to_solver_map=>solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3633  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%INTERFACE_EQUATIONS_TO_SOLVER_MATRIX_MAPS( &
3634  & interface_matrix_idx)%PTR
3635  CALL write_string_value(diagnostic_output_type," Interface matrix index : ",interface_matrix_idx, &
3636  & err,error,*999)
3637  CALL write_string_value(diagnostic_output_type," Interface matrix number = ",interface_to_solver_map% &
3638  & interface_matrix_number,err,error,*999)
3639  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",interface_to_solver_map% &
3640  & solver_matrix_number,err,error,*999)
3641  DO row_idx=1,interface_mapping%INTERFACE_MATRIX_ROWS_TO_VAR_MAPS(interface_matrix_idx)%NUMBER_OF_ROWS
3642  CALL write_string_value(diagnostic_output_type," Interface matrix row : ",row_idx, &
3643  & err,error,*999)
3644  CALL write_string_value(diagnostic_output_type," Number of solver columns mapped to = ", &
3645  & interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP(row_idx)%NUMBER_OF_SOLVER_COLS,err,error,*999)
3646  IF(interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP(row_idx)%NUMBER_OF_SOLVER_COLS>0) THEN
3647  CALL write_string_vector(diagnostic_output_type,1,1,interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP( &
3648  & row_idx)%NUMBER_OF_SOLVER_COLS,5,5,interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP(row_idx)% &
3649  & solver_cols,'(" Solver columns :",5(X,I13))','(38X,5(X,I13))',err,error,*999)
3650  CALL write_string_vector(diagnostic_output_type,1,1,interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP( &
3651  & row_idx)%NUMBER_OF_SOLVER_COLS,5,5,interface_to_solver_map%INTERFACE_ROW_TO_SOLVER_COLS_MAP(row_idx)% &
3652  & coupling_coefficients,'(" Coupling coefficients :",5(X,E13.6))','(38X,5(X,E13.6))', &
3653  & err,error,*999)
3654  ENDIF
3655  ENDDO !row_idx
3656  ENDDO !interface_matrix_idx
3657  CALL write_string(diagnostic_output_type," Variable dofs to solver matrix dofs:",err,error,*999)
3658  CALL write_string(diagnostic_output_type," Lagrange variables:",err,error,*999)
3659  CALL write_string_value(diagnostic_output_type," Lagrange variable type = ",solver_mapping% &
3660  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3661  & lagrange_variable_type,err,error,*999)
3662  lagrange_variable=>solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3663  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%LAGRANGE_VARIABLE
3664  CALL write_string_value(diagnostic_output_type," Number of Lagrange variable dofs = ",lagrange_variable% &
3665  & number_of_dofs,err,error,*999)
3666  DO local_dof=1,lagrange_variable%TOTAL_NUMBER_OF_DOFS
3667  CALL write_string_value(diagnostic_output_type," Variable dof : ",local_dof,err,error,*999)
3668  CALL write_string_value(diagnostic_output_type," Solver column number = ",solver_mapping% &
3669  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3670  & solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP%COLUMN_NUMBERS(local_dof),err,error,*999)
3671  CALL write_string_value(diagnostic_output_type," Coupling coefficient = ",solver_mapping% &
3672  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3673  & solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP%COUPLING_COEFFICIENTS(local_dof),err,error,*999)
3674  CALL write_string_value(diagnostic_output_type," Additive constant = ",solver_mapping% &
3675  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3676  & solver_matrix_idx)%LAGRANGE_VARIABLE_TO_SOLVER_COL_MAP%ADDITIVE_CONSTANTS(local_dof),err,error,*999)
3677  ENDDO !local_dof
3678  CALL write_string(diagnostic_output_type," Dependent variables:",err,error,*999)
3679  CALL write_string_value(diagnostic_output_type," Number of dependent variables = ",solver_mapping% &
3680  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)% &
3681  & number_of_dependent_variables,err,error,*999)
3682  CALL write_string_vector(diagnostic_output_type,1,1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP( &
3683  & interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM(solver_matrix_idx)%NUMBER_OF_DEPENDENT_VARIABLES, &
3684  & 5,5,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3685  & solver_matrix_idx)%DEPENDENT_VARIABLE_TYPES,'(" Dependent variable types :",5(X,I13))', &
3686  & '(38X,5(X,I13))',err,error,*999)
3687  DO variable_idx=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3688  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%NUMBER_OF_DEPENDENT_VARIABLES
3689  dependent_variable=>solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3690  & interface_to_solver_matrix_maps_sm(solver_matrix_idx)%DEPENDENT_VARIABLES(variable_idx)%PTR
3691  CALL write_string_value(diagnostic_output_type," Dependent variable index : ",variable_idx,err,error,*999)
3692  CALL write_string_value(diagnostic_output_type," Number of dependent variable dofs = ", &
3693  & dependent_variable%NUMBER_OF_DOFS,err,error,*999)
3694  DO local_dof=1,dependent_variable%TOTAL_NUMBER_OF_DOFS
3695  CALL write_string_value(diagnostic_output_type," Variable dof : ",local_dof,err,error,*999)
3696  CALL write_string_value(diagnostic_output_type," Solver column number = ",solver_mapping% &
3697  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3698  & solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COLUMN_NUMBERS(local_dof), &
3699  & err,error,*999)
3700  CALL write_string_value(diagnostic_output_type," Coupling coefficient = ",solver_mapping% &
3701  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3702  & solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%COUPLING_COEFFICIENTS(local_dof), &
3703  & err,error,*999)
3704  CALL write_string_value(diagnostic_output_type," Additive constant = ",solver_mapping% &
3705  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_SM( &
3706  & solver_matrix_idx)%DEPENDENT_VARIABLE_TO_SOLVER_COL_MAPS(variable_idx)%ADDITIVE_CONSTANTS(local_dof), &
3707  & err,error,*999)
3708  ENDDO !local_dof
3709  ENDDO !variable_idx
3710  ENDDO !solver_matrix_idx
3711  CALL write_string(diagnostic_output_type," Interface equations matrix indexing:",err,error,*999)
3712  DO interface_matrix_idx=1,interface_mapping%NUMBER_OF_INTERFACE_MATRICES
3713  CALL write_string_value(diagnostic_output_type," Interface matrix : ",interface_matrix_idx,err,error,*999)
3714  CALL write_string_value(diagnostic_output_type," Number of solver matrices = ",solver_mapping% &
3715  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS_IM( &
3716  & interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES,err,error,*999)
3717  DO solver_matrix_idx=1,solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3718  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%NUMBER_OF_SOLVER_MATRICES
3719  interface_to_solver_map=>solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)% &
3720  & interface_to_solver_matrix_maps_im(interface_matrix_idx)%INTERFACE_TO_SOLVER_MATRIX_MAPS( &
3721  & solver_matrix_idx)%PTR
3722  CALL write_string_value(diagnostic_output_type," Solver matrix index : ",solver_matrix_idx,err,error,*999)
3723  CALL write_string_value(diagnostic_output_type," Interface matrix number = ",interface_to_solver_map% &
3724  & interface_matrix_number,err,error,*999)
3725  CALL write_string_value(diagnostic_output_type," Solver matrix number = ",interface_to_solver_map% &
3726  & solver_matrix_number,err,error,*999)
3727  ENDDO !solver_matrix_idx
3728  ENDDO !equations_matrix_idx
3729  CALL write_string(diagnostic_output_type," Interface column to solver rows mapping:",err,error,*999)
3730  CALL write_string_value(diagnostic_output_type," Number of columns = ",interface_mapping%NUMBER_OF_COLUMNS, &
3731  & err,error,*999)
3732  DO column_idx=1,interface_mapping%NUMBER_OF_COLUMNS
3733  CALL write_string_value(diagnostic_output_type," Column : ",column_idx, err,error,*999)
3734  CALL write_string_value(diagnostic_output_type," Number of solver rows = ",solver_mapping% &
3735  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS(column_idx)% &
3736  & number_of_solver_rows,err,error,*999)
3737  IF(solver_mapping%INTERFACE_CONDITION_TO_SOLVER_MAP(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS( &
3738  & column_idx)%NUMBER_OF_SOLVER_ROWS>0) THEN
3739  CALL write_string_fmt_value(diagnostic_output_type," Solver row : ",solver_mapping% &
3740  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS( &
3741  & column_idx)%SOLVER_ROW,"(I13)",err,error,*999)
3742  CALL write_string_fmt_value(diagnostic_output_type," Coupling coefficients : ",solver_mapping% &
3743  & interface_condition_to_solver_map(interface_condition_idx)%INTERFACE_COLUMN_TO_SOLVER_ROWS_MAPS( &
3744  & column_idx)%COUPLING_COEFFICIENT,"(E13.6)", &
3745  & err,error,*999)
3746  ENDIF
3747  ENDDO !column_idx
3748  ENDDO !interface_condition_idx
3749  ENDIF
3750  ENDIF
3751 
3752  exits("SOLVER_MAPPING_CALCULATE")
3753  RETURN
3754 999 IF(ALLOCATED(sub_matrix_information)) DEALLOCATE(sub_matrix_information)
3755  IF(ALLOCATED(sub_matrix_list)) DEALLOCATE(sub_matrix_list)
3756  IF(ALLOCATED(variable_rank_processed)) DEALLOCATE(variable_rank_processed)
3757  IF(ALLOCATED(number_of_variable_global_solver_dofs)) DEALLOCATE(number_of_variable_global_solver_dofs)
3758  IF(ALLOCATED(number_of_variable_local_solver_dofs)) DEALLOCATE(number_of_variable_local_solver_dofs)
3759  IF(ALLOCATED(total_number_of_variable_local_solver_dofs)) DEALLOCATE(total_number_of_variable_local_solver_dofs)
3760  IF(ALLOCATED(dummydofcoupling%globalDofs)) DEALLOCATE(dummydofcoupling%globalDofs)
3761  IF(ALLOCATED(dummydofcoupling%localDofs)) DEALLOCATE(dummydofcoupling%localDofs)
3762  IF(ALLOCATED(dummydofcoupling%coefficients)) DEALLOCATE(dummydofcoupling%coefficients)
3763  CALL solverdofcouplings_finalise(rowcouplings,err,error,*998)
3764 998 CALL solverdofcouplings_finalise(columncouplings,err,error,*997)
3765 997 errorsexits("SOLVER_MAPPING_CALCULATE",err,error)
3766  RETURN 1
3767  END SUBROUTINE solver_mapping_calculate
3768 
3769  !
3770  !================================================================================================================================
3771  !
3772 
3774  SUBROUTINE solver_mapping_create_finish(SOLVER_MAPPING,ERR,ERROR,*)
3776  !Argument variables
3777  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
3778  INTEGER(INTG), INTENT(OUT) :: ERR
3779  TYPE(varying_string), INTENT(OUT) :: ERROR
3780  !Local Variables
3781  INTEGER(INTG) :: DUMMY_ERR
3782  TYPE(varying_string) :: DUMMY_ERROR
3783 
3784  enters("SOLVER_MAPPING_CREATE_FINISH",err,error,*998)
3785 
3786  IF(ASSOCIATED(solver_mapping)) THEN
3787  IF(solver_mapping%SOLVER_MAPPING_FINISHED) THEN
3788  CALL flagerror("Solver mapping has already been finished",err,error,*998)
3789  ELSE
3790  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE)) THEN
3791  CALL solver_mapping_calculate(solver_mapping,err,error,*999)
3792  CALL solver_mapping_create_values_cache_finalise(solver_mapping%CREATE_VALUES_CACHE,err,error,*999)
3793  solver_mapping%SOLVER_MAPPING_FINISHED=.true.
3794  ELSE
3795  CALL flagerror("Solver mapping create values cache is not associated",err,error,*999)
3796  ENDIF
3797  ENDIF
3798  ELSE
3799  CALL flagerror("Solver mapping is not associated",err,error,*998)
3800  ENDIF
3801 
3802  exits("SOLVER_MAPPING_CREATE_FINISH")
3803  RETURN
3804 999 CALL solver_mapping_finalise(solver_mapping,dummy_err,dummy_error,*998)
3805 998 errorsexits("SOLVER_MAPPING_CREATE_FINISH",err,error)
3806  RETURN 1
3807  END SUBROUTINE solver_mapping_create_finish
3808 
3809  !
3810  !================================================================================================================================
3811  !
3812 
3814  SUBROUTINE solver_mapping_create_start(SOLVER_EQUATIONS,SOLVER_MAPPING,ERR,ERROR,*)
3816  !Argument variables
3817  TYPE(solver_equations_type), POINTER :: SOLVER_EQUATIONS
3818  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
3819  INTEGER(INTG), INTENT(OUT) :: ERR
3820  TYPE(varying_string), INTENT(OUT) :: ERROR
3821  !Local Variables
3822 
3823  enters("SOLVER_MAPPING_CREATE_START",err,error,*999)
3824 
3825  IF(ASSOCIATED(solver_equations)) THEN
3826  IF(solver_equations%SOLVER_EQUATIONS_FINISHED) THEN
3827  CALL flagerror("Solver equations has already been finished.",err,error,*999)
3828  ELSE
3829  IF(ASSOCIATED(solver_mapping)) THEN
3830  CALL flagerror("Solver mapping is already associated.",err,error,*999)
3831  ELSE
3832  NULLIFY(solver_mapping)
3833  CALL solver_mapping_initialise(solver_equations,err,error,*999)
3834  solver_mapping=>solver_equations%SOLVER_MAPPING
3835  ENDIF
3836  ENDIF
3837  ELSE
3838  CALL flagerror("Solver is not associated",err,error,*999)
3839  ENDIF
3840 
3841  exits("SOLVER_MAPPING_CREATE_START")
3842  RETURN
3843 999 errorsexits("SOLVER_MAPPING_CREATE_START",err,error)
3844  RETURN 1
3845  END SUBROUTINE solver_mapping_create_start
3846 
3847  !
3848  !================================================================================================================================
3849  !
3850 
3852  SUBROUTINE solver_mapping_create_values_cache_finalise(CREATE_VALUES_CACHE,ERR,ERROR,*)
3854  !Argument variables
3855  TYPE(solver_mapping_create_values_cache_type), POINTER :: CREATE_VALUES_CACHE
3856  INTEGER(INTG), INTENT(OUT) :: ERR
3857  TYPE(varying_string), INTENT(OUT) :: ERROR
3858  !Local Variables
3859  INTEGER(INTG) :: equations_set_idx,solver_matrix_idx
3860 
3861  enters("SOLVER_MAPPING_CREATE_VALUES_CACHE_FINALISE",err,error,*999)
3862 
3863  IF(ASSOCIATED(create_values_cache)) THEN
3864  IF(ASSOCIATED(create_values_cache%EQUATIONS_VARIABLE_LIST)) THEN
3865  DO solver_matrix_idx=1,SIZE(create_values_cache%EQUATIONS_VARIABLE_LIST,1)
3866  IF(ASSOCIATED(create_values_cache%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR)) &
3867  & CALL list_destroy(create_values_cache%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3868  ENDDO !solver_matrix_idx
3869  DEALLOCATE(create_values_cache%EQUATIONS_VARIABLE_LIST)
3870  ENDIF
3871  IF(ALLOCATED(create_values_cache%DYNAMIC_VARIABLE_TYPE)) DEALLOCATE(create_values_cache%DYNAMIC_VARIABLE_TYPE)
3872  IF(ALLOCATED(create_values_cache%MATRIX_VARIABLE_TYPES)) DEALLOCATE(create_values_cache%MATRIX_VARIABLE_TYPES)
3873  IF(ALLOCATED(create_values_cache%RESIDUAL_VARIABLE_TYPES)) DEALLOCATE(create_values_cache%RESIDUAL_VARIABLE_TYPES)
3874  IF(ALLOCATED(create_values_cache%RHS_VARIABLE_TYPE)) DEALLOCATE(create_values_cache%RHS_VARIABLE_TYPE)
3875  IF(ALLOCATED(create_values_cache%SOURCE_VARIABLE_TYPE)) DEALLOCATE(create_values_cache%SOURCE_VARIABLE_TYPE)
3876  IF(ASSOCIATED(create_values_cache%INTERFACE_VARIABLE_LIST)) THEN
3877  DO solver_matrix_idx=1,SIZE(create_values_cache%INTERFACE_VARIABLE_LIST,1)
3878  IF(ASSOCIATED(create_values_cache%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR)) &
3879  & CALL list_destroy(create_values_cache%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3880  ENDDO !solver_matrix_idx
3881  DEALLOCATE(create_values_cache%INTERFACE_VARIABLE_LIST)
3882  ENDIF
3883  IF(ASSOCIATED(create_values_cache%INTERFACE_INDICES)) THEN
3884  DO equations_set_idx=1,SIZE(create_values_cache%INTERFACE_INDICES,1)
3885  IF(ASSOCIATED(create_values_cache%INTERFACE_INDICES(equations_set_idx)%PTR)) &
3886  & CALL list_destroy(create_values_cache%INTERFACE_INDICES(equations_set_idx)%PTR, &
3887  & err,error,*999)
3888  ENDDO !equaitons_set_idx
3889  DEALLOCATE(create_values_cache%INTERFACE_INDICES)
3890  ENDIF
3891  DEALLOCATE(create_values_cache)
3892  ENDIF
3893 
3894  exits("SOLVER_MAPPING_CREATE_VALUES_CACHE_FINALISE")
3895  RETURN
3896 999 errorsexits("SOLVER_MAPPING_CREATE_VALUES_CACHE_FINALISE",err,error)
3897  RETURN 1
3899 
3900  !
3901  !================================================================================================================================
3902  !
3903 
3905  SUBROUTINE solvermapping_createvaluescacheinitialise(SOLVER_MAPPING,ERR,ERROR,*)
3907  !Argument variables
3908  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
3909  INTEGER(INTG), INTENT(OUT) :: ERR
3910  TYPE(varying_string), INTENT(OUT) :: ERROR
3911  !Local Variables
3912  INTEGER(INTG) :: DUMMY_ERR,equations_set_idx,solver_matrix_idx
3913  TYPE(varying_string) :: DUMMY_ERROR
3914 
3915  enters("SolverMapping_CreateValuesCacheInitialise",err,error,*998)
3916 
3917  IF(ASSOCIATED(solver_mapping)) THEN
3918  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE)) THEN
3919  CALL flagerror("Solver mapping create values cache is already associated.",err,error,*998)
3920  ELSE
3921  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE,stat=err)
3922  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache.",err,error,*999)
3923  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
3924  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache equations variable list.", &
3925  & err,error,*999)
3926  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
3927  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache dynamic variable type.", &
3928  & err,error,*999)
3929  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0:field_number_of_variable_types, &
3930  & solver_mapping%NUMBER_OF_EQUATIONS_SETS,solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
3931  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache matrix variable types.", &
3932  & err,error,*999)
3933  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(0:field_number_of_variable_types, &
3934  & solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
3935  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache residual variable type.", &
3936  & err,error,*999)
3937  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
3938  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache RHS variable type.", &
3939  & err,error,*999)
3940  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
3941  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache source variable type.", &
3942  & err,error,*999)
3943  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
3944  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache interface variable list.", &
3945  & err,error,*999)
3946  ALLOCATE(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping%NUMBER_OF_EQUATIONS_SETS),stat=err)
3947  IF(err/=0) CALL flagerror("Could not allocate solver mapping create values cache interface condition indices.", &
3948  & err,error,*999)
3949  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
3950  NULLIFY(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR)
3951  CALL list_create_start(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3952  CALL list_data_type_set(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
3953  & list_intg_type,err,error,*999)
3954  CALL list_data_dimension_set(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
3955  & 2,err,error,*999)
3956  CALL list_create_finish(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3957  NULLIFY(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR)
3958  CALL list_create_start(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3959  CALL list_data_type_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
3960  & list_intg_type,err,error,*999)
3961  CALL list_data_dimension_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
3962  & 2,err,error,*999)
3963  CALL list_create_finish(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR,err,error,*999)
3964  ENDDO !solver_idx
3965  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
3966  NULLIFY(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR)
3967  CALL list_create_start(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR,err,error,*999)
3968  CALL list_data_type_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR,list_intg_type, &
3969  & err,error,*999)
3970  CALL list_data_dimension_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR,2, &
3971  & err,error,*999)
3972  CALL list_key_dimension_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR,1, &
3973  & err,error,*999)
3974  CALL list_create_finish(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(equations_set_idx)%PTR, &
3975  & err,error,*999)
3976  ENDDO !equations_set_idx
3977  solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE=0
3978  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES=0
3979  solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES=0
3980  solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE=0
3981  solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE=0
3982  ENDIF
3983  ELSE
3984  CALL flagerror("Solver mapping is not associated.",err,error,*998)
3985  ENDIF
3986 
3987  exits("SolverMapping_CreateValuesCacheInitialise")
3988  RETURN
3989 999 CALL solver_mapping_create_values_cache_finalise(solver_mapping%CREATE_VALUES_CACHE,dummy_err,dummy_error,*998)
3990 998 errorsexits("SolverMapping_CreateValuesCacheInitialise",err,error)
3991  RETURN 1
3993 
3994  !
3995  !================================================================================================================================
3996  !
3997 
3999  SUBROUTINE solvermapping_createvaluescacheeqnvarlistadd(SOLVER_MAPPING,solver_matrix_idx,equations_set_idx, &
4000  & variable_type,err,error,*)
4002  !Argument variables
4003  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
4004  INTEGER(INTG), INTENT(IN) :: solver_matrix_idx
4005  INTEGER(INTG), INTENT(IN) :: equations_set_idx
4006  INTEGER(INTG), INTENT(IN) :: variable_type
4007  INTEGER(INTG), INTENT(OUT) :: ERR
4008  TYPE(varying_string), INTENT(OUT) :: ERROR
4009  !Local Variables
4010  INTEGER(INTG) :: equations_set_idx2,NUMBER_OF_VARIABLES,variable_idx,VARIABLE_ITEM(2)
4011  LOGICAL :: VARIABLE_FOUND
4012  TYPE(equations_set_type), POINTER :: EQUATIONS_SET,VAR_EQUATIONS_SET
4013  TYPE(field_type), POINTER :: DEPENDENT_FIELD,VAR_DEPENDENT_FIELD
4014  TYPE(varying_string) :: LOCAL_ERROR
4015 
4016  enters("SolverMapping_CreateValuesCacheEqnVarListAdd",err,error,*999)
4017 
4018  IF(ASSOCIATED(solver_mapping)) THEN
4019  IF(equations_set_idx>0.AND.equations_set_idx<=solver_mapping%NUMBER_OF_EQUATIONS_SETS) THEN
4020  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
4021  IF(ASSOCIATED(equations_set)) THEN
4022  dependent_field=>equations_set%DEPENDENT%DEPENDENT_FIELD
4023  IF(ASSOCIATED(dependent_field)) THEN
4024  IF(variable_type/=0) THEN
4025  variable_found=.false.
4026  CALL list_number_of_items_get(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4027  & number_of_variables,err,error,*999)
4028  DO variable_idx=1,number_of_variables
4029  CALL list_item_get(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4030  & variable_idx,variable_item,err,error,*999)
4031  equations_set_idx2=variable_item(1)
4032  var_equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_idx2)%PTR
4033  IF(ASSOCIATED(var_equations_set)) THEN
4034  var_dependent_field=>var_equations_set%DEPENDENT%DEPENDENT_FIELD
4035  IF(ASSOCIATED(var_dependent_field)) THEN
4036  IF(ASSOCIATED(dependent_field,var_dependent_field)) THEN
4037  IF(variable_type==variable_item(2)) variable_found=.true.
4038  ENDIF
4039  ELSE
4040  CALL flagerror("Variable dependent field is not associated.",err,error,*999)
4041  ENDIF
4042  ELSE
4043  CALL flagerror("Variable equations set is not associated.",err,error,*999)
4044  ENDIF
4045  ENDDO !variable_idx
4046  IF(.NOT.variable_found) THEN
4047  variable_item(1)=equations_set_idx
4048  variable_item(2)=variable_type
4049  CALL list_item_add(solver_mapping%CREATE_VALUES_CACHE%EQUATIONS_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4050  & variable_item,err,error,*999)
4051  ENDIF
4052  ENDIF
4053  ELSE
4054  CALL flagerror("Dependent field is not associated.",err,error,*999)
4055  ENDIF
4056  ELSE
4057  CALL flagerror("Equations set is not associated.",err,error,*999)
4058  ENDIF
4059  ELSE
4060  local_error="The specified equations set index of "//trim(number_to_vstring(equations_set_idx,"*",err,error))// &
4061  & " is invalid. The index must be > 0 and <= "// &
4062  & trim(number_to_vstring(solver_mapping%NUMBER_OF_EQUATIONS_SETS,"*",err,error))//"."
4063  CALL flagerror(local_error,err,error,*999)
4064  ENDIF
4065  ELSE
4066  CALL flagerror("Solver mapping is not associated.",err,error,*999)
4067  ENDIF
4068 
4069  exits("SolverMapping_CreateValuesCacheEqnVarListAdd")
4070  RETURN
4071 999 errors("SolverMapping_CreateValuesCacheEqnVarListAdd",err,error)
4072  exits("SolverMapping_CreateValuesCacheEqnVarListAdd")
4073  RETURN 1
4074 
4076 
4077  !
4078  !================================================================================================================================
4079  !
4080 
4082  SUBROUTINE solvermapping_createvaluescacheinterfvarlistadd(SOLVER_MAPPING,solver_matrix_idx,interface_condition_idx, &
4083  & variable_type,err,error,*)
4085  !Argument variables
4086  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
4087  INTEGER(INTG), INTENT(IN) :: solver_matrix_idx
4088  INTEGER(INTG), INTENT(IN) :: interface_condition_idx
4089  INTEGER(INTG), INTENT(IN) :: variable_type
4090  INTEGER(INTG), INTENT(OUT) :: ERR
4091  TYPE(varying_string), INTENT(OUT) :: ERROR
4092  !Local Variables
4093  INTEGER(INTG) :: interface_condition_idx2,NUMBER_OF_VARIABLES,variable_idx,VARIABLE_ITEM(2)
4094  LOGICAL :: VARIABLE_FOUND
4095  TYPE(interface_condition_type), POINTER :: INTERFACE_CONDITION,VAR_INTERFACE_CONDITION
4096  TYPE(field_type), POINTER :: LAGRANGE_FIELD,VAR_LAGRANGE_FIELD
4097  TYPE(varying_string) :: LOCAL_ERROR
4098 
4099  enters("SolverMapping_CreateValuesCacheInterfVarListAdd",err,error,*999)
4100 
4101  IF(ASSOCIATED(solver_mapping)) THEN
4102  IF(interface_condition_idx>0.AND.interface_condition_idx<=solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS) THEN
4103  interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx)%PTR
4104  IF(ASSOCIATED(interface_condition)) THEN
4105  SELECT CASE(interface_condition%METHOD)
4107  IF(ASSOCIATED(interface_condition%LAGRANGE)) THEN
4108  lagrange_field=>interface_condition%LAGRANGE%LAGRANGE_FIELD
4109  IF(ASSOCIATED(lagrange_field)) THEN
4110  IF(variable_type/=0) THEN
4111  variable_found=.false.
4112  CALL list_number_of_items_get(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4113  & number_of_variables,err,error,*999)
4114  DO variable_idx=1,number_of_variables
4115  CALL list_item_get(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4116  & variable_idx,variable_item,err,error,*999)
4117  interface_condition_idx2=variable_item(1)
4118  var_interface_condition=>solver_mapping%INTERFACE_CONDITIONS(interface_condition_idx2)%PTR
4119  IF(ASSOCIATED(var_interface_condition)) THEN
4120  SELECT CASE(var_interface_condition%METHOD)
4122  IF(ASSOCIATED(interface_condition%LAGRANGE)) THEN
4123  var_lagrange_field=>var_interface_condition%LAGRANGE%LAGRANGE_FIELD
4124  IF(ASSOCIATED(var_lagrange_field)) THEN
4125  IF(ASSOCIATED(lagrange_field,var_lagrange_field)) THEN
4126  IF(variable_type==variable_item(2)) variable_found=.true.
4127  ENDIF
4128  ELSE
4129  CALL flagerror("Variable Lagrange field is not associated.",err,error,*999)
4130  ENDIF
4131  ELSE
4132  CALL flagerror("Variable interface Lagrange is not associated.",err,error,*999)
4133  ENDIF
4135  CALL flagerror("Not implemented.",err,error,*999)
4137  CALL flagerror("Not implemented.",err,error,*999)
4138  CASE DEFAULT
4139  local_error="The interface condition method of "// &
4140  & trim(number_to_vstring(var_interface_condition%METHOD,"*",err,error))// &
4141  & " is invalid."
4142  CALL flagerror(local_error,err,error,*999)
4143  END SELECT
4144  ELSE
4145  CALL flagerror("Variable equations set is not associated.",err,error,*999)
4146  ENDIF
4147  ENDDO !variable_idx
4148  IF(.NOT.variable_found) THEN
4149  variable_item(1)=interface_condition_idx
4150  variable_item(2)=variable_type
4151  CALL list_item_add(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_VARIABLE_LIST(solver_matrix_idx)%PTR, &
4152  & variable_item,err,error,*999)
4153  ENDIF
4154  ENDIF
4155  ELSE
4156  CALL flagerror("Lagrange field is not associated.",err,error,*999)
4157  ENDIF
4158  ELSE
4159  CALL flagerror("Interface condition Lagrange is not asssociated.",err,error,*999)
4160  ENDIF
4162  CALL flagerror("Not implemented.",err,error,*999)
4164  CALL flagerror("Not implemented.",err,error,*999)
4165  CASE DEFAULT
4166  local_error="The interface condition method of "// &
4167  & trim(number_to_vstring(interface_condition%METHOD,"*",err,error))// &
4168  & " is invalid."
4169  CALL flagerror(local_error,err,error,*999)
4170  END SELECT
4171  ELSE
4172  CALL flagerror("Interface condition is not associated.",err,error,*999)
4173  ENDIF
4174  ELSE
4175  local_error="The specified interface condition index of "// &
4176  & trim(number_to_vstring(interface_condition_idx,"*",err,error))// &
4177  & " is invalid. The index must be > 0 and <= "// &
4178  & trim(number_to_vstring(solver_mapping%NUMBER_OF_INTERFACE_CONDITIONS,"*",err,error))//"."
4179  CALL flagerror(local_error,err,error,*999)
4180  ENDIF
4181  ELSE
4182  CALL flagerror("Solver mapping is not associated.",err,error,*999)
4183  ENDIF
4184 
4185  exits("SolverMapping_CreateValuesCacheInterfVarListAdd")
4186  RETURN
4187 999 errors("SolverMapping_CreateValuesCacheInterfVarListAdd",err,error)
4188  exits("SolverMapping_CreateValuesCacheInterfVarListAdd")
4189  RETURN 1
4190 
4192 
4193  !
4194  !================================================================================================================================
4195  !
4196 
4198  SUBROUTINE solver_mapping_destroy(SOLVER_MAPPING,ERR,ERROR,*)
4200  !Argument variables
4201  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
4202  INTEGER(INTG), INTENT(OUT) :: ERR
4203  TYPE(varying_string), INTENT(OUT) :: ERROR
4204  !Local Variables
4205 
4206  enters("SOLVER_MAPPING_DESTROY",err,error,*999)
4207 
4208  IF(ASSOCIATED(solver_mapping)) THEN
4209  CALL solver_mapping_finalise(solver_mapping,err,error,*999)
4210  ELSE
4211  CALL flagerror("Solver mapping is not associated",err,error,*999)
4212  ENDIF
4213 
4214  exits("SOLVER_MAPPING_DESTROY")
4215  RETURN
4216 999 errorsexits("SOLVER_MAPPING_DESTROY",err,error)
4217  RETURN 1
4218 
4219  END SUBROUTINE solver_mapping_destroy
4220 
4221  !
4222  !================================================================================================================================
4223  !
4224 
4226  SUBROUTINE solvermapping_equatscoltosolcolsmapfinalise(EQUATIONS_COL_TO_SOLVER_COLS_MAP,ERR,ERROR,*)
4228  !Argument variables
4229  TYPE(equations_col_to_solver_cols_map_type) :: EQUATIONS_COL_TO_SOLVER_COLS_MAP
4230  INTEGER(INTG), INTENT(OUT) :: ERR
4231  TYPE(varying_string), INTENT(OUT) :: ERROR
4232  !Local Variables
4233 
4234  enters("SolverMapping_EquatsColToSolColsMapFinalise",err,error,*999)
4235 
4236  IF(ALLOCATED(equations_col_to_solver_cols_map%SOLVER_COLS)) &
4237  & DEALLOCATE(equations_col_to_solver_cols_map%SOLVER_COLS)
4238  IF(ALLOCATED(equations_col_to_solver_cols_map%COUPLING_COEFFICIENTS)) &
4239  & DEALLOCATE(equations_col_to_solver_cols_map%COUPLING_COEFFICIENTS)
4240 
4241  exits("SolverMapping_EquatsColToSolColsMapFinalise")
4242  RETURN
4243 999 errorsexits("SolverMapping_EquatsColToSolColsMapFinalise",err,error)
4244  RETURN 1
4245 
4247 
4248  !
4249  !================================================================================================================================
4250  !
4251 
4253  SUBROUTINE solvermapping_equatscoltosolcolsmapinitialise(EQUATIONS_COL_TO_SOLVER_COLS_MAP,ERR,ERROR,*)
4255  !Argument variables
4256  TYPE(equations_col_to_solver_cols_map_type) :: EQUATIONS_COL_TO_SOLVER_COLS_MAP
4257  INTEGER(INTG), INTENT(OUT) :: ERR
4258  TYPE(varying_string), INTENT(OUT) :: ERROR
4259  !Local Variables
4260 
4261  enters("SolverMapping_EquatsColToSolColsMapInitialise",err,error,*999)
4262 
4263  equations_col_to_solver_cols_map%NUMBER_OF_SOLVER_COLS=0
4264 
4265  exits("SolverMapping_EquatsColToSolColsMapInitialise")
4266  RETURN
4267 999 errors("SolverMapping_EquatsColToSolColsMapInitialise",err,error)
4268  exits("SolverMapping_EquatsColToSolColsMapInitialise")
4269  RETURN 1
4270 
4272 
4273  !
4274  !================================================================================================================================
4275  !
4276 
4278  SUBROUTINE solvermapping_equatsvarstosolvermatrixset(SOLVER_MAPPING,SOLVER_MATRIX,EQUATIONS_SET_INDEX, &
4279  & variable_types,err,error,*)
4281  !Argument variables
4282  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
4283  INTEGER(INTG), INTENT(IN) :: SOLVER_MATRIX
4284  INTEGER(INTG), INTENT(IN) :: EQUATIONS_SET_INDEX
4285  INTEGER(INTG), INTENT(IN) :: VARIABLE_TYPES(:)
4286  INTEGER(INTG), INTENT(OUT) :: ERR
4287  TYPE(varying_string), INTENT(OUT) :: ERROR
4288  !Local Variables
4289  INTEGER(INTG) :: variable_idx
4290  TYPE(equations_type), POINTER :: EQUATIONS
4291  TYPE(equations_mapping_type), POINTER :: EQUATIONS_MAPPING
4292  TYPE(equations_mapping_linear_type), POINTER :: LINEAR_MAPPING
4293  TYPE(equations_set_type), POINTER :: EQUATIONS_SET
4294  TYPE(varying_string) :: LOCAL_ERROR
4295 
4296  enters("SolverMapping_EquatsVarsToSolverMatrixSet",err,error,*999)
4297 
4298  IF(ASSOCIATED(solver_mapping)) THEN
4299  IF(solver_mapping%SOLVER_MAPPING_FINISHED) THEN
4300  CALL flagerror("Solver mappings has been finished",err,error,*999)
4301  ELSE
4302  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE)) THEN
4303  IF(solver_matrix>=1.AND.solver_matrix<=solver_mapping%NUMBER_OF_SOLVER_MATRICES) THEN
4304  IF(equations_set_index>=1.AND.equations_set_index<=solver_mapping%NUMBER_OF_EQUATIONS_SETS) THEN
4305  equations_set=>solver_mapping%EQUATIONS_SETS(equations_set_index)%PTR
4306  IF(ASSOCIATED(equations_set)) THEN
4307  equations=>equations_set%EQUATIONS
4308  IF(ASSOCIATED(equations)) THEN
4309  equations_mapping=>equations%EQUATIONS_MAPPING
4310  IF(ASSOCIATED(equations_mapping)) THEN
4311  linear_mapping=>equations_mapping%LINEAR_MAPPING
4312  IF(ASSOCIATED(linear_mapping)) THEN
4313  IF(SIZE(variable_types,1)>=1.AND.SIZE(variable_types,1)<=field_number_of_variable_types) THEN
4314  DO variable_idx=1,SIZE(variable_types,1)
4315 !!TODO: CHECK THAT THE VARIABLE TYPE IS NOT REPEATED
4316  !write(*,*) VARIABLE_TYPES(variable_idx)
4317  IF(variable_types(variable_idx)<1.OR. &
4318  & variable_types(variable_idx)>field_number_of_variable_types) THEN
4319  local_error="The variable type of "// &
4320  & trim(number_to_vstring(variable_types(variable_idx),"*",err,error))// &
4321  & " at position "//trim(number_to_vstring(variable_idx,"*",err,error))// &
4322  & " in the array is invalid. The number must be >=1 and <= "// &
4323  & trim(number_to_vstring(field_number_of_variable_types,"*",err,error))
4324  CALL flagerror(local_error,err,error,*999)
4325  ENDIF
4326  IF(linear_mapping%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_types(variable_idx))% &
4327  & number_of_equations_matrices==0) THEN
4328  local_error="The variable type of "// &
4329  & trim(number_to_vstring(variable_types(variable_idx),"*",err,error))// &
4330  & " at position "//trim(number_to_vstring(variable_idx,"*",err,error))// &
4331  & " in the array is invalid. That variable type is not mapped to any equations matrices"
4332  ENDIF
4333  ENDDO !variable_idx
4334  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0,equations_set_index,solver_matrix)= &
4335  & SIZE(variable_types,1)
4336  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(1:SIZE(variable_types,1),equations_set_index, &
4337  & solver_matrix)=variable_types
4338  ELSE
4339  local_error="The supplied size of variable types array of "// &
4340  & trim(number_to_vstring(SIZE(variable_types,1),"*",err,error))// &
4341  & " is invalid. The size must be between 1 and "// &
4342  & trim(number_to_vstring(field_number_of_variable_types,"*",err,error))
4343  CALL flagerror(local_error,err,error,*999)
4344  ENDIF
4345  ELSE
4346  CALL flagerror("Equations mapping linear mapping is not associated.",err,error,*999)
4347  ENDIF
4348  ELSE
4349  CALL flagerror("Equations mapping is not associated.",err,error,*999)
4350  ENDIF
4351  ELSE
4352  CALL flagerror("Equations is not associated.",err,error,*999)
4353  ENDIF
4354  ELSE
4355  CALL flagerror("Equations set is not associated.",err,error,*999)
4356  ENDIF
4357  ELSE
4358  local_error="The equations set index of "//trim(number_to_vstring(equations_set_index,"*",err,error))// &
4359  & " is invalid. The number must be >= 1 and <= "// &
4360  & trim(number_to_vstring(solver_mapping%NUMBER_OF_EQUATIONS_SETS,"*",err,error))//"."
4361  CALL flagerror(local_error,err,error,*999)
4362  ENDIF
4363  ELSE
4364  local_error="The solver matrix number of "//trim(number_to_vstring(solver_matrix,"*",err,error))// &
4365  & " is invalid. The number must be >= 1 and <= "// &
4366  & trim(number_to_vstring(solver_mapping%NUMBER_OF_SOLVER_MATRICES,"*",err,error))//"."
4367  CALL flagerror(local_error,err,error,*999)
4368  ENDIF
4369  ELSE
4370  CALL flagerror("Solver mapping create values cache is not associated",err,error,*999)
4371  ENDIF
4372  ENDIF
4373  ELSE
4374  CALL flagerror("Solver mapping is not associated",err,error,*999)
4375  ENDIF
4376 
4377  exits("SolverMapping_EquatsVarsToSolverMatrixSet")
4378  RETURN
4379 999 errorsexits("SolverMapping_EquatsVarsToSolverMatrixSet",err,error)
4380  RETURN 1
4381 
4383 
4384  !
4385  !================================================================================================================================
4386  !
4387 
4389  SUBROUTINE solvermapping_equatsrowtosolrowsmapfinalise(EQUATIONS_ROW_SOLVER_ROWS_MAP,ERR,ERROR,*)
4391  !Argument variables
4392  TYPE(equations_row_to_solver_rows_map_type) :: EQUATIONS_ROW_SOLVER_ROWS_MAP
4393  INTEGER(INTG), INTENT(OUT) :: ERR
4394  TYPE(varying_string), INTENT(OUT) :: ERROR
4395  !Local Variables
4396 
4397  enters("SolverMapping_EquatsRowToSolRowsMapFinalise",err,error,*999)
4398 
4399  IF(ALLOCATED(equations_row_solver_rows_map%SOLVER_ROWS)) &
4400  & DEALLOCATE(equations_row_solver_rows_map%SOLVER_ROWS)
4401  IF(ALLOCATED(equations_row_solver_rows_map%COUPLING_COEFFICIENTS)) &
4402  & DEALLOCATE(equations_row_solver_rows_map%COUPLING_COEFFICIENTS)
4403 
4404  exits("SolverMapping_EquatsRowToSolRowsMapFinalise")
4405  RETURN
4406 999 errorsexits("SolverMapping_EquatsRowToSolRowsMapFinalise",err,error)
4407  RETURN 1
4408 
4410 
4411  !
4412  !================================================================================================================================
4413  !
4414 
4416  SUBROUTINE solvermapping_equatsrowtosolrowsmapinitialise(EQUATIONS_ROW_SOLVER_ROWS_MAP,ERR,ERROR,*)
4418  !Argument variables
4419  TYPE(equations_row_to_solver_rows_map_type) :: EQUATIONS_ROW_SOLVER_ROWS_MAP
4420  INTEGER(INTG), INTENT(OUT) :: ERR
4421  TYPE(varying_string), INTENT(OUT) :: ERROR
4422  !Local Variables
4423 
4424  enters("SolverMapping_EquatsRowToSolRowsMapInitialise",err,error,*999)
4425 
4426  equations_row_solver_rows_map%NUMBER_OF_SOLVER_ROWS=0
4427 
4428  exits("SolverMapping_EquatsRowToSolRowsMapInitialise")
4429  RETURN
4430 999 errors("SolverMapping_EquatsRowToSolRowsMapInitialise",err,error)
4431  exits("SolverMapping_EquatsRowToSolRowsMapInitialise")
4432  RETURN 1
4433 
4435 
4436  !
4437  !================================================================================================================================
4438  !
4439 
4441  SUBROUTINE solver_mapping_equations_set_add(SOLVER_MAPPING,EQUATIONS_SET,EQUATIONS_SET_INDEX,ERR,ERROR,*)
4443  !Argument variables
4444  TYPE(solver_mapping_type), POINTER :: SOLVER_MAPPING
4445  TYPE(equations_set_type), POINTER :: EQUATIONS_SET
4446  INTEGER(INTG), INTENT(OUT) :: EQUATIONS_SET_INDEX
4447  INTEGER(INTG), INTENT(OUT) :: ERR
4448  TYPE(varying_string), INTENT(OUT) :: ERROR
4449  !Local Variables
4450  INTEGER(INTG) :: equations_set_idx,matrix_idx,solver_matrix_idx,variable_idx,variable_type
4451  INTEGER(INTG), ALLOCATABLE :: NEW_DYNAMIC_VARIABLE_TYPE(:),NEW_MATRIX_VARIABLE_TYPES(:,:,:),NEW_RHS_VARIABLE_TYPE(:), &
4452  & NEW_RESIDUAL_VARIABLE_TYPES(:,:),NEW_SOURCE_VARIABLE_TYPE(:)
4453  LOGICAL :: MATRIX_DONE
4454  TYPE(equations_type), POINTER :: EQUATIONS
4455  TYPE(equations_mapping_type), POINTER :: EQUATIONS_MAPPING
4456  TYPE(equations_set_ptr_type), ALLOCATABLE :: NEW_EQUATIONS_SETS(:)
4457  TYPE(list_ptr_type), POINTER :: NEW_INTERFACE_INDICES(:)
4458  TYPE(solver_equations_type), POINTER :: SOLVER_EQUATIONS
4459  TYPE(varying_string) :: LOCAL_ERROR
4460 
4461  NULLIFY(new_interface_indices)
4462 
4463  enters("SOLVER_MAPPING_EQUATIONS_SET_ADD",err,error,*999)
4464 
4465  equations_set_index=0
4466  IF(ASSOCIATED(solver_mapping)) THEN
4467  IF(solver_mapping%SOLVER_MAPPING_FINISHED) THEN
4468  CALL flagerror("Solver mapping has been finished.",err,error,*999)
4469  ELSE
4470  solver_equations=>solver_mapping%SOLVER_EQUATIONS
4471  IF(ASSOCIATED(solver_equations)) THEN
4472  IF(ASSOCIATED(equations_set)) THEN
4473  IF(equations_set%EQUATIONS_SET_FINISHED) THEN
4474  equations=>equations_set%EQUATIONS
4475  IF(ASSOCIATED(equations)) THEN
4476  equations_mapping=>equations%EQUATIONS_MAPPING
4477  IF(ASSOCIATED(equations_mapping)) THEN
4478  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE)) THEN
4479  IF(solver_mapping%NUMBER_OF_EQUATIONS_SETS>0) THEN
4480  ALLOCATE(new_dynamic_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4481  IF(err/=0) CALL flagerror("Could not allocate new dynamic variable type.",err,error,*999)
4482  ALLOCATE(new_matrix_variable_types(0:field_number_of_variable_types,solver_mapping% &
4483  & number_of_equations_sets+1,solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
4484  IF(err/=0) CALL flagerror("Could not allocate new matrix variable types.",err,error,*999)
4485  ALLOCATE(new_residual_variable_types(0:field_number_of_variable_types, &
4486  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4487  IF(err/=0) CALL flagerror("Could not allocate new residual variable type.",err,error,*999)
4488  ALLOCATE(new_rhs_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4489  IF(err/=0) CALL flagerror("Could not allocate new RHS variable type.",err,error,*999)
4490  ALLOCATE(new_source_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4491  IF(err/=0) CALL flagerror("Could not allocate new source variable type.",err,error,*999)
4492  ALLOCATE(new_interface_indices(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4493  IF(err/=0) CALL flagerror("Could not allocate new interface indices.",err,error,*999)
4494  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
4495  new_interface_indices(equations_set_idx)%PTR=>solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES( &
4496  & equations_set_idx)%PTR
4497  ENDDO !equations_sets
4498  ALLOCATE(new_equations_sets(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4499  IF(err/=0) CALL flagerror("Could not allocate new equations sets.",err,error,*999)
4500 
4501  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES)) &
4502  & DEALLOCATE(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES)
4503 
4504  new_dynamic_variable_type(1:solver_mapping% &
4505  & number_of_equations_sets)=solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE
4506  new_matrix_variable_types(:,1:solver_mapping% &
4507  & number_of_equations_sets,:)=solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES
4508  new_residual_variable_types(:,1:solver_mapping% &
4509  & number_of_equations_sets)=solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES
4510  new_rhs_variable_type(1:solver_mapping% &
4511  & number_of_equations_sets)=solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE
4512  new_source_variable_type(1:solver_mapping% &
4513  & number_of_equations_sets)=solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE
4514  DO equations_set_idx=1,solver_mapping%NUMBER_OF_EQUATIONS_SETS
4515  new_equations_sets(equations_set_idx)%PTR=>solver_mapping%EQUATIONS_SETS(equations_set_idx)%PTR
4516  ENDDO !equations_set_idx
4517  solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES=>new_interface_indices
4518 
4519  new_dynamic_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)=0
4520  new_matrix_variable_types(:,solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,:)=0
4521  new_residual_variable_types(:,solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)=0
4522  new_rhs_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)=0
4523  new_source_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)=0
4524 
4525  CALL move_alloc(new_dynamic_variable_type,solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE)
4526  CALL move_alloc(new_matrix_variable_types,solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES)
4527  CALL move_alloc(new_residual_variable_types,solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES)
4528  CALL move_alloc(new_rhs_variable_type,solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE)
4529  CALL move_alloc(new_source_variable_type,solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE)
4530  CALL move_alloc(new_equations_sets,solver_mapping%EQUATIONS_SETS)
4531  solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES=>new_interface_indices
4532 
4533  ELSE IF(solver_mapping%NUMBER_OF_EQUATIONS_SETS==0) THEN
4534  ALLOCATE(new_dynamic_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4535  IF(err/=0) CALL flagerror("Could not allocate dynamic variable type.",err,error,*999)
4536  ALLOCATE(new_matrix_variable_types(0:field_number_of_variable_types, &
4537  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,solver_mapping%NUMBER_OF_SOLVER_MATRICES),stat=err)
4538  IF(err/=0) CALL flagerror("Could not allocate matrix variable types.",err,error,*999)
4539  ALLOCATE(new_residual_variable_types(0:field_number_of_variable_types, &
4540  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4541  IF(err/=0) CALL flagerror("Could not allocate residual variable type.",err,error,*999)
4542  ALLOCATE(new_rhs_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4543  IF(err/=0) CALL flagerror("Could not allocate RHS variable type.",err,error,*999)
4544  ALLOCATE(new_source_variable_type(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4545  IF(err/=0) CALL flagerror("Could not allocate source variable type.",err,error,*999)
4546  ALLOCATE(new_interface_indices(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4547  IF(err/=0) CALL flagerror("Could not allocate new interface indices.",err,error,*999)
4548  ALLOCATE(new_equations_sets(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1),stat=err)
4549  IF(err/=0) CALL flagerror("Could not allocate new equations sets.",err,error,*999)
4550 
4551  new_dynamic_variable_type=0
4552  new_matrix_variable_types=0
4553  new_residual_variable_types=0
4554  new_rhs_variable_type=0
4555  new_source_variable_type=0
4556 
4557  CALL move_alloc(new_dynamic_variable_type,solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE)
4558  CALL move_alloc(new_matrix_variable_types,solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES)
4559  CALL move_alloc(new_residual_variable_types,solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES)
4560  CALL move_alloc(new_rhs_variable_type,solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE)
4561  CALL move_alloc(new_source_variable_type,solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE)
4562  CALL move_alloc(new_equations_sets,solver_mapping%EQUATIONS_SETS)
4563  IF(ASSOCIATED(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES)) &
4564  & DEALLOCATE(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES)
4565  solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES=>new_interface_indices
4566  ELSE
4567  CALL flagerror("The number of equations sets is < 0.",err,error,*999)
4568  ENDIF
4569  NULLIFY(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)%PTR)
4570  CALL list_create_start(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping% &
4571  & number_of_equations_sets+1)%PTR,err,error,*999)
4572  CALL list_data_type_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping% &
4573  & number_of_equations_sets+1)%PTR,list_intg_type,err,error,*999)
4574  CALL list_data_dimension_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping% &
4575  & number_of_equations_sets+1)%PTR,2,err,error,*999)
4576  CALL list_key_dimension_set(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping% &
4577  & number_of_equations_sets+1)%PTR,1,err,error,*999)
4578  CALL list_create_finish(solver_mapping%CREATE_VALUES_CACHE%INTERFACE_INDICES(solver_mapping% &
4579  & number_of_equations_sets+1)%PTR,err,error,*999)
4580  SELECT CASE(equations%TIME_DEPENDENCE)
4582  SELECT CASE(equations%LINEARITY)
4583  CASE(equations_linear)
4584  IF(ASSOCIATED(equations_mapping%LINEAR_MAPPING)) THEN
4585  !Linear matrices to map.
4586  !Map the first matrix variable found in the equations set to the first solver matrix, the second
4587  !variable found to the second, etc.
4588  variable_type=1
4589  DO matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
4590  matrix_done=.false.
4591  DO WHILE(variable_type<=field_number_of_variable_types.AND..NOT.matrix_done)
4592  IF(equations_mapping%LINEAR_MAPPING%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
4593  & number_of_equations_matrices>0) THEN
4594  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0, &
4595  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,matrix_idx)=1
4596  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(1, &
4597  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,matrix_idx)=variable_type
4598  matrix_done=.true.
4599  ELSE
4600  variable_type=variable_type+1
4601  ENDIF
4602  ENDDO
4603  IF(.NOT.matrix_done) THEN
4604  !Error - could not find any more variables to map to this solver matrix
4605  local_error="Could not find any unmapped variables for solver matrix "// &
4606  & trim(number_to_vstring(matrix_idx,"*",err,error))//"."
4607  CALL flagerror(local_error,err,error,*999)
4608  ENDIF
4609  ENDDO !matrix_idx
4610  !Check if there are still unmapped matrix variables.
4611  DO variable_idx=variable_type+1,field_number_of_variable_types
4612  IF(equations_mapping%LINEAR_MAPPING%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_idx)% &
4613  & number_of_equations_matrices>0) THEN
4614  local_error="Variable type "//trim(number_to_vstring(variable_idx,"*",err,error))// &
4615  & " is mapped to a linear matrix but has not been mapped to any solver matrices."
4616  CALL flagerror(local_error,err,error,*999)
4617  ENDIF
4618  ENDDO !variable_idx
4619  ELSE
4620  CALL flagerror("Equations mapping linear mapping is not associated.",err,error,*999)
4621  ENDIF
4622  CASE(equations_nonlinear)
4623  IF(ASSOCIATED(equations_mapping%NONLINEAR_MAPPING)) THEN
4624  !Set the number of residual variables for this equations set
4625  solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(0,solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)= &
4626  & equations_mapping%NONLINEAR_MAPPING%NUMBER_OF_RESIDUAL_VARIABLES
4627  !Map the residual variables to the solver Jacobian
4628  DO matrix_idx=1,equations_mapping%NONLINEAR_MAPPING%NUMBER_OF_RESIDUAL_VARIABLES
4629  solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(matrix_idx,solver_mapping% &
4630  & number_of_equations_sets+1)=equations_mapping%NONLINEAR_MAPPING% &
4631  & jacobian_to_var_map(matrix_idx)%VARIABLE_TYPE
4632  ENDDO
4633  IF(ASSOCIATED(equations_mapping%LINEAR_MAPPING)) THEN
4634  !If there are linear matrices operating on the residual variable then map them to the
4635  !solver matrix (Jacobian)
4636  IF(solver_mapping%NUMBER_OF_SOLVER_MATRICES==1) THEN
4637  DO matrix_idx=1,equations_mapping%NONLINEAR_MAPPING%NUMBER_OF_RESIDUAL_VARIABLES
4638  variable_type=equations_mapping%NONLINEAR_MAPPING%JACOBIAN_TO_VAR_MAP(matrix_idx)%VARIABLE_TYPE
4639  IF(equations_mapping%LINEAR_MAPPING%VAR_TO_EQUATIONS_MATRICES_MAPS(variable_type)% &
4640  & number_of_equations_matrices>0) THEN
4641  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(0, &
4642  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,1)=1
4643  solver_mapping%CREATE_VALUES_CACHE%MATRIX_VARIABLE_TYPES(1, &
4644  & solver_mapping%NUMBER_OF_EQUATIONS_SETS+1,1)=variable_type
4645  ENDIF
4646  ENDDO
4647  ELSE
4648  local_error="Invalid number of solve matrices. For nonlinear solver equations there should "// &
4649  & "be 1 solver matrix and there are "// &
4650  & trim(number_to_vstring(solver_mapping%NUMBER_OF_SOLVER_MATRICES,"*",err,error))// &
4651  & " solver matrices."
4652  CALL flagerror(local_error,err,error,*999)
4653  ENDIF
4654  ENDIF
4655  ELSE
4656  CALL flagerror("Equations mapping nonlinear mapping is not associated.",err,error,*999)
4657  ENDIF
4658  CASE DEFAULT
4659  local_error="The equations linearity type of "// &
4660  & trim(number_to_vstring(solver_equations%LINEARITY,"*",err,error))//" is invalid."
4661  CALL flagerror(local_error,err,error,*999)
4662  END SELECT
4664  SELECT CASE(equations%LINEARITY)
4665  CASE(equations_linear)
4666  IF(ASSOCIATED(equations_mapping%DYNAMIC_MAPPING)) THEN
4667  solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)= &
4668  & equations_mapping%DYNAMIC_MAPPING%DYNAMIC_VARIABLE_TYPE
4669  ELSE
4670  CALL flagerror("Equations mapping dynamic mapping is not associated.",err,error,*999)
4671  ENDIF
4673  IF(ASSOCIATED(equations_mapping%DYNAMIC_MAPPING)) THEN
4674  solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)= &
4675  & equations_mapping%DYNAMIC_MAPPING%DYNAMIC_VARIABLE_TYPE
4676  DO matrix_idx=1,equations_mapping%NONLINEAR_MAPPING%NUMBER_OF_RESIDUAL_VARIABLES
4677  solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(matrix_idx,solver_mapping% &
4678  & number_of_equations_sets+1)=equations_mapping%NONLINEAR_MAPPING% &
4679  & jacobian_to_var_map(matrix_idx)%VARIABLE_TYPE
4680  ENDDO
4681  ELSE
4682  CALL flagerror("Equations mapping dynamic mapping is not associated.",err,error,*999)
4683  ENDIF
4684  CASE DEFAULT
4685  local_error="The equations linearity type of "// &
4686  & trim(number_to_vstring(solver_equations%LINEARITY,"*",err,error))//" is invalid."
4687  CALL flagerror(local_error,err,error,*999)
4688  END SELECT
4689  CASE DEFAULT
4690  local_error="The equations time dependence type of "// &
4691  & trim(number_to_vstring(solver_equations%TIME_DEPENDENCE,"*",err,error))//" is invalid."
4692  CALL flagerror(local_error,err,error,*999)
4693  END SELECT
4694  IF(ASSOCIATED(equations_mapping%RHS_MAPPING)) THEN
4695  solver_mapping%CREATE_VALUES_CACHE%RHS_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)= &
4696  & equations_mapping%RHS_MAPPING%RHS_VARIABLE_TYPE
4697  ENDIF
4698  IF(ASSOCIATED(equations_mapping%SOURCE_MAPPING)) THEN
4699  solver_mapping%CREATE_VALUES_CACHE%SOURCE_VARIABLE_TYPE(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)= &
4700  & equations_mapping%SOURCE_MAPPING%SOURCE_VARIABLE_TYPE
4701  ENDIF
4702  solver_mapping%EQUATIONS_SETS(solver_mapping%NUMBER_OF_EQUATIONS_SETS+1)%PTR=>equations_set
4703  solver_mapping%NUMBER_OF_EQUATIONS_SETS=solver_mapping%NUMBER_OF_EQUATIONS_SETS+1
4704  equations_set_index=solver_mapping%NUMBER_OF_EQUATIONS_SETS
4705 
4706  !Add the variables to the list of variables
4707  variable_type=solver_mapping%CREATE_VALUES_CACHE%DYNAMIC_VARIABLE_TYPE(equations_set_index)
4708  CALL solvermapping_createvaluescacheeqnvarlistadd(solver_mapping,1,equations_set_index,variable_type, &
4709  & err,error,*999)
4710  DO solver_matrix_idx=1,solver_mapping%NUMBER_OF_SOLVER_MATRICES
4711  DO matrix_idx=1,solver_mapping%CREATE_VALUES_CACHE% &
4712  & matrix_variable_types(0,equations_set_index,solver_matrix_idx)
4713  variable_type=solver_mapping%CREATE_VALUES_CACHE% &
4714  & matrix_variable_types(matrix_idx,equations_set_index,solver_matrix_idx)
4715  CALL solvermapping_createvaluescacheeqnvarlistadd(solver_mapping,1,equations_set_index, &
4716  & variable_type,err,error,*999)
4717  ENDDO !matrix_idx
4718  ENDDO !solver_matrix_idx
4719  DO matrix_idx=1,solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(0,equations_set_index)
4720  variable_type=solver_mapping%CREATE_VALUES_CACHE%RESIDUAL_VARIABLE_TYPES(matrix_idx,equations_set_index)
4721  CALL solvermapping_createvaluescacheeqnvarlistadd(solver_mapping,1,equations_set_index,variable_type, &
4722  & err,error,*999)
4723  ENDDO
4724  ELSE
4725  CALL flagerror("Solvers mapping create values cache is not associated.",err,error,*999)
4726  ENDIF
4727  ELSE
4728  CALL flagerror("Equations mapping is not associated.",err,error,*999)
4729  ENDIF
4730  ELSE
4731  CALL flagerror("Equations set equations is not associated.",err,error,*999)
4732  ENDIF
4733  ELSE
4734  CALL flagerror("Equations set has not been finished.",err,error,*999)
4735  ENDIF
4736  ELSE
4737  CALL flagerror("Equations set is not associated.",err,error,*999)
4738  ENDIF
4739  ELSE
4740  CALL flagerror("Solver mapping solver is not associated.",err,error,*999)
4741  ENDIF
4742  ENDIF
4743  ELSE
4744  CALL flagerror("Solver mapping is not associated.",err,error,*999)
4745  ENDIF
4746 
4747  exits("SOLVER_MAPPING_EQUATIONS_SET_ADD")
4748  RETURN
4749 999 IF(ALLOCATED(new_matrix_variable_types)) DEALLOCATE(new_matrix_variable_types)
4750  IF(ALLOCATED(new_residual_variable_types)) DEALLOCATE(new_residual_variable_types)
4751  IF(ALLOCATED(new_rhs_variable_type)) DEALLOCATE(new_rhs_variable_type)
4752  IF(ALLOCATED(new_source_variable_type)) DEALLOCATE(new_source_variable_type)
4753  IF(ALLOCATED(new_equations_sets)) DEALLOCATE(new_equations_sets)
4754  errorsexits("SOLVER_MAPPING_EQUATIONS_SET_ADD",err,error)
4755  RETURN 1
4756 
4757  END SUBROUTINE solver_mapping_equations_set_add
4758 
4759  !
4760  !================================================================================================================================
4761  !
4762 
4764  SUBROUTINE solvermapping_equationssettosolvermapfinalise(EQUATIONS_SET_TO_SOLVER_MAP,ERR,ERROR,*)
4766  !Argument variables
4767  TYPE(equations_set_to_solver_map_type) :: EQUATIONS_SET_TO_SOLVER_MAP
4768  INTEGER(INTG), INTENT(OUT) :: ERR
4769  TYPE(varying_string), INTENT(OUT) :: ERROR
4770  !Local Variables
4771  INTEGER(INTG) :: equations_matrix_idx,interface_condition_idx,row_idx,solver_matrix_idx
4772 
4773  enters("SolverMapping_EquationsSetToSolverMapFinalise",err,error,*999)
4774 
4775  IF(ALLOCATED(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE)) THEN
4776  DO interface_condition_idx=1,SIZE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE,1)
4777  CALL solvermapping_equationstosolverinterfacefinalise(equations_set_to_solver_map% &
4778  & equations_to_solver_matrix_maps_interface(interface_condition_idx),err,error,*999)
4779  ENDDO !interface_condition_idx
4780  DEALLOCATE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_INTERFACE)
4781  ENDIF
4782  IF(ALLOCATED(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM)) THEN
4783  DO solver_matrix_idx=1,SIZE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM,1)
4784  CALL solvermapping_equatstosolmatmapssmfinalise(equations_set_to_solver_map% &
4785  & equations_to_solver_matrix_maps_sm(solver_matrix_idx),err,error,*999)
4786  ENDDO !solver_matrix_idx
4787  DEALLOCATE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_SM)
4788  ENDIF
4789  IF(ALLOCATED(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM)) THEN
4790  DO equations_matrix_idx=1,SIZE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM,1)
4791  CALL solvermapping_equatstosolmatmapsemfinalise(equations_set_to_solver_map% &
4792  & equations_to_solver_matrix_maps_em(equations_matrix_idx),err,error,*999)
4793  ENDDO !equations_matrix_idx
4794  DEALLOCATE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM)
4795  ENDIF
4796  IF(ALLOCATED(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM)) THEN
4797  CALL solvermapping_equatstosolmatmapsjmfinalise(equations_set_to_solver_map% &
4798  & equations_to_solver_matrix_maps_jm,err,error,*999)
4799  DEALLOCATE(equations_set_to_solver_map%EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM)
4800  ENDIF
4801  IF(ALLOCATED(equations_set_to_solver_map%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS)) THEN
4802  DO row_idx=1,SIZE(equations_set_to_solver_map%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS,1)
4803  CALL solvermapping_equatsrowtosolrowsmapfinalise(equations_set_to_solver_map% &
4804  & equations_row_to_solver_rows_maps(row_idx),err,error,*999)
4805  ENDDO !row_idx
4806  DEALLOCATE(equations_set_to_solver_map%EQUATIONS_ROW_TO_SOLVER_ROWS_MAPS)
4807  ENDIF
4808 
4809  exits("SolverMapping_EquationsSetToSolverMapFinalise")
4810  RETURN
4811 999 errors("SolverMapping_EquationsSetToSolverMapFinalise",err,error)
4812  exits("SolverMapping_EquationsSetToSolverMapFinalise")
4813  RETURN 1
4814 
4816 
4817  !
4818  !================================================================================================================================
4819  !
4820 
4822  SUBROUTINE solvermapping_equationssettosolvermapinitialise(EQUATIONS_SET_TO_SOLVER_MAP,ERR,ERROR,*)
4824  !Argument variables
4825  TYPE(equations_set_to_solver_map_type) :: EQUATIONS_SET_TO_SOLVER_MAP
4826  INTEGER(INTG), INTENT(OUT) :: ERR
4827  TYPE(varying_string), INTENT(OUT) :: ERROR
4828  !Local Variables
4829 
4830  enters("SolverMapping_EquationsSetToSolverMapInitialise",err,error,*999)
4831 
4832  equations_set_to_solver_map%EQUATIONS_SET_INDEX=0
4833  NULLIFY(equations_set_to_solver_map%SOLVER_MAPPING)
4834  NULLIFY(equations_set_to_solver_map%EQUATIONS)
4835  equations_set_to_solver_map%NUMBER_OF_INTERFACE_CONDITIONS=0
4836 
4837  exits("SolverMapping_EquationsSetToSolverMapInitialise")
4838  RETURN
4839 999 errors("SolverMapping_EquationsSetToSolverMapInitialise",err,error)
4840  exits("SolverMapping_EquationsSetToSolverMapInitialise")
4841  RETURN 1
4842 
4844 
4845  !
4846  !================================================================================================================================
4847  !
4848 
4850  SUBROUTINE solvermapping_equationstosolvermapsfinalise(EQUATIONS_TO_SOLVER_MAP,ERR,ERROR,*)
4852  !Argument variables
4853  TYPE(equations_to_solver_maps_type), POINTER :: EQUATIONS_TO_SOLVER_MAP
4854  INTEGER(INTG), INTENT(OUT) :: ERR
4855  TYPE(varying_string), INTENT(OUT) :: ERROR
4856  !Local Variables
4857  INTEGER(INTG) :: column_idx
4858 
4859  enters("SolverMapping_EquationsToSolverMapsFinalise",err,error,*999)
4860 
4861  IF(ASSOCIATED(equations_to_solver_map)) THEN
4862  IF(ALLOCATED(equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP)) THEN
4863  DO column_idx=1,SIZE(equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP,1)
4864  CALL solvermapping_equatscoltosolcolsmapfinalise(equations_to_solver_map% &
4865  & equations_col_to_solver_cols_map(column_idx),err,error,*999)
4866  ENDDO !column_idx
4867  DEALLOCATE(equations_to_solver_map%EQUATIONS_COL_TO_SOLVER_COLS_MAP)
4868  ENDIF
4869  ENDIF
4870 
4871  exits("SolverMapping_EquationsToSolverMapsFinalise")
4872  RETURN
4873 999 errorsexits("SolverMapping_EquationsToSolverMapsFinalise",err,error)
4874  RETURN 1
4875 
4877 
4878  !
4879  !================================================================================================================================
4880  !
4881 
4883  SUBROUTINE solvermapping_equationstosolvermapsinitialise(EQUATIONS_TO_SOLVER_MAP,ERR,ERROR,*)
4885  !Argument variables
4886  TYPE(equations_to_solver_maps_type), POINTER :: EQUATIONS_TO_SOLVER_MAP
4887  INTEGER(INTG), INTENT(OUT) :: ERR
4888  TYPE(varying_string), INTENT(OUT) :: ERROR
4889  !Local Variables
4890 
4891  enters("SolverMapping_EquationsToSolverMapsInitialise",err,error,*999)
4892 
4893  IF(ASSOCIATED(equations_to_solver_map)) THEN
4894  equations_to_solver_map%EQUATIONS_MATRIX_TYPE=0
4895  equations_to_solver_map%EQUATIONS_MATRIX_NUMBER=0
4896  equations_to_solver_map%SOLVER_MATRIX_NUMBER=0
4897  NULLIFY(equations_to_solver_map%EQUATIONS_MATRIX)
4898  NULLIFY(equations_to_solver_map%SOLVER_MATRIX)
4899  ELSE
4900  CALL flagerror("Equations to solver map is not associated.",err,error,*999)
4901  ENDIF
4902 
4903  exits("SolverMapping_EquationsToSolverMapsInitialise")
4904  RETURN
4905 999 errors("SolverMapping_EquationsToSolverMapsInitialise",err,error)
4906  exits("SolverMapping_EquationsToSolverMapsInitialise")
4907  RETURN 1
4908 
4910 
4911  !
4912  !================================================================================================================================
4913  !
4914 
4916  SUBROUTINE solvermapping_equationstosolverinterfacefinalise(EQUATIONS_TO_SOLVER_INTERFACE_MAP,ERR,ERROR,*)
4918  !Argument variables
4919  TYPE(equations_to_solver_matrix_maps_interface_type) :: EQUATIONS_TO_SOLVER_INTERFACE_MAP
4920  INTEGER(INTG), INTENT(OUT) :: ERR
4921  TYPE(varying_string), INTENT(OUT) :: ERROR
4922  !Local Variables
4923 
4924  enters("SolverMapping_EquationsToSolverInterfaceFinalise",err,error,*999)
4925 
4926  equations_to_solver_interface_map%INTERFACE_CONDITION_INDEX=0
4927  NULLIFY(equations_to_solver_interface_map%INTERFACE_CONDITION)
4928  equations_to_solver_interface_map%INTERFACE_MATRIX_NUMBER=0
4929 
4930  exits("SolverMapping_EquationsToSolverInterfaceFinalise")
4931  RETURN
4932 999 errors("SolverMapping_EquationsToSolverInterfaceFinalise",err,error)
4933  exits("SolverMapping_EquationsToSolverInterfaceFinalise")
4934  RETURN 1
4935 
4937 
4938  !
4939  !================================================================================================================================
4940  !
4941 
4943  SUBROUTINE solvermapping_equationstosolverinterfaceinitialise(EQUATIONS_TO_SOLVER_INTERFACE_MAP,ERR,ERROR,*)
4945  !Argument variables
4946  TYPE(equations_to_solver_matrix_maps_interface_type) :: EQUATIONS_TO_SOLVER_INTERFACE_MAP
4947  INTEGER(INTG), INTENT(OUT) :: ERR
4948  TYPE(varying_string), INTENT(OUT) :: ERROR
4949  !Local Variables
4950 
4951  enters("SolverMapping_EquationsToSolverInterfaceInitialise",err,error,*999)
4952 
4953  equations_to_solver_interface_map%INTERFACE_CONDITION_INDEX=0
4954  NULLIFY(equations_to_solver_interface_map%INTERFACE_CONDITION)
4955  equations_to_solver_interface_map%INTERFACE_MATRIX_NUMBER=0
4956 
4957  exits("SolverMapping_EquationsToSolverInterfaceInitialise")
4958  RETURN
4959 999 errors("SolverMapping_EquationsToSolverInterfaceInitialise",err,error)
4960  exits("SolverMapping_EquationsToSolverInterfaceInitialise")
4961  RETURN 1
4962 
4964 
4965  !
4966  !================================================================================================================================
4967  !
4968 
4970  SUBROUTINE solvermapping_equatstosolmatmapsemfinalise(EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM,ERR,ERROR,*)
4972  !Argument variables
4973  TYPE(equations_to_solver_matrix_maps_em_type) :: EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM
4974  INTEGER(INTG), INTENT(OUT) :: ERR
4975  TYPE(varying_string), INTENT(OUT) :: ERROR
4976  !Local Variables
4977  INTEGER(INTG) :: matrix_idx
4978 
4979  enters("SolverMapping_EquatsToSolMatMapsEMFinalise",err,error,*999)
4980 
4981  IF(ALLOCATED(equations_to_solver_matrix_maps_em%EQUATIONS_TO_SOLVER_MATRIX_MAPS)) THEN
4982  DO matrix_idx=1,SIZE(equations_to_solver_matrix_maps_em%EQUATIONS_TO_SOLVER_MATRIX_MAPS,1)
4983  CALL solvermapping_equationstosolvermapsfinalise(equations_to_solver_matrix_maps_em% &
4984  & equations_to_solver_matrix_maps(matrix_idx)%PTR,err,error,*999)
4985  ENDDO !variable_idx
4986  DEALLOCATE(equations_to_solver_matrix_maps_em%EQUATIONS_TO_SOLVER_MATRIX_MAPS)
4987  ENDIF
4988 
4989  exits("SolverMapping_EquatsToSolMatMapsEMFinalise")
4990  RETURN
4991 999 errorsexits("SolverMapping_EquatsToSolMatMapsEMFinalise",err,error)
4992  RETURN 1
4993 
4995 
4996  !
4997  !================================================================================================================================
4998  !
4999 
5001  SUBROUTINE solvermapping_equatstosolmatmapseminitialise(EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM,ERR,ERROR,*)
5003  !Argument variables
5004  TYPE(equations_to_solver_matrix_maps_em_type) :: EQUATIONS_TO_SOLVER_MATRIX_MAPS_EM
5005  INTEGER(INTG), INTENT(OUT) :: ERR
5006  TYPE(varying_string), INTENT(OUT) :: ERROR
5007  !Local Variables
5008 
5009  enters("SolverMapping_EquatsToSolMatMapsEMInitialise",err,error,*999)
5010 
5011  equations_to_solver_matrix_maps_em%EQUATIONS_MATRIX_NUMBER=0
5012  equations_to_solver_matrix_maps_em%NUMBER_OF_SOLVER_MATRICES=0
5013 
5014  exits("SolverMapping_EquatsToSolMatMapsEMInitialise")
5015  RETURN
5016 999 errors("SolverMapping_EquatsToSolMatMapsEMInitialise",err,error)
5017  exits("SolverMapping_EquatsToSolMatMapsEMInitialise")
5018  RETURN 1
5019 
5021 
5022  !
5023  !================================================================================================================================
5024  !
5025 
5027  SUBROUTINE solvermapping_equatstosolmatmapsjmfinalise(EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM,ERR,ERROR,*)
5029  !Argument variables
5030  TYPE(jacobian_to_solver_map_ptr_type), ALLOCATABLE, INTENT(IN) :: EQUATIONS_TO_SOLVER_MATRIX_MAPS_JM(:)
5031  INTEGER(INTG), INTENT(OUT) :: ERR
5032  TYPE(varying_string), INTENT(OUT) :: ERROR
5033  !Local Variables
5034  INTEGER(INTG) :: equations_matrix_idx
5035 
5036  enters("SolverMapping_EquatsToSolMatMapsJMFinalise",err,error,*999)
5037 
5038  IF(ALLOCATED(equations_to_solver_matrix_maps_jm)) THEN
5039  DO equations_matrix_idx=1,SIZE(equations_to_solver_matrix_maps_jm,1)