PageRenderTime 38ms CodeModel.GetById 13ms app.highlight 21ms RepoModel.GetById 2ms app.codeStats 0ms

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