-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnonlinear_poisson_equation.F90
More file actions
521 lines (448 loc) · 24.7 KB
/
Copy pathnonlinear_poisson_equation.F90
File metadata and controls
521 lines (448 loc) · 24.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
PROGRAM NONLINEAR_POISSON_EQUATION
USE OpenCMISS
USE OpenCMISS_Iron
#ifndef NOMPIMOD
USE MPI
#endif
#ifdef WIN32
USE IFQWIN
#endif
IMPLICIT NONE
#ifdef NOMPIMOD
#include "mpif.h"
#endif
!-----------------------------------------------------------------------------------------------------------
! PROGRAM VARIABLES AND TYPES
!-----------------------------------------------------------------------------------------------------------
!Test program parameters
REAL(CMISSRP), PARAMETER :: HEIGHT=0.5_CMISSRP
REAL(CMISSRP), PARAMETER :: WIDTH=0.5_CMISSRP
REAL(CMISSRP), PARAMETER :: LENGTH=1.0_CMISSRP
INTEGER(CMISSIntg), PARAMETER :: CoordinateSystemUserNumber=1
INTEGER(CMISSIntg), PARAMETER :: RegionUserNumber=2
INTEGER(CMISSIntg), PARAMETER :: BasisUserNumber=3
INTEGER(CMISSIntg), PARAMETER :: GeneratedMeshUserNumber=4
INTEGER(CMISSIntg), PARAMETER :: MeshUserNumber=5
INTEGER(CMISSIntg), PARAMETER :: DecompositionUserNumber=6
INTEGER(CMISSIntg), PARAMETER :: GeometricFieldUserNumber=7
INTEGER(CMISSIntg), PARAMETER :: DependentFieldUserNumber=8
INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumber=9
INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumber=11
INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=12
INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=13
!Program variables
INTEGER(CMISSIntg) :: NUMBER_DIMENSIONS,INTERPOLATION_TYPE,NUMBER_OF_GAUSS_XI
INTEGER(CMISSIntg) :: NUMBER_GLOBAL_X_ELEMENTS,NUMBER_GLOBAL_Y_ELEMENTS,NUMBER_GLOBAL_Z_ELEMENTS
INTEGER(CMISSIntg) :: component_idx,parameter_idx
INTEGER(CMISSIntg) :: NUMBER_OF_ARGUMENTS,ARGUMENT_LENGTH,STATUS
CHARACTER(LEN=255) :: COMMAND_ARGUMENT
INTEGER(CMISSIntg),ALLOCATABLE :: LeftSurfaceNodes(:)
INTEGER(CMISSIntg),ALLOCATABLE :: RightSurfaceNodes(:)
INTEGER(CMISSIntg) :: LeftNormalXi,RightNormalXi
!INTEGER(CMISSIntg) :: FirstNodeNumber,LastNodeNumber,FirstNodeDomain,LastNodeDomain
INTEGER(CMISSIntg) :: node_idx,NodeNumber,NodeDomain
LOGICAL :: EXPORT_FIELD
!CMISS variables
TYPE(cmfe_BasisType) :: Basis
TYPE(cmfe_BoundaryConditionsType) :: BoundaryConditions
TYPE(cmfe_CoordinateSystemType) :: CoordinateSystem,WorldCoordinateSystem
TYPE(cmfe_DecompositionType) :: Decomposition
TYPE(cmfe_EquationsType) :: Equations
TYPE(cmfe_EquationsSetType) :: EquationsSet
TYPE(cmfe_FieldType) :: GeometricField,DependentField,MaterialsField
TYPE(cmfe_FieldsType) :: Fields
TYPE(cmfe_GeneratedMeshType) :: GeneratedMesh
TYPE(cmfe_MeshType) :: Mesh
TYPE(cmfe_ProblemType) :: Problem
TYPE(cmfe_RegionType) :: Region,WorldRegion
TYPE(cmfe_SolverType) :: Solver,LinearSolver
TYPE(cmfe_SolverEquationsType) :: SolverEquations
TYPE(cmfe_FieldType) :: EquationsSetField
!Generic CMISS variables
INTEGER(CMISSIntg) :: EquationsSetIndex
INTEGER(CMISSIntg) :: Err
INTEGER(CMISSIntg) :: NumberOfComputationalNodes,ComputationalNodeNumber
#ifdef WIN32
!Quickwin type
LOGICAL :: QUICKWIN_STATUS=.FALSE.
TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
!Initialise QuickWin
QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
!Set the window parameters
QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
!If attempt fails set with system estimated values
IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
#endif
!Get input arguments
NUMBER_OF_ARGUMENTS = COMMAND_ARGUMENT_COUNT()
IF(NUMBER_OF_ARGUMENTS >= 4) THEN
!If we have enough arguments then use the first four for setting up the problem. The subsequent arguments may be used to
!pass flags to, say, PETSc.
CALL GET_COMMAND_ARGUMENT(1,COMMAND_ARGUMENT,ARGUMENT_LENGTH,STATUS)
IF(STATUS>0) CALL HANDLE_ERROR("Error for command argument 1.")
READ(COMMAND_ARGUMENT(1:ARGUMENT_LENGTH),*) NUMBER_GLOBAL_X_ELEMENTS
IF(NUMBER_GLOBAL_X_ELEMENTS<=0) CALL HANDLE_ERROR("Invalid number of X elements.")
CALL GET_COMMAND_ARGUMENT(2,COMMAND_ARGUMENT,ARGUMENT_LENGTH,STATUS)
IF(STATUS>0) CALL HANDLE_ERROR("Error for command argument 2.")
READ(COMMAND_ARGUMENT(1:ARGUMENT_LENGTH),*) NUMBER_GLOBAL_Y_ELEMENTS
IF(NUMBER_GLOBAL_Y_ELEMENTS<0) CALL HANDLE_ERROR("Invalid number of Y elements.")
CALL GET_COMMAND_ARGUMENT(3,COMMAND_ARGUMENT,ARGUMENT_LENGTH,STATUS)
IF(STATUS>0) CALL HANDLE_ERROR("Error for command argument 3.")
READ(COMMAND_ARGUMENT(1:ARGUMENT_LENGTH),*) NUMBER_GLOBAL_Z_ELEMENTS
IF(NUMBER_GLOBAL_Z_ELEMENTS<0) CALL HANDLE_ERROR("Invalid number of Z elements.")
CALL GET_COMMAND_ARGUMENT(4,COMMAND_ARGUMENT,ARGUMENT_LENGTH,STATUS)
IF(STATUS>0) CALL HANDLE_ERROR("Error for command argument 4.")
READ(COMMAND_ARGUMENT(1:ARGUMENT_LENGTH),*) INTERPOLATION_TYPE
IF(INTERPOLATION_TYPE<=0) CALL HANDLE_ERROR("Invalid Interpolation specification.")
IF(NUMBER_GLOBAL_Z_ELEMENTS>0) THEN
NUMBER_DIMENSIONS=3
ELSEIF(NUMBER_GLOBAL_Y_ELEMENTS>0) THEN
NUMBER_DIMENSIONS=2
ELSE
NUMBER_DIMENSIONS=1
ENDIF
ELSE
!If there are not enough arguments default the problem specification
NUMBER_DIMENSIONS=2
NUMBER_GLOBAL_X_ELEMENTS=5
NUMBER_GLOBAL_Y_ELEMENTS=5
NUMBER_GLOBAL_Z_ELEMENTS=0
INTERPOLATION_TYPE=1
ENDIF
!Intialise OpenCMISS
CALL cmfe_Initialise(WorldCoordinateSystem,WorldRegion,Err)
!Trap all errors
CALL cmfe_ErrorHandlingModeSet(CMFE_ERRORS_TRAP_ERROR,Err)
!Output to a file
CALL cmfe_OutputSetOn("nonlinear_poisson_equation",Err)
!Get the computational nodes information
CALL cmfe_ComputationalNumberOfNodesGet(numberOfComputationalNodes,err)
CALL cmfe_ComputationalNodeNumberGet(computationalNodeNumber,err)
!-----------------------------------------------------------------------------------------------------------
! COORDINATE SYSTEM
!-----------------------------------------------------------------------------------------------------------
!Start the creation of a new RC coordinate system
CALL cmfe_CoordinateSystem_Initialise(CoordinateSystem,Err)
CALL cmfe_CoordinateSystem_CreateStart(CoordinateSystemUserNumber,CoordinateSystem,Err)
!Set the coordinate system number of dimensions
CALL cmfe_CoordinateSystem_DimensionSet(CoordinateSystem,NUMBER_DIMENSIONS,Err)
!Set the origin
CALL cmfe_CoordinateSystem_OriginSet(CoordinateSystemUserNumber,[0.0_CMISSRP,0.0_CMISSRP,0.0_CMISSRP],Err)
!Finish the creation of the coordinate system
CALL cmfe_CoordinateSystem_CreateFinish(CoordinateSystem,Err)
!-----------------------------------------------------------------------------------------------------------
! REGION
!-----------------------------------------------------------------------------------------------------------
!Start the creation of the region
CALL cmfe_Region_Initialise(Region,Err)
CALL cmfe_Region_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
CALL cmfe_Region_LabelSet(Region,"nonlinear_poisson_equation",Err)
!Set the regions coordinate system to the 2D RC coordinate system that we have created
CALL cmfe_Region_CoordinateSystemSet(Region,CoordinateSystem,Err)
!Finish the creation of the region
CALL cmfe_Region_CreateFinish(Region,Err)
!-----------------------------------------------------------------------------------------------------------
! BASIS
!-----------------------------------------------------------------------------------------------------------
!Start the creation of a basis (default is trilinear lagrange)
CALL cmfe_Basis_Initialise(Basis,Err)
CALL cmfe_Basis_CreateStart(BasisUserNumber,Basis,Err)
CALL cmfe_Basis_NumberOfXiSet(Basis,NUMBER_DIMENSIONS,Err)
SELECT CASE(INTERPOLATION_TYPE)
CASE(1,2,3,4)
CALL cmfe_Basis_TypeSet(Basis,CMFE_BASIS_LAGRANGE_HERMITE_TP_TYPE,Err)
CASE(7,8,9)
CALL cmfe_Basis_TypeSet(Basis,CMFE_BASIS_SIMPLEX_TYPE,Err)
CASE DEFAULT
CALL HANDLE_ERROR("Invalid interpolation type.")
END SELECT
SELECT CASE(INTERPOLATION_TYPE)
CASE(1)
NUMBER_OF_GAUSS_XI=2
CASE(2)
NUMBER_OF_GAUSS_XI=3
CASE(3,4)
NUMBER_OF_GAUSS_XI=4
CASE DEFAULT
NUMBER_OF_GAUSS_XI=0
END SELECT
IF(NUMBER_DIMENSIONS==1) THEN
CALL cmfe_Basis_InterpolationXiSet(Basis,[INTERPOLATION_TYPE],Err)
IF(NUMBER_OF_GAUSS_XI>0) THEN
CALL cmfe_Basis_QuadratureNumberOfGaussXiSet(Basis,[NUMBER_OF_GAUSS_XI],Err)
ENDIF
ELSEIF(NUMBER_DIMENSIONS==2) THEN
CALL cmfe_Basis_InterpolationXiSet(Basis,[INTERPOLATION_TYPE,INTERPOLATION_TYPE],Err)
IF(NUMBER_OF_GAUSS_XI>0) THEN
CALL cmfe_Basis_QuadratureNumberOfGaussXiSet(Basis,[NUMBER_OF_GAUSS_XI,NUMBER_OF_GAUSS_XI],Err)
ENDIF
ELSE
CALL cmfe_Basis_InterpolationXiSet(Basis,[INTERPOLATION_TYPE,INTERPOLATION_TYPE,INTERPOLATION_TYPE],Err)
IF(NUMBER_OF_GAUSS_XI>0) THEN
CALL cmfe_Basis_QuadratureNumberOfGaussXiSet(Basis,[NUMBER_OF_GAUSS_XI,NUMBER_OF_GAUSS_XI,NUMBER_OF_GAUSS_XI],Err)
ENDIF
ENDIF
!Finish the creation of the basis
CALL cmfe_Basis_CreateFinish(Basis,Err)
!-----------------------------------------------------------------------------------------------------------
! MESH
!-----------------------------------------------------------------------------------------------------------
!Start the creation of a generated mesh in the region
CALL cmfe_GeneratedMesh_Initialise(GeneratedMesh,Err)
CALL cmfe_GeneratedMesh_CreateStart(GeneratedMeshUserNumber,Region,GeneratedMesh,Err)
!Set up a regular x*y*z mesh
CALL cmfe_GeneratedMesh_TypeSet(GeneratedMesh,CMFE_GENERATED_MESH_REGULAR_MESH_TYPE,Err)
!Set the default basis
CALL cmfe_GeneratedMesh_BasisSet(GeneratedMesh,Basis,Err)
!Define the mesh on the region
IF(NUMBER_DIMENSIONS==1) THEN
CALL cmfe_GeneratedMesh_ExtentSet(GeneratedMesh,[WIDTH],Err)
CALL cmfe_GeneratedMesh_NumberOfElementsSet(GeneratedMesh,[NUMBER_GLOBAL_X_ELEMENTS],Err)
ELSEIF(NUMBER_DIMENSIONS==2) THEN
CALL cmfe_GeneratedMesh_ExtentSet(GeneratedMesh,[WIDTH,HEIGHT],Err)
CALL cmfe_GeneratedMesh_NumberOfElementsSet(GeneratedMesh,[NUMBER_GLOBAL_X_ELEMENTS,NUMBER_GLOBAL_Y_ELEMENTS],Err)
ELSE
CALL cmfe_GeneratedMesh_ExtentSet(GeneratedMesh,[WIDTH,HEIGHT,LENGTH],Err)
CALL cmfe_GeneratedMesh_NumberOfElementsSet(GeneratedMesh,[NUMBER_GLOBAL_X_ELEMENTS,NUMBER_GLOBAL_Y_ELEMENTS, &
& NUMBER_GLOBAL_Z_ELEMENTS],Err)
ENDIF
!Finish the creation of a generated mesh in the region
CALL cmfe_Mesh_Initialise(Mesh,Err)
CALL cmfe_GeneratedMesh_CreateFinish(GeneratedMesh,MeshUserNumber,Mesh,Err)
!-----------------------------------------------------------------------------------------------------------
! DECOMPOSITION
!-----------------------------------------------------------------------------------------------------------
!Create a decomposition
CALL cmfe_Decomposition_Initialise(Decomposition,Err)
CALL cmfe_Decomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition,Err)
!Set the decomposition to be a general decomposition with the specified number of domains
CALL cmfe_Decomposition_TypeSet(Decomposition,CMFE_DECOMPOSITION_CALCULATED_TYPE,Err)
CALL cmfe_Decomposition_NumberOfDomainsSet(Decomposition,NumberOfComputationalNodes,Err)
!Finish the decomposition
CALL cmfe_Decomposition_CreateFinish(Decomposition,Err)
!-----------------------------------------------------------------------------------------------------------
! GEOMETRIC FIELD
!-----------------------------------------------------------------------------------------------------------
!Start to create a default (geometric) field on the region
CALL cmfe_Field_Initialise(GeometricField,Err)
CALL cmfe_Field_CreateStart(GeometricFieldUserNumber,Region,GeometricField,Err)
!Set the decomposition to use
CALL cmfe_Field_MeshDecompositionSet(GeometricField,Decomposition,Err)
!Set the domain to be used by the field components.
DO component_idx=1,NUMBER_DIMENSIONS
CALL cmfe_Field_ComponentMeshComponentSet(GeometricField,CMFE_FIELD_U_VARIABLE_TYPE,component_idx,1,Err)
ENDDO
!Finish creating the field
CALL cmfe_Field_CreateFinish(GeometricField,Err)
!Update the geometric field parameters
CALL cmfe_GeneratedMesh_GeometricParametersCalculate(GeneratedMesh,GeometricField,Err)
!-----------------------------------------------------------------------------------------------------------
! MATERIAL FIELD
!-----------------------------------------------------------------------------------------------------------
!Create a material field for diagonal components of the rank-2 tensor K and scalars a, b and c in the source term.
CALL cmfe_Field_Initialise(MaterialsField,Err)
CALL cmfe_Field_CreateStart(MaterialsFieldUserNumber,Region,MaterialsField,Err)
!Set the decomposition to use
CALL cmfe_Field_MeshDecompositionSet(MaterialsField,Decomposition,Err)
!Set the type
CALL cmfe_Field_TypeSet(MaterialsField,CMFE_FIELD_MATERIAL_TYPE,Err)
!One field variable with five(2D)/six(3D) components
CALL cmfe_Field_NumberOfVariablesSet(MaterialsField,1,Err)
CALL cmfe_Field_NumberOfComponentsSet(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,NUMBER_DIMENSIONS+3,Err)
DO parameter_idx=1,NUMBER_DIMENSIONS+3
CALL cmfe_Field_ComponentMeshComponentSet(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,parameter_idx,1,Err)
ENDDO
!Set associated geometric field
CALL cmfe_Field_GeometricFieldSet(MaterialsField,GeometricField,Err)
!Set the label of the field
CALL cmfe_Field_VariableLabelSet(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,"Parameters",Err)
!Finish creating the field
CALL cmfe_Field_CreateFinish(MaterialsField,Err)
!Update material field components
!Rank-2 K tensor diagonal components:
DO component_idx=1,NUMBER_DIMENSIONS
CALL cmfe_Field_ComponentValuesInitialise(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& component_idx,1.0_CMISSRP,Err)
ENDDO
!a parameter:
CALL cmfe_Field_ComponentValuesInitialise(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& NUMBER_DIMENSIONS+1,1.0_CMISSRP,Err)
!b parameter:
CALL cmfe_Field_ComponentValuesInitialise(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& NUMBER_DIMENSIONS+2,0.5_CMISSRP,Err)
!c parameter:
CALL cmfe_Field_ComponentValuesInitialise(MaterialsField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& NUMBER_DIMENSIONS+3,1.0_CMISSRP,Err)
!-----------------------------------------------------------------------------------------------------------
! DEPENDENT FIELD
!-----------------------------------------------------------------------------------------------------------
!Create dependent fields
CALL cmfe_Field_Initialise(DependentField,Err)
CALL cmfe_Field_CreateStart(DependentFieldUserNumber,Region,DependentField,Err)
!Set the decomposition to use
CALL cmfe_Field_MeshDecompositionSet(DependentField,Decomposition,Err)
!Set the type
CALL cmfe_Field_TypeSet(DependentField,CMFE_FIELD_GENERAL_TYPE,Err)
CALL cmfe_Field_DependentTypeSet(DependentField,CMFE_FIELD_DEPENDENT_TYPE,Err)
!Set associated geometric field
CALL cmfe_Field_GeometricFieldSet(DependentField,GeometricField,Err)
!Two dependent variables: primary variable 'U' and secondary variable 'DELUDELN'
CALL cmfe_Field_NumberOfVariablesSet(DependentField,2,Err)
CALL cmfe_Field_DimensionSet(DependentField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_SCALAR_DIMENSION_TYPE,Err)
CALL cmfe_Field_DimensionSet(DependentField,CMFE_FIELD_DELUDELN_VARIABLE_TYPE,CMFE_FIELD_SCALAR_DIMENSION_TYPE,Err)
CALL cmfe_Field_DOFOrderTypeSet(DependentField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_SEPARATED_COMPONENT_DOF_ORDER,Err)
CALL cmfe_Field_DOFOrderTypeSet(DependentField,CMFE_FIELD_DELUDELN_VARIABLE_TYPE,CMFE_FIELD_SEPARATED_COMPONENT_DOF_ORDER,Err)
!Set appropriate labels
CALL cmfe_Field_VariableLabelSet(DependentField,CMFE_FIELD_U_VARIABLE_TYPE,"U",Err)
CALL cmfe_Field_VariableLabelSet(DependentField,CMFE_FIELD_DELUDELN_VARIABLE_TYPE,"DELUDELN",Err)
!Finish creating the field
CALL cmfe_Field_CreateFinish(DependentField,Err)
!Update dependent fields (initial guess for iterative solver)
CALL cmfe_Field_ComponentValuesInitialise(DependentField,CMFE_FIELD_U_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& 1,0.5_CMISSRP,Err)
CALL cmfe_Field_ComponentValuesInitialise(DependentField,CMFE_FIELD_DELUDELN_VARIABLE_TYPE,CMFE_FIELD_VALUES_SET_TYPE, &
& 1,0.1_CMISSRP,Err)
!-----------------------------------------------------------------------------------------------------------
! EQUATIONS SETS
!-----------------------------------------------------------------------------------------------------------
!Create the equations_sets
CALL cmfe_EquationsSet_Initialise(EquationsSet,Err)
CALL cmfe_Field_Initialise(EquationsSetField,Err)
!Poisson equation with exponential (nonlinear) source term
CALL cmfe_EquationsSet_CreateStart(EquationsSetUserNumber,Region,GeometricField,[CMFE_EQUATIONS_SET_CLASSICAL_FIELD_CLASS, &
& CMFE_EQUATIONS_SET_POISSON_EQUATION_TYPE,CMFE_EQUATIONS_SET_EXPONENTIAL_SOURCE_POISSON_SUBTYPE], &
& EquationsSetFieldUserNumber,EquationsSetField,EquationsSet,Err)
!Finish creating eqiations sets
CALL cmfe_EquationsSet_CreateFinish(EquationsSet,Err)
!Attach dependent field already created to equation sets
CALL cmfe_EquationsSet_DependentCreateStart(EquationsSet,DependentFieldUserNumber,DependentField,Err)
CALL cmfe_EquationsSet_DependentCreateFinish(EquationsSet,Err)
!Attach material field already created to equation sets
CALL cmfe_EquationsSet_MaterialsCreateStart(EquationsSet,MaterialsFieldUserNumber,MaterialsField,Err)
CALL cmfe_EquationsSet_MaterialsCreateFinish(EquationsSet,Err)
!-----------------------------------------------------------------------------------------------------------
! EQUATIONS
!-----------------------------------------------------------------------------------------------------------
!Create the equations set equations
CALL cmfe_Equations_Initialise(Equations,Err)
CALL cmfe_EquationsSet_EquationsCreateStart(EquationsSet,Equations,Err)
!Set the equations matrices sparsity type
CALL cmfe_Equations_SparsityTypeSet(Equations,CMFE_EQUATIONS_SPARSE_MATRICES,Err)
!Set the equations set output
CALL cmfe_Equations_OutputTypeSet(Equations,CMFE_EQUATIONS_NO_OUTPUT,Err)
!Finish the equations set equations
CALL cmfe_EquationsSet_EquationsCreateFinish(EquationsSet,Err)
!-----------------------------------------------------------------------------------------------------------
! PROBLEM
!-----------------------------------------------------------------------------------------------------------
!Start the creation of a problem.
CALL cmfe_Problem_Initialise(Problem,Err)
CALL cmfe_Problem_CreateStart(ProblemUserNumber,[CMFE_PROBLEM_CLASSICAL_FIELD_CLASS,CMFE_PROBLEM_POISSON_EQUATION_TYPE, &
& CMFE_PROBLEM_NONLINEAR_SOURCE_POISSON_SUBTYPE],Problem,Err)
!Finish the creation of a problem.
CALL cmfe_Problem_CreateFinish(Problem,Err)
!Start the creation of the problem control loop
CALL cmfe_Problem_ControlLoopCreateStart(Problem,Err)
!Finish creating the problem control loop
CALL cmfe_Problem_ControlLoopCreateFinish(Problem,Err)
!-----------------------------------------------------------------------------------------------------------
! SOLVER
!-----------------------------------------------------------------------------------------------------------
!Start the creation of the problem solvers
CALL cmfe_Solver_Initialise(Solver,Err)
CALL cmfe_Solver_Initialise(LinearSolver,Err)
CALL cmfe_Problem_SolversCreateStart(Problem,Err)
CALL cmfe_Problem_SolverGet(Problem,CMFE_CONTROL_LOOP_NODE,1,Solver,Err)
!Set the solver output
!CALL cmfe_Solver_OutputTypeSet(Solver,CMFE_SOLVER_NO_OUTPUT,Err)
CALL cmfe_Solver_OutputTypeSet(Solver,CMFE_SOLVER_PROGRESS_OUTPUT,Err)
!CALL cmfe_Solver_OutputTypeSet(Solver,CMFE_SOLVER_TIMING_OUTPUT,Err)
!CALL cmfe_Solver_OutputTypeSet(Solver,CMFE_SOLVER_SOLVER_OUTPUT,Err)
!CALL cmfe_Solver_OutputTypeSet(Solver,CMFE_SOLVER_MATRIX_OUTPUT,Err)
!Set the Jacobian type
!CALL cmfe_Solver_NewtonJacobianCalculationTypeSet(Solver,CMFE_SOLVER_NEWTON_JACOBIAN_EQUATIONS_CALCULATED,Err)
CALL cmfe_Solver_NewtonJacobianCalculationTypeSet(Solver,CMFE_SOLVER_NEWTON_JACOBIAN_FD_CALCULATED,Err)
CALL cmfe_Solver_NewtonAbsoluteToleranceSet(Solver,1.0E-8_CMISSRP,Err)
CALL cmfe_Solver_NewtonRelativeToleranceSet(Solver,1.0E-8_CMISSRP,Err)
CALL cmfe_Solver_NewtonMaximumIterationsSet(Solver,100000,Err)
!Get the associated linear solver
CALL cmfe_Solver_NewtonLinearSolverGet(Solver,LinearSolver,Err)
CALL cmfe_Solver_LinearIterativeRelativeToleranceSet(LinearSolver,1.0E-8_CMISSRP,Err)
CALL cmfe_Solver_LinearIterativeAbsoluteToleranceSet(LinearSolver,1.0E-8_CMISSRP,Err)
CALL cmfe_Solver_LinearIterativeMaximumIterationsSet(LinearSolver,10000,Err)
!Finish the creation of the problem solver
CALL cmfe_Problem_SolversCreateFinish(Problem,Err)
!-----------------------------------------------------------------------------------------------------------
! SOLVER EQUATIONS
!-----------------------------------------------------------------------------------------------------------
!Start the creation of the problem solver equations
CALL cmfe_Solver_Initialise(Solver,Err)
CALL cmfe_SolverEquations_Initialise(SolverEquations,Err)
CALL cmfe_Problem_SolverEquationsCreateStart(Problem,Err)
!Get the solve equations
CALL cmfe_Problem_SolverGet(Problem,CMFE_CONTROL_LOOP_NODE,1,Solver,Err)
CALL cmfe_Solver_SolverEquationsGet(Solver,SolverEquations,Err)
!Set the solver equations sparsity
CALL cmfe_SolverEquations_SparsityTypeSet(SolverEquations,CMFE_SOLVER_SPARSE_MATRICES,Err)
!CALL cmfe_SolverEquations_SparsityTypeSet(SolverEquations,CMFE_SOLVER_FULL_MATRICES,Err)
!Add in the equations set
CALL cmfe_SolverEquations_EquationsSetAdd(SolverEquations,EquationsSet,EquationsSetIndex,Err)
!Finish the creation of the problem solver equations
CALL cmfe_Problem_SolverEquationsCreateFinish(Problem,Err)
!-----------------------------------------------------------------------------------------------------------
! BOUNDARY CONDITIONS
!-----------------------------------------------------------------------------------------------------------
!Set up the boundary conditions
CALL cmfe_BoundaryConditions_Initialise(BoundaryConditions,Err)
CALL cmfe_SolverEquations_BoundaryConditionsCreateStart(SolverEquations,BoundaryConditions,Err)
CALL cmfe_GeneratedMesh_SurfaceGet(GeneratedMesh,CMFE_GENERATED_MESH_REGULAR_LEFT_SURFACE,LeftSurfaceNodes,LeftNormalXi,Err)
CALL cmfe_GeneratedMesh_SurfaceGet(GeneratedMesh,CMFE_GENERATED_MESH_REGULAR_RIGHT_SURFACE,RightSurfaceNodes,RightNormalXi,Err)
!Set the fixed boundary conditions on opposide sides
DO node_idx=1,SIZE(LeftSurfaceNodes,1)
NodeNumber=LeftSurfaceNodes(node_idx)
CALL cmfe_Decomposition_NodeDomainGet(Decomposition,NodeNumber,1,NodeDomain,Err)
IF(NodeDomain==ComputationalNodeNumber) THEN
CALL cmfe_BoundaryConditions_SetNode(BoundaryConditions,DependentField,CMFE_FIELD_U_VARIABLE_TYPE,1,1,NodeNumber,1, &
& CMFE_BOUNDARY_CONDITION_FIXED,0.0_CMISSRP,Err)
ENDIF
ENDDO
DO node_idx=1,SIZE(RightSurfaceNodes,1)
NodeNumber=RightSurfaceNodes(node_idx)
CALL cmfe_Decomposition_NodeDomainGet(Decomposition,NodeNumber,1,NodeDomain,Err)
IF(NodeDomain==ComputationalNodeNumber) THEN
CALL cmfe_BoundaryConditions_SetNode(BoundaryConditions,DependentField,CMFE_FIELD_U_VARIABLE_TYPE,1,1,NodeNumber,1, &
& CMFE_BOUNDARY_CONDITION_FIXED,1.0_CMISSRP,Err)
ENDIF
ENDDO
!Finish the creation of the equations set boundary conditions
CALL cmfe_SolverEquations_BoundaryConditionsCreateFinish(SolverEquations,Err)
!-----------------------------------------------------------------------------------------------------------
! SOLVE
!-----------------------------------------------------------------------------------------------------------
!Solve the problem
CALL cmfe_Problem_Solve(Problem,Err)
!-----------------------------------------------------------------------------------------------------------
! OUTPUT
!-----------------------------------------------------------------------------------------------------------
!Export results
EXPORT_FIELD=.TRUE.
IF(EXPORT_FIELD) THEN
CALL cmfe_Fields_Initialise(Fields,Err)
CALL cmfe_Fields_Create(Region,Fields,Err)
CALL cmfe_Fields_NodesExport(Fields,"nonlinear_poisson_equation","FORTRAN",Err)
CALL cmfe_Fields_ElementsExport(Fields,"nonlinear_poisson_equation","FORTRAN",Err)
CALL cmfe_Fields_Finalise(Fields,Err)
ENDIF
!Finialise CMISS
CALL cmfe_Finalise(Err)
WRITE(*,'(A)') "Program successfully completed."
STOP
CONTAINS
SUBROUTINE HANDLE_ERROR(ERROR_STRING)
CHARACTER(LEN=*), INTENT(IN) :: ERROR_STRING
WRITE(*,'(">>ERROR: ",A)') ERROR_STRING(1:LEN_TRIM(ERROR_STRING))
STOP
END SUBROUTINE HANDLE_ERROR
END PROGRAM NONLINEAR_POISSON_EQUATION