/ClassicalField/Diffusion/DiffusionExponentialSource/src/DiffusionExponentialSourceExample.f90

http://github.com/xyan075/examples · Fortran Modern · 311 lines · 148 code · 40 blank · 123 comment · 0 complexity · fc25f0972b0c92cf734a6bf0673bf670 MD5 · raw file

  1. !> \file
  2. !> \author Chris Bradley
  3. !> \brief This is an example program to solve a 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. !> \example ClassicalField/Diffusion/DiffusionExponentialSource/src/DiffusionExponentialSourceExample.f90
  42. !! Example program to solve a diffusion equation using openCMISS calls.
  43. !!
  44. !! \htmlinclude ClassicalField/Diffusion/DiffusionExponentialSource/history.html
  45. !<
  46. !> Main program
  47. PROGRAM DIFFUSIONEXPONENTIALSOURCEEXAMPLE
  48. USE OPENCMISS
  49. #ifdef WIN32
  50. USE IFQWIN
  51. #endif
  52. IMPLICIT NONE
  53. !Test program parameters
  54. INTEGER(CMISSIntg), PARAMETER :: NUMBER_GLOBAL_X_ELEMENTS=4
  55. REAL(CMISSDP), PARAMETER :: LENGTH=3.0_CMISSDP
  56. REAL(CMISSDP), PARAMETER :: END_TIME=0.1001_CMISSDP
  57. INTEGER(CMISSIntg), PARAMETER :: CoordinateSystemUserNumber=1
  58. INTEGER(CMISSIntg), PARAMETER :: RegionUserNumber=2
  59. INTEGER(CMISSIntg), PARAMETER :: BasisUserNumber=3
  60. INTEGER(CMISSIntg), PARAMETER :: GeneratedMeshUserNumber=4
  61. INTEGER(CMISSIntg), PARAMETER :: MeshUserNumber=5
  62. INTEGER(CMISSIntg), PARAMETER :: DecompositionUserNumber=6
  63. INTEGER(CMISSIntg), PARAMETER :: GeometricFieldUserNumber=7
  64. INTEGER(CMISSIntg), PARAMETER :: DependentFieldUserNumber=8
  65. INTEGER(CMISSIntg), PARAMETER :: MaterialsFieldUserNumber=9
  66. INTEGER(CMISSIntg), PARAMETER :: EquationsSetUserNumber=10
  67. INTEGER(CMISSIntg), PARAMETER :: EquationsSetFieldUserNumber=11
  68. INTEGER(CMISSIntg), PARAMETER :: ProblemUserNumber=12
  69. INTEGER(CMISSIntg), PARAMETER :: AnalyticFieldUserNumber=13
  70. !Program types
  71. !Program variables
  72. !CMISS variables
  73. TYPE(CMISSBasisType) :: Basis
  74. TYPE(CMISSCoordinateSystemType) :: CoordinateSystem,WorldCoordinateSystem
  75. TYPE(CMISSDecompositionType) :: Decomposition
  76. TYPE(CMISSEquationsType) :: Equations
  77. TYPE(CMISSEquationsSetType) :: EquationsSet
  78. TYPE(CMISSFieldType) :: GeometricField,DependentField,EquationsSetField,MaterialsField,AnalyticField
  79. TYPE(CMISSFieldsType) :: Fields
  80. TYPE(CMISSGeneratedMeshType) :: GeneratedMesh
  81. TYPE(CMISSMeshType) :: Mesh
  82. TYPE(CMISSProblemType) :: Problem
  83. TYPE(CMISSControlLoopType) :: ControlLoop
  84. TYPE(CMISSRegionType) :: Region,WorldRegion
  85. TYPE(CMISSSolverType) :: Solver, NonlinearSolver
  86. TYPE(CMISSSolverEquationsType) :: SolverEquations
  87. TYPE(CMISSBoundaryConditionsType) :: BoundaryConditions
  88. #ifdef WIN32
  89. !Quickwin type
  90. LOGICAL :: QUICKWIN_STATUS=.FALSE.
  91. TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
  92. #endif
  93. !Generic CMISS variables
  94. INTEGER(CMISSIntg) :: EquationsSetIndex
  95. INTEGER(CMISSIntg) :: Err
  96. #ifdef WIN32
  97. !Initialise QuickWin
  98. QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
  99. QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
  100. QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
  101. !Set the window parameters
  102. QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
  103. !If attempt fails set with system estimated values
  104. IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
  105. #endif
  106. !Intialise OpenCMISS
  107. CALL CMISSInitialise(WorldCoordinateSystem,WorldRegion,Err)
  108. !Start the creation of a new RC coordinate system
  109. CALL CMISSCoordinateSystem_Initialise(CoordinateSystem,Err)
  110. CALL CMISSCoordinateSystem_CreateStart(CoordinateSystemUserNumber,CoordinateSystem,Err)
  111. !Set the coordinate system to be 1D
  112. CALL CMISSCoordinateSystem_DimensionSet(CoordinateSystem,1,Err)
  113. !Finish the creation of the coordinate system
  114. CALL CMISSCoordinateSystem_CreateFinish(CoordinateSystem,Err)
  115. !Start the creation of the region
  116. CALL CMISSRegion_Initialise(Region,Err)
  117. CALL CMISSRegion_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
  118. !Label the Region
  119. CALL CMISSRegion_LabelSet(Region,"Region",Err)
  120. !Set the regions coordinate system to the 1D RC coordinate system that we have created
  121. CALL CMISSRegion_CoordinateSystemSet(Region,CoordinateSystem,Err)
  122. !Finish the creation of the region
  123. CALL CMISSRegion_CreateFinish(Region,Err)
  124. !Start the creation of a basis (default is trilinear lagrange)
  125. CALL CMISSBasis_Initialise(Basis,Err)
  126. CALL CMISSBasis_CreateStart(BasisUserNumber,Basis,Err)
  127. !Set the basis to be a linear Lagrange basis
  128. CALL CMISSBasis_NumberOfXiSet(Basis,1,Err)
  129. !Finish the creation of the basis
  130. CALL CMISSBasis_CreateFinish(BASIS,Err)
  131. !Start the creation of a generated mesh in the region
  132. CALL CMISSGeneratedMesh_Initialise(GeneratedMesh,Err)
  133. CALL CMISSGeneratedMesh_CreateStart(GeneratedMeshUserNumber,Region,GeneratedMesh,Err)
  134. !Set up a regular x*y*z mesh
  135. CALL CMISSGeneratedMesh_TypeSet(GeneratedMesh,CMISS_GENERATED_MESH_REGULAR_MESH_TYPE,Err)
  136. !Set the default basis
  137. CALL CMISSGeneratedMesh_BasisSet(GeneratedMesh,Basis,Err)
  138. !Define the mesh on the region
  139. CALL CMISSGeneratedMesh_ExtentSet(GeneratedMesh,[LENGTH],Err)
  140. CALL CMISSGeneratedMesh_NumberOfElementsSet(GeneratedMesh,[NUMBER_GLOBAL_X_ELEMENTS],Err)
  141. !Finish the creation of a generated mesh in the region
  142. CALL CMISSMesh_Initialise(Mesh,Err)
  143. CALL CMISSGeneratedMesh_CreateFinish(GeneratedMesh,MeshUserNumber,Mesh,Err)
  144. !Create a decomposition
  145. CALL CMISSDecomposition_Initialise(Decomposition,Err)
  146. CALL CMISSDecomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition,Err)
  147. !Set the decomposition to be a general decomposition with the specified number of domains
  148. CALL CMISSDecomposition_TypeSet(Decomposition,CMISS_DECOMPOSITION_CALCULATED_TYPE,Err)
  149. CALL CMISSDecomposition_NumberOfDomainsSet(Decomposition,1,Err)
  150. !Finish the decomposition
  151. CALL CMISSDecomposition_CreateFinish(Decomposition,Err)
  152. !Start to create a default (geometric) field on the region
  153. CALL CMISSField_Initialise(GeometricField,Err)
  154. CALL CMISSField_CreateStart(GeometricFieldUserNumber,Region,GeometricField,Err)
  155. !Set the decomposition to use
  156. CALL CMISSField_MeshDecompositionSet(GeometricField,Decomposition,Err)
  157. !Set the domain to be used by the field components.
  158. CALL CMISSField_ComponentMeshComponentSet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,1,1,Err)
  159. !Finish creating the field
  160. CALL CMISSField_CreateFinish(GeometricField,Err)
  161. !Update the geometric field parameters
  162. CALL CMISSGeneratedMesh_GeometricParametersCalculate(GeneratedMesh,GeometricField,Err)
  163. !Create the equations_set
  164. CALL CMISSEquationsSet_Initialise(EquationsSet,Err)
  165. CALL CMISSField_Initialise(EquationsSetField,Err)
  166. CALL CMISSEquationsSet_CreateStart(EquationsSetUserNumber,Region,GeometricField,CMISS_EQUATIONS_SET_CLASSICAL_FIELD_CLASS, &
  167. & CMISS_EQUATIONS_SET_DIFFUSION_EQUATION_TYPE,CMISS_EQUATIONS_SET_EXPONENTIAL_SOURCE_DIFFUSION_SUBTYPE, &
  168. & EquationsSetFieldUserNumber, &
  169. & EquationsSetField,EquationsSet,Err)
  170. !Finish creating the equations set
  171. CALL CMISSEquationsSet_CreateFinish(EquationsSet,Err)
  172. !Create the equations set dependent field variables
  173. CALL CMISSField_Initialise(DependentField,Err)
  174. CALL CMISSEquationsSet_DependentCreateStart(EquationsSet,DependentFieldUserNumber,DependentField,Err)
  175. !Finish the equations set dependent field variables
  176. CALL CMISSEquationsSet_DependentCreateFinish(EquationsSet,Err)
  177. !Create the equations set material field variables
  178. CALL CMISSField_Initialise(MaterialsField,Err)
  179. CALL CMISSEquationsSet_MaterialsCreateStart(EquationsSet,MaterialsFieldUserNumber,MaterialsField,Err)
  180. !Finish the equations set dependent field variables
  181. CALL CMISSEquationsSet_MaterialsCreateFinish(EquationsSet,Err)
  182. CALL CMISSField_ComponentValuesInitialise(MaterialsField,CMISS_FIELD_U_VARIABLE_TYPE,CMISS_FIELD_VALUES_SET_TYPE,2,-1.0_CMISSDP, &
  183. & Err)
  184. !Create the equations set analytic field variables
  185. CALL CMISSField_Initialise(AnalyticField,Err)
  186. CALL CMISSEquationsSet_AnalyticCreateStart(EquationsSet,CMISS_EQUATIONS_SET_EXPONENTIAL_SOURCE_DIFFUSION_ONE_DIM_1, &
  187. & AnalyticFieldUserNumber,AnalyticField,Err)
  188. !Finish the equations set analytic field variables
  189. CALL CMISSEquationsSet_AnalyticCreateFinish(EquationsSet,Err)
  190. !Create the equations set equations
  191. CALL CMISSEquations_Initialise(Equations,Err)
  192. CALL CMISSEquationsSet_EquationsCreateStart(EquationsSet,Equations,Err)
  193. !Set the equations matrices sparsity type
  194. CALL CMISSEquations_SparsityTypeSet(Equations,CMISS_EQUATIONS_SPARSE_MATRICES,Err)
  195. !Set the equations set output
  196. !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_NO_OUTPUT,Err)
  197. !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_TIMING_OUTPUT,Err)
  198. !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_MATRIX_OUTPUT,Err)
  199. !CALL CMISSEquations_OutputTypeSet(Equations,CMISS_EQUATIONS_ELEMENT_MATRIX_OUTPUT,Err)
  200. !Finish the equations set equations
  201. CALL CMISSEquationsSet_EquationsCreateFinish(EquationsSet,Err)
  202. !Create the problem
  203. CALL CMISSProblem_Initialise(Problem,Err)
  204. CALL CMISSProblem_CreateStart(ProblemUserNumber,Problem,Err)
  205. !Set the problem to be a No Source Diffusion problem
  206. CALL CMISSProblem_SpecificationSet(Problem,CMISS_PROBLEM_CLASSICAL_FIELD_CLASS,CMISS_PROBLEM_DIFFUSION_EQUATION_TYPE, &
  207. & CMISS_PROBLEM_NONLINEAR_SOURCE_DIFFUSION_SUBTYPE,Err)
  208. !Finish the creation of a problem.
  209. CALL CMISSProblem_CreateFinish(Problem,Err)
  210. !Create the problem control
  211. CALL CMISSProblem_ControlLoopCreateStart(Problem,Err)
  212. CALL CMISSControlLoop_Initialise(ControlLoop,Err)
  213. !Get the control loop
  214. CALL CMISSProblem_ControlLoopGet(Problem,CMISS_CONTROL_LOOP_NODE,ControlLoop,Err)
  215. !Set the times
  216. CALL CMISSControlLoop_TimesSet(ControlLoop,0.0_CMISSDP,END_TIME,0.001_CMISSDP,Err)
  217. !Finish creating the problem control loop
  218. CALL CMISSProblem_ControlLoopCreateFinish(Problem,Err)
  219. !Start the creation of the problem solvers
  220. CALL CMISSSolver_Initialise(Solver,Err)
  221. CALL CMISSSolver_Initialise(NonlinearSolver,Err)
  222. CALL CMISSProblem_SolversCreateStart(Problem,Err)
  223. CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,Solver,Err)
  224. !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_NO_OUTPUT,Err)
  225. !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
  226. !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_TIMING_OUTPUT,Err)
  227. !CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_SOLVER_OUTPUT,Err)
  228. CALL CMISSSolver_OutputTypeSet(Solver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
  229. CALL CMISSSolver_DynamicNonlinearSolverGet(Solver,NonlinearSolver,Err)
  230. CALL CMISSSolver_OutputTypeSet(NonlinearSolver,CMISS_SOLVER_PROGRESS_OUTPUT,Err)
  231. !Set the nonlinear Jacobian type
  232. CALL CMISSSolver_NewtonJacobianCalculationTypeSet(NonlinearSolver,CMISS_SOLVER_NEWTON_JACOBIAN_EQUATIONS_CALCULATED,Err)
  233. !CALL CMISSSolver_NewtonJacobianCalculationTypeSet(NonlinearSolver,CMISS_SOLVER_NEWTON_JACOBIAN_FD_CALCULATED,Err)
  234. !Finish the creation of the problem solver
  235. CALL CMISSProblem_SolversCreateFinish(Problem,Err)
  236. !Create the problem solver equations
  237. CALL CMISSSolver_Initialise(Solver,Err)
  238. CALL CMISSSolverEquations_Initialise(SolverEquations,Err)
  239. CALL CMISSProblem_SolverEquationsCreateStart(Problem,Err)
  240. !Get the solve equations
  241. CALL CMISSProblem_SolverGet(Problem,CMISS_CONTROL_LOOP_NODE,1,Solver,Err)
  242. CALL CMISSSolver_SolverEquationsGet(Solver,SolverEquations,Err)
  243. !Set the solver equations sparsity
  244. CALL CMISSSolverEquations_SparsityTypeSet(SolverEquations,CMISS_SOLVER_SPARSE_MATRICES,Err)
  245. !CALL CMISSSolverEquations_SparsityTypeSet(SolverEquations,CMISS_SOLVER_FULL_MATRICES,Err)
  246. !Add in the equations set
  247. CALL CMISSSolverEquations_EquationsSetAdd(SolverEquations,EquationsSet,EquationsSetIndex,Err)
  248. !Finish the creation of the problem solver equations
  249. CALL CMISSProblem_SolverEquationsCreateFinish(Problem,Err)
  250. !Create the equations set boundary conditions
  251. CALL CMISSBoundaryConditions_Initialise(BoundaryConditions,Err)
  252. CALL CMISSSolverEquations_BoundaryConditionsCreateStart(SolverEquations,BoundaryConditions,Err)
  253. CALL CMISSSolverEquations_BoundaryConditionsAnalytic(SolverEquations,Err)
  254. CALL CMISSSolverEquations_BoundaryConditionsCreateFinish(SolverEquations,Err)
  255. !Solve the problem
  256. CALL CMISSProblem_Solve(Problem,Err)
  257. !Output Analytic analysis
  258. !CALL CMISSEquationsSet_AnalyticTimeSet(EquationsSet,END_TIME,Err)
  259. !CALL CMISSEquationsSet_AnalyticEvaluate(EquationsSet,Err)
  260. CALL CMISSAnalyticAnalysisOutput(DependentField,"DiffusionExponentialSourceAnalytic",Err)
  261. !Output fields
  262. CALL CMISSFields_Initialise(Fields,Err)
  263. CALL CMISSFields_Create(Region,Fields,Err)
  264. CALL CMISSFields_NodesExport(Fields,"DiffusionExponentialSource","FORTRAN",Err)
  265. CALL CMISSFields_ElementsExport(Fields,"DiffusionExponentialSource","FORTRAN",Err)
  266. CALL CMISSFields_Finalise(Fields,Err)
  267. !Finalise and quit
  268. CALL CMISSFinalise(Err)
  269. WRITE(*,'(A)') "Program successfully completed."
  270. STOP
  271. END PROGRAM DIFFUSIONEXPONENTIALSOURCEEXAMPLE