PageRenderTime 61ms CodeModel.GetById 14ms app.highlight 42ms RepoModel.GetById 1ms app.codeStats 0ms

/FluidMechanics/NavierStokes/Static_FieldML/src/Static_FieldMLExample.f90

http://github.com/xyan075/examples
FORTRAN Modern | 647 lines | 340 code | 117 blank | 190 comment | 0 complexity | 141f45defc168f696733f69af6fa8189 MD5 | raw file
  1!> \file
  2!> \author Sebastian Krittian
  3!> \brief This is an example program to solve a static Navier-Stokes 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 FluidMechanics/NavierStokes/Static_FieldML/src/Static_FieldMLExample.f90
 43!! Example program to solve a static Navier-Stokes equation using OpenCMISS calls.
 44!! \htmlinclude FluidMechanics/NavierStokes/Static_FieldML/history.html
 45!!
 46!<
 47
 48!> Main program
 49
 50PROGRAM NAVIERSTOKESSTATICEXAMPLE
 51
 52  !
 53  !================================================================================================================================
 54  !
 55
 56  !PROGRAM LIBRARIES
 57
 58  USE OPENCMISS
 59  USE MPI
 60  USE FIELDML_API
 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  !Test program parameters
 75
 76  INTEGER(CMISSIntg), PARAMETER :: CoordinateSystemUserNumber=1
 77  INTEGER(CMISSIntg), PARAMETER :: RegionUserNumber=2
 78  INTEGER(CMISSIntg), PARAMETER :: MeshUserNumber=3
 79  INTEGER(CMISSIntg), PARAMETER :: DecompositionUserNumber=4
 80  INTEGER(CMISSIntg), PARAMETER :: GeometricFieldUserNumber=5
 81  INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=6
 82  INTEGER(CMISSIntg), PARAMETER :: DependentFieldUserNumberNavierStokes=7
 83  INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumberNavierStokes=8
 84  INTEGER(CMISSIntg), PARAMETER :: IndependentFieldUserNumberNavierStokes=9
 85  INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumberNavierStokes=10
 86  INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=11
 87
 88  INTEGER(CMISSIntg), PARAMETER :: DomainUserNumber=1
 89  INTEGER(CMISSIntg), PARAMETER :: SolverNavierStokesUserNumber=1
 90  INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumberNavierStokesMu=1
 91  INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumberNavierStokesRho=2
 92
 93  INTEGER(CMISSIntg), PARAMETER :: basisNumberTrilinear=1
 94  INTEGER(CMISSIntg), PARAMETER :: basisNumberTriquadratic=2
 95
 96  INTEGER(CMISSIntg), PARAMETER :: gaussQuadrature(3) = [3,3,3]
 97
 98  CHARACTER(KIND=C_CHAR,LEN=*), PARAMETER :: inputFilename = "../../TOOLS/NavierStokesMeshes/HEX-M2-V2-P1_FE.xml"
 99
100  CHARACTER(KIND=C_CHAR,LEN=*), PARAMETER :: outputDirectory = "output"
101  CHARACTER(KIND=C_CHAR,LEN=*), PARAMETER :: outputFilename = outputDirectory//"/HEX-M2-V2-P1_FE_out.xml"
102
103  CHARACTER(KIND=C_CHAR,LEN=*), PARAMETER :: basename = "static_navier_stokes"
104  CHARACTER(KIND=C_CHAR,LEN=*), PARAMETER :: dataFormat = "PLAIN_TEXT"
105  !Program types
106
107  !Program variables
108
109  INTEGER(CMISSIntg) :: BASIS_XI_GAUSS_SPACE
110  INTEGER(CMISSIntg) :: BASIS_XI_GAUSS_VELOCITY
111  INTEGER(CMISSIntg) :: BASIS_XI_GAUSS_PRESSURE
112  INTEGER(CMISSIntg) :: MESH_COMPONENT_NUMBER_SPACE
113  INTEGER(CMISSIntg) :: MESH_COMPONENT_NUMBER_VELOCITY
114  INTEGER(CMISSIntg) :: MESH_COMPONENT_NUMBER_PRESSURE
115  INTEGER(CMISSIntg) :: MAXIMUM_ITERATIONS
116  INTEGER(CMISSIntg) :: RESTART_VALUE
117!   INTEGER(CMISSIntg) :: MPI_IERROR
118  INTEGER(CMISSIntg) :: NUMBER_OF_FIXED_WALL_NODES_NAVIER_STOKES
119  INTEGER(CMISSIntg) :: NUMBER_OF_INLET_WALL_NODES_NAVIER_STOKES
120
121  INTEGER(CMISSIntg) :: EQUATIONS_NAVIER_STOKES_OUTPUT
122  INTEGER(CMISSIntg) :: COMPONENT_NUMBER
123  INTEGER(CMISSIntg) :: NODE_NUMBER
124  INTEGER(CMISSIntg) :: NODE_COUNTER
125  INTEGER(CMISSIntg) :: CONDITION
126
127  INTEGER(CMISSIntg) :: LINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE
128  INTEGER(CMISSIntg) :: NONLINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE
129
130  INTEGER, ALLOCATABLE, DIMENSION(:):: FIXED_WALL_NODES_NAVIER_STOKES
131  INTEGER, ALLOCATABLE, DIMENSION(:):: INLET_WALL_NODES_NAVIER_STOKES
132
133  REAL(CMISSDP) :: INITIAL_FIELD_NAVIER_STOKES(3)
134  REAL(CMISSDP) :: BOUNDARY_CONDITIONS_NAVIER_STOKES(3)
135  REAL(CMISSDP) :: DIVERGENCE_TOLERANCE
136  REAL(CMISSDP) :: RELATIVE_TOLERANCE
137  REAL(CMISSDP) :: ABSOLUTE_TOLERANCE
138  REAL(CMISSDP) :: LINESEARCH_ALPHA
139  REAL(CMISSDP) :: VALUE
140  REAL(CMISSDP) :: MU_PARAM_NAVIER_STOKES
141  REAL(CMISSDP) :: RHO_PARAM_NAVIER_STOKES
142
143  LOGICAL :: EXPORT_FIELD_IO
144  LOGICAL :: LINEAR_SOLVER_NAVIER_STOKES_DIRECT_FLAG
145  LOGICAL :: FIXED_WALL_NODES_NAVIER_STOKES_FLAG
146  LOGICAL :: INLET_WALL_NODES_NAVIER_STOKES_FLAG
147
148  !CMISS variables
149
150  !Regions
151  TYPE(CMISSRegionType) :: Region
152  TYPE(CMISSRegionType) :: WorldRegion
153  !Coordinate systems
154  TYPE(CMISSCoordinateSystemType) :: CoordinateSystem
155  TYPE(CMISSCoordinateSystemType) :: WorldCoordinateSystem
156  !Nodes
157  TYPE(CMISSNodesType) :: Nodes
158  !Meshes
159  TYPE(CMISSMeshType) :: Mesh
160  !Decompositions
161  TYPE(CMISSDecompositionType) :: Decomposition
162  !Fields
163  TYPE(CMISSFieldsType) :: Fields
164  !Field types
165  TYPE(CMISSFieldType) :: GeometricField
166  TYPE(CMISSFieldType) :: EquationsSetField
167  TYPE(CMISSFieldType) :: DependentFieldNavierStokes
168  TYPE(CMISSFieldType) :: MaterialsFieldNavierStokes
169  !Boundary conditions
170  TYPE(CMISSBoundaryConditionsType) :: BoundaryConditionsNavierStokes
171  !Equations sets
172  TYPE(CMISSEquationsSetType) :: EquationsSetNavierStokes
173  !Equations
174  TYPE(CMISSEquationsType) :: EquationsNavierStokes
175  !Problems
176  TYPE(CMISSProblemType) :: Problem
177  !Control loops
178  TYPE(CMISSControlLoopType) :: ControlLoop
179  !Solvers
180  TYPE(CMISSSolverType) :: NonlinearSolverNavierStokes
181  TYPE(CMISSSolverType) :: LinearSolverNavierStokes
182  !Solver equations
183  TYPE(CMISSSolverEquationsType) :: SolverEquationsNavierStokes
184  
185  !FieldML parsing variables
186  TYPE(CMISSFieldMLIOType) :: fieldmlInfo, outputInfo
187  
188  INTEGER(CMISSIntg) :: meshComponentCount
189  
190  INTEGER(CMISSIntg) :: typeHandle
191  INTEGER(CMISSIntg) :: coordinateCount
192  
193#ifdef WIN32
194  !Quickwin type
195  LOGICAL :: QUICKWIN_STATUS=.FALSE.
196  TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
197#endif
198  
199  !Generic CMISS variables
200
201  INTEGER(CMISSIntg) :: EquationsSetIndex
202  INTEGER(CMISSIntg) :: err
203
204#ifdef WIN32
205  !Initialise QuickWin
206  QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
207  QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
208  QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
209  !Set the window parameters
210  QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
211  !If attempt fails set with system estimated values
212  IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
213#endif
214
215  !
216  !================================================================================================================================
217  !
218
219  !PROBLEM CONTROL PANEL
220  
221  !Set initial values
222  INITIAL_FIELD_NAVIER_STOKES(1)=0.0_CMISSDP
223  INITIAL_FIELD_NAVIER_STOKES(2)=0.0_CMISSDP
224  INITIAL_FIELD_NAVIER_STOKES(3)=0.0_CMISSDP
225  !Set boundary conditions
226  FIXED_WALL_NODES_NAVIER_STOKES_FLAG=.TRUE.
227  INLET_WALL_NODES_NAVIER_STOKES_FLAG=.TRUE.
228  IF(FIXED_WALL_NODES_NAVIER_STOKES_FLAG) THEN
229    NUMBER_OF_FIXED_WALL_NODES_NAVIER_STOKES=80
230    ALLOCATE(FIXED_WALL_NODES_NAVIER_STOKES(NUMBER_OF_FIXED_WALL_NODES_NAVIER_STOKES))
231    FIXED_WALL_NODES_NAVIER_STOKES=[1,2,3,4,5,7,9,10,11,12,13,14,17,20,24,28,29,30,31,32,33,34,35,37,39, & 
232    & 41,44,46,47,48,50,51,52,53,54,57,60,64,65,66,67,68,70,72,74,76,77,78,79,80,83,86, & 
233    & 89,90,91,92,93,94,95,97,99,101,102,103,104,105,106,107,108,111,114,115,116,117,118, & 
234    & 120,122,123,124,125]
235  ENDIF
236  IF(INLET_WALL_NODES_NAVIER_STOKES_FLAG) THEN
237    NUMBER_OF_INLET_WALL_NODES_NAVIER_STOKES=9
238    ALLOCATE(INLET_WALL_NODES_NAVIER_STOKES(NUMBER_OF_INLET_WALL_NODES_NAVIER_STOKES))
239    INLET_WALL_NODES_NAVIER_STOKES=[6,15,16,23,36,42,81,82,96]
240    !Set initial boundary conditions
241    BOUNDARY_CONDITIONS_NAVIER_STOKES(1)=0.0_CMISSDP
242    BOUNDARY_CONDITIONS_NAVIER_STOKES(2)=1.0_CMISSDP
243    BOUNDARY_CONDITIONS_NAVIER_STOKES(3)=0.0_CMISSDP
244  ENDIF
245  !Set material parameters
246  MU_PARAM_NAVIER_STOKES=1.0_CMISSDP
247  RHO_PARAM_NAVIER_STOKES=1.0_CMISSDP
248  !Set interpolation parameters
249  BASIS_XI_GAUSS_SPACE=3
250  BASIS_XI_GAUSS_VELOCITY=3
251  BASIS_XI_GAUSS_PRESSURE=3
252  !Set output parameter
253  !(NoOutput/ProgressOutput/TimingOutput/SolverOutput/SolverMatrixOutput)
254  LINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE=CMISS_SOLVER_NO_OUTPUT
255  NONLINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE=CMISS_SOLVER_NO_OUTPUT
256  !(NoOutput/TimingOutput/MatrixOutput/ElementOutput)
257  EQUATIONS_NAVIER_STOKES_OUTPUT=CMISS_EQUATIONS_NO_OUTPUT
258  !Set solver parameters
259  LINEAR_SOLVER_NAVIER_STOKES_DIRECT_FLAG=.FALSE.
260  RELATIVE_TOLERANCE=1.0E-10_CMISSDP !default: 1.0E-05_CMISSDP
261  ABSOLUTE_TOLERANCE=1.0E-10_CMISSDP !default: 1.0E-10_CMISSDP
262  DIVERGENCE_TOLERANCE=1.0E20 !default: 1.0E5
263  MAXIMUM_ITERATIONS=100000 !default: 100000
264  RESTART_VALUE=3000 !default: 30
265  LINESEARCH_ALPHA=1.0
266
267
268  !
269  !================================================================================================================================
270  !
271
272  !INITIALISE OPENCMISS
273
274  CALL CMISSInitialise(WorldCoordinateSystem,WorldRegion, err )
275
276  CALL CMISSErrorHandlingModeSet(CMISS_ERRORS_TRAP_ERROR,Err)
277
278  !
279  !================================================================================================================================
280  !
281
282  CALL CMISSFieldMLIO_Initialise( fieldmlInfo, err ) 
283  CALL CMISSFieldML_InputCreateFromFile( inputFilename, fieldmlInfo, err )
284
285  !COORDINATE SYSTEM
286
287  !Start the creation of a new RC coordinate system
288  CALL CMISSCoordinateSystem_Initialise( CoordinateSystem, err )
289  CALL CMISSFieldML_InputCoordinateSystemCreateStart( fieldmlInfo, "test_mesh.coordinates", CoordinateSystem, &
290    & CoordinateSystemUserNumber, err )
291  CALL CMISSCoordinateSystem_CreateFinish( CoordinateSystem, err )
292  CALL CMISSCoordinateSystem_DimensionGet( CoordinateSystem, coordinateCount, err )
293
294  !
295  !================================================================================================================================
296  !
297
298  !REGION
299
300  !Start the creation of a new region
301  CALL CMISSRegion_Initialise( Region, err )
302  CALL CMISSRegion_CreateStart( RegionUserNumber, WorldRegion, Region, err )
303  !Set the regions coordinate system as defined above
304  CALL CMISSRegion_CoordinateSystemSet( Region, CoordinateSystem, err )
305  !Finish the creation of the region
306  CALL CMISSRegion_CreateFinish( Region, err )
307
308  !
309  !================================================================================================================================
310  !
311
312  !NODES
313  CALL CMISSFieldML_InputNodesCreateStart( fieldmlInfo, "test_mesh.nodes.argument", Region, nodes, err )
314  CALL CMISSNodes_CreateFinish( Nodes, err )
315
316  !
317  !================================================================================================================================
318  !
319
320  !BASES
321  CALL CMISSFieldML_InputBasisCreateStart( fieldmlInfo, "test_mesh.trilinear_lagrange", basisNumberTrilinear, err )
322  CALL CMISSBasis_QuadratureNumberOfGaussXiSet( basisNumberTrilinear, gaussQuadrature, err )
323  CALL CMISSBasis_CreateFinish( basisNumberTrilinear, err )
324
325  CALL CMISSFieldML_InputBasisCreateStart( fieldmlInfo, "test_mesh.triquadratic_lagrange", basisNumberTriquadratic, err )
326  CALL CMISSBasis_QuadratureNumberOfGaussXiSet( basisNumberTriquadratic, gaussQuadrature, err )
327  CALL CMISSBasis_CreateFinish( basisNumberTriquadratic, err )
328  
329  !
330  !================================================================================================================================
331  !
332
333  !MESH
334  
335  meshComponentCount = 2
336
337  CALL CMISSFieldML_InputMeshCreateStart( fieldmlInfo, "test_mesh.mesh.argument", Mesh, MeshUserNumber, Region, err )
338  CALL CMISSMesh_NumberOfComponentsSet( Mesh, meshComponentCount, err )
339  
340  CALL CMISSFieldML_InputCreateMeshComponent( fieldmlInfo, RegionUserNumber, MeshUserNumber, 1, &
341    & "test_mesh.template.triquadratic", err )
342  CALL CMISSFieldML_InputCreateMeshComponent( fieldmlInfo, RegionUserNumber, MeshUserNumber, 2, &
343    & "test_mesh.template.trilinear", err )
344  
345  MESH_COMPONENT_NUMBER_SPACE = 1
346  MESH_COMPONENT_NUMBER_VELOCITY = 1
347  MESH_COMPONENT_NUMBER_PRESSURE = 2
348
349  !Finish the creation of the mesh
350  CALL CMISSMesh_CreateFinish(Mesh, err )
351
352  !
353  !================================================================================================================================
354  !
355
356  !GEOMETRIC FIELD
357
358  !Create a decomposition
359  CALL CMISSDecomposition_Initialise(Decomposition, err )
360  CALL CMISSDecomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition, err )
361  !Set the decomposition to be a general decomposition with the specified number of domains
362  CALL CMISSDecomposition_TypeSet(Decomposition,CMISS_DECOMPOSITION_CALCULATED_TYPE, err )
363  CALL CMISSDecomposition_NumberOfDomainsSet(Decomposition,DomainUserNumber, err )
364  !Finish the decomposition
365  CALL CMISSDecomposition_CreateFinish(Decomposition, err )
366  
367  CALL CMISSFieldML_InputFieldCreateStart( fieldmlInfo, Region, Decomposition, GeometricFieldUserNumber, GeometricField, &
368    & CMISS_FIELD_U_VARIABLE_TYPE, "test_mesh.coordinates", err )
369  CALL CMISSField_CreateFinish( RegionUserNumber, GeometricFieldUserNumber, err )
370
371  CALL CMISSFieldML_InputFieldParametersUpdate( fieldmlInfo, GeometricField, "test_mesh.node.coordinates", &
372    & CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
373  CALL CMISSField_ParameterSetUpdateStart( GeometricField, CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
374  CALL CMISSField_ParameterSetUpdateFinish( GeometricField, CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
375
376  !
377  !================================================================================================================================
378  !
379
380  CALL CMISSFieldMLIO_Finalise( fieldmlInfo, err )
381
382  !
383  !================================================================================================================================
384  !
385
386  !EQUATIONS SETS
387
388  !Create the equations set for static Navier-Stokes
389  CALL CMISSEquationsSet_Initialise(EquationsSetNavierStokes, err )
390  CALL CMISSField_Initialise(EquationsSetField,Err)
391  CALL CMISSEquationsSet_CreateStart(EquationsSetUserNumberNavierStokes,Region,GeometricField, &
392    & CMISS_EQUATIONS_SET_FLUID_MECHANICS_CLASS,CMISS_EQUATIONS_SET_NAVIER_STOKES_EQUATION_TYPE, &
393      & CMISS_EQUATIONS_SET_STATIC_NAVIER_STOKES_SUBTYPE, &
394    & EquationsSetFieldUserNumber,EquationsSetField,EquationsSetNavierStokes,err)
395  !Set the equations set to be a static Navier-Stokes problem
396  
397  !Finish creating the equations set
398  CALL CMISSEquationsSet_CreateFinish(EquationsSetNavierStokes, err )
399
400
401  !
402  !================================================================================================================================
403  !
404
405  !DEPENDENT FIELDS
406
407  !Create the equations set dependent field variables for static Navier-Stokes
408  CALL CMISSField_Initialise(DependentFieldNavierStokes, err )
409  CALL CMISSEquationsSet_DependentCreateStart(EquationsSetNavierStokes,DependentFieldUserNumberNavierStokes, & 
410    & DependentFieldNavierStokes, err )
411  !Set the mesh component to be used by the field components.
412  DO COMPONENT_NUMBER=1,coordinateCount
413    CALL CMISSField_ComponentMeshComponentSet(DependentFieldNavierStokes,CMISS_FIELD_U_VARIABLE_TYPE,COMPONENT_NUMBER, & 
414      & MESH_COMPONENT_NUMBER_VELOCITY, err )
415    CALL CMISSField_ComponentMeshComponentSet(DependentFieldNavierStokes,CMISS_FIELD_DELUDELN_VARIABLE_TYPE,COMPONENT_NUMBER, & 
416      & MESH_COMPONENT_NUMBER_VELOCITY, err )
417  ENDDO
418  COMPONENT_NUMBER=coordinateCount+1
419    CALL CMISSField_ComponentMeshComponentSet(DependentFieldNavierStokes,CMISS_FIELD_U_VARIABLE_TYPE,COMPONENT_NUMBER, & 
420      & MESH_COMPONENT_NUMBER_PRESSURE, err )
421    CALL CMISSField_ComponentMeshComponentSet(DependentFieldNavierStokes,CMISS_FIELD_DELUDELN_VARIABLE_TYPE,COMPONENT_NUMBER, & 
422      & MESH_COMPONENT_NUMBER_PRESSURE, err )
423  !Finish the equations set dependent field variables
424  CALL CMISSEquationsSet_DependentCreateFinish(EquationsSetNavierStokes, err )
425
426  !Initialise dependent field
427  DO COMPONENT_NUMBER=1,coordinateCount
428    CALL CMISSField_ComponentValuesInitialise(DependentFieldNavierStokes,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, & 
429      & COMPONENT_NUMBER,INITIAL_FIELD_NAVIER_STOKES(COMPONENT_NUMBER), err )
430  ENDDO
431
432
433  !
434  !================================================================================================================================
435  !
436
437  !MATERIALS FIELDS
438
439  !Create the equations set materials field variables for static Navier-Stokes
440  CALL CMISSField_Initialise(MaterialsFieldNavierStokes, err )
441  CALL CMISSEquationsSet_MaterialsCreateStart(EquationsSetNavierStokes,MaterialsFieldUserNumberNavierStokes, & 
442    & MaterialsFieldNavierStokes, err )
443  !Finish the equations set materials field variables
444  CALL CMISSEquationsSet_MaterialsCreateFinish(EquationsSetNavierStokes, err )
445  CALL CMISSField_ComponentValuesInitialise(MaterialsFieldNavierStokes,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, & 
446    & MaterialsFieldUserNumberNavierStokesMu,MU_PARAM_NAVIER_STOKES, err )
447  CALL CMISSField_ComponentValuesInitialise(MaterialsFieldNavierStokes,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, & 
448    & MaterialsFieldUserNumberNavierStokesRho,RHO_PARAM_NAVIER_STOKES, err )
449
450
451  !
452  !================================================================================================================================
453  !
454
455  !EQUATIONS
456
457
458  !Create the equations set equations
459  CALL CMISSEquations_Initialise(EquationsNavierStokes, err )
460  CALL CMISSEquationsSet_EquationsCreateStart(EquationsSetNavierStokes,EquationsNavierStokes, err )
461  !Set the equations matrices sparsity type
462  CALL CMISSEquations_SparsityTypeSet(EquationsNavierStokes,CMISS_EQUATIONS_SPARSE_MATRICES, err )
463  !Set the equations set output
464  CALL CMISSEquations_OutputTypeSet(EquationsNavierStokes,EQUATIONS_NAVIER_STOKES_OUTPUT, err )
465  !Finish the equations set equations
466  CALL CMISSEquationsSet_EquationsCreateFinish(EquationsSetNavierStokes, err )
467  !
468  !================================================================================================================================
469  !
470
471  !PROBLEMS
472
473  !Start the creation of a problem.
474  CALL CMISSProblem_Initialise(Problem, err )
475  CALL CMISSControlLoop_Initialise(ControlLoop, err )
476  CALL CMISSProblem_CreateStart(ProblemUserNumber,Problem, err )
477  !Set the problem to be a static Navier-Stokes problem
478  CALL CMISSProblem_SpecificationSet(Problem,CMISS_PROBLEM_FLUID_MECHANICS_CLASS,CMISS_PROBLEM_NAVIER_STOKES_EQUATION_TYPE, &
479    & CMISS_PROBLEM_STATIC_NAVIER_STOKES_SUBTYPE, err )
480  !Finish the creation of a problem.
481  CALL CMISSProblem_CreateFinish(Problem, err )
482  !Start the creation of the problem control loop
483  CALL CMISSProblem_ControlLoopCreateStart(Problem, err )
484  !Finish creating the problem control loop
485  CALL CMISSProblem_ControlLoopCreateFinish(Problem, err )
486
487  !
488  !================================================================================================================================
489  !
490
491  !SOLVERS
492
493  !Start the creation of the problem solvers
494  CALL CMISSSolver_Initialise(NonlinearSolverNavierStokes, err )
495  CALL CMISSSolver_Initialise(LinearSolverNavierStokes, err )
496  CALL CMISSProblem_SolversCreateStart(Problem, err )
497  !Get the nonlinear static solver
498  CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,SolverNavierStokesUserNumber,NonlinearSolverNavierStokes, err )
499  !Set the nonlinear Jacobian type
500  CALL CMISSSolver_NewtonJacobianCalculationTypeSet(NonlinearSolverNavierStokes,CMISS_SOLVER_NEWTON_JACOBIAN_EQUATIONS_CALCULATED, &
501    &  err )
502  !Set the output type
503  CALL CMISSSolver_OutputTypeSet(NonlinearSolverNavierStokes,NONLINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE, err )
504  !Set the solver settings
505  CALL CMISSSolver_NewtonAbsoluteToleranceSet(NonlinearSolverNavierStokes,ABSOLUTE_TOLERANCE, err )
506  CALL CMISSSolver_NewtonRelativeToleranceSet(NonlinearSolverNavierStokes,RELATIVE_TOLERANCE, err )
507  !Get the nonlinear linear solver
508  CALL CMISSSolver_NewtonLinearSolverGet(NonlinearSolverNavierStokes,LinearSolverNavierStokes, err )
509  !Set the output type
510  CALL CMISSSolver_OutputTypeSet(LinearSolverNavierStokes,LINEAR_SOLVER_NAVIER_STOKES_OUTPUT_TYPE, err )
511
512
513  !Set the solver settings
514  IF(LINEAR_SOLVER_NAVIER_STOKES_DIRECT_FLAG) THEN
515    CALL CMISSSolver_LinearTypeSet(LinearSolverNavierStokes,CMISS_SOLVER_LINEAR_DIRECT_SOLVE_TYPE, err )
516    CALL CMISSSolver_LibraryTypeSet(LinearSolverNavierStokes,CMISS_SOLVER_MUMPS_LIBRARY, err )
517  ELSE
518    CALL CMISSSolver_LinearTypeSet(LinearSolverNavierStokes,CMISS_SOLVER_LINEAR_ITERATIVE_SOLVE_TYPE, err )
519    CALL CMISSSolver_LinearIterativeMaximumIterationsSet(LinearSolverNavierStokes,MAXIMUM_ITERATIONS, err )
520    CALL CMISSSolver_LinearIterativeDivergenceToleranceSet(LinearSolverNavierStokes,DIVERGENCE_TOLERANCE, err )
521    CALL CMISSSolver_LinearIterativeRelativeToleranceSet(LinearSolverNavierStokes,RELATIVE_TOLERANCE, err )
522    CALL CMISSSolver_LinearIterativeAbsoluteToleranceSet(LinearSolverNavierStokes,ABSOLUTE_TOLERANCE, err )
523    CALL CMISSSolver_LinearIterativeGMRESRestartSet(LinearSolverNavierStokes,RESTART_VALUE, err )
524  ENDIF
525  !Finish the creation of the problem solver
526  CALL CMISSProblem_SolversCreateFinish(Problem, err )
527
528  !
529  !================================================================================================================================
530  !
531
532  !SOLVER EQUATIONS
533
534  !Start the creation of the problem solver equations
535  CALL CMISSSolver_Initialise(LinearSolverNavierStokes, err )
536  CALL CMISSSolverEquations_Initialise(SolverEquationsNavierStokes, err )
537  CALL CMISSProblem_SolverEquationsCreateStart(Problem, err )
538  !Get the linear solver equations
539  CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,SolverNavierStokesUserNumber,LinearSolverNavierStokes, err )
540  CALL CMISSSolver_SolverEquationsGet(LinearSolverNavierStokes,SolverEquationsNavierStokes, err )
541  !Set the solver equations sparsity
542  CALL CMISSSolverEquations_SparsityTypeSet(SolverEquationsNavierStokes,CMISS_SOLVER_SPARSE_MATRICES, err )
543  !Add in the equations set
544  CALL CMISSSolverEquations_EquationsSetAdd(SolverEquationsNavierStokes,EquationsSetNavierStokes,EquationsSetIndex, err )
545  !Finish the creation of the problem solver equations
546  CALL CMISSProblem_SolverEquationsCreateFinish(Problem, err )
547
548
549  !
550  !================================================================================================================================
551  !
552
553  !BOUNDARY CONDITIONS
554
555  !Start the creation of the equations set boundary conditions for Navier-Stokes
556  CALL CMISSBoundaryConditions_Initialise(BoundaryConditionsNavierStokes, err )
557  CALL CMISSSolverEquations_BoundaryConditionsCreateStart(SolverEquationsNavierStokes,BoundaryConditionsNavierStokes, err )
558  !Set fixed wall nodes
559  IF(FIXED_WALL_NODES_NAVIER_STOKES_FLAG) THEN
560    DO NODE_COUNTER=1,NUMBER_OF_FIXED_WALL_NODES_NAVIER_STOKES
561      NODE_NUMBER=FIXED_WALL_NODES_NAVIER_STOKES(NODE_COUNTER)
562      CONDITION=CMISS_BOUNDARY_CONDITION_FIXED_WALL
563      DO COMPONENT_NUMBER=1,coordinateCount
564        VALUE=0.0_CMISSDP
565        CALL CMISSBoundaryConditions_SetNode(BoundaryConditionsNavierStokes,DependentFieldNavierStokes, &
566          & CMISS_FIELD_U_VARIABLE_TYPE, &
567          & 1, &
568          & CMISS_NO_GLOBAL_DERIV, &
569          & NODE_NUMBER,COMPONENT_NUMBER,CONDITION,VALUE, err )
570      ENDDO
571    ENDDO
572  ENDIF
573  !Set velocity boundary conditions
574  IF(INLET_WALL_NODES_NAVIER_STOKES_FLAG) THEN
575    DO NODE_COUNTER=1,NUMBER_OF_INLET_WALL_NODES_NAVIER_STOKES
576      NODE_NUMBER=INLET_WALL_NODES_NAVIER_STOKES(NODE_COUNTER)
577      CONDITION=CMISS_BOUNDARY_CONDITION_FIXED_INLET
578      DO COMPONENT_NUMBER=1,coordinateCount
579        VALUE=BOUNDARY_CONDITIONS_NAVIER_STOKES(COMPONENT_NUMBER)
580        CALL CMISSBoundaryConditions_SetNode(BoundaryConditionsNavierStokes,DependentFieldNavierStokes, &
581          & CMISS_FIELD_U_VARIABLE_TYPE, &
582          & 1, &
583          & CMISS_NO_GLOBAL_DERIV, &
584          & NODE_NUMBER,COMPONENT_NUMBER,CONDITION,VALUE, err )
585      ENDDO
586    ENDDO
587  ENDIF
588  !Finish the creation of the equations set boundary conditions
589  CALL CMISSSolverEquations_BoundaryConditionsCreateFinish(SolverEquationsNavierStokes, err )
590
591  !
592  !================================================================================================================================
593  !
594
595  !RUN SOLVERS
596
597  !Turn of PETSc error handling
598  !CALL PETSC_ERRORHANDLING_SET_ON(ERR,ERROR,*999)
599
600  !Solve the problem
601  WRITE(*,'(A)') "Solving problem..."
602  CALL CMISSProblem_Solve(Problem, err )
603  WRITE(*,'(A)') "Problem solved!"
604
605  !
606  !================================================================================================================================
607  !
608
609  !OUTPUT
610  CALL CMISSFieldMLIO_Initialise( outputInfo, err )
611
612  CALL CMISSFieldML_OutputCreate( Mesh, outputDirectory, basename, dataFormat, outputInfo, err )
613  
614  CALL CMISSFieldML_OutputAddImport( outputInfo, "coordinates.rc.3d", typeHandle, err )
615  CALL CMISSFieldML_OutputAddField( outputInfo, baseName//".geometric", dataFormat, GeometricField, &
616    & CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
617  
618  CALL CMISSFieldML_OutputAddFieldComponents( outputInfo, typeHandle, baseName//".velocity", dataFormat, &
619    & DependentFieldNavierStokes, [1,2,3], CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
620  
621  CALL CMISSFieldML_OutputAddImport( outputInfo, "real.1d", typeHandle, err )
622  CALL CMISSFieldML_OutputAddFieldComponents( outputInfo, typeHandle, baseName//".pressure", dataFormat, &
623    & DependentFieldNavierStokes, [4], CMISS_FIELD_U_VARIABLE_TYPE, CMISS_FIELD_VALUES_SET_TYPE, err )
624  
625  CALL CMISSFieldML_OutputWrite( outputInfo, outputFilename, err )
626  
627  CALL CMISSFieldMLIO_Finalise( outputInfo, err )
628  
629  EXPORT_FIELD_IO=.TRUE.
630  IF(EXPORT_FIELD_IO) THEN
631    WRITE(*,'(A)') "Exporting fields..."
632    CALL CMISSFields_Initialise(Fields, err )
633    CALL CMISSFields_Create(Region,Fields, err )
634    CALL CMISSFields_NodesExport(Fields,"StaticNavierStokes","FORTRAN", err )
635    CALL CMISSFields_ElementsExport(Fields,"StaticNavierStokes","FORTRAN", err )
636    CALL CMISSFields_Finalise(Fields, err )
637    WRITE(*,'(A)') "Field exported!"
638  ENDIF
639
640  !Finialise CMISS
641  CALL CMISSFinalise(Err)
642
643  WRITE(*,'(A)') "Program successfully completed."
644  
645  STOP
646
647END PROGRAM NAVIERSTOKESSTATICEXAMPLE