root/src/exosetfind.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. exosetfind
  2. exoset_check

   1 /*     CalculiX - A 3-dimensional finite element program                 */
   2 /*              Copyright (C) 1998-2011 Guido Dhondt                     */
   3 /*     This subroutine                                                   */
   4 /*              Copyright (C) 2013-2014 Peter A. Gustafson                    */
   5 /*                                                                       */
   6 /*     This program is free software; you can redistribute it and/or     */
   7 /*     modify it under the terms of the GNU General Public License as    */
   8 /*     published by the Free Software Foundation(version 2);    */
   9 /*                                                                       */
  10 
  11 /*     This program is distributed in the hope that it will be useful,   */
  12 /*     but WITHOUT ANY WARRANTY; without even the implied warranty of    */ 
  13 /*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the      */
  14 /*     GNU General Public License for more details.                      */
  15 
  16 /*     You should have received a copy of the GNU General Public License */
  17 /*     along with this program; if not, write to the Free Software       */
  18 /*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.         */
  19 
  20 #include <stdlib.h>
  21 #include <math.h>
  22 #include <stdio.h>
  23 #include <string.h>
  24 #include "CalculiX.h"
  25 #include "exodusII.h"
  26 #include "exo.h"
  27 
  28 void exosetfind(char *set, ITG *nset, ITG *ialset, ITG *istartset, ITG *iendset, 
  29                 ITG *num_ns, ITG *num_ss, ITG *num_es, ITG *num_fs, ITG *node_map_inv,
  30                 int exoid, int store, ITG *nk){
  31   
  32   ITG i,j,k,l,n,s,e,gen;
  33   char tmpstr[81];
  34   char *space = " ";
  35   char *pos;
  36   ITG *set_nums;
  37   int errr;
  38   int dropped=0, unidentified=0;
  39   
  40   *num_ns = 0; 
  41   *num_ss = 0;
  42   *num_es = 0;
  43   *num_fs = 0; 
  44   
  45   for (i=0; i<*nset; i++){
  46     
  47     if (store) {
  48       // Find and store the set numbers
  49       // The pointer integers are 1 based (fortran)
  50       s=istartset[i]-1;
  51       e=iendset[i]-1;
  52       // Determine if generate was used
  53       gen=0; l=0;
  54       for (j=s; j<=e; j++){
  55         if (ialset[j]<0) {
  56           gen+=(ialset[j-1]-ialset[j-2])/(-ialset[j])+1;
  57           l-=3;
  58         }
  59       }
  60       
  61       // Now set the length of the set allocation
  62       l=e-s+1+gen+l;
  63       set_nums = (ITG *) calloc(l, sizeof(ITG));
  64 
  65       /* Only add the generate code if there are at least
  66          three points in the vector */
  67       n=0; j=s;
  68       if (l>2){
  69         while (j<=e-2){
  70           // Account for generated ids
  71           if (ialset[j+2]<0) {
  72             for (k=ialset[j]; k<=ialset[j+1]; k-=ialset[j+2]){
  73               set_nums[n++]=exoset_check(k-1, node_map_inv, nk, &dropped, &unidentified);
  74             }
  75             j+=3;
  76           }else{
  77             // Account for directly added id
  78             gen=ialset[j++]-1;
  79             set_nums[n++]=exoset_check(gen, node_map_inv, nk, &dropped, &unidentified);
  80           }
  81         }
  82         // Must finish the last two of directly added set
  83         if (ialset[e]>0){ // only if the last set is not a generated set
  84           // 1+n++ and -1+n++ to preserve order
  85           set_nums[1+n++]=exoset_check(ialset[e]-2, node_map_inv, nk, &dropped, &unidentified);
  86           if (ialset[e-1]>0){
  87             set_nums[-1+n++]=exoset_check(ialset[e]-3, node_map_inv, nk, &dropped, &unidentified);
  88           }
  89         }
  90       }else if(l>1){
  91         set_nums[n++]=exoset_check(ialset[s]-1, node_map_inv, nk, &dropped, &unidentified);
  92         set_nums[n++]=exoset_check(ialset[e]-1, node_map_inv, nk, &dropped, &unidentified);
  93       }else{
  94         set_nums[n++]=exoset_check(ialset[e]-1, node_map_inv, nk, &dropped, &unidentified);
  95       }
  96     } // if (store)
  97 
  98     strncpy(tmpstr,set+i*81,81);
  99     pos = strpbrk(tmpstr, space)-1;
 100 
 101     if(strcmp1(pos,"N")==0){
 102       (*num_ns)++; // printf ("Node set identified\n"); 
 103       if (store){
 104         errr = ex_put_node_set_param (exoid, i, n, 0); // CURRENTLY NO DISTRIBUTIONS ADDED
 105         if (errr) printf ("Error writing set parameters\n");
 106         errr = ex_put_node_set       (exoid, i, set_nums);
 107         if (errr) printf ("Error writing set numbers\n");
 108         // ex_put_node_set_dist_fact (exoid, i, set_nums);  // 
 109       }
 110     }    
 111     if(strcmp1(pos,"E")==0) {
 112       (*num_es)++; // printf ("Element set identified\n");}
 113       /* No element set storage mechanism?
 114       if (store){ 
 115         errr = ex_put_elem_set_param (exoid, i, n, 0);
 116         if (errr) printf ("Error writing set parameters\n");
 117         errr = ex_put_elem_set       (exoid, i, set_nums);
 118         if (errr) printf ("Error writing set numbers\n");
 119         // ex_put_elem_set_dist_fact (exoid, i, set_nums);  // 
 120         } */
 121     } 
 122     if(strcmp1(pos,"S")==0) {
 123       (*num_ss)++; // printf ("Node side set surface identified\n");}
 124       /* Side sets (node surfaces) not yet implemented
 125          if (store){ 
 126         errr = ex_put_side_set_param (exoid, i, n, 0);
 127         if (errr) printf ("Error writing set parameters\n");
 128         errr = ex_put_side_set       (exoid, i, set_nums);
 129         if (errr) printf ("Error writing set numbers\n");
 130         // ex_put_side_set_dist_fact (exoid, i, set_nums);  // 
 131         } */
 132     } 
 133     if(strcmp1(pos,"T")==0) {
 134       (*num_fs)++; // printf ("Face set surface identified\n");} 
 135       /* Face sets not yet implemented
 136          if (store){ 
 137          errr = ex_put_face_set_param (exoid, i, n, 0);
 138          if (errr) printf ("Error writing set parameters\n");
 139          errr = ex_put_face_set       (exoid, i, set_nums);
 140          if (errr) printf ("Error writing set numbers\n");
 141          // ex_put_face_set_dist_fact (exoid, i, set_nums);  // 
 142          } */
 143     }
 144     if (store) {free (set_nums);}
 145   }
 146   
 147   if (store){
 148     // char *namesnset[*num_ns]; j=0;
 149     // char *namessset[*num_ss]; k=0;
 150     // char *nameseset[*num_es]; l=0;
 151     // char *namesfset[*num_fs]; n=0;
 152 
 153     for (i=0; i<*nset; i++){
 154       strncpy(tmpstr,set+i*81,81);
 155       pos = strpbrk(tmpstr, space)-1;
 156       // This crashed in valgrind
 157       // if(strcmp1(pos,"N")==0) {strncpy(namesnset[j++], tmpstr, MAX_STR_LENGTH);}
 158       // if(strcmp1(pos,"E")==0) {strcpy(nameseset[l++],tmpstr);}
 159       // if(strcmp1(pos,"S")==0) {strcpy(namessset[k++],tmpstr);}
 160       // if(strcmp1(pos,"T")==0) {strcpy(namesfset[n++],tmpstr);}
 161     }
 162     
 163     // if (*num_ns>0){
 164     //   errr = ex_put_names (exoid, EX_NODE_SET, namesnset);
 165     //   if (errr) printf ("Error writing node set names\n");
 166     // }
 167     /* side sets not implemented yet
 168        if (*num_ss>0){
 169        errr = ex_put_names (exoid, EX_SIDE_SET, namessset);
 170        if (errr) printf ("Error writing side set names\n");
 171        }
 172     */
 173   }
 174 
 175   if (dropped){
 176     printf ("\nExodus Output WARNING: At least one node or element is dropped from a set.\n");
 177     printf ("  This may be due rigid bodies or 3D expansion (beams, shells, OUTPUT=3D).\n\n");
 178   }
 179 
 180   if (unidentified){
 181     printf ("\nExodus Output WARNING: At least one unidentified node or element is dropped from a set.\n\n");
 182   }
 183 
 184   return;
 185 }
 186 
 187 
 188 ITG exoset_check(ITG n, ITG *node_map_inv, ITG *nk, int *dropped, int *unidentified){
 189   ITG val=0;
 190   // printf ("%" ITGFORMAT ", %" ITGFORMAT "\n", n, *nk);
 191   if (n<=*nk){
 192     val = node_map_inv[n]-1;
 193     // printf ("val node number %" ITGFORMAT "\n", val+1);
 194     if (val==-1) {
 195       *dropped = 1;
 196     }
 197   }else{
 198     // printf("UNIDENTIFIED %" ITGFORMAT "\n", n);
 199     *unidentified = 1;
 200   }
 201   return val;
 202 }

/* [<][>][^][v][top][bottom][index][help] */