/Meshes/Simplex/Triangular/Quadratic/src/QuadraticExample.f90

http://github.com/xyan075/examples · Fortran Modern · 212 lines · 92 code · 36 blank · 84 comment · 0 complexity · 4fc05ce678e76a993b8dac2e821009ac MD5 · raw file

  1. !> \file
  2. !> \author Chris Bradley
  3. !> \brief This is an example program to set up a generated mesh of quadratic Simplex triangle elements.
  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 Meshes/Simplex/Triangle/Quadratic/src/QuadraticExample.f90
  42. !! Example program to to set up a generated mesh of quadratic Simplex triangle elements.
  43. !! \htmlinclude Meshes/Simplex/Triangle/Quadratic/history.html
  44. !!
  45. !<
  46. !> Main program
  47. PROGRAM QUADRATICTRIANGLESIMPLEXEXAMPLE
  48. USE OPENCMISS
  49. USE MPI
  50. #ifdef WIN32
  51. USE IFQWIN
  52. #endif
  53. IMPLICIT NONE
  54. !Test program parameters
  55. REAL(CMISSDP), PARAMETER :: HEIGHT=1.0_CMISSDP
  56. REAL(CMISSDP), PARAMETER :: WIDTH=2.0_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. !Program types
  65. !Program variables
  66. INTEGER(CMISSIntg) :: NUMBER_GLOBAL_X_ELEMENTS,NUMBER_GLOBAL_Y_ELEMENTS
  67. INTEGER(CMISSIntg) :: MPI_IERROR
  68. !CMISS variables
  69. TYPE(CMISSBasisType) :: Basis
  70. TYPE(CMISSCoordinateSystemType) :: CoordinateSystem,WorldCoordinateSystem
  71. TYPE(CMISSDecompositionType) :: Decomposition
  72. TYPE(CMISSFieldType) :: GeometricField
  73. TYPE(CMISSFieldsType) :: Fields
  74. TYPE(CMISSGeneratedMeshType) :: GeneratedMesh
  75. TYPE(CMISSMeshType) :: Mesh
  76. TYPE(CMISSRegionType) :: Region,WorldRegion
  77. #ifdef WIN32
  78. !Quickwin type
  79. LOGICAL :: QUICKWIN_STATUS=.FALSE.
  80. TYPE(WINDOWCONFIG) :: QUICKWIN_WINDOW_CONFIG
  81. #endif
  82. !Generic CMISS variables
  83. INTEGER(CMISSIntg) :: NumberOfComputationalNodes,ComputationalNodeNumber
  84. INTEGER(CMISSIntg) :: Err
  85. #ifdef WIN32
  86. !Initialise QuickWin
  87. QUICKWIN_WINDOW_CONFIG%TITLE="General Output" !Window title
  88. QUICKWIN_WINDOW_CONFIG%NUMTEXTROWS=-1 !Max possible number of rows
  89. QUICKWIN_WINDOW_CONFIG%MODE=QWIN$SCROLLDOWN
  90. !Set the window parameters
  91. QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
  92. !If attempt fails set with system estimated values
  93. IF(.NOT.QUICKWIN_STATUS) QUICKWIN_STATUS=SETWINDOWCONFIG(QUICKWIN_WINDOW_CONFIG)
  94. #endif
  95. !Intialise OpenCMISS
  96. CALL CMISSInitialise(WorldCoordinateSystem,WorldRegion,Err)
  97. CALL CMISSErrorHandlingModeSet(CMISS_ERRORS_TRAP_ERROR,Err)
  98. CALL CMISSDiagnosticsSetOn(CMISS_IN_DIAG_TYPE,(/1,2,3,4,5/),"Diagnostics",(/"MESH_TOPOLOGY_ELEMENTS_CREATE_FINISH"/),Err)
  99. !Get the computational nodes information
  100. CALL CMISSComputationalNumberOfNodesGet(NumberOfComputationalNodes,Err)
  101. CALL CMISSComputationalNodeNumberGet(ComputationalNodeNumber,Err)
  102. NUMBER_GLOBAL_X_ELEMENTS=3
  103. NUMBER_GLOBAL_Y_ELEMENTS=3
  104. !Broadcast the number of elements in the X & Y directions to the other computational nodes
  105. CALL MPI_BCAST(NUMBER_GLOBAL_X_ELEMENTS,1,MPI_INTEGER,0,MPI_COMM_WORLD,MPI_IERROR)
  106. CALL MPI_BCAST(NUMBER_GLOBAL_Y_ELEMENTS,1,MPI_INTEGER,0,MPI_COMM_WORLD,MPI_IERROR)
  107. !Start the creation of a new RC coordinate system
  108. CALL CMISSCoordinateSystem_Initialise(CoordinateSystem,Err)
  109. CALL CMISSCoordinateSystem_CreateStart(CoordinateSystemUserNumber,CoordinateSystem,Err)
  110. !Set the coordinate system to be 2D
  111. CALL CMISSCoordinateSystem_DimensionSet(CoordinateSystem,2,Err)
  112. !Finish the creation of the coordinate system
  113. CALL CMISSCoordinateSystem_CreateFinish(CoordinateSystem,Err)
  114. !Start the creation of the region
  115. CALL CMISSRegion_Initialise(Region,Err)
  116. CALL CMISSRegion_CreateStart(RegionUserNumber,WorldRegion,Region,Err)
  117. !Set the regions coordinate system to the 2D RC coordinate system that we have created
  118. CALL CMISSRegion_CoordinateSystemSet(Region,CoordinateSystem,Err)
  119. !Finish the creation of the region
  120. CALL CMISSRegion_CreateFinish(Region,Err)
  121. !Start the creation of a basis
  122. CALL CMISSBasis_Initialise(Basis,Err)
  123. CALL CMISSBasis_CreateStart(BasisUserNumber,Basis,Err)
  124. !Set the type to be a Simplex basis
  125. CALL CMISSBasis_TypeSet(Basis,CMISS_BASIS_SIMPLEX_TYPE,Err)
  126. !Set the basis to be a triangular basis
  127. CALL CMISSBasis_NumberOfXiSet(Basis,2,Err)
  128. !Set the interpolation to be quadratic
  129. CALL CMISSBasis_InterpolationXiSet(Basis,(/CMISS_BASIS_QUADRATIC_SIMPLEX_INTERPOLATION, &
  130. & CMISS_BASIS_QUADRATIC_SIMPLEX_INTERPOLATION/),Err)
  131. !Finish the creation of the basis
  132. CALL CMISSBasis_CreateFinish(Basis,Err)
  133. !Start the creation of a generated mesh in the region
  134. CALL CMISSGeneratedMesh_Initialise(GeneratedMesh,Err)
  135. CALL CMISSGeneratedMesh_CreateStart(GeneratedMeshUserNumber,Region,GeneratedMesh,Err)
  136. !Set up a regular x*y mesh
  137. CALL CMISSGeneratedMesh_TypeSet(GeneratedMesh,CMISS_GENERATED_MESH_REGULAR_MESH_TYPE,Err)
  138. !Set the default basis
  139. CALL CMISSGeneratedMesh_BasisSet(GeneratedMesh,Basis,Err)
  140. !Define the mesh on the region
  141. CALL CMISSGeneratedMesh_ExtentSet(GeneratedMesh,(/WIDTH,HEIGHT/),Err)
  142. CALL CMISSGeneratedMesh_NumberOfElementsSet(GeneratedMesh,(/NUMBER_GLOBAL_X_ELEMENTS,NUMBER_GLOBAL_Y_ELEMENTS/),Err)
  143. !Finish the creation of a generated mesh in the region
  144. CALL CMISSMesh_Initialise(Mesh,Err)
  145. CALL CMISSGeneratedMesh_CreateFinish(GeneratedMesh,MeshUserNumber,Mesh,Err)
  146. !Create a decomposition
  147. CALL CMISSDecomposition_Initialise(Decomposition,Err)
  148. CALL CMISSDecomposition_CreateStart(DecompositionUserNumber,Mesh,Decomposition,Err)
  149. !Set the decomposition to be a general decomposition with the specified number of domains
  150. CALL CMISSDecomposition_TypeSet(Decomposition,CMISS_DECOMPOSITION_CALCULATED_TYPE,Err)
  151. CALL CMISSDecomposition_NumberOfDomainsSet(Decomposition,NumberOfComputationalNodes,Err)
  152. !Finish the decomposition
  153. CALL CMISSDecomposition_CreateFinish(Decomposition,Err)
  154. !Start to create a default (geometric) field on the region
  155. CALL CMISSField_Initialise(GeometricField,Err)
  156. CALL CMISSField_CreateStart(GeometricFieldUserNumber,Region,GeometricField,Err)
  157. !Set the decomposition to use
  158. CALL CMISSField_MeshDecompositionSet(GeometricField,Decomposition,Err)
  159. !Set the domain to be used by the field components.
  160. CALL CMISSField_ComponentMeshComponentSet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,1,1,Err)
  161. CALL CMISSField_ComponentMeshComponentSet(GeometricField,CMISS_FIELD_U_VARIABLE_TYPE,2,1,Err)
  162. !Finish creating the field
  163. CALL CMISSField_CreateFinish(GeometricField,Err)
  164. !Update the geometric field parameters
  165. CALL CMISSGeneratedMesh_GeometricParametersCalculate(GeneratedMesh,GeometricField,Err)
  166. !Export the fields
  167. CALL CMISSFields_Initialise(Fields,Err)
  168. CALL CMISSFields_Create(Region,Fields,Err)
  169. CALL CMISSFields_NodesExport(Fields,"QuadraticTriangleSimplex","FORTRAN",Err)
  170. CALL CMISSFields_ElementsExport(Fields,"QuadraticTriangleSimplex","FORTRAN",Err)
  171. CALL CMISSFields_Finalise(Fields,Err)
  172. !Finialise CMISS
  173. CALL CMISSFinalise(Err)
  174. WRITE(*,'(A)') "Program successfully completed."
  175. STOP
  176. END PROGRAM QUADRATICTRIANGLESIMPLEXEXAMPLE