1 /*
2     Copyright (C) 1998  Dennis Roddeman
3     email: dennis.roddeman@feat.nl
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software Foundation
17     59 Temple Place, Suite 330, Boston, MA, 02111-1307, USA
18 */
19 
20 #include "tochnog.h"
21 
adjust_geom(long int geometry_entity[],long int geometry_entity_edge[])22 void adjust_geom( long int geometry_entity[],
23   long int geometry_entity_edge[] )
24 
25 {
26   long int element=0, max_element=0, inol=0, nnol=0, inod=0, length=0,
27     all_in_geometry=0, some_in_geometry=0, in_geometry=0,
28     node_boundary=-YES, swit=0, ldum=0,
29     idum[1], *nodes=NULL, *el=NULL, *node_in_geometry=NULL;
30   double rdum=0., ddum[MDIM], coord[MDIM],
31     diff_coord[MDIM], node_start_refined[MDIM], projection[MDIM],
32     normal_dum[MDIM];
33 
34   area_node_dataitem();
35 
36   swit = set_swit(-1,-1,"adjust_geom");
37   if ( swit ) pri( "In routine ADJUST_GEOM" );
38 
39   nodes = get_new_int(MNOL);
40   el = get_new_int(MNOL+1);
41   node_in_geometry = get_new_int(MNOL);
42 
43   db_max_index( ELEMENT, max_element, VERSION_NORMAL, GET );
44   if ( geometry_entity[0]==-GEOMETRY_SET ) {
45     cout << "Sorry, a GEOMETRY_SET cannot be used for adjusting geometry.";
46     exit(TN_EXIT_STATUS);
47   }
48 
49   for ( element=0; element<=max_element; element++ ) {
50     if ( db_active_index( ELEMENT, element, VERSION_NORMAL ) &&
51          !db_active_index( ELEMENT_ADJUST, element, VERSION_NORMAL ) ) {
52       db( ELEMENT, element, el, ddum, length, VERSION_NORMAL, GET );
53       nnol = length - 1; array_move( &el[1], nodes, nnol );
54       some_in_geometry = 0; all_in_geometry = 1;
55       array_set( node_in_geometry, 0., nnol );
56       for ( inol=0; inol<nnol; inol++ ) {
57         inod = nodes[inol];
58         geometry( inod, ddum, geometry_entity, in_geometry, rdum,
59           normal_dum, rdum, projection, NODE_START_REFINED, PROJECT_EXACT,
60           VERSION_NORMAL );
61         if ( in_geometry ) {
62           some_in_geometry = 1;
63           node_in_geometry[inol] = 1;
64         }
65         else
66           all_in_geometry = 0;
67       }
68       if ( some_in_geometry && !all_in_geometry ) {
69         for ( inol=0; inol<nnol; inol++ ) {
70           inod = nodes[inol];
71           if ( node_in_geometry[inol] &&
72                !db_active_index( NODE_ADJUST, inod, VERSION_NORMAL ) ) {
73             geometry( inod, ddum, geometry_entity_edge, in_geometry, rdum,
74               normal_dum, rdum, projection, NODE_START_REFINED, PROJECT_EXACT,
75               VERSION_NORMAL );
76             db( NODE_START_REFINED, inod, idum, node_start_refined,
77               ldum, VERSION_NORMAL, GET );
78             db( NODE, inod, idum, coord, ldum, VERSION_NORMAL, GET );
79             array_subtract( projection, node_start_refined, diff_coord, ndim );
80             array_add( coord, diff_coord, coord, ndim );
81             length = 1;
82             db( NODE, inod, idum, coord, ndim, VERSION_NORMAL, PUT );
83             db( NODE_START_REFINED, inod, idum, projection,
84               ndim, VERSION_NORMAL, PUT );
85             db( NODE_BOUNDARY, inod, &node_boundary, ddum, length,
86                VERSION_NORMAL, PUT );
87           }
88         }
89       }
90     }
91   }
92   mesh_has_changed( VERSION_NORMAL );
93 
94   delete[] nodes;
95   delete[] el;
96   delete[] node_in_geometry;
97 
98   if ( swit ) pri( "Out routine ADJUST_GEOM" );
99 
100 }
101