/FluidMechanics/Burgers/GeneralisedBurgers/src/GeneralisedBurgersExample.f90
http://github.com/xyan075/examples · Fortran Modern · 409 lines · 182 code · 51 blank · 176 comment · 0 complexity · f7e5936a798e59da55b406e151902173 MD5 · raw file
- !> \file
- !> \author David Ladd
- !> \brief This is an example program to solve a generalised Burgers's equation using OpenCMISS calls.
- !>
- !> \section LICENSE
- !>
- !> Version: MPL 1.1/GPL 2.0/LGPL 2.1
- !>
- !> The contents of this file are subject to the Mozilla Public License
- !> Version 1.1 (the "License"); you may not use this file except in
- !> compliance with the License. You may obtain a copy of the License at
- !> http://www.mozilla.org/MPL/
- !>
- !> Software distributed under the License is distributed on an "AS IS"
- !> basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
- !> License for the specific language governing rights and limitations
- !> under the License.
- !>
- !> The Original Code is OpenCMISS
- !>
- !> The Initial Developer of the Original Code is University of Auckland,
- !> Auckland, New Zealand and University of Oxford, Oxford, United
- !> Kingdom. Portions created by the University of Auckland and University
- !> of Oxford are Copyright (C) 2007 by the University of Auckland and
- !> the University of Oxford. All Rights Reserved.
- !>
- !> Contributor(s):
- !>
- !> Alternatively, the contents of this file may be used under the terms of
- !> either the GNU General Public License Version 2 or later (the "GPL"), or
- !> the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
- !> in which case the provisions of the GPL or the LGPL are applicable instead
- !> of those above. If you wish to allow use of your version of this file only
- !> under the terms of either the GPL or the LGPL, and not to allow others to
- !> use your version of this file under the terms of the MPL, indicate your
- !> decision by deleting the provisions above and replace them with the notice
- !> and other provisions required by the GPL or the LGPL. If you do not delete
- !> the provisions above, a recipient may use your version of this file under
- !> the terms of any one of the MPL, the GPL or the LGPL.
- !>
- !> \example ClassicalField/Burgers/src/GeneralisedBurgersExample.f90
- !! Example program to solve a generalised Burgers equation using OpenCMISS calls.
- !! \htmlinclude ClassicalField/Burgers/history.html
- !<
- !> Main program
- PROGRAM GENERALISEDBURGERSEXAMPLE
- USE OPENCMISS
- USE MPI
- #ifdef WIN32
- USE IFQWIN
- #endif
- IMPLICIT NONE
- !-----------------------------------------------------------------------------------------------------------
- ! PROGRAM VARIABLES AND TYPES
- !-----------------------------------------------------------------------------------------------------------
- !Test program parameters
-
- REAL(CMISSDP), PARAMETER :: LENGTH=3.0_CMISSDP
- INTEGER(CMISSIntg), PARAMETER :: NUMBER_GLOBAL_X_ELEMENTS=6
- REAL(CMISSDP), PARAMETER :: START_TIME=0.0_CMISSDP
- REAL(CMISSDP), PARAMETER :: STOP_TIME=0.1_CMISSDP
- REAL(CMISSDP), PARAMETER :: TIME_INCREMENT=0.01_CMISSDP
-
- INTEGER(CMISSIntg), PARAMETER :: CoordinateSystemUserNumber=1
- INTEGER(CMISSIntg), PARAMETER :: RegionUserNumber=2
- INTEGER(CMISSIntg), PARAMETER :: BasisUserNumber=3
- INTEGER(CMISSIntg), PARAMETER :: GeneratedMeshUserNumber=4
- INTEGER(CMISSIntg), PARAMETER :: MeshUserNumber=5
- INTEGER(CMISSIntg), PARAMETER :: DecompositionUserNumber=6
- INTEGER(CMISSIntg), PARAMETER :: GeometricFieldUserNumber=7
- INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=8
- INTEGER(CMISSIntg), PARAMETER :: DependentFieldUserNumber=9
- INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumber=10
- INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumber=11
- INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=12
- INTEGER(CMISSIntg), PARAMETER :: ControlLoopNode=0
- INTEGER(CMISSIntg), PARAMETER :: AnalyticFieldUserNumber=13
- INTEGER(CMISSIntg), PARAMETER :: SolverUserNumber=1
-
- !Program variables
- !Program types
- TYPE(CMISSBasisType) :: Basis
- TYPE(CMISSCoordinateSystemType) :: CoordinateSystem,WorldCoordinateSystem
- TYPE(CMISSDecompositionType) :: Decomposition
- TYPE(CMISSEquationsType) :: Equations
- TYPE(CMISSEquationsSetType) :: EquationsSet
- TYPE(CMISSFieldType) :: AnalyticField,DependentField,EquationsSetField,GeometricField,MaterialsField
- TYPE(CMISSFieldsType) :: Fields
- TYPE(CMISSGeneratedMeshType) :: GeneratedMesh
- TYPE(CMISSMeshType) :: Mesh
- TYPE(CMISSProblemType) :: Problem
- TYPE(CMISSControlLoopType) :: ControlLoop
- TYPE(CMISSRegionType) :: Region,WorldRegion
- TYPE(CMISSSolverType) :: DynamicSolver,NonlinearSolver,LinearSolver
- TYPE(CMISSSolverEquationsType) :: SolverEquations
- TYPE(CMISSBoundaryConditionsType) :: BoundaryConditions
- #ifdef WIN32
- !Quickwin type
- LOGICAL :: QUICKWIN_STATUS=.FALSE.
- TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
- #endif
-
- !Generic CMISS variables
-
- INTEGER(CMISSIntg) :: NumberOfComputationalNodes,ComputationalNodeNumber
- INTEGER(CMISSIntg) :: EquationsSetIndex
- INTEGER(CMISSIntg) :: Err
- LOGICAL :: LINEAR_SOLVER_DIRECT_FLAG
-
- #ifdef WIN32
- !Initialise QuickWin
- QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
- QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
- QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
- !Set the window parameters
- QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
- !If attempt fails set with system estimated values
- IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
- #endif
-
- !Intialise OpenCMISS
- CALL CMISSInitialise(WorldCoordinateSystem,WorldRegion,Err)
- CALL CMISSErrorHandlingModeSet(CMISS_ERRORS_TRAP_ERROR,Err)
- CALL CMISSOutputSetOn("Burgers1DAnalytic",Err)
-
- !Get the computational nodes information
- CALL CMISSComputationalNumberOfNodesGet(NumberOfComputationalNodes,Err)
- CALL CMISSComputationalNodeNumberGet(ComputationalNodeNumber,Err)
- !-----------------------------------------------------------------------------------------------------------
- !COORDINATE SYSTEM
- !-----------------------------------------------------------------------------------------------------------
- !Start the creation of a new RC coordinate system
- CALL CMISSCoordinateSystem_Initialise(CoordinateSystem,Err)
- CALL CMISSCoordinateSystem_CreateStart(CoordinateSystemUserNumber,CoordinateSystem,Err)
- !Set the coordinate system to be 1D
- CALL CMISSCoordinateSystem_DimensionSet(CoordinateSystem,1,Err)
- !Finish the creation of the coordinate system
- CALL CMISSCoordinateSystem_CreateFinish(CoordinateSystem,Err)
- !-----------------------------------------------------------------------------------------------------------
- !REGION
- !-----------------------------------------------------------------------------------------------------------
- !Start the creation of the region
- CALL CMISSRegion_Initialise(Region,Err)
- CALL CMISSRegion_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
- CALL CMISSRegion_LabelSet(Region,"BurgersRegion",Err)
- !Set the regions coordinate system to the 1D RC coordinate system that we have created
- CALL CMISSRegion_CoordinateSystemSet(Region,CoordinateSystem,Err)
- !Finish the creation of the region
- CALL CMISSRegion_CreateFinish(Region,Err)
-
- !-----------------------------------------------------------------------------------------------------------
- !BASIS
- !-----------------------------------------------------------------------------------------------------------
- !Start the creation of a basis
- CALL CMISSBasis_Initialise(Basis,Err)
- CALL CMISSBasis_CreateStart(BasisUserNumber,Basis,Err)
- CALL CMISSBasis_TypeSet(Basis,CMISS_BASIS_LAGRANGE_HERMITE_TP_TYPE,Err)
- CALL CMISSBasis_NumberOfXiSet(Basis,1,Err)
- !Set the basis xi interpolation and number of Gauss points
- CALL CMISSBasis_InterpolationXiSet(Basis,[CMISS_BASIS_LINEAR_LAGRANGE_INTERPOLATION],Err)
- CALL CMISSBasis_QuadratureNumberOfGaussXiSet(Basis,[3],Err)
- !Finish the creation of the basis
- CALL CMISSBasis_CreateFinish(Basis,Err)
- !-----------------------------------------------------------------------------------------------------------
- !MESH
- !-----------------------------------------------------------------------------------------------------------
- !Start the creation of a generated mesh in the region
- CALL CMISSGeneratedMesh_Initialise(GeneratedMesh,Err)
- CALL CMISSGeneratedMesh_CreateStart(GeneratedMeshUserNumber,Region,GeneratedMesh,Err)
- !Set up a regular x mesh
- CALL CMISSGeneratedMesh_TypeSet(GeneratedMesh,CMISS_GENERATED_MESH_REGULAR_MESH_TYPE,Err)
- !Set the default basis
- CALL CMISSGeneratedMesh_BasisSet(GeneratedMesh,Basis,Err)
- !Define the mesh on the region
- CALL CMISSGeneratedMesh_ExtentSet(GeneratedMesh,[LENGTH],Err)
- CALL CMISSGeneratedMesh_NumberOfElementsSet(GeneratedMesh,[NUMBER_GLOBAL_X_ELEMENTS],Err)
- !Finish the creation of a generated mesh in the region
- CALL CMISSMesh_Initialise(Mesh,Err)
- CALL CMISSGeneratedMesh_CreateFinish(GeneratedMesh,MeshUserNumber,Mesh,Err)
- !-----------------------------------------------------------------------------------------------------------
- !GEOMETRIC FIELD
- !-----------------------------------------------------------------------------------------------------------
- !Create a decomposition
- CALL CMISSDecomposition_Initialise(Decomposition,Err)
- CALL CMISSDecomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition,Err)
- !Set the decomposition to be a general decomposition with the specified number of domains
- CALL CMISSDecomposition_TypeSet(Decomposition,CMISS_DECOMPOSITION_CALCULATED_TYPE,Err)
- CALL CMISSDecomposition_NumberOfDomainsSet(Decomposition,NumberOfComputationalNodes,Err)
- !Finish the decomposition
- CALL CMISSDecomposition_CreateFinish(Decomposition,Err)
-
- !Start to create a default (geometric) field on the region
- CALL CMISSField_Initialise(GeometricField,Err)
- CALL CMISSField_CreateStart(GeometricFieldUserNumber,Region,GeometricField,Err)
- !Set the decomposition to use
- CALL CMISSField_MeshDecompositionSet(GeometricField,Decomposition,Err)
- !Set the scaling to use
- CALL CMISSField_ScalingTypeSet(GeometricField,CMISS_FIELD_NO_SCALING,Err)
- !Set the domain to be used by the field components.
- CALL CMISSField_ComponentMeshComponentSet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,1,1,Err)
- !Finish creating the field
- CALL CMISSField_CreateFinish(GeometricField,Err)
- !Update the geometric field parameters
- CALL CMISSGeneratedMesh_GeometricParametersCalculate(GeneratedMesh,GeometricField,Err)
- !-----------------------------------------------------------------------------------------------------------
- !EQUATIONS SETS
- !-----------------------------------------------------------------------------------------------------------
-
- !Create the equations_set for a Generalised Burgers's equation
- CALL CMISSEquationsSet_Initialise(EquationsSet,Err)
- CALL CMISSField_Initialise(EquationsSetField,Err)
- CALL CMISSEquationsSet_CreateStart(EquationsSetUserNumber,Region,GeometricField,CMISS_EQUATIONS_SET_FLUID_MECHANICS_CLASS, &
- & CMISS_EQUATIONS_SET_BURGERS_EQUATION_TYPE,CMISS_EQUATIONS_SET_GENERALISED_BURGERS_SUBTYPE,EquationsSetFieldUserNumber, &
- & EquationsSetField,EquationsSet,Err)
- !Finish creating the equations set
- CALL CMISSEquationsSet_CreateFinish(EquationsSet,Err)
- !-----------------------------------------------------------------------------------------------------------
- ! DEPENDENT FIELD
- !-----------------------------------------------------------------------------------------------------------
- !Create the equations set dependent field variables
- CALL CMISSField_Initialise(DependentField,Err)
- CALL CMISSEquationsSet_DependentCreateStart(EquationsSet,DependentFieldUserNumber,DependentField,Err)
- !Finish the equations set dependent field variables
- CALL CMISSEquationsSet_DependentCreateFinish(EquationsSet,Err)
- !-----------------------------------------------------------------------------------------------------------
- ! MATERIALS FIELD
- !-----------------------------------------------------------------------------------------------------------
- !Create the equations set material field variables
- CALL CMISSField_Initialise(MaterialsField,Err)
- CALL CMISSEquationsSet_MaterialsCreateStart(EquationsSet,MaterialsFieldUserNumber,MaterialsField,Err)
- !Finish the equations set material field variables
- CALL CMISSEquationsSet_MaterialsCreateFinish(EquationsSet,Err)
- !Initialise materials field
- !Set A
- CALL CMISSField_ComponentValuesInitialise(MaterialsField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, &
- & 1,1.0_CMISSDP,Err)
- !Set B
- CALL CMISSField_ComponentValuesInitialise(MaterialsField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, &
- & 2,-1.0_CMISSDP,Err)
- !Set C
- CALL CMISSField_ComponentValuesInitialise(MaterialsField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE, &
- & 3,1.0_CMISSDP,Err)
- !-----------------------------------------------------------------------------------------------------------
- ! ANALYTIC FIELD
- !-----------------------------------------------------------------------------------------------------------
- !Create the equations set analytic field variables
- CALL CMISSField_Initialise(AnalyticField,Err)
- CALL CMISSEquationsSet_AnalyticCreateStart(EquationsSet,CMISS_EQUATIONS_SET_GENERALISED_BURGERS_EQUATION_ONE_DIM_2, &
- & AnalyticFieldUserNumber,AnalyticField,Err)
- !Finish the equations set analytic field variables
- CALL CMISSEquationsSet_AnalyticCreateFinish(EquationsSet,Err)
- !-----------------------------------------------------------------------------------------------------------
- ! EQUATIONS
- !-----------------------------------------------------------------------------------------------------------
- !Create the equations set equations
- CALL CMISSEquations_Initialise(Equations,Err)
- CALL CMISSEquationsSet_EquationsCreateStart(EquationsSet,Equations,Err)
- !Set the equations matrices sparsity type (Sparse/Full)
- CALL CMISSEquations_SparsityTypeSet(Equations,CMISS_EQUATIONS_FULL_MATRICES,Err)
- !Set the equations set output (NoOutput/TimingOutput/MatrixOutput/SolverMatrix/ElementMatrixOutput)
- CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_ELEMENT_MATRIX_OUTPUT,Err)
- !Finish the equations set equations
- CALL CMISSEquationsSet_EquationsCreateFinish(EquationsSet,Err)
- !-----------------------------------------------------------------------------------------------------------
- !PROBLEM
- !-----------------------------------------------------------------------------------------------------------
- !Create the problem
- CALL CMISSProblem_Initialise(Problem,Err)
- CALL CMISSProblem_CreateStart(ProblemUserNumber,Problem,Err)
- !Set the problem to be a static Burgers problem
- CALL CMISSProblem_SpecificationSet(Problem,CMISS_PROBLEM_FLUID_MECHANICS_CLASS,CMISS_PROBLEM_BURGERS_EQUATION_TYPE, &
- & CMISS_PROBLEM_DYNAMIC_BURGERS_SUBTYPE,Err)
- !Finish the creation of a problem.
- CALL CMISSProblem_CreateFinish(Problem,Err)
- !Create the problem control
- CALL CMISSControlLoop_Initialise(ControlLoop,Err)
- CALL CMISSProblem_ControlLoopCreateStart(Problem,Err)
- !Get the control loop
- CALL CMISSProblem_ControlLoopGet(Problem,CMISS_CONTROL_LOOP_NODE,ControlLoop,Err)
- !Set the times
- CALL CMISSControlLoop_TimesSet(ControlLoop,START_TIME,STOP_TIME,TIME_INCREMENT,Err)
- !Set the output timing
- CALL CMISSControlLoop_TimeOutputSet(ControlLoop,1,Err)
- !Finish creating the problem control loop
- CALL CMISSProblem_ControlLoopCreateFinish(Problem,Err)
- !-----------------------------------------------------------------------------------------------------------
- !SOLVER
- !-----------------------------------------------------------------------------------------------------------
- !Start the creation of the problem solvers
- CALL CMISSSolver_Initialise(DynamicSolver,Err)
- CALL CMISSSolver_Initialise(NonlinearSolver,Err)
- CALL CMISSSolver_Initialise(LinearSolver,Err)
- CALL CMISSProblem_SolversCreateStart(Problem,Err)
- !Get the dymamic solver
- CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,SolverUserNumber,DynamicSolver,Err)
- !Set the output type
- CALL CMISSSolver_OutputTypeSet(DynamicSolver,CMISS_SOLVER_MATRIX_OUTPUT,Err)
- !Set theta
- CALL CMISSSolver_DynamicThetaSet(DynamicSolver,0.5_CMISSDP,Err)
- !Get the dynamic nonlinear solver
- CALL CMISSSolver_DynamicNonlinearSolverGet(DynamicSolver,NonlinearSolver,Err)
- !Set the nonlinear Jacobian type
- !CALL CMISSSolver_NewtonJacobianCalculationTypeSet(NonlinearSolver,CMISS_SOLVER_NEWTON_JACOBIAN_FD_CALCULATED,Err)
- CALL CMISSSolver_NewtonJacobianCalculationTypeSet(NonlinearSolver,CMISS_SOLVER_NEWTON_JACOBIAN_EQUATIONS_CALCULATED,Err)
- !Set the line search
- CALL CMISSSolver_NewtonLineSearchTypeSet(NonlinearSolver,CMISS_SOLVER_NEWTON_LINESEARCH_NONE,Err)
- !Set the output type
- CALL CMISSSolver_OutputTypeSet(NonlinearSolver,CMISS_SOLVER_MATRIX_OUTPUT,Err)
- !Get the dynamic nonlinear linear solver
- CALL CMISSSolver_NewtonLinearSolverGet(NonlinearSolver,LinearSolver,Err)
- !Set the output type
- CALL CMISSSolver_OutputTypeSet(LinearSolver,CMISS_SOLVER_MATRIX_OUTPUT,Err)
- !Set the solver settings
- LINEAR_SOLVER_DIRECT_FLAG=.FALSE.
- IF(LINEAR_SOLVER_DIRECT_FLAG) THEN
- CALL CMISSSolver_LinearTypeSet(LinearSolver,CMISS_SOLVER_LINEAR_DIRECT_SOLVE_TYPE,Err)
- CALL CMISSSolver_LibraryTypeSet(LinearSolver,CMISS_SOLVER_MUMPS_LIBRARY,Err)
- ELSE
- CALL CMISSSolver_LinearTypeSet(LinearSolver,CMISS_SOLVER_LINEAR_ITERATIVE_SOLVE_TYPE,Err)
- CALL CMISSSolver_LinearIterativeMaximumIterationsSet(LinearSolver,10000,Err)
- CALL CMISSSolver_LinearIterativeGMRESRestartSet(LinearSolver,50,Err)
- ENDIF
- !Finish the creation of the problem solver
- CALL CMISSProblem_SolversCreateFinish(Problem,Err)
- !-----------------------------------------------------------------------------------------------------------
- !SOLVER EQUATIONS
- !-----------------------------------------------------------------------------------------------------------
- !Create the problem solver equations
- CALL CMISSSolver_Initialise(LinearSolver,Err)
- CALL CMISSSolverEquations_Initialise(SolverEquations,Err)
- CALL CMISSProblem_SolverEquationsCreateStart(Problem,Err)
- !Get the dynamic solver equations
- CALL CMISSSolver_Initialise(DynamicSolver,Err)
- CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,DynamicSolver,Err)
- CALL CMISSSolver_SolverEquationsGet(DynamicSolver,SolverEquations,Err)
- !Set the solver equations sparsity (Sparse/Full)
- CALL CMISSSolverEquations_SparsityTypeSet(SolverEquations,CMISS_SOLVER_FULL_MATRICES,Err)
- !Add in the equations set
- CALL CMISSSolverEquations_EquationsSetAdd(SolverEquations,EquationsSet,EquationsSetIndex,Err)
- !Finish the creation of the problem solver equations
- CALL CMISSProblem_SolverEquationsCreateFinish(Problem,Err)
- !-----------------------------------------------------------------------------------------------------------
- !BOUNDARY CONDITIONS
- !-----------------------------------------------------------------------------------------------------------
- !Set up the boundary conditions
- !Create the equations set boundary conditions
- CALL CMISSBoundaryConditions_Initialise(BoundaryConditions,Err)
- CALL CMISSSolverEquations_BoundaryConditionsCreateStart(SolverEquations,BoundaryConditions,Err)
- CALL CMISSSolverEquations_BoundaryConditionsAnalytic(SolverEquations,Err)
- CALL CMISSSolverEquations_BoundaryConditionsCreateFinish(SolverEquations,Err)
- !-----------------------------------------------------------------------------------------------------------
- !SOLVE
- !-----------------------------------------------------------------------------------------------------------
- !Solve the problem
- CALL CMISSProblem_Solve(Problem,Err)
- !-----------------------------------------------------------------------------------------------------------
- !OUTPUT
- !-----------------------------------------------------------------------------------------------------------
- !Output Analytic analysis
- Call CMISSAnalyticAnalysisOutput(DependentField,"BurgersAnalytic_1D",Err)
- !export fields
- CALL CMISSFields_Initialise(Fields,Err)
- CALL CMISSFields_Create(Region,Fields,Err)
- CALL CMISSFields_NodesExport(Fields,"Burgers_1D","FORTRAN",Err)
- CALL CMISSFields_ElementsExport(Fields,"Burgers_1D","FORTRAN",Err)
- CALL CMISSFields_Finalise(Fields,Err)
- WRITE(*,'(A)') "Program successfully completed."
- STOP
-
- END PROGRAM GENERALISEDBURGERSEXAMPLE