| 1 | #!/bin/sh |
| 2 | # autopkgtest check: Build and run a program against libmedc |
| 3 | # (C) 2013 Thomas Moulard |
| 4 | # (C) 2014 Anton Gladky |
| 5 | # Author: Thomas Moulard <[email protected]> |
| 6 | # Anton Gladky <[email protected]> |
| 7 | |
| 8 | set -e |
| 9 | |
| 10 | WORKDIR=$(mktemp -d) |
| 11 | trap "rm -rf $WORKDIR" 0 INT QUIT ABRT PIPE TERM |
| 12 | cd $WORKDIR |
| 13 | cat <<EOF > usescase.c |
| 14 | /* This file is part of MED. |
| 15 | * |
| 16 | * COPYRIGHT (C) 1999 - 2012 EDF R&D, CEA/DEN |
| 17 | * MED is free software: you can redistribute it and/or modify |
| 18 | * it under the terms of the GNU Lesser General Public License as published by |
| 19 | * the Free Software Foundation, either version 3 of the License, or |
| 20 | * (at your option) any later version. |
| 21 | * |
| 22 | * MED is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU Lesser General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU Lesser General Public License |
| 28 | * along with MED. If not, see <http://www.gnu.org/licenses/>. |
| 29 | */ |
| 30 | |
| 31 | /* |
| 32 | * Field use case 10 : write a field in a MED file with computing steps, |
| 33 | * profiles, integration points and interpolation families |
| 34 | */ |
| 35 | |
| 36 | #include <med.h> |
| 37 | #define MESGERR 1 |
| 38 | #include <med_utils.h> |
| 39 | |
| 40 | #include <string.h> |
| 41 | |
| 42 | |
| 43 | int main (int argc, char **argv) { |
| 44 | med_idt fid; |
| 45 | const char meshname[MED_NAME_SIZE+1] = "2D unstructured mesh"; |
| 46 | const char fieldname[MED_NAME_SIZE+1] = "TEMPERATURE_FIELD"; |
| 47 | const med_int ncomponent = 1; |
| 48 | const char componentname[MED_SNAME_SIZE+1] = "TEMPERATURE"; |
| 49 | const char componentunit[MED_SNAME_SIZE+1] = "C"; |
| 50 | const med_float tria3values_step1_profile1[9] = {1000.,1010.,1020., |
| 51 | 4000.,4010.,4020., |
| 52 | 8000.,8010.,8020. }; |
| 53 | const med_float tria3values_step2_profile1[24] = {1500.,1510.,1520., |
| 54 | 0., 0., 0., |
| 55 | 0., 0., 0., |
| 56 | 4500.,4510,4520., |
| 57 | 0., 0., 0., |
| 58 | 0., 0., 0., |
| 59 | 0., 0., 0., |
| 60 | 8500., 8510, 8520 }; |
| 61 | const med_float tria3values_step2_profile2[32] = { 0., 0., 0., 0., |
| 62 | 2500.,2510.,2520,2530., |
| 63 | 3500.,3510.,3520.,3530., |
| 64 | 0., 0., 0., 0., |
| 65 | 5500.,5510.,5520.,5530., |
| 66 | 6500.,6510.,6520.,6530., |
| 67 | 7500.,7510.,7520.,7530., |
| 68 | 0., 0., 0., 0. }; |
| 69 | const med_int ntria3 = 8; |
| 70 | const med_int nquad4 = 4; |
| 71 | const med_float quad4values_step1[4] = {10000., 20000., 30000., 40000.}; |
| 72 | const med_float quad4values_step2[4] = {15000., 25000., 35000., 45000.}; |
| 73 | const char profile1name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE1"; |
| 74 | const med_int profile1[3] = {1, 4, 8}; |
| 75 | const med_int profile1size = 3; |
| 76 | const char profile2name[MED_NAME_SIZE+1] = "MED_TRIA3_PROFILE2"; |
| 77 | const med_int profile2[5] = {2, 3, 5, 6, 7}; |
| 78 | const med_int profile2size = 5; |
| 79 | const char localization1name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_3"; |
| 80 | const med_float weight1[3] = {1.0/6, 1.0/6, 1.0/6}; |
| 81 | const med_float elementcoordinate[6] = {0.0, 0.0, 1.0, 0.0, 0.0,1.0}; |
| 82 | const med_float ipoint1coordinate[6] = {1.0/6, 1.0/6, 2.0/3, 1.0/6, 1.0/6, 2.0/6}; |
| 83 | const char localization2name[MED_NAME_SIZE+1] = "TRIA3_INTEGRATION_POINTS_4"; |
| 84 | const med_float weight2[6] = {25.0/(24*4), 25.0/(24*4), 25.0/(24*4), -27.0/(24*4)}; |
| 85 | const med_float ipoint2coordinate[8] = {1.0/5, 1.0/5, 3.0/5, 1.0/5, 1.0/5, 3.0/5, 1.0/3, 1.0/3}; |
| 86 | med_int nipoint, spacedim; |
| 87 | const char interpname[MED_NAME_SIZE+1] = "MED_TRIA3 interpolation family"; |
| 88 | int ret=-1; |
| 89 | |
| 90 | /* file creation */ |
| 91 | fid = MEDfileOpen("UsesCase_MEDfield_10.med",MED_ACC_CREAT); |
| 92 | if (fid < 0) { |
| 93 | MESSAGE("ERROR : file creation ..."); |
| 94 | goto ERROR; |
| 95 | } |
| 96 | |
| 97 | /* create mesh link */ |
| 98 | if (MEDlinkWr(fid,meshname,"./UsesCase_MEDmesh_1.med") < 0) { |
| 99 | MESSAGE("ERROR : create mesh link ..."); |
| 100 | goto ERROR; |
| 101 | } |
| 102 | |
| 103 | /* create the profiles in the file */ |
| 104 | if (MEDprofileWr(fid, profile1name, profile1size, profile1 ) < 0) { |
| 105 | MESSAGE("ERROR : create profile ..."); |
| 106 | goto ERROR; |
| 107 | } |
| 108 | |
| 109 | if (MEDprofileWr(fid, profile2name, profile2size, profile2 ) < 0) { |
| 110 | MESSAGE("ERROR : create profile ..."); |
| 111 | goto ERROR; |
| 112 | } |
| 113 | |
| 114 | /* create the localization elements for integration points */ |
| 115 | spacedim = 2; |
| 116 | nipoint = 3; |
| 117 | if (MEDlocalizationWr(fid, localization1name, MED_TRIA3, spacedim, |
| 118 | elementcoordinate, MED_FULL_INTERLACE, |
| 119 | nipoint, ipoint1coordinate, weight1, |
| 120 | MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) { |
| 121 | MESSAGE("ERROR : create famlily of integration points ..."); |
| 122 | goto ERROR; |
| 123 | } |
| 124 | |
| 125 | spacedim = 2; |
| 126 | nipoint = 4; |
| 127 | if (MEDlocalizationWr(fid, localization2name, MED_TRIA3, spacedim, |
| 128 | elementcoordinate, MED_FULL_INTERLACE, |
| 129 | nipoint, ipoint2coordinate, weight2, |
| 130 | MED_NO_INTERPOLATION, MED_NO_MESH_SUPPORT) < 0) { |
| 131 | MESSAGE("ERROR : create famlily of integration points ..."); |
| 132 | goto ERROR; |
| 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Temperature field creation : |
| 137 | * - 1 component |
| 138 | * - component unit : celsius degree |
| 139 | * - mesh is the 2D unstructured mesh of UsecaseMEDmesh_1.c use case. |
| 140 | * - computation step unit in 'ms' |
| 141 | */ |
| 142 | if (MEDfieldCr(fid, fieldname, MED_FLOAT64, |
| 143 | ncomponent, componentname, componentunit, |
| 144 | "ms", meshname) < 0) { |
| 145 | MESSAGE("ERROR : create field"); |
| 146 | goto ERROR; |
| 147 | } |
| 148 | |
| 149 | /* write interpolation family name for MED_TRIA3 cell type */ |
| 150 | /* The interpolation family "interpname" is created in the UsesCase_MEDinterp_1 |
| 151 | use case */ |
| 152 | if (MEDfieldInterpWr(fid,fieldname,interpname) <0) { |
| 153 | MESSAGE("ERROR : write field interpolation family name ..."); |
| 154 | goto ERROR; |
| 155 | } |
| 156 | |
| 157 | /* two computation steps */ |
| 158 | /* write values at cell centers : 8 MED_TRIA3 and 4 MED_QUAD4 */ |
| 159 | |
| 160 | /* STEP 1 : dt1 = 5.5, it = 1*/ |
| 161 | /* MED_TRIA3 : with a profile of 3 values in compact memory storage mode |
| 162 | and a family of 3 integration points */ |
| 163 | if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL,MED_TRIA3, |
| 164 | MED_COMPACT_PFLMODE, profile1name, localization1name, |
| 165 | MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, |
| 166 | ntria3, (unsigned char*) tria3values_step1_profile1) < 0) { |
| 167 | MESSAGE("ERROR : write field values on MED_TRIA3"); |
| 168 | goto ERROR; |
| 169 | } |
| 170 | /* MED_QUAD4 : with no profile */ |
| 171 | if (MEDfieldValueWithProfileWr(fid, fieldname, 1, 1, 5.5, MED_CELL, MED_QUAD4, |
| 172 | MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION, |
| 173 | MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, |
| 174 | nquad4, (unsigned char*) quad4values_step1) < 0) { |
| 175 | MESSAGE("ERROR : write field values on MED_QUAD4 "); |
| 176 | goto ERROR; |
| 177 | } |
| 178 | |
| 179 | /* STEP 2 : dt2 = 8.9, it = 1*/ |
| 180 | /* MED_TRIA3 : with a profile of 3 values then a profile of 5 values in global memory storage mode |
| 181 | * For each profile, a family of 3 and then 4 integration points */ |
| 182 | if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, |
| 183 | MED_GLOBAL_PFLMODE, profile1name, localization1name, |
| 184 | MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, |
| 185 | ntria3, (unsigned char*) tria3values_step2_profile1) < 0) { |
| 186 | MESSAGE("ERROR : write field values on MED_TRIA3 ..."); |
| 187 | goto ERROR; |
| 188 | } |
| 189 | if (MEDfieldValueWithProfileWr(fid, fieldname, 2 , 1 , 8.9 , MED_CELL, MED_TRIA3, |
| 190 | MED_GLOBAL_PFLMODE, profile2name, localization2name, |
| 191 | MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, |
| 192 | ntria3, (unsigned char*) tria3values_step2_profile2) < 0) { |
| 193 | MESSAGE("ERROR : write field values on MED_TRIA3 ..."); |
| 194 | goto ERROR; |
| 195 | } |
| 196 | |
| 197 | /* MED_QUAD4 : with no profile */ |
| 198 | if (MEDfieldValueWithProfileWr(fid, fieldname, 2, 1, 8.9, MED_CELL, MED_QUAD4, |
| 199 | MED_COMPACT_PFLMODE, MED_NO_PROFILE, MED_NO_LOCALIZATION, |
| 200 | MED_FULL_INTERLACE, MED_ALL_CONSTITUENT, |
| 201 | nquad4, (unsigned char*) quad4values_step2) < 0) { |
| 202 | MESSAGE("ERROR : write field values on MED_QUAD4 ... "); |
| 203 | goto ERROR; |
| 204 | } |
| 205 | |
| 206 | ret=0; |
| 207 | ERROR: |
| 208 | |
| 209 | /* close file */ |
| 210 | if (MEDfileClose(fid) < 0) { |
| 211 | MESSAGE("ERROR : close file ..."); |
| 212 | ret=-1; |
| 213 | } |
| 214 | |
| 215 | return ret; |
| 216 | } |
| 217 | |
| 218 | EOF |
| 219 | |
| 220 | mpicc -I/usr/include/hdf5/openmpi -I/usr/include/hdf5/mpich -I/usr/include/hdf5/serial -I/usr/include -Wl,--as-needed -o usescase usescase.c -lmedC |
| 221 | echo "build: OK" |
| 222 | [ -x usescase ] |
| 223 | ./usescase |
| 224 | echo "run: OK" |