1
by hhiester
deleting initialisation as none of tools are used any longer. |
1 |
! Copyright (C) 2006 Imperial College London and others.
|
2 |
!
|
|
3 |
! Please see the AUTHORS file in the main source directory for a full list
|
|
4 |
! of copyright holders.
|
|
5 |
!
|
|
6 |
! Prof. C Pain
|
|
7 |
! Applied Modelling and Computation Group
|
|
8 |
! Department of Earth Science and Engineering
|
|
9 |
! Imperial College London
|
|
10 |
!
|
|
2392
by tmb1
Changing isntances of Chris' person email address to the group |
11 |
! amcgsoftware@imperial.ac.uk
|
1
by hhiester
deleting initialisation as none of tools are used any longer. |
12 |
!
|
13 |
! This library is free software; you can redistribute it and/or
|
|
14 |
! modify it under the terms of the GNU Lesser General Public
|
|
15 |
! License as published by the Free Software Foundation; either
|
|
16 |
! version 2.1 of the License, or (at your option) any later version.
|
|
17 |
!
|
|
18 |
! This library is distributed in the hope that it will be useful,
|
|
19 |
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
20 |
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
21 |
! Lesser General Public License for more details.
|
|
22 |
!
|
|
23 |
! You should have received a copy of the GNU Lesser General Public
|
|
24 |
! License along with this library; if not, write to the Free Software
|
|
25 |
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
26 |
! USA
|
|
27 |
||
28 |
#include "fdebug.h"
|
|
29 |
||
30 |
subroutine pseudo_mesh(filename, filename_len, target_elements) |
|
31 |
||
32 |
use adapt_state_module |
|
33 |
use conformity_measurement |
|
34 |
use fields |
|
35 |
use fldebug |
|
36 |
use global_parameters, only : current_debug_level |
|
37 |
use interpolation_module |
|
38 |
use limit_metric_module |
|
39 |
use read_triangle |
|
40 |
use parallel_tools |
|
41 |
use reference_counting |
|
42 |
use write_triangle |
|
43 |
||
44 |
implicit none
|
|
45 |
|
|
46 |
integer, intent(in) :: filename_len |
|
47 |
||
48 |
character(len = filename_len), intent(in) :: filename |
|
49 |
integer, intent(in) :: target_elements |
|
50 |
||
51 |
integer :: i |
|
52 |
integer, parameter :: adapt_iterations = 5 |
|
53 |
real, dimension(:, :), allocatable :: unit_matrix |
|
54 |
type(tensor_field) :: metric, target_metric |
|
55 |
type(vector_field) :: input_positions, output_positions, stage_2_input_positions |
|
56 |
||
57 |
ewrite(1, *) "In pseudo_mesh" |
|
58 |
||
59 |
if(isparallel()) then |
|
1759
by jhill1
FLAbort/FLExit fixes. IGW does not actually compile, but at least the FLAborts and FLExits are correct... |
60 |
ewrite(-1,*) "You are running in parallel" |
61 |
FLExit("pseudo_mesh does not work in parallel") |
|
1
by hhiester
deleting initialisation as none of tools are used any longer. |
62 |
end if
|
63 |
|
|
64 |
ewrite(2, *) "Target input elements? ", target_elements /= 0 |
|
65 |
||
66 |
! Step 1: Input
|
|
67 |
input_positions = read_triangle_files(filename, quad_degree = 4) |
|
68 |
||
69 |
! Step 2: Adapt. We do this in two stages - the first to pull us a long way
|
|
70 |
! from the target mesh, and the second to pull us back towards it. This
|
|
71 |
! ensures that adaptivity actually does something, rather than just giving us
|
|
72 |
! a copy of the input mesh.
|
|
73 |
||
74 |
! Adapt stage 1: Coarsen as much as possible everywhere
|
|
75 |
ewrite(2, *) "Adapt stage 1: Coarsening" |
|
76 |
||
77 |
call allocate(metric, input_positions%mesh, "Metric", field_type = FIELD_TYPE_CONSTANT) |
|
78 |
allocate(unit_matrix(metric%dim, metric%dim)) |
|
79 |
unit_matrix = 0.0 |
|
80 |
do i = 1, metric%dim |
|
81 |
unit_matrix(i, i) = 1.0 |
|
82 |
end do
|
|
83 |
call set(metric, unit_matrix) |
|
84 |
deallocate(unit_matrix) |
|
85 |
call limit_metric(input_positions, metric, target_nodes = 1) |
|
86 |
||
87 |
call adapt_mesh(input_positions, metric, output_positions) |
|
88 |
call deallocate(metric) |
|
89 |
||
90 |
call write_triangle_files("pseudo_mesh_stage_1", output_positions) |
|
91 |
ewrite(2, *) "Node count = ", node_count(output_positions) |
|
92 |
ewrite(2, *) "Element count = ", ele_count(output_positions) |
|
93 |
||
94 |
! Adapt stage 2: Now adapt to the actual target metric
|
|
95 |
ewrite(2, *) "Adapt stage 2: Targetting input mesh metric" |
|
96 |
||
97 |
call compute_mesh_metric(input_positions, target_metric) |
|
98 |
||
99 |
! Subcycle, as each time we're targetting an interpolated metric
|
|
100 |
do i = 1, adapt_iterations |
|
101 |
ewrite(2, "(a,i0,a,i0)") "Iteration ", i, " of ", adapt_iterations |
|
102 |
||
103 |
call allocate(metric, output_positions%mesh, "InterpolatedTargetMetric") |
|
104 |
call linear_interpolation(target_metric, input_positions, metric, output_positions) |
|
105 |
if(target_elements /= 0) then |
|
106 |
! Target elements, to ensure convergence of repeated pseudo-meshing
|
|
107 |
call limit_metric_elements(output_positions, metric, target_eles = ele_count(input_positions)) |
|
108 |
else
|
|
109 |
! If we're not targetting, limit the metric anyway (but loosly) as it's
|
|
110 |
! possible that there are very small or large edge lengths at the
|
|
111 |
! boundaries of the input mesh
|
|
112 |
call limit_metric(output_positions, metric, min_nodes = max(int(0.5 * node_count(input_positions)), 1), max_nodes = 2 * node_count(input_positions)) |
|
113 |
end if
|
|
114 |
||
115 |
! Copy the output from the last adapt, for use as input for the next adapt
|
|
116 |
call allocate(stage_2_input_positions, output_positions%dim, output_positions%mesh, output_positions%name) |
|
117 |
call set(stage_2_input_positions, output_positions) |
|
118 |
call deallocate(output_positions) |
|
119 |
||
120 |
call adapt_mesh(stage_2_input_positions, metric, output_positions) |
|
121 |
call deallocate(metric) |
|
122 |
call deallocate(stage_2_input_positions) |
|
123 |
||
124 |
call write_triangle_files("pseudo_mesh_stage_2_" // int2str(i), output_positions) |
|
125 |
ewrite(2, *) "Node count = ", node_count(output_positions) |
|
126 |
ewrite(2, *) "Element count = ", ele_count(output_positions) |
|
127 |
end do
|
|
128 |
|
|
129 |
call deallocate(target_metric) |
|
130 |
call deallocate(input_positions) |
|
131 |
||
132 |
! Step 3: Output
|
|
133 |
||
134 |
call write_triangle_files("pseudo_mesh", output_positions) |
|
135 |
call deallocate(output_positions) |
|
136 |
||
137 |
call print_references(0) |
|
138 |
||
139 |
ewrite(1, *) "Exiting pseudo_mesh" |
|
140 |
||
141 |
end subroutine pseudo_mesh |