root/src/exoselect.c

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

DEFINITIONS

This source file includes following definitions.
  1. exoselect

   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 #define min(a,b) ((a) <= (b) ? (a) : (b))
  29 #define max(a,b) ((a) >= (b) ? (a) : (b))
  30 
  31 void exoselect(double *field1,double *field2,ITG *iset,ITG *nkcoords,ITG *inum,
  32                ITG *istartset,ITG *iendset,ITG *ialset,ITG *ngraph,ITG *ncomp,
  33                ITG *ifield,ITG *icomp,ITG *nfield,ITG *iselect,ITG exoid,
  34                ITG time_step, int countvar, ITG nout){
  35     
  36   /* storing scalars, components of vectors and tensors without additional
  37      transformations */
  38 
  39   /* number of components in field1: nfield[0]
  40      number of components in field2: nfield[1]
  41 
  42      number of entities to store: ncomp
  43      for each entity i, 0<=i<ncomp:
  44      - ifield[i]: 1=field1,2=field2
  45      - icomp[i]: component: 0...,(nfield[0]-1 or nfield[1]-1) */
  46   
  47   ITG i,j,k,l,m,o,nksegment;
  48   /* When initializing parameter values:
  49      "g" (or "G")
  50      For global variables.
  51      "n" (or "N")
  52      For nodal variables.
  53      "e" (or "E")
  54      For element variables.
  55      "m" (or "M")
  56      For nodeset variables.
  57      "s" (or "S")
  58      For sideset variables.
  59   */
  60   // ITG num_nod_vars = *ncomp;
  61   float *nodal_var_vals;
  62   nodal_var_vals = (float *) calloc (nout, sizeof(float));
  63   
  64   
  65   for(j=0;j<*ncomp;j++){
  66     if(*iset==0){
  67       m=0;
  68       for(i=0;i<*nkcoords;i++){
  69         /* check whether output is requested for solid nodes or
  70            network nodes */
  71       
  72         if(*iselect==1){
  73           if(inum[i]<=0) continue;
  74         }else if(*iselect==-1){
  75           if(inum[i]>=0) continue;
  76         }else{
  77           if(inum[i]==0) continue;
  78         }
  79       
  80         /* storing the entities */
  81         if(ifield[j]==1){
  82           nodal_var_vals[m]=field1[i*nfield[0]+icomp[j]];
  83         }else{
  84           nodal_var_vals[m]=field2[i*nfield[1]+icomp[j]];
  85         }
  86         m++;
  87       }
  88     }else{
  89       nksegment=(*nkcoords)/(*ngraph);
  90       for(k=istartset[*iset-1]-1;k<iendset[*iset-1];k++){
  91         if(ialset[k]>0){
  92           
  93           m=0;
  94           for(l=0;l<*ngraph;l++){
  95             i=ialset[k]+l*nksegment-1;
  96             
  97             /* check whether output is requested for solid nodes or
  98                network nodes */
  99             
 100             if(*iselect==1){
 101               if(inum[i]<=0) continue;
 102             }else if(*iselect==-1){
 103               if(inum[i]>=0) continue;
 104             }else{
 105               if(inum[i]==0) continue;
 106             }
 107             
 108             /* storing the entities */
 109             if(ifield[j]==1){
 110               nodal_var_vals[m]=field1[i*nfield[0]+icomp[j]];
 111             }else{
 112               nodal_var_vals[m]=field2[i*nfield[1]+icomp[j]];
 113             }
 114             m++;
 115           }
 116         }else{
 117           l=ialset[k-2];
 118           do{
 119             l-=ialset[k];
 120             if(l>=ialset[k-1]) break;
 121             o=0;
 122             for(m=0;m<*ngraph;m++){
 123               i=l+m*nksegment-1;
 124             
 125               /* check whether output is requested for solid nodes or
 126                  network nodes */
 127             
 128               if(*iselect==1){
 129                 if(inum[i]<=0) continue;
 130               }else if(*iselect==-1){
 131                 if(inum[i]>=0) continue;
 132               }else{
 133                 if(inum[i]==0) continue;
 134               }
 135             
 136               /* storing the entities */
 137               if(ifield[j]==1){
 138                 nodal_var_vals[o]=field1[i*nfield[0]+icomp[j]];
 139               }else{
 140                 nodal_var_vals[o]=field2[i*nfield[1]+icomp[j]];
 141               }
 142             }
 143             o++;
 144             printf ("%f\n",nodal_var_vals[m]);
 145           }while(1);
 146         }
 147       }
 148     }
 149     
 150     // Note: reorder the results for exo tensor format
 151     if (*ncomp==12){
 152       k=j;
 153     }else if (j==4){
 154       k=5;
 155     }else if(j==5){
 156       k=4;
 157     }else{k=j;}
 158 
 159     int errr = ex_put_nodal_var (exoid, time_step, k+1+countvar, nout, nodal_var_vals);
 160     if (errr) printf ("ERROR exoselect data for dim %i record %i.\n", j, countvar+j);
 161   }
 162   
 163   free(nodal_var_vals);
 164   return;
 165 
 166 }

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