PageRenderTime 297ms CodeModel.GetById 4ms app.highlight 203ms RepoModel.GetById 1ms app.codeStats 0ms

/ClassicalField/AdvectionDiffusion/AdvectionDiffusionIO_ALE/src/AdvectionDiffusionIO_ALEExample.f90

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