/ClassicalField/Diffusion/Analytic1DDiffusion/src/Analytic1DDiffusionExample.f90
http://github.com/xyan075/examples · Fortran Modern · 326 lines · 158 code · 42 blank · 126 comment · 0 complexity · ceb7fbe67449d11cad19eb66871c26dc MD5 · raw file
- !> \file
- !> \author Chris Bradley
- !> \brief This is an example program to solve a 1D diffusion equation and compare it to the analytic solution 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/Diffusion/Analytic1DDiffusion/src/Analytic1DDiffusionExample.f90
- !! Example program to solve a 1D diffusion equation using OpenCMISS calls.
- !!
- !! \htmlinclude ClassicalField/Diffusion/Analytic1DDiffusion/history.html
- !<
- !> Main program
- PROGRAM ANALYTIC1DDIFFUSIONEXAMPLE
- USE OPENCMISS
- #ifdef WIN32
- USE IFQWIN
- #endif
- IMPLICIT NONE
- !Test program parameters
- REAL(CMISSDP), PARAMETER :: PI=3.141592653589793238462643383279502884197_CMISSDP
- INTEGER(CMISSIntg), PARAMETER :: NUMBER_GLOBAL_X_ELEMENTS=6
- REAL(CMISSDP), PARAMETER :: LENGTH=3.0_CMISSDP
- REAL(CMISSDP), PARAMETER :: END_TIME=0.1_CMISSDP
- REAL(CMISSDP), PARAMETER :: TIME_STEP=0.01_CMISSDP
- REAL(CMISSDP), PARAMETER :: A=1.0_CMISSDP
- REAL(CMISSDP), PARAMETER :: B=PI/2.0_CMISSDP
- REAL(CMISSDP), PARAMETER :: C=0.0_CMISSDP
- REAL(CMISSDP), PARAMETER :: K=1.0_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 :: DependentFieldUserNumber=8
- INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumber=9
- INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumber=10
- INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=11
- INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=12
- INTEGER(CMISSIntg), PARAMETER :: AnalyticFieldUserNumber=13
- !Program types
-
- !Program variables
-
- !CMISS variables
- TYPE(CMISSBasisType) :: Basis
- TYPE(CMISSCoordinateSystemType) :: CoordinateSystem,WorldCoordinateSystem
- TYPE(CMISSDecompositionType) :: Decomposition
- TYPE(CMISSEquationsType) :: Equations
- TYPE(CMISSEquationsSetType) :: EquationsSet
- TYPE(CMISSFieldType) :: GeometricField,DependentField,EquationsSetField,MaterialsField,AnalyticField
- TYPE(CMISSFieldsType) :: Fields
- TYPE(CMISSGeneratedMeshType) :: GeneratedMesh
- TYPE(CMISSMeshType) :: Mesh
- TYPE(CMISSProblemType) :: Problem
- TYPE(CMISSControlLoopType) :: ControlLoop
- TYPE(CMISSRegionType) :: Region,WorldRegion
- TYPE(CMISSSolverType) :: Solver, 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) :: EquationsSetIndex
- INTEGER(CMISSIntg) :: Err
-
- #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("Diffusion1DAnalytic",Err)
-
- !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)
-
- !Start the creation of the region
- CALL CMISSRegion_Initialise(Region,Err)
- CALL CMISSRegion_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
- !Label the Region
- CALL CMISSRegion_LabelSet(Region,"Region",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)
-
- !Start the creation of a basis (default is trilinear lagrange)
- CALL CMISSBasis_Initialise(Basis,Err)
- CALL CMISSBasis_CreateStart(BasisUserNumber,Basis,Err)
- !Set the basis to be a linear Lagrange basis
- CALL CMISSBasis_NumberOfXiSet(Basis,1,Err)
- !Finish the creation of the basis
- CALL CMISSBasis_CreateFinish(BASIS,Err)
-
- !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 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)
-
- !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,1,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 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)
-
- !Create the equations_set
- CALL CMISSEquationsSet_Initialise(EquationsSet,Err)
- CALL CMISSField_Initialise(EquationsSetField,Err)
- CALL CMISSEquationsSet_CreateStart(EquationsSetUserNumber,Region,GeometricField,CMISS_EQUATIONS_SET_CLASSICAL_FIELD_CLASS, &
- & CMISS_EQUATIONS_SET_DIFFUSION_EQUATION_TYPE,CMISS_EQUATIONS_SET_NO_SOURCE_DIFFUSION_SUBTYPE,EquationsSetFieldUserNumber, &
- & EquationsSetField,EquationsSet,Err)
- !Finish creating the equations set
- CALL CMISSEquationsSet_CreateFinish(EquationsSet,Err)
- !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)
- !Create the equations set material field variables
- CALL CMISSField_Initialise(MaterialsField,Err)
- CALL CMISSEquationsSet_MaterialsCreateStart(EquationsSet,MaterialsFieldUserNumber,MaterialsField,Err)
- !Finish the equations set dependent field variables
- CALL CMISSEquationsSet_MaterialsCreateFinish(EquationsSet,Err)
- !Set the conductivity
- CALL CMISSField_ComponentValuesInitialise(MaterialsField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,1,K,Err)
-
- !Create the equations set analytic field variables
- CALL CMISSField_Initialise(AnalyticField,Err)
- CALL CMISSEquationsSet_AnalyticCreateStart(EquationsSet,CMISS_EQUATIONS_SET_DIFFUSION_EQUATION_ONE_DIM_1, &
- & AnalyticFieldUserNumber,AnalyticField,Err)
- !Finish the equations set analytic field variables
- CALL CMISSEquationsSet_AnalyticCreateFinish(EquationsSet,Err)
- !Set the analytic field parameters
- !Set the multiplicative constant.
- CALL CMISSField_ComponentValuesInitialise(AnalyticField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,1,A,Err)
- !Set the phase.
- CALL CMISSField_ComponentValuesInitialise(AnalyticField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,2,B,Err)
- !Set the offset.
- CALL CMISSField_ComponentValuesInitialise(AnalyticField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,3,C,Err)
- !Set the length to be the length of the mesh
- CALL CMISSField_ComponentValuesInitialise(AnalyticField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,4,LENGTH,Err)
-
- !Create the equations set equations
- CALL CMISSEquations_Initialise(Equations,Err)
- CALL CMISSEquationsSet_EquationsCreateStart(EquationsSet,Equations,Err)
- !Set the equations matrices sparsity type
- CALL CMISSEquations_SparsityTypeSet(Equations,CMISS_EQUATIONS_SPARSE_MATRICES,Err)
- !Set the equations set output
- !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_NO_OUTPUT,Err)
- !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_TIMING_OUTPUT,Err)
- !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_MATRIX_OUTPUT,Err)
- CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_ELEMENT_MATRIX_OUTPUT,Err)
- !Finish the equations set equations
- CALL CMISSEquationsSet_EquationsCreateFinish(EquationsSet,Err)
- !Create the problem
- CALL CMISSProblem_Initialise(Problem,Err)
- CALL CMISSProblem_CreateStart(ProblemUserNumber,Problem,Err)
- !Set the problem to be a No Source Diffusion problem
- CALL CMISSProblem_SpecificationSet(Problem,CMISS_PROBLEM_CLASSICAL_FIELD_CLASS,CMISS_PROBLEM_DIFFUSION_EQUATION_TYPE, &
- & CMISS_PROBLEM_LINEAR_SOURCE_DIFFUSION_SUBTYPE,Err)
- !Finish the creation of a problem.
- CALL CMISSProblem_CreateFinish(Problem,Err)
- !Create the problem control
- CALL CMISSProblem_ControlLoopCreateStart(Problem,Err)
- CALL CMISSControlLoop_Initialise(ControlLoop,Err)
- !Get the control loop
- CALL CMISSProblem_ControlLoopGet(Problem,CMISS_CONTROL_LOOP_NODE,ControlLoop,Err)
- !Set the times
- CALL CMISSControlLoop_TimesSet(ControlLoop,0.0_CMISSDP,END_TIME,TIME_STEP,Err)
- !Finish creating the problem control loop
- CALL CMISSProblem_ControlLoopCreateFinish(Problem,Err)
- !Start the creation of the problem solvers
- CALL CMISSSolver_Initialise(Solver,Err)
- CALL CMISSSolver_Initialise(LinearSolver,Err)
- CALL CMISSProblem_SolversCreateStart(Problem,Err)
- CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,Solver,Err)
- !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_NO_OUTPUT,Err)
- !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
- !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_TIMING_OUTPUT,Err)
- !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_SOLVER_OUTPUT,Err)
- CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_MATRIX_OUTPUT,Err)
- CALL CMISSSolver_DynamicLinearSolverGet(Solver,LinearSolver,Err)
- CALL CMISSSolver_OutputTypeSet(LinearSolver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
- !Finish the creation of the problem solver
- CALL CMISSProblem_SolversCreateFinish(Problem,Err)
- !Create the problem solver equations
- CALL CMISSSolver_Initialise(Solver,Err)
- CALL CMISSSolverEquations_Initialise(SolverEquations,Err)
- CALL CMISSProblem_SolverEquationsCreateStart(Problem,Err)
- !Get the solve equations
- CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,Solver,Err)
- CALL CMISSSolver_SolverEquationsGet(Solver,SolverEquations,Err)
- !Set the solver equations sparsity
- CALL CMISSSolverEquations_SparsityTypeSet(SolverEquations,CMISS_SOLVER_SPARSE_MATRICES,Err)
- !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)
- !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 the problem
- CALL CMISSProblem_Solve(Problem,Err)
- !Output Analytic analysis
- !CALL CMISSEquationsSet_AnalyticTimeSet(EquationsSet,END_TIME,Err)
- !CALL CMISSEquationsSet_AnalyticEvaluate(EquationsSet,Err)
- CALL CMISSAnalyticAnalysisOutput(DependentField,"Diffusion1DAnalytic",Err)
- !Output fields
- CALL CMISSFields_Initialise(Fields,Err)
- CALL CMISSFields_Create(Region,Fields,Err)
- CALL CMISSFields_NodesExport(Fields,"Diffusion1DAnalytic","FORTRAN",Err)
- CALL CMISSFields_ElementsExport(Fields,"Diffusion1DAnalytic","FORTRAN",Err)
- CALL CMISSFields_Finalise(Fields,Err)
- !Finalise and quit
- CALL CMISSFinalise(Err)
- WRITE(*,'(A)') "Program successfully completed."
- STOP
-
- END PROGRAM ANALYTIC1DDIFFUSIONEXAMPLE