PageRenderTime 59ms CodeModel.GetById 12ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 1ms

/ClassicalField/AdvectionDiffusion/AdvectionDiffusionIO/src/AdvectionDiffusionIOExample.f90

http://github.com/xyan075/examples
FORTRAN Modern | 710 lines | 362 code | 102 blank | 246 comment | 0 complexity | 33dc66122b9250cc8b8e49e949acb94e MD5 | raw file
  1!> \file
  2!> \author Chris Bradley
  3!> \brief This is an example program to solve an advection-diffusion equation using openCMISS calls.
  4!>
  5!> \section LICENSE
  6!>
  7!> Version: MPL 1.1/GPL 2.0/LGPL 2.1
  8!>
  9!> The contents of this file are subject to the Mozilla Public License
 10!> Version 1.1 (the "License"); you may not use this file except in
 11!> compliance with the License. You may obtain a copy of the License at
 12!> http://www.mozilla.org/MPL/
 13!>
 14!> Software distributed under the License is distributed on an "AS IS"
 15!> basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 16!> License for the specific language governing rights and limitations
 17!> under the License.
 18!>
 19!> The Original Code is openCMISS
 20!>
 21!> The Initial Developer of the Original Code is University of Auckland,
 22!> Auckland, New Zealand and University of Oxford, Oxford, United
 23!> Kingdom. Portions created by the University of Auckland and University
 24!> of Oxford are Copyright (C) 2007 by the University of Auckland and
 25!> the University of Oxford. All Rights Reserved.
 26!>
 27!> Contributor(s):
 28!>
 29!> Alternatively, the contents of this file may be used under the terms of
 30!> either the GNU General Public License Version 2 or later (the "GPL"), or
 31!> the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 32!> in which case the provisions of the GPL or the LGPL are applicable instead
 33!> of those above. If you wish to allow use of your version of this file only
 34!> under the terms of either the GPL or the LGPL, and not to allow others to
 35!> use your version of this file under the terms of the MPL, indicate your
 36!> decision by deleting the provisions above and replace them with the notice
 37!> and other provisions required by the GPL or the LGPL. If you do not delete
 38!> the provisions above, a recipient may use your version of this file under
 39!> the terms of any one of the MPL, the GPL or the LGPL.
 40!>
 41
 42!> \example ClassicalField/AdvectionDiffusion/AdvectionDiffusionIO/src/AdvectionDiffusionIOExample.f90
 43!! Example program to solve a diffusion equation using openCMISS calls.
 44!!
 45!! \htmlinclude ClassicalField/AdvectionDiffusion/AdvectionDiffusionIO/history.html
 46!<
 47
 48!> Main program
 49PROGRAM ADVECTIONDIFFUSIONIOEXAMPLE
 50
 51  !
 52  !================================================================================================================================
 53  !
 54
 55  !PROGRAM LIBRARIES
 56
 57  USE OPENCMISS
 58  USE FLUID_MECHANICS_IO_ROUTINES
 59  USE MPI
 60
 61#ifdef WIN32
 62  USE IFQWINCMISS
 63#endif
 64
 65  !
 66  !================================================================================================================================
 67  !
 68
 69  !PROGRAM VARIABLES AND TYPES
 70
 71  IMPLICIT NONE
 72
 73  INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=1337
 74  TYPE(CMISSFieldType) :: EquationsSetField
 75
 76
 77  !Test program parameters
 78
 79  INTEGER(CMISSIntg), PARAMETER :: CoordinateSystemUserNumber=1
 80  INTEGER(CMISSIntg), PARAMETER :: RegionUserNumber=2
 81  INTEGER(CMISSIntg), PARAMETER :: BasisUserNumber=3
 82  INTEGER(CMISSIntg), PARAMETER :: GeneratedMeshUserNumber=4
 83  INTEGER(CMISSIntg), PARAMETER :: MeshUserNumber=5
 84  INTEGER(CMISSIntg), PARAMETER :: DecompositionUserNumber=6
 85  INTEGER(CMISSIntg), PARAMETER :: GeometricFieldUserNumber=7
 86  INTEGER(CMISSIntg), PARAMETER :: DependentFieldUserNumberAdvecDiff=8
 87  INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumberAdvecDiff=9
 88  INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumberAdvecDiff=10
 89  INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=11
 90  INTEGER(CMISSIntg), PARAMETER :: ControlLoopNode=0
 91  INTEGER(CMISSIntg), PARAMETER :: IndependentFieldUserNumberAdvecDiff=12
 92  !INTEGER(CMISSIntg), PARAMETER :: AnalyticFieldUserNumber=13
 93  INTEGER(CMISSIntg), PARAMETER :: SourceFieldUserNumberAdvecDiff=14
 94  INTEGER(CMISSIntg), PARAMETER :: DomainUserNumber=1
 95
 96  !Program types
 97
 98  TYPE(EXPORT_CONTAINER):: CM
 99  
100  !Program variables
101
102  INTEGER(CMISSIntg) :: NUMBER_OF_DIMENSIONS
103
104  INTEGER(CMISSIntg) :: BASIS_TYPE
105  INTEGER(CMISSIntg) :: BASIS_NUMBER_SPACE
106  INTEGER(CMISSIntg) :: BASIS_NUMBER_CONCENTRATION
107  INTEGER(CMISSIntg) :: BASIS_XI_GAUSS_SPACE
108  INTEGER(CMISSIntg) :: BASIS_XI_GAUSS_CONCENTRATION
109  INTEGER(CMISSIntg) :: BASIS_XI_INTERPOLATION_SPACE
110  INTEGER(CMISSIntg) :: BASIS_XI_INTERPOLATION_CONCENTRATION
111  INTEGER(CMISSIntg) :: MESH_NUMBER_OF_COMPONENTS
112  INTEGER(CMISSIntg) :: MESH_COMPONENT_NUMBER_SPACE
113  INTEGER(CMISSIntg) :: MESH_COMPONENT_NUMBER_CONCENTRATION
114  INTEGER(CMISSIntg) :: NUMBER_OF_NODES_SPACE
115  INTEGER(CMISSIntg) :: NUMBER_OF_NODES_CONCENTRATION
116  INTEGER(CMISSIntg) :: NUMBER_OF_ELEMENT_NODES_SPACE
117  INTEGER(CMISSIntg) :: NUMBER_OF_ELEMENT_NODES_CONCENTRATION
118  INTEGER(CMISSIntg) :: TOTAL_NUMBER_OF_NODES
119  INTEGER(CMISSIntg) :: TOTAL_NUMBER_OF_ELEMENTS
120  INTEGER(CMISSIntg) :: MAXIMUM_ITERATIONS
121  INTEGER(CMISSIntg) :: RESTART_VALUE
122!  INTEGER(CMISSIntg) :: MPI_IERROR
123  INTEGER(CMISSIntg) :: NUMBER_OF_FIXED_WALL_NODES_ADVECTION_DIFFUSION
124  INTEGER(CMISSIntg) :: NUMBER_OF_INLET_WALL_NODES_ADVECTION_DIFFUSION
125
126  INTEGER(CMISSIntg) :: EQUATIONS_ADVECTION_DIFFUSION_OUTPUT
127  INTEGER(CMISSIntg) :: COMPONENT_NUMBER
128  INTEGER(CMISSIntg) :: NODE_NUMBER
129  INTEGER(CMISSIntg) :: ELEMENT_NUMBER
130  INTEGER(CMISSIntg) :: NODE_COUNTER
131  INTEGER(CMISSIntg) :: CONDITION
132
133  INTEGER(CMISSIntg) :: LINEAR_SOLVER_ADVECTION_DIFFUSION_OUTPUT_TYPE
134
135  INTEGER, ALLOCATABLE, DIMENSION(:):: FIXED_WALL_NODES_ADVECTION_DIFFUSION
136  INTEGER, ALLOCATABLE, DIMENSION(:):: INLET_WALL_NODES_ADVECTION_DIFFUSION
137
138  REAL(CMISSDP) :: INITIAL_FIELD_ADVECTION_DIFFUSION(3)
139  REAL(CMISSDP) :: BOUNDARY_CONDITIONS_ADVECTION_DIFFUSION(3)
140  REAL(CMISSDP) :: DIVERGENCE_TOLERANCE
141  REAL(CMISSDP) :: RELATIVE_TOLERANCE
142  REAL(CMISSDP) :: ABSOLUTE_TOLERANCE
143  REAL(CMISSDP) :: LINESEARCH_ALPHA
144  REAL(CMISSDP) :: VALUE
145  REAL(CMISSDP) :: DIFF_COEFF_PARAM_ADVECTION_DIFFUSION(3)
146
147  LOGICAL :: EXPORT_FIELD_IO
148  LOGICAL :: LINEAR_SOLVER_ADVECTION_DIFFUSION_DIRECT_FLAG
149  LOGICAL :: FIXED_WALL_NODES_ADVECTION_DIFFUSION_FLAG
150  LOGICAL :: INLET_WALL_NODES_ADVECTION_DIFFUSION_FLAG
151
152  !CMISS variables
153
154  !Regions
155  TYPE(CMISSRegionType) :: Region
156  TYPE(CMISSRegionType) :: WorldRegion
157  !Coordinate systems
158  TYPE(CMISSCoordinateSystemType) :: CoordinateSystem
159  TYPE(CMISSCoordinateSystemType) :: WorldCoordinateSystem
160  !Basis
161  TYPE(CMISSBasisType) :: BasisSpace
162  TYPE(CMISSBasisType) :: BasisConcentration
163  !Nodes
164  TYPE(CMISSNodesType) :: Nodes
165  !Elements
166  TYPE(CMISSMeshElementsType) :: MeshElementsSpace
167  TYPE(CMISSMeshElementsType) :: MeshElementsConcentration
168  !Meshes
169  TYPE(CMISSMeshType) :: Mesh
170  !Decompositions
171  TYPE(CMISSDecompositionType) :: Decomposition
172  !Fields
173  TYPE(CMISSFieldsType) :: Fields
174  !Field types
175  TYPE(CMISSFieldType) :: GeometricField
176  TYPE(CMISSFieldType) :: DependentFieldAdvecDiff
177  TYPE(CMISSFieldType) :: MaterialsFieldAdvecDiff
178  TYPE(CMISSFieldType) :: IndependentFieldAdvecDiff
179  TYPE(CMISSFieldType) :: SourceFieldAdvecDiff
180  !Boundary conditions
181  TYPE(CMISSBoundaryConditionsType) :: BoundaryConditionsAdvecDiff
182  !Equations sets
183  TYPE(CMISSEquationsSetType) :: EquationsSetAdvecDiff
184  !Equations
185  TYPE(CMISSEquationsType) :: EquationsAdvecDiff
186  !Problems
187  TYPE(CMISSProblemType) :: Problem
188  !Control loops
189  TYPE(CMISSControlLoopType) :: ControlLoop
190  !Solvers
191  TYPE(CMISSSolverType) :: SolverAdvecDiff, LinearSolverAdvecDiff
192  !Solver equations
193  TYPE(CMISSSolverEquationsType) :: SolverEquationsAdvecDiff
194
195
196#ifdef WIN32
197  !Quickwin type
198  LOGICAL :: QUICKWIN_STATUS=.FALSE.
199  TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
200#endif
201  
202  !Generic CMISS variables
203  
204  INTEGER(CMISSIntg) :: EquationsSetIndex
205  INTEGER(CMISSIntg) :: Err
206  
207#ifdef WIN32
208  !Initialise QuickWin
209  QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
210  QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
211  QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
212  !Set the window parameters
213  QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
214  !If attempt fails set with system estimated values
215  IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
216#endif
217
218  !
219  !================================================================================================================================
220  !
221
222  !INITIALISE OPENCMISS
223
224  CALL CMISSInitialise(WorldCoordinateSystem,WorldRegion,Err)
225
226  CALL CMISSErrorHandlingModeSet(CMISS_ERRORS_TRAP_ERROR,Err)
227
228  !
229  !================================================================================================================================
230  !
231
232  !PROBLEM CONTROL PANEL
233
234  !Import cmHeart mesh information
235  CALL FLUID_MECHANICS_IO_READ_CMHEART(CM,Err)  
236  BASIS_NUMBER_SPACE=CM%ID_M
237  BASIS_NUMBER_CONCENTRATION=CM%ID_V
238  NUMBER_OF_DIMENSIONS=CM%D
239  BASIS_TYPE=CM%IT_T
240  BASIS_XI_INTERPOLATION_SPACE=CM%IT_M
241  BASIS_XI_INTERPOLATION_CONCENTRATION=CM%IT_V
242  NUMBER_OF_NODES_SPACE=CM%N_M
243  NUMBER_OF_NODES_CONCENTRATION=CM%N_V
244  TOTAL_NUMBER_OF_NODES=CM%N_T
245  TOTAL_NUMBER_OF_ELEMENTS=CM%E_T
246  NUMBER_OF_ELEMENT_NODES_SPACE=CM%EN_M
247  NUMBER_OF_ELEMENT_NODES_CONCENTRATION=CM%EN_V
248  !Set initial values
249  INITIAL_FIELD_ADVECTION_DIFFUSION(1)=0.0_CMISSDP
250  INITIAL_FIELD_ADVECTION_DIFFUSION(2)=0.0_CMISSDP
251  INITIAL_FIELD_ADVECTION_DIFFUSION(3)=0.0_CMISSDP
252  !Set boundary conditions - what condition should be applied?
253  !Set boundary conditions
254  FIXED_WALL_NODES_ADVECTION_DIFFUSION_FLAG=.FALSE.
255  INLET_WALL_NODES_ADVECTION_DIFFUSION_FLAG=.TRUE.
256  IF(FIXED_WALL_NODES_ADVECTION_DIFFUSION_FLAG) THEN
257    NUMBER_OF_FIXED_WALL_NODES_ADVECTION_DIFFUSION=1
258    ALLOCATE(FIXED_WALL_NODES_ADVECTION_DIFFUSION(NUMBER_OF_FIXED_WALL_NODES_ADVECTION_DIFFUSION))
259    FIXED_WALL_NODES_ADVECTION_DIFFUSION=(/42/)
260  ENDIF
261  IF(INLET_WALL_NODES_ADVECTION_DIFFUSION_FLAG) THEN
262    NUMBER_OF_INLET_WALL_NODES_ADVECTION_DIFFUSION=105
263    ALLOCATE(INLET_WALL_NODES_ADVECTION_DIFFUSION(NUMBER_OF_INLET_WALL_NODES_ADVECTION_DIFFUSION))
264    INLET_WALL_NODES_ADVECTION_DIFFUSION=(/4,11,12,13,29,33,34,35,47,51,52,53,69,71,83,87,88,89,100,102,103,104,112,114,115, & 
265    & 116,126,128,137,141,142,143,154,156,157,158,166,168,169,170,180,182,191,195,196,197,208,210,211, & 
266    & 212,220,222,223,224,234,236,245,249,250,251,262,264,265,266,274,276,277,278,288,290,299,303,304, & 
267    & 305,316,318,319,320,328,330,331,332,342,344,353,357,358,359,370,372,373,374,382,384,385,386,396, & 
268    & 398,411,412,426,427,438,439,450/)
269
270    !Set initial boundary conditions
271    BOUNDARY_CONDITIONS_ADVECTION_DIFFUSION(1)=42.0_CMISSDP
272    BOUNDARY_CONDITIONS_ADVECTION_DIFFUSION(2)=0.0_CMISSDP
273    BOUNDARY_CONDITIONS_ADVECTION_DIFFUSION(3)=0.0_CMISSDP
274  ENDIF  !Set material parameters
275  DIFF_COEFF_PARAM_ADVECTION_DIFFUSION(1)=1.0_CMISSDP
276  DIFF_COEFF_PARAM_ADVECTION_DIFFUSION(2)=1.0_CMISSDP
277  DIFF_COEFF_PARAM_ADVECTION_DIFFUSION(3)=1.0_CMISSDP
278  !Set interpolation parameters
279  BASIS_XI_GAUSS_SPACE=3
280  BASIS_XI_GAUSS_CONCENTRATION=3
281  !Set output parameter
282  !(NoOutput/ProgressOutput/TimingOutput/SolverOutput/SolverMatrixOutput)
283  LINEAR_SOLVER_ADVECTION_DIFFUSION_OUTPUT_TYPE=CMISS_SOLVER_NO_OUTPUT
284  !(NoOutput/TimingOutput/MatrixOutput/ElementOutput)
285  EQUATIONS_ADVECTION_DIFFUSION_OUTPUT=CMISS_EQUATIONS_NO_OUTPUT
286  !Set solver parameters
287  LINEAR_SOLVER_ADVECTION_DIFFUSION_DIRECT_FLAG=.FALSE.
288  RELATIVE_TOLERANCE=1.0E-10_CMISSDP !default: 1.0E-05_CMISSDP
289  ABSOLUTE_TOLERANCE=1.0E-10_CMISSDP !default: 1.0E-10_CMISSDP
290  DIVERGENCE_TOLERANCE=1.0E20 !default: 1.0E5
291  MAXIMUM_ITERATIONS=100000 !default: 100000
292  RESTART_VALUE=3000 !default: 30
293  LINESEARCH_ALPHA=1.0
294
295  !
296  !================================================================================================================================
297  !
298
299  !COORDINATE SYSTEM
300
301  !Start the creation of a new RC coordinate system
302  CALL CMISSCoordinateSystem_Initialise(CoordinateSystem,Err)
303  CALL CMISSCoordinateSystem_CreateStart(CoordinateSystemUserNumber,CoordinateSystem,Err)
304  !Set the coordinate system dimension
305  CALL CMISSCoordinateSystem_DimensionSet(CoordinateSystem,NUMBER_OF_DIMENSIONS,Err)
306  !Finish the creation of the coordinate system
307  CALL CMISSCoordinateSystem_CreateFinish(CoordinateSystem,Err)
308
309  !
310  !================================================================================================================================
311  !
312
313  !REGION
314
315  !Start the creation of a new region
316  CALL CMISSRegion_Initialise(Region,Err)
317  CALL CMISSRegion_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
318  !Set the regions coordinate system as defined above
319  CALL CMISSRegion_CoordinateSystemSet(Region,CoordinateSystem,Err)
320  !Finish the creation of the region
321  CALL CMISSRegion_CreateFinish(Region,Err)
322
323  !
324  !================================================================================================================================
325  !
326
327  !BASES
328
329  !Start the creation of new bases
330  MESH_NUMBER_OF_COMPONENTS=1
331  CALL CMISSBasis_Initialise(BasisSpace,Err)
332  CALL CMISSBasis_CreateStart(BASIS_NUMBER_SPACE,BasisSpace,Err)
333  !Set the basis type (Lagrange/Simplex)
334  CALL CMISSBasis_TypeSet(BasisSpace,BASIS_TYPE,Err)
335  !Set the basis xi number
336  CALL CMISSBasis_NumberOfXiSet(BasisSpace,NUMBER_OF_DIMENSIONS,Err)
337  !Set the basis xi interpolation and number of Gauss points
338  IF(NUMBER_OF_DIMENSIONS==2) THEN
339    CALL CMISSBasis_InterpolationXiSet(BasisSpace,(/BASIS_XI_INTERPOLATION_SPACE,BASIS_XI_INTERPOLATION_SPACE/),Err)
340    CALL CMISSBasis_QuadratureNumberOfGaussXiSet(BasisSpace,(/BASIS_XI_GAUSS_SPACE,BASIS_XI_GAUSS_SPACE/),Err)
341  ELSE IF(NUMBER_OF_DIMENSIONS==3) THEN
342    CALL CMISSBasis_InterpolationXiSet(BasisSpace,(/BASIS_XI_INTERPOLATION_SPACE,BASIS_XI_INTERPOLATION_SPACE, & 
343      & BASIS_XI_INTERPOLATION_SPACE/),Err)                         
344    CALL CMISSBasis_QuadratureNumberOfGaussXiSet(BasisSpace,(/BASIS_XI_GAUSS_SPACE,BASIS_XI_GAUSS_SPACE,BASIS_XI_GAUSS_SPACE/),Err)
345  ENDIF
346  !Finish the creation of the basis
347  CALL CMISSBasis_CreateFinish(BasisSpace,Err)
348  !Start the creation of another basis
349  IF(BASIS_XI_INTERPOLATION_CONCENTRATION==BASIS_XI_INTERPOLATION_SPACE) THEN
350    BasisConcentration=BasisSpace
351  ELSE
352    MESH_NUMBER_OF_COMPONENTS=MESH_NUMBER_OF_COMPONENTS+1
353    !Initialise a new pressure basis
354    CALL CMISSBasis_Initialise(BasisConcentration,Err)
355    !Start the creation of a basis
356    CALL CMISSBasis_CreateStart(BASIS_NUMBER_CONCENTRATION,BasisConcentration,Err)
357    !Set the basis type (Lagrange/Simplex)
358    CALL CMISSBasis_TypeSet(BasisConcentration,BASIS_TYPE,Err)
359    !Set the basis xi number
360    CALL CMISSBasis_NumberOfXiSet(BasisConcentration,NUMBER_OF_DIMENSIONS,Err)
361    !Set the basis xi interpolation and number of Gauss points
362    IF(NUMBER_OF_DIMENSIONS==2) THEN
363      CALL CMISSBasis_InterpolationXiSet(BasisConcentration,(/BASIS_XI_INTERPOLATION_CONCENTRATION, &
364        & BASIS_XI_INTERPOLATION_CONCENTRATION/),Err)
365      CALL CMISSBasis_QuadratureNumberOfGaussXiSet(BasisConcentration,(/BASIS_XI_GAUSS_CONCENTRATION, &
366        & BASIS_XI_GAUSS_CONCENTRATION/),Err)
367    ELSE IF(NUMBER_OF_DIMENSIONS==3) THEN
368      CALL CMISSBasis_InterpolationXiSet(BasisConcentration,(/BASIS_XI_INTERPOLATION_CONCENTRATION, & 
369        & BASIS_XI_INTERPOLATION_CONCENTRATION, BASIS_XI_INTERPOLATION_CONCENTRATION/),Err)                         
370      CALL CMISSBasis_QuadratureNumberOfGaussXiSet(BasisConcentration,(/BASIS_XI_GAUSS_CONCENTRATION, & 
371        & BASIS_XI_GAUSS_CONCENTRATION, BASIS_XI_GAUSS_CONCENTRATION/),Err)
372    ENDIF
373    !Finish the creation of the basis
374    CALL CMISSBasis_CreateFinish(BasisConcentration,Err)
375  ENDIF
376  !
377  !================================================================================================================================
378  !
379
380  !MESH
381
382  !Start the creation of mesh nodes
383  CALL CMISSNodes_Initialise(Nodes,Err)
384  CALL CMISSMesh_Initialise(Mesh,Err)
385  CALL CMISSNodes_CreateStart(Region,TOTAL_NUMBER_OF_NODES,Nodes,Err)
386  CALL CMISSNodes_CreateFinish(Nodes,Err)
387  !Start the creation of the mesh
388  CALL CMISSMesh_CreateStart(MeshUserNumber,Region,NUMBER_OF_DIMENSIONS,Mesh,Err)
389  !Set number of mesh elements
390  CALL CMISSMesh_NumberOfElementsSet(Mesh,TOTAL_NUMBER_OF_ELEMENTS,Err)
391  !Set number of mesh components
392  CALL CMISSMesh_NumberOfComponentsSet(Mesh,MESH_NUMBER_OF_COMPONENTS,Err)
393  !Specify spatial mesh component
394  CALL CMISSMeshElements_Initialise(MeshElementsSpace,Err)
395  CALL CMISSMeshElements_Initialise(MeshElementsConcentration,Err)
396  MESH_COMPONENT_NUMBER_SPACE=1
397  MESH_COMPONENT_NUMBER_CONCENTRATION=1
398  CALL CMISSMeshElements_CreateStart(Mesh,MESH_COMPONENT_NUMBER_SPACE,BasisSpace,MeshElementsSpace,Err)
399  DO ELEMENT_NUMBER=1,TOTAL_NUMBER_OF_ELEMENTS
400    CALL CMISSMeshElements_NodesSet(MeshElementsSpace,ELEMENT_NUMBER,CM%M(ELEMENT_NUMBER,1:NUMBER_OF_ELEMENT_NODES_SPACE),Err)
401  ENDDO
402  CALL CMISSMeshElements_CreateFinish(MeshElementsSpace,Err)
403  !Specify pressure mesh component
404  IF(BASIS_XI_INTERPOLATION_CONCENTRATION==BASIS_XI_INTERPOLATION_SPACE) THEN
405    MeshElementsConcentration=MeshElementsSpace
406    MESH_COMPONENT_NUMBER_CONCENTRATION=MESH_COMPONENT_NUMBER_SPACE
407  ELSE
408    MESH_COMPONENT_NUMBER_CONCENTRATION=MESH_COMPONENT_NUMBER_SPACE+1
409    CALL CMISSMeshElements_CreateStart(Mesh,MESH_COMPONENT_NUMBER_CONCENTRATION,BasisConcentration,MeshElementsConcentration,Err)
410    DO ELEMENT_NUMBER=1,TOTAL_NUMBER_OF_ELEMENTS
411      CALL CMISSMeshElements_NodesSet(MeshElementsConcentration,ELEMENT_NUMBER,CM%V(ELEMENT_NUMBER, & 
412        & 1:NUMBER_OF_ELEMENT_NODES_CONCENTRATION),Err)
413    ENDDO
414    CALL CMISSMeshElements_CreateFinish(MeshElementsConcentration,Err)
415  ENDIF
416  !Finish the creation of the mesh
417  CALL CMISSMesh_CreateFinish(Mesh,Err)
418
419  !
420  !================================================================================================================================
421  !
422
423  !GEOMETRIC FIELD
424
425  !Create a decomposition
426  CALL CMISSDecomposition_Initialise(Decomposition,Err)
427  CALL CMISSDecomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition,Err)
428  !Set the decomposition to be a general decomposition with the specified number of domains
429  CALL CMISSDecomposition_TypeSet(Decomposition,CMISS_DECOMPOSITION_CALCULATED_TYPE,Err)
430  CALL CMISSDecomposition_NumberOfDomainsSet(Decomposition,DomainUserNumber,Err)
431  !Finish the decomposition
432  CALL CMISSDecomposition_CreateFinish(Decomposition,Err)
433
434  !Start to create a default (geometric) field on the region
435  CALL CMISSField_Initialise(GeometricField,Err)
436  CALL CMISSField_CreateStart(GeometricFieldUserNumber,Region,GeometricField,Err)
437  !Set the field type
438  CALL CMISSField_TypeSet(GeometricField,CMISS_FIELD_GEOMETRIC_TYPE,Err)
439  !Set the decomposition to use
440  CALL CMISSField_MeshDecompositionSet(GeometricField,Decomposition,Err)
441  !Set the scaling to use
442  CALL CMISSField_ScalingTypeSet(GeometricField,CMISS_FIELD_NO_SCALING,Err)
443  !Set the mesh component to be used by the field components.
444  DO COMPONENT_NUMBER=1,NUMBER_OF_DIMENSIONS
445    CALL CMISSField_ComponentMeshComponentSet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,COMPONENT_NUMBER, & 
446      & MESH_COMPONENT_NUMBER_SPACE,Err)
447  ENDDO
448  !Finish creating the field
449  CALL CMISSField_CreateFinish(GeometricField,Err)
450  !Update the geometric field parameters
451  DO NODE_NUMBER=1,NUMBER_OF_NODES_SPACE
452    DO COMPONENT_NUMBER=1,NUMBER_OF_DIMENSIONS
453      VALUE=CM%N(NODE_NUMBER,COMPONENT_NUMBER)
454      CALL CMISSField_ParameterSetUpdateNode(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, & 
455        & 1,CMISS_NO_GLOBAL_DERIV,NODE_NUMBER,COMPONENT_NUMBER,VALUE,Err)
456    ENDDO
457  ENDDO
458  CALL CMISSField_ParameterSetUpdateStart(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,Err)
459  CALL CMISSField_ParameterSetUpdateFinish(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,Err)
460
461  !
462  !================================================================================================================================
463  !
464
465  !EQUATIONS SETS
466 
467  !Create the equations_set
468  CALL CMISSEquationsSet_Initialise(EquationsSetAdvecDiff,Err)
469    CALL CMISSField_Initialise(EquationsSetField,Err)
470  CALL CMISSEquationsSet_CreateStart(EquationsSetUserNumberAdvecDiff,Region,GeometricField, &
471    & CMISS_EQUATIONS_SET_CLASSICAL_FIELD_CLASS,&
472    & CMISS_EQUATIONS_SET_ADVECTION_DIFFUSION_EQUATION_TYPE,CMISS_EQUATIONS_SET_NO_SOURCE_ADVECTION_DIFFUSION_SUBTYPE,& 
473    & EquationsSetFieldUserNumber,EquationsSetField,EquationsSetAdvecDiff,Err)
474  !Set the equations set to be a standard Laplace problem
475  !Finish creating the equations set
476  CALL CMISSEquationsSet_CreateFinish(EquationsSetAdvecDiff,Err)
477
478  !
479  !================================================================================================================================
480  !
481
482  !DEPENDENT FIELDS
483
484  !Create the equations set dependent field variables
485  CALL CMISSField_Initialise(DependentFieldAdvecDiff,Err)
486  CALL CMISSEquationsSet_DependentCreateStart(EquationsSetAdvecDiff,DependentFieldUserNumberAdvecDiff,DependentFieldAdvecDiff,Err)
487  !Finish the equations set dependent field variables
488  CALL CMISSEquationsSet_DependentCreateFinish(EquationsSetAdvecDiff,Err)
489
490  !
491  !================================================================================================================================
492  !
493
494  !MATERIALS FIELDS
495
496  !Create the equations set material field variables
497  CALL CMISSField_Initialise(MaterialsFieldAdvecDiff,Err)
498  CALL CMISSEquationsSet_MaterialsCreateStart(EquationsSetAdvecDiff,MaterialsFieldUserNumberAdvecDiff,MaterialsFieldAdvecDiff,Err)
499  !Finish the equations set dependent field variables
500  CALL CMISSEquationsSet_MaterialsCreateFinish(EquationsSetAdvecDiff,Err)
501
502  !
503  !================================================================================================================================
504  !
505
506  !SOURCE FIELDS
507
508
509  !Create the equations set source field variables
510!   CALL CMISSField_Initialise(SourceFieldAdvecDiff,Err)
511!   CALL CMISSEquationsSet_SourceCreateStart(EquationsSetAdvecDiff,SourceFieldUserNumberAdvecDiff,SourceFieldAdvecDiff,Err)
512!   CALL CMISSField_ComponentInterpolationSet(SourceFieldAdvecDiff,CMISS_FIELD_U_VARIABLE_TYPE,1,CMISS_FIELD_NODE_BASED_INTERPOLATION,Err)
513!   !Finish the equations set dependent field variables
514!   CALL CMISSEquationsSet_SourceCreateFinish(EquationsSetAdvecDiff,Err)
515
516
517  !
518  !================================================================================================================================
519  !
520
521  !INDEPENDENT FIELDS
522
523 ! CALL CMISSField_ParameterSetDataGet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,GEOMETRIC_PARAMETERS,Err)
524
525
526  !Create the equations set independent field variables
527  CALL CMISSField_Initialise(IndependentFieldAdvecDiff,Err)
528  CALL CMISSEquationsSet_IndependentCreateStart(EquationsSetAdvecDiff,IndependentFieldUserNumberAdvecDiff, &
529    & IndependentFieldAdvecDiff,Err)
530!   IF(NUMBER_GLOBAL_Z_ELEMENTS==0) THEN
531!   CALL CMISSField_ComponentInterpolationSet(IndependentField,CMISS_FIELD_U_VARIABLE_TYPE,1,CMISS_FIELD_NODE_BASED_INTERPOLATION,Err) 
532!   CALL CMISSField_ComponentInterpolationSet(IndependentField,CMISS_FIELD_U_VARIABLE_TYPE,2,CMISS_FIELD_NODE_BASED_INTERPOLATION,Err)
533!   ENDIF
534  !Set the mesh component to be used by the field components.
535  CALL CMISSField_ComponentMeshComponentSet(IndependentFieldAdvecDiff,CMISS_FIELD_U_VARIABLE_TYPE,MESH_COMPONENT_NUMBER_SPACE, & 
536    & MESH_COMPONENT_NUMBER_CONCENTRATION,Err)
537
538  !Finish the equations set dependent field variables
539  CALL CMISSEquationsSet_IndependentCreateFinish(EquationsSetAdvecDiff,Err)
540 
541  !
542  !================================================================================================================================
543  !
544
545
546  !EQUATIONS
547
548
549  !Create the equations set equations
550  CALL CMISSEquations_Initialise(EquationsAdvecDiff,Err)
551  CALL CMISSEquationsSet_EquationsCreateStart(EquationsSetAdvecDiff,EquationsAdvecDiff,Err)
552  !Set the equations matrices sparsity type
553  CALL CMISSEquations_SparsityTypeSet(EquationsAdvecDiff,CMISS_EQUATIONS_SPARSE_MATRICES,Err)
554  !Set the equations set output
555  CALL CMISSEquations_OutputTypeSet(EquationsAdvecDiff,EQUATIONS_ADVECTION_DIFFUSION_OUTPUT,Err)
556  !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_NO_OUTPUT,Err)
557  !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_TIMING_OUTPUT,Err)
558  !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_MATRIX_OUTPUT,Err)
559  !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_ELEMENT_MATRIX_OUTPUT,Err)
560  !Finish the equations set equations
561  CALL CMISSEquationsSet_EquationsCreateFinish(EquationsSetAdvecDiff,Err)
562
563  !
564  !================================================================================================================================
565  !
566
567  !Start the creation of a problem.
568  CALL CMISSProblem_Initialise(Problem,Err)
569  CALL CMISSControlLoop_Initialise(ControlLoop,Err)
570  CALL CMISSProblem_CreateStart(ProblemUserNumber,Problem,Err)
571  !Set the problem to be a No Source Diffusion problem
572  CALL CMISSProblem_SpecificationSet(Problem,CMISS_PROBLEM_CLASSICAL_FIELD_CLASS,CMISS_PROBLEM_ADVECTION_DIFFUSION_EQUATION_TYPE, &
573    & CMISS_PROBLEM_NO_SOURCE_ADVECTION_DIFFUSION_SUBTYPE,Err)
574  !Finish the creation of a problem.
575  CALL CMISSProblem_CreateFinish(Problem,Err)
576  !Start the creation of the problem control loop
577  CALL CMISSProblem_ControlLoopCreateStart(Problem,Err)
578  !Get the control loop
579  CALL CMISSProblem_ControlLoopGet(Problem,ControlLoopNode,ControlLoop,Err)
580  !Set the times
581  CALL CMISSControlLoop_TimesSet(ControlLoop,0.0_CMISSDP,0.03_CMISSDP,0.01_CMISSDP,Err)
582  !Finish creating the problem control loop
583  CALL CMISSProblem_ControlLoopCreateFinish(Problem,Err)
584
585  !
586  !================================================================================================================================
587  !
588
589
590  !SOLVERS
591
592  !Start the creation of the problem solvers
593!  
594! !   !For the Direct Solver MUMPS, uncomment the below two lines and comment out the above five
595! !   CALL SOLVER_LINEAR_TYPE_SET(LINEAR_SOLVER,SOLVER_LINEAR_DIRECT_SOLVE_TYPE,ERR,ERROR,*999)
596! !   CALL SOLVER_LINEAR_DIRECT_TYPE_SET(LINEAR_SOLVER,SOLVER_DIRECT_MUMPS,ERR,ERROR,*999) 
597! 
598
599  CALL CMISSSolver_Initialise(SolverAdvecDiff,Err)
600  CALL CMISSSolver_Initialise(LinearSolverAdvecDiff,Err)
601  CALL CMISSProblem_SolversCreateStart(Problem,Err)
602  CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,SolverAdvecDiff,Err)
603  !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_NO_OUTPUT,Err)
604  !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
605  !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_TIMING_OUTPUT,Err)
606  !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_SOLVER_OUTPUT,Err)
607  CALL CMISSSolver_OutputTypeSet(SolverAdvecDiff,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
608  CALL CMISSSolver_DynamicLinearSolverGet(SolverAdvecDiff,LinearSolverAdvecDiff,Err)
609  CALL CMISSSolver_LinearIterativeMaximumIterationsSet(LinearSolverAdvecDiff,300,Err)
610  !Finish the creation of the problem solver
611  CALL CMISSProblem_SolversCreateFinish(Problem,Err)
612
613  !
614  !================================================================================================================================
615  !
616  !SOLVER EQUATIONS
617
618  !Create the problem solver equations
619  CALL CMISSSolver_Initialise(SolverAdvecDiff,Err)
620  CALL CMISSSolverEquations_Initialise(SolverEquationsAdvecDiff,Err)
621  CALL CMISSProblem_SolverEquationsCreateStart(Problem,Err)
622  !Get the solve equations
623  CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,SolverAdvecDiff,Err)
624  CALL CMISSSolver_SolverEquationsGet(SolverAdvecDiff,SolverEquationsAdvecDiff,Err)
625  !Set the solver equations sparsity
626  CALL CMISSSolverEquations_SparsityTypeSet(SolverEquationsAdvecDiff,CMISS_SOLVER_SPARSE_MATRICES,Err)
627  !CALL CMISSSolverEquations_SparsityTypeSet(SolverEquations,CMISS_SOLVER_FULL_MATRICES,Err)  
628  !Add in the equations set
629  CALL CMISSSolverEquations_EquationsSetAdd(SolverEquationsAdvecDiff,EquationsSetAdvecDiff,EquationsSetIndex,Err)
630  !Finish the creation of the problem solver equations
631  CALL CMISSProblem_SolverEquationsCreateFinish(Problem,Err)
632
633  !
634  !================================================================================================================================
635  !
636
637 !BOUNDARY CONDITIONS
638
639  !Start the creation of the equations set boundary conditions for Poisson
640  CALL CMISSBoundaryConditions_Initialise(BoundaryConditionsAdvecDiff,Err)
641  CALL CMISSSolverEquations_BoundaryConditionsCreateStart(SolverEquationsAdvecDiff,BoundaryConditionsAdvecDiff,Err)
642  !Set fixed wall nodes
643  IF(FIXED_WALL_NODES_ADVECTION_DIFFUSION_FLAG) THEN
644    DO NODE_COUNTER=1,NUMBER_OF_FIXED_WALL_NODES_ADVECTION_DIFFUSION
645      NODE_NUMBER=FIXED_WALL_NODES_ADVECTION_DIFFUSION(NODE_COUNTER)
646      CONDITION=CMISS_BOUNDARY_CONDITION_FIXED
647!       DO COMPONENT_NUMBER=1,NUMBER_OF_DIMENSIONS
648        VALUE=0.0_CMISSDP
649        CALL CMISSBoundaryConditions_SetNode(BoundaryConditionsAdvecDiff,DependentFieldAdvecDiff,CMISS_FIELD_U_VARIABLE_TYPE, &
650          & CMISS_NO_GLOBAL_DERIV, &
651          & 1,NODE_NUMBER,MESH_COMPONENT_NUMBER_CONCENTRATION,CONDITION,VALUE,Err)
652!       ENDDO
653    ENDDO
654  ENDIF
655  !Set velocity boundary conditions
656  IF(INLET_WALL_NODES_ADVECTION_DIFFUSION_FLAG) THEN
657    DO NODE_COUNTER=1,NUMBER_OF_INLET_WALL_NODES_ADVECTION_DIFFUSION
658      NODE_NUMBER=INLET_WALL_NODES_ADVECTION_DIFFUSION(NODE_COUNTER)
659      CONDITION=CMISS_BOUNDARY_CONDITION_FIXED
660!       DO COMPONENT_NUMBER=1,NUMBER_OF_DIMENSIONS
661        VALUE=0.1_CMISSDP
662        CALL CMISSBoundaryConditions_SetNode(BoundaryConditionsAdvecDiff,DependentFieldAdvecDiff,CMISS_FIELD_U_VARIABLE_TYPE, &
663          & CMISS_NO_GLOBAL_DERIV, &
664          & 1,NODE_NUMBER,MESH_COMPONENT_NUMBER_CONCENTRATION,CONDITION,VALUE,Err)
665!       ENDDO
666    ENDDO
667  ENDIF
668  !Finish the creation of the equations set boundary conditions
669  CALL CMISSSolverEquations_BoundaryConditionsCreateFinish(SolverEquationsAdvecDiff,Err)
670
671  !
672  !================================================================================================================================
673  !
674
675  !RUN SOLVERS
676
677  !Turn of PETSc error handling
678  !CALL PETSC_ERRORHANDLING_SET_ON(ERR,ERROR,*999)
679
680  !Solve the problem
681  WRITE(*,'(A)') "Solving problem..."
682  CALL CMISSProblem_Solve(Problem,Err)
683  WRITE(*,'(A)') "Problem solved!"
684
685  !
686  !================================================================================================================================
687  !
688
689  !OUTPUT
690
691  EXPORT_FIELD_IO=.TRUE.
692  IF(EXPORT_FIELD_IO) THEN
693    WRITE(*,'(A)') "Exporting fields..."
694    CALL CMISSFields_Initialise(Fields,Err)
695    CALL CMISSFields_Create(Region,Fields,Err)
696    CALL CMISSFields_NodesExport(Fields,"AdvectionDiffusionIO","FORTRAN",Err)
697    CALL CMISSFields_ElementsExport(Fields,"AdvectionDiffusionIO","FORTRAN",Err)
698    CALL CMISSFields_Finalise(Fields,Err)
699    WRITE(*,'(A)') "Field exported!"
700  ENDIF
701  
702
703  !Finialise CMISS
704  !CALL CMISSFinalise(Err)
705
706  WRITE(*,'(A)') "Program successfully completed."
707  
708  STOP
709
710END PROGRAM ADVECTIONDIFFUSIONIOEXAMPLE